NVIDIA DeepStream SDK API Reference

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