#pragma once #include #include "global.h" #define net_set_push_callback tomsg__net_set_push_callback #define net_set_history_callback tomsg__net_set_history_callback #define net_sendf tomsg__net_sendf #define net_handle_recv tomsg__net_handle_recv enum net_response_type{ NET_OK, // - NET_NUMBER, // number NET_ERROR, // error NET_NAME, // name NET_LIST, // nitems, items NET_PONG, // - NET_MESSAGE, // room, username, timestamp, msgid, replyid, message NET_HISTORY, // room, username, timestamp, msgid, replyid, message NET_JOIN, // room, username NET_INVITE, // room, username NET_LEAVE, // room, username NET_ONLINE, // online.username, online.num }; struct net_response{ enum net_response_type type; union { i64 number; char *error; char *name; struct { int nitems; char **items; }; struct { char *room; char *username; i64 timestamp; i64 msgid; i64 replyid; char *message; }; struct { char *username; i64 num; } online; }; }; typedef void net_callback_t(int fd,struct net_response res,void *payload); void net_set_push_callback(net_callback_t *callback); void net_set_history_callback(net_callback_t *callback); bool net_sendf(int fd,net_callback_t *callback,void *payload,const char *format,...) __attribute__((format (printf, 4, 5))); void net_handle_recv(int fd,const char *msg);