RetroArch
civetweb.h
Go to the documentation of this file.
1 #ifndef CIVETWEB_CONFIGURED
2 #define CIVETWEB_CONFIGURED
3 
4 /* Put those here to avoid defining solution-wide macros to configure the embedded server. */
5 
6 #define NO_FILES 1
7 #define NO_SSL 1
8 #define NO_CGI 1
9 #define NO_POPEN 1
10 
11 #endif /* CIVETWEB_CONFIGURED */
12 
13 /* Copyright (c) 2013-2016 the Civetweb developers
14 * Copyright (c) 2004-2013 Sergey Lyubka
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a copy
17 * of this software and associated documentation files (the "Software"), to deal
18 * in the Software without restriction, including without limitation the rights
19 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 * copies of the Software, and to permit persons to whom the Software is
21 * furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included in
24 * all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 * THE SOFTWARE.
33 */
34 
35 #ifndef CIVETWEB_HEADER_INCLUDED
36 #define CIVETWEB_HEADER_INCLUDED
37 
38 #define CIVETWEB_VERSION "1.8"
39 
40 #ifndef CIVETWEB_API
41 #if defined(_WIN32)
42 #if defined(CIVETWEB_DLL_EXPORTS)
43 #define CIVETWEB_API __declspec(dllexport)
44 #elif defined(CIVETWEB_DLL_IMPORTS)
45 #define CIVETWEB_API __declspec(dllimport)
46 #else
47 #define CIVETWEB_API
48 #endif
49 #elif __GNUC__ >= 4
50 #define CIVETWEB_API __attribute__((visibility("default")))
51 #else
52 #define CIVETWEB_API
53 #endif
54 #endif
55 
56 #include <stdio.h>
57 #include <stddef.h>
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif /* __cplusplus */
62 
63 
64  struct mg_context; /* Handle for the HTTP service itself */
65  struct mg_connection; /* Handle for the individual connection */
66 
67 
68  /* This structure contains information about the HTTP request. */
69  struct mg_request_info {
70  const char *request_method; /* "GET", "POST", etc */
71  const char *request_uri; /* URL-decoded URI (absolute or relative,
72  * as in the request) */
73  const char *local_uri; /* URL-decoded URI (relative). Can be NULL
74  * if the request_uri does not address a
75  * resource at the server host. */
76  const char *uri; /* Deprecated: use local_uri instead */
77  const char *http_version; /* E.g. "1.0", "1.1" */
78  const char *query_string; /* URL part after '?', not including '?', or
79  NULL */
80  const char *remote_user; /* Authenticated user, or NULL if no auth
81  used */
82  char remote_addr[48]; /* Client's IP address as a string. */
83 
84 #if defined(MG_LEGACY_INTERFACE)
85  long remote_ip; /* Client's IP address. Deprecated: use remote_addr instead
86  */
87 #endif
88 
89  long long content_length; /* Length (in bytes) of the request body,
90  can be -1 if no length was given. */
91  int remote_port; /* Client's port */
92  int is_ssl; /* 1 if SSL-ed, 0 if not */
93  void *user_data; /* User data pointer passed to mg_start() */
94  void *conn_data; /* Connection-specific user data */
95 
96  int num_headers; /* Number of HTTP headers */
97  struct mg_header {
98  const char *name; /* HTTP header name */
99  const char *value; /* HTTP header value */
100  } http_headers[64]; /* Maximum 64 headers */
101  };
102 
103 
104  /* This structure needs to be passed to mg_start(), to let civetweb know
105  which callbacks to invoke. For a detailed description, see
106  https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md */
107  struct mg_callbacks {
108  /* Called when civetweb has received new HTTP request.
109  If the callback returns one, it must process the request
110  by sending valid HTTP headers and a body. Civetweb will not do
111  any further processing. Otherwise it must return zero.
112  Note that since V1.7 the "begin_request" function is called
113  before an authorization check. If an authorization check is
114  required, use a request_handler instead.
115  Return value:
116  0: civetweb will process the request itself. In this case,
117  the callback must not send any data to the client.
118  1-999: callback already processed the request. Civetweb will
119  not send any data after the callback returned. The
120  return code is stored as a HTTP status code for the
121  access log. */
122  int(*begin_request)(struct mg_connection *);
123 
124  /* Called when civetweb has finished processing request. */
125  void(*end_request)(const struct mg_connection *, int reply_status_code);
126 
127  /* Called when civetweb is about to log a message. If callback returns
128  non-zero, civetweb does not log anything. */
129  int(*log_message)(const struct mg_connection *, const char *message);
130 
131  /* Called when civetweb is about to log access. If callback returns
132  non-zero, civetweb does not log anything. */
133  int(*log_access)(const struct mg_connection *, const char *message);
134 
135  /* Called when civetweb initializes SSL library.
136  Parameters:
137  user_data: parameter user_data passed when starting the server.
138  Return value:
139  0: civetweb will set up the SSL certificate.
140  1: civetweb assumes the callback already set up the certificate.
141  -1: initializing ssl fails. */
142  int(*init_ssl)(void *ssl_context, void *user_data);
143 
144 #if defined(MG_LEGACY_INTERFACE)
145  /* Called when websocket request is received, before websocket handshake.
146  Return value:
147  0: civetweb proceeds with websocket handshake.
148  1: connection is closed immediately.
149  This callback is deprecated: Use mg_set_websocket_handler instead. */
150  int(*websocket_connect)(const struct mg_connection *);
151 
152  /* Called when websocket handshake is successfully completed, and
153  connection is ready for data exchange.
154  This callback is deprecated: Use mg_set_websocket_handler instead. */
155  void(*websocket_ready)(struct mg_connection *);
156 
157  /* Called when data frame has been received from the client.
158  Parameters:
159  bits: first byte of the websocket frame, see websocket RFC at
160  http://tools.ietf.org/html/rfc6455, section 5.2
161  data, data_len: payload, with mask (if any) already applied.
162  Return value:
163  1: keep this websocket connection open.
164  0: close this websocket connection.
165  This callback is deprecated: Use mg_set_websocket_handler instead. */
166  int(*websocket_data)(struct mg_connection *,
167  int bits,
168  char *data,
169  size_t data_len);
170 #endif /* MG_LEGACY_INTERFACE */
171 
172  /* Called when civetweb is closing a connection. The per-context mutex is
173  locked when this is invoked. This is primarily useful for noting when
174  a websocket is closing and removing it from any application-maintained
175  list of clients.
176  Using this callback for websocket connections is deprecated: Use
177  mg_set_websocket_handler instead. */
179 
180  /* Called when civetweb tries to open a file. Used to intercept file open
181  calls, and serve file data from memory instead.
182  Parameters:
183  path: Full path to the file to open.
184  data_len: Placeholder for the file size, if file is served from
185  memory.
186  Return value:
187  NULL: do not serve file from memory, proceed with normal file open.
188  non-NULL: pointer to the file contents in memory. data_len must be
189  initilized with the size of the memory block. */
190  const char *(*open_file)(const struct mg_connection *,
191  const char *path,
192  size_t *data_len);
193 
194  /* Called when civetweb is about to serve Lua server page, if
195  Lua support is enabled.
196  Parameters:
197  lua_context: "lua_State *" pointer. */
198  void(*init_lua)(const struct mg_connection *, void *lua_context);
199 
200  /* Called when civetweb has uploaded a file to a temporary directory as a
201  result of mg_upload() call.
202  Parameters:
203  file_name: full path name to the uploaded file. */
204  void(*upload)(struct mg_connection *, const char *file_name);
205 
206  /* Called when civetweb is about to send HTTP error to the client.
207  Implementing this callback allows to create custom error pages.
208  Parameters:
209  status: HTTP error status code.
210  Return value:
211  1: run civetweb error handler.
212  0: callback already handled the error. */
213  int(*http_error)(struct mg_connection *, int status);
214 
215  /* Called after civetweb context has been created, before requests
216  are processed.
217  Parameters:
218  ctx: context handle */
219  void(*init_context)(const struct mg_context *ctx);
220 
221  /* Called when civetweb context is deleted.
222  Parameters:
223  ctx: context handle */
224  void(*exit_context)(const struct mg_context *ctx);
225  };
226 
227 
228  /* Start web server.
229 
230  Parameters:
231  callbacks: mg_callbacks structure with user-defined callbacks.
232  options: NULL terminated list of option_name, option_value pairs that
233  specify Civetweb configuration parameters.
234 
235  Side-effects: on UNIX, ignores SIGCHLD and SIGPIPE signals. If custom
236  processing is required for these, signal handlers must be set up
237  after calling mg_start().
238 
239 
240  Example:
241  const char *options[] = {
242  "document_root", "/var/www",
243  "listening_ports", "80,443s",
244  NULL
245  };
246  struct mg_context *ctx = mg_start(&my_func, NULL, options);
247 
248  Refer to https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md
249  for the list of valid option and their possible values.
250 
251  Return:
252  web server context, or NULL on error. */
253  CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
254  void *user_data,
255  const char **configuration_options);
256 
257 
258  /* Stop the web server.
259 
260  Must be called last, when an application wants to stop the web server and
261  release all associated resources. This function blocks until all Civetweb
262  threads are stopped. Context pointer becomes invalid. */
263  CIVETWEB_API void mg_stop(struct mg_context *);
264 
265 
266  /* mg_request_handler
267 
268  Called when a new request comes in. This callback is URI based
269  and configured with mg_set_request_handler().
270 
271  Parameters:
272  conn: current connection information.
273  cbdata: the callback data configured with mg_set_request_handler().
274  Returns:
275  0: the handler could not handle the request, so fall through.
276  1 - 999: the handler processed the request. The return code is
277  stored as a HTTP status code for the access log. */
278  typedef int(*mg_request_handler)(struct mg_connection *conn, void *cbdata);
279 
280 
281  /* mg_set_request_handler
282 
283  Sets or removes a URI mapping for a request handler.
284  This function uses mg_lock_context internally.
285 
286  URI's are ordered and prefixed URI's are supported. For example,
287  consider two URIs: /a/b and /a
288  /a matches /a
289  /a/b matches /a/b
290  /a/c matches /a
291 
292  Parameters:
293  ctx: server context
294  uri: the URI (exact or pattern) for the handler
295  handler: the callback handler to use when the URI is requested.
296  If NULL, an already registered handler for this URI will be
297  removed.
298  The URI used to remove a handler must match exactly the one used
299  to
300  register it (not only a pattern match).
301  cbdata: the callback data to give to the handler when it is called. */
303  const char *uri,
305  void *cbdata);
306 
307 
308  /* Callback types for websocket handlers in C/C++.
309 
310  mg_websocket_connect_handler
311  Is called when the client intends to establish a websocket connection,
312  before websocket handshake.
313  Return value:
314  0: civetweb proceeds with websocket handshake.
315  1: connection is closed immediately.
316 
317  mg_websocket_ready_handler
318  Is called when websocket handshake is successfully completed, and
319  connection is ready for data exchange.
320 
321  mg_websocket_data_handler
322  Is called when a data frame has been received from the client.
323  Parameters:
324  bits: first byte of the websocket frame, see websocket RFC at
325  http://tools.ietf.org/html/rfc6455, section 5.2
326  data, data_len: payload, with mask (if any) already applied.
327  Return value:
328  1: keep this websocket connection open.
329  0: close this websocket connection.
330 
331  mg_connection_close_handler
332  Is called, when the connection is closed.*/
333  typedef int(*mg_websocket_connect_handler)(const struct mg_connection *,
334  void *);
335  typedef void(*mg_websocket_ready_handler)(struct mg_connection *, void *);
336  typedef int(*mg_websocket_data_handler)(struct mg_connection *,
337  int,
338  char *,
339  size_t,
340  void *);
342  void *);
343 
344 
345  /* mg_set_websocket_handler
346 
347  Set or remove handler functions for websocket connections.
348  This function works similar to mg_set_request_handler - see there. */
349  CIVETWEB_API void
351  const char *uri,
352  mg_websocket_connect_handler connect_handler,
353  mg_websocket_ready_handler ready_handler,
354  mg_websocket_data_handler data_handler,
355  mg_websocket_close_handler close_handler,
356  void *cbdata);
357 
358 
359  /* mg_authorization_handler
360 
361  Some description here
362 
363  Parameters:
364  conn: current connection information.
365  cbdata: the callback data configured with mg_set_request_handler().
366  Returns:
367  0: access denied
368  1: access granted
369  */
370  typedef int(*mg_authorization_handler)(struct mg_connection *conn,
371  void *cbdata);
372 
373 
374  /* mg_set_auth_handler
375 
376  Sets or removes a URI mapping for an authorization handler.
377  This function works similar to mg_set_request_handler - see there. */
379  const char *uri,
381  void *cbdata);
382 
383 
384  /* Get the value of particular configuration parameter.
385  The value returned is read-only. Civetweb does not allow changing
386  configuration at run time.
387  If given parameter name is not valid, NULL is returned. For valid
388  names, return value is guaranteed to be non-NULL. If parameter is not
389  set, zero-length string is returned. */
390  CIVETWEB_API const char *mg_get_option(const struct mg_context *ctx,
391  const char *name);
392 
393 
394  /* Get context from connection. */
395  CIVETWEB_API struct mg_context *
396  mg_get_context(const struct mg_connection *conn);
397 
398 
399  /* Get user data passed to mg_start from context. */
400  CIVETWEB_API void *mg_get_user_data(const struct mg_context *ctx);
401 
402 
403  /* Set user data for the current connection. */
405  void *data);
406 
407 
408  /* Get user data set for the current connection. */
409  CIVETWEB_API void *
410  mg_get_user_connection_data(const struct mg_connection *conn);
411 
412 
413 #if defined(MG_LEGACY_INTERFACE)
414  /* Return array of strings that represent valid configuration options.
415  For each option, option name and default value is returned, i.e. the
416  number of entries in the array equals to number_of_options x 2.
417  Array is NULL terminated. */
418  /* Deprecated: Use mg_get_valid_options instead. */
419  CIVETWEB_API const char **mg_get_valid_option_names(void);
420 #endif
421 
422 
423  struct mg_option {
424  const char *name;
425  int type;
426  const char *default_value;
427  };
428 
429 
430  enum {
438  };
439 
440 
441  /* Return array of struct mg_option, representing all valid configuration
442  options of civetweb.c.
443  The array is terminated by a NULL name option. */
444  CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
445 
446 
448  int protocol; /* 1 = IPv4, 2 = IPv6, 3 = both */
449  int port; /* port number */
450  int is_ssl; /* https port: 0 = no, 1 = yes */
451  int is_redirect; /* redirect all requests: 0 = no, 1 = yes */
456  };
457 
458 
459  /* Get the list of ports that civetweb is listening on.
460  The parameter size is the size of the ports array in elements.
461  The caller is responsibility to allocate the required memory.
462  This function returns the number of struct mg_server_ports elements
463  filled in, or <0 in case of an error. */
465  int size,
466  struct mg_server_ports *ports);
467 
468 
469  /* Deprecated: Use mg_get_server_ports instead. */
470  CIVETWEB_API size_t
471  mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl);
472 
473 
474  /* Add, edit or delete the entry in the passwords file.
475 
476  This function allows an application to manipulate .htpasswd files on the
477  fly by adding, deleting and changing user records. This is one of the
478  several ways of implementing authentication on the server side. For another,
479  cookie-based way please refer to the examples/chat in the source tree.
480 
481  If password is not NULL, entry is added (or modified if already exists).
482  If password is NULL, entry is deleted.
483 
484  Return:
485  1 on success, 0 on error. */
486  CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name,
487  const char *domain,
488  const char *user,
489  const char *password);
490 
491 
492  /* Return information associated with the request. */
493  CIVETWEB_API const struct mg_request_info *
494  mg_get_request_info(const struct mg_connection *);
495 
496 
497  /* Send data to the client.
498  Return:
499  0 when the connection has been closed
500  -1 on error
501  >0 number of bytes written on success */
502  CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len);
503 
504 
505  /* Send data to a websocket client wrapped in a websocket frame. Uses
506  mg_lock_connection to ensure that the transmission is not interrupted,
507  i.e., when the application is proactively communicating and responding to
508  a request simultaneously.
509 
510  Send data to a websocket client wrapped in a websocket frame.
511  This function is available when civetweb is compiled with -DUSE_WEBSOCKET
512 
513  Return:
514  0 when the connection has been closed
515  -1 on error
516  >0 number of bytes written on success */
518  int opcode,
519  const char *data,
520  size_t data_len);
521 
522 
523  /* Send data to a websocket server wrapped in a masked websocket frame. Uses
524  mg_lock_connection to ensure that the transmission is not interrupted,
525  i.e., when the application is proactively communicating and responding to
526  a request simultaneously.
527 
528  Send data to a websocket server wrapped in a masked websocket frame.
529  This function is available when civetweb is compiled with -DUSE_WEBSOCKET
530 
531  Return:
532  0 when the connection has been closed
533  -1 on error
534  >0 number of bytes written on success */
536  int opcode,
537  const char *data,
538  size_t data_len);
539 
540 
541  /* Blocks until unique access is obtained to this connection. Intended for use
542  with websockets only.
543  Invoke this before mg_write or mg_printf when communicating with a
544  websocket if your code has server-initiated communication as well as
545  communication in direct response to a message. */
546  CIVETWEB_API void mg_lock_connection(struct mg_connection *conn);
548 
549 
550 #if defined(MG_LEGACY_INTERFACE)
551 #define mg_lock mg_lock_connection
552 #define mg_unlock mg_unlock_connection
553 #endif
554 
555 
556  /* Lock server context. This lock may be used to protect resources
557  that are shared between different connection/worker threads. */
560 
561 
562  /* Opcodes, from http://tools.ietf.org/html/rfc6455 */
563  enum {
570  };
571 
572 
573  /* Macros for enabling compiler-specific checks for printf-like arguments. */
574 #undef PRINTF_FORMAT_STRING
575 #if defined(_MSC_VER) && _MSC_VER >= 1400
576 #include <sal.h>
577 #if defined(_MSC_VER) && _MSC_VER > 1400
578 #define PRINTF_FORMAT_STRING(s) _Printf_format_string_ s
579 #else
580 #define PRINTF_FORMAT_STRING(s) __format_string s
581 #endif
582 #else
583 #define PRINTF_FORMAT_STRING(s) s
584 #endif
585 
586 #ifdef __GNUC__
587 #define PRINTF_ARGS(x, y) __attribute__((format(printf, x, y)))
588 #else
589 #define PRINTF_ARGS(x, y)
590 #endif
591 
592 
593  /* Send data to the client using printf() semantics.
594  Works exactly like mg_write(), but allows to do message formatting. */
595  CIVETWEB_API int mg_printf(struct mg_connection *,
596  PRINTF_FORMAT_STRING(const char *fmt),
597  ...) PRINTF_ARGS(2, 3);
598 
599 
600  /* Send contents of the entire file together with HTTP headers. */
601  CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path);
602 
603  /* Send contents of the entire file together with HTTP headers.
604  Parameters:
605  conn: Current connection information.
606  path: Full path to the file to send.
607  mime_type: Content-Type for file. NULL will cause the type to be
608  looked up by the file extension.
609  */
610  CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn,
611  const char *path,
612  const char *mime_type);
613 
614  /* Store body data into a file. */
615  CIVETWEB_API long long mg_store_body(struct mg_connection *conn,
616  const char *path);
617  /* Read entire request body and stor it in a file "path".
618  Return:
619  < 0 Error
620  >= 0 Number of bytes stored in file "path".
621  */
622 
623 
624  /* Read data from the remote end, return number of bytes read.
625  Return:
626  0 connection has been closed by peer. No more data could be read.
627  < 0 read error. No more data could be read from the connection.
628  > 0 number of bytes read into the buffer. */
629  CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len);
630 
631 
632  /* Get the value of particular HTTP header.
633 
634  This is a helper function. It traverses request_info->http_headers array,
635  and if the header is present in the array, returns its value. If it is
636  not present, NULL is returned. */
638  const char *name);
639 
640 
641  /* Get a value of particular form variable.
642 
643  Parameters:
644  data: pointer to form-uri-encoded buffer. This could be either POST data,
645  or request_info.query_string.
646  data_len: length of the encoded data.
647  var_name: variable name to decode from the buffer
648  dst: destination buffer for the decoded variable
649  dst_len: length of the destination buffer
650 
651  Return:
652  On success, length of the decoded variable.
653  On error:
654  -1 (variable not found).
655  -2 (destination buffer is NULL, zero length or too small to hold the
656  decoded variable).
657 
658  Destination buffer is guaranteed to be '\0' - terminated if it is not
659  NULL or zero length. */
660  CIVETWEB_API int mg_get_var(const char *data,
661  size_t data_len,
662  const char *var_name,
663  char *dst,
664  size_t dst_len);
665 
666 
667  /* Get a value of particular form variable.
668 
669  Parameters:
670  data: pointer to form-uri-encoded buffer. This could be either POST data,
671  or request_info.query_string.
672  data_len: length of the encoded data.
673  var_name: variable name to decode from the buffer
674  dst: destination buffer for the decoded variable
675  dst_len: length of the destination buffer
676  occurrence: which occurrence of the variable, 0 is the first, 1 the
677  second...
678  this makes it possible to parse a query like
679  b=x&a=y&a=z which will have occurrence values b:0, a:0 and a:1
680 
681  Return:
682  On success, length of the decoded variable.
683  On error:
684  -1 (variable not found).
685  -2 (destination buffer is NULL, zero length or too small to hold the
686  decoded variable).
687 
688  Destination buffer is guaranteed to be '\0' - terminated if it is not
689  NULL or zero length. */
691  size_t data_len,
692  const char *var_name,
693  char *dst,
694  size_t dst_len,
695  size_t occurrence);
696 
697 
698  /* Fetch value of certain cookie variable into the destination buffer.
699 
700  Destination buffer is guaranteed to be '\0' - terminated. In case of
701  failure, dst[0] == '\0'. Note that RFC allows many occurrences of the same
702  parameter. This function returns only first occurrence.
703 
704  Return:
705  On success, value length.
706  On error:
707  -1 (either "Cookie:" header is not present at all or the requested
708  parameter is not found).
709  -2 (destination buffer is NULL, zero length or too small to hold the
710  value). */
711  CIVETWEB_API int mg_get_cookie(const char *cookie,
712  const char *var_name,
713  char *buf,
714  size_t buf_len);
715 
716 
717  /* Download data from the remote web server.
718  host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
719  port: port number, e.g. 80.
720  use_ssl: wether to use SSL connection.
721  error_buffer, error_buffer_size: error message placeholder.
722  request_fmt,...: HTTP request.
723  Return:
724  On success, valid pointer to the new connection, suitable for mg_read().
725  On error, NULL. error_buffer contains error message.
726  Example:
727  char ebuf[100];
728  struct mg_connection *conn;
729  conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
730  "%s", "GET / HTTP/1.0\r\nHost: google.com\r\n\r\n");
731  */
732  CIVETWEB_API struct mg_connection *
733  mg_download(const char *host,
734  int port,
735  int use_ssl,
736  char *error_buffer,
737  size_t error_buffer_size,
738  PRINTF_FORMAT_STRING(const char *request_fmt),
739  ...) PRINTF_ARGS(6, 7);
740 
741 
742  /* Close the connection opened by mg_download(). */
744 
745 
746  /* File upload functionality. Each uploaded file gets saved into a temporary
747  file and MG_UPLOAD event is sent.
748  Return number of uploaded files.
749  Deprecated: Use mg_handle_form_request instead. */
750  CIVETWEB_API int mg_upload(struct mg_connection *conn,
751  const char *destination_dir);
752 
753 
754  /* This structure contains callback functions for handling form fields.
755  It is used as an argument to mg_handle_form_request. */
757  /* This callback function is called, if a new field has been found.
758  * The return value of this callback is used to define how the field
759  * should be processed.
760  *
761  * Parameters:
762  * key: Name of the field ("name" property of the HTML input field).
763  * filename: Name of a file to upload, at the client computer.
764  * Only set for input fields of type "file", otherwise NULL.
765  * path: Output parameter: File name (incl. path) to store the file
766  * at the server computer. Only used if FORM_FIELD_STORAGE_STORE
767  * is returned by this callback. Existing files will be
768  * overwritten.
769  * pathlen: Length of the buffer for path.
770  * user_data: Value of the member user_data of mg_form_data_handler
771  *
772  * Return value:
773  * The callback must return the intended storage for this field
774  * (See FORM_FIELD_STORAGE_*).
775  */
776  int(*field_found)(const char *key,
777  const char *filename,
778  char *path,
779  size_t pathlen,
780  void *user_data);
781 
782  /* If the "field_found" callback returned FORM_FIELD_STORAGE_GET,
783  * this callback will receive the field data.
784  *
785  * Parameters:
786  * key: Name of the field ("name" property of the HTML input field).
787  * value: Value of the input field.
788  * user_data: Value of the member user_data of mg_form_data_handler
789  *
790  * Return value:
791  * TODO: Needs to be defined.
792  */
793  int(*field_get)(const char *key,
794  const char *value,
795  size_t valuelen,
796  void *user_data);
797 
798  /* If the "field_found" callback returned FORM_FIELD_STORAGE_STORE,
799  * the data will be stored into a file. If the file has been written
800  * successfully, this callback will be called. This callback will
801  * not be called for only partially uploaded files. The
802  * mg_handle_form_request function will either store the file completely
803  * and call this callback, or it will remove any partial content and
804  * not call this callback function.
805  *
806  * Parameters:
807  * path: Path of the file stored at the server.
808  * file_size: Size of the stored file in bytes.
809  * user_data: Value of the member user_data of mg_form_data_handler
810  *
811  * Return value:
812  * TODO: Needs to be defined.
813  */
814  int(*field_store)(const char *path, size_t file_size, void *user_data);
815 
816  /* User supplied argument, passed to all callback functions. */
817  void *user_data;
818  };
819 
820 
821  /* Return values definition for the "field_found" callback in
822  * mg_form_data_handler. */
823  enum {
824  /* Skip this field (neither get nor store it). Continue with the
825  * next field. */
827  /* Get the field value. */
829  /* Store the field value into a file. */
831  /* Stop parsing this request. Skip the remaining fields. */
833  };
834 
835 
836  /* Process form data.
837  * Returns the number of fields handled, or < 0 in case of an error.
838  * Note: It is possible that several fields are already handled successfully
839  * (e.g., stored into files), before the request handling is stopped with an
840  * error. In this case a number < 0 is returned as well.
841  * In any case, it is the duty of the caller to remove files once they are
842  * no longer required. */
844  struct mg_form_data_handler *fdh);
845 
846 
847  /* Convenience function -- create detached thread.
848  Return: 0 on success, non-0 on error. */
849  typedef void *(*mg_thread_func_t)(void *);
851 
852 
853  /* Return builtin mime type for the given file name.
854  For unrecognized extensions, "text/plain" is returned. */
855  CIVETWEB_API const char *mg_get_builtin_mime_type(const char *file_name);
856 
857 
858  /* Return Civetweb version. */
859  CIVETWEB_API const char *mg_version(void);
860 
861 
862  /* URL-decode input buffer into destination buffer.
863  0-terminate the destination buffer.
864  form-url-encoded data differs from URI encoding in a way that it
865  uses '+' as character for space, see RFC 1866 section 8.2.1
866  http://ftp.ics.uci.edu/pub/ietf/html/rfc1866.txt
867  Return: length of the decoded data, or -1 if dst buffer is too small. */
868  CIVETWEB_API int mg_url_decode(const char *src,
869  int src_len,
870  char *dst,
871  int dst_len,
872  int is_form_url_encoded);
873 
874 
875  /* URL-encode input buffer into destination buffer.
876  returns the length of the resulting buffer or -1
877  is the buffer is too small. */
878  CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len);
879 
880 
881  /* MD5 hash given strings.
882  Buffer 'buf' must be 33 bytes long. Varargs is a NULL terminated list of
883  ASCIIz strings. When function returns, buf will contain human-readable
884  MD5 hash. Example:
885  char buf[33];
886  mg_md5(buf, "aa", "bb", NULL); */
887  CIVETWEB_API char *mg_md5(char buf[33], ...);
888 
889 
890  /* Print error message to the opened error log stream.
891  This utilizes the provided logging configuration.
892  conn: connection
893  fmt: format string without the line return
894  ...: variable argument list
895  Example:
896  mg_cry(conn,"i like %s", "logging"); */
897  CIVETWEB_API void mg_cry(const struct mg_connection *conn,
898  PRINTF_FORMAT_STRING(const char *fmt),
899  ...) PRINTF_ARGS(2, 3);
900 
901 
902  /* utility method to compare two buffers, case incensitive. */
903  CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len);
904 
905 
906  /* Connect to a websocket as a client
907  Parameters:
908  host: host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or
909  "localhost"
910  port: server port
911  use_ssl: make a secure connection to server
912  error_buffer, error_buffer_size: buffer for an error message
913  path: server path you are trying to connect to, i.e. if connection to
914  localhost/app, path should be "/app"
915  origin: value of the Origin HTTP header
916  data_func: callback that should be used when data is received from the
917  server
918  user_data: user supplied argument
919 
920  Return:
921  On success, valid mg_connection object.
922  On error, NULL. Se error_buffer for details.
923  */
924  CIVETWEB_API struct mg_connection *
926  int port,
927  int use_ssl,
928  char *error_buffer,
929  size_t error_buffer_size,
930  const char *path,
931  const char *origin,
932  mg_websocket_data_handler data_func,
934  void *user_data);
935 
936 
937  /* Connect to a TCP server as a client (can be used to connect to a HTTP server)
938  Parameters:
939  host: host to connect to, i.e. "www.wikipedia.org" or "192.168.1.1" or
940  "localhost"
941  port: server port
942  use_ssl: make a secure connection to server
943  error_buffer, error_buffer_size: buffer for an error message
944 
945  Return:
946  On success, valid mg_connection object.
947  On error, NULL. Se error_buffer for details.
948  */
950  int port,
951  int use_ssl,
952  char *error_buffer,
953  size_t error_buffer_size);
954 
955 
957  const char *host;
958  int port;
959  const char *client_cert;
960  const char *server_cert;
961  /* TODO: add more data */
962  };
963 
964 
965  CIVETWEB_API struct mg_connection *
966  mg_connect_client_secure(const struct mg_client_options *client_options,
967  char *error_buffer,
968  size_t error_buffer_size);
969 
970 
971  enum { TIMEOUT_INFINITE = -1 };
972 
973 
974  /* Wait for a response from the server
975  Parameters:
976  conn: connection
977  ebuf, ebuf_len: error message placeholder.
978  timeout: time to wait for a response in milliseconds (if < 0 then wait
979  forever)
980 
981  Return:
982  On success, >= 0
983  On error/timeout, < 0
984  */
985  CIVETWEB_API int mg_get_response(struct mg_connection *conn,
986  char *ebuf,
987  size_t ebuf_len,
988  int timeout);
989 
990 
991  /* Check which features where set when civetweb has been compiled.
992  Parameters:
993  feature: specifies which feature should be checked
994  1 serve files (NO_FILES not set)
995  2 support HTTPS (NO_SSL not set)
996  4 support CGI (NO_CGI not set)
997  8 support IPv6 (USE_IPV6 set)
998  16 support WebSocket (USE_WEBSOCKET set)
999  32 support Lua scripts and Lua server pages (USE_LUA is set)
1000  64 support server side JavaScript (USE_DUKTAPE is set)
1001  The result is undefined for all other feature values.
1002 
1003  Return:
1004  If feature is available > 0
1005  If feature is not available = 0
1006  */
1007  CIVETWEB_API unsigned mg_check_feature(unsigned feature);
1008 
1009 
1010 #ifdef __cplusplus
1011 }
1012 #endif /* __cplusplus */
1013 
1014 #endif /* CIVETWEB_HEADER_INCLUDED */
int port
Definition: civetweb.h:958
Definition: civetweb.h:828
const char * http_version
Definition: civetweb.h:77
CIVETWEB_API void * mg_get_user_connection_data(const struct mg_connection *conn)
Definition: civetweb.c:1745
int(* log_access)(const struct mg_connection *, const char *message)
Definition: civetweb.h:133
CIVETWEB_API const struct mg_option * mg_get_valid_options(void)
Definition: civetweb.c:1458
const char * mime_type
Definition: civetweb.c:4910
GLuint const GLchar * name
Definition: glext.h:6671
CIVETWEB_API int mg_get_cookie(const char *cookie, const char *var_name, char *buf, size_t buf_len)
Definition: civetweb.c:4405
CIVETWEB_API void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
Definition: civetweb.c:9537
GLbitfield GLuint64 timeout
Definition: glext.h:7831
#define file_name
Definition: ps3_defines.h:291
Definition: civetweb.h:971
#define const
Definition: zconf.h:217
static const unsigned char password[MAX_TESTS][32]
Definition: pkcs5.c:305
Definition: civetweb.h:756
CIVETWEB_API int mg_websocket_client_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
Definition: civetweb.h:107
CIVETWEB_API void * mg_get_user_data(const struct mg_context *ctx)
Definition: civetweb.c:1729
#define file_size
Definition: ps3_defines.h:293
int _reserved1
Definition: civetweb.h:452
int _reserved4
Definition: civetweb.h:455
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:9557
CIVETWEB_API const char * mg_get_builtin_mime_type(const char *file_name)
Definition: civetweb.c:5009
int _reserved2
Definition: civetweb.h:453
void(* init_lua)(const struct mg_connection *, void *lua_context)
Definition: civetweb.h:198
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
int remote_port
Definition: civetweb.h:91
int(* mg_websocket_connect_handler)(const struct mg_connection *, void *)
Definition: civetweb.h:333
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:11557
GLsizei const GLchar ** path
Definition: glext.h:7901
const char * request_method
Definition: civetweb.h:70
void(* connection_close)(const struct mg_connection *)
Definition: civetweb.h:178
GLenum GLsizei len
Definition: glext.h:7389
CIVETWEB_API int mg_write(struct mg_connection *, const void *buf, size_t len)
Definition: civetweb.c:4123
int(* http_error)(struct mg_connection *, int status)
Definition: civetweb.h:213
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:4302
int(* mg_websocket_data_handler)(struct mg_connection *, int, char *, size_t, void *)
Definition: civetweb.h:336
int(* log_message)(const struct mg_connection *, const char *message)
Definition: civetweb.h:129
GLsizeiptr size
Definition: glext.h:6559
int(* mg_request_handler)(struct mg_connection *conn, void *cbdata)
Definition: civetweb.h:278
GLfloat f
Definition: glext.h:8207
int protocol
Definition: civetweb.h:448
int is_redirect
Definition: civetweb.h:451
#define ssl_context
Definition: compat-1.3.h:2276
int type
Definition: civetweb.h:425
Definition: civetweb.h:437
includes all by default used to find thumbnails Please choose a single playlist first Add Entry Add Folder Select Files< multiple > Please fill out all required fields RetroArch updated successfully Please restart the application for the changes to take effect Contributors Move Down Load Remove Add Pass No shader passes Reset All Passes Download thumbnail Start on Download All Thumbnails This Playlist Configured in port
Definition: msg_hash_us.h:7699
Definition: civetweb.h:447
CIVETWEB_API struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **configuration_options)
Definition: civetweb.c:12793
int num_headers
Definition: civetweb.h:96
CIVETWEB_API const struct mg_request_info * mg_get_request_info(const struct mg_connection *)
Definition: civetweb.c:1949
static void close_func(LexState *ls)
Definition: lparser.c:552
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:11978
CIVETWEB_API void CIVETWEB_API int mg_strncasecmp(const char *s1, const char *s2, size_t len)
Definition: civetweb.c:1562
CIVETWEB_API void mg_set_auth_handler(struct mg_context *ctx, const char *uri, mg_authorization_handler handler, void *cbdata)
Definition: civetweb.c:9582
Definition: civetweb.h:832
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
Definition: ibxm.h:9
void(* end_request)(const struct mg_connection *, int reply_status_code)
Definition: civetweb.h:125
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
const char * name
Definition: civetweb.h:98
CIVETWEB_API int mg_handle_form_request(struct mg_connection *conn, struct mg_form_data_handler *fdh)
Definition: handle_form.inl:155
CIVETWEB_API void mg_send_mime_file(struct mg_connection *conn, const char *path, const char *mime_type)
Definition: civetweb.c:6616
CIVETWEB_API void mg_set_user_connection_data(const struct mg_connection *conn, void *data)
Definition: civetweb.c:1736
void(* mg_websocket_close_handler)(const struct mg_connection *, void *)
Definition: civetweb.h:341
void * conn_data
Definition: civetweb.h:94
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:11545
Definition: civetweb.h:568
CIVETWEB_API const char * mg_get_header(const struct mg_connection *, const char *name)
Definition: civetweb.c:2042
const char * request_uri
Definition: civetweb.h:71
int port
Definition: civetweb.h:449
void(* init_context)(const struct mg_context *ctx)
Definition: civetweb.h:219
CIVETWEB_API int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout)
Definition: civetweb.c:11856
struct mg_request_info::mg_header http_headers[64]
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
const char * name
Definition: civetweb.h:424
CIVETWEB_API int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
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 char * mg_md5(char buf[33],...)
Definition: civetweb.c:5077
const char * remote_user
Definition: civetweb.h:80
Definition: civetweb.h:567
Definition: civetweb.h:432
const char * local_uri
Definition: civetweb.h:73
const char * default_value
Definition: civetweb.h:426
Definition: civetweb.h:569
const char * query_string
Definition: civetweb.h:78
CIVETWEB_API struct mg_context * mg_get_context(const struct mg_connection *conn)
Definition: civetweb.c:1722
CIVETWEB_API void mg_lock_context(struct mg_context *ctx)
Definition: civetweb.c:8381
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:6233
CIVETWEB_API size_t mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl)
Definition: civetweb.c:1755
Definition: civetweb.h:431
CIVETWEB_API struct mg_connection CIVETWEB_API void mg_close_connection(struct mg_connection *conn)
Definition: civetweb.c:11374
void(* exit_context)(const struct mg_context *ctx)
Definition: civetweb.h:224
GLenum src
Definition: glext.h:6980
const char * server_cert
Definition: civetweb.h:960
Definition: civetweb.h:434
CIVETWEB_API int mg_start_thread(mg_thread_func_t f, void *p)
Definition: civetweb.c:3440
Definition: civetweb.h:565
Definition: civetweb.h:826
CIVETWEB_API void mg_cry(const struct mg_connection *conn, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
const char * uri
Definition: civetweb.h:76
struct mg_callbacks callbacks
Definition: civetweb.c:1223
char remote_addr[48]
Definition: civetweb.h:82
GLfloat GLfloat p
Definition: glext.h:9809
CIVETWEB_API void mg_unlock_context(struct mg_context *ctx)
Definition: civetweb.c:8389
Definition: civetweb.h:566
CIVETWEB_API int CIVETWEB_API void mg_send_file(struct mg_connection *conn, const char *path)
Definition: civetweb.c:6610
const char * host
Definition: civetweb.h:957
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:4335
Definition: civetweb.h:97
CIVETWEB_API int mg_modify_passwords_file(const char *passwords_file_name, const char *domain, const char *user, const char *password)
Definition: civetweb.c:5603
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:11836
void * user_data
Definition: civetweb.c:1224
const char * value
Definition: civetweb.h:99
int(* begin_request)(struct mg_connection *)
Definition: civetweb.h:122
CIVETWEB_API const char * mg_get_option(const struct mg_context *ctx, const char *name)
Definition: civetweb.c:1706
void(* mg_websocket_ready_handler)(struct mg_connection *, void *)
Definition: civetweb.h:335
CIVETWEB_API int mg_printf(struct mg_connection *, PRINTF_FORMAT_STRING(const char *fmt),...) PRINTF_ARGS(2
CIVETWEB_API int mg_read(struct mg_connection *, void *buf, size_t len)
Definition: civetweb.c:4042
Definition: civetweb.h:564
Definition: civetweb.h:435
void *(* mg_thread_func_t)(void *)
Definition: civetweb.h:849
int data_len
Definition: civetweb.c:1293
int is_ssl
Definition: civetweb.h:92
JSON_Parser_EncodingDetectedHandler handler
Definition: jsonsax_full.h:561
Definition: civetweb.h:956
Definition: civetweb.c:1266
int _reserved3
Definition: civetweb.h:454
CIVETWEB_API int mg_url_encode(const char *src, char *dst, size_t dst_len)
Definition: civetweb.c:5888
CIVETWEB_API void mg_unlock_connection(struct mg_connection *conn)
Definition: civetweb.c:8373
const char * client_cert
Definition: civetweb.h:959
CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server_ports *ports)
Definition: civetweb.c:1770
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:4346
void * user_data
Definition: civetweb.h:93
GLsizei const GLfloat * value
Definition: glext.h:6709
CIVETWEB_API const char * mg_version(void)
Definition: civetweb.c:1942
void(* upload)(struct mg_connection *, const char *file_name)
Definition: civetweb.h:204
CIVETWEB_API int mg_upload(struct mg_connection *conn, const char *destination_dir)
Definition: civetweb.c:9304
int is_ssl
Definition: civetweb.h:450
GLenum GLenum dst
Definition: glext.h:6980
#define CIVETWEB_API
Definition: civetweb.h:52
CIVETWEB_API long long mg_store_body(struct mg_connection *conn, const char *path)
Definition: civetweb.c:6701
#define PRINTF_FORMAT_STRING(s)
Definition: civetweb.h:583
CIVETWEB_API void mg_lock_connection(struct mg_connection *conn)
Definition: civetweb.c:8365
Definition: civetweb.h:433
#define PRINTF_ARGS(x, y)
Definition: civetweb.h:589
Definition: civetweb.c:1219
Definition: civetweb.h:830
void * user_data
Definition: civetweb.h:817
Definition: civetweb.h:436
CIVETWEB_API unsigned mg_check_feature(unsigned feature)
Definition: civetweb.c:13016
long long content_length
Definition: civetweb.h:89
int(* mg_authorization_handler)(struct mg_connection *conn, void *cbdata)
Definition: civetweb.h:370
Definition: civetweb.h:423
int(* init_ssl)(void *ssl_context, void *user_data)
Definition: civetweb.h:142
Definition: civetweb.h:69
CIVETWEB_API void mg_stop(struct mg_context *)
Definition: civetweb.c:12719