Skip to content
Snippets Groups Projects
Select Git revision
  • 0b7200f97e02e338395af0c8cf1bfe77c5c1830f
  • master default protected
2 results

http-server.c

Blame
  • http-server.c 16.51 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();
    void check_win(int user, char *keyword);
    char *substring(char *string, int position, int length);
    void insert_substring(char *a, char *b, int position);
    
    // 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;
    char user1_current_guesses[10100];
    char user2_current_guesses[10100];
    
    int gameover = 0;
    
    static char *webpage;
    
    // represents the types of method
    typedef enum
    {