#ifndef _TIP_CORE_H #define _TIP_CORE_H #include #include "list.h" #include #include #define TIP_MSG_REQUEST_MAXLEN 131072 extern const char *root; #define DEFAULT_MAX_CLIENTS 3 extern int max_clients; extern int num_clients; extern bool redirect; /* max_client logic only applies for files larger than 1024 bytes. */ #define FILE_SIZE_THRESHOLD 1024ULL enum tip_client_state { TIP_CLIENT_PENDING = 0, TIP_CLIENT_RECEIVING_HEADER, TIP_CLIENT_RECEIVING_PAYLOAD, TIP_CLIENT_PROCESSING_REQUEST, TIP_CLIENT_PROCESSING_REQUEST_2, TIP_CLIENT_PROCESSING_REQUEST_3, }; struct tip_client { struct list_head list; struct ev_io io; struct ev_timer timer; struct sockaddr_in addr; enum tip_client_state state; char buf[TIP_MSG_REQUEST_MAXLEN]; unsigned int buf_len; unsigned int msg_len; int content_length; char auth_token[64]; /* for file serving. */ const char *uri; const char *path; off_t size; int fd; off_t offset; /* for redirection. */ bool redirect; struct sockaddr_in redirect_addr; bool allow_redirect; }; static inline int tip_client_socket(const struct tip_client *cli) { return cli->io.fd; } void tip_client_pending(struct tip_client *cli); bool tip_client_redirect(struct tip_client *cli); extern struct ev_loop *tip_main_loop; int tip_socket_server_init(const char *port); void tip_server_accept_cb(struct ev_loop *loop, struct ev_io *io, int events); int tip_client_state_process_payload(struct tip_client *cli); int tip_client_state_process_payload_reply(struct tip_client *cli); int tip_client_state_process_payload_bulk(struct tip_client *cli); enum tip_http_method { TIP_METHOD_GET = 0, TIP_METHOD_POST, TIP_METHOD_NO_HTTP }; struct tip_client_redirect { struct list_head list; struct sockaddr_in addr; const char *uri; struct ev_timer timer; }; #endif