22 #ifndef CIVETWEB_HEADER_INCLUDED
23 #define CIVETWEB_HEADER_INCLUDED
25 #ifndef CIVETWEB_VERSION
26 #define CIVETWEB_VERSION "1.6"
41 struct mg_request_info {
42 const char *request_method;
44 const char *http_version;
45 const char *query_string;
47 const char *remote_user;
73 int (*begin_request)(
struct mg_connection *);
76 void (*end_request)(
const struct mg_connection *,
int reply_status_code);
80 int (*log_message)(
const struct mg_connection *,
const char *message);
83 int (*init_ssl)(
void *ssl_context,
void *user_data);
88 int (*websocket_connect)(
const struct mg_connection *);
92 void (*websocket_ready)(
struct mg_connection *);
102 int (*websocket_data)(
struct mg_connection *,
int bits,
103 char *data,
size_t data_len);
109 void (*connection_close)(
struct mg_connection *);
121 const char * (*open_file)(
const struct mg_connection *,
122 const char *path,
size_t *data_len);
128 void (*init_lua)(
struct mg_connection *,
void *lua_context);
134 void (*upload)(
struct mg_connection *,
const char *file_name);
140 int (*http_error)(
struct mg_connection *,
int status);
168 struct mg_context *mg_start(
const struct mg_callbacks *callbacks,
170 const char **configuration_options);
178 void mg_stop(
struct mg_context *);
191 typedef int (* mg_request_handler)(
struct mg_connection *conn,
void *cbdata);
209 void mg_set_request_handler(
struct mg_context *ctx,
const char *uri, mg_request_handler handler,
void *cbdata);
218 const char *mg_get_option(
const struct mg_context *ctx,
const char *name);
225 const char **mg_get_valid_option_names(
void);
234 size_t mg_get_ports(
const struct mg_context *ctx,
size_t size,
int* ports,
int* ssl);
248 int mg_modify_passwords_file(
const char *passwords_file_name,
251 const char *password);
255 struct mg_request_info *mg_get_request_info(
struct mg_connection *);
263 int mg_write(
struct mg_connection *,
const void *buf,
size_t len);
278 int mg_websocket_write(
struct mg_connection* conn,
int opcode,
279 const char *data,
size_t data_len);
286 void mg_lock(
struct mg_connection* conn);
287 void mg_unlock(
struct mg_connection* conn);
291 WEBSOCKET_OPCODE_CONTINUATION = 0x0,
292 WEBSOCKET_OPCODE_TEXT = 0x1,
293 WEBSOCKET_OPCODE_BINARY = 0x2,
294 WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
295 WEBSOCKET_OPCODE_PING = 0x9,
296 WEBSOCKET_OPCODE_PONG = 0xa
301 #undef PRINTF_FORMAT_STRING
302 #if defined(_MSC_VER) && _MSC_VER >= 1400
304 #if defined(_MSC_VER) && _MSC_VER > 1400
305 #define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
307 #define PRINTF_FORMAT_STRING(s) __format_string s
310 #define PRINTF_FORMAT_STRING(s) s
314 #define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
316 #define PRINTF_ARGS(x, y)
322 int mg_printf(
struct mg_connection *,
323 PRINTF_FORMAT_STRING(
const char *fmt), ...) PRINTF_ARGS(2, 3);
327 void mg_send_file(struct mg_connection *conn, const
char *path);
335 int mg_read(struct mg_connection *,
void *buf,
size_t len);
343 const
char *mg_get_header(const struct mg_connection *, const
char *name);
365 int mg_get_var(const
char *data,
size_t data_len,
366 const
char *var_name,
char *dst,
size_t dst_len);
391 int mg_get_var2(const
char *data,
size_t data_len,
392 const
char *var_name,
char *dst,
size_t dst_len,
size_t occurrence);
407 int mg_get_cookie(const
char *cookie, const
char *var_name,
408 char *buf,
size_t buf_len);
426 struct mg_connection *mg_download(const
char *host,
int port,
int use_ssl,
427 char *error_buffer,
size_t error_buffer_size,
428 PRINTF_FORMAT_STRING(const
char *request_fmt),
429 ...) PRINTF_ARGS(6, 7);
433 void mg_close_connection(struct mg_connection *conn);
439 int mg_upload(struct mg_connection *conn, const
char *destination_dir);
444 typedef
void * (*mg_thread_func_t)(
void *);
445 int mg_start_thread(mg_thread_func_t f,
void *p);
450 const
char *mg_get_builtin_mime_type(const
char *file_name);
454 const
char *mg_version(
void);
462 int mg_url_decode(const
char *src,
int src_len,
char *dst,
463 int dst_len,
int is_form_url_encoded);
468 int mg_url_encode(const
char *src,
char *dst,
size_t dst_len);
476 char *mg_md5(
char buf[33], ...);
486 void mg_cry(struct mg_connection *conn,
487 PRINTF_FORMAT_STRING(const
char *fmt), ...) PRINTF_ARGS(2, 3);
490 int mg_strncasecmp(const
char *s1, const
char *s2,
size_t len);