Debian Codegraph @

src/include/mongoose.h

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