#ifndef SERVER_CODE_ETUDIANT_H #define SERVER_CODE_ETUDIANT_H #include #include #define MAX_CLIENTS 100 #define NAME_MAX_LENGTH 32 /* Client structure */ typedef struct { struct sockaddr_in addr; /* Client remote address */ FILE *client_conn; /* Connection file handle */ int uid; /* Client unique identifier */ char name[NAME_MAX_LENGTH]; /* Client name */ pid_t pid; /* PID of the client */ int fd; /* Client file descriptor */ } client_t; /* number of connected clients */ extern int cli_count; #define HT_SIZE 16 struct bucket { char key[NAME_MAX_LENGTH]; client_t value; struct bucket* next; }; struct hash_table { struct bucket *buckets[HT_SIZE]; int nb_entries; }; /* Calcule le hash d'une cle. La valeur retournee est un entier entre 0 et 15. */ int ht_hash(char key[NAME_MAX_LENGTH]); /* Retourne un double representant la date actuelle. */ void ht_get_clock(double *date); /* Alloue et initialise un struct bucket */ struct bucket* ht_alloc(char key[NAME_MAX_LENGTH], client_t* value); /* Retourne le struct bucket dont la cle vaut key. Retroune NULL si la cle n'est pas trouvee. */ struct bucket* ht_search(char key[NAME_MAX_LENGTH]); /* Insere un couple dans la hashtable. * Si la cle key existe deja, sa valeur est mise a jour. */ void ht_insert(char key[NAME_MAX_LENGTH], client_t* value); /* Supprime le struct bucket dont la cle vaut key */ void ht_remove(char key[NAME_MAX_LENGTH]); /* Enregistre la liste des utilisateurs dans le fichier filename */ void ht_dump(char* filename); /* Envoie a client la liste des utilisateurs contenue dans le fichier filename */ void ht_load(client_t* client, char* filename); /* initialize stuff */ void server_init(); /* finalize stuff */ void server_finalize(int signo); /* return the connected client whose fd is fd */ client_t *get_client_from_fd(int fd); /* add a client to the list of connected clients */ void queue_add(client_t *cl); /* remove a client from the list of connected clients */ void queue_delete(client_t *cl); /* Send a message to a client */ void send_message(char *s, client_t *client); /* send a message to all clients */ void send_message_all(char *s); /* Send message to sender */ //void send_message_self(const char *s, FILE* client_conn); /* Send message to client */ void send_message_client(char *s, int uid); /* Send list of active clients */ void send_active_clients(client_t*client); /* initiate a connexion */ void say_hello(client_t *cli); /* process an incoming message from a client */ void handle_incoming_cmd(client_t *cli); #endif /* SERVER_CODE_ETUDIANT_H */