00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MONGOOSE_HEADER_INCLUDED
00019 #define MONGOOSE_HEADER_INCLUDED
00020
00021 #define MONGOOSE_VERSION "5.6"
00022
00023 #include <stdio.h>
00024 #include <stddef.h>
00025 #include <sys/types.h>
00026
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif // __cplusplus
00030
00031
00032 struct mg_connection {
00033 const char *request_method;
00034 const char *uri;
00035 const char *http_version;
00036 const char *query_string;
00037
00038 char remote_ip[48];
00039 char local_ip[48];
00040 unsigned short remote_port;
00041 unsigned short local_port;
00042
00043 int num_headers;
00044 struct mg_header {
00045 const char *name;
00046 const char *value;
00047 } http_headers[30];
00048
00049 char *content;
00050 size_t content_len;
00051
00052 int is_websocket;
00053 int status_code;
00054 int wsbits;
00055 void *server_param;
00056 void *connection_param;
00057 void *callback_param;
00058 };
00059
00060 struct mg_server;
00061 enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };
00062 enum mg_event {
00063 MG_POLL = 100,
00064 MG_CONNECT,
00065 MG_AUTH,
00066 MG_REQUEST,
00067 MG_REPLY,
00068 MG_RECV,
00069
00070
00071 MG_CLOSE,
00072 MG_WS_HANDSHAKE,
00073 MG_WS_CONNECT,
00074 MG_HTTP_ERROR
00075 };
00076 typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);
00077
00078
00079 enum {
00080 WEBSOCKET_OPCODE_CONTINUATION = 0x0,
00081 WEBSOCKET_OPCODE_TEXT = 0x1,
00082 WEBSOCKET_OPCODE_BINARY = 0x2,
00083 WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
00084 WEBSOCKET_OPCODE_PING = 0x9,
00085 WEBSOCKET_OPCODE_PONG = 0xa
00086 };
00087
00088
00089 struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);
00090 void mg_destroy_server(struct mg_server **);
00091 const char *mg_set_option(struct mg_server *, const char *opt, const char *val);
00092 time_t mg_poll_server(struct mg_server *, int milliseconds);
00093 const char **mg_get_valid_option_names(void);
00094 const char *mg_get_option(const struct mg_server *server, const char *name);
00095 void mg_copy_listeners(struct mg_server *from, struct mg_server *to);
00096 struct mg_connection *mg_next(struct mg_server *, struct mg_connection *);
00097 void mg_wakeup_server(struct mg_server *);
00098 void mg_wakeup_server_ex(struct mg_server *, mg_handler_t, const char *, ...);
00099 struct mg_connection *mg_connect(struct mg_server *, const char *);
00100
00101
00102 void mg_send_status(struct mg_connection *, int status_code);
00103 void mg_send_header(struct mg_connection *, const char *name, const char *val);
00104 size_t mg_send_data(struct mg_connection *, const void *data, int data_len);
00105 size_t mg_printf_data(struct mg_connection *, const char *format, ...);
00106 size_t mg_write(struct mg_connection *, const void *buf, size_t len);
00107 size_t mg_printf(struct mg_connection *conn, const char *fmt, ...);
00108
00109 size_t mg_websocket_write(struct mg_connection *, int opcode,
00110 const char *data, size_t data_len);
00111 size_t mg_websocket_printf(struct mg_connection* conn, int opcode,
00112 const char *fmt, ...);
00113
00114 void mg_send_file(struct mg_connection *, const char *path, const char *);
00115 void mg_send_file_data(struct mg_connection *, int fd);
00116
00117 const char *mg_get_header(const struct mg_connection *, const char *name);
00118 const char *mg_get_mime_type(const char *name, const char *default_mime_type);
00119 int mg_get_var(const struct mg_connection *conn, const char *var_name,
00120 char *buf, size_t buf_len);
00121 int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);
00122 int mg_parse_multipart(const char *buf, int buf_len,
00123 char *var_name, int var_name_len,
00124 char *file_name, int file_name_len,
00125 const char **data, int *data_len);
00126
00127
00128
00129 void *mg_start_thread(void *(*func)(void *), void *param);
00130 char *mg_md5(char buf[33], ...);
00131 int mg_authorize_digest(struct mg_connection *c, FILE *fp);
00132 size_t mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len);
00133 int mg_url_decode(const char *src, size_t src_len, char *dst, size_t dst_len, int);
00134 int mg_terminate_ssl(struct mg_connection *c, const char *cert);
00135 int mg_forward(struct mg_connection *c, const char *addr);
00136 void *mg_mmap(FILE *fp, size_t size);
00137 void mg_munmap(void *p, size_t size);
00138
00139
00140
00141 struct mg_expansion {
00142 const char *keyword;
00143 void (*handler)(struct mg_connection *);
00144 };
00145 void mg_template(struct mg_connection *, const char *text,
00146 struct mg_expansion *expansions);
00147
00148 #ifdef __cplusplus
00149 }
00150 #endif // __cplusplus
00151
00152 #endif // MONGOOSE_HEADER_INCLUDED