Skip to content
Snippets Groups Projects
Select Git revision
  • 3d2172ccb3b590e575e94a235bf8ff8544c67ac5
  • master default protected
2 results

http-server.c

Blame
  • http-server.c 14.40 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);
    void print_details();
    
    // constants
    static char const * const HTTP_200_FORMAT = "HTTP/1.1 200 OK\r\n\
    Content-Type: text/html\r\n\
    Content-Length: %ld\r\n\r\n";
    static char const * const HTTP_200_FORMAT_WITH_COOKIE = "HTTP/1.1 200 OK\r\n\
    Content-Type: text/html\r\n\
    Set-Cookie: id=%s\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 char *user1_name = "";
    static int user1_start = 0;
    char user1_guesses[100][100];
    int user1_guess_number = 0;
    
    static int user2 = -1;
    static char *user2_name = "";
    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;