// // parser.h // mcc@exe // // Created by Finn Behrens on 19.02.21. // #ifndef parser_h #define parser_h #include #include #include #include #include "protocol.h" #include "package.h" /** * A struct for client specific data. * * @field fd of the client * * @field bufferevent ev-buffer to write data to * * @field compression_threshold when to start compressing packages * * @field state protocoll state of the client * * @field user the user associated to the client * * TODO: add crypto and compression parsing */ typedef struct { /* The clients socket. */ int fd; /* The bufferedevent for this client. */ struct bufferevent *buf_ev; /* negative means no compression */ int compression_threshold; enum mc_state state; mc_play_user_t *user; // TODO: encrpytion } client_t; int parse_packet(client_t *client, uint8_t *buffer); static inline void mc_close_user(client_t *client) { bufferevent_free(client->buf_ev); close(client->fd); if (client->user != NULL) free(client->user); free(client); } struct mc_package_op { int (*doit) (client_t *client, mc_package_header_t *header); int cmd; enum mc_direction direction; enum mc_state state; }; #endif /* parser_h */