NVIDIA DeepStream SDK API Reference

7.0 Release
civetweb.h
Go to the documentation of this file.
1 /* Copyright (c) 2013-2021 the Civetweb developers
2  * Copyright (c) 2004-2013 Sergey Lyubka
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef CIVETWEB_HEADER_INCLUDED
24 #define CIVETWEB_HEADER_INCLUDED
25 
26 #define CIVETWEB_VERSION "1.16"
27 #define CIVETWEB_VERSION_MAJOR (1)
28 #define CIVETWEB_VERSION_MINOR (16)
29 #define CIVETWEB_VERSION_PATCH (0)
30 
31 #ifndef CIVETWEB_API
32 #if defined(_WIN32)
33 #if defined(CIVETWEB_DLL_EXPORTS)
34 #define CIVETWEB_API __declspec(dllexport)
35 #elif defined(CIVETWEB_DLL_IMPORTS)
36 #define CIVETWEB_API __declspec(dllimport)
37 #else
38 #define CIVETWEB_API
39 #endif
40 #elif __GNUC__ >= 4
41 #define CIVETWEB_API __attribute__((visibility("default")))
42 #else
43 #define CIVETWEB_API
44 #endif
45 #endif
46 
47 #include <stddef.h>
48 #include <stdio.h>
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif /* __cplusplus */
53 
54 
55 /* Init Features */
56 enum {
58 
59  /* Support files from local directories */
60  /* Will only work, if NO_FILES is not set. */
62 
63  /* Support transport layer security (TLS). */
64  /* SSL is still often used synonymously for TLS. */
65  /* Will only work, if NO_SSL is not set. */
68 
69  /* Support common gateway interface (CGI). */
70  /* Will only work, if NO_CGI is not set. */
72 
73  /* Support IPv6. */
74  /* Will only work, if USE_IPV6 is set. */
76 
77  /* Support WebSocket protocol. */
78  /* Will only work, if USE_WEBSOCKET is set. */
80 
81  /* Support server side Lua scripting. */
82  /* Will only work, if USE_LUA is set. */
83  MG_FEATURES_LUA = 0x20u,
84 
85  /* Support server side JavaScript scripting. */
86  /* Will only work, if USE_DUKTAPE is set. */
88 
89  /* Provide data required for caching files. */
90  /* Will only work, if NO_CACHING is not set. */
92 
93  /* Collect server status information. */
94  /* Will only work, if USE_SERVER_STATS is set. */
96 
97  /* Support on-the-fly compression. */
98  /* Will only work, if USE_ZLIB is set. */
100 
101  /* HTTP/2 support enabled. */
103 
104  /* Support unix domain sockets. */
106 
107  /* Bit mask for all feature defines. */
108  MG_FEATURES_ALL = 0xFFFFu
109 };
110 
111 
112 /* Initialize this library. This should be called once before any other
113  * function from this library. This function is not guaranteed to be
114  * thread safe.
115  * Parameters:
116  * features: bit mask for features to be initialized.
117  * Note: The TLS libraries (like OpenSSL) is initialized
118  * only if the MG_FEATURES_TLS bit is set.
119  * Currently the other bits do not influence
120  * initialization, but this may change in future
121  * versions.
122  * Return value:
123  * initialized features
124  * 0: error
125  */
126 CIVETWEB_API unsigned mg_init_library(unsigned features);
127 
128 
129 /* Un-initialize this library.
130  * Return value:
131  * 0: error
132  */
133 CIVETWEB_API unsigned mg_exit_library(void);
134 
135 
136 struct mg_context; /* Handle for the HTTP service itself */
137 struct mg_connection; /* Handle for the individual connection */
138 
139 
140 /* Maximum number of headers */
141 #define MG_MAX_HEADERS (64)
142 
143 struct mg_header {
144  const char *name; /* HTTP header name */
145  const char *value; /* HTTP header value */
146 };
147 
148 
149 /* This structure contains information about the HTTP request. */
151  const char *request_method; /* "GET", "POST", etc */
152  const char *request_uri; /* URL-decoded URI (absolute or relative,
153  * as in the request) */
154  const char *local_uri_raw; /* URL-decoded URI (relative). Can be NULL
155  * if the request_uri does not address a
156  * resource at the server host. */
157  const char *local_uri; /* Same as local_uri_raw, however, cleaned
158  * so a path like
159  * allowed_dir/../forbidden_file
160  * is not possible. */
161  const char *http_version; /* E.g. "1.0", "1.1" */
162  const char *query_string; /* URL part after '?', not including '?', or
163  NULL */
164  const char *remote_user; /* Authenticated user, or NULL if no auth
165  used */
166  char remote_addr[48]; /* Client's IP address as a string. */
167 
168  long long content_length; /* Length (in bytes) of the request body,
169  can be -1 if no length was given. */
170  int remote_port; /* Port at client side */
171  int server_port; /* Port at server side (one of the listening
172  ports) */
173  int is_ssl; /* 1 if HTTPS or WS is used (SSL/TLS used),
174  0 if not */
175  void *user_data; /* User data pointer passed to mg_start() */
176  void *conn_data; /* Connection-specific user data */
177 
178  int num_headers; /* Number of HTTP headers */
179  struct mg_header
180  http_headers[MG_MAX_HEADERS]; /* Allocate maximum headers */
181 
182  struct mg_client_cert *client_cert; /* Client certificate information */
183 
184  const char *acceptedWebSocketSubprotocol; /* websocket subprotocol,
185  * accepted during handshake */
186 };
187 
188 
189 /* This structure contains information about the HTTP request. */
190 /* This structure may be extended in future versions. */
192  int status_code; /* E.g. 200 */
193  const char *status_text; /* E.g. "OK" */
194  const char *http_version; /* E.g. "1.0", "1.1" */
195 
196  long long content_length; /* Length (in bytes) of the request body,
197  can be -1 if no length was given. */
198 
199  int num_headers; /* Number of HTTP headers */
200  struct mg_header
201  http_headers[MG_MAX_HEADERS]; /* Allocate maximum headers */
202 };
203 
204 
205 /* Client certificate information (part of mg_request_info) */
207  void *peer_cert;
208  const char *subject;
209  const char *issuer;
210  const char *serial;
211  const char *finger;
212 };
213 
214 
215 /* This structure needs to be passed to mg_start(), to let civetweb know
216  which callbacks to invoke. For a detailed description, see
217  https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md */
218 struct mg_callbacks {
219  /* Called when civetweb has received new HTTP request.
220  If the callback returns one, it must process the request
221  by sending valid HTTP headers and a body. Civetweb will not do
222  any further processing. Otherwise it must return zero.
223  Note that since V1.7 the "begin_request" function is called
224  before an authorization check. If an authorization check is
225  required, use a request_handler instead.
226  Return value:
227  0: civetweb will process the request itself. In this case,
228  the callback must not send any data to the client.
229  1-999: callback already processed the request. Civetweb will
230  not send any data after the callback returned. The
231  return code is stored as a HTTP status code for the
232  access log. */
233  int (*begin_request)(struct mg_connection *);
234 
235  /* Called when civetweb has finished processing request. */
236  void (*end_request)(const struct mg_connection *, int reply_status_code);
237 
238  /* Called when civetweb is about to log a message. If callback returns
239  non-zero, civetweb does not log anything. */
240  int (*log_message)(const struct mg_connection *, const char *message);
241 
242  /* Called when civetweb is about to log access. If callback returns
243  non-zero, civetweb does not log anything. */
244  int (*log_access)(const struct mg_connection *, const char *message);
245 
246  /* Called when civetweb initializes SSL library.
247  Parameters:
248  ssl_ctx: SSL_CTX pointer.
249  user_data: parameter user_data passed when starting the server.
250  Return value:
251  0: civetweb will set up the SSL certificate.
252  1: civetweb assumes the callback already set up the certificate.
253  -1: initializing ssl fails. */
254  int (*init_ssl)(void *ssl_ctx, void *user_data);
255 
256  /* Called when civetweb initializes SSL library for a domain.
257  Parameters:
258  server_domain: authentication_domain from the domain config.
259  ssl_ctx: SSL_CTX pointer.
260  user_data: parameter user_data passed when starting the server.
261  Return value:
262  0: civetweb will set up the SSL certificate.
263  1: civetweb assumes the callback already set up the certificate.
264  -1: initializing ssl fails. */
265  int (*init_ssl_domain)(const char *server_domain,
266  void *ssl_ctx,
267  void *user_data);
268 
269  /* Called when civetweb is about to create or free a SSL_CTX.
270  Parameters:
271  ssl_ctx: SSL_CTX pointer. NULL at creation time, Not NULL when
272  mg_context will be freed user_data: parameter user_data passed when starting
273  the server. Return value: 0: civetweb will continue to create the context,
274  just as if the callback would not be present. The value in *ssl_ctx when the
275  function returns is ignored. 1: civetweb will copy the value from *ssl_ctx
276  to the civetweb context and doesn't create its own. -1: initializing ssl
277  fails.*/
278  int (*external_ssl_ctx)(void **ssl_ctx, void *user_data);
279 
280  /* Called when civetweb is about to create or free a SSL_CTX for a domain.
281  Parameters:
282  server_domain: authentication_domain from the domain config.
283  ssl_ctx: SSL_CTX pointer. NULL at creation time, Not NULL when
284  mg_context will be freed user_data: parameter user_data passed when starting
285  the server. Return value: 0: civetweb will continue to create the context,
286  just as if the callback would not be present. The value in *ssl_ctx when the
287  function returns is ignored. 1: civetweb will copy the value from *ssl_ctx
288  to the civetweb context and doesn't create its own. -1: initializing ssl
289  fails.*/
290  int (*external_ssl_ctx_domain)(const char *server_domain,
291  void **ssl_ctx,
292  void *user_data);
293 
294 #if defined(MG_EXPERIMENTAL_INTERFACES) /* 2019-11-03 */
295  /* Called when data frame has been received from the peer.
296  Parameters:
297  bits: first byte of the websocket frame, see websocket RFC at
298  http://tools.ietf.org/html/rfc6455, section 5.2
299  data, data_len: payload, with mask (if any) already applied.
300  Return value:
301  1: keep this websocket connection open.
302  0: close this websocket connection.
303  This callback is deprecated: Use mg_set_websocket_handler instead. */
304  int (*websocket_data)(struct mg_connection *,
305  int bits,
306  char *data,
307  size_t data_len);
308 #endif /* MG_LEGACY_INTERFACE */
309 
310  /* Called when civetweb is closing a connection. The per-context mutex is
311  locked when this is invoked.
312 
313  Websockets:
314  Before mg_set_websocket_handler has been added, it was primarily useful
315  for noting when a websocket is closing, and used to remove it from any
316  application-maintained list of clients.
317  Using this callback for websocket connections is deprecated: Use
318  mg_set_websocket_handler instead.
319  */
320  void (*connection_close)(const struct mg_connection *);
321 
322  /* Called after civetweb has closed a connection. The per-context mutex is
323  locked when this is invoked.
324 
325  Connection specific data:
326  If memory has been allocated for the connection specific user data
327  (mg_request_info->conn_data, mg_get_user_connection_data),
328  this is the last chance to free it.
329  */
330  void (*connection_closed)(const struct mg_connection *);
331 
332 
333  /* init_lua is called when civetweb is about to serve Lua server page.
334  exit_lua is called when the Lua processing is complete.
335  Both will work only if Lua support is enabled.
336  Parameters:
337  conn: current connection.
338  lua_context: "lua_State *" pointer.
339  context_flags: context type information as bitmask:
340  context_flags & 0x0F: (0-15) Lua environment type
341  */
342  void (*init_lua)(const struct mg_connection *conn,
343  void *lua_context,
344  unsigned context_flags);
345  void (*exit_lua)(const struct mg_connection *conn,
346  void *lua_context,
347  unsigned context_flags);
348 
349 
350  /* Called when civetweb is about to send HTTP error to the client.
351  Implementing this callback allows to create custom error pages.
352  Parameters:
353  conn: current connection.
354  status: HTTP error status code.
355  errmsg: error message text.
356  Return value:
357  1: run civetweb error handler.
358  0: callback already handled the error. */
359  int (*http_error)(struct mg_connection *conn,
360  int status,
361  const char *errmsg);
362 
363  /* Called after civetweb context has been created, before requests
364  are processed.
365  Parameters:
366  ctx: context handle */
367  void (*init_context)(const struct mg_context *ctx);
368 
369  /* Called when civetweb context is deleted.
370  Parameters:
371  ctx: context handle */
372  void (*exit_context)(const struct mg_context *ctx);
373 
374  /* Called when a new worker thread is initialized.
375  * It is always called from the newly created thread and can be used to
376  * initialize thread local storage data.
377  * Parameters:
378  * ctx: context handle
379  * thread_type:
380  * 0 indicates the master thread
381  * 1 indicates a worker thread handling client connections
382  * 2 indicates an internal helper thread (timer thread)
383  * Return value:
384  * This function returns a user supplied pointer. The pointer is assigned
385  * to the thread and can be obtained from the mg_connection object using
386  * mg_get_thread_pointer in all server callbacks. Note: A connection and
387  * a thread are not directly related. Threads will serve several different
388  * connections, and data from a single connection may call different
389  * callbacks using different threads. The thread pointer can be obtained
390  * in a callback handler, but should not be stored beyond the scope of
391  * one call to one callback.
392  */
393  void *(*init_thread)(const struct mg_context *ctx, int thread_type);
394 
395  /* Called when a worker exits.
396  * The parameters "ctx" and "thread_type" correspond to the "init_thread"
397  * call. The "thread_pointer" parameter is the value returned by
398  * "init_thread".
399  */
400  void (*exit_thread)(const struct mg_context *ctx,
401  int thread_type,
402  void *thread_pointer);
403 
404  /* Called when initializing a new connection object.
405  * Can be used to initialize the connection specific user data
406  * (mg_request_info->conn_data, mg_get_user_connection_data).
407  * When the callback is called, it is not yet known if a
408  * valid HTTP(S) request will be made.
409  * Parameters:
410  * conn: not yet fully initialized connection object
411  * conn_data: output parameter, set to initialize the
412  * connection specific user data
413  * Return value:
414  * must be 0
415  * Otherwise, the result is undefined
416  */
417  int (*init_connection)(const struct mg_connection *conn, void **conn_data);
418 };
419 
420 
421 /* Start web server.
422 
423  Parameters:
424  callbacks: mg_callbacks structure with user-defined callbacks.
425  options: NULL terminated list of option_name, option_value pairs that
426  specify Civetweb configuration parameters.
427 
428  Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
429  processing is required for these, signal handlers must be set up
430  after calling mg_start().
431 
432 
433  Example:
434  const char *options[] = {
435  "document_root", "/var/www",
436  "listening_ports", "80,443s",
437  NULL
438  };
439  struct mg_context *ctx = mg_start(&my_func, NULL, options);
440 
441  Refer to https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
442  for the list of valid option and their possible values.
443 
444  Return:
445  web server context, or NULL on error. */
446 CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
447  void *user_data,
448  const char **configuration_options);
449 
450 
451 /* Stop the web server.
452 
453  Must be called last, when an application wants to stop the web server and
454  release all associated resources. This function blocks until all Civetweb
455  threads are stopped. Context pointer becomes invalid. */
456 CIVETWEB_API void mg_stop(struct mg_context *);
457 
458 
459 /* Add an additional domain to an already running web server.
460  *
461  * Parameters:
462  * ctx: Context handle of a server started by mg_start.
463  * options: NULL terminated list of option_name, option_value pairs that
464  * specify CivetWeb configuration parameters.
465  *
466  * Return:
467  * < 0 in case of an error
468  * -1 for a parameter error
469  * -2 invalid options
470  * -3 initializing SSL failed
471  * -4 mandatory domain option missing
472  * -5 duplicate domain
473  * -6 out of memory
474  * > 0 index / handle of a new domain
475  */
476 CIVETWEB_API int mg_start_domain(struct mg_context *ctx,
477  const char **configuration_options);
478 
479 
480 /* mg_request_handler
481 
482  Called when a new request comes in. This callback is URI based
483  and configured with mg_set_request_handler().
484 
485  Parameters:
486  conn: current connection information.
487  cbdata: the callback data configured with mg_set_request_handler().
488  Returns:
489  0: the handler could not handle the request, so fall through.
490  1 - 999: the handler processed the request. The return code is
491  stored as a HTTP status code for the access log. */
492 typedef int (*mg_request_handler)(struct mg_connection *conn, void *cbdata);
493 
494 
495 /* mg_set_request_handler
496 
497  Sets or removes a URI mapping for a request handler.
498  This function waits until a removing/updating handler becomes unused, so
499  do not call from the handler itself.
500 
501  URI's are ordered and prefixed URI's are supported. For example,
502  consider two URIs: /a/b and /a
503  /a matches /a
504  /a/b matches /a/b
505  /a/c matches /a
506 
507  Parameters:
508  ctx: server context
509  uri: the URI (exact or pattern) for the handler
510  handler: the callback handler to use when the URI is requested.
511  If NULL, an already registered handler for this URI will
512  be removed.
513  The URI used to remove a handler must match exactly the
514  one used to register it (not only a pattern match).
515  cbdata: the callback data to give to the handler when it is called. */
516 CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx,
517  const char *uri,
518  mg_request_handler handler,
519  void *cbdata);
520 
521 
522 /* Callback types for websocket handlers in C/C++.
523 
524  mg_websocket_connect_handler
525  Is called when the client intends to establish a websocket connection,
526  before websocket handshake.
527  Return value:
528  0: civetweb proceeds with websocket handshake.
529  1: connection is closed immediately.
530 
531  mg_websocket_ready_handler
532  Is called when websocket handshake is successfully completed, and
533  connection is ready for data exchange.
534 
535  mg_websocket_data_handler
536  Is called when a data frame has been received from the client.
537  Parameters:
538  bits: first byte of the websocket frame, see websocket RFC at
539  http://tools.ietf.org/html/rfc6455, section 5.2
540  data, data_len: payload, with mask (if any) already applied.
541  Return value:
542  1: keep this websocket connection open.
543  0: close this websocket connection.
544 
545  mg_connection_close_handler
546  Is called, when the connection is closed.*/
547 typedef int (*mg_websocket_connect_handler)(const struct mg_connection *,
548  void *);
549 typedef void (*mg_websocket_ready_handler)(struct mg_connection *, void *);
550 typedef int (*mg_websocket_data_handler)(struct mg_connection *,
551  int,
552  char *,
553  size_t,
554  void *);
555 typedef void (*mg_websocket_close_handler)(const struct mg_connection *,
556  void *);
557 
558 /* struct mg_websocket_subprotocols
559  *
560  * List of accepted subprotocols
561  */
564  const char **subprotocols;
565 };
566 
567 /* mg_set_websocket_handler
568 
569  Set or remove handler functions for websocket connections.
570  This function works similar to mg_set_request_handler - see there. */
571 CIVETWEB_API void
572 mg_set_websocket_handler(struct mg_context *ctx,
573  const char *uri,
574  mg_websocket_connect_handler connect_handler,
575  mg_websocket_ready_handler ready_handler,
576  mg_websocket_data_handler data_handler,
577  mg_websocket_close_handler close_handler,
578  void *cbdata);
579 
580 /* mg_set_websocket_handler
581 
582  Set or remove handler functions for websocket connections.
583  This function works similar to mg_set_request_handler - see there. */
585  struct mg_context *ctx,
586  const char *uri,
587  struct mg_websocket_subprotocols *subprotocols,
588  mg_websocket_connect_handler connect_handler,
589  mg_websocket_ready_handler ready_handler,
590  mg_websocket_data_handler data_handler,
591  mg_websocket_close_handler close_handler,
592  void *cbdata);
593 
594 
595 /* mg_authorization_handler
596 
597  Callback function definition for mg_set_auth_handler
598 
599  Parameters:
600  conn: current connection information.
601  cbdata: the callback data configured with mg_set_request_handler().
602  Returns:
603  0: access denied
604  1: access granted
605  */
606 typedef int (*mg_authorization_handler)(struct mg_connection *conn,
607  void *cbdata);
608 
609 
610 /* mg_set_auth_handler
611 
612  Sets or removes a URI mapping for an authorization handler.
613  This function works similar to mg_set_request_handler - see there. */
614 CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx,
615  const char *uri,
616  mg_authorization_handler handler,
617  void *cbdata);
618 
619 
620 /* Get the value of particular configuration parameter.
621  The value returned is read-only. Civetweb does not allow changing
622  configuration at run time.
623  If given parameter name is not valid, NULL is returned. For valid
624  names, return value is guaranteed to be non-NULL. If parameter is not
625  set, zero-length string is returned. */
626 CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx,
627  const char *name);
628 
629 
630 /* Get context from connection. */
631 CIVETWEB_API struct mg_context *
632 mg_get_context(const struct mg_connection *conn);
633 
634 
635 /* Get user data passed to mg_start from context. */
636 CIVETWEB_API void *mg_get_user_data(const struct mg_context *ctx);
637 
638 
639 /* Get user data passed to mg_start from connection. */
640 CIVETWEB_API void *mg_get_user_context_data(const struct mg_connection *conn);
641 
642 
643 /* Get user defined thread pointer for server threads (see init_thread). */
644 CIVETWEB_API void *mg_get_thread_pointer(const struct mg_connection *conn);
645 
646 
647 /* Set user data for the current connection. */
648 /* Note: CivetWeb callbacks use "struct mg_connection *conn" as input
649  when mg_read/mg_write callbacks are allowed in the callback,
650  while "const struct mg_connection *conn" is used as input in case
651  calling mg_read/mg_write is not allowed.
652  Setting the user connection data will modify the connection
653  object represented by mg_connection *, but it will not read from
654  or write to the connection. */
655 /* Note: An alternative is to use the init_connection callback
656  instead to initialize the user connection data pointer. It is
657  reccomended to supply a pointer to some user defined data structure
658  as conn_data initializer in init_connection. In case it is required
659  to change some data after the init_connection call, store another
660  data pointer in the user defined data structure and modify that
661  pointer. In either case, after the init_connection callback, only
662  calls to mg_get_user_connection_data should be required. */
663 CIVETWEB_API void mg_set_user_connection_data(const struct mg_connection *conn,
664  void *data);
665 
666 
667 /* Get user data set for the current connection. */
668 CIVETWEB_API void *
669 mg_get_user_connection_data(const struct mg_connection *conn);
670 
671 
672 /* Get a formatted link corresponding to the current request
673 
674  Parameters:
675  conn: current connection information.
676  buf: string buffer (out)
677  buflen: length of the string buffer
678  Returns:
679  <0: error
680  >=0: ok */
681 CIVETWEB_API int
682 mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen);
683 
684 
685 struct mg_option {
686  const char *name;
687  int type;
688  const char *default_value;
689 };
690 
691 
692 /* Configuration types */
693 enum {
704 };
705 
706 /* Return array of struct mg_option, representing all valid configuration
707  options of civetweb.c.
708  The array is terminated by a NULL name option. */
709 CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
710 
711 
713  int protocol; /* 1 = IPv4, 2 = IPv6, 3 = both */
714  int port; /* port number */
715  int is_ssl; /* https port: 0 = no, 1 = yes */
716  int is_redirect; /* redirect all requests: 0 = no, 1 = yes */
721 };
722 
723 /* Legacy name */
724 #define mg_server_ports mg_server_port
725 
726 
727 /* Get the list of ports that civetweb is listening on.
728  The parameter size is the size of the ports array in elements.
729  The caller is responsibility to allocate the required memory.
730  This function returns the number of struct mg_server_port elements
731  filled in, or <0 in case of an error. */
732 CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx,
733  int size,
734  struct mg_server_port *ports);
735 
736 
737 /* Add, edit or delete the entry in the passwords file.
738  *
739  * This function allows an application to manipulate .htpasswd files on the
740  * fly by adding, deleting and changing user records. This is one of the
741  * several ways of implementing authentication on the server side. For another,
742  * cookie-based way please refer to the examples/chat in the source tree.
743  *
744  * Parameter:
745  * passwords_file_name: Path and name of a file storing multiple passwords
746  * realm: HTTP authentication realm (authentication domain) name
747  * user: User name
748  * password:
749  * If password is not NULL, entry modified or added.
750  * If password is NULL, entry is deleted.
751  *
752  * Return:
753  * 1 on success, 0 on error.
754  */
755 CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
756  const char *realm,
757  const char *user,
758  const char *password);
759 
760 
761 /* Same as mg_modify_passwords_file, but instead of the plain-text
762  * password, the HA1 hash is specified. The plain-text password is
763  * not made known to civetweb.
764  *
765  * The HA1 hash is the MD5 checksum of a "user:realm:password" string
766  * in lower-case hex format. For example, if the user name is "myuser",
767  * the realm is "myrealm", and the password is "secret", then the HA1 is
768  * e67fd3248b58975c3e89ff18ecb75e2f.
769  */
770 CIVETWEB_API int mg_modify_passwords_file_ha1(const char *passwords_file_name,
771  const char *realm,
772  const char *user,
773  const char *ha1);
774 
775 
776 /* Return information associated with the request.
777  * Use this function to implement a server and get data about a request
778  * from a HTTP/HTTPS client.
779  * Note: Before CivetWeb 1.10, this function could be used to read
780  * a response from a server, when implementing a client, although the
781  * values were never returned in appropriate mg_request_info elements.
782  * It is strongly advised to use mg_get_response_info for clients.
783  */
784 CIVETWEB_API const struct mg_request_info *
785 mg_get_request_info(const struct mg_connection *);
786 
787 
788 /* Return information associated with a HTTP/HTTPS response.
789  * Use this function in a client, to check the response from
790  * the server. */
791 CIVETWEB_API const struct mg_response_info *
792 mg_get_response_info(const struct mg_connection *);
793 
794 
795 /* Send data to the client.
796  Return:
797  0 when the connection has been closed
798  -1 on error
799  >0 number of bytes written on success */
800 CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
801 
802 
803 /* Send data to a websocket client wrapped in a websocket frame. Uses
804  mg_lock_connection to ensure that the transmission is not interrupted,
805  i.e., when the application is proactively communicating and responding to
806  a request simultaneously.
807 
808  Send data to a websocket client wrapped in a websocket frame.
809  This function is available when civetweb is compiled with -DUSE_WEBSOCKET
810 
811  Return:
812  0 when the connection has been closed
813  -1 on error
814  >0 number of bytes written on success */
815 CIVETWEB_API int mg_websocket_write(struct mg_connection *conn,
816  int opcode,
817  const char *data,
818  size_t data_len);
819 
820 
821 /* Send data to a websocket server wrapped in a masked websocket frame. Uses
822  mg_lock_connection to ensure that the transmission is not interrupted,
823  i.e., when the application is proactively communicating and responding to
824  a request simultaneously.
825 
826  Send data to a websocket server wrapped in a masked websocket frame.
827  This function is available when civetweb is compiled with -DUSE_WEBSOCKET
828 
829  Return:
830  0 when the connection has been closed
831  -1 on error
832  >0 number of bytes written on success */
833 CIVETWEB_API int mg_websocket_client_write(struct mg_connection *conn,
834  int opcode,
835  const char *data,
836  size_t data_len);
837 
838 
839 /* Blocks until unique access is obtained to this connection. Intended for use
840  with websockets only.
841  Invoke this before mg_write or mg_printf when communicating with a
842  websocket if your code has server-initiated communication as well as
843  communication in direct response to a message.
844  Do not acquire this lock while holding mg_lock_context(). */
845 CIVETWEB_API void mg_lock_connection(struct mg_connection *conn);
846 CIVETWEB_API void mg_unlock_connection(struct mg_connection *conn);
847 
848 
849 /* Lock server context. This lock may be used to protect resources
850  that are shared between different connection/worker threads.
851  If the given context is not server, these functions do nothing. */
852 CIVETWEB_API void mg_lock_context(struct mg_context *ctx);
853 CIVETWEB_API void mg_unlock_context(struct mg_context *ctx);
854 
855 
856 /* WebSocket OpcCodes, from http://tools.ietf.org/html/rfc6455 */
857 enum {
864 };
865 
866 
867 /* Macros for enabling compiler-specific checks for printf-like arguments. */
868 #undef PRINTF_FORMAT_STRING
869 #if defined(_MSC_VER) && _MSC_VER >= 1400
870 #include <sal.h>
871 #if defined(_MSC_VER) && _MSC_VER > 1400
872 #define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
873 #else
874 #define PRINTF_FORMAT_STRING(s) __format_string s
875 #endif
876 #else
877 #define PRINTF_FORMAT_STRING(s) s
878 #endif
879 
880 #ifdef __GNUC__
881 #define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
882 #else
883 #define PRINTF_ARGS(x, y)
884 #endif
885 
886 
887 /* Send data to the client using printf() semantics.
888  Works exactly like mg_write(), but allows to do message formatting. */
889 CIVETWEB_API int mg_printf(struct mg_connection *,
890  PRINTF_FORMAT_STRING(const char *fmt),
891  ...) PRINTF_ARGS(2, 3);
892 
893 
894 /* Send a part of the message body, if chunked transfer encoding is set.
895  * Only use this function after sending a complete HTTP request or response
896  * header with "Transfer-Encoding: chunked" set. */
897 CIVETWEB_API int mg_send_chunk(struct mg_connection *conn,
898  const char *chunk,
899  unsigned int chunk_len);
900 
901 
902 /* Send contents of the entire file together with HTTP headers.
903  * Parameters:
904  * conn: Current connection information.
905  * path: Full path to the file to send.
906  * This function has been superseded by mg_send_mime_file
907  */
908 CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
909 
910 
911 /* Send contents of the file without HTTP headers.
912  * The code must send a valid HTTP response header before using this function.
913  *
914  * Parameters:
915  * conn: Current connection information.
916  * path: Full path to the file to send.
917  *
918  * Return:
919  * < 0 Error
920  */
921 CIVETWEB_API int mg_send_file_body(struct mg_connection *conn,
922  const char *path);
923 
924 
925 /* Send HTTP error reply. */
926 CIVETWEB_API int mg_send_http_error(struct mg_connection *conn,
927  int status_code,
928  PRINTF_FORMAT_STRING(const char *fmt),
929  ...) PRINTF_ARGS(3, 4);
930 
931 
932 /* Send "HTTP 200 OK" response header.
933  * After calling this function, use mg_write or mg_send_chunk to send the
934  * response body.
935  * Parameters:
936  * conn: Current connection handle.
937  * mime_type: Set Content-Type for the following content.
938  * content_length: Size of the following content, if content_length >= 0.
939  * Will set transfer-encoding to chunked, if set to -1.
940  * Return:
941  * < 0 Error
942  */
943 CIVETWEB_API int mg_send_http_ok(struct mg_connection *conn,
944  const char *mime_type,
945  long long content_length);
946 
947 
948 /* Send "HTTP 30x" redirect response.
949  * The response has content-size zero: do not send any body data after calling
950  * this function.
951  * Parameters:
952  * conn: Current connection handle.
953  * target_url: New location.
954  * redirect_code: HTTP redirect type. Could be 301, 302, 303, 307, 308.
955  * Return:
956  * < 0 Error (-1 send error, -2 parameter error)
957  */
958 CIVETWEB_API int mg_send_http_redirect(struct mg_connection *conn,
959  const char *target_url,
960  int redirect_code);
961 
962 
963 /* Send HTTP digest access authentication request.
964  * Browsers will send a user name and password in their next request, showing
965  * an authentication dialog if the password is not stored.
966  * Parameters:
967  * conn: Current connection handle.
968  * realm: Authentication realm. If NULL is supplied, the sever domain
969  * set in the authentication_domain configuration is used.
970  * Return:
971  * < 0 Error
972  */
973 CIVETWEB_API int
974 mg_send_digest_access_authentication_request(struct mg_connection *conn,
975  const char *realm);
976 
977 
978 /* Check if the current request has a valid authentication token set.
979  * A file is used to provide a list of valid user names, realms and
980  * password hashes. The file can be created and modified using the
981  * mg_modify_passwords_file API function.
982  * Parameters:
983  * conn: Current connection handle.
984  * realm: Authentication realm. If NULL is supplied, the sever domain
985  * set in the authentication_domain configuration is used.
986  * filename: Path and name of a file storing multiple password hashes.
987  * Return:
988  * > 0 Valid authentication
989  * 0 Invalid authentication
990  * < 0 Error (all values < 0 should be considered as invalid
991  * authentication, future error codes will have negative
992  * numbers)
993  * -1 Parameter error
994  * -2 File not found
995  */
996 CIVETWEB_API int
997 mg_check_digest_access_authentication(struct mg_connection *conn,
998  const char *realm,
999  const char *filename);
1000 
1001 
1002 /* Send contents of the entire file together with HTTP headers.
1003  * Parameters:
1004  * conn: Current connection handle.
1005  * path: Full path to the file to send.
1006  * mime_type: Content-Type for file. NULL will cause the type to be
1007  * looked up by the file extension.
1008  */
1009 CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn,
1010  const char *path,
1011  const char *mime_type);
1012 
1013 
1014 /* Send contents of the entire file together with HTTP headers.
1015  Parameters:
1016  conn: Current connection information.
1017  path: Full path to the file to send.
1018  mime_type: Content-Type for file. NULL will cause the type to be
1019  looked up by the file extension.
1020  additional_headers: Additional custom header fields appended to the header.
1021  Each header should start with an X-, to ensure it is
1022  not included twice.
1023  NULL does not append anything.
1024 */
1025 CIVETWEB_API void mg_send_mime_file2(struct mg_connection *conn,
1026  const char *path,
1027  const char *mime_type,
1028  const char *additional_headers);
1029 
1030 
1031 /* Store body data into a file. */
1032 CIVETWEB_API long long mg_store_body(struct mg_connection *conn,
1033  const char *path);
1034 /* Read entire request body and store it in a file "path".
1035  Return:
1036  < 0 Error
1037  >= 0 Number of bytes stored in file "path".
1038 */
1039 
1040 
1041 /* Read data from the remote end, return number of bytes read.
1042  Return:
1043  0 connection has been closed by peer. No more data could be read.
1044  < 0 read error. No more data could be read from the connection.
1045  > 0 number of bytes read into the buffer. */
1046 CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
1047 
1048 
1049 /* Get the value of particular HTTP header.
1050 
1051  This is a helper function. It traverses request_info->http_headers array,
1052  and if the header is present in the array, returns its value. If it is
1053  not present, NULL is returned. */
1054 CIVETWEB_API const char *mg_get_header(const struct mg_connection *,
1055  const char *name);
1056 
1057 
1058 /* Get a value of particular form variable.
1059 
1060  Parameters:
1061  data: pointer to form-uri-encoded buffer. This could be either POST data,
1062  or request_info.query_string.
1063  data_len: length of the encoded data.
1064  var_name: variable name to decode from the buffer
1065  dst: destination buffer for the decoded variable
1066  dst_len: length of the destination buffer
1067 
1068  Return:
1069  On success, length of the decoded variable.
1070  On error:
1071  -1 (variable not found).
1072  -2 (destination buffer is NULL, zero length or too small to hold the
1073  decoded variable).
1074 
1075  Destination buffer is guaranteed to be '\0' - terminated if it is not
1076  NULL or zero length. */
1077 CIVETWEB_API int mg_get_var(const char *data,
1078  size_t data_len,
1079  const char *var_name,
1080  char *dst,
1081  size_t dst_len);
1082 
1083 
1084 /* Get a value of particular form variable.
1085 
1086  Parameters:
1087  data: pointer to form-uri-encoded buffer. This could be either POST data,
1088  or request_info.query_string.
1089  data_len: length of the encoded data.
1090  var_name: variable name to decode from the buffer
1091  dst: destination buffer for the decoded variable
1092  dst_len: length of the destination buffer
1093  occurrence: which occurrence of the variable, 0 is the 1st, 1 the 2nd, ...
1094  this makes it possible to parse a query like
1095  b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
1096 
1097  Return:
1098  On success, length of the decoded variable.
1099  On error:
1100  -1 (variable not found).
1101  -2 (destination buffer is NULL, zero length or too small to hold the
1102  decoded variable).
1103 
1104  Destination buffer is guaranteed to be '\0' - terminated if it is not
1105  NULL or zero length. */
1106 CIVETWEB_API int mg_get_var2(const char *data,
1107  size_t data_len,
1108  const char *var_name,
1109  char *dst,
1110  size_t dst_len,
1111  size_t occurrence);
1112 
1113 
1114 /* Split form encoded data into a list of key value pairs.
1115  A form encoded input might be a query string, the body of a
1116  x-www-form-urlencoded POST request or any other data with this
1117  structure: "keyName1=value1&keyName2=value2&keyName3=value3".
1118  Values might be percent-encoded - this function will transform
1119  them to the unencoded characters.
1120  The input string is modified by this function: To split the
1121  "query_string" member of struct request_info, create a copy first
1122  (e.g., using strdup).
1123  The function itself does not allocate memory. Thus, it is not
1124  required to free any pointer returned from this function.
1125  The output list of is limited to MG_MAX_FORM_FIELDS name-value-
1126  pairs. The default value is reasonably oversized for typical
1127  applications, however, for special purpose systems it might be
1128  required to increase this value at compile time.
1129 
1130  Parameters:
1131  data: form encoded iput string. Will be modified by this function.
1132  form_fields: output list of name/value-pairs. A buffer with a size
1133  specified by num_form_fields must be provided by the
1134  caller.
1135  num_form_fields: Size of provided form_fields buffer in number of
1136  "struct mg_header" elements.
1137 
1138  Return:
1139  On success: number of form_fields filled
1140  On error:
1141  -1 (parameter error). */
1142 CIVETWEB_API int mg_split_form_urlencoded(char *data,
1143  struct mg_header *form_fields,
1144  unsigned num_form_fields);
1145 
1146 
1147 /* Fetch value of certain cookie variable into the destination buffer.
1148 
1149  Destination buffer is guaranteed to be '\0' - terminated. In case of
1150  failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
1151  parameter. This function returns only first occurrence.
1152 
1153  Return:
1154  On success, value length.
1155  On error:
1156  -1 (either "Cookie:" header is not present at all or the requested
1157  parameter is not found).
1158  -2 (destination buffer is NULL, zero length or too small to hold the
1159  value). */
1160 CIVETWEB_API int mg_get_cookie(const char *cookie,
1161  const char *var_name,
1162  char *buf,
1163  size_t buf_len);
1164 
1165 
1166 /* Download data from the remote web server.
1167  host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
1168  port: port number, e.g. 80.
1169  use_ssl: whether to use SSL connection.
1170  error_buffer, error_buffer_size: error message placeholder.
1171  request_fmt,...: HTTP request.
1172  Return:
1173  On success, valid pointer to the new connection, suitable for mg_read().
1174  On error, NULL. error_buffer contains error message.
1175  Example:
1176  char ebuf[100];
1177  struct mg_connection *conn;
1178  conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
1179  "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
1180 
1181  mg_download is equivalent to calling mg_connect_client followed by
1182  mg_printf and mg_get_response. Using these three functions directly may
1183  allow more control as compared to using mg_download.
1184  */
1185 CIVETWEB_API struct mg_connection *
1186 mg_download(const char *host,
1187  int port,
1188  int use_ssl,
1189  char *error_buffer,
1190  size_t error_buffer_size,
1191  PRINTF_FORMAT_STRING(const char *request_fmt),
1192  ...) PRINTF_ARGS(6, 7);
1193 
1194 
1195 /* Close the connection opened by mg_download(). */
1196 CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
1197 
1198 
1199 /* This structure contains callback functions for handling form fields.
1200  It is used as an argument to mg_handle_form_request. */
1202  /* This callback function is called, if a new field has been found.
1203  * The return value of this callback is used to define how the field
1204  * should be processed.
1205  *
1206  * Parameters:
1207  * key: Name of the field ("name" property of the HTML input field).
1208  * filename: Name of a file to upload, at the client computer.
1209  * Only set for input fields of type "file", otherwise NULL.
1210  * path: Output parameter: File name (incl. path) to store the file
1211  * at the server computer. Only used if FORM_FIELD_STORAGE_STORE
1212  * is returned by this callback. Existing files will be
1213  * overwritten.
1214  * pathlen: Length of the buffer for path.
1215  * user_data: Value of the member user_data of mg_form_data_handler
1216  *
1217  * Return value:
1218  * The callback must return the intended storage for this field
1219  * (See FORM_FIELD_STORAGE_*).
1220  */
1221  int (*field_found)(const char *key,
1222  const char *filename,
1223  char *path,
1224  size_t pathlen,
1225  void *user_data);
1226 
1227  /* If the "field_found" callback returned FORM_FIELD_STORAGE_GET,
1228  * this callback will receive the field data.
1229  *
1230  * Parameters:
1231  * key: Name of the field ("name" property of the HTML input field).
1232  * value: Value of the input field.
1233  * user_data: Value of the member user_data of mg_form_data_handler
1234  *
1235  * Return value:
1236  * The return code determines how the server should continue processing
1237  * the current request (See MG_FORM_FIELD_HANDLE_*).
1238  */
1239  int (*field_get)(const char *key,
1240  const char *value,
1241  size_t valuelen,
1242  void *user_data);
1243 
1244  /* If the "field_found" callback returned FORM_FIELD_STORAGE_STORE,
1245  * the data will be stored into a file. If the file has been written
1246  * successfully, this callback will be called. This callback will
1247  * not be called for only partially uploaded files. The
1248  * mg_handle_form_request function will either store the file completely
1249  * and call this callback, or it will remove any partial content and
1250  * not call this callback function.
1251  *
1252  * Parameters:
1253  * path: Path of the file stored at the server.
1254  * file_size: Size of the stored file in bytes.
1255  * user_data: Value of the member user_data of mg_form_data_handler
1256  *
1257  * Return value:
1258  * The return code determines how the server should continue processing
1259  * the current request (See MG_FORM_FIELD_HANDLE_*).
1260  */
1261  int (*field_store)(const char *path, long long file_size, void *user_data);
1262 
1263  /* User supplied argument, passed to all callback functions. */
1264  void *user_data;
1265 };
1266 
1267 
1268 /* Return values definition for the "field_found" callback in
1269  * mg_form_data_handler. */
1270 enum {
1271  /* Skip this field (neither get nor store it). Continue with the
1272  * next field. */
1274  /* Get the field value. */
1276  /* Store the field value into a file. */
1278  /* Stop parsing this request. Skip the remaining fields. */
1280 };
1281 
1282 /* Return values for "field_get" and "field_store" */
1283 enum {
1284  /* Only "field_get": If there is more data in this field, get the next
1285  * chunk. Otherwise: handle the next field. */
1287  /* Handle the next field */
1289  /* Stop parsing this request */
1291 };
1292 
1293 
1294 /* Process form data.
1295  * Returns the number of fields handled, or < 0 in case of an error.
1296  * Note: It is possible that several fields are already handled successfully
1297  * (e.g., stored into files), before the request handling is stopped with an
1298  * error. In this case a number < 0 is returned as well.
1299  * In any case, it is the duty of the caller to remove files once they are
1300  * no longer required. */
1301 CIVETWEB_API int mg_handle_form_request(struct mg_connection *conn,
1302  struct mg_form_data_handler *fdh);
1303 
1304 
1305 /* Convenience function -- create detached thread.
1306  Return: 0 on success, non-0 on error. */
1307 typedef void *(*mg_thread_func_t)(void *);
1309 
1310 
1311 /* Return builtin mime type for the given file name.
1312  For unrecognized extensions, "text/plain" is returned. */
1313 CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
1314 
1315 
1316 /* Get text representation of HTTP status code. */
1317 CIVETWEB_API const char *
1318 mg_get_response_code_text(const struct mg_connection *conn, int response_code);
1319 
1320 
1321 /* Return CivetWeb version. */
1322 CIVETWEB_API const char *mg_version(void);
1323 
1324 
1325 /* URL-decode input buffer into destination buffer.
1326  0-terminate the destination buffer.
1327  form-url-encoded data differs from URI encoding in a way that it
1328  uses '+' as character for space, see RFC 1866 section 8.2.1
1329  http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
1330  Return: length of the decoded data, or -1 if dst buffer is too small. */
1331 CIVETWEB_API int mg_url_decode(const char *src,
1332  int src_len,
1333  char *dst,
1334  int dst_len,
1335  int is_form_url_encoded);
1336 
1337 
1338 /* URL-encode input buffer into destination buffer.
1339  returns the length of the resulting buffer or -1
1340  is the buffer is too small. */
1341 CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
1342 
1343 
1344 /* BASE64-encode input buffer into destination buffer.
1345  returns -1 on OK. */
1346 CIVETWEB_API int mg_base64_encode(const unsigned char *src,
1347  size_t src_len,
1348  char *dst,
1349  size_t *dst_len);
1350 
1351 
1352 /* BASE64-decode input buffer into destination buffer.
1353  returns -1 on OK. */
1354 CIVETWEB_API int mg_base64_decode(const char *src,
1355  size_t src_len,
1356  unsigned char *dst,
1357  size_t *dst_len);
1358 
1359 
1360 /* MD5 hash given strings.
1361  Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
1362  ASCIIz strings. When function returns, buf will contain human-readable
1363  MD5 hash. Example:
1364  char buf[33];
1365  mg_md5(buf, "aa", "bb", NULL); */
1366 CIVETWEB_API char *mg_md5(char buf[33], ...);
1367 
1368 
1369 #if !defined(MG_MATCH_CONTEXT_MAX_MATCHES)
1370 #define MG_MATCH_CONTEXT_MAX_MATCHES (32)
1371 #endif
1372 
1374  const char *str; /* First character matching wildcard */
1375  size_t len; /* Number of character matching wildcard */
1376 };
1377 
1379  int case_sensitive; /* Input: 1 (case sensitive) or 0 (insensitive) */
1380  size_t num_matches; /* Output: Number of wildcard matches returned. */
1382 };
1383 
1384 
1385 #if defined(MG_EXPERIMENTAL_INTERFACES)
1386 /* Pattern matching and extraction function.
1387  Parameters:
1388  pat: Pattern string (see UserManual.md)
1389  str: String to search for match patterns.
1390  mcx: Match context (optional, can be NULL).
1391 
1392  Return:
1393  Number of characters matched.
1394  -1 if no valid match was found.
1395  Note: 0 characters might be a valid match for some patterns.
1396 */
1397 CIVETWEB_API ptrdiff_t mg_match(const char *pat,
1398  const char *str,
1399  struct mg_match_context *mcx);
1400 #endif
1401 
1402 
1403 /* Print error message to the opened error log stream.
1404  This utilizes the provided logging configuration.
1405  conn: connection (not used for sending data, but to get perameters)
1406  fmt: format string without the line return
1407  ...: variable argument list
1408  Example:
1409  mg_cry(conn,"i like %s", "logging"); */
1410 CIVETWEB_API void mg_cry(const struct mg_connection *conn,
1411  PRINTF_FORMAT_STRING(const char *fmt),
1412  ...) PRINTF_ARGS(2, 3);
1413 
1414 
1415 /* utility methods to compare two buffers, case insensitive. */
1416 CIVETWEB_API int mg_strcasecmp(const char *s1, const char *s2);
1417 CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
1418 
1419 
1420 /* Connect to a websocket as a client
1421  Parameters:
1422  host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or
1423  "localhost"
1424  port: server port
1425  use_ssl: make a secure connection to server
1426  error_buffer, error_buffer_size: buffer for an error message
1427  path: server path you are trying to connect to, i.e. if connection to
1428  localhost/app, path should be "/app"
1429  origin: value of the Origin HTTP header
1430  data_func: callback that should be used when data is received from the
1431  server
1432  user_data: user supplied argument
1433 
1434  Return:
1435  On success, valid mg_connection object.
1436  On error, NULL. Se error_buffer for details.
1437 */
1438 CIVETWEB_API struct mg_connection *
1439 mg_connect_websocket_client(const char *host,
1440  int port,
1441  int use_ssl,
1442  char *error_buffer,
1443  size_t error_buffer_size,
1444  const char *path,
1445  const char *origin,
1446  mg_websocket_data_handler data_func,
1447  mg_websocket_close_handler close_func,
1448  void *user_data);
1449 
1450 CIVETWEB_API struct mg_connection *
1452  int port,
1453  int use_ssl,
1454  char *error_buffer,
1455  size_t error_buffer_size,
1456  const char *path,
1457  const char *origin,
1458  const char *extensions,
1459  mg_websocket_data_handler data_func,
1460  mg_websocket_close_handler close_func,
1461  void *user_data);
1462 
1463 
1464 /* Connect to a TCP server as a client (can be used to connect to a HTTP server)
1465  Parameters:
1466  host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or
1467  "localhost"
1468  port: server port
1469  use_ssl: make a secure connection to server
1470  error_buffer, error_buffer_size: buffer for an error message
1471 
1472  Return:
1473  On success, valid mg_connection object.
1474  On error, NULL. Se error_buffer for details.
1475 */
1476 CIVETWEB_API struct mg_connection *mg_connect_client(const char *host,
1477  int port,
1478  int use_ssl,
1479  char *error_buffer,
1480  size_t error_buffer_size);
1481 
1482 
1484  const char *host;
1485  int port;
1486  const char *client_cert;
1487  const char *server_cert;
1488  const char *host_name;
1489  /* TODO: add more data */
1490 };
1491 
1492 
1493 CIVETWEB_API struct mg_connection *
1494 mg_connect_client_secure(const struct mg_client_options *client_options,
1495  char *error_buffer,
1496  size_t error_buffer_size);
1497 
1498 
1499 CIVETWEB_API struct mg_connection *mg_connect_websocket_client_secure(
1500  const struct mg_client_options *client_options,
1501  char *error_buffer,
1502  size_t error_buffer_size,
1503  const char *path,
1504  const char *origin,
1505  mg_websocket_data_handler data_func,
1506  mg_websocket_close_handler close_func,
1507  void *user_data);
1508 
1509 CIVETWEB_API struct mg_connection *
1511  const struct mg_client_options *client_options,
1512  char *error_buffer,
1513  size_t error_buffer_size,
1514  const char *path,
1515  const char *origin,
1516  const char *extensions,
1517  mg_websocket_data_handler data_func,
1518  mg_websocket_close_handler close_func,
1519  void *user_data);
1520 
1521 #if defined(MG_LEGACY_INTERFACE) /* 2019-11-02 */
1522 enum { TIMEOUT_INFINITE = -1 };
1523 #endif
1524 enum { MG_TIMEOUT_INFINITE = -1 };
1525 
1526 
1527 /* Wait for a response from the server
1528  Parameters:
1529  conn: connection
1530  ebuf, ebuf_len: error message placeholder.
1531  timeout: time to wait for a response in milliseconds (if < 0 then wait
1532  forever)
1533 
1534  Return:
1535  On success, >= 0
1536  On error/timeout, < 0
1537 */
1538 CIVETWEB_API int mg_get_response(struct mg_connection *conn,
1539  char *ebuf,
1540  size_t ebuf_len,
1541  int timeout);
1542 
1543 
1544 /* mg_response_header_* functions can be used from server callbacks
1545  * to prepare HTTP server response headers. Using this function will
1546  * allow a callback to work with HTTP/1.x and HTTP/2.
1547  */
1548 
1549 /* Initialize a new HTTP response
1550  * Parameters:
1551  * conn: Current connection handle.
1552  * status: HTTP status code (e.g., 200 for "OK").
1553  * Return:
1554  * 0: ok
1555  * -1: parameter error
1556  * -2: invalid connection type
1557  * -3: invalid connection status
1558  * -4: network error (only if built with NO_RESPONSE_BUFFERING)
1559  */
1560 CIVETWEB_API int mg_response_header_start(struct mg_connection *conn,
1561  int status);
1562 
1563 
1564 /* Add a new HTTP response header line
1565  * Parameters:
1566  * conn: Current connection handle.
1567  * header: Header name.
1568  * value: Header value.
1569  * value_len: Length of header value, excluding the terminating zero.
1570  * Use -1 for "strlen(value)".
1571  * Return:
1572  * 0: ok
1573  * -1: parameter error
1574  * -2: invalid connection type
1575  * -3: invalid connection status
1576  * -4: too many headers
1577  * -5: out of memory
1578  */
1579 CIVETWEB_API int mg_response_header_add(struct mg_connection *conn,
1580  const char *header,
1581  const char *value,
1582  int value_len);
1583 
1584 
1585 /* Add a complete header string (key + value).
1586  * This function is less efficient as compared to mg_response_header_add,
1587  * and should only be used to convert complete HTTP/1.x header lines.
1588  * Parameters:
1589  * conn: Current connection handle.
1590  * http1_headers: Header line(s) in the form "name: value\r\n".
1591  * Return:
1592  * >=0: no error, number of header lines added
1593  * -1: parameter error
1594  * -2: invalid connection type
1595  * -3: invalid connection status
1596  * -4: too many headers
1597  * -5: out of memory
1598  */
1599 CIVETWEB_API int mg_response_header_add_lines(struct mg_connection *conn,
1600  const char *http1_headers);
1601 
1602 
1603 /* Send http response
1604  * Parameters:
1605  * conn: Current connection handle.
1606  * Return:
1607  * 0: ok
1608  * -1: parameter error
1609  * -2: invalid connection type
1610  * -3: invalid connection status
1611  * -4: sending failed (network error)
1612  */
1613 CIVETWEB_API int mg_response_header_send(struct mg_connection *conn);
1614 
1615 
1616 /* Check which features where set when the civetweb library has been compiled.
1617  The function explicitly addresses compile time defines used when building
1618  the library - it does not mean, the feature has been initialized using a
1619  mg_init_library call.
1620  mg_check_feature can be called anytime, even before mg_init_library has
1621  been called.
1622 
1623  Parameters:
1624  feature: specifies which feature should be checked
1625  The value is a bit mask. The individual bits are defined as:
1626  1 serve files (NO_FILES not set)
1627  2 support HTTPS (NO_SSL not set)
1628  4 support CGI (NO_CGI not set)
1629  8 support IPv6 (USE_IPV6 set)
1630  16 support WebSocket (USE_WEBSOCKET set)
1631  32 support Lua scripts and Lua server pages (USE_LUA is set)
1632  64 support server side JavaScript (USE_DUKTAPE is set)
1633  128 support caching (NO_CACHING not set)
1634  256 support server statistics (USE_SERVER_STATS is set)
1635  512 support for on the fly compression (USE_ZLIB is set)
1636 
1637  These values are defined as MG_FEATURES_*
1638 
1639  The result is undefined, if bits are set that do not represent a
1640  defined feature (currently: feature >= 1024).
1641  The result is undefined, if no bit is set (feature == 0).
1642 
1643  Return:
1644  If a feature is available, the corresponding bit is set
1645  If a feature is not available, the bit is 0
1646 */
1647 CIVETWEB_API unsigned mg_check_feature(unsigned feature);
1648 
1649 
1650 /* Get information on the system. Useful for support requests.
1651  Parameters:
1652  buffer: Store system information as string here.
1653  buflen: Length of buffer (including a byte required for a terminating 0).
1654  Return:
1655  Available size of system information, exluding a terminating 0.
1656  The information is complete, if the return value is smaller than buflen.
1657  The result is a JSON formatted string, the exact content may vary.
1658  Note:
1659  It is possible to determine the required buflen, by first calling this
1660  function with buffer = NULL and buflen = NULL. The required buflen is
1661  one byte more than the returned value.
1662 */
1663 CIVETWEB_API int mg_get_system_info(char *buffer, int buflen);
1664 
1665 
1666 /* Get context information. Useful for server diagnosis.
1667  Parameters:
1668  ctx: Context handle
1669  buffer: Store context information here.
1670  buflen: Length of buffer (including a byte required for a terminating 0).
1671  Return:
1672  Available size of system information, exluding a terminating 0.
1673  The information is complete, if the return value is smaller than buflen.
1674  The result is a JSON formatted string, the exact content may vary.
1675  Note:
1676  It is possible to determine the required buflen, by first calling this
1677  function with buffer = NULL and buflen = NULL. The required buflen is
1678  one byte more than the returned value. However, since the available
1679  context information changes, you should allocate a few bytes more.
1680 */
1681 CIVETWEB_API int
1682 mg_get_context_info(const struct mg_context *ctx, char *buffer, int buflen);
1683 
1684 
1685 /* Disable HTTP keep-alive on a per-connection basis.
1686  Reference: https://github.com/civetweb/civetweb/issues/727
1687  Parameters:
1688  conn: Current connection handle.
1689 */
1690 CIVETWEB_API void mg_disable_connection_keep_alive(struct mg_connection *conn);
1691 
1692 
1693 #if defined(MG_EXPERIMENTAL_INTERFACES)
1694 /* Get connection information. Useful for server diagnosis.
1695  Parameters:
1696  ctx: Context handle
1697  idx: Connection index
1698  buffer: Store context information here.
1699  buflen: Length of buffer (including a byte required for a terminating 0).
1700  Return:
1701  Available size of system information, exluding a terminating 0.
1702  The information is complete, if the return value is smaller than buflen.
1703  The result is a JSON formatted string, the exact content may vary.
1704  Note:
1705  It is possible to determine the required buflen, by first calling this
1706  function with buffer = NULL and buflen = NULL. The required buflen is
1707  one byte more than the returned value. However, since the available
1708  context information changes, you should allocate a few bytes more.
1709 */
1710 CIVETWEB_API int mg_get_connection_info(const struct mg_context *ctx,
1711  int idx,
1712  char *buffer,
1713  int buflen);
1714 #endif
1715 
1716 
1717 /* New APIs for enhanced option and error handling.
1718  These mg_*2 API functions have the same purpose as their original versions,
1719  but provide additional options and/or provide improved error diagnostics.
1720 
1721  Note: Experimental interfaces may change
1722 */
1724  unsigned code; /* error code (number) */
1725  unsigned code_sub; /* error sub code (number) */
1726  char *text; /* buffer for error text */
1727  size_t text_buffer_size; /* size of buffer of "text" */
1728 };
1729 
1730 
1731 /* Values for error "code" in mg_error_data */
1732 enum {
1733  /* No error */
1735 
1736  /* Caller provided invalid parameter */
1738 
1739  /* "configuration_option" contains invalid element */
1741 
1742  /* Initializen TLS / SSL library failed */
1744 
1745  /* Mandatory "configuration_option" missing */
1747 
1748  /* Duplicate "authentication_domain" option */
1750 
1751  /* Not enough memory */
1753 
1754  /* Server already stopped */
1756 
1757  /* mg_init_library must be called first */
1759 
1760  /* Operating system function failed */
1762 
1763  /* Failed to bind to server ports */
1765 
1766  /* Failed to switch user (option "run_as_user") */
1768 
1769  /* Access Control List error */
1771 
1772  /* Global password file error */
1774 
1775  /* Lua background script init error */
1777 
1778  /* Client: Host not found, invalid IP to connect */
1780 
1781  /* Client: TCP connect timeout */
1783 
1784  /* Client: TCP connect failed */
1786 
1787  /* Error using TLS client certificate */
1789 
1790  /* Error setting trusted TLS server certificate for client connection */
1792 
1793  /* Error establishing TLS connection to HTTPS server */
1795 };
1796 
1797 
1799  const struct mg_callbacks *callbacks; /* callback function pointer */
1800  void *user_data; /* data */
1802 };
1803 
1804 
1805 #if defined(MG_EXPERIMENTAL_INTERFACES)
1806 
1807 CIVETWEB_API struct mg_connection *
1808 mg_connect_client2(const char *host,
1809  const char *protocol,
1810  int port,
1811  const char *path,
1812  struct mg_init_data *init,
1813  struct mg_error_data *error);
1814 
1815 CIVETWEB_API int mg_get_response2(struct mg_connection *conn,
1816  struct mg_error_data *error,
1817  int timeout);
1818 #endif
1819 
1820 
1821 CIVETWEB_API struct mg_context *mg_start2(struct mg_init_data *init,
1822  struct mg_error_data *error);
1823 
1824 CIVETWEB_API int mg_start_domain2(struct mg_context *ctx,
1825  const char **configuration_options,
1826  struct mg_error_data *error);
1827 
1828 
1829 #ifdef __cplusplus
1830 }
1831 #endif /* __cplusplus */
1832 
1833 #endif /* CIVETWEB_HEADER_INCLUDED */
mg_client_cert::issuer
const char * issuer
Definition: civetweb.h:209
mg_lock_context
CIVETWEB_API void mg_lock_context(struct mg_context *ctx)
MG_CONFIG_TYPE_STRING
@ MG_CONFIG_TYPE_STRING
Definition: civetweb.h:696
MG_FEATURES_X_DOMAIN_SOCKET
@ MG_FEATURES_X_DOMAIN_SOCKET
Definition: civetweb.h:105
mg_get_cookie
CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name, char *buf, size_t buf_len)
mg_init_data
Definition: civetweb.h:1798
mg_request_info::client_cert
struct mg_client_cert * client_cert
Definition: civetweb.h:182
MG_FORM_FIELD_STORAGE_SKIP
@ MG_FORM_FIELD_STORAGE_SKIP
Definition: civetweb.h:1273
MG_CONFIG_TYPE_STRING_MULTILINE
@ MG_CONFIG_TYPE_STRING_MULTILINE
Definition: civetweb.h:702
mg_server_port
Definition: civetweb.h:712
mg_response_info
Definition: civetweb.h:191
MG_ERROR_DATA_CODE_SCRIPT_ERROR
@ MG_ERROR_DATA_CODE_SCRIPT_ERROR
Definition: civetweb.h:1776
MG_WEBSOCKET_OPCODE_PONG
@ MG_WEBSOCKET_OPCODE_PONG
Definition: civetweb.h:863
mg_unlock_context
CIVETWEB_API void mg_unlock_context(struct mg_context *ctx)
mg_callbacks::log_message
int(* log_message)(const struct mg_connection *, const char *message)
Definition: civetweb.h:240
mg_lock_connection
CIVETWEB_API void mg_lock_connection(struct mg_connection *conn)
mg_match_context
Definition: civetweb.h:1378
mg_callbacks::log_access
int(* log_access)(const struct mg_connection *, const char *message)
Definition: civetweb.h:244
mg_websocket_client_write
CIVETWEB_API int mg_websocket_client_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
mg_set_auth_handler
CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx, const char *uri, mg_authorization_handler handler, void *cbdata)
mg_server_port::_reserved1
int _reserved1
Definition: civetweb.h:717
mg_callbacks::http_error
int(* http_error)(struct mg_connection *conn, int status, const char *errmsg)
Definition: civetweb.h:359
mg_callbacks::exit_context
void(* exit_context)(const struct mg_context *ctx)
Definition: civetweb.h:372
mg_callbacks::external_ssl_ctx
int(* external_ssl_ctx)(void **ssl_ctx, void *user_data)
Definition: civetweb.h:278
MG_CONFIG_TYPE_FILE
@ MG_CONFIG_TYPE_FILE
Definition: civetweb.h:697
mg_request_info::num_headers
int num_headers
Definition: civetweb.h:178
mg_request_info::local_uri
const char * local_uri
Definition: civetweb.h:157
mg_match_element::len
size_t len
Definition: civetweb.h:1375
mg_option::default_value
const char * default_value
Definition: civetweb.h:688
mg_get_request_link
CIVETWEB_API int mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen)
mg_send_file
CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path)
mg_client_options
Definition: civetweb.h:1483
MG_FORM_FIELD_HANDLE_NEXT
@ MG_FORM_FIELD_HANDLE_NEXT
Definition: civetweb.h:1288
MG_CONFIG_TYPE_BOOLEAN
@ MG_CONFIG_TYPE_BOOLEAN
Definition: civetweb.h:699
mg_init_data::configuration_options
const char ** configuration_options
Definition: civetweb.h:1801
mg_get_request_info
CIVETWEB_API const struct mg_request_info * mg_get_request_info(const struct mg_connection *)
MG_ERROR_DATA_CODE_INVALID_PASS_FILE
@ MG_ERROR_DATA_CODE_INVALID_PASS_FILE
Definition: civetweb.h:1773
mg_set_websocket_handler_with_subprotocols
CIVETWEB_API void mg_set_websocket_handler_with_subprotocols(struct mg_context *ctx, const char *uri, struct mg_websocket_subprotocols *subprotocols, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata)
mg_start_thread
CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p)
MG_MATCH_CONTEXT_MAX_MATCHES
#define MG_MATCH_CONTEXT_MAX_MATCHES
Definition: civetweb.h:1370
mg_server_port::port
int port
Definition: civetweb.h:714
mg_response_info::status_code
int status_code
Definition: civetweb.h:192
MG_WEBSOCKET_OPCODE_TEXT
@ MG_WEBSOCKET_OPCODE_TEXT
Definition: civetweb.h:859
MG_FORM_FIELD_STORAGE_ABORT
@ MG_FORM_FIELD_STORAGE_ABORT
Definition: civetweb.h:1279
mg_request_info::http_headers
struct mg_header http_headers[MG_MAX_HEADERS]
Definition: civetweb.h:179
mg_client_options::host_name
const char * host_name
Definition: civetweb.h:1488
MG_FEATURES_SSL
@ MG_FEATURES_SSL
Definition: civetweb.h:67
mg_client_cert::finger
const char * finger
Definition: civetweb.h:211
mg_client_options::client_cert
const char * client_cert
Definition: civetweb.h:1486
MG_WEBSOCKET_OPCODE_BINARY
@ MG_WEBSOCKET_OPCODE_BINARY
Definition: civetweb.h:860
mg_request_info::conn_data
void * conn_data
Definition: civetweb.h:176
mg_error_data::text_buffer_size
size_t text_buffer_size
Definition: civetweb.h:1727
mg_response_info::num_headers
int num_headers
Definition: civetweb.h:199
mg_callbacks::connection_close
void(* connection_close)(const struct mg_connection *)
Definition: civetweb.h:320
MG_ERROR_DATA_CODE_SERVER_STOPPED
@ MG_ERROR_DATA_CODE_SERVER_STOPPED
Definition: civetweb.h:1755
mg_init_data::callbacks
const struct mg_callbacks * callbacks
Definition: civetweb.h:1799
mg_request_info::http_version
const char * http_version
Definition: civetweb.h:161
mg_get_option
const CIVETWEB_API char * mg_get_option(const struct mg_context *ctx, const char *name)
mg_websocket_subprotocols
Definition: civetweb.h:562
mg_get_system_info
CIVETWEB_API int mg_get_system_info(char *buffer, int buflen)
mg_url_decode
CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
mg_get_user_connection_data
CIVETWEB_API void * mg_get_user_connection_data(const struct mg_connection *conn)
mg_get_user_data
CIVETWEB_API void * mg_get_user_data(const struct mg_context *ctx)
mg_get_context_info
CIVETWEB_API int mg_get_context_info(const struct mg_context *ctx, char *buffer, int buflen)
MG_CONFIG_TYPE_STRING_LIST
@ MG_CONFIG_TYPE_STRING_LIST
Definition: civetweb.h:701
MG_ERROR_DATA_CODE_TLS_CONNECT_ERROR
@ MG_ERROR_DATA_CODE_TLS_CONNECT_ERROR
Definition: civetweb.h:1794
MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE
@ MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE
Definition: civetweb.h:861
mg_server_port::_reserved4
int _reserved4
Definition: civetweb.h:720
mg_callbacks::init_ssl_domain
int(* init_ssl_domain)(const char *server_domain, void *ssl_ctx, void *user_data)
Definition: civetweb.h:265
mg_get_response_info
CIVETWEB_API const struct mg_response_info * mg_get_response_info(const struct mg_connection *)
mg_cry
CIVETWEB_API void mg_cry(const struct mg_connection *conn, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
mg_response_info::http_version
const char * http_version
Definition: civetweb.h:194
mg_send_file_body
CIVETWEB_API int mg_send_file_body(struct mg_connection *conn, const char *path)
mg_base64_decode
CIVETWEB_API int mg_base64_decode(const char *src, size_t src_len, unsigned char *dst, size_t *dst_len)
mg_handle_form_request
CIVETWEB_API int mg_handle_form_request(struct mg_connection *conn, struct mg_form_data_handler *fdh)
mg_match_context::case_sensitive
int case_sensitive
Definition: civetweb.h:1379
MG_FEATURES_HTTP2
@ MG_FEATURES_HTTP2
Definition: civetweb.h:102
MG_ERROR_DATA_CODE_INVALID_PARAM
@ MG_ERROR_DATA_CODE_INVALID_PARAM
Definition: civetweb.h:1737
mg_get_var2
CIVETWEB_API int mg_get_var2(const char *data, size_t data_len, const char *var_name, char *dst, size_t dst_len, size_t occurrence)
mg_get_header
const CIVETWEB_API char * mg_get_header(const struct mg_connection *, const char *name)
mg_websocket_close_handler
void(* mg_websocket_close_handler)(const struct mg_connection *, void *)
Definition: civetweb.h:555
mg_exit_library
CIVETWEB_API unsigned mg_exit_library(void)
mg_read
CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len)
mg_get_builtin_mime_type
const CIVETWEB_API char * mg_get_builtin_mime_type(const char *file_name)
MG_CONFIG_TYPE_EXT_PATTERN
@ MG_CONFIG_TYPE_EXT_PATTERN
Definition: civetweb.h:700
mg_response_header_add
CIVETWEB_API int mg_response_header_add(struct mg_connection *conn, const char *header, const char *value, int value_len)
MG_ERROR_DATA_CODE_INVALID_OPTION
@ MG_ERROR_DATA_CODE_INVALID_OPTION
Definition: civetweb.h:1740
MG_FEATURES_COMPRESSION
@ MG_FEATURES_COMPRESSION
Definition: civetweb.h:99
mg_websocket_subprotocols::nb_subprotocols
int nb_subprotocols
Definition: civetweb.h:563
mg_printf
CIVETWEB_API int mg_printf(struct mg_connection *, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
mg_connect_client_secure
CIVETWEB_API struct mg_connection * mg_connect_client_secure(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size)
MG_CONFIG_TYPE_NUMBER
@ MG_CONFIG_TYPE_NUMBER
Definition: civetweb.h:695
MG_ERROR_DATA_CODE_INIT_LIBRARY_FAILED
@ MG_ERROR_DATA_CODE_INIT_LIBRARY_FAILED
Definition: civetweb.h:1758
mg_response_header_start
CIVETWEB_API int mg_response_header_start(struct mg_connection *conn, int status)
mg_download
CIVETWEB_API struct mg_connection * mg_download(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, PRINTF_FORMAT_STRING(const char *request_fmt),...) PRINTF_ARGS(6
mg_connect_websocket_client_secure_extensions
CIVETWEB_API struct mg_connection * mg_connect_websocket_client_secure_extensions(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, const char *extensions, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
mg_check_digest_access_authentication
CIVETWEB_API int mg_check_digest_access_authentication(struct mg_connection *conn, const char *realm, const char *filename)
MG_ERROR_DATA_CODE_INIT_PORTS_FAILED
@ MG_ERROR_DATA_CODE_INIT_PORTS_FAILED
Definition: civetweb.h:1764
mg_server_port::_reserved3
int _reserved3
Definition: civetweb.h:719
mg_connect_websocket_client
CIVETWEB_API struct mg_connection * mg_connect_websocket_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
mg_callbacks::exit_lua
void(* exit_lua)(const struct mg_connection *conn, void *lua_context, unsigned context_flags)
Definition: civetweb.h:345
mg_client_options::server_cert
const char * server_cert
Definition: civetweb.h:1487
MG_WEBSOCKET_OPCODE_PING
@ MG_WEBSOCKET_OPCODE_PING
Definition: civetweb.h:862
MG_ERROR_DATA_CODE_HOST_NOT_FOUND
@ MG_ERROR_DATA_CODE_HOST_NOT_FOUND
Definition: civetweb.h:1779
mg_connect_websocket_client_secure
CIVETWEB_API struct mg_connection * mg_connect_websocket_client_secure(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
mg_send_mime_file2
CIVETWEB_API void mg_send_mime_file2(struct mg_connection *conn, const char *path, const char *mime_type, const char *additional_headers)
mg_split_form_urlencoded
CIVETWEB_API int mg_split_form_urlencoded(char *data, struct mg_header *form_fields, unsigned num_form_fields)
mg_response_header_add_lines
CIVETWEB_API int mg_response_header_add_lines(struct mg_connection *conn, const char *http1_headers)
mg_error_data
Definition: civetweb.h:1723
mg_get_thread_pointer
CIVETWEB_API void * mg_get_thread_pointer(const struct mg_connection *conn)
mg_authorization_handler
int(* mg_authorization_handler)(struct mg_connection *conn, void *cbdata)
Definition: civetweb.h:606
mg_client_cert::subject
const char * subject
Definition: civetweb.h:208
mg_get_response
CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout)
mg_store_body
CIVETWEB_API long long mg_store_body(struct mg_connection *conn, const char *path)
mg_get_server_ports
CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server_port *ports)
mg_match_element
Definition: civetweb.h:1373
mg_stop
CIVETWEB_API void mg_stop(struct mg_context *)
MG_FEATURES_DEFAULT
@ MG_FEATURES_DEFAULT
Definition: civetweb.h:57
mg_start_domain
CIVETWEB_API int mg_start_domain(struct mg_context *ctx, const char **configuration_options)
mg_option::name
const char * name
Definition: civetweb.h:686
mg_modify_passwords_file
CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name, const char *realm, const char *user, const char *password)
MG_CONFIG_TYPE_YES_NO_OPTIONAL
@ MG_CONFIG_TYPE_YES_NO_OPTIONAL
Definition: civetweb.h:703
PRINTF_ARGS
#define PRINTF_ARGS(x, y)
Definition: civetweb.h:883
mg_request_info::remote_port
int remote_port
Definition: civetweb.h:170
mg_request_info::query_string
const char * query_string
Definition: civetweb.h:162
mg_callbacks::init_context
void(* init_context)(const struct mg_context *ctx)
Definition: civetweb.h:367
mg_send_http_error
CIVETWEB_API int mg_send_http_error(struct mg_connection *conn, int status_code, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(3
MG_TIMEOUT_INFINITE
@ MG_TIMEOUT_INFINITE
Definition: civetweb.h:1524
mg_check_feature
CIVETWEB_API unsigned mg_check_feature(unsigned feature)
MG_FEATURES_IPV6
@ MG_FEATURES_IPV6
Definition: civetweb.h:75
MG_WEBSOCKET_OPCODE_CONTINUATION
@ MG_WEBSOCKET_OPCODE_CONTINUATION
Definition: civetweb.h:858
mg_start
CIVETWEB_API struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **configuration_options)
MG_ERROR_DATA_CODE_OS_ERROR
@ MG_ERROR_DATA_CODE_OS_ERROR
Definition: civetweb.h:1761
mg_callbacks::exit_thread
void(* exit_thread)(const struct mg_context *ctx, int thread_type, void *thread_pointer)
Definition: civetweb.h:400
mg_send_chunk
CIVETWEB_API int CIVETWEB_API int mg_send_chunk(struct mg_connection *conn, const char *chunk, unsigned int chunk_len)
mg_match_element::str
const char * str
Definition: civetweb.h:1374
MG_CONFIG_TYPE_UNKNOWN
@ MG_CONFIG_TYPE_UNKNOWN
Definition: civetweb.h:694
mg_client_options::host
const char * host
Definition: civetweb.h:1484
mg_request_info::local_uri_raw
const char * local_uri_raw
Definition: civetweb.h:154
mg_base64_encode
CIVETWEB_API int mg_base64_encode(const unsigned char *src, size_t src_len, char *dst, size_t *dst_len)
mg_get_user_context_data
CIVETWEB_API void * mg_get_user_context_data(const struct mg_connection *conn)
mg_start_domain2
CIVETWEB_API int mg_start_domain2(struct mg_context *ctx, const char **configuration_options, struct mg_error_data *error)
mg_request_info::content_length
long long content_length
Definition: civetweb.h:168
mg_init_library
CIVETWEB_API unsigned mg_init_library(unsigned features)
mg_init_data::user_data
void * user_data
Definition: civetweb.h:1800
MG_ERROR_DATA_CODE_TLS_SERVER_CERT_ERROR
@ MG_ERROR_DATA_CODE_TLS_SERVER_CERT_ERROR
Definition: civetweb.h:1791
MG_ERROR_DATA_CODE_MISSING_OPTION
@ MG_ERROR_DATA_CODE_MISSING_OPTION
Definition: civetweb.h:1746
mg_md5
CIVETWEB_API char * mg_md5(char buf[33],...)
mg_client_cert::peer_cert
void * peer_cert
Definition: civetweb.h:207
MG_ERROR_DATA_CODE_DUPLICATE_DOMAIN
@ MG_ERROR_DATA_CODE_DUPLICATE_DOMAIN
Definition: civetweb.h:1749
mg_callbacks::end_request
void(* end_request)(const struct mg_connection *, int reply_status_code)
Definition: civetweb.h:236
mg_set_websocket_handler
CIVETWEB_API void mg_set_websocket_handler(struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata)
mg_client_cert
Definition: civetweb.h:206
MG_ERROR_DATA_CODE_OUT_OF_MEMORY
@ MG_ERROR_DATA_CODE_OUT_OF_MEMORY
Definition: civetweb.h:1752
mg_unlock_connection
CIVETWEB_API void mg_unlock_connection(struct mg_connection *conn)
mg_close_connection
CIVETWEB_API struct mg_connection CIVETWEB_API void mg_close_connection(struct mg_connection *conn)
mg_response_info::content_length
long long content_length
Definition: civetweb.h:196
MG_ERROR_DATA_CODE_TLS_CLIENT_CERT_ERROR
@ MG_ERROR_DATA_CODE_TLS_CLIENT_CERT_ERROR
Definition: civetweb.h:1788
mg_request_info::remote_addr
char remote_addr[48]
Definition: civetweb.h:166
mg_websocket_ready_handler
void(* mg_websocket_ready_handler)(struct mg_connection *, void *)
Definition: civetweb.h:549
mg_request_info::request_uri
const char * request_uri
Definition: civetweb.h:152
mg_response_header_send
CIVETWEB_API int mg_response_header_send(struct mg_connection *conn)
mg_get_var
CIVETWEB_API int mg_get_var(const char *data, size_t data_len, const char *var_name, char *dst, size_t dst_len)
mg_set_request_handler
CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
mg_request_info::request_method
const char * request_method
Definition: civetweb.h:151
mg_form_data_handler
Definition: civetweb.h:1201
mg_header::name
const char * name
Definition: civetweb.h:144
MG_FEATURES_ALL
@ MG_FEATURES_ALL
Definition: civetweb.h:108
mg_set_user_connection_data
CIVETWEB_API void mg_set_user_connection_data(const struct mg_connection *conn, void *data)
mg_send_digest_access_authentication_request
CIVETWEB_API int mg_send_digest_access_authentication_request(struct mg_connection *conn, const char *realm)
mg_strcasecmp
CIVETWEB_API void CIVETWEB_API int mg_strcasecmp(const char *s1, const char *s2)
mg_thread_func_t
void *(* mg_thread_func_t)(void *)
Definition: civetweb.h:1307
mg_callbacks::external_ssl_ctx_domain
int(* external_ssl_ctx_domain)(const char *server_domain, void **ssl_ctx, void *user_data)
Definition: civetweb.h:290
mg_get_response_code_text
const CIVETWEB_API char * mg_get_response_code_text(const struct mg_connection *conn, int response_code)
mg_callbacks::init_ssl
int(* init_ssl)(void *ssl_ctx, void *user_data)
Definition: civetweb.h:254
mg_response_info::status_text
const char * status_text
Definition: civetweb.h:193
mg_client_options::port
int port
Definition: civetweb.h:1485
MG_FORM_FIELD_HANDLE_ABORT
@ MG_FORM_FIELD_HANDLE_ABORT
Definition: civetweb.h:1290
mg_url_encode
CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len)
mg_server_port::protocol
int protocol
Definition: civetweb.h:713
mg_websocket_subprotocols::subprotocols
const char ** subprotocols
Definition: civetweb.h:564
mg_get_valid_options
CIVETWEB_API const struct mg_option * mg_get_valid_options(void)
MG_FEATURES_TLS
@ MG_FEATURES_TLS
Definition: civetweb.h:66
mg_option::type
int type
Definition: civetweb.h:687
mg_client_cert::serial
const char * serial
Definition: civetweb.h:210
mg_response_info::http_headers
struct mg_header http_headers[MG_MAX_HEADERS]
Definition: civetweb.h:200
mg_server_port::_reserved2
int _reserved2
Definition: civetweb.h:718
mg_write
CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len)
mg_version
const CIVETWEB_API char * mg_version(void)
mg_header
Definition: civetweb.h:143
mg_server_port::is_ssl
int is_ssl
Definition: civetweb.h:715
mg_request_info::user_data
void * user_data
Definition: civetweb.h:175
MG_ERROR_DATA_CODE_INIT_ACL_FAILED
@ MG_ERROR_DATA_CODE_INIT_ACL_FAILED
Definition: civetweb.h:1770
mg_option
Definition: civetweb.h:685
mg_match_context::num_matches
size_t num_matches
Definition: civetweb.h:1380
MG_ERROR_DATA_CODE_INIT_TLS_FAILED
@ MG_ERROR_DATA_CODE_INIT_TLS_FAILED
Definition: civetweb.h:1743
mg_request_info::is_ssl
int is_ssl
Definition: civetweb.h:173
mg_callbacks::begin_request
int(* begin_request)(struct mg_connection *)
Definition: civetweb.h:233
MG_ERROR_DATA_CODE_OK
@ MG_ERROR_DATA_CODE_OK
Definition: civetweb.h:1734
MG_FEATURES_CACHE
@ MG_FEATURES_CACHE
Definition: civetweb.h:91
mg_callbacks::init_connection
int(* init_connection)(const struct mg_connection *conn, void **conn_data)
Definition: civetweb.h:417
mg_callbacks
Definition: civetweb.h:218
mg_server_port::is_redirect
int is_redirect
Definition: civetweb.h:716
MG_ERROR_DATA_CODE_CONNECT_TIMEOUT
@ MG_ERROR_DATA_CODE_CONNECT_TIMEOUT
Definition: civetweb.h:1782
MG_FEATURES_STATS
@ MG_FEATURES_STATS
Definition: civetweb.h:95
mg_request_handler
int(* mg_request_handler)(struct mg_connection *conn, void *cbdata)
Definition: civetweb.h:492
mg_modify_passwords_file_ha1
CIVETWEB_API int mg_modify_passwords_file_ha1(const char *passwords_file_name, const char *realm, const char *user, const char *ha1)
mg_callbacks::init_lua
void(* init_lua)(const struct mg_connection *conn, void *lua_context, unsigned context_flags)
Definition: civetweb.h:342
CIVETWEB_API
#define CIVETWEB_API
Definition: civetweb.h:43
mg_form_data_handler::user_data
void * user_data
Definition: civetweb.h:1264
MG_FORM_FIELD_STORAGE_STORE
@ MG_FORM_FIELD_STORAGE_STORE
Definition: civetweb.h:1277
PRINTF_FORMAT_STRING
#define PRINTF_FORMAT_STRING(s)
Definition: civetweb.h:877
mg_match_context::match
struct mg_match_element match[MG_MATCH_CONTEXT_MAX_MATCHES]
Definition: civetweb.h:1381
MG_FEATURES_SSJS
@ MG_FEATURES_SSJS
Definition: civetweb.h:87
mg_request_info
Definition: civetweb.h:150
MG_FEATURES_WEBSOCKET
@ MG_FEATURES_WEBSOCKET
Definition: civetweb.h:79
mg_error_data::code
unsigned code
Definition: civetweb.h:1724
mg_strncasecmp
CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len)
mg_websocket_write
CIVETWEB_API int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
mg_send_mime_file
CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn, const char *path, const char *mime_type)
MG_CONFIG_TYPE_DIRECTORY
@ MG_CONFIG_TYPE_DIRECTORY
Definition: civetweb.h:698
mg_send_http_redirect
CIVETWEB_API int mg_send_http_redirect(struct mg_connection *conn, const char *target_url, int redirect_code)
mg_callbacks::connection_closed
void(* connection_closed)(const struct mg_connection *)
Definition: civetweb.h:330
mg_websocket_data_handler
int(* mg_websocket_data_handler)(struct mg_connection *, int, char *, size_t, void *)
Definition: civetweb.h:550
MG_FORM_FIELD_STORAGE_GET
@ MG_FORM_FIELD_STORAGE_GET
Definition: civetweb.h:1275
MG_ERROR_DATA_CODE_INIT_USER_FAILED
@ MG_ERROR_DATA_CODE_INIT_USER_FAILED
Definition: civetweb.h:1767
MG_FORM_FIELD_HANDLE_GET
@ MG_FORM_FIELD_HANDLE_GET
Definition: civetweb.h:1286
mg_error_data::code_sub
unsigned code_sub
Definition: civetweb.h:1725
mg_header::value
const char * value
Definition: civetweb.h:145
mg_error_data::text
char * text
Definition: civetweb.h:1726
MG_FEATURES_FILES
@ MG_FEATURES_FILES
Definition: civetweb.h:61
mg_websocket_connect_handler
int(* mg_websocket_connect_handler)(const struct mg_connection *, void *)
Definition: civetweb.h:547
mg_request_info::remote_user
const char * remote_user
Definition: civetweb.h:164
MG_FEATURES_LUA
@ MG_FEATURES_LUA
Definition: civetweb.h:83
mg_send_http_ok
CIVETWEB_API int CIVETWEB_API int mg_send_http_ok(struct mg_connection *conn, const char *mime_type, long long content_length)
mg_request_info::server_port
int server_port
Definition: civetweb.h:171
MG_FEATURES_CGI
@ MG_FEATURES_CGI
Definition: civetweb.h:71
MG_ERROR_DATA_CODE_CONNECT_FAILED
@ MG_ERROR_DATA_CODE_CONNECT_FAILED
Definition: civetweb.h:1785
mg_get_context
CIVETWEB_API struct mg_context * mg_get_context(const struct mg_connection *conn)
mg_request_info::acceptedWebSocketSubprotocol
const char * acceptedWebSocketSubprotocol
Definition: civetweb.h:184
mg_disable_connection_keep_alive
CIVETWEB_API void mg_disable_connection_keep_alive(struct mg_connection *conn)
mg_connect_websocket_client_extensions
CIVETWEB_API struct mg_connection * mg_connect_websocket_client_extensions(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, const char *extensions, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
MG_MAX_HEADERS
#define MG_MAX_HEADERS
Definition: civetweb.h:141
mg_start2
CIVETWEB_API struct mg_context * mg_start2(struct mg_init_data *init, struct mg_error_data *error)
mg_connect_client
CIVETWEB_API struct mg_connection * mg_connect_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size)