civetweb.h 67 KB

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