Skip to content
Snippets Groups Projects
Select Git revision
  • 6fc704b601c055af8dd4ab91525ef082308a0627
  • master default protected
2 results

search_algorithm.cpython-38.pyc

Blame
  • http-server.c 13.47 KiB
    /*
    ** http-server.c
    */
    
    #include <errno.h>
    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #include <arpa/inet.h>
    #include <fcntl.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <strings.h>
    #include <sys/select.h>
    #include <sys/sendfile.h>
    #include <sys/socket.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <unistd.h>
    
    #include <stdarg.h>
    #include <stddef.h>
    #include <stdint.h>
    #include <time.h>
    
    void reset_game();
    void reset_user(int sockfd);
    void set_user(int sockfd);
    void user_ready(int sockfd);
    
    // constants
    static char const * const HTTP_200_FORMAT = "HTTP/1.1 200 OK\r\n\
    Content-Type: text/html\r\n\
    Set-Cookie: name=foo\r\n\
    Content-Length: %ld\r\n\r\n";
    static char const * const HTTP_400 = "HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n";
    static int const HTTP_400_LENGTH = 47;
    static char const * const HTTP_404 = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n";
    static int const HTTP_404_LENGTH = 45;
    
    static int user1 = -1;
    static int user1_start = 0;
    char user1_guesses[100][100];
    int user1_guess_number = 0;
    
    static int user2 = -1;
    static int user2_start = 0;
    char user2_guesses[100][100];
    int user2_guess_number = 0;
    
    int gameover = 0;
    
    static char *webpage;
    
    // represents the types of method
    typedef enum
    {
        GET,
        POST,
        UNKNOWN
    } METHOD;
    
    static bool handle_http_request(int sockfd)
    {
        // try to read the request
        char buff[2049];
        int n = read(sockfd, buff, 2049);
        if (n <= 0)