Logo ROOT   6.14/05
Reference Guide
civetweb.h
Go to the documentation of this file.
1 /* Copyright (c) 2013-2017 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.10"
27 #define CIVETWEB_VERSION_MAJOR (1)
28 #define CIVETWEB_VERSION_MINOR (10)
29 #define CIVETWEB_VERSION_PATCH (0)
30 #define CIVETWEB_VERSION_RELEASED
31 
32 #ifndef CIVETWEB_API
33 #if defined(_WIN32)
34 #if defined(CIVETWEB_DLL_EXPORTS)
35 #define CIVETWEB_API __declspec(dllexport)
36 #elif defined(CIVETWEB_DLL_IMPORTS)
37 #define CIVETWEB_API __declspec(dllimport)
38 #else
39 #define CIVETWEB_API
40 #endif
41 #elif __GNUC__ >= 4
42 #define CIVETWEB_API __attribute__((visibility("default")))
43 #else
44 #define CIVETWEB_API
45 #endif
46 #endif
47 
48 #include <stdio.h>
49 #include <stddef.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif /* __cplusplus */
54 
55 
56 /* Initialize this library. This should be called once before any other
57  * function from this library. This function is not guaranteed to be
58  * thread safe.
59  * Parameters:
60  * features: bit mask for features to be initialized.
61  * Return value:
62  * initialized features
63  * 0: error
64  */
65 CIVETWEB_API unsigned mg_init_library(unsigned features);
66 
67 
68 /* Un-initialize this library.
69  * Return value:
70  * 0: error
71  */
72 CIVETWEB_API unsigned mg_exit_library(void);
73 
74 
75 struct mg_context; /* Handle for the HTTP service itself */
76 struct mg_connection; /* Handle for the individual connection */
77 
78 
79 /* Maximum number of headers */
80 #define MG_MAX_HEADERS (64)
81 
82 struct mg_header {
83  const char *name; /* HTTP header name */
84  const char *value; /* HTTP header value */
85 };
86 
87 
88 /* This structure contains information about the HTTP request. */
90  const char *request_method; /* "GET", "POST", etc */
91  const char *request_uri; /* URL-decoded URI (absolute or relative,
92  * as in the request) */
93  const char *local_uri; /* URL-decoded URI (relative). Can be NULL
94  * if the request_uri does not address a
95  * resource at the server host. */
96 #if defined(MG_LEGACY_INTERFACE)
97  const char *uri; /* Deprecated: use local_uri instead */
98 #endif
99  const char *http_version; /* E.g. "1.0", "1.1" */
100  const char *query_string; /* URL part after '?', not including '?', or
101  NULL */
102  const char *remote_user; /* Authenticated user, or NULL if no auth
103  used */
104  char remote_addr[48]; /* Client's IP address as a string. */
105 
106 #if defined(MG_LEGACY_INTERFACE)
107  long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead
108  */
109 #endif
110 
111  long long content_length; /* Length (in bytes) of the request body,
112  can be -1 if no length was given. */
113  int remote_port; /* Client's port */
114  int is_ssl; /* 1 if SSL-ed, 0 if not */
115  void *user_data; /* User data pointer passed to mg_start() */
116  void *conn_data; /* Connection-specific user data */
117 
118  int num_headers; /* Number of HTTP headers */
119  struct mg_header
120  http_headers[MG_MAX_HEADERS]; /* Allocate maximum headers */
121 
122  struct mg_client_cert *client_cert; /* Client certificate information */
123 
124  const char *acceptedWebSocketSubprotocol; /* websocket subprotocol,
125  * accepted during handshake */
126 };
127 
128 
129 /* This structure contains information about the HTTP request. */
130 /* This structure may be extended in future versions. */
132  int status_code; /* E.g. 200 */
133  const char *status_text; /* E.g. "OK" */
134  const char *http_version; /* E.g. "1.0", "1.1" */
135 
136  long long content_length; /* Length (in bytes) of the request body,
137  can be -1 if no length was given. */
138 
139  int num_headers; /* Number of HTTP headers */
140  struct mg_header
141  http_headers[MG_MAX_HEADERS]; /* Allocate maximum headers */
142 };
143 
144 
145 /* Client certificate information (part of mg_request_info) */
146 /* New nomenclature. */
148  const char *subject;
149  const char *issuer;
150  const char *serial;
151  const char *finger;
152 };
153 
154 /* Old nomenclature. */
155 struct client_cert {
156  const char *subject;
157  const char *issuer;
158  const char *serial;
159  const char *finger;
160 };
161 
162 
163 /* This structure needs to be passed to mg_start(), to let civetweb know
164  which callbacks to invoke. For a detailed description, see
165  https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md */
166 struct mg_callbacks {
167  /* Called when civetweb has received new HTTP request.
168  If the callback returns one, it must process the request
169  by sending valid HTTP headers and a body. Civetweb will not do
170  any further processing. Otherwise it must return zero.
171  Note that since V1.7 the "begin_request" function is called
172  before an authorization check. If an authorization check is
173  required, use a request_handler instead.
174  Return value:
175  0: civetweb will process the request itself. In this case,
176  the callback must not send any data to the client.
177  1-999: callback already processed the request. Civetweb will
178  not send any data after the callback returned. The
179  return code is stored as a HTTP status code for the
180  access log. */
181  int (*begin_request)(struct mg_connection *);
182 
183  /* Called when civetweb has finished processing request. */
184  void (*end_request)(const struct mg_connection *, int reply_status_code);
185 
186  /* Called when civetweb is about to log a message. If callback returns
187  non-zero, civetweb does not log anything. */
188  int (*log_message)(const struct mg_connection *, const char *message);
189 
190  /* Called when civetweb is about to log access. If callback returns
191  non-zero, civetweb does not log anything. */
192  int (*log_access)(const struct mg_connection *, const char *message);
193 
194  /* Called when civetweb initializes SSL library.
195  Parameters:
196  user_data: parameter user_data passed when starting the server.
197  Return value:
198  0: civetweb will set up the SSL certificate.
199  1: civetweb assumes the callback already set up the certificate.
200  -1: initializing ssl fails. */
201  int (*init_ssl)(void *ssl_context, void *user_data);
202 
203 #if defined(MG_LEGACY_INTERFACE)
204  /* Called when websocket request is received, before websocket handshake.
205  Return value:
206  0: civetweb proceeds with websocket handshake.
207  1: connection is closed immediately.
208  This callback is deprecated: Use mg_set_websocket_handler instead. */
209  int (*websocket_connect)(const struct mg_connection *);
210 
211  /* Called when websocket handshake is successfully completed, and
212  connection is ready for data exchange.
213  This callback is deprecated: Use mg_set_websocket_handler instead. */
214  void (*websocket_ready)(struct mg_connection *);
215 
216  /* Called when data frame has been received from the client.
217  Parameters:
218  bits: first byte of the websocket frame, see websocket RFC at
219  http://tools.ietf.org/html/rfc6455, section 5.2
220  data, data_len: payload, with mask (if any) already applied.
221  Return value:
222  1: keep this websocket connection open.
223  0: close this websocket connection.
224  This callback is deprecated: Use mg_set_websocket_handler instead. */
225  int (*websocket_data)(struct mg_connection *,
226  int bits,
227  char *data,
228  size_t data_len);
229 #endif /* MG_LEGACY_INTERFACE */
230 
231  /* Called when civetweb is closing a connection. The per-context mutex is
232  locked when this is invoked.
233 
234  Websockets:
235  Before mg_set_websocket_handler has been added, it was primarily useful
236  for noting when a websocket is closing, and used to remove it from any
237  application-maintained list of clients.
238  Using this callback for websocket connections is deprecated: Use
239  mg_set_websocket_handler instead.
240 
241  Connection specific data:
242  If memory has been allocated for the connection specific user data
243  (mg_request_info->conn_data, mg_get_user_connection_data),
244  this is the last chance to free it.
245  */
246  void (*connection_close)(const struct mg_connection *);
247 
248 #if defined(MG_USE_OPEN_FILE)
249  /* Note: The "file in memory" feature is a deletion candidate, since
250  * it complicates the code, and does not add any value compared to
251  * "mg_add_request_handler".
252  * See this discussion thread:
253  * https://groups.google.com/forum/#!topic/civetweb/h9HT4CmeYqI
254  * If you disagree, if there is any situation this is indeed useful
255  * and cannot trivially be replaced by another existing feature,
256  * please contribute to this discussion during the next 3 month
257  * (till end of April 2017), otherwise this feature might be dropped
258  * in future releases. */
259 
260  /* Called when civetweb tries to open a file. Used to intercept file open
261  calls, and serve file data from memory instead.
262  Parameters:
263  path: Full path to the file to open.
264  data_len: Placeholder for the file size, if file is served from
265  memory.
266  Return value:
267  NULL: do not serve file from memory, proceed with normal file open.
268  non-NULL: pointer to the file contents in memory. data_len must be
269  initialized with the size of the memory block. */
270  const char *(*open_file)(const struct mg_connection *,
271  const char *path,
272  size_t *data_len);
273 #endif
274 
275  /* Called when civetweb is about to serve Lua server page, if
276  Lua support is enabled.
277  Parameters:
278  lua_context: "lua_State *" pointer. */
279  void (*init_lua)(const struct mg_connection *, void *lua_context);
280 
281 #if defined(MG_LEGACY_INTERFACE)
282  /* Called when civetweb has uploaded a file to a temporary directory as a
283  result of mg_upload() call.
284  Note that mg_upload is deprecated. Use mg_handle_form_request instead.
285  Parameters:
286  file_name: full path name to the uploaded file. */
287  void (*upload)(struct mg_connection *, const char *file_name);
288 #endif
289 
290  /* Called when civetweb is about to send HTTP error to the client.
291  Implementing this callback allows to create custom error pages.
292  Parameters:
293  status: HTTP error status code.
294  Return value:
295  1: run civetweb error handler.
296  0: callback already handled the error. */
297  int (*http_error)(struct mg_connection *, int status);
298 
299  /* Called after civetweb context has been created, before requests
300  are processed.
301  Parameters:
302  ctx: context handle */
303  void (*init_context)(const struct mg_context *ctx);
304 
305  /* Called when a new worker thread is initialized.
306  Parameters:
307  ctx: context handle
308  thread_type:
309  0 indicates the master thread
310  1 indicates a worker thread handling client connections
311  2 indicates an internal helper thread (timer thread)
312  */
313  void (*init_thread)(const struct mg_context *ctx, int thread_type);
314 
315  /* Called when civetweb context is deleted.
316  Parameters:
317  ctx: context handle */
318  void (*exit_context)(const struct mg_context *ctx);
319 
320  /* Called when initializing a new connection object.
321  * Can be used to initialize the connection specific user data
322  * (mg_request_info->conn_data, mg_get_user_connection_data).
323  * When the callback is called, it is not yet known if a
324  * valid HTTP(S) request will be made.
325  * Parameters:
326  * conn: not yet fully initialized connection object
327  * conn_data: output parameter, set to initialize the
328  * connection specific user data
329  * Return value:
330  * must be 0
331  * Otherwise, the result is undefined
332  */
333  int (*init_connection)(const struct mg_connection *conn, void **conn_data);
334 };
335 
336 
337 /* Start web server.
338 
339  Parameters:
340  callbacks: mg_callbacks structure with user-defined callbacks.
341  options: NULL terminated list of option_name, option_value pairs that
342  specify Civetweb configuration parameters.
343 
344  Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
345  processing is required for these, signal handlers must be set up
346  after calling mg_start().
347 
348 
349  Example:
350  const char *options[] = {
351  "document_root", "/var/www",
352  "listening_ports", "80,443s",
353  NULL
354  };
355  struct mg_context *ctx = mg_start(&my_func, NULL, options);
356 
357  Refer to https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
358  for the list of valid option and their possible values.
359 
360  Return:
361  web server context, or NULL on error. */
362 CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
363  void *user_data,
364  const char **configuration_options);
365 
366 
367 /* Stop the web server.
368 
369  Must be called last, when an application wants to stop the web server and
370  release all associated resources. This function blocks until all Civetweb
371  threads are stopped. Context pointer becomes invalid. */
372 CIVETWEB_API void mg_stop(struct mg_context *);
373 
374 
375 /* mg_request_handler
376 
377  Called when a new request comes in. This callback is URI based
378  and configured with mg_set_request_handler().
379 
380  Parameters:
381  conn: current connection information.
382  cbdata: the callback data configured with mg_set_request_handler().
383  Returns:
384  0: the handler could not handle the request, so fall through.
385  1 - 999: the handler processed the request. The return code is
386  stored as a HTTP status code for the access log. */
387 typedef int (*mg_request_handler)(struct mg_connection *conn, void *cbdata);
388 
389 
390 /* mg_set_request_handler
391 
392  Sets or removes a URI mapping for a request handler.
393  This function uses mg_lock_context internally.
394 
395  URI's are ordered and prefixed URI's are supported. For example,
396  consider two URIs: /a/b and /a
397  /a matches /a
398  /a/b matches /a/b
399  /a/c matches /a
400 
401  Parameters:
402  ctx: server context
403  uri: the URI (exact or pattern) for the handler
404  handler: the callback handler to use when the URI is requested.
405  If NULL, an already registered handler for this URI will
406  be removed.
407  The URI used to remove a handler must match exactly the
408  one used to register it (not only a pattern match).
409  cbdata: the callback data to give to the handler when it is called. */
410 CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx,
411  const char *uri,
412  mg_request_handler handler,
413  void *cbdata);
414 
415 
416 /* Callback types for websocket handlers in C/C++.
417 
418  mg_websocket_connect_handler
419  Is called when the client intends to establish a websocket connection,
420  before websocket handshake.
421  Return value:
422  0: civetweb proceeds with websocket handshake.
423  1: connection is closed immediately.
424 
425  mg_websocket_ready_handler
426  Is called when websocket handshake is successfully completed, and
427  connection is ready for data exchange.
428 
429  mg_websocket_data_handler
430  Is called when a data frame has been received from the client.
431  Parameters:
432  bits: first byte of the websocket frame, see websocket RFC at
433  http://tools.ietf.org/html/rfc6455, section 5.2
434  data, data_len: payload, with mask (if any) already applied.
435  Return value:
436  1: keep this websocket connection open.
437  0: close this websocket connection.
438 
439  mg_connection_close_handler
440  Is called, when the connection is closed.*/
441 typedef int (*mg_websocket_connect_handler)(const struct mg_connection *,
442  void *);
443 typedef void (*mg_websocket_ready_handler)(struct mg_connection *, void *);
444 typedef int (*mg_websocket_data_handler)(struct mg_connection *,
445  int,
446  char *,
447  size_t,
448  void *);
449 typedef void (*mg_websocket_close_handler)(const struct mg_connection *,
450  void *);
451 
452 /* struct mg_websocket_subprotocols
453  *
454  * List of accepted subprotocols
455  */
458  char **subprotocols;
459 };
460 
461 /* mg_set_websocket_handler
462 
463  Set or remove handler functions for websocket connections.
464  This function works similar to mg_set_request_handler - see there. */
465 CIVETWEB_API void
466 mg_set_websocket_handler(struct mg_context *ctx,
467  const char *uri,
468  mg_websocket_connect_handler connect_handler,
469  mg_websocket_ready_handler ready_handler,
470  mg_websocket_data_handler data_handler,
471  mg_websocket_close_handler close_handler,
472  void *cbdata);
473 
474 /* mg_set_websocket_handler
475 
476  Set or remove handler functions for websocket connections.
477  This function works similar to mg_set_request_handler - see there. */
479  struct mg_context *ctx,
480  const char *uri,
481  struct mg_websocket_subprotocols *subprotocols,
482  mg_websocket_connect_handler connect_handler,
483  mg_websocket_ready_handler ready_handler,
484  mg_websocket_data_handler data_handler,
485  mg_websocket_close_handler close_handler,
486  void *cbdata);
487 
488 
489 /* mg_authorization_handler
490 
491  Callback function definition for mg_set_auth_handler
492 
493  Parameters:
494  conn: current connection information.
495  cbdata: the callback data configured with mg_set_request_handler().
496  Returns:
497  0: access denied
498  1: access granted
499  */
500 typedef int (*mg_authorization_handler)(struct mg_connection *conn,
501  void *cbdata);
502 
503 
504 /* mg_set_auth_handler
505 
506  Sets or removes a URI mapping for an authorization handler.
507  This function works similar to mg_set_request_handler - see there. */
508 CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx,
509  const char *uri,
510  mg_authorization_handler handler,
511  void *cbdata);
512 
513 
514 /* Get the value of particular configuration parameter.
515  The value returned is read-only. Civetweb does not allow changing
516  configuration at run time.
517  If given parameter name is not valid, NULL is returned. For valid
518  names, return value is guaranteed to be non-NULL. If parameter is not
519  set, zero-length string is returned. */
520 CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx,
521  const char *name);
522 
523 
524 /* Get context from connection. */
525 CIVETWEB_API struct mg_context *
526 mg_get_context(const struct mg_connection *conn);
527 
528 
529 /* Get user data passed to mg_start from context. */
530 CIVETWEB_API void *mg_get_user_data(const struct mg_context *ctx);
531 
532 
533 /* Set user data for the current connection. */
534 CIVETWEB_API void mg_set_user_connection_data(struct mg_connection *conn,
535  void *data);
536 
537 
538 /* Get user data set for the current connection. */
539 CIVETWEB_API void *
540 mg_get_user_connection_data(const struct mg_connection *conn);
541 
542 
543 /* Get a formatted link corresponding to the current request
544 
545  Parameters:
546  conn: current connection information.
547  buf: string buffer (out)
548  buflen: length of the string buffer
549  Returns:
550  <0: error
551  >=0: ok */
552 CIVETWEB_API int
553 mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen);
554 
555 
556 #if defined(MG_LEGACY_INTERFACE)
557 /* Return array of strings that represent valid configuration options.
558  For each option, option name and default value is returned, i.e. the
559  number of entries in the array equals to number_of_options x 2.
560  Array is NULL terminated. */
561 /* Deprecated: Use mg_get_valid_options instead. */
562 CIVETWEB_API const char **mg_get_valid_option_names(void);
563 #endif
564 
565 
566 struct mg_option {
567  const char *name;
568  int type;
569  const char *default_value;
570 };
571 
572 /* Old nomenclature */
573 enum {
583 };
584 
585 /* New nomenclature */
586 enum {
596 };
597 
598 /* Return array of struct mg_option, representing all valid configuration
599  options of civetweb.c.
600  The array is terminated by a NULL name option. */
601 CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
602 
603 
605  int protocol; /* 1 = IPv4, 2 = IPv6, 3 = both */
606  int port; /* port number */
607  int is_ssl; /* https port: 0 = no, 1 = yes */
608  int is_redirect; /* redirect all requests: 0 = no, 1 = yes */
613 };
614 
615 
616 /* Get the list of ports that civetweb is listening on.
617  The parameter size is the size of the ports array in elements.
618  The caller is responsibility to allocate the required memory.
619  This function returns the number of struct mg_server_ports elements
620  filled in, or <0 in case of an error. */
621 CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx,
622  int size,
623  struct mg_server_ports *ports);
624 
625 
626 #if defined(MG_LEGACY_INTERFACE)
627 /* Deprecated: Use mg_get_server_ports instead. */
628 CIVETWEB_API size_t
629 mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl);
630 #endif
631 
632 
633 /* Add, edit or delete the entry in the passwords file.
634  *
635  * This function allows an application to manipulate .htpasswd files on the
636  * fly by adding, deleting and changing user records. This is one of the
637  * several ways of implementing authentication on the server side. For another,
638  * cookie-based way please refer to the examples/chat in the source tree.
639  *
640  * Parameter:
641  * passwords_file_name: Path and name of a file storing multiple passwords
642  * realm: HTTP authentication realm (authentication domain) name
643  * user: User name
644  * password:
645  * If password is not NULL, entry modified or added.
646  * If password is NULL, entry is deleted.
647  *
648  * Return:
649  * 1 on success, 0 on error.
650  */
651 CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
652  const char *realm,
653  const char *user,
654  const char *password);
655 
656 
657 /* Return information associated with the request.
658  * Use this function to implement a server and get data about a request
659  * from a HTTP/HTTPS client.
660  * Note: Before CivetWeb 1.10, this function could be used to read
661  * a response from a server, when implementing a client, although the
662  * values were never returned in appropriate mg_request_info elements.
663  * It is strongly advised to use mg_get_response_info for clients.
664  */
665 CIVETWEB_API const struct mg_request_info *
666 mg_get_request_info(const struct mg_connection *);
667 
668 
669 /* Return information associated with a HTTP/HTTPS response.
670  * Use this function in a client, to check the response from
671  * the server. */
672 CIVETWEB_API const struct mg_response_info *
673 mg_get_response_info(const struct mg_connection *);
674 
675 
676 /* Send data to the client.
677  Return:
678  0 when the connection has been closed
679  -1 on error
680  >0 number of bytes written on success */
681 CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
682 
683 
684 /* Send data to a websocket client wrapped in a websocket frame. Uses
685  mg_lock_connection to ensure that the transmission is not interrupted,
686  i.e., when the application is proactively communicating and responding to
687  a request simultaneously.
688 
689  Send data to a websocket client wrapped in a websocket frame.
690  This function is available when civetweb is compiled with -DUSE_WEBSOCKET
691 
692  Return:
693  0 when the connection has been closed
694  -1 on error
695  >0 number of bytes written on success */
696 CIVETWEB_API int mg_websocket_write(struct mg_connection *conn,
697  int opcode,
698  const char *data,
699  size_t data_len);
700 
701 
702 /* Send data to a websocket server wrapped in a masked websocket frame. Uses
703  mg_lock_connection to ensure that the transmission is not interrupted,
704  i.e., when the application is proactively communicating and responding to
705  a request simultaneously.
706 
707  Send data to a websocket server wrapped in a masked websocket frame.
708  This function is available when civetweb is compiled with -DUSE_WEBSOCKET
709 
710  Return:
711  0 when the connection has been closed
712  -1 on error
713  >0 number of bytes written on success */
714 CIVETWEB_API int mg_websocket_client_write(struct mg_connection *conn,
715  int opcode,
716  const char *data,
717  size_t data_len);
718 
719 
720 /* Blocks until unique access is obtained to this connection. Intended for use
721  with websockets only.
722  Invoke this before mg_write or mg_printf when communicating with a
723  websocket if your code has server-initiated communication as well as
724  communication in direct response to a message. */
725 CIVETWEB_API void mg_lock_connection(struct mg_connection *conn);
726 CIVETWEB_API void mg_unlock_connection(struct mg_connection *conn);
727 
728 
729 #if defined(MG_LEGACY_INTERFACE)
730 #define mg_lock mg_lock_connection
731 #define mg_unlock mg_unlock_connection
732 #endif
733 
734 
735 /* Lock server context. This lock may be used to protect resources
736  that are shared between different connection/worker threads. */
737 CIVETWEB_API void mg_lock_context(struct mg_context *ctx);
738 CIVETWEB_API void mg_unlock_context(struct mg_context *ctx);
739 
740 
741 /* Opcodes, from http://tools.ietf.org/html/rfc6455 */
742 /* Old nomenclature */
743 enum {
750 };
751 
752 /* New nomenclature */
753 enum {
760 };
761 
762 /* Macros for enabling compiler-specific checks for printf-like arguments. */
763 #undef PRINTF_FORMAT_STRING
764 #if defined(_MSC_VER) && _MSC_VER >= 1400
765 #include <sal.h>
766 #if defined(_MSC_VER) && _MSC_VER > 1400
767 #define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
768 #else
769 #define PRINTF_FORMAT_STRING(s) __format_string s
770 #endif
771 #else
772 #define PRINTF_FORMAT_STRING(s) s
773 #endif
774 
775 #ifdef __GNUC__
776 #define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
777 #else
778 #define PRINTF_ARGS(x, y)
779 #endif
780 
781 
782 /* Send data to the client using printf() semantics.
783  Works exactly like mg_write(), but allows to do message formatting. */
784 CIVETWEB_API int mg_printf(struct mg_connection *,
785  PRINTF_FORMAT_STRING(const char *fmt),
786  ...) PRINTF_ARGS(2, 3);
787 
788 
789 /* Send a part of the message body, if chunked transfer encoding is set.
790  * Only use this function after sending a complete HTTP request or response
791  * header with "Transfer-Encoding: chunked" set. */
792 CIVETWEB_API int mg_send_chunk(struct mg_connection *conn,
793  const char *chunk,
794  unsigned int chunk_len);
795 
796 
797 /* Send contents of the entire file together with HTTP headers. */
798 CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
799 
800 
801 /* Send HTTP error reply. */
802 CIVETWEB_API void mg_send_http_error(struct mg_connection *conn,
803  int status_code,
804  PRINTF_FORMAT_STRING(const char *fmt),
805  ...) PRINTF_ARGS(3, 4);
806 
807 
808 /* Send HTTP digest access authentication request.
809  * Browsers will send a user name and password in their next request, showing
810  * an authentication dialog if the password is not stored.
811  * Parameters:
812  * conn: Current connection handle.
813  * realm: Authentication realm. If NULL is supplied, the sever domain
814  * set in the authentication_domain configuration is used.
815  * Return:
816  * < 0 Error
817  */
818 CIVETWEB_API int
819 mg_send_digest_access_authentication_request(struct mg_connection *conn,
820  const char *realm);
821 
822 
823 /* Check if the current request has a valid authentication token set.
824  * A file is used to provide a list of valid user names, realms and
825  * password hashes. The file can be created and modified using the
826  * mg_modify_passwords_file API function.
827  * Parameters:
828  * conn: Current connection handle.
829  * realm: Authentication realm. If NULL is supplied, the sever domain
830  * set in the authentication_domain configuration is used.
831  * filename: Path and name of a file storing multiple password hashes.
832  * Return:
833  * > 0 Valid authentication
834  * 0 Invalid authentication
835  * < 0 Error (all values < 0 should be considered as invalid
836  * authentication, future error codes will have negative
837  * numbers)
838  * -1 Parameter error
839  * -2 File not found
840  */
841 CIVETWEB_API int
842 mg_check_digest_access_authentication(struct mg_connection *conn,
843  const char *realm,
844  const char *filename);
845 
846 
847 /* Send contents of the entire file together with HTTP headers.
848  * Parameters:
849  * conn: Current connection handle.
850  * path: Full path to the file to send.
851  * mime_type: Content-Type for file. NULL will cause the type to be
852  * looked up by the file extension.
853  */
854 CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn,
855  const char *path,
856  const char *mime_type);
857 
858 
859 /* Send contents of the entire file together with HTTP headers.
860  Parameters:
861  conn: Current connection information.
862  path: Full path to the file to send.
863  mime_type: Content-Type for file. NULL will cause the type to be
864  looked up by the file extension.
865  additional_headers: Additional custom header fields appended to the header.
866  Each header should start with an X-, to ensure it is
867  not included twice.
868  NULL does not append anything.
869 */
870 CIVETWEB_API void mg_send_mime_file2(struct mg_connection *conn,
871  const char *path,
872  const char *mime_type,
873  const char *additional_headers);
874 
875 
876 /* Store body data into a file. */
877 CIVETWEB_API long long mg_store_body(struct mg_connection *conn,
878  const char *path);
879 /* Read entire request body and store it in a file "path".
880  Return:
881  < 0 Error
882  >= 0 Number of bytes stored in file "path".
883 */
884 
885 
886 /* Read data from the remote end, return number of bytes read.
887  Return:
888  0 connection has been closed by peer. No more data could be read.
889  < 0 read error. No more data could be read from the connection.
890  > 0 number of bytes read into the buffer. */
891 CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
892 
893 
894 /* Get the value of particular HTTP header.
895 
896  This is a helper function. It traverses request_info->http_headers array,
897  and if the header is present in the array, returns its value. If it is
898  not present, NULL is returned. */
899 CIVETWEB_API const char *mg_get_header(const struct mg_connection *,
900  const char *name);
901 
902 
903 /* Get a value of particular form variable.
904 
905  Parameters:
906  data: pointer to form-uri-encoded buffer. This could be either POST data,
907  or request_info.query_string.
908  data_len: length of the encoded data.
909  var_name: variable name to decode from the buffer
910  dst: destination buffer for the decoded variable
911  dst_len: length of the destination buffer
912 
913  Return:
914  On success, length of the decoded variable.
915  On error:
916  -1 (variable not found).
917  -2 (destination buffer is NULL, zero length or too small to hold the
918  decoded variable).
919 
920  Destination buffer is guaranteed to be '\0' - terminated if it is not
921  NULL or zero length. */
922 CIVETWEB_API int mg_get_var(const char *data,
923  size_t data_len,
924  const char *var_name,
925  char *dst,
926  size_t dst_len);
927 
928 
929 /* Get a value of particular form variable.
930 
931  Parameters:
932  data: pointer to form-uri-encoded buffer. This could be either POST data,
933  or request_info.query_string.
934  data_len: length of the encoded data.
935  var_name: variable name to decode from the buffer
936  dst: destination buffer for the decoded variable
937  dst_len: length of the destination buffer
938  occurrence: which occurrence of the variable, 0 is the first, 1 the
939  second...
940  this makes it possible to parse a query like
941  b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
942 
943  Return:
944  On success, length of the decoded variable.
945  On error:
946  -1 (variable not found).
947  -2 (destination buffer is NULL, zero length or too small to hold the
948  decoded variable).
949 
950  Destination buffer is guaranteed to be '\0' - terminated if it is not
951  NULL or zero length. */
952 CIVETWEB_API int mg_get_var2(const char *data,
953  size_t data_len,
954  const char *var_name,
955  char *dst,
956  size_t dst_len,
957  size_t occurrence);
958 
959 
960 /* Fetch value of certain cookie variable into the destination buffer.
961 
962  Destination buffer is guaranteed to be '\0' - terminated. In case of
963  failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
964  parameter. This function returns only first occurrence.
965 
966  Return:
967  On success, value length.
968  On error:
969  -1 (either "Cookie:" header is not present at all or the requested
970  parameter is not found).
971  -2 (destination buffer is NULL, zero length or too small to hold the
972  value). */
973 CIVETWEB_API int mg_get_cookie(const char *cookie,
974  const char *var_name,
975  char *buf,
976  size_t buf_len);
977 
978 
979 /* Download data from the remote web server.
980  host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
981  port: port number, e.g. 80.
982  use_ssl: wether to use SSL connection.
983  error_buffer, error_buffer_size: error message placeholder.
984  request_fmt,...: HTTP request.
985  Return:
986  On success, valid pointer to the new connection, suitable for mg_read().
987  On error, NULL. error_buffer contains error message.
988  Example:
989  char ebuf[100];
990  struct mg_connection *conn;
991  conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
992  "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
993  */
994 CIVETWEB_API struct mg_connection *
995 mg_download(const char *host,
996  int port,
997  int use_ssl,
998  char *error_buffer,
999  size_t error_buffer_size,
1000  PRINTF_FORMAT_STRING(const char *request_fmt),
1001  ...) PRINTF_ARGS(6, 7);
1002 
1003 
1004 /* Close the connection opened by mg_download(). */
1005 CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
1006 
1007 
1008 #if defined(MG_LEGACY_INTERFACE)
1009 /* File upload functionality. Each uploaded file gets saved into a temporary
1010  file and MG_UPLOAD event is sent.
1011  Return number of uploaded files.
1012  Deprecated: Use mg_handle_form_request instead. */
1013 CIVETWEB_API int mg_upload(struct mg_connection *conn,
1014  const char *destination_dir);
1015 #endif
1016 
1017 
1018 /* This structure contains callback functions for handling form fields.
1019  It is used as an argument to mg_handle_form_request. */
1021  /* This callback function is called, if a new field has been found.
1022  * The return value of this callback is used to define how the field
1023  * should be processed.
1024  *
1025  * Parameters:
1026  * key: Name of the field ("name" property of the HTML input field).
1027  * filename: Name of a file to upload, at the client computer.
1028  * Only set for input fields of type "file", otherwise NULL.
1029  * path: Output parameter: File name (incl. path) to store the file
1030  * at the server computer. Only used if FORM_FIELD_STORAGE_STORE
1031  * is returned by this callback. Existing files will be
1032  * overwritten.
1033  * pathlen: Length of the buffer for path.
1034  * user_data: Value of the member user_data of mg_form_data_handler
1035  *
1036  * Return value:
1037  * The callback must return the intended storage for this field
1038  * (See FORM_FIELD_STORAGE_*).
1039  */
1040  int (*field_found)(const char *key,
1041  const char *filename,
1042  char *path,
1043  size_t pathlen,
1044  void *user_data);
1045 
1046  /* If the "field_found" callback returned FORM_FIELD_STORAGE_GET,
1047  * this callback will receive the field data.
1048  *
1049  * Parameters:
1050  * key: Name of the field ("name" property of the HTML input field).
1051  * value: Value of the input field.
1052  * user_data: Value of the member user_data of mg_form_data_handler
1053  *
1054  * Return value:
1055  * TODO: Needs to be defined.
1056  */
1057  int (*field_get)(const char *key,
1058  const char *value,
1059  size_t valuelen,
1060  void *user_data);
1061 
1062  /* If the "field_found" callback returned FORM_FIELD_STORAGE_STORE,
1063  * the data will be stored into a file. If the file has been written
1064  * successfully, this callback will be called. This callback will
1065  * not be called for only partially uploaded files. The
1066  * mg_handle_form_request function will either store the file completely
1067  * and call this callback, or it will remove any partial content and
1068  * not call this callback function.
1069  *
1070  * Parameters:
1071  * path: Path of the file stored at the server.
1072  * file_size: Size of the stored file in bytes.
1073  * user_data: Value of the member user_data of mg_form_data_handler
1074  *
1075  * Return value:
1076  * TODO: Needs to be defined.
1077  */
1078  int (*field_store)(const char *path, long long file_size, void *user_data);
1079 
1080  /* User supplied argument, passed to all callback functions. */
1081  void *user_data;
1082 };
1083 
1084 
1085 /* Return values definition for the "field_found" callback in
1086  * mg_form_data_handler. */
1087 /* Old nomenclature */
1088 enum {
1089  /* Skip this field (neither get nor store it). Continue with the
1090  * next field. */
1092  /* Get the field value. */
1094  /* Store the field value into a file. */
1096  /* Stop parsing this request. Skip the remaining fields. */
1098 };
1099 
1100 /* New nomenclature */
1101 enum {
1102  /* Skip this field (neither get nor store it). Continue with the
1103  * next field. */
1105  /* Get the field value. */
1107  /* Store the field value into a file. */
1109  /* Stop parsing this request. Skip the remaining fields. */
1111 };
1112 
1113 /* Process form data.
1114  * Returns the number of fields handled, or < 0 in case of an error.
1115  * Note: It is possible that several fields are already handled successfully
1116  * (e.g., stored into files), before the request handling is stopped with an
1117  * error. In this case a number < 0 is returned as well.
1118  * In any case, it is the duty of the caller to remove files once they are
1119  * no longer required. */
1120 CIVETWEB_API int mg_handle_form_request(struct mg_connection *conn,
1121  struct mg_form_data_handler *fdh);
1122 
1123 
1124 /* Convenience function -- create detached thread.
1125  Return: 0 on success, non-0 on error. */
1126 typedef void *(*mg_thread_func_t)(void *);
1128 
1129 
1130 /* Return builtin mime type for the given file name.
1131  For unrecognized extensions, "text/plain" is returned. */
1132 CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
1133 
1134 
1135 /* Get text representation of HTTP status code. */
1136 CIVETWEB_API const char *
1137 mg_get_response_code_text(const struct mg_connection *conn, int response_code);
1138 
1139 
1140 /* Return CivetWeb version. */
1141 CIVETWEB_API const char *mg_version(void);
1142 
1143 
1144 /* URL-decode input buffer into destination buffer.
1145  0-terminate the destination buffer.
1146  form-url-encoded data differs from URI encoding in a way that it
1147  uses '+' as character for space, see RFC 1866 section 8.2.1
1148  http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
1149  Return: length of the decoded data, or -1 if dst buffer is too small. */
1150 CIVETWEB_API int mg_url_decode(const char *src,
1151  int src_len,
1152  char *dst,
1153  int dst_len,
1154  int is_form_url_encoded);
1155 
1156 
1157 /* URL-encode input buffer into destination buffer.
1158  returns the length of the resulting buffer or -1
1159  is the buffer is too small. */
1160 CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
1161 
1162 
1163 /* MD5 hash given strings.
1164  Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
1165  ASCIIz strings. When function returns, buf will contain human-readable
1166  MD5 hash. Example:
1167  char buf[33];
1168  mg_md5(buf, "aa", "bb", NULL); */
1169 CIVETWEB_API char *mg_md5(char buf[33], ...);
1170 
1171 
1172 /* Print error message to the opened error log stream.
1173  This utilizes the provided logging configuration.
1174  conn: connection (not used for sending data, but to get perameters)
1175  fmt: format string without the line return
1176  ...: variable argument list
1177  Example:
1178  mg_cry(conn,"i like %s", "logging"); */
1179 CIVETWEB_API void mg_cry(const struct mg_connection *conn,
1180  PRINTF_FORMAT_STRING(const char *fmt),
1181  ...) PRINTF_ARGS(2, 3);
1182 
1183 
1184 /* utility methods to compare two buffers, case insensitive. */
1185 CIVETWEB_API int mg_strcasecmp(const char *s1, const char *s2);
1186 CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
1187 
1188 
1189 /* Connect to a websocket as a client
1190  Parameters:
1191  host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or
1192  "localhost"
1193  port: server port
1194  use_ssl: make a secure connection to server
1195  error_buffer, error_buffer_size: buffer for an error message
1196  path: server path you are trying to connect to, i.e. if connection to
1197  localhost/app, path should be "/app"
1198  origin: value of the Origin HTTP header
1199  data_func: callback that should be used when data is received from the
1200  server
1201  user_data: user supplied argument
1202 
1203  Return:
1204  On success, valid mg_connection object.
1205  On error, NULL. Se error_buffer for details.
1206 */
1207 CIVETWEB_API struct mg_connection *
1208 mg_connect_websocket_client(const char *host,
1209  int port,
1210  int use_ssl,
1211  char *error_buffer,
1212  size_t error_buffer_size,
1213  const char *path,
1214  const char *origin,
1215  mg_websocket_data_handler data_func,
1216  mg_websocket_close_handler close_func,
1217  void *user_data);
1218 
1219 
1220 /* Connect to a TCP server as a client (can be used to connect to a HTTP server)
1221  Parameters:
1222  host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or
1223  "localhost"
1224  port: server port
1225  use_ssl: make a secure connection to server
1226  error_buffer, error_buffer_size: buffer for an error message
1227 
1228  Return:
1229  On success, valid mg_connection object.
1230  On error, NULL. Se error_buffer for details.
1231 */
1232 CIVETWEB_API struct mg_connection *mg_connect_client(const char *host,
1233  int port,
1234  int use_ssl,
1235  char *error_buffer,
1236  size_t error_buffer_size);
1237 
1238 
1240  const char *host;
1241  int port;
1242  const char *client_cert;
1243  const char *server_cert;
1244  /* TODO: add more data */
1245 };
1246 
1247 
1248 CIVETWEB_API struct mg_connection *
1249 mg_connect_client_secure(const struct mg_client_options *client_options,
1250  char *error_buffer,
1251  size_t error_buffer_size);
1252 
1253 
1254 enum { TIMEOUT_INFINITE = -1 };
1255 enum { MG_TIMEOUT_INFINITE = -1 };
1256 
1257 /* Wait for a response from the server
1258  Parameters:
1259  conn: connection
1260  ebuf, ebuf_len: error message placeholder.
1261  timeout: time to wait for a response in milliseconds (if < 0 then wait
1262  forever)
1263 
1264  Return:
1265  On success, >= 0
1266  On error/timeout, < 0
1267 */
1268 CIVETWEB_API int mg_get_response(struct mg_connection *conn,
1269  char *ebuf,
1270  size_t ebuf_len,
1271  int timeout);
1272 
1273 
1274 /* Check which features where set when the civetweb library has been compiled.
1275  The function explicitly addresses compile time defines used when building
1276  the library - it does not mean, the feature has been initialized using a
1277  mg_init_library call.
1278  mg_check_feature can be called anytime, even before mg_init_library has
1279  been called.
1280 
1281  Parameters:
1282  feature: specifies which feature should be checked
1283  The value is a bit mask. The individual bits are defined as:
1284  1 serve files (NO_FILES not set)
1285  2 support HTTPS (NO_SSL not set)
1286  4 support CGI (NO_CGI not set)
1287  8 support IPv6 (USE_IPV6 set)
1288  16 support WebSocket (USE_WEBSOCKET set)
1289  32 support Lua scripts and Lua server pages (USE_LUA is set)
1290  64 support server side JavaScript (USE_DUKTAPE is set)
1291  128 support caching (NO_CACHING not set)
1292  256 support server statistics (USE_SERVER_STATS is set)
1293  The result is undefined, if bits are set that do not represent a
1294  defined feature (currently: feature >= 512).
1295  The result is undefined, if no bit is set (feature == 0).
1296 
1297  Return:
1298  If feature is available, the corresponding bit is set
1299  If feature is not available, the bit is 0
1300 */
1301 CIVETWEB_API unsigned mg_check_feature(unsigned feature);
1302 
1303 
1304 /* Get information on the system. Useful for support requests.
1305  Parameters:
1306  buffer: Store system information as string here.
1307  buflen: Length of buffer (including a byte required for a terminating 0).
1308  Return:
1309  Available size of system information, exluding a terminating 0.
1310  The information is complete, if the return value is smaller than buflen.
1311  The result is a JSON formatted string, the exact content may vary.
1312  Note:
1313  It is possible to determine the required buflen, by first calling this
1314  function with buffer = NULL and buflen = NULL. The required buflen is
1315  one byte more than the returned value.
1316 */
1317 CIVETWEB_API int mg_get_system_info(char *buffer, int buflen);
1318 
1319 
1320 /* Get context information. Useful for server diagnosis.
1321  Parameters:
1322  ctx: Context handle
1323  buffer: Store context information here.
1324  buflen: Length of buffer (including a byte required for a terminating 0).
1325  Return:
1326  Available size of system information, exluding a terminating 0.
1327  The information is complete, if the return value is smaller than buflen.
1328  The result is a JSON formatted string, the exact content may vary.
1329  Note:
1330  It is possible to determine the required buflen, by first calling this
1331  function with buffer = NULL and buflen = NULL. The required buflen is
1332  one byte more than the returned value. However, since the available
1333  context information changes, you should allocate a few bytes more.
1334 */
1335 CIVETWEB_API int
1336 mg_get_context_info(const struct mg_context *ctx, char *buffer, int buflen);
1337 
1338 
1339 #ifdef MG_EXPERIMENTAL_INTERFACES
1340 /* Get connection information. Useful for server diagnosis.
1341  Parameters:
1342  ctx: Context handle
1343  idx: Connection index
1344  buffer: Store context information here.
1345  buflen: Length of buffer (including a byte required for a terminating 0).
1346  Return:
1347  Available size of system information, exluding a terminating 0.
1348  The information is complete, if the return value is smaller than buflen.
1349  The result is a JSON formatted string, the exact content may vary.
1350  Note:
1351  It is possible to determine the required buflen, by first calling this
1352  function with buffer = NULL and buflen = NULL. The required buflen is
1353  one byte more than the returned value. However, since the available
1354  context information changes, you should allocate a few bytes more.
1355 */
1356 CIVETWEB_API int mg_get_connection_info(const struct mg_context *ctx,
1357  int idx,
1358  char *buffer,
1359  int buflen);
1360 #endif
1361 
1362 
1363 #ifdef __cplusplus
1364 }
1365 #endif /* __cplusplus */
1366 
1367 #endif /* CIVETWEB_HEADER_INCLUDED */
CIVETWEB_API struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **configuration_options)
Definition: civetweb.c:16676
const char * remote_user
Definition: civetweb.h:102
CIVETWEB_API void CIVETWEB_API int mg_send_digest_access_authentication_request(struct mg_connection *conn, const char *realm)
Definition: civetweb.c:7884
CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len)
Definition: civetweb.c:2962
const char * issuer
Definition: civetweb.h:149
const char * local_uri
Definition: civetweb.h:93
CIVETWEB_API unsigned mg_init_library(unsigned features)
Definition: civetweb.c:17941
const char * mime_type
Definition: civetweb.c:7147
#define PRINTF_ARGS(x, y)
Definition: civetweb.h:778
const char * host
Definition: civetweb.h:1240
CIVETWEB_API void mg_unlock_connection(struct mg_connection *conn)
Definition: civetweb.c:11121
CIVETWEB_API void mg_set_user_connection_data(struct mg_connection *conn, void *data)
Definition: civetweb.c:3136
const char * server_cert
Definition: civetweb.h:1243
CIVETWEB_API void * mg_get_user_data(const struct mg_context *ctx)
Definition: civetweb.c:3129
CIVETWEB_API struct mg_connection * mg_connect_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size)
Definition: civetweb.c:15031
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)
Definition: civetweb.c:12212
const char * finger
Definition: civetweb.h:151
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
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)
Definition: civetweb.c:15634
CIVETWEB_API int mg_printf(struct mg_connection *, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
CIVETWEB_API struct mg_connection CIVETWEB_API void mg_close_connection(struct mg_connection *conn)
Definition: civetweb.c:14779
CIVETWEB_API const char * mg_get_option(const struct mg_context *ctx, const char *name)
Definition: civetweb.c:3108
CIVETWEB_API void mg_lock_context(struct mg_context *ctx)
Definition: civetweb.c:11129
#define f(i)
Definition: RSha256.hxx:104
CIVETWEB_API struct mg_connection * mg_connect_client_secure(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size)
Definition: civetweb.c:15019
CIVETWEB_API int mg_check_digest_access_authentication(struct mg_connection *conn, const char *realm, const char *filename)
Definition: civetweb.c:7769
CIVETWEB_API void mg_unlock_context(struct mg_context *ctx)
Definition: civetweb.c:11137
CIVETWEB_API const char * mg_get_header(const struct mg_connection *, const char *name)
Definition: civetweb.c:3628
const char * issuer
Definition: civetweb.h:157
int(* mg_authorization_handler)(struct mg_connection *conn, void *cbdata)
Definition: civetweb.h:500
CIVETWEB_API long long mg_store_body(struct mg_connection *conn, const char *path)
Definition: civetweb.c:9130
CIVETWEB_API const char * mg_get_response_code_text(const struct mg_connection *conn, int response_code)
Definition: civetweb.c:3926
CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn, const char *path, const char *mime_type)
Definition: civetweb.c:9034
const char * default_value
Definition: civetweb.h:569
#define PRINTF_FORMAT_STRING(s)
Definition: civetweb.h:772
const char * request_method
Definition: civetweb.h:90
CIVETWEB_API unsigned mg_check_feature(unsigned feature)
Definition: civetweb.c:16992
CIVETWEB_API const char * mg_get_builtin_mime_type(const char *file_name)
Definition: civetweb.c:7247
static void init_connection(struct mg_connection *conn)
Definition: civetweb.c:15770
const char * subject
Definition: civetweb.h:148
CIVETWEB_API int mg_get_context_info(const struct mg_context *ctx, char *buffer, int buflen)
Definition: civetweb.c:17900
int(* mg_websocket_data_handler)(struct mg_connection *, int, char *, size_t, void *)
Definition: civetweb.h:444
long long content_length
Definition: civetweb.h:136
const char * acceptedWebSocketSubprotocol
Definition: civetweb.h:124
#define MG_MAX_HEADERS
Definition: civetweb.h:80
void(* mg_websocket_close_handler)(const struct mg_connection *, void *)
Definition: civetweb.h:449
CIVETWEB_API void mg_send_http_error(struct mg_connection *conn, int status_code, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(3
CIVETWEB_API void mg_cry(const struct mg_connection *conn, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
CIVETWEB_API void CIVETWEB_API int mg_strcasecmp(const char *s1, const char *s2)
Definition: civetweb.c:2977
CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
Definition: civetweb.c:12191
CIVETWEB_API void mg_lock_connection(struct mg_connection *conn)
Definition: civetweb.c:11113
CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name, char *buf, size_t buf_len)
Definition: civetweb.c:6460
CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len)
Definition: civetweb.c:6138
CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len)
Definition: civetweb.c:8243
CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server_ports *ports)
Definition: civetweb.c:3179
CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path)
Definition: civetweb.c:9027
#define s1(x)
Definition: RSha256.hxx:91
const char * http_version
Definition: civetweb.h:99
CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout)
Definition: civetweb.c:15471
const char * name
Definition: civetweb.h:567
long long content_length
Definition: civetweb.h:111
CIVETWEB_API void mg_send_mime_file2(struct mg_connection *conn, const char *path, const char *mime_type, const char *additional_headers)
Definition: civetweb.c:9043
int(* mg_request_handler)(struct mg_connection *conn, void *cbdata)
Definition: civetweb.h:387
CIVETWEB_API const struct mg_request_info * mg_get_request_info(const struct mg_connection *)
Definition: civetweb.c:3368
CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p)
Definition: civetweb.c:5213
const char * serial
Definition: civetweb.h:150
CIVETWEB_API int mg_get_system_info(char *buffer, int buflen)
Definition: civetweb.c:17885
CIVETWEB_API int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
struct mg_client_cert * client_cert
Definition: civetweb.h:122
CIVETWEB_API const struct mg_response_info * mg_get_response_info(const struct mg_connection *)
Definition: civetweb.c:3397
const char * status_text
Definition: civetweb.h:133
CIVETWEB_API int CIVETWEB_API int mg_send_chunk(struct mg_connection *conn, const char *chunk, unsigned int chunk_len)
Definition: civetweb.c:6200
const char * finger
Definition: civetweb.h:159
int(* mg_websocket_connect_handler)(const struct mg_connection *, void *)
Definition: civetweb.h:441
CIVETWEB_API int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
Definition: civetweb.c:6360
CIVETWEB_API void * mg_get_user_connection_data(const struct mg_connection *conn)
Definition: civetweb.c:3145
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)
Definition: civetweb.c:12232
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)
Definition: civetweb.c:6402
CIVETWEB_API char * mg_md5(char buf[33],...)
Definition: civetweb.c:7319
CIVETWEB_API struct mg_context * mg_get_context(const struct mg_connection *conn)
Definition: civetweb.c:3122
CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len)
Definition: civetweb.c:6038
void * user_data
Definition: civetweb.h:115
typedef void((*Func_t)())
int type
Definition: civetweb.h:568
void(* mg_websocket_ready_handler)(struct mg_connection *, void *)
Definition: civetweb.h:443
CIVETWEB_API unsigned mg_exit_library(void)
Definition: civetweb.c:18015
const char * name
Definition: civetweb.h:83
void *(* mg_thread_func_t)(void *)
Definition: civetweb.h:1126
CIVETWEB_API int mg_handle_form_request(struct mg_connection *conn, struct mg_form_data_handler *fdh)
CIVETWEB_API int mg_get_var(const char *data, size_t data_len, const char *var_name, char *dst, size_t dst_len)
Definition: civetweb.c:6391
CIVETWEB_API int mg_websocket_client_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
const char * query_string
Definition: civetweb.h:100
CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx, const char *uri, mg_authorization_handler handler, void *cbdata)
Definition: civetweb.c:12261
void * conn_data
Definition: civetweb.h:116
const char * client_cert
Definition: civetweb.h:1242
CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name, const char *realm, const char *user, const char *password)
Definition: civetweb.c:7918
CIVETWEB_API const char * mg_version(void)
Definition: civetweb.c:3361
CIVETWEB_API int mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen)
Definition: civetweb.c:3437
const char * value
Definition: civetweb.h:84
CIVETWEB_API const struct mg_option * mg_get_valid_options(void)
Definition: civetweb.c:2735
const char * subject
Definition: civetweb.h:156
const char * http_version
Definition: civetweb.h:134
static void log_access(const struct mg_connection *conn)
Definition: civetweb.c:13438
CIVETWEB_API void mg_stop(struct mg_context *)
Definition: civetweb.c:16590
const char * request_uri
Definition: civetweb.h:91
#define CIVETWEB_API
Definition: civetweb.h:44
const char * serial
Definition: civetweb.h:158