]> git.mxchange.org Git - flightgear.git/blob - 3rdparty/mongoose/mongoose.h
Canvas: generate keypress event for text input.
[flightgear.git] / 3rdparty / mongoose / mongoose.h
1 // Copyright (c) 2004-2013 Sergey Lyubka <valenok@gmail.com>\r
2 // Copyright (c) 2013-2014 Cesanta Software Limited\r
3 // All rights reserved\r
4 //\r
5 // This library is dual-licensed: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License version 2 as\r
7 // published by the Free Software Foundation. For the terms of this\r
8 // license, see <http://www.gnu.org/licenses/>.\r
9 //\r
10 // You are free to use this library under the terms of the GNU General\r
11 // Public License, but WITHOUT ANY WARRANTY; without even the implied\r
12 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
13 // See the GNU General Public License for more details.\r
14 //\r
15 // Alternatively, you can license this library under a commercial\r
16 // license, as set out in <http://cesanta.com/>.\r
17 //\r
18 // NOTE: Detailed API documentation is at http://cesanta.com/#docs\r
19 \r
20 #ifndef MONGOOSE_HEADER_INCLUDED\r
21 #define  MONGOOSE_HEADER_INCLUDED\r
22 \r
23 #define MONGOOSE_VERSION "5.3"\r
24 \r
25 #include <stdio.h>      // required for FILE\r
26 #include <stddef.h>     // required for size_t\r
27 \r
28 #ifdef __cplusplus\r
29 extern "C" {\r
30 #endif // __cplusplus\r
31 \r
32 // This structure contains information about HTTP request.\r
33 struct mg_connection {\r
34   const char *request_method; // "GET", "POST", etc\r
35   const char *uri;            // URL-decoded URI\r
36   const char *http_version;   // E.g. "1.0", "1.1"\r
37   const char *query_string;   // URL part after '?', not including '?', or NULL\r
38 \r
39   char remote_ip[48];         // Max IPv6 string length is 45 characters\r
40   const char *local_ip;       // Local IP address\r
41   unsigned short remote_port; // Client's port\r
42   unsigned short local_port;  // Local port number\r
43 \r
44   int num_headers;            // Number of HTTP headers\r
45   struct mg_header {\r
46     const char *name;         // HTTP header name\r
47     const char *value;        // HTTP header value\r
48   } http_headers[30];\r
49 \r
50   char *content;              // POST (or websocket message) data, or NULL\r
51   size_t content_len;       // content length\r
52 \r
53   int is_websocket;           // Connection is a websocket connection\r
54   int status_code;            // HTTP status code for HTTP error handler\r
55   int wsbits;                 // First byte of the websocket frame\r
56   void *server_param;         // Parameter passed to mg_add_uri_handler()\r
57   void *connection_param;     // Placeholder for connection-specific data\r
58 };\r
59 \r
60 struct mg_server; // Opaque structure describing server instance\r
61 enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };\r
62 enum mg_event {\r
63   MG_POLL = 100,  // Callback return value is ignored\r
64   MG_CONNECT,     // If callback returns MG_FALSE, connect fails\r
65   MG_AUTH,        // If callback returns MG_FALSE, authentication fails\r
66   MG_REQUEST,     // If callback returns MG_FALSE, Mongoose continues with req\r
67   MG_REPLY,       // If callback returns MG_FALSE, Mongoose closes connection\r
68   MG_CLOSE,       // Connection is closed\r
69   MG_LUA,         // Called before LSP page invoked\r
70   MG_HTTP_ERROR   // If callback returns MG_FALSE, Mongoose continues with err\r
71 };\r
72 typedef int (*mg_handler_t)(struct mg_connection *, enum mg_event);\r
73 \r
74 // Server management functions\r
75 struct mg_server *mg_create_server(void *server_param, mg_handler_t handler);\r
76 void mg_destroy_server(struct mg_server **);\r
77 const char *mg_set_option(struct mg_server *, const char *opt, const char *val);\r
78 int mg_poll_server(struct mg_server *, int milliseconds);\r
79 const char **mg_get_valid_option_names(void);\r
80 const char *mg_get_option(const struct mg_server *server, const char *name);\r
81 void mg_set_listening_socket(struct mg_server *, int sock);\r
82 int mg_get_listening_socket(struct mg_server *);\r
83 void mg_iterate_over_connections(struct mg_server *, mg_handler_t);\r
84 void mg_wakeup_server(struct mg_server *);\r
85 struct mg_connection *mg_connect(struct mg_server *, const char *, int, int);\r
86 \r
87 // Connection management functions\r
88 void mg_send_status(struct mg_connection *, int status_code);\r
89 void mg_send_header(struct mg_connection *, const char *name, const char *val);\r
90 void mg_send_data(struct mg_connection *, const void *data, int data_len);\r
91 void mg_printf_data(struct mg_connection *, const char *format, ...);\r
92 \r
93 int mg_websocket_write(struct mg_connection *, int opcode,\r
94                        const char *data, size_t data_len);\r
95 \r
96 // Deprecated in favor of mg_send_* interface\r
97 int mg_write(struct mg_connection *, const void *buf, int len);\r
98 int mg_printf(struct mg_connection *conn, const char *fmt, ...);\r
99 \r
100 const char *mg_get_header(const struct mg_connection *, const char *name);\r
101 const char *mg_get_mime_type(const char *name, const char *default_mime_type);\r
102 int mg_get_var(const struct mg_connection *conn, const char *var_name,\r
103                char *buf, size_t buf_len);\r
104 int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t);\r
105 int mg_parse_multipart(const char *buf, int buf_len,\r
106                        char *var_name, int var_name_len,\r
107                        char *file_name, int file_name_len,\r
108                        const char **data, int *data_len);\r
109 \r
110 // Utility functions\r
111 void *mg_start_thread(void *(*func)(void *), void *param);\r
112 char *mg_md5(char buf[33], ...);\r
113 int mg_authorize_digest(struct mg_connection *c, FILE *fp);\r
114 \r
115 // Lua utility functions\r
116 #ifdef MONGOOSE_USE_LUA\r
117 #include <lua.h>\r
118 #include <lauxlib.h>\r
119 void reg_string(lua_State *L, const char *name, const char *val);\r
120 void reg_int(lua_State *L, const char *name, int val);\r
121 void reg_function(lua_State *L, const char *,\r
122                          lua_CFunction, struct mg_connection *);\r
123 #endif\r
124 \r
125 #ifdef __cplusplus\r
126 }\r
127 #endif // __cplusplus\r
128 \r
129 #endif // MONGOOSE_HEADER_INCLUDED\r