Coverage Report

Created: 2026-07-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mhd2/src/include/microhttpd2.h
Line
Count
Source
1
/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
2
/*
3
  This file is part of GNU libmicrohttpd.
4
  Copyright (C) 2006-2026 Christian Grothoff, Karlson2k (Evgeny Grin)
5
  (and other contributing authors)
6
7
  GNU libmicrohttpd is free software; you can redistribute it and/or
8
  modify it under the terms of the GNU Lesser General Public
9
  License as published by the Free Software Foundation; either
10
  version 2.1 of the License, or (at your option) any later version.
11
12
  GNU libmicrohttpd is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
  Lesser General Public License for more details.
16
17
  Alternatively, you can redistribute GNU libmicrohttpd and/or
18
  modify it under the terms of the GNU General Public License as
19
  published by the Free Software Foundation; either version 2 of
20
  the License, or (at your option) any later version, together
21
  with the eCos exception, as follows:
22
23
    As a special exception, if other files instantiate templates or
24
    use macros or inline functions from this file, or you compile this
25
    file and link it with other works to produce a work based on this
26
    file, this file does not by itself cause the resulting work to be
27
    covered by the GNU General Public License. However the source code
28
    for this file must still be made available in accordance with
29
    section (3) of the GNU General Public License v2.
30
31
    This exception does not invalidate any other reasons why a work
32
    based on this file might be covered by the GNU General Public
33
    License.
34
35
  You should have received copies of the GNU Lesser General Public
36
  License and the GNU General Public License along with this library;
37
  if not, see <https://www.gnu.org/licenses/>.
38
*/
39
40
/*
41
  Main goals for the libmicrohttpd 2.0 API:
42
43
  - simplify application callbacks by splitting header/upload/post
44
    functionality currently provided by calling the same
45
    MHD_AccessHandlerCallback 3+ times into separate callbacks.
46
  - keep the API very simple for simple requests, but allow
47
    more complex logic to be incrementally introduced
48
    (via new struct MHD_Action construction)
49
  - avoid repeated scans for URL matches via the new
50
    struct MHD_Action construction
51
  - better types, in particular avoid varargs for options
52
  - make it harder to pass inconsistent options
53
  - combine options and flags into more uniform API (at least
54
    exterally!)
55
  - simplify API use by using sane defaults (benefiting from
56
    breaking backwards compatibility) and making all options
57
    really optional, and where applicable avoid having options
58
    where the default works if nothing is specified
59
  - simplify API by moving rarely used http_version into
60
    MHD_request_get_info_fixed()
61
  - avoid 'int' for MHD_YES/MHD_NO by introducing `enum MHD_Bool`
62
  - improve terminology by eliminating confusion between
63
    'request' and 'connection'; add 'session' for HTTP2/3;
64
    use clear separation between connection and request. Do not mix the kind
65
    data in the callbacks.  Currently we are mixing things in
66
    MHD_AccessHandlerCallback and MHD_RequestCompletedCallback. Instead of
67
    pointers to struct MHD_Connection we should use pointers to (new) struct
68
    MHD_Request.
69
  - prepare API for having multiple TLS backends
70
  - use more consistent prefixes for related functions
71
    by using MHD_subject_verb_object naming convention, also
72
    at the same time avoid symbol conflict with legacy names
73
    (so we can have one binary implementing old and new
74
    library API at the same time via compatibility layer).
75
  - make it impossible to queue a response at the wrong time
76
  - make it impossible to suspend a connection/request at the
77
    wrong time (improves thread-safety)
78
  - make it clear which response status codes are "properly"
79
    supported (include the descriptive string) by using an enum;
80
  - simplify API for common-case of one-shot responses by
81
    eliminating need for destroy response in most cases;
82
  - avoid fixed types, like uint32_t. They may not exist on some
83
    platforms. Instead use uint_fast32_t.
84
    It is also better for future-proof.
85
  - check portability for embedded platforms. Some of them support
86
    64 bits, but 'int' could be just 16 bits resulting of silently
87
    dropping enum values higher than 65535.
88
    => in general, more functions, fewer enums for setup
89
  - Avoid returning pointers to internal members. It is not thread-safe and
90
    even in single thread the value could change over the time. Prefer pointers to
91
    app-allocated memory with the size, like MHD_daemon_get_static_info(enum
92
    MHD_enum_name info_type, void *buf, size_t buf_size).
93
    => Except in cases where zero-copy matters.
94
  - Use separate app calls/functions for data the will not change for the
95
    lifetime of the object and dynamic data. The only difference should be the
96
    name. Like MHD_daemon_get_static_info(enum MHD_enum_name info_type, void *buf,
97
    size_t buf_size) MHD_daemon_get_dynamic_info(enum MHD_enum_name info_type,
98
    void *buf, size_t buf_size) Examples of static data: listen socket, number of
99
    workers, daemon flags.  Examples of dynamic data: number of connections,
100
    quiesce status.  It should give a clear idea whether the data could be changed
101
    over the time (could be not obvious for some data) and thus may change the
102
    approach how to use the data in app.  The same for: library, daemon,
103
    connection, request. Not sure that dynamic data makes sense for the library.
104
  - Define response code in response object. There are a very little
105
    chance that response body designed for 404 or 403 codes will be used with
106
    200 code. However, the responses body for 307 and 308 could be the same. So:
107
    Add default response code in response object.
108
  - Make responses unmodifiable after first use. It is not thread-safe.
109
    MHD-generated headers (Date, Connection/Keep-Alive) are again
110
    part of the *request* and do not count as part of the "response" here.
111
  - Remove "footers" from responses. With unmodifiable responses everything should
112
    be "headers". Add footers to *requests* instead.
113
  - Add API for adding request-specific response headers and footers. To
114
    simplify the things it should just copy the strings (to avoid dealing with
115
    complicated deinit of possible dynamic strings).  After this change it should
116
    be possible to simplify DAuth handling as response could be reused (currently
117
    403 responses are modified for each reply).
118
  - Control response behaviour mainly by response flags, not by additional
119
    headers (like MHD_RF_FORCE_CLOSE instead of "Connection: close").
120
    It is easier&faster for both: app and MHD.
121
  - Move response codes from MHD_HTTP_xxx namespace to MHD_HTTP_CODE_xxx
122
    namespace. It already may clash with other HTTP values.
123
  - Postprocessor is unusable night-mare when doing "stream processing"
124
    for tiny values where the application basically has to copy together
125
    the stream back into a single compact heap value, just making the
126
    parsing highly more complicated (see examples in Challenger)
127
  - non-stream processing variant for request bodies, give apps a
128
    way to request the full body in one buffer; give apps a way
129
    to request a 'large new allocation' for such buffers; give apps
130
    a way to specify a global quota for large allocations to ensure
131
    memory usage has a hard bound
132
133
  - Internals: carefully check where locking is really required. Probably
134
    separate locks. Check out-of-thread value reading. Currently code assumes
135
    atomic reading of values used in other threads, which mostly true on x86,
136
    but not OK on other arches. Probably use read/write locking to minimize
137
    the threads interference.
138
  - Internals: figure out how to do portable variant of cork/uncork
139
  - Internals: remove request data from memory pool when response is queued
140
    (IF no callbacks and thus data cannot be used anymore, or IF
141
     application permits explicitly per daemon) to get more space
142
    for building response;
143
  - Internals: Fix TCP FIN graceful closure issue for upgraded
144
    connections (API implications?)
145
146
*/
147
148
#ifndef MICROHTTPD2_H
149
#define MICROHTTPD2_H
150
151
#ifndef __cplusplus
152
#  define MHD_C_DECLARATIONS_START_HERE_   /* Empty */
153
#  define MHD_C_DECLARATIONS_FINISH_HERE_  /* Empty */
154
#else  /* __cplusplus */
155
/* *INDENT-OFF* */
156
#  define MHD_C_DECLARATIONS_START_HERE_   extern "C" {
157
#  define MHD_C_DECLARATIONS_FINISH_HERE_  }
158
/* *INDENT-ON* */
159
#endif /* __cplusplus */
160
161
MHD_C_DECLARATIONS_START_HERE_
162
163
/**
164
 * Current version of the library in packed BCD form.
165
 * (For example, version 1.9.30-1 would be 0x01093001)
166
 */
167
#define MHD_VERSION 0x01990001
168
169
#include "microhttpd2_portability.h"
170
171
/* If generic headers do not work on your platform, include headers that
172
   define 'va_list', 'size_t', 'uint_least16_t', 'uint_fast32_t',
173
   'uint_fast64_t', and 'struct sockaddr', and then
174
   add "#define MHD_HAVE_SYS_HEADERS_INCLUDED" before including "microhttpd2.h".
175
   When 'MHD_HAVE_SYS_HEADERS_INCLUDED' is defined, the following "standard"
176
   includes will not be used (which might be a good idea, especially on
177
   platforms where they do not exist).
178
   */
179
#ifndef MHD_HAVE_SYS_HEADERS_INCLUDED
180
#  include <stdarg.h>
181
#  ifndef MHD_SYS_BASE_TYPES_H
182
/* Headers for uint_fastXX_t, size_t */
183
#    include <stdint.h>
184
#    include <stddef.h>
185
#    include <sys/types.h> /* This header is actually optional */
186
#  endif
187
#  ifndef MHD_SYS_SOCKET_TYPES_H
188
/* Headers for 'struct sockaddr' */
189
#    if !defined(_WIN32) || defined(__CYGWIN__)
190
#      include <sys/socket.h>
191
#    else
192
/* Prevent conflict of <winsock.h> and <winsock2.h> */
193
#      if !defined(_WINSOCK2API_) && !defined(_WINSOCKAPI_)
194
#        ifndef WIN32_LEAN_AND_MEAN
195
/* Do not use unneeded parts of W32 headers. */
196
#          define WIN32_LEAN_AND_MEAN 1
197
#        endif /* !WIN32_LEAN_AND_MEAN */
198
#        include <winsock2.h>
199
#      endif
200
#    endif
201
#  endif
202
#endif
203
204
#ifndef MHD_BOOL_DEFINED
205
206
/**
207
 * Representation of 'bool' in the public API as stdbool.h may not
208
 * always be available and presence of 'bool' keyword may depend on
209
 * used C version.
210
 * It is always safe to cast 'MHD_Bool' variable to 'bool' and vice versa.
211
 * Note: it may be UNSAFE to cast pointers 'MHD_Bool*' to 'bool*' and
212
 *       vice versa.
213
 */
214
enum MHD_Bool
215
{
216
217
  /**
218
   * MHD-internal return code for "NO".
219
   */
220
  MHD_NO = 0
221
  ,
222
  /**
223
   * MHD-internal return code for "YES".  All non-zero values
224
   * will be interpreted as "YES", but MHD will only ever
225
   * return #MHD_YES or #MHD_NO.
226
   */
227
  MHD_YES = 1
228
};
229
230
231
#  define MHD_BOOL_DEFINED 1
232
#endif /* ! MHD_BOOL_DEFINED */
233
234
#ifndef MHD_STRINGS_DEFINED
235
236
237
/**
238
 * String with length data.
239
 * This type should always have valid @a cstr pointer.
240
 */
241
struct MHD_String
242
{
243
  /**
244
   * Number of characters in @e str, not counting 0-termination.
245
   */
246
  size_t len;
247
248
  /**
249
   * 0-terminated C-string.
250
   * Must not be NULL.
251
   */
252
  const char *cstr;
253
};
254
255
/**
256
 * String with length data.
257
 * This type of data may have NULL as the @a cstr pointer.
258
 */
259
struct MHD_StringNullable
260
{
261
  /**
262
   * Number of characters in @e cstr, not counting 0-termination.
263
   * If @a cstr is NULL, it must be zero.
264
   */
265
  size_t len;
266
267
  /**
268
   * 0-terminated C-string.
269
   * In some cases it could be NULL.
270
   */
271
  const char *cstr;
272
};
273
274
#  define MHD_STRINGS_DEFINED 1
275
#endif /* ! MHD_STRINGS_DEFINED */
276
277
278
#ifndef MHD_INVALID_SOCKET
279
#  if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
280
#    define MHD_SOCKETS_KIND_POSIX 1
281
/**
282
 * MHD_Socket is a type for socket FDs
283
 */
284
typedef int MHD_Socket;
285
#    define MHD_INVALID_SOCKET (-1)
286
#  else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
287
#    define MHD_SOCKETS_KIND_WINSOCK 1
288
/**
289
 * MHD_Socket is a type for socket FDs
290
 */
291
typedef SOCKET MHD_Socket;
292
#    define MHD_INVALID_SOCKET (INVALID_SOCKET)
293
#  endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
294
#endif /* MHD_INVALID_SOCKET */
295
296
297
/**
298
 * Constant used to indicate unknown size (use when creating a response).
299
 * Any possible larger sizes are interpreted as the same value.
300
 */
301
#ifdef UINT64_MAX
302
8
#  define MHD_SIZE_UNKNOWN UINT64_MAX
303
#else
304
#  define MHD_SIZE_UNKNOWN \
305
          MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU)
306
#endif
307
308
309
/**
310
 * Constant used to indicate unlimited wait time.
311
 * Any possible larger values are interpreted as this value.
312
 */
313
#ifdef UINT64_MAX
314
#  define MHD_WAIT_INDEFINITELY UINT64_MAX
315
#else
316
#  define MHD_WAIT_INDEFINITELY \
317
          MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU)
318
#endif
319
320
321
/* ********** (a) Core HTTP Processing ************ */
322
323
324
/**
325
 * @brief Handle for a daemon that listens for requests.
326
 *
327
 * Manages the listen socket, event loop, optional threads and server
328
 * settings.
329
 *
330
 * @defgroup daemon HTTP server handling client connections
331
 */
332
struct MHD_Daemon;
333
334
335
/**
336
 * @brief Handle/identifier of a network connection abstraction.
337
 *
338
 * A single network (i.e. TCP) connection can be used for
339
 * a single (in HTTP/1.1) data stream.
340
 *
341
 * @defgroup connection client connection with streams
342
 */
343
struct MHD_Connection;
344
345
346
/**
347
 * @brief Handle/identifier of a data stream over network
348
 * connection.
349
 *
350
 * A data stream may be used for multiple requests, which
351
 * in HTTP/1.1 must be processed sequentially.
352
 *
353
 * @defgroup stream stream of HTTP requests
354
 */
355
struct MHD_Stream;
356
357
/**
358
 * @brief Handle representing an HTTP request.
359
 *
360
 * With HTTP/1.1, multiple requests can be run over the same
361
 * stream.  However, MHD will only show one request per data
362
 * stream to the client at any given time.
363
 *
364
 * Replaces `struct MHD_Connection` in the API prior to version 2.0.0,
365
 * renamed to better reflect what this object truly represents to
366
 * the application using MHD.
367
 *
368
 * @defgroup request HTTP requests
369
 */
370
struct MHD_Request;
371
372
373
/**
374
 * @brief Actions are returned by the application when processed client header
375
 * to drive the request handling of MHD.
376
 *
377
 * @defgroup action Request actions
378
 */
379
struct MHD_Action;
380
381
382
/**
383
 * @brief Actions are returned by the application when processing client upload
384
 * to drive the request handling of MHD.
385
 *
386
 * @defgroup action Request actions
387
 */
388
struct MHD_UploadAction;
389
390
/**
391
 * @defgroup general Primary MHD functions and data
392
 */
393
394
/**
395
 * @defgroup specialized Introspection and other special control
396
 */
397
398
/**
399
 * @defgroup authentication Digest and other HTTP authentications
400
 */
401
402
403
/**
404
 * Status codes returned by API functions, also used for logging.
405
 *
406
 * As a return value, zero (#MHD_SC_OK) always indicates success.
407
 * Values 00001-09999 must be handled explicitly by the application.
408
 * Values 10000-19999 are informational events.
409
 * Values 20000-29999 indicate successful operations.
410
 * Values 30000-39999 indicate unsuccessful but normal operations.
411
 * Values 40000-49999 indicate client (or network) errors.
412
 * Values 50000-59999 indicate MHD-internal (or platform) errors.
413
 * Values 60000-65535 indicate application errors.
414
 *
415
 * @ingroup general
416
 */
417
enum MHD_FIXED_ENUM_MHD_SET_ MHD_StatusCode
418
{
419
420
  /* 00000-level codes are return values the application must handle.
421
     The zero code always means success. */
422
423
  /**
424
   * Successful operation (not used for logging).
425
   * The code is guaranteed to be always zero.
426
   */
427
  MHD_SC_OK = 0
428
  ,
429
430
  /* 10000-level codes are purely informational events. */
431
432
  /**
433
   * Informational event, MHD started.
434
   */
435
  MHD_SC_DAEMON_STARTED = 10000
436
  ,
437
  /**
438
   * Informational event, we accepted a connection.
439
   */
440
  MHD_SC_CONNECTION_ACCEPTED = 10001
441
  ,
442
  /**
443
   * Informational event, thread processing connection terminates.
444
   */
445
  MHD_SC_THREAD_TERMINATING = 10002
446
  ,
447
  /**
448
   * Informational event, state machine status for a connection.
449
   */
450
  MHD_SC_STATE_MACHINE_STATUS_REPORT = 10003
451
  ,
452
  /**
453
   * accept() returned transient error.
454
   */
455
  MHD_SC_ACCEPT_FAILED_EAGAIN = 10004
456
  ,
457
  /**
458
   * Accepted socket is unknown type (probably non-IP).
459
   */
460
  MHD_SC_ACCEPTED_UNKNOWN_TYPE = 10040
461
  ,
462
  /**
463
   * The sockaddr for the accepted socket does not fit the buffer.
464
   * (Strange)
465
   */
466
  MHD_SC_ACCEPTED_SOCKADDR_TOO_LARGE = 10041
467
  ,
468
469
  /* 20000-level codes indicate successful operations. */
470
  /* Examples: a connection has been closed normally, the response data
471
     generation has been completed. */
472
473
  /**
474
   * MHD is closing a connection after the client closed it
475
   * (perfectly normal end).
476
   */
477
  MHD_SC_CONNECTION_CLOSED = 20000
478
  ,
479
  /**
480
   * MHD is closing a connection because the application
481
   * logic to generate the response data completed.
482
   */
483
  MHD_SC_APPLICATION_DATA_GENERATION_FINISHED = 20001
484
  ,
485
  /**
486
   * The request does not contain a particular type of Authentication
487
   * credentials
488
   */
489
  MHD_SC_AUTH_ABSENT = 20060
490
  ,
491
492
  /* 30000-level codes indicate unsuccessful but normal operations. */
493
  /* Examples: a connections limit has been reached, the accept policy
494
     callback has rejected a connection, a memory pool is exhausted. */
495
496
497
  /**
498
   * Resource limit in terms of number of parallel connections
499
   * hit.
500
   */
501
  MHD_SC_LIMIT_CONNECTIONS_REACHED = 30000
502
  ,
503
  /**
504
   * The operation failed because the respective
505
   * daemon is already too deep inside of the shutdown
506
   * activity.
507
   */
508
  MHD_SC_DAEMON_ALREADY_SHUTDOWN = 30020
509
  ,
510
  /**
511
   * Failed to start new thread because of system limits.
512
   */
513
  MHD_SC_CONNECTION_THREAD_SYS_LIMITS_REACHED = 30030
514
  ,
515
  /**
516
   * Failed to start a thread.
517
   */
518
  MHD_SC_CONNECTION_THREAD_LAUNCH_FAILURE = 30031
519
  ,
520
  /**
521
   * The operation failed because we either have no
522
   * listen socket or were already quiesced.
523
   */
524
  MHD_SC_DAEMON_ALREADY_QUIESCED = 30040
525
  ,
526
  /**
527
   * The operation failed because client disconnected
528
   * faster than we could accept().
529
   */
530
  MHD_SC_ACCEPT_FAST_DISCONNECT = 30050
531
  ,
532
  /**
533
   * Operating resource limits hit on accept().
534
   */
535
  MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED = 30060
536
  ,
537
  /**
538
   * Connection was refused by accept policy callback.
539
   */
540
  MHD_SC_ACCEPT_POLICY_REJECTED = 30070
541
  ,
542
  /**
543
   * Failed to allocate memory for the daemon resources.
544
   * TODO: combine similar error codes for daemon
545
   */
546
  MHD_SC_DAEMON_MEM_ALLOC_FAILURE = 30081
547
  ,
548
  /**
549
   * We failed to allocate memory for the connection.
550
   * (May be transient.)
551
   */
552
  MHD_SC_CONNECTION_MEM_ALLOC_FAILURE = 30082
553
  ,
554
  /**
555
   * We failed to allocate memory for the connection's memory pool.
556
   * (May be transient.)
557
   */
558
  MHD_SC_POOL_MEM_ALLOC_FAILURE = 30083
559
  ,
560
  /**
561
   * We failed to allocate memory for the HTTP/2 connection's resources.
562
   * (May be transient.)
563
   */
564
  MHD_SC_H2_CONN_MEM_ALLOC_FAILURE = 30084
565
  ,
566
  /**
567
   * We failed to forward data from a Web socket to the
568
   * application to the remote side due to the socket
569
   * being closed prematurely. (May be transient.)
570
   */
571
  MHD_SC_UPGRADE_FORWARD_INCOMPLETE = 30100
572
  ,
573
  /**
574
   * Failed to allocate memory from our memory pool for processing
575
   * the request.  Likely the request fields are too large to leave
576
   * enough room.
577
   */
578
  MHD_SC_CONNECTION_POOL_NO_MEM_REQ = 30130
579
  ,
580
  /**
581
   * Failed to allocate memory from our memory pool to store GET parameter.
582
   * Likely the request URI or header fields are too large to leave enough room.
583
   */
584
  MHD_SC_CONNECTION_POOL_NO_MEM_GET_PARAM = 30131
585
  ,
586
  /**
587
   * Failed to allocate memory from our memory pool to store parsed cookie.
588
   */
589
  MHD_SC_CONNECTION_POOL_NO_MEM_COOKIE = 30132
590
  ,
591
  /**
592
   * Failed to allocate memory from connection memory pool to store
593
   * parsed Authentication data.
594
   */
595
  MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA = 30133
596
  ,
597
  /**
598
   * Detected jump back of system clock
599
   */
600
  MHD_SC_SYS_CLOCK_JUMP_BACK_LARGE = 30140
601
  ,
602
  /**
603
   * Detected correctable jump back of system clock
604
   */
605
  MHD_SC_SYS_CLOCK_JUMP_BACK_CORRECTED = 30141
606
  ,
607
  /**
608
   * Timeout waiting for communication operation for HTTP-Upgraded connection
609
   */
610
  MHD_SC_UPGRADED_NET_TIMEOUT = 30161
611
  ,
612
  /**
613
   * Not enough system resources
614
   */
615
  MHD_SC_NO_SYS_RESOURCES = 30180
616
  ,
617
618
  /* 40000-level errors are caused by the HTTP client or the network. */
619
620
  /**
621
   * MHD is closing a connection because parsing the
622
   * request failed.
623
   */
624
  MHD_SC_CONNECTION_PARSE_FAIL_CLOSED = 40000
625
  ,
626
  /**
627
   * MHD is returning an error because the header provided
628
   * by the client is too big.
629
   */
630
  MHD_SC_CLIENT_HEADER_TOO_BIG = 40020
631
  ,
632
  /**
633
   * An HTTP/1.1 request was sent without the "Host:" header.
634
   */
635
  MHD_SC_HOST_HEADER_MISSING = 40060
636
  ,
637
  /**
638
   * Request has more than one "Host:" header.
639
   */
640
  MHD_SC_HOST_HEADER_SEVERAL = 40061
641
  ,
642
  /**
643
   * The value of the "Host:" header is invalid.
644
   */
645
  MHD_SC_HOST_HEADER_MALFORMED = 40062
646
  ,
647
  /**
648
   * The given content length was not a number.
649
   */
650
  MHD_SC_CONTENT_LENGTH_MALFORMED = 40065
651
  ,
652
  /**
653
   * Request has more than one "Content-Length:" header with the same value.
654
   */
655
  MHD_SC_CONTENT_LENGTH_SEVERAL_SAME = 40066
656
  ,
657
  /**
658
   * Request has more than one "Content-Length:" header with the different
659
   * values.
660
   */
661
  MHD_SC_CONTENT_LENGTH_SEVERAL_DIFFERENT = 40067
662
  ,
663
  /**
664
   * The BOTH Content-Length and Transfer-Encoding headers are used.
665
   */
666
  MHD_SC_CONTENT_LENGTH_AND_TR_ENC = 40068
667
  ,
668
  /**
669
   * The Content-Length is too large to be handled.
670
   */
671
  MHD_SC_CONTENT_LENGTH_TOO_LARGE = 40069
672
  ,
673
  /**
674
   * Transfer encoding in request is unsupported or invalid.
675
   */
676
  MHD_SC_TRANSFER_ENCODING_UNSUPPORTED = 40075
677
  ,
678
  /**
679
   * "Expect:" value in request is unsupported or invalid.
680
   */
681
  MHD_SC_EXPECT_HEADER_VALUE_UNSUPPORTED = 40076
682
  ,
683
  /**
684
   * The given uploaded, chunked-encoded body was malformed.
685
   */
686
  MHD_SC_CHUNKED_ENCODING_MALFORMED = 40080
687
  ,
688
  /**
689
   * The first header line has whitespace at the start
690
   */
691
  MHD_SC_REQ_FIRST_HEADER_LINE_SPACE_PREFIXED = 40100
692
  ,
693
  /**
694
   * The request target (URI) has whitespace character
695
   */
696
  MHD_SC_REQ_TARGET_HAS_WHITESPACE = 40101
697
  ,
698
  /**
699
   * Wrong bare CR characters has been replaced with space.
700
   */
701
  MHD_SC_REQ_HEADER_CR_REPLACED = 40120
702
  ,
703
  /**
704
   * Header line has not colon and skipped.
705
   */
706
  MHD_SC_REQ_HEADER_LINE_NO_COLON = 40121
707
  ,
708
  /**
709
   * Wrong bare CR characters has been replaced with space.
710
   */
711
  MHD_SC_REQ_FOOTER_CR_REPLACED = 40140
712
  ,
713
  /**
714
   * Footer line has not colon and skipped.
715
   */
716
  MHD_SC_REQ_FOOTER_LINE_NO_COLON = 40141
717
  ,
718
  /**
719
   * The request is malformed.
720
   */
721
  MHD_SC_REQ_MALFORMED = 40155
722
  ,
723
  /**
724
   * The cookie string has been parsed, but it is not fully compliant with
725
   * specifications
726
   */
727
  MHD_SC_REQ_COOKIE_PARSED_NOT_COMPLIANT = 40160
728
  ,
729
  /**
730
   * The cookie string has been parsed only partially
731
   */
732
  MHD_SC_REQ_COOKIE_PARSED_PARTIALLY = 40161
733
  ,
734
  /**
735
   * The cookie string is ignored, as it is not fully compliant with
736
   * specifications
737
   */
738
  MHD_SC_REQ_COOKIE_IGNORED_NOT_COMPLIANT = 40162
739
  ,
740
  /**
741
   * The cookie string has been ignored as it is invalid
742
   */
743
  MHD_SC_REQ_COOKIE_INVALID = 40163
744
  ,
745
  /**
746
   * The POST data parsed successfully, but has missing or incorrect
747
   * termination.
748
   * The last parsed field may have incorrect data.
749
   */
750
  MHD_SC_REQ_POST_PARSE_OK_BAD_TERMINATION = 40202
751
  ,
752
  /**
753
   * Parsing of the POST data is incomplete because client used incorrect
754
   * format of POST encoding.
755
   * Some POST data is available or has been provided via callback.
756
   */
757
  MHD_SC_REQ_POST_PARSE_PARTIAL_INVALID_POST_FORMAT = 40203
758
  ,
759
  /**
760
   * The request does not have "Content-Type:" header and POST data cannot
761
   * be parsed
762
   */
763
  MHD_SC_REQ_POST_PARSE_FAILED_NO_CNTN_TYPE = 40280
764
  ,
765
  /**
766
   * The request has unknown POST encoding specified by "Content-Type:" header
767
   */
768
  MHD_SC_REQ_POST_PARSE_FAILED_UNKNOWN_CNTN_TYPE = 40281
769
  ,
770
  /**
771
   * The request has "Content-Type: multipart/form-data" header without
772
   * "boundary" parameter
773
   */
774
  MHD_SC_REQ_POST_PARSE_FAILED_HEADER_NO_BOUNDARY = 40282
775
  ,
776
  /**
777
   * The request has "Content-Type: multipart/form-data" header with misformed
778
   * data
779
   */
780
  MHD_SC_REQ_POST_PARSE_FAILED_HEADER_MISFORMED = 40283
781
  ,
782
  /**
783
   * The POST data cannot be parsed because client used incorrect format
784
   * of POST encoding.
785
   */
786
  MHD_SC_REQ_POST_PARSE_FAILED_INVALID_POST_FORMAT = 40290
787
  ,
788
  /**
789
   * The data in Auth request header has invalid format.
790
   * For example, for Basic Authentication base64 decoding failed.
791
   */
792
  MHD_SC_REQ_AUTH_DATA_BROKEN = 40320
793
  ,
794
  /**
795
   * The request cannot be processed. Sending error reply.
796
   */
797
  MHD_SC_REQ_PROCESSING_ERR_REPLY = 41000
798
  ,
799
  /**
800
   * MHD is closing a connection because of timeout.
801
   */
802
  MHD_SC_CONNECTION_TIMEOUT = 42000
803
  ,
804
  /**
805
   * MHD is closing a connection because receiving the
806
   * request failed.
807
   */
808
  MHD_SC_CONNECTION_RECV_FAIL_CLOSED = 42020
809
  ,
810
  /**
811
   * MHD is closing a connection because sending the response failed.
812
   */
813
  MHD_SC_CONNECTION_SEND_FAIL_CLOSED = 42021
814
  ,
815
  /**
816
   * MHD is closing a connection because remote client shut down its sending
817
   * side before full request was sent.
818
   */
819
  MHD_SC_CLIENT_SHUTDOWN_EARLY = 42040
820
  ,
821
  /**
822
   * MHD is closing a connection because remote client closed connection
823
   * early.
824
   */
825
  MHD_SC_CLIENT_CLOSED_CONN_EARLY = 42041
826
  ,
827
  /**
828
   * MHD is closing a connection connection has been (remotely) aborted.
829
   */
830
  MHD_SC_CONNECTION_ABORTED = 42042
831
  ,
832
  /**
833
   * MHD is closing a connection because it was reset.
834
   */
835
  MHD_SC_CONNECTION_RESET = 42060
836
  ,
837
  /**
838
   * MHD is closing a connection connection (or connection socket) has
839
   * been broken.
840
   */
841
  MHD_SC_CONNECTION_BROKEN = 42061
842
  ,
843
  /**
844
   * ALPN in TLS connection selected HTTP/2 (as advertised by the client),
845
   * but the client did not send a valid HTTP/2 connection preface.
846
   */
847
  MHD_SC_ALPN_H2_NO_PREFACE = 43001
848
  ,
849
850
  /* 50000-level errors are internal MHD or platform failures,
851
     not caused by the application (see 60000-level). */
852
  /* Examples: a socket error on a broken connection, a read failure for
853
     a file-backed response, an unexpected accept() error. */
854
855
  /**
856
   * This build of MHD does not support TLS, but the application
857
   * requested TLS.
858
   */
859
  MHD_SC_TLS_DISABLED = 50000
860
  ,
861
  /**
862
   * The selected TLS backend does not yet support this operation.
863
   */
864
  MHD_SC_TLS_BACKEND_OPERATION_UNSUPPORTED = 50004
865
  ,
866
  /**
867
   * Failed to setup ITC channel.
868
   */
869
  MHD_SC_ITC_INITIALIZATION_FAILED = 50005
870
  ,
871
  /**
872
   * File descriptor for ITC cannot be used because the FD number is higher
873
   * than the limit set by FD_SETSIZE (if internal polling with select is used)
874
   * or by application.
875
   */
876
  MHD_SC_ITC_FD_OUTSIDE_OF_SET_RANGE = 50006
877
  ,
878
  /**
879
   * The specified value for the NC length is way too large
880
   * for this platform (integer overflow on `size_t`).
881
   */
882
  MHD_SC_DIGEST_AUTH_NC_LENGTH_TOO_BIG = 50010
883
  ,
884
  /**
885
   * We failed to allocate memory for the specified nonce
886
   * counter array.  The option was not set.
887
   */
888
  MHD_SC_DIGEST_AUTH_NC_ALLOCATION_FAILURE = 50011
889
  ,
890
  /**
891
   * This build of the library does not support
892
   * digest authentication.
893
   */
894
  MHD_SC_DIGEST_AUTH_NOT_SUPPORTED_BY_BUILD = 50012
895
  ,
896
  /**
897
   * IPv6 requested but not supported by this build.
898
   * @sa #MHD_SC_AF_NOT_SUPPORTED_BY_BUILD
899
   */
900
  MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD = 50020
901
  ,
902
  /**
903
   * Specified address/protocol family is not supported by this build.
904
   * @sa MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD
905
   */
906
  MHD_SC_AF_NOT_SUPPORTED_BY_BUILD = 50021
907
  ,
908
  /**
909
   * The requested address/protocol family is rejected by the OS.
910
   * @sa #MHD_SC_AF_NOT_SUPPORTED_BY_BUILD
911
   */
912
  MHD_SC_AF_NOT_AVAILABLE = 50022
913
  ,
914
  /**
915
   * We failed to open the listen socket.
916
   */
917
  MHD_SC_FAILED_TO_OPEN_LISTEN_SOCKET = 50040
918
  ,
919
  /**
920
   * Failed to enable listen port reuse.
921
   */
922
  MHD_SC_LISTEN_PORT_REUSE_ENABLE_FAILED = 50041
923
  ,
924
  /**
925
   * Failed to enable listen port reuse.
926
   */
927
  MHD_SC_LISTEN_PORT_REUSE_ENABLE_NOT_SUPPORTED = 50042
928
  ,
929
  /**
930
   * Failed to enable listen address reuse.
931
   */
932
  MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED = 50043
933
  ,
934
  /**
935
   * Enabling listen address reuse is not supported by this platform.
936
   */
937
  MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED = 50044
938
  ,
939
  /**
940
   * Failed to enable exclusive use of listen address.
941
   */
942
  MHD_SC_LISTEN_ADDRESS_EXCLUSIVE_ENABLE_FAILED = 50045
943
  ,
944
  /**
945
   * Dual stack configuration is not possible for provided sockaddr.
946
   */
947
  MHD_SC_LISTEN_DUAL_STACK_NOT_SUITABLE = 50046
948
  ,
949
  /**
950
   * Failed to enable or disable dual stack for the IPv6 listen socket.
951
   * The OS default dual-stack setting is different from what is requested.
952
   */
953
  MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_REJECTED = 50047
954
  ,
955
  /**
956
   * Failed to enable or disable dual stack for the IPv6 listen socket.
957
   * The socket will be used in whatever the default is the OS uses.
958
   */
959
  MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_UNKNOWN = 50048
960
  ,
961
  /**
962
   * On this platform, MHD does not support explicitly configuring
963
   * dual stack behaviour.
964
   */
965
  MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED = 50049
966
  ,
967
  /**
968
   * Failed to enable TCP FAST OPEN option.
969
   */
970
  MHD_SC_LISTEN_FAST_OPEN_FAILURE = 50050
971
  ,
972
  /**
973
   * TCP FAST OPEN is not supported by the platform or by this MHD build.
974
   */
975
  MHD_SC_FAST_OPEN_NOT_SUPPORTED = 50051
976
  ,
977
  /**
978
   * We failed to set the listen socket to non-blocking.
979
   */
980
  MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE = 50052
981
  ,
982
  /**
983
   * Failed to configure listen socket to be non-inheritable.
984
   */
985
  MHD_SC_LISTEN_SOCKET_NOINHERIT_FAILED = 50053
986
  ,
987
  /**
988
   * Listen socket FD cannot be used because the FD number is higher than
989
   * the limit set by FD_SETSIZE (if internal polling with select is used) or
990
   * by application.
991
   */
992
  MHD_SC_LISTEN_FD_OUTSIDE_OF_SET_RANGE = 50054
993
  ,
994
  /**
995
   * We failed to bind the listen socket.
996
   */
997
  MHD_SC_LISTEN_SOCKET_BIND_FAILED = 50055
998
  ,
999
  /**
1000
   * Failed to start listening on listen socket.
1001
   */
1002
  MHD_SC_LISTEN_FAILURE = 50056
1003
  ,
1004
  /**
1005
   * Failed to detect the port number on the listening socket
1006
   */
1007
  MHD_SC_LISTEN_PORT_DETECT_FAILURE = 50057
1008
  ,
1009
  /**
1010
   * We failed to create control socket for the epoll().
1011
   */
1012
  MHD_SC_EPOLL_CTL_CREATE_FAILED = 50060
1013
  ,
1014
  /**
1015
   * We failed to configure control socket for the epoll()
1016
   * to be non-inheritable.
1017
   */
1018
  MHD_SC_EPOLL_CTL_CONFIGURE_NOINHERIT_FAILED = 50061
1019
  ,
1020
  /**
1021
   * The epoll() control FD cannot be used because the FD number is higher
1022
   * than the limit set by application.
1023
   */
1024
  MHD_SC_EPOLL_CTL_OUTSIDE_OF_SET_RANGE = 50062
1025
  ,
1026
  /**
1027
   * Failed to allocate memory for daemon's events data, like fd_sets,
1028
   * poll, epoll or kqueue structures.
1029
   */
1030
  MHD_SC_EVENTS_MEMORY_ALLOCATE_FAILURE = 50063
1031
  ,
1032
  /**
1033
   * Failed to add daemon's FDs (ITC and/or listening) to the internal events
1034
   * monitoring
1035
   */
1036
  MHD_SC_EVENTS_REG_DAEMON_FDS_FAILURE = 50065
1037
  ,
1038
  /**
1039
   * Failed to register daemon's FDs (ITC or listening) in the application
1040
   * (external event) monitoring
1041
   */
1042
  MHD_SC_EXT_EVENT_REG_DAEMON_FDS_FAILURE = 50066
1043
  ,
1044
  /**
1045
   * Failed to create kqueue FD
1046
   */
1047
  MHD_SC_KQUEUE_FD_CREATE_FAILED = 50067
1048
  ,
1049
  /**
1050
   * Failed to configure kqueue FD to be non-inheritable.
1051
   */
1052
  MHD_SC_KQUEUE_FD_SET_NOINHERIT_FAILED = 50068
1053
  ,
1054
  /**
1055
   * The kqueue FD cannot be used because the FD number is higher
1056
   * than the limit set by application.
1057
   */
1058
  MHD_SC_KQUEUE_FD_OUTSIDE_OF_SET_RANGE = 50069
1059
  ,
1060
  /**
1061
   * The select() syscall is not available on this platform or in this MHD
1062
   * build.
1063
   */
1064
  MHD_SC_SELECT_SYSCALL_NOT_AVAILABLE = 50070
1065
  ,
1066
  /**
1067
   * The poll() syscall is not available on this platform or in this MHD
1068
   * build.
1069
   */
1070
  MHD_SC_POLL_SYSCALL_NOT_AVAILABLE = 50071
1071
  ,
1072
  /**
1073
   * The epoll syscalls are not available on this platform or in this MHD
1074
   * build.
1075
   */
1076
  MHD_SC_EPOLL_SYSCALL_NOT_AVAILABLE = 50072
1077
  ,
1078
  /**
1079
   * The kqueue syscalls are not available on this platform or in this MHD
1080
   * build.
1081
   */
1082
  MHD_SC_KQUEUE_SYSCALL_NOT_AVAILABLE = 50073
1083
  ,
1084
  /**
1085
   * Failed to obtain our listen port via introspection.
1086
   * FIXME: remove?
1087
   */
1088
  MHD_SC_LISTEN_PORT_INTROSPECTION_FAILURE = 50080
1089
  ,
1090
  /**
1091
   * Failed to obtain our listen port via introspection
1092
   * due to unsupported address family being used.
1093
   */
1094
  MHD_SC_LISTEN_PORT_INTROSPECTION_UNKNOWN_AF = 50081
1095
  ,
1096
  /**
1097
   * Failed to initialise mutex.
1098
   */
1099
  MHD_SC_MUTEX_INIT_FAILURE = 50085
1100
  ,
1101
  /**
1102
   * Failed to allocate memory for the thread pool.
1103
   */
1104
  MHD_SC_THREAD_POOL_MEM_ALLOC_FAILURE = 50090
1105
  ,
1106
  /**
1107
   * We failed to allocate mutex for thread pool worker.
1108
   */
1109
  MHD_SC_THREAD_POOL_CREATE_MUTEX_FAILURE = 50093
1110
  ,
1111
  /**
1112
   * Failed to start the main daemon thread.
1113
   */
1114
  MHD_SC_THREAD_MAIN_LAUNCH_FAILURE = 50095
1115
  ,
1116
  /**
1117
   * Failed to start the daemon thread for listening.
1118
   */
1119
  MHD_SC_THREAD_LISTENING_LAUNCH_FAILURE = 50096
1120
  ,
1121
  /**
1122
   * Failed to start the worker thread for the thread pool.
1123
   */
1124
  MHD_SC_THREAD_WORKER_LAUNCH_FAILURE = 50097
1125
  ,
1126
  /**
1127
   * There was an attempt to upgrade a connection on
1128
   * a daemon where upgrades are disallowed.
1129
   */
1130
  MHD_SC_UPGRADE_ON_DAEMON_WITH_UPGRADE_DISALLOWED = 50100
1131
  ,
1132
  /**
1133
   * Failed to signal via ITC channel.
1134
   */
1135
  MHD_SC_ITC_USE_FAILED = 50101
1136
  ,
1137
  /**
1138
   * Failed to check for the signal on the ITC channel.
1139
   */
1140
  MHD_SC_ITC_CHECK_FAILED = 50102
1141
  ,
1142
  /**
1143
   * System reported error conditions on the ITC FD.
1144
   */
1145
  MHD_SC_ITC_STATUS_ERROR = 50104
1146
  ,
1147
  /**
1148
   * Failed to add a socket to the epoll set.
1149
   */
1150
  MHD_SC_EPOLL_CTL_ADD_FAILED = 50110
1151
  ,
1152
  /**
1153
   * Socket FD cannot be used because the FD number is higher than the limit set
1154
   * by FD_SETSIZE (if internal polling with select is used) or by application.
1155
   */
1156
  MHD_SC_SOCKET_OUTSIDE_OF_SET_RANGE = 50111
1157
  ,
1158
  /**
1159
   * The daemon cannot be started with the specified settings as no space
1160
   * left for the connections sockets within limits set by FD_SETSIZE.
1161
   * Consider use another sockets polling syscall (only select() has such
1162
   * limitations)
1163
   */
1164
  MHD_SC_SYS_FD_SETSIZE_TOO_STRICT = 50112
1165
  ,
1166
  /**
1167
   * This daemon was not configured with options that
1168
   * would allow us to obtain a meaningful timeout.
1169
   */
1170
  MHD_SC_CONFIGURATION_MISMATCH_FOR_GET_TIMEOUT = 50113
1171
  ,
1172
  /**
1173
   * This daemon was not configured with options that
1174
   * would allow us to run with select() data.
1175
   */
1176
  MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_SELECT = 50114
1177
  ,
1178
  /**
1179
   * This daemon was not configured to run with an
1180
   * external event loop.
1181
   */
1182
  MHD_SC_CONFIGURATION_MISMATCH_FOR_RUN_EXTERNAL = 50115
1183
  ,
1184
  /**
1185
   * Encountered an unexpected error from select()
1186
   * (should never happen).
1187
   */
1188
  MHD_SC_UNEXPECTED_SELECT_ERROR = 50116
1189
  ,
1190
  /**
1191
   * Failed to remove a connection socket to the epoll or kqueue monitoring.
1192
   */
1193
  MHD_SC_EVENTS_CONN_REMOVE_FAILED = 50117
1194
  ,
1195
  /**
1196
   * poll() is not supported.
1197
   */
1198
  MHD_SC_POLL_NOT_SUPPORTED = 50120
1199
  ,
1200
  /**
1201
   * Encountered a (potentially) recoverable error from poll().
1202
   */
1203
  MHD_SC_POLL_SOFT_ERROR = 50121
1204
  ,
1205
  /**
1206
   * Encountered an unrecoverable error from poll().
1207
   */
1208
  MHD_SC_POLL_HARD_ERROR = 50122
1209
  ,
1210
  /**
1211
   * Encountered a (potentially) recoverable error from select().
1212
   */
1213
  MHD_SC_SELECT_SOFT_ERROR = 50123
1214
  ,
1215
  /**
1216
   * Encountered an unrecoverable error from select().
1217
   */
1218
  MHD_SC_SELECT_HARD_ERROR = 50124
1219
  ,
1220
  /**
1221
   * System reported error conditions on the listening socket.
1222
   */
1223
  MHD_SC_LISTEN_STATUS_ERROR = 50129
1224
  ,
1225
  /**
1226
   * Encountered an unrecoverable error from epoll function.
1227
   */
1228
  MHD_SC_EPOLL_HARD_ERROR = 50130
1229
  ,
1230
  /**
1231
   * Encountered an unrecoverable error from kevent() function.
1232
   */
1233
  MHD_SC_KQUEUE_HARD_ERROR = 50131
1234
  ,
1235
  /**
1236
   * We failed to configure accepted socket
1237
   * to not use a SIGPIPE.
1238
   */
1239
  MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED = 50140
1240
  ,
1241
  /**
1242
   * We failed to configure accepted socket
1243
   * to be non-inheritable.
1244
   */
1245
  MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED = 50141
1246
  ,
1247
  /**
1248
   * We failed to configure accepted socket
1249
   * to be non-blocking.
1250
   */
1251
  MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED = 50142
1252
  ,
1253
  /**
1254
   * The accepted socket FD value is too large.
1255
   */
1256
  MHD_SC_ACCEPT_OUTSIDE_OF_SET_RANGE = 50143
1257
  ,
1258
  /**
1259
   * accept() returned unexpected error.
1260
   */
1261
  MHD_SC_ACCEPT_FAILED_UNEXPECTEDLY = 50144
1262
  ,
1263
  /**
1264
   * Operating resource limits hit on accept() while
1265
   * zero connections are active. Oopsie.
1266
   */
1267
  MHD_SC_ACCEPT_SYSTEM_LIMIT_REACHED_INSTANTLY = 50145
1268
  ,
1269
  /**
1270
   * The daemon sockets polling mode requires non-blocking sockets.
1271
   */
1272
  MHD_SC_NONBLOCKING_REQUIRED = 50146
1273
  ,
1274
  /**
1275
   * Encountered an unexpected error from epoll_wait()
1276
   * (should never happen).
1277
   */
1278
  MHD_SC_UNEXPECTED_EPOLL_WAIT_ERROR = 50150
1279
  ,
1280
  /**
1281
   * epoll file descriptor is invalid (strange)
1282
   */
1283
  MHD_SC_EPOLL_FD_INVALID = 50151
1284
  ,
1285
  /**
1286
   * Unexpected socket error (strange)
1287
   */
1288
  MHD_SC_UNEXPECTED_SOCKET_ERROR = 50152
1289
  ,
1290
  /**
1291
   * Failed to add IP address to per-IP counter for
1292
   * some reason.
1293
   */
1294
  MHD_SC_IP_COUNTER_FAILURE = 50160
1295
  ,
1296
  /**
1297
   * Application violated our API by calling shutdown
1298
   * while having an upgrade connection still open.
1299
   */
1300
  MHD_SC_SHUTDOWN_WITH_OPEN_UPGRADED_CONNECTION = 50180
1301
  ,
1302
  /**
1303
   * Due to an unexpected internal error with the
1304
   * state machine, we closed the connection.
1305
   */
1306
  MHD_SC_STATEMACHINE_FAILURE_CONNECTION_CLOSED = 50200
1307
  ,
1308
  /**
1309
   * Failed to allocate memory in connection's pool
1310
   * to parse the cookie header.
1311
   */
1312
  MHD_SC_COOKIE_POOL_ALLOCATION_FAILURE = 50220
1313
  ,
1314
  /**
1315
   * MHD failed to build the reply header.
1316
   */
1317
  MHD_SC_REPLY_HEADER_GENERATION_FAILED = 50230
1318
  ,
1319
  /**
1320
   * Failed to allocate memory in connection's pool for the reply.
1321
   */
1322
  MHD_SC_REPLY_POOL_ALLOCATION_FAILURE = 50231
1323
  ,
1324
  /**
1325
   * Failed to read the file for file-backed response.
1326
   */
1327
  MHD_SC_REPLY_FILE_READ_ERROR = 50232
1328
  ,
1329
  /**
1330
   * Failed to generate the nonce for the Digest Auth.
1331
   */
1332
  MHD_SC_REPLY_NONCE_ERROR = 50233
1333
  ,
1334
  /**
1335
   * Failed to allocate memory in connection's pool for the reply.
1336
   */
1337
  MHD_SC_REPLY_ALLOCATION_FAILED = 50250
1338
  ,
1339
  /**
1340
   * The request POST data cannot be parsed because stream has not enough
1341
   * pool memory free.
1342
   */
1343
  MHD_SC_REQ_POST_PARSE_FAILED_NO_POOL_MEM = 50260
1344
  ,
1345
  /**
1346
   * The POST data cannot be parsed completely because no "large shared buffer"
1347
   * space is available.
1348
   * Some POST data may be parsed.
1349
   */
1350
  MHD_SC_REQ_POST_PARSE_FAILED_NO_LARGE_BUF_MEM = 50261
1351
  ,
1352
  /**
1353
   * The application set POST encoding to "multipart/form-data", but the request
1354
   * has no "Content-Type: multipart/form-data" header which is required
1355
   * to find "boundary" used in this encoding
1356
   */
1357
  MHD_SC_REQ_POST_PARSE_FAILED_HEADER_NOT_MPART = 50284
1358
  ,
1359
  /**
1360
   * The feature is not supported by this MHD build (either
1361
   * disabled by configure parameters or build platform
1362
   * did not support it, because headers are missing or
1363
   * so kernel does not have such feature).
1364
   * The feature will not be enabled if the same MHD binary
1365
   * will be run on another kernel, computer or system
1366
   * configuration.
1367
   */
1368
  MHD_SC_FEATURE_DISABLED = 50300
1369
  ,
1370
  /**
1371
   * The feature is not supported by this platform, while
1372
   * supported by MHD build.
1373
   * The feature can be enabled by changing the kernel or
1374
   * running on another computer or with other system
1375
   * configuration.
1376
   */
1377
  MHD_SC_FEATURE_NOT_AVAILABLE = 50320
1378
  ,
1379
  /**
1380
   * Failed to stop the thread
1381
   */
1382
  MHD_SC_DAEMON_THREAD_STOP_ERROR = 50350
1383
  ,
1384
  /**
1385
   * Unexpected reasons for thread stop
1386
   */
1387
  MHD_SC_DAEMON_THREAD_STOP_UNEXPECTED = 50351
1388
  ,
1389
  /**
1390
   * Daemon system data is broken (like listen socket was unexpectedly closed).
1391
   * The daemon needs to be closed.
1392
   * A new daemon can be started as a replacement after closing the current
1393
   * daemon.
1394
   */
1395
  MHD_SC_DAEMON_SYS_DATA_BROKEN = 50370
1396
  ,
1397
  /**
1398
   * Failed to acquire response mutex lock
1399
   */
1400
  MHD_SC_RESP_MUTEX_LOCK_FAILED = 50500
1401
  ,
1402
  /**
1403
   * Failed to initialise response mutex
1404
   */
1405
  MHD_SC_RESP_MUTEX_INIT_FAILED = 50501
1406
  ,
1407
  /**
1408
   * Unable to allocate memory for the response header
1409
   */
1410
  MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED = 50540
1411
  ,
1412
  /**
1413
   * Failed to switch TCP_NODELAY option for the socket
1414
   */
1415
  MHD_SC_SOCKET_TCP_NODELAY_FAILED = 50600
1416
  ,
1417
  /**
1418
   * Failed to switch TCP_CORK or TCP_NOPUSH option for the socket
1419
   */
1420
  MHD_SC_SOCKET_TCP_CORK_NOPUSH_FAILED = 50601
1421
  ,
1422
  /**
1423
   * Failed to force flush the last part of the response header or
1424
   * the response content
1425
   */
1426
  MHD_SC_SOCKET_FLUSH_LAST_PART_FAILED = 50620
1427
  ,
1428
  /**
1429
   * Failed to push buffered data by zero-sized send()
1430
   */
1431
  MHD_SC_SOCKET_ZERO_SEND_FAILED = 50621
1432
  ,
1433
  /**
1434
   * The HTTP-Upgraded network connection has been closed / disconnected
1435
   */
1436
  MHD_SC_UPGRADED_NET_CONN_CLOSED = 50800
1437
  ,
1438
  /**
1439
   * The HTTP-Upgraded network connection has been broken
1440
   */
1441
  MHD_SC_UPGRADED_NET_CONN_BROKEN = 50801
1442
  ,
1443
  /**
1444
   * The TLS communication error on HTTP-Upgraded connection
1445
   */
1446
  MHD_SC_UPGRADED_TLS_ERROR = 50802
1447
  ,
1448
  /**
1449
   * Unrecoverable sockets communication error on HTTP-Upgraded connection
1450
   */
1451
  MHD_SC_UPGRADED_NET_HARD_ERROR = 50840
1452
  ,
1453
  /**
1454
   * MHD cannot wait for the data on the HTTP-Upgraded connection, because
1455
   * current build or the platform does not support required functionality.
1456
   * Communication with zero timeout is fully supported.
1457
   */
1458
  MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED = 50860
1459
  ,
1460
  /**
1461
   * Global initialisation of MHD library failed
1462
   */
1463
  MHD_SC_LIB_INIT_GLOBAL_FAILED = 51000
1464
  ,
1465
  /**
1466
   * Failed to initialise TLS context for the daemon
1467
   */
1468
  MHD_SC_TLS_DAEMON_INIT_FAILED = 51200
1469
  ,
1470
  /**
1471
   * Failed to initialise TLS context for the new connection
1472
   */
1473
  MHD_SC_TLS_CONNECTION_INIT_FAILED = 51201
1474
  ,
1475
  /**
1476
   * Warning about TLS backend configuration
1477
   */
1478
  MHD_SC_TLS_LIB_CONF_WARNING = 51202
1479
  ,
1480
  /**
1481
   * Failed to perform TLS handshake
1482
   */
1483
  MHD_SC_TLS_CONNECTION_HANDSHAKED_FAILED = 51220
1484
  ,
1485
  /**
1486
   * Hashing failed.
1487
   * Internal hashing function can never fail (and this code is never returned
1488
   * for them). External hashing function (like TLS backend-based) may fail
1489
   * for various reasons, like failure of hardware acccelerated hashing.
1490
   */
1491
  MHD_SC_HASH_FAILED = 51260
1492
  ,
1493
  /**
1494
   * Something wrong in the internal MHD logic.
1495
   * This error should be never returned if MHD works as expected.
1496
   * If this code is ever returned, please report to MHD maintainers.
1497
   */
1498
  MHD_SC_INTERNAL_ERROR = 59900
1499
  ,
1500
1501
  /* 60000-level errors are caused by the application
1502
     (callbacks, settings or API misuse). */
1503
1504
  /**
1505
   * The application called function too early.
1506
   * For example, a header value was requested before the headers
1507
   * had been received.
1508
   */
1509
  MHD_SC_TOO_EARLY = 60000
1510
  ,
1511
  /**
1512
   * The application called this function too late.
1513
   * For example, MHD has already started sending reply.
1514
   */
1515
  MHD_SC_TOO_LATE = 60001
1516
  ,
1517
  /**
1518
   * MHD does not support the requested combination of
1519
   * the sockets polling syscall and the work mode.
1520
   */
1521
  MHD_SC_SYSCALL_WORK_MODE_COMBINATION_INVALID = 60010
1522
  ,
1523
  /**
1524
   * MHD does not support quiescing if ITC was disabled
1525
   * and threads are used.
1526
   */
1527
  MHD_SC_SYSCALL_QUIESCE_REQUIRES_ITC = 60011
1528
  ,
1529
  /**
1530
   * The option provided or function called can be used only with "external
1531
   * events" modes.
1532
   */
1533
  MHD_SC_EXTERNAL_EVENT_ONLY = 60012
1534
  ,
1535
  /**
1536
   * MHD is closing a connection because the application
1537
   * logic to generate the response data failed.
1538
   */
1539
  MHD_SC_APPLICATION_DATA_GENERATION_FAILURE_CLOSED = 60015
1540
  ,
1541
  /**
1542
   * MHD is closing a connection because the application
1543
   * callback told it to do so.
1544
   */
1545
  MHD_SC_APPLICATION_CALLBACK_ABORT_ACTION = 60016
1546
  ,
1547
  /**
1548
   * Application only partially processed upload and did
1549
   * not suspend connection. This may result in a hung
1550
   * connection.
1551
   */
1552
  MHD_SC_APPLICATION_HUNG_CONNECTION = 60017
1553
  ,
1554
  /**
1555
   * Application only partially processed upload and did
1556
   * not suspend connection and the read buffer was maxxed
1557
   * out, so MHD closed the connection.
1558
   */
1559
  MHD_SC_APPLICATION_HUNG_CONNECTION_CLOSED = 60018
1560
  ,
1561
  /**
1562
   * Attempted to set an option that conflicts with another option
1563
   * already set.
1564
   */
1565
  MHD_SC_OPTIONS_CONFLICT = 60020
1566
  ,
1567
  /**
1568
   * Attempted to set an option that not recognised by MHD.
1569
   */
1570
  MHD_SC_OPTION_UNKNOWN = 60021
1571
  ,
1572
  /**
1573
   * Parameter specified unknown work mode.
1574
   */
1575
  MHD_SC_CONFIGURATION_UNEXPECTED_WM = 60022
1576
  ,
1577
  /**
1578
   * Parameter specified unknown Sockets Polling Syscall (SPS).
1579
   */
1580
  MHD_SC_CONFIGURATION_UNEXPECTED_SPS = 60023
1581
  ,
1582
  /**
1583
   * The size of the provided sockaddr does not match address family.
1584
   */
1585
  MHD_SC_CONFIGURATION_WRONG_SA_SIZE = 60024
1586
  ,
1587
  /**
1588
   * The number set by #MHD_D_O_FD_NUMBER_LIMIT is too strict to run
1589
   * the daemon
1590
   */
1591
  MHD_SC_MAX_FD_NUMBER_LIMIT_TOO_STRICT = 60025
1592
  ,
1593
  /**
1594
   * The number set by #MHD_D_O_GLOBAL_CONNECTION_LIMIT is too for the daemon
1595
   * configuration
1596
   */
1597
  MHD_SC_CONFIGURATION_CONN_LIMIT_TOO_SMALL = 60026
1598
  ,
1599
  /**
1600
   * The provided configuration parameter is NULL, but it must be non-NULL
1601
   */
1602
  MHD_SC_CONFIGURATION_PARAM_NULL = 60027
1603
  ,
1604
  /**
1605
   * The size of the provided configuration parameter is too large
1606
   */
1607
  MHD_SC_CONFIGURATION_PARAM_TOO_LARGE = 60028
1608
  ,
1609
  /**
1610
   * The application requested an unsupported TLS backend to be used.
1611
   */
1612
  MHD_SC_TLS_BACKEND_UNSUPPORTED = 60030
1613
  ,
1614
  /**
1615
   * The application attempted to setup TLS parameters before
1616
   * enabling TLS.
1617
   */
1618
  MHD_SC_TLS_BACKEND_UNINITIALIZED = 60031
1619
  ,
1620
  /**
1621
   * The application requested a TLS backend which cannot be used due
1622
   * to missing TLS dynamic library or backend initialisation problem.
1623
   */
1624
  MHD_SC_TLS_BACKEND_UNAVAILABLE = 60032
1625
  ,
1626
  /**
1627
   * Provided TLS certificate and/or private key are incorrect
1628
   */
1629
  MHD_SC_TLS_CONF_BAD_CERT = 60033
1630
  ,
1631
  /**
1632
   * The application requested a daemon setting that cannot be used with
1633
   * selected TLS backend
1634
   */
1635
  MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS = 60034
1636
  ,
1637
  /**
1638
   * The pointer to the response object is NULL
1639
   */
1640
  MHD_SC_RESP_POINTER_NULL = 60060
1641
  ,
1642
  /**
1643
   * The response HTTP status code is not suitable
1644
   */
1645
  MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE = 60061
1646
  ,
1647
  /**
1648
   * The provided MHD_Action is invalid
1649
   */
1650
  MHD_SC_ACTION_INVALID = 60080
1651
  ,
1652
  /**
1653
   * The provided MHD_UploadAction is invalid
1654
   */
1655
  MHD_SC_UPLOAD_ACTION_INVALID = 60081
1656
  ,
1657
  /**
1658
   * The provided Dynamic Content Creator action is invalid
1659
   */
1660
  MHD_SC_DCC_ACTION_INVALID = 60082
1661
  ,
1662
  /**
1663
   * The response must be empty
1664
   */
1665
  MHD_SC_REPLY_NOT_EMPTY_RESPONSE = 60101
1666
  ,
1667
  /**
1668
   * The "Content-Length" header is not allowed in the reply
1669
   */
1670
  MHD_SC_REPLY_CONTENT_LENGTH_NOT_ALLOWED = 60102
1671
  ,
1672
  /**
1673
   * The provided reply headers do not fit the connection buffer
1674
   */
1675
  MHD_SC_REPLY_HEADERS_TOO_LARGE = 60103
1676
  ,
1677
  /**
1678
   * Specified offset in file-backed response is too large and not supported
1679
   * by the platform
1680
   */
1681
  MHD_SC_REPLY_FILE_OFFSET_TOO_LARGE = 60104
1682
  ,
1683
  /**
1684
   * File-backed response has file smaller than specified combination of
1685
   * the file offset and the response size.
1686
   */
1687
  MHD_SC_REPLY_FILE_TOO_SHORT = 60105
1688
  ,
1689
  /**
1690
   * The new connection cannot be used because the FD number is higher than
1691
   * the limit set by FD_SETSIZE (if internal polling with select is used) or
1692
   * by application.
1693
   */
1694
  MHD_SC_NEW_CONN_FD_OUTSIDE_OF_SET_RANGE = 60140
1695
  ,
1696
  /**
1697
   * The daemon is being destroyed, while not all HTTP-Upgraded connections
1698
   * has been closed.
1699
   */
1700
  MHD_SC_DAEMON_DESTROYED_WITH_UNCLOSED_UPGRADED = 60160
1701
  ,
1702
  /**
1703
   * The provided pointer to 'struct MHD_UpgradedHandle' is invalid
1704
   */
1705
  MHD_SC_UPGRADED_HANDLE_INVALID = 60161
1706
  ,
1707
  /**
1708
   * The provided output buffer is too small.
1709
   */
1710
  MHD_SC_OUT_BUFF_TOO_SMALL = 60180
1711
  ,
1712
  /**
1713
   * The requested type of information is not recognised.
1714
   */
1715
  MHD_SC_INFO_GET_TYPE_UNKNOWN = 60200
1716
  ,
1717
  /**
1718
   * The information of the requested type is too large to fit into
1719
   * the provided buffer.
1720
   */
1721
  MHD_SC_INFO_GET_BUFF_TOO_SMALL = 60201
1722
  ,
1723
  /**
1724
   * The type of the information is not supported by this MHD build.
1725
   * It can be information not supported on the current platform or related
1726
   * to feature disabled for this build.
1727
   */
1728
  MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD = 60202
1729
  ,
1730
  /**
1731
   * The type of the information is not available due to configuration
1732
   * or state of the object.
1733
   */
1734
  MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE = 60203
1735
  ,
1736
  /**
1737
   * The type of the information should be available for the object, but
1738
   * cannot be provided due to some error or other reasons.
1739
   */
1740
  MHD_SC_INFO_GET_TYPE_UNOBTAINABLE = 60204
1741
  ,
1742
  /**
1743
   * The type of the Digest Auth algorithm is unknown or not supported.
1744
   */
1745
  MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED = 60240
1746
  ,
1747
  /**
1748
   * The Digest Auth QOP value is unknown or not supported.
1749
   */
1750
  MHD_SC_AUTH_DIGEST_QOP_NOT_SUPPORTED = 60241
1751
  ,
1752
  /**
1753
   * The Digest Auth is not supported due to configuration
1754
   */
1755
  MHD_SC_AUTH_DIGEST_UNSUPPORTED = 60242
1756
  ,
1757
  /**
1758
   * The application failed to register FD for the external events monitoring
1759
   */
1760
  MHD_SC_EXTR_EVENT_REG_FAILED = 60243
1761
  ,
1762
  /**
1763
   * The application failed to de-register FD for the external events monitoring
1764
   */
1765
  MHD_SC_EXTR_EVENT_DEREG_FAILED = 60244
1766
  ,
1767
  /**
1768
   * The application called #MHD_daemon_event_update() with broken data
1769
   */
1770
  MHD_SC_EXTR_EVENT_BROKEN_DATA = 60250
1771
  ,
1772
  /**
1773
   * The application called #MHD_daemon_event_update() with status that
1774
   * has not been requested
1775
   */
1776
  MHD_SC_EXTR_EVENT_UNEXPECTED_STATUS = 60251
1777
  ,
1778
  /**
1779
   * Unable to clear "reusable" flag.
1780
   * Once this flag is set, it cannot be removed for the response lifetime.
1781
   */
1782
  MHD_SC_RESP_REUSABLE_CANNOT_CLEAR = 60300
1783
  ,
1784
  /**
1785
   * The response header name has forbidden characters or token
1786
   */
1787
  MHD_SC_RESP_HEADER_NAME_INVALID = 60320
1788
  ,
1789
  /**
1790
   * The response header value has forbidden characters or token
1791
   */
1792
  MHD_SC_RESP_HEADER_VALUE_INVALID = 60321
1793
  ,
1794
  /**
1795
   * An attempt to add header conflicting with other response header
1796
   */
1797
  MHD_SC_RESP_HEADERS_CONFLICT = 60330
1798
  ,
1799
  /**
1800
   * The application tried to add second DATE header.
1801
   */
1802
  MHD_SC_RESP_HEADER_DATE_DUPLICATE = 60340
1803
  ,
1804
  /**
1805
   * The application tried to add second CONNECTION header.
1806
   */
1807
  MHD_SC_RESP_HEADER_CONNECTION_DUPLICATE = 60341
1808
};
1809
1810
/**
1811
 * Get text description for the MHD error code.
1812
 *
1813
 * This function works for @b MHD error codes, not for @b HTTP status codes.
1814
 * @param code the MHD code to get description for
1815
 * @return the pointer to the text description,
1816
 *         NULL if MHD code in not known.
1817
 *
1818
 * @ingroup general
1819
 */
1820
MHD_EXTERN_ const struct MHD_String *
1821
MHD_status_code_to_string (enum MHD_StatusCode code)
1822
MHD_FN_CONST_;
1823
1824
/**
1825
 * Get the pointer to the C string for the MHD error code, never NULL.
1826
 */
1827
#define MHD_status_code_to_string_lazy(code) \
1828
        (MHD_status_code_to_string ((code)) ? \
1829
         ((MHD_status_code_to_string (code))->cstr) : ("[No code]") )
1830
1831
#ifndef MHD_HTTP_METHOD_DEFINED
1832
1833
/**
1834
 * @brief HTTP request methods
1835
 *
1836
 * @defgroup methods HTTP methods
1837
 *
1838
 * See: https://www.iana.org/assignments/http-methods/http-methods.xml
1839
 * Registry export date: 2023-10-02
1840
 * @{
1841
 */
1842
1843
/**
1844
 * HTTP methods explicitly supported by MHD.  Note that for non-canonical
1845
 * methods, MHD will return #MHD_HTTP_METHOD_OTHER and you can use
1846
 * #MHD_REQUEST_INFO_FIXED_HTTP_METHOD to get the original string.
1847
 *
1848
 * However, applications must check for #MHD_HTTP_METHOD_OTHER *or* any enum-value
1849
 * above those in this list, as future versions of MHD may add additional
1850
 * methods (as per IANA registry), thus even if the API returns
1851
 * #MHD_HTTP_METHOD_OTHER today, it may return a method-specific header in the
1852
 * future!
1853
 */
1854
enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_Method
1855
{
1856
1857
  /**
1858
   * Method did not match any of the methods given below.
1859
   */
1860
  MHD_HTTP_METHOD_OTHER = 255
1861
  ,
1862
  /* Main HTTP methods. */
1863
1864
  /**
1865
   * "GET"
1866
   * Safe.     Idempotent.     RFC9110, Section 9.3.1.
1867
   */
1868
  MHD_HTTP_METHOD_GET = 1
1869
  ,
1870
  /**
1871
   * "HEAD"
1872
   * Safe.     Idempotent.     RFC9110, Section 9.3.2.
1873
   */
1874
  MHD_HTTP_METHOD_HEAD = 2
1875
  ,
1876
  /**
1877
   * "POST"
1878
   * Not safe. Not idempotent. RFC9110, Section 9.3.3.
1879
   */
1880
  MHD_HTTP_METHOD_POST = 3
1881
  ,
1882
  /**
1883
   * "PUT"
1884
   * Not safe. Idempotent.     RFC9110, Section 9.3.4.
1885
   */
1886
  MHD_HTTP_METHOD_PUT = 4
1887
  ,
1888
  /**
1889
   * "DELETE"
1890
   * Not safe. Idempotent.     RFC9110, Section 9.3.5.
1891
   */
1892
  MHD_HTTP_METHOD_DELETE = 5
1893
  ,
1894
  /**
1895
   * "CONNECT"
1896
   * Not safe. Not idempotent. RFC9110, Section 9.3.6.
1897
   */
1898
  MHD_HTTP_METHOD_CONNECT = 6
1899
  ,
1900
  /**
1901
   * "OPTIONS"
1902
   * Safe.     Idempotent.     RFC9110, Section 9.3.7.
1903
   */
1904
  MHD_HTTP_METHOD_OPTIONS = 7
1905
  ,
1906
  /**
1907
   * "TRACE"
1908
   * Safe.     Idempotent.     RFC9110, Section 9.3.8.
1909
   */
1910
  MHD_HTTP_METHOD_TRACE = 8
1911
  ,
1912
  /**
1913
   * "*"
1914
   * Not safe. Not idempotent. RFC9110, Section 18.2.
1915
   */
1916
  MHD_HTTP_METHOD_ASTERISK = 9
1917
};
1918
1919
#  define MHD_HTTP_METHOD_DEFINED 1
1920
#endif /* ! MHD_HTTP_METHOD_DEFINED */
1921
1922
/**
1923
 * Get text version of the method name.
1924
 * @param method the method to get the text version
1925
 * @return the pointer to the text version,
1926
 *         NULL if method is MHD_HTTP_METHOD_OTHER
1927
 *         or not known.
1928
 */
1929
MHD_EXTERN_ const struct MHD_String *
1930
MHD_http_method_to_string (enum MHD_HTTP_Method method)
1931
MHD_FN_CONST_;
1932
1933
1934
/* Main HTTP methods. */
1935
/* Safe.     Idempotent.     RFC9110, Section 9.3.1. */
1936
1
#define MHD_HTTP_METHOD_STR_GET      "GET"
1937
/* Safe.     Idempotent.     RFC9110, Section 9.3.2. */
1938
1
#define MHD_HTTP_METHOD_STR_HEAD     "HEAD"
1939
/* Not safe. Not idempotent. RFC9110, Section 9.3.3. */
1940
1
#define MHD_HTTP_METHOD_STR_POST     "POST"
1941
/* Not safe. Idempotent.     RFC9110, Section 9.3.4. */
1942
0
#define MHD_HTTP_METHOD_STR_PUT      "PUT"
1943
/* Not safe. Idempotent.     RFC9110, Section 9.3.5. */
1944
1
#define MHD_HTTP_METHOD_STR_DELETE   "DELETE"
1945
/* Not safe. Not idempotent. RFC9110, Section 9.3.6. */
1946
0
#define MHD_HTTP_METHOD_STR_CONNECT  "CONNECT"
1947
/* Safe.     Idempotent.     RFC9110, Section 9.3.7. */
1948
0
#define MHD_HTTP_METHOD_STR_OPTIONS  "OPTIONS"
1949
/* Safe.     Idempotent.     RFC9110, Section 9.3.8. */
1950
3
#define MHD_HTTP_METHOD_STR_TRACE    "TRACE"
1951
/* Not safe. Not idempotent. RFC9110, Section 18.2. */
1952
#define MHD_HTTP_METHOD_STR_ASTERISK  "*"
1953
1954
/* Additional HTTP methods. */
1955
/* Not safe. Idempotent.     RFC3744, Section 8.1. */
1956
#define MHD_HTTP_METHOD_STR_ACL            "ACL"
1957
/* Not safe. Idempotent.     RFC3253, Section 12.6. */
1958
#define MHD_HTTP_METHOD_STR_BASELINE_CONTROL "BASELINE-CONTROL"
1959
/* Not safe. Idempotent.     RFC5842, Section 4. */
1960
#define MHD_HTTP_METHOD_STR_BIND           "BIND"
1961
/* Not safe. Idempotent.     RFC3253, Section 4.4, Section 9.4. */
1962
#define MHD_HTTP_METHOD_STR_CHECKIN        "CHECKIN"
1963
/* Not safe. Idempotent.     RFC3253, Section 4.3, Section 8.8. */
1964
#define MHD_HTTP_METHOD_STR_CHECKOUT       "CHECKOUT"
1965
/* Not safe. Idempotent.     RFC4918, Section 9.8. */
1966
#define MHD_HTTP_METHOD_STR_COPY           "COPY"
1967
/* Not safe. Idempotent.     RFC3253, Section 8.2. */
1968
#define MHD_HTTP_METHOD_STR_LABEL          "LABEL"
1969
/* Not safe. Idempotent.     RFC2068, Section 19.6.1.2. */
1970
#define MHD_HTTP_METHOD_STR_LINK           "LINK"
1971
/* Not safe. Not idempotent. RFC4918, Section 9.10. */
1972
#define MHD_HTTP_METHOD_STR_LOCK           "LOCK"
1973
/* Not safe. Idempotent.     RFC3253, Section 11.2. */
1974
#define MHD_HTTP_METHOD_STR_MERGE          "MERGE"
1975
/* Not safe. Idempotent.     RFC3253, Section 13.5. */
1976
#define MHD_HTTP_METHOD_STR_MKACTIVITY     "MKACTIVITY"
1977
/* Not safe. Idempotent.     RFC4791, Section 5.3.1; RFC8144, Section 2.3. */
1978
#define MHD_HTTP_METHOD_STR_MKCALENDAR     "MKCALENDAR"
1979
/* Not safe. Idempotent.     RFC4918, Section 9.3; RFC5689, Section 3; RFC8144, Section 2.3. */
1980
#define MHD_HTTP_METHOD_STR_MKCOL          "MKCOL"
1981
/* Not safe. Idempotent.     RFC4437, Section 6. */
1982
#define MHD_HTTP_METHOD_STR_MKREDIRECTREF  "MKREDIRECTREF"
1983
/* Not safe. Idempotent.     RFC3253, Section 6.3. */
1984
#define MHD_HTTP_METHOD_STR_MKWORKSPACE    "MKWORKSPACE"
1985
/* Not safe. Idempotent.     RFC4918, Section 9.9. */
1986
#define MHD_HTTP_METHOD_STR_MOVE           "MOVE"
1987
/* Not safe. Idempotent.     RFC3648, Section 7. */
1988
#define MHD_HTTP_METHOD_STR_ORDERPATCH     "ORDERPATCH"
1989
/* Not safe. Not idempotent. RFC5789, Section 2. */
1990
#define MHD_HTTP_METHOD_STR_PATCH          "PATCH"
1991
/* Safe.     Idempotent.     RFC9113, Section 3.4. */
1992
#define MHD_HTTP_METHOD_STR_PRI            "PRI"
1993
/* Safe.     Idempotent.     RFC4918, Section 9.1; RFC8144, Section 2.1. */
1994
#define MHD_HTTP_METHOD_STR_PROPFIND       "PROPFIND"
1995
/* Not safe. Idempotent.     RFC4918, Section 9.2; RFC8144, Section 2.2. */
1996
#define MHD_HTTP_METHOD_STR_PROPPATCH      "PROPPATCH"
1997
/* Not safe. Idempotent.     RFC5842, Section 6. */
1998
#define MHD_HTTP_METHOD_STR_REBIND         "REBIND"
1999
/* Safe.     Idempotent.     RFC3253, Section 3.6; RFC8144, Section 2.1. */
2000
#define MHD_HTTP_METHOD_STR_REPORT         "REPORT"
2001
/* Safe.     Idempotent.     RFC5323, Section 2. */
2002
#define MHD_HTTP_METHOD_STR_SEARCH         "SEARCH"
2003
/* Not safe. Idempotent.     RFC5842, Section 5. */
2004
#define MHD_HTTP_METHOD_STR_UNBIND         "UNBIND"
2005
/* Not safe. Idempotent.     RFC3253, Section 4.5. */
2006
#define MHD_HTTP_METHOD_STR_UNCHECKOUT     "UNCHECKOUT"
2007
/* Not safe. Idempotent.     RFC2068, Section 19.6.1.3. */
2008
#define MHD_HTTP_METHOD_STR_UNLINK         "UNLINK"
2009
/* Not safe. Idempotent.     RFC4918, Section 9.11. */
2010
#define MHD_HTTP_METHOD_STR_UNLOCK         "UNLOCK"
2011
/* Not safe. Idempotent.     RFC3253, Section 7.1. */
2012
#define MHD_HTTP_METHOD_STR_UPDATE         "UPDATE"
2013
/* Not safe. Idempotent.     RFC4437, Section 7. */
2014
#define MHD_HTTP_METHOD_STR_UPDATEREDIRECTREF "UPDATEREDIRECTREF"
2015
/* Not safe. Idempotent.     RFC3253, Section 3.5. */
2016
#define MHD_HTTP_METHOD_STR_VERSION_CONTROL "VERSION-CONTROL"
2017
2018
/** @} */ /* end of group methods */
2019
2020
#ifndef MHD_HTTP_POSTENCODING_DEFINED
2021
2022
2023
/**
2024
 * @brief Possible encodings for HTML forms submitted as HTTP POST requests
2025
 *
2026
 * @defgroup postenc HTTP POST encodings
2027
 * See also: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#form-submission-2
2028
 * @{
2029
 */
2030
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_HTTP_PostEncoding
2031
{
2032
  /**
2033
   * No post encoding / broken data / unknown encoding
2034
   */
2035
  MHD_HTTP_POST_ENCODING_OTHER = 0
2036
  ,
2037
  /**
2038
   * "application/x-www-form-urlencoded"
2039
   * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#url-encoded-form-data
2040
   * See https://url.spec.whatwg.org/#application/x-www-form-urlencoded
2041
   * See https://datatracker.ietf.org/doc/html/rfc3986#section-2
2042
   */
2043
  MHD_HTTP_POST_ENCODING_FORM_URLENCODED = 1
2044
  ,
2045
  /**
2046
   * "multipart/form-data"
2047
   * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data
2048
   * See https://www.rfc-editor.org/rfc/rfc7578.html
2049
   */
2050
  MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA = 2
2051
  ,
2052
  /**
2053
   * "text/plain"
2054
   * Introduced by HTML5
2055
   * See https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data
2056
   * @warning Format is ambiguous. Do not use unless there is a very strong reason.
2057
   */
2058
  MHD_HTTP_POST_ENCODING_TEXT_PLAIN = 3
2059
};
2060
2061
2062
/** @} */ /* end of group postenc */
2063
2064
#  define MHD_HTTP_POSTENCODING_DEFINED 1
2065
#endif /* ! MHD_HTTP_POSTENCODING_DEFINED */
2066
2067
2068
/**
2069
 * @brief Standard headers found in HTTP requests and responses.
2070
 *
2071
 * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml
2072
 *
2073
 * @defgroup headers HTTP headers
2074
 * Registry export date: 2023-10-02
2075
 * @{
2076
 */
2077
2078
/* Main HTTP headers. */
2079
/* Permanent.     RFC9110, Section 12.5.1: HTTP Semantics */
2080
#define MHD_HTTP_HEADER_ACCEPT       "Accept"
2081
/* Deprecated.    RFC9110, Section 12.5.2: HTTP Semantics */
2082
#define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
2083
/* Permanent.     RFC9110, Section 12.5.3: HTTP Semantics */
2084
#define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
2085
/* Permanent.     RFC9110, Section 12.5.4: HTTP Semantics */
2086
#define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
2087
/* Permanent.     RFC9110, Section 14.3: HTTP Semantics */
2088
#define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
2089
/* Permanent.     RFC9111, Section 5.1: HTTP Caching */
2090
#define MHD_HTTP_HEADER_AGE          "Age"
2091
/* Permanent.     RFC9110, Section 10.2.1: HTTP Semantics */
2092
#define MHD_HTTP_HEADER_ALLOW        "Allow"
2093
/* Permanent.     RFC9110, Section 11.6.3: HTTP Semantics */
2094
#define MHD_HTTP_HEADER_AUTHENTICATION_INFO "Authentication-Info"
2095
/* Permanent.     RFC9110, Section 11.6.2: HTTP Semantics */
2096
#define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
2097
/* Permanent.     RFC9111, Section 5.2 */
2098
#define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
2099
/* Permanent.     RFC9112, Section 9.6: HTTP/1.1 */
2100
#define MHD_HTTP_HEADER_CLOSE        "Close"
2101
/* Permanent.     RFC9110, Section 7.6.1: HTTP Semantics */
2102
#define MHD_HTTP_HEADER_CONNECTION   "Connection"
2103
/* Permanent.     RFC9110, Section 8.4: HTTP Semantics */
2104
#define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
2105
/* Permanent.     RFC9110, Section 8.5: HTTP Semantics */
2106
#define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
2107
/* Permanent.     RFC9110, Section 8.6: HTTP Semantics */
2108
#define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
2109
/* Permanent.     RFC9110, Section 8.7: HTTP Semantics */
2110
#define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
2111
/* Permanent.     RFC9110, Section 14.4: HTTP Semantics */
2112
#define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
2113
/* Permanent.     RFC9110, Section 8.3: HTTP Semantics */
2114
#define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
2115
/* Permanent.     RFC9110, Section 6.6.1: HTTP Semantics */
2116
#define MHD_HTTP_HEADER_DATE         "Date"
2117
/* Permanent.     RFC9110, Section 8.8.3: HTTP Semantics */
2118
#define MHD_HTTP_HEADER_ETAG         "ETag"
2119
/* Permanent.     RFC9110, Section 10.1.1: HTTP Semantics */
2120
#define MHD_HTTP_HEADER_EXPECT       "Expect"
2121
/* Permanent.     RFC9111, Section 5.3: HTTP Caching */
2122
#define MHD_HTTP_HEADER_EXPIRES      "Expires"
2123
/* Permanent.     RFC9110, Section 10.1.2: HTTP Semantics */
2124
#define MHD_HTTP_HEADER_FROM         "From"
2125
/* Permanent.     RFC9110, Section 7.2: HTTP Semantics */
2126
0
#define MHD_HTTP_HEADER_HOST         "Host"
2127
/* Permanent.     RFC9110, Section 13.1.1: HTTP Semantics */
2128
#define MHD_HTTP_HEADER_IF_MATCH     "If-Match"
2129
/* Permanent.     RFC9110, Section 13.1.3: HTTP Semantics */
2130
#define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
2131
/* Permanent.     RFC9110, Section 13.1.2: HTTP Semantics */
2132
#define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
2133
/* Permanent.     RFC9110, Section 13.1.5: HTTP Semantics */
2134
#define MHD_HTTP_HEADER_IF_RANGE     "If-Range"
2135
/* Permanent.     RFC9110, Section 13.1.4: HTTP Semantics */
2136
#define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
2137
/* Permanent.     RFC9110, Section 8.8.2: HTTP Semantics */
2138
#define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
2139
/* Permanent.     RFC9110, Section 10.2.2: HTTP Semantics */
2140
0
#define MHD_HTTP_HEADER_LOCATION     "Location"
2141
/* Permanent.     RFC9110, Section 7.6.2: HTTP Semantics */
2142
#define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
2143
/* Permanent.     RFC9112, Appendix B.1: HTTP/1.1 */
2144
#define MHD_HTTP_HEADER_MIME_VERSION "MIME-Version"
2145
/* Deprecated.    RFC9111, Section 5.4: HTTP Caching */
2146
#define MHD_HTTP_HEADER_PRAGMA       "Pragma"
2147
/* Permanent.     RFC9110, Section 11.7.1: HTTP Semantics */
2148
#define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
2149
/* Permanent.     RFC9110, Section 11.7.3: HTTP Semantics */
2150
#define MHD_HTTP_HEADER_PROXY_AUTHENTICATION_INFO "Proxy-Authentication-Info"
2151
/* Permanent.     RFC9110, Section 11.7.2: HTTP Semantics */
2152
#define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
2153
/* Permanent.     RFC9110, Section 14.2: HTTP Semantics */
2154
#define MHD_HTTP_HEADER_RANGE        "Range"
2155
/* Permanent.     RFC9110, Section 10.1.3: HTTP Semantics */
2156
#define MHD_HTTP_HEADER_REFERER      "Referer"
2157
/* Permanent.     RFC9110, Section 10.2.3: HTTP Semantics */
2158
#define MHD_HTTP_HEADER_RETRY_AFTER  "Retry-After"
2159
/* Permanent.     RFC9110, Section 10.2.4: HTTP Semantics */
2160
#define MHD_HTTP_HEADER_SERVER       "Server"
2161
/* Permanent.     RFC9110, Section 10.1.4: HTTP Semantics */
2162
#define MHD_HTTP_HEADER_TE           "TE"
2163
/* Permanent.     RFC9110, Section 6.6.2: HTTP Semantics */
2164
#define MHD_HTTP_HEADER_TRAILER      "Trailer"
2165
/* Permanent.     RFC9112, Section 6.1: HTTP Semantics */
2166
#define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
2167
/* Permanent.     RFC9110, Section 7.8: HTTP Semantics */
2168
#define MHD_HTTP_HEADER_UPGRADE      "Upgrade"
2169
/* Permanent.     RFC9110, Section 10.1.5: HTTP Semantics */
2170
#define MHD_HTTP_HEADER_USER_AGENT   "User-Agent"
2171
/* Permanent.     RFC9110, Section 12.5.5: HTTP Semantics */
2172
#define MHD_HTTP_HEADER_VARY         "Vary"
2173
/* Permanent.     RFC9110, Section 7.6.3: HTTP Semantics */
2174
#define MHD_HTTP_HEADER_VIA          "Via"
2175
/* Permanent.     RFC9110, Section 11.6.1: HTTP Semantics */
2176
#define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
2177
/* Permanent.     RFC9110, Section 12.5.5: HTTP Semantics */
2178
#define MHD_HTTP_HEADER_ASTERISK     "*"
2179
2180
/* Additional HTTP headers. */
2181
/* Permanent.     RFC 3229: Delta encoding in HTTP */
2182
#define MHD_HTTP_HEADER_A_IM         "A-IM"
2183
/* Permanent.     RFC 2324: Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) */
2184
#define MHD_HTTP_HEADER_ACCEPT_ADDITIONS "Accept-Additions"
2185
/* Permanent.     RFC 8942, Section 3.1: HTTP Client Hints */
2186
#define MHD_HTTP_HEADER_ACCEPT_CH    "Accept-CH"
2187
/* Permanent.     RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
2188
#define MHD_HTTP_HEADER_ACCEPT_DATETIME "Accept-Datetime"
2189
/* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
2190
#define MHD_HTTP_HEADER_ACCEPT_FEATURES "Accept-Features"
2191
/* Permanent.     RFC 5789: PATCH Method for HTTP */
2192
#define MHD_HTTP_HEADER_ACCEPT_PATCH "Accept-Patch"
2193
/* Permanent.     Linked Data Platform 1.0 */
2194
#define MHD_HTTP_HEADER_ACCEPT_POST  "Accept-Post"
2195
/* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 5.1: HTTP Message Signatures */
2196
#define MHD_HTTP_HEADER_ACCEPT_SIGNATURE "Accept-Signature"
2197
/* Permanent.     Fetch */
2198
#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS \
2199
        "Access-Control-Allow-Credentials"
2200
/* Permanent.     Fetch */
2201
#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_HEADERS \
2202
        "Access-Control-Allow-Headers"
2203
/* Permanent.     Fetch */
2204
#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_METHODS \
2205
        "Access-Control-Allow-Methods"
2206
/* Permanent.     Fetch */
2207
#define MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN \
2208
        "Access-Control-Allow-Origin"
2209
/* Permanent.     Fetch */
2210
#define MHD_HTTP_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS \
2211
        "Access-Control-Expose-Headers"
2212
/* Permanent.     Fetch */
2213
#define MHD_HTTP_HEADER_ACCESS_CONTROL_MAX_AGE "Access-Control-Max-Age"
2214
/* Permanent.     Fetch */
2215
#define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_HEADERS \
2216
        "Access-Control-Request-Headers"
2217
/* Permanent.     Fetch */
2218
#define MHD_HTTP_HEADER_ACCESS_CONTROL_REQUEST_METHOD \
2219
        "Access-Control-Request-Method"
2220
/* Permanent.     RFC 7639, Section 2: The ALPN HTTP Header Field */
2221
#define MHD_HTTP_HEADER_ALPN         "ALPN"
2222
/* Permanent.     RFC 7838: HTTP Alternative Services */
2223
#define MHD_HTTP_HEADER_ALT_SVC      "Alt-Svc"
2224
/* Permanent.     RFC 7838: HTTP Alternative Services */
2225
#define MHD_HTTP_HEADER_ALT_USED     "Alt-Used"
2226
/* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
2227
#define MHD_HTTP_HEADER_ALTERNATES   "Alternates"
2228
/* Permanent.     RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
2229
#define MHD_HTTP_HEADER_APPLY_TO_REDIRECT_REF "Apply-To-Redirect-Ref"
2230
/* Permanent.     RFC 8053, Section 4: HTTP Authentication Extensions for Interactive Clients */
2231
#define MHD_HTTP_HEADER_AUTHENTICATION_CONTROL "Authentication-Control"
2232
/* Permanent.     RFC9211: The Cache-Status HTTP Response Header Field */
2233
#define MHD_HTTP_HEADER_CACHE_STATUS "Cache-Status"
2234
/* Permanent.     RFC 8607, Section 5.1: Calendaring Extensions to WebDAV (CalDAV): Managed Attachments */
2235
#define MHD_HTTP_HEADER_CAL_MANAGED_ID "Cal-Managed-ID"
2236
/* Permanent.     RFC 7809, Section 7.1: Calendaring Extensions to WebDAV (CalDAV): Time Zones by Reference */
2237
#define MHD_HTTP_HEADER_CALDAV_TIMEZONES "CalDAV-Timezones"
2238
/* Permanent.     RFC9297 */
2239
#define MHD_HTTP_HEADER_CAPSULE_PROTOCOL "Capsule-Protocol"
2240
/* Permanent.     RFC9213: Targeted HTTP Cache Control */
2241
#define MHD_HTTP_HEADER_CDN_CACHE_CONTROL "CDN-Cache-Control"
2242
/* Permanent.     RFC 8586: Loop Detection in Content Delivery Networks (CDNs) */
2243
#define MHD_HTTP_HEADER_CDN_LOOP     "CDN-Loop"
2244
/* Permanent.     RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
2245
#define MHD_HTTP_HEADER_CERT_NOT_AFTER "Cert-Not-After"
2246
/* Permanent.     RFC 8739, Section 3.3: Support for Short-Term, Automatically Renewed (STAR) Certificates in the Automated Certificate Management Environment (ACME) */
2247
#define MHD_HTTP_HEADER_CERT_NOT_BEFORE "Cert-Not-Before"
2248
/* Permanent.     Clear Site Data */
2249
#define MHD_HTTP_HEADER_CLEAR_SITE_DATA "Clear-Site-Data"
2250
/* Permanent.     RFC9440, Section 2: Client-Cert HTTP Header Field */
2251
#define MHD_HTTP_HEADER_CLIENT_CERT  "Client-Cert"
2252
/* Permanent.     RFC9440, Section 2: Client-Cert HTTP Header Field */
2253
#define MHD_HTTP_HEADER_CLIENT_CERT_CHAIN "Client-Cert-Chain"
2254
/* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 2: Digest Fields */
2255
#define MHD_HTTP_HEADER_CONTENT_DIGEST "Content-Digest"
2256
/* Permanent.     RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP) */
2257
#define MHD_HTTP_HEADER_CONTENT_DISPOSITION "Content-Disposition"
2258
/* Permanent.     The HTTP Distribution and Replication Protocol */
2259
#define MHD_HTTP_HEADER_CONTENT_ID   "Content-ID"
2260
/* Permanent.     Content Security Policy Level 3 */
2261
#define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY "Content-Security-Policy"
2262
/* Permanent.     Content Security Policy Level 3 */
2263
#define MHD_HTTP_HEADER_CONTENT_SECURITY_POLICY_REPORT_ONLY \
2264
        "Content-Security-Policy-Report-Only"
2265
/* Permanent.     RFC 6265: HTTP State Management Mechanism */
2266
#define MHD_HTTP_HEADER_COOKIE       "Cookie"
2267
/* Permanent.     HTML */
2268
#define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY \
2269
        "Cross-Origin-Embedder-Policy"
2270
/* Permanent.     HTML */
2271
#define MHD_HTTP_HEADER_CROSS_ORIGIN_EMBEDDER_POLICY_REPORT_ONLY \
2272
        "Cross-Origin-Embedder-Policy-Report-Only"
2273
/* Permanent.     HTML */
2274
#define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY "Cross-Origin-Opener-Policy"
2275
/* Permanent.     HTML */
2276
#define MHD_HTTP_HEADER_CROSS_ORIGIN_OPENER_POLICY_REPORT_ONLY \
2277
        "Cross-Origin-Opener-Policy-Report-Only"
2278
/* Permanent.     Fetch */
2279
#define MHD_HTTP_HEADER_CROSS_ORIGIN_RESOURCE_POLICY \
2280
        "Cross-Origin-Resource-Policy"
2281
/* Permanent.     RFC 5323: Web Distributed Authoring and Versioning (WebDAV) SEARCH */
2282
#define MHD_HTTP_HEADER_DASL         "DASL"
2283
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2284
#define MHD_HTTP_HEADER_DAV          "DAV"
2285
/* Permanent.     RFC 3229: Delta encoding in HTTP */
2286
#define MHD_HTTP_HEADER_DELTA_BASE   "Delta-Base"
2287
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2288
#define MHD_HTTP_HEADER_DEPTH        "Depth"
2289
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2290
#define MHD_HTTP_HEADER_DESTINATION  "Destination"
2291
/* Permanent.     The HTTP Distribution and Replication Protocol */
2292
#define MHD_HTTP_HEADER_DIFFERENTIAL_ID "Differential-ID"
2293
/* Permanent.     RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
2294
#define MHD_HTTP_HEADER_DPOP         "DPoP"
2295
/* Permanent.     RFC9449: OAuth 2.0 Demonstrating Proof of Possession (DPoP) */
2296
#define MHD_HTTP_HEADER_DPOP_NONCE   "DPoP-Nonce"
2297
/* Permanent.     RFC 8470: Using Early Data in HTTP */
2298
#define MHD_HTTP_HEADER_EARLY_DATA   "Early-Data"
2299
/* Permanent.     RFC9163: Expect-CT Extension for HTTP */
2300
#define MHD_HTTP_HEADER_EXPECT_CT    "Expect-CT"
2301
/* Permanent.     RFC 7239: Forwarded HTTP Extension */
2302
#define MHD_HTTP_HEADER_FORWARDED    "Forwarded"
2303
/* Permanent.     RFC 7486, Section 6.1.1: HTTP Origin-Bound Authentication (HOBA) */
2304
#define MHD_HTTP_HEADER_HOBAREG      "Hobareg"
2305
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2306
#define MHD_HTTP_HEADER_IF           "If"
2307
/* Permanent.      RFC 6338: Scheduling Extensions to CalDAV */
2308
#define MHD_HTTP_HEADER_IF_SCHEDULE_TAG_MATCH "If-Schedule-Tag-Match"
2309
/* Permanent.     RFC 3229: Delta encoding in HTTP */
2310
#define MHD_HTTP_HEADER_IM           "IM"
2311
/* Permanent.     RFC 8473: Token Binding over HTTP */
2312
#define MHD_HTTP_HEADER_INCLUDE_REFERRED_TOKEN_BINDING_ID \
2313
        "Include-Referred-Token-Binding-ID"
2314
/* Permanent.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
2315
#define MHD_HTTP_HEADER_KEEP_ALIVE   "Keep-Alive"
2316
/* Permanent.     RFC 3253: Versioning Extensions to WebDAV: (Web Distributed Authoring and Versioning) */
2317
#define MHD_HTTP_HEADER_LABEL        "Label"
2318
/* Permanent.     HTML */
2319
#define MHD_HTTP_HEADER_LAST_EVENT_ID "Last-Event-ID"
2320
/* Permanent.     RFC 8288: Web Linking */
2321
#define MHD_HTTP_HEADER_LINK         "Link"
2322
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2323
#define MHD_HTTP_HEADER_LOCK_TOKEN   "Lock-Token"
2324
/* Permanent.     RFC 7089: HTTP Framework for Time-Based Access to Resource States -- Memento */
2325
#define MHD_HTTP_HEADER_MEMENTO_DATETIME "Memento-Datetime"
2326
/* Permanent.     RFC 2227: Simple Hit-Metering and Usage-Limiting for HTTP */
2327
#define MHD_HTTP_HEADER_METER        "Meter"
2328
/* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
2329
#define MHD_HTTP_HEADER_NEGOTIATE    "Negotiate"
2330
/* Permanent.     Network Error Logging */
2331
#define MHD_HTTP_HEADER_NEL          "NEL"
2332
/* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
2333
#define MHD_HTTP_HEADER_ODATA_ENTITYID "OData-EntityId"
2334
/* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
2335
#define MHD_HTTP_HEADER_ODATA_ISOLATION "OData-Isolation"
2336
/* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
2337
#define MHD_HTTP_HEADER_ODATA_MAXVERSION "OData-MaxVersion"
2338
/* Permanent.     OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
2339
#define MHD_HTTP_HEADER_ODATA_VERSION "OData-Version"
2340
/* Permanent.     RFC 8053, Section 3: HTTP Authentication Extensions for Interactive Clients */
2341
#define MHD_HTTP_HEADER_OPTIONAL_WWW_AUTHENTICATE "Optional-WWW-Authenticate"
2342
/* Permanent.     RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
2343
#define MHD_HTTP_HEADER_ORDERING_TYPE "Ordering-Type"
2344
/* Permanent.     RFC 6454: The Web Origin Concept */
2345
#define MHD_HTTP_HEADER_ORIGIN       "Origin"
2346
/* Permanent.     HTML */
2347
#define MHD_HTTP_HEADER_ORIGIN_AGENT_CLUSTER "Origin-Agent-Cluster"
2348
/* Permanent.     RFC 8613, Section 11.1: Object Security for Constrained RESTful Environments (OSCORE) */
2349
#define MHD_HTTP_HEADER_OSCORE       "OSCORE"
2350
/* Permanent.     OASIS Project Specification 01; OASIS; Chet_Ensign */
2351
#define MHD_HTTP_HEADER_OSLC_CORE_VERSION "OSLC-Core-Version"
2352
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2353
#define MHD_HTTP_HEADER_OVERWRITE    "Overwrite"
2354
/* Permanent.     HTML */
2355
#define MHD_HTTP_HEADER_PING_FROM    "Ping-From"
2356
/* Permanent.     HTML */
2357
#define MHD_HTTP_HEADER_PING_TO      "Ping-To"
2358
/* Permanent.     RFC 3648: Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol */
2359
#define MHD_HTTP_HEADER_POSITION     "Position"
2360
/* Permanent.     RFC 7240: Prefer Header for HTTP */
2361
#define MHD_HTTP_HEADER_PREFER       "Prefer"
2362
/* Permanent.     RFC 7240: Prefer Header for HTTP */
2363
#define MHD_HTTP_HEADER_PREFERENCE_APPLIED "Preference-Applied"
2364
/* Permanent.     RFC9218: Extensible Prioritization Scheme for HTTP */
2365
#define MHD_HTTP_HEADER_PRIORITY     "Priority"
2366
/* Permanent.     RFC9209: The Proxy-Status HTTP Response Header Field */
2367
#define MHD_HTTP_HEADER_PROXY_STATUS "Proxy-Status"
2368
/* Permanent.     RFC 7469: Public Key Pinning Extension for HTTP */
2369
#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS "Public-Key-Pins"
2370
/* Permanent.     RFC 7469: Public Key Pinning Extension for HTTP */
2371
#define MHD_HTTP_HEADER_PUBLIC_KEY_PINS_REPORT_ONLY \
2372
        "Public-Key-Pins-Report-Only"
2373
/* Permanent.     RFC 4437: Web Distributed Authoring and Versioning (WebDAV) Redirect Reference Resources */
2374
#define MHD_HTTP_HEADER_REDIRECT_REF "Redirect-Ref"
2375
/* Permanent.     HTML */
2376
#define MHD_HTTP_HEADER_REFRESH      "Refresh"
2377
/* Permanent.     RFC 8555, Section 6.5.1: Automatic Certificate Management Environment (ACME) */
2378
#define MHD_HTTP_HEADER_REPLAY_NONCE "Replay-Nonce"
2379
/* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 3: Digest Fields */
2380
#define MHD_HTTP_HEADER_REPR_DIGEST  "Repr-Digest"
2381
/* Permanent.     RFC 6638: Scheduling Extensions to CalDAV */
2382
#define MHD_HTTP_HEADER_SCHEDULE_REPLY "Schedule-Reply"
2383
/* Permanent.     RFC 6338: Scheduling Extensions to CalDAV */
2384
#define MHD_HTTP_HEADER_SCHEDULE_TAG "Schedule-Tag"
2385
/* Permanent.     Fetch */
2386
#define MHD_HTTP_HEADER_SEC_PURPOSE  "Sec-Purpose"
2387
/* Permanent.     RFC 8473: Token Binding over HTTP */
2388
#define MHD_HTTP_HEADER_SEC_TOKEN_BINDING "Sec-Token-Binding"
2389
/* Permanent.     RFC 6455: The WebSocket Protocol */
2390
#define MHD_HTTP_HEADER_SEC_WEBSOCKET_ACCEPT "Sec-WebSocket-Accept"
2391
/* Permanent.     RFC 6455: The WebSocket Protocol */
2392
#define MHD_HTTP_HEADER_SEC_WEBSOCKET_EXTENSIONS "Sec-WebSocket-Extensions"
2393
/* Permanent.     RFC 6455: The WebSocket Protocol */
2394
#define MHD_HTTP_HEADER_SEC_WEBSOCKET_KEY "Sec-WebSocket-Key"
2395
/* Permanent.     RFC 6455: The WebSocket Protocol */
2396
#define MHD_HTTP_HEADER_SEC_WEBSOCKET_PROTOCOL "Sec-WebSocket-Protocol"
2397
/* Permanent.     RFC 6455: The WebSocket Protocol */
2398
#define MHD_HTTP_HEADER_SEC_WEBSOCKET_VERSION "Sec-WebSocket-Version"
2399
/* Permanent.     Server Timing */
2400
#define MHD_HTTP_HEADER_SERVER_TIMING "Server-Timing"
2401
/* Permanent.     RFC 6265: HTTP State Management Mechanism */
2402
#define MHD_HTTP_HEADER_SET_COOKIE   "Set-Cookie"
2403
/* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 4.2: HTTP Message Signatures */
2404
#define MHD_HTTP_HEADER_SIGNATURE    "Signature"
2405
/* Permanent.     RFC-ietf-httpbis-message-signatures-19, Section 4.1: HTTP Message Signatures */
2406
#define MHD_HTTP_HEADER_SIGNATURE_INPUT "Signature-Input"
2407
/* Permanent.     RFC 5023: The Atom Publishing Protocol */
2408
#define MHD_HTTP_HEADER_SLUG         "SLUG"
2409
/* Permanent.     Simple Object Access Protocol (SOAP) 1.1 */
2410
#define MHD_HTTP_HEADER_SOAPACTION   "SoapAction"
2411
/* Permanent.     RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV */
2412
#define MHD_HTTP_HEADER_STATUS_URI   "Status-URI"
2413
/* Permanent.     RFC 6797: HTTP Strict Transport Security (HSTS) */
2414
#define MHD_HTTP_HEADER_STRICT_TRANSPORT_SECURITY "Strict-Transport-Security"
2415
/* Permanent.     RFC 8594: The Sunset HTTP Header Field */
2416
#define MHD_HTTP_HEADER_SUNSET       "Sunset"
2417
/* Permanent.     Edge Architecture Specification */
2418
#define MHD_HTTP_HEADER_SURROGATE_CAPABILITY "Surrogate-Capability"
2419
/* Permanent.     Edge Architecture Specification */
2420
#define MHD_HTTP_HEADER_SURROGATE_CONTROL "Surrogate-Control"
2421
/* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
2422
#define MHD_HTTP_HEADER_TCN          "TCN"
2423
/* Permanent.     RFC 4918: HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV) */
2424
#define MHD_HTTP_HEADER_TIMEOUT      "Timeout"
2425
/* Permanent.     RFC 8030, Section 5.4: Generic Event Delivery Using HTTP Push */
2426
#define MHD_HTTP_HEADER_TOPIC        "Topic"
2427
/* Permanent.     Trace Context */
2428
#define MHD_HTTP_HEADER_TRACEPARENT  "Traceparent"
2429
/* Permanent.     Trace Context */
2430
#define MHD_HTTP_HEADER_TRACESTATE   "Tracestate"
2431
/* Permanent.     RFC 8030, Section 5.2: Generic Event Delivery Using HTTP Push */
2432
#define MHD_HTTP_HEADER_TTL          "TTL"
2433
/* Permanent.     RFC 8030, Section 5.3: Generic Event Delivery Using HTTP Push */
2434
#define MHD_HTTP_HEADER_URGENCY      "Urgency"
2435
/* Permanent.     RFC 2295: Transparent Content Negotiation in HTTP */
2436
#define MHD_HTTP_HEADER_VARIANT_VARY "Variant-Vary"
2437
/* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
2438
#define MHD_HTTP_HEADER_WANT_CONTENT_DIGEST "Want-Content-Digest"
2439
/* Permanent.     RFC-ietf-httpbis-digest-headers-13, Section 4: Digest Fields */
2440
#define MHD_HTTP_HEADER_WANT_REPR_DIGEST "Want-Repr-Digest"
2441
/* Permanent.     Fetch */
2442
#define MHD_HTTP_HEADER_X_CONTENT_TYPE_OPTIONS "X-Content-Type-Options"
2443
/* Permanent.     HTML */
2444
#define MHD_HTTP_HEADER_X_FRAME_OPTIONS "X-Frame-Options"
2445
/* Provisional.   AMP-Cache-Transform HTTP request header */
2446
#define MHD_HTTP_HEADER_AMP_CACHE_TRANSFORM "AMP-Cache-Transform"
2447
/* Provisional.   OSLC Configuration Management Version 1.0. Part 3: Configuration Specification */
2448
#define MHD_HTTP_HEADER_CONFIGURATION_CONTEXT "Configuration-Context"
2449
/* Provisional.   RFC 6017: Electronic Data Interchange - Internet Integration (EDIINT) Features Header Field */
2450
#define MHD_HTTP_HEADER_EDIINT_FEATURES "EDIINT-Features"
2451
/* Provisional.   OData Version 4.01 Part 1: Protocol; OASIS; Chet_Ensign */
2452
#define MHD_HTTP_HEADER_ISOLATION    "Isolation"
2453
/* Provisional.   Permissions Policy */
2454
#define MHD_HTTP_HEADER_PERMISSIONS_POLICY "Permissions-Policy"
2455
/* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
2456
#define MHD_HTTP_HEADER_REPEATABILITY_CLIENT_ID "Repeatability-Client-ID"
2457
/* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
2458
#define MHD_HTTP_HEADER_REPEATABILITY_FIRST_SENT "Repeatability-First-Sent"
2459
/* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
2460
#define MHD_HTTP_HEADER_REPEATABILITY_REQUEST_ID "Repeatability-Request-ID"
2461
/* Provisional.   Repeatable Requests Version 1.0; OASIS; Chet_Ensign */
2462
#define MHD_HTTP_HEADER_REPEATABILITY_RESULT "Repeatability-Result"
2463
/* Provisional.   Reporting API */
2464
#define MHD_HTTP_HEADER_REPORTING_ENDPOINTS "Reporting-Endpoints"
2465
/* Provisional.   Global Privacy Control (GPC) */
2466
#define MHD_HTTP_HEADER_SEC_GPC      "Sec-GPC"
2467
/* Provisional.   Resource Timing Level 1 */
2468
#define MHD_HTTP_HEADER_TIMING_ALLOW_ORIGIN "Timing-Allow-Origin"
2469
/* Deprecated.    PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
2470
#define MHD_HTTP_HEADER_C_PEP_INFO   "C-PEP-Info"
2471
/* Deprecated.    White Paper: Joint Electronic Payment Initiative */
2472
#define MHD_HTTP_HEADER_PROTOCOL_INFO "Protocol-Info"
2473
/* Deprecated.    White Paper: Joint Electronic Payment Initiative */
2474
#define MHD_HTTP_HEADER_PROTOCOL_QUERY "Protocol-Query"
2475
/* Obsoleted.     Access Control for Cross-site Requests */
2476
#define MHD_HTTP_HEADER_ACCESS_CONTROL "Access-Control"
2477
/* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
2478
#define MHD_HTTP_HEADER_C_EXT        "C-Ext"
2479
/* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
2480
#define MHD_HTTP_HEADER_C_MAN        "C-Man"
2481
/* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
2482
#define MHD_HTTP_HEADER_C_OPT        "C-Opt"
2483
/* Obsoleted.     PEP - an Extension Mechanism for HTTP; status-change-http-experiments-to-historic */
2484
#define MHD_HTTP_HEADER_C_PEP        "C-PEP"
2485
/* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1; RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 */
2486
#define MHD_HTTP_HEADER_CONTENT_BASE "Content-Base"
2487
/* Obsoleted.     RFC 2616, Section 14.15: Hypertext Transfer Protocol -- HTTP/1.1; RFC 7231, Appendix B: Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content */
2488
#define MHD_HTTP_HEADER_CONTENT_MD5  "Content-MD5"
2489
/* Obsoleted.     HTML 4.01 Specification */
2490
#define MHD_HTTP_HEADER_CONTENT_SCRIPT_TYPE "Content-Script-Type"
2491
/* Obsoleted.     HTML 4.01 Specification */
2492
#define MHD_HTTP_HEADER_CONTENT_STYLE_TYPE "Content-Style-Type"
2493
/* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
2494
#define MHD_HTTP_HEADER_CONTENT_VERSION "Content-Version"
2495
/* Obsoleted.     RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
2496
#define MHD_HTTP_HEADER_COOKIE2      "Cookie2"
2497
/* Obsoleted.     HTML 4.01 Specification */
2498
#define MHD_HTTP_HEADER_DEFAULT_STYLE "Default-Style"
2499
/* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
2500
#define MHD_HTTP_HEADER_DERIVED_FROM "Derived-From"
2501
/* Obsoleted.     RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
2502
#define MHD_HTTP_HEADER_DIGEST       "Digest"
2503
/* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
2504
#define MHD_HTTP_HEADER_EXT          "Ext"
2505
/* Obsoleted.     Implementation of OPS Over HTTP */
2506
#define MHD_HTTP_HEADER_GETPROFILE   "GetProfile"
2507
/* Obsoleted.     RFC 7540, Section 3.2.1: Hypertext Transfer Protocol Version 2 (HTTP/2) */
2508
#define MHD_HTTP_HEADER_HTTP2_SETTINGS "HTTP2-Settings"
2509
/* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
2510
#define MHD_HTTP_HEADER_MAN          "Man"
2511
/* Obsoleted.     Access Control for Cross-site Requests */
2512
#define MHD_HTTP_HEADER_METHOD_CHECK "Method-Check"
2513
/* Obsoleted.     Access Control for Cross-site Requests */
2514
#define MHD_HTTP_HEADER_METHOD_CHECK_EXPIRES "Method-Check-Expires"
2515
/* Obsoleted.     RFC 2774: An HTTP Extension Framework; status-change-http-experiments-to-historic */
2516
#define MHD_HTTP_HEADER_OPT          "Opt"
2517
/* Obsoleted.     The Platform for Privacy Preferences 1.0 (P3P1.0) Specification */
2518
#define MHD_HTTP_HEADER_P3P          "P3P"
2519
/* Obsoleted.     PEP - an Extension Mechanism for HTTP */
2520
#define MHD_HTTP_HEADER_PEP          "PEP"
2521
/* Obsoleted.     PEP - an Extension Mechanism for HTTP */
2522
#define MHD_HTTP_HEADER_PEP_INFO     "Pep-Info"
2523
/* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
2524
#define MHD_HTTP_HEADER_PICS_LABEL   "PICS-Label"
2525
/* Obsoleted.     Implementation of OPS Over HTTP */
2526
#define MHD_HTTP_HEADER_PROFILEOBJECT "ProfileObject"
2527
/* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
2528
#define MHD_HTTP_HEADER_PROTOCOL     "Protocol"
2529
/* Obsoleted.     PICS Label Distribution Label Syntax and Communication Protocols */
2530
#define MHD_HTTP_HEADER_PROTOCOL_REQUEST "Protocol-Request"
2531
/* Obsoleted.     Notification for Proxy Caches */
2532
#define MHD_HTTP_HEADER_PROXY_FEATURES "Proxy-Features"
2533
/* Obsoleted.     Notification for Proxy Caches */
2534
#define MHD_HTTP_HEADER_PROXY_INSTRUCTION "Proxy-Instruction"
2535
/* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
2536
#define MHD_HTTP_HEADER_PUBLIC       "Public"
2537
/* Obsoleted.     Access Control for Cross-site Requests */
2538
#define MHD_HTTP_HEADER_REFERER_ROOT "Referer-Root"
2539
/* Obsoleted.     RFC 2310: The Safe Response Header Field; status-change-http-experiments-to-historic */
2540
#define MHD_HTTP_HEADER_SAFE         "Safe"
2541
/* Obsoleted.     RFC 2660: The Secure HyperText Transfer Protocol; status-change-http-experiments-to-historic */
2542
#define MHD_HTTP_HEADER_SECURITY_SCHEME "Security-Scheme"
2543
/* Obsoleted.     RFC 2965: HTTP State Management Mechanism; RFC 6265: HTTP State Management Mechanism */
2544
#define MHD_HTTP_HEADER_SET_COOKIE2  "Set-Cookie2"
2545
/* Obsoleted.     Implementation of OPS Over HTTP */
2546
#define MHD_HTTP_HEADER_SETPROFILE   "SetProfile"
2547
/* Obsoleted.     RFC 2068: Hypertext Transfer Protocol -- HTTP/1.1 */
2548
#define MHD_HTTP_HEADER_URI          "URI"
2549
/* Obsoleted.     RFC 3230: Instance Digests in HTTP; RFC-ietf-httpbis-digest-headers-13, Section 1.3: Digest Fields */
2550
#define MHD_HTTP_HEADER_WANT_DIGEST  "Want-Digest"
2551
/* Obsoleted.     RFC9111, Section 5.5: HTTP Caching */
2552
#define MHD_HTTP_HEADER_WARNING      "Warning"
2553
2554
/* Headers removed from the registry. Do not use! */
2555
/* Obsoleted.     RFC4229 */
2556
#define MHD_HTTP_HEADER_COMPLIANCE   "Compliance"
2557
/* Obsoleted.     RFC4229 */
2558
#define MHD_HTTP_HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
2559
/* Obsoleted.     RFC4229 */
2560
#define MHD_HTTP_HEADER_COST         "Cost"
2561
/* Obsoleted.     RFC4229 */
2562
#define MHD_HTTP_HEADER_MESSAGE_ID   "Message-ID"
2563
/* Obsoleted.     RFC4229 */
2564
#define MHD_HTTP_HEADER_NON_COMPLIANCE "Non-Compliance"
2565
/* Obsoleted.     RFC4229 */
2566
#define MHD_HTTP_HEADER_OPTIONAL     "Optional"
2567
/* Obsoleted.     RFC4229 */
2568
#define MHD_HTTP_HEADER_RESOLUTION_HINT "Resolution-Hint"
2569
/* Obsoleted.     RFC4229 */
2570
#define MHD_HTTP_HEADER_RESOLVER_LOCATION "Resolver-Location"
2571
/* Obsoleted.     RFC4229 */
2572
#define MHD_HTTP_HEADER_SUBOK        "SubOK"
2573
/* Obsoleted.     RFC4229 */
2574
#define MHD_HTTP_HEADER_SUBST        "Subst"
2575
/* Obsoleted.     RFC4229 */
2576
#define MHD_HTTP_HEADER_TITLE        "Title"
2577
/* Obsoleted.     RFC4229 */
2578
#define MHD_HTTP_HEADER_UA_COLOR     "UA-Color"
2579
/* Obsoleted.     RFC4229 */
2580
#define MHD_HTTP_HEADER_UA_MEDIA     "UA-Media"
2581
/* Obsoleted.     RFC4229 */
2582
#define MHD_HTTP_HEADER_UA_PIXELS    "UA-Pixels"
2583
/* Obsoleted.     RFC4229 */
2584
#define MHD_HTTP_HEADER_UA_RESOLUTION "UA-Resolution"
2585
/* Obsoleted.     RFC4229 */
2586
#define MHD_HTTP_HEADER_UA_WINDOWPIXELS "UA-Windowpixels"
2587
/* Obsoleted.     RFC4229 */
2588
#define MHD_HTTP_HEADER_VERSION      "Version"
2589
/* Obsoleted.     W3C Mobile Web Best Practices Working Group */
2590
#define MHD_HTTP_HEADER_X_DEVICE_ACCEPT "X-Device-Accept"
2591
/* Obsoleted.     W3C Mobile Web Best Practices Working Group */
2592
#define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_CHARSET "X-Device-Accept-Charset"
2593
/* Obsoleted.     W3C Mobile Web Best Practices Working Group */
2594
#define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_ENCODING "X-Device-Accept-Encoding"
2595
/* Obsoleted.     W3C Mobile Web Best Practices Working Group */
2596
#define MHD_HTTP_HEADER_X_DEVICE_ACCEPT_LANGUAGE "X-Device-Accept-Language"
2597
/* Obsoleted.     W3C Mobile Web Best Practices Working Group */
2598
#define MHD_HTTP_HEADER_X_DEVICE_USER_AGENT "X-Device-User-Agent"
2599
2600
2601
/**
2602
 * Predefined list of headers
2603
 * To be filled with HPACK static data
2604
 */
2605
enum MHD_PredefinedHeader
2606
{
2607
  MHD_PREDEF_ACCEPT_CHARSET = 15,
2608
  MHD_PREDEF_ACCEPT_LANGUAGE = 17
2609
};
2610
2611
2612
/** @} */ /* end of group headers */
2613
2614
/**
2615
 * A client has requested the given url using the given method
2616
 * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
2617
 * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc).
2618
 * If @a upload_size is not zero and response action is provided by this
2619
 * callback, then upload will be discarded and the stream (the connection for
2620
 * HTTP/1.1) will be closed after sending the response.
2621
 *
2622
 * @param cls argument given together with the function
2623
 *        pointer when the handler was registered with MHD
2624
 * @param request the request object
2625
 * @param path the requested uri (without arguments after "?")
2626
 * @param method the HTTP method used (#MHD_HTTP_METHOD_GET,
2627
 *        #MHD_HTTP_METHOD_PUT, etc.)
2628
 * @param upload_size the size of the message upload content payload,
2629
 *                    #MHD_SIZE_UNKNOWN for chunked uploads (if the
2630
 *                    final chunk has not been processed yet)
2631
 * @return action how to proceed, NULL
2632
 *         if the request must be aborted due to a serious
2633
 *         error while handling the request (implies closure
2634
 *         of underling data stream, for HTTP/1.1 it means
2635
 *         socket closure).
2636
 */
2637
typedef const struct MHD_Action *
2638
(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (3)
2639
 *MHD_RequestCallback)(void *cls,
2640
                       struct MHD_Request *MHD_RESTRICT request,
2641
                       const struct MHD_String *MHD_RESTRICT path,
2642
                       enum MHD_HTTP_Method method,
2643
                       uint_fast64_t upload_size);
2644
2645
2646
/**
2647
 * Create (but do not yet start) an MHD daemon.
2648
 * Usually, various options are set before
2649
 * starting the daemon with #MHD_daemon_start().
2650
 *
2651
 * @param req_cb the function to be called for incoming requests
2652
 * @param req_cb_cls the closure for @a cb
2653
 * @return the pointer to the new object on success,
2654
 *         NULL on error (like out-of-memory)
2655
 */
2656
MHD_EXTERN_ struct MHD_Daemon *
2657
MHD_daemon_create (MHD_RequestCallback req_cb,
2658
                   void *req_cb_cls)
2659
MHD_FN_MUST_CHECK_RESULT_;
2660
2661
2662
/**
2663
 * Start a webserver.
2664
 * This function:
2665
 * + checks the combination of set options,
2666
 * + initialises the TLS library (if TLS is requested),
2667
 * + creates the listen socket (if not provided and if allowed),
2668
 * + starts the daemon internal threads (if allowed)
2669
 *
2670
 * @param[in,out] daemon daemon to start; you can no longer set
2671
 *        options on this daemon after this call!
2672
 * @return #MHD_SC_OK on success
2673
 * @ingroup daemon
2674
 */
2675
MHD_EXTERN_ enum MHD_StatusCode
2676
MHD_daemon_start (struct MHD_Daemon *daemon)
2677
MHD_FN_PAR_NONNULL_ (1) MHD_FN_MUST_CHECK_RESULT_;
2678
2679
2680
/**
2681
 * Stop accepting connections from the listening socket.  Allows
2682
 * clients to continue processing, but stops accepting new
2683
 * connections.  Note that the caller is responsible for closing the
2684
 * returned socket; however, if MHD is run using threads (anything but
2685
 * external select mode), it must not be closed until AFTER
2686
 * #MHD_daemon_destroy() has been called (as it is theoretically possible
2687
 * that an existing thread is still using it).
2688
 *
2689
 * @param[in,out] daemon the daemon to stop accepting new connections for
2690
 * @return the old listen socket on success, #MHD_INVALID_SOCKET if
2691
 *         the daemon was already not listening anymore, or
2692
 *         was never started, or has no listen socket.
2693
 * @ingroup daemon
2694
 */
2695
MHD_EXTERN_ MHD_Socket
2696
MHD_daemon_quiesce (struct MHD_Daemon *daemon)
2697
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1);
2698
2699
2700
/**
2701
 * Shutdown and destroy an HTTP daemon.
2702
 *
2703
 * @param[in] daemon daemon to stop
2704
 * @ingroup daemon
2705
 */
2706
MHD_EXTERN_ void
2707
MHD_daemon_destroy (struct MHD_Daemon *daemon)
2708
MHD_FN_PAR_NONNULL_ALL_;
2709
2710
/* ******************* External event loop ************************ */
2711
2712
/**
2713
 * @defgroup event External network events processing
2714
 */
2715
2716
/**
2717
 * The network status of the socket.
2718
 * When set by MHD (by #MHD_SocketRegistrationUpdateCallback or
2719
 * similar) it indicates a request to watch for specific socket state:
2720
 * watch for readiness for receiving the data, watch for readiness for sending
2721
 * the data and/or watch for exception state of the socket.
2722
 * When set by application (and provided for #MHD_daemon_event_update() and
2723
 * similar) it must indicate the actual status of the socket.
2724
 *
2725
 * Any actual state is a bitwise OR combination of #MHD_FD_STATE_RECV,
2726
 * #MHD_FD_STATE_SEND, #MHD_FD_STATE_EXCEPT.
2727
 * @ingroup event
2728
 */
2729
enum MHD_FIXED_ENUM_ MHD_FdState
2730
{
2731
  /**
2732
   * The socket is not ready for receiving or sending and
2733
   * does not have any exceptional state.
2734
   * The state never set by MHD, except de-registration of the sockets
2735
   * in a #MHD_SocketRegistrationUpdateCallback.
2736
   */
2737
  MHD_FD_STATE_NONE = 0
2738
  ,
2739
  /* ** Three bit-flags ** */
2740
2741
  /**
2742
   * Indicates that socket should be watched for incoming data
2743
   * (when set by #MHD_SocketRegistrationUpdateCallback)
2744
   * / socket has incoming data ready to read (when used for
2745
   * #MHD_daemon_event_update())
2746
   */
2747
  MHD_FD_STATE_RECV = 1 << 0
2748
  ,
2749
  /**
2750
   * Indicates that socket should be watched for availability for sending
2751
   * (when set by #MHD_SocketRegistrationUpdateCallback)
2752
   * / socket has ability to send data (when used for
2753
   * #MHD_daemon_event_update())
2754
   */
2755
  MHD_FD_STATE_SEND = 1 << 1
2756
  ,
2757
  /**
2758
   * Indicates that socket should be watched for disconnect, out-of-band
2759
   * data available or high priority data available (when set by
2760
   * #MHD_SocketRegistrationUpdateCallback)
2761
   * / socket has been disconnected, has out-of-band data available or
2762
   * has high priority data available (when used for
2763
   * #MHD_daemon_event_update()). This status must not include "remote
2764
   * peer shut down writing" status.
2765
   * Note: #MHD_SocketRegistrationUpdateCallback() always set it as exceptions
2766
   * must be always watched.
2767
   */
2768
  MHD_FD_STATE_EXCEPT = 1 << 2
2769
  ,
2770
2771
  /* The rest of the list is a bit-wise combination of three main
2772
   * states. Application may use three main states directly as
2773
   * a bit-mask instead of using of the following values
2774
   */
2775
2776
  /**
2777
   * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_SEND states.
2778
   */
2779
  MHD_FD_STATE_RECV_SEND = MHD_FD_STATE_RECV | MHD_FD_STATE_SEND
2780
  ,
2781
  /**
2782
   * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_EXCEPT states.
2783
   */
2784
  MHD_FD_STATE_RECV_EXCEPT = MHD_FD_STATE_RECV | MHD_FD_STATE_EXCEPT
2785
  ,
2786
  /**
2787
   * Combination of #MHD_FD_STATE_RECV and #MHD_FD_STATE_EXCEPT states.
2788
   */
2789
  MHD_FD_STATE_SEND_EXCEPT = MHD_FD_STATE_RECV | MHD_FD_STATE_EXCEPT
2790
  ,
2791
  /**
2792
   * Combination of #MHD_FD_STATE_RECV, #MHD_FD_STATE_SEND and
2793
   * #MHD_FD_STATE_EXCEPT states.
2794
   */
2795
  MHD_FD_STATE_RECV_SEND_EXCEPT = \
2796
    MHD_FD_STATE_RECV | MHD_FD_STATE_SEND | MHD_FD_STATE_EXCEPT
2797
};
2798
2799
/**
2800
 * Checks whether specific @a state is enabled/set in the @a var
2801
 */
2802
#define MHD_FD_STATE_IS_SET(var, state)              \
2803
        (MHD_FD_STATE_NONE !=                        \
2804
         ((enum MHD_FdState) (((unsigned int) (var)) \
2805
                              & ((unsigned int) (state)))))
2806
2807
/**
2808
 * Checks whether RECV is enabled/set in the @a var
2809
 */
2810
#define MHD_FD_STATE_IS_SET_RECV(var) \
2811
        MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_RECV)
2812
/**
2813
 * Checks whether SEND is enabled/set in the @a var
2814
 */
2815
#define MHD_FD_STATE_IS_SET_SEND(var) \
2816
        MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_SEND)
2817
/**
2818
 * Checks whether EXCEPT is enabled/set in the @a var
2819
 */
2820
#define MHD_FD_STATE_IS_SET_EXCEPT(var) \
2821
        MHD_FD_STATE_IS_SET ((var),MHD_FD_STATE_EXCEPT)
2822
2823
2824
/**
2825
 * Set/enable specific @a state in the @a var
2826
 */
2827
#define MHD_FD_STATE_SET(var, state) \
2828
        ((var) =                     \
2829
           (enum MHD_FdState) (((unsigned int) var) | ((unsigned int) state)))
2830
/**
2831
 * Set/enable RECV state in the @a var
2832
 */
2833
#define MHD_FD_STATE_SET_RECV(var) MHD_FD_STATE_SET ((var),MHD_FD_STATE_RECV)
2834
/**
2835
 * Set/enable SEND state in the @a var
2836
 */
2837
#define MHD_FD_STATE_SET_SEND(var) MHD_FD_STATE_SET ((var),MHD_FD_STATE_SEND)
2838
/**
2839
 * Set/enable EXCEPT state in the @a var
2840
 */
2841
#define MHD_FD_STATE_SET_EXCEPT(var) \
2842
        MHD_FD_STATE_SET ((var),MHD_FD_STATE_EXCEPT)
2843
2844
/**
2845
 * Clear/disable specific @a state in the @a var
2846
 */
2847
#define MHD_FD_STATE_CLEAR(var, state) \
2848
        ( (var) =                      \
2849
            (enum MHD_FdState)         \
2850
            (((unsigned int) var)      \
2851
             & ((enum MHD_FdState) (~((unsigned int) state)))) \
2852
        )
2853
/**
2854
 * Clear/disable RECV state in the @a var
2855
 */
2856
#define MHD_FD_STATE_CLEAR_RECV(var) \
2857
        MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_RECV)
2858
/**
2859
 * Clear/disable SEND state in the @a var
2860
 */
2861
#define MHD_FD_STATE_CLEAR_SEND(var) \
2862
        MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_SEND)
2863
/**
2864
 * Clear/disable EXCEPT state in the @a var
2865
 */
2866
#define MHD_FD_STATE_CLEAR_EXCEPT(var) \
2867
        MHD_FD_STATE_CLEAR ((var),MHD_FD_STATE_EXCEPT)
2868
2869
2870
/**
2871
 * The context data to be used for updates of the socket state
2872
 */
2873
struct MHD_EventUpdateContext;
2874
2875
2876
/* Define MHD_APP_SOCKET_CNTX_TYPE to the socket context type before
2877
 * including this header.
2878
 * This is optional, but improves the types safety.
2879
 * For example:
2880
 * #define MHD_APP_SOCKET_CNTX_TYPE struct my_structure
2881
 */
2882
#ifndef MHD_APP_SOCKET_CNTX_TYPE
2883
#  define MHD_APP_SOCKET_CNTX_TYPE void
2884
#endif
2885
2886
/**
2887
 * The callback for registration/de-registration of the sockets to watch.
2888
 *
2889
 * This callback must not call #MHD_daemon_destroy(), #MHD_daemon_quiesce(),
2890
 * #MHD_daemon_add_connection().
2891
 *
2892
 * @param cls the closure
2893
 * @param fd the socket to watch
2894
 * @param watch_for the states of the @a fd to watch, if set to
2895
 *                  #MHD_FD_STATE_NONE the socket must be de-registred
2896
 * @param app_cntx_old the old application defined context for the socket,
2897
 *                     NULL if @a fd socket was not registered before
2898
 * @param ecb_cntx the context handle to be used
2899
 *                 with #MHD_daemon_event_update()
2900
 * @return must be NULL for the removed (de-registred) sockets,
2901
 *         for new and updated sockets: NULL in case of error (the connection
2902
 *         will be aborted or daemon failed to start if FD does not belong to
2903
 *         connection)
2904
 *         or the new socket context (opaque for MHD, must be non-NULL)
2905
 * @sa #MHD_D_OPTION_REREGISTER_ALL
2906
 * @ingroup event
2907
 */
2908
typedef MHD_APP_SOCKET_CNTX_TYPE *
2909
(MHD_FN_PAR_NONNULL_ (5)
2910
 *MHD_SocketRegistrationUpdateCallback)(
2911
  void *cls,
2912
  MHD_Socket fd,
2913
  enum MHD_FdState watch_for,
2914
  MHD_APP_SOCKET_CNTX_TYPE *app_cntx_old,
2915
  struct MHD_EventUpdateContext *ecb_cntx);
2916
2917
2918
/**
2919
 * Update the sockets state.
2920
 * Must be called for every socket that got state updated.
2921
 * For #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL() mode
2922
 * this function must be called for each socket between any two calls of
2923
 * #MHD_daemon_process_reg_events() function.
2924
 * Available only for daemons started in
2925
 * #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL or
2926
 * #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes.
2927
 * @param daemon the daemon handle
2928
 * @param ecb_cntx the context handle provided
2929
 *                 for #MHD_SocketRegistrationUpdateCallback
2930
 * @param fd_current_state the current state of the socket
2931
 * @ingroup event
2932
 */
2933
MHD_EXTERN_ void
2934
MHD_daemon_event_update (
2935
  struct MHD_Daemon *MHD_RESTRICT daemon,
2936
  struct MHD_EventUpdateContext *MHD_RESTRICT ecb_cntx,
2937
  enum MHD_FdState fd_current_state)
2938
MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2);
2939
2940
2941
/**
2942
 * Perform all daemon activities based on FDs events provided earlier by
2943
 * application via #MHD_daemon_event_update().
2944
 *
2945
 * This function accepts new connections (if any), performs HTTP communications
2946
 * on all active connections, closes connections as needed and performs FDs
2947
 * registration updates by calling #MHD_SocketRegistrationUpdateCallback
2948
 * callback for every socket that needs to be added/updated/removed.
2949
 *
2950
 * Available only for daemons started in #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL or
2951
 * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes.
2952
 *
2953
 * When used in #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL mode, application must
2954
 * provide all updates by calling #MHD_daemon_event_update() for every
2955
 * registered FD between any two calls of this function.
2956
 *
2957
 * @param daemon the daemon handle
2958
 * @param[out] next_max_wait_milsec the optional pointer to receive the
2959
                                    next maximum wait time in milliseconds
2960
                                    to be used for the sockets polling
2961
                                    function, can be NULL
2962
 * @return #MHD_SC_OK on success,
2963
 *         error code otherwise
2964
 * @sa #MHD_D_OPTION_REREGISTER_ALL
2965
 * @ingroup event
2966
 */
2967
MHD_EXTERN_ enum MHD_StatusCode
2968
MHD_daemon_process_reg_events (
2969
  struct MHD_Daemon *MHD_RESTRICT daemon,
2970
  uint_fast64_t *MHD_RESTRICT next_max_wait_milsec)
2971
MHD_FN_PAR_NONNULL_ (1);
2972
2973
/* ********************* daemon options ************** */
2974
2975
2976
/**
2977
 * Which threading and polling mode should be used by MHD?
2978
 */
2979
enum MHD_FIXED_ENUM_APP_SET_ MHD_WorkMode
2980
{
2981
  /**
2982
   * Work mode with no internal threads.
2983
   * The application periodically calls #MHD_daemon_process_blocking(), where
2984
   * MHD internally checks all sockets automatically.
2985
   * This is the default mode.
2986
   * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_PERIODIC() to enable
2987
   * this mode.
2988
   */
2989
  MHD_WM_EXTERNAL_PERIODIC = 0
2990
  ,
2991
  /**
2992
   * Work mode with an external event loop with level triggers.
2993
   * MHD provides registration of all FDs to be monitored by using
2994
   * #MHD_SocketRegistrationUpdateCallback, application performs level triggered
2995
   * FDs polling (like select() or poll()), calls function
2996
   * #MHD_daemon_event_update() for every registered FD and then calls main
2997
   * function MHD_daemon_process_reg_events() to process the data.
2998
   * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL() to enable
2999
   * this mode.
3000
   * @sa #MHD_D_OPTION_REREGISTER_ALL
3001
   */
3002
  MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL = 8
3003
  ,
3004
  /**
3005
   * Work mode with an external event loop with edge triggers.
3006
   * MHD provides registration of all FDs to be monitored by using
3007
   * #MHD_SocketRegistrationUpdateCallback, application performs edge triggered
3008
   * sockets polling (like epoll with EPOLLET), calls function
3009
   * #MHD_daemon_event_update() for FDs with updated states and then calls main
3010
   * function MHD_daemon_process_reg_events() to process the data.
3011
   * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE() to enable
3012
   * this mode.
3013
   * @sa #MHD_D_OPTION_REREGISTER_ALL
3014
   */
3015
  MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE = 9
3016
  ,
3017
  /**
3018
   * Work mode with no internal threads and aggregate watch FD.
3019
   * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
3020
   * that gets triggered by any MHD event.
3021
   * This FD can be watched as an aggregate indicator for all MHD events.
3022
   * This mode is available only on selected platforms (currently
3023
   * GNU/Linux and OpenIndiana only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
3024
   * When the FD is triggered, #MHD_daemon_process_nonblocking() should
3025
   * be called.
3026
   * Use helper macro #MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH() to enable
3027
   * this mode.
3028
   */
3029
  MHD_WM_EXTERNAL_SINGLE_FD_WATCH = 16
3030
  ,
3031
  /**
3032
   * Work mode with one or more worker threads.
3033
   * If specified number of threads is one, then daemon starts with single
3034
   * worker thread that handles all connections.
3035
   * If number of threads is larger than one, then that number of worker
3036
   * threads, and handling of connection is distributed among the workers.
3037
   * Use helper macro #MHD_D_OPTION_WM_WORKER_THREADS() to enable
3038
   * this mode.
3039
   */
3040
  MHD_WM_WORKER_THREADS = 24
3041
  ,
3042
  /**
3043
   * Work mode with one internal thread for listening and additional threads
3044
   * per every connection.  Use this if handling requests is CPU-intensive or
3045
   * blocking, your application is thread-safe and you have plenty of
3046
   * memory (per connection).
3047
   * Use helper macro #MHD_D_OPTION_WM_THREAD_PER_CONNECTION() to enable
3048
   * this mode.
3049
   */
3050
  MHD_WM_THREAD_PER_CONNECTION = 32
3051
};
3052
3053
/**
3054
 * Work mode parameters for #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL and
3055
 * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes
3056
 */
3057
struct MHD_WorkModeExternalEventLoopCBParam
3058
{
3059
  /**
3060
   * Socket registration callback
3061
   */
3062
  MHD_SocketRegistrationUpdateCallback reg_cb;
3063
  /**
3064
   * Closure for the @a reg_cb
3065
   */
3066
  void *reg_cb_cls;
3067
};
3068
3069
/**
3070
 * MHD work mode parameters
3071
 */
3072
union MHD_WorkModeParam
3073
{
3074
  /**
3075
   * Work mode parameters for #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL and
3076
   * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE modes
3077
   */
3078
  struct MHD_WorkModeExternalEventLoopCBParam v_external_event_loop_cb;
3079
  /**
3080
   * Number of worker threads for #MHD_WM_WORKER_THREADS.
3081
   * If set to one, then daemon starts with single worker thread that process
3082
   * all connections.
3083
   * If set to value larger than one, then that number of worker threads
3084
   * and distributed handling of requests among the workers.
3085
   * Zero is treated as one.
3086
   */
3087
  unsigned int num_worker_threads;
3088
};
3089
3090
/**
3091
 * Parameter for #MHD_D_O_WORK_MODE().
3092
 * Not recommended to be used directly, better use macro/functions to create it:
3093
 * #MHD_WM_OPTION_EXTERNAL_PERIODIC(),
3094
 * #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(),
3095
 * #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(),
3096
 * #MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH(),
3097
 * #MHD_WM_OPTION_WORKER_THREADS(),
3098
 * #MHD_WM_OPTION_THREAD_PER_CONNECTION()
3099
 */
3100
struct MHD_WorkModeWithParam
3101
{
3102
  /**
3103
   * The work mode for MHD
3104
   */
3105
  enum MHD_WorkMode mode;
3106
  /**
3107
   * The parameters used for specified work mode
3108
   */
3109
  union MHD_WorkModeParam params;
3110
};
3111
3112
3113
#if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT)
3114
/**
3115
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3116
 * no internal threads.
3117
 * The application periodically calls #MHD_daemon_process_blocking(), where
3118
 * MHD internally checks all sockets automatically.
3119
 * This is the default mode.
3120
 * @return the object of struct MHD_WorkModeWithParam with requested values
3121
 */
3122
#  define MHD_WM_OPTION_EXTERNAL_PERIODIC()      \
3123
          MHD_NOWARN_COMPOUND_LITERALS_          \
3124
            (const struct MHD_WorkModeWithParam) \
3125
          {                                      \
3126
            .mode = (MHD_WM_EXTERNAL_PERIODIC)   \
3127
          }                                      \
3128
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
3129
3130
/**
3131
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3132
 * an external event loop with level triggers.
3133
 * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered
3134
 * sockets polling (like select() or poll()) and #MHD_daemon_event_update().
3135
 * @param cb_val the callback for sockets registration
3136
 * @param cb_cls_val the closure for the @a cv_val callback
3137
 * @return the object of struct MHD_WorkModeWithParam with requested values
3138
 */
3139
#  define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \
3140
          MHD_NOWARN_COMPOUND_LITERALS_                                  \
3141
            (const struct MHD_WorkModeWithParam)                         \
3142
          {                                                              \
3143
            .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL),               \
3144
            .params.v_external_event_loop_cb.reg_cb = (cb_val),          \
3145
            .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val)   \
3146
          }                                                              \
3147
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
3148
3149
/**
3150
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3151
 * an external event loop with edge triggers.
3152
 * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered
3153
 * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update().
3154
 * @param cb_val the callback for sockets registration
3155
 * @param cb_cls_val the closure for the @a cv_val callback
3156
 * @return the object of struct MHD_WorkModeWithParam with requested values
3157
 */
3158
#  define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \
3159
          MHD_NOWARN_COMPOUND_LITERALS_                                 \
3160
            (const struct MHD_WorkModeWithParam)                        \
3161
          {                                                             \
3162
            .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE),               \
3163
            .params.v_external_event_loop_cb.reg_cb = (cb_val),         \
3164
            .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val)  \
3165
          }                                                             \
3166
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
3167
3168
/**
3169
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3170
 * no internal threads and aggregate watch FD.
3171
 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
3172
 * that gets triggered by any MHD event.
3173
 * This FD can be watched as an aggregate indicator for all MHD events.
3174
 * This mode is available only on selected platforms (currently
3175
 * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
3176
 * When the FD is triggered, #MHD_daemon_process_nonblocking() should
3177
 * be called.
3178
 * @return the object of struct MHD_WorkModeWithParam with requested values
3179
 */
3180
#  define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()    \
3181
          MHD_NOWARN_COMPOUND_LITERALS_               \
3182
            (const struct MHD_WorkModeWithParam)      \
3183
          {                                           \
3184
            .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \
3185
          }                                           \
3186
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
3187
3188
/**
3189
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3190
 * one or more worker threads.
3191
 * If number of threads is one, then daemon starts with single worker thread
3192
 * that handles all connections.
3193
 * If number of threads is larger than one, then that number of worker threads,
3194
 * and handling of connection is distributed among the workers.
3195
 * @param num_workers the number of worker threads, zero is treated as one
3196
 * @return the object of struct MHD_WorkModeWithParam with requested values
3197
 */
3198
#  define MHD_WM_OPTION_WORKER_THREADS(num_workers)    \
3199
          MHD_NOWARN_COMPOUND_LITERALS_                \
3200
            (const struct MHD_WorkModeWithParam)       \
3201
          {                                            \
3202
            .mode = (MHD_WM_WORKER_THREADS),           \
3203
            .params.num_worker_threads = (num_workers) \
3204
          }                                            \
3205
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
3206
3207
/**
3208
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3209
 * one internal thread for listening and additional threads per every
3210
 * connection.  Use this if handling requests is CPU-intensive or blocking,
3211
 * your application is thread-safe and you have plenty of memory (per
3212
 * connection).
3213
 * @return the object of struct MHD_WorkModeWithParam with requested values
3214
 */
3215
#  define MHD_WM_OPTION_THREAD_PER_CONNECTION()    \
3216
          MHD_NOWARN_COMPOUND_LITERALS_            \
3217
            (const struct MHD_WorkModeWithParam)   \
3218
          {                                        \
3219
            .mode = (MHD_WM_THREAD_PER_CONNECTION) \
3220
          }                                        \
3221
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
3222
3223
#else  /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
3224
MHD_NOWARN_UNUSED_FUNC_
3225
3226
/**
3227
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3228
 * no internal threads.
3229
 * The application periodically calls #MHD_daemon_process_blocking(), where
3230
 * MHD internally checks all sockets automatically.
3231
 * This is the default mode.
3232
 * @return the object of struct MHD_WorkModeWithParam with requested values
3233
 */
3234
static MHD_INLINE struct MHD_WorkModeWithParam
3235
MHD_WM_OPTION_EXTERNAL_PERIODIC (void)
3236
0
{
3237
0
  struct MHD_WorkModeWithParam wm_val;
3238
0
3239
0
  wm_val.mode = MHD_WM_EXTERNAL_PERIODIC;
3240
0
3241
0
  return wm_val;
3242
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: connection_helper.cpp:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: daemon_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: request_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: response_destroy.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: response_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: stream_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: stream_process_states.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: stream_process_request.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: stream_process_reply.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_comm.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_proc_conn.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_proc_in.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_proc_out.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_conn_streams.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_req_fields.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_app_cb.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_reply_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: post_parser_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: response_auth_digest.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: auth_digest.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: upgrade_proc.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: conn_tls_check.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: tls_gnu_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: mhd_panic.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: http_status_str.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: daemon_logger.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: extr_events_funcs.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: conn_timeout.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: request_get_value.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: respond_with_error.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: response_from.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: response_add_header.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_proc_settings.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: h2_req_get_items.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
Unexecuted instantiation: request_auth_get.c:MHD_WM_OPTION_EXTERNAL_PERIODIC()
3243
3244
3245
/**
3246
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3247
 * an external event loop with level triggers.
3248
 * Application uses #MHD_SocketRegistrationUpdateCallback, level triggered
3249
 * sockets polling (like select() or poll()) and #MHD_daemon_event_update().
3250
 * @param cb_val the callback for sockets registration
3251
 * @param cb_cls_val the closure for the @a cv_val callback
3252
 * @return the object of struct MHD_WorkModeWithParam with requested values
3253
 */
3254
static MHD_INLINE struct MHD_WorkModeWithParam
3255
MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL (
3256
  MHD_SocketRegistrationUpdateCallback cb_val,
3257
  void *cb_cls_val)
3258
0
{
3259
0
  struct MHD_WorkModeWithParam wm_val;
3260
0
3261
0
  wm_val.mode = MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL;
3262
0
  wm_val.params.v_external_event_loop_cb.reg_cb = cb_val;
3263
0
  wm_val.params.v_external_event_loop_cb.reg_cb_cls = cb_cls_val;
3264
0
3265
0
  return wm_val;
3266
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: connection_helper.cpp:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: daemon_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: request_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_destroy.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_process_states.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_process_request.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_process_reply.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_comm.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_conn.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_in.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_out.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_conn_streams.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_req_fields.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_app_cb.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_reply_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: post_parser_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_auth_digest.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: auth_digest.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: upgrade_proc.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: conn_tls_check.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: tls_gnu_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: mhd_panic.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: http_status_str.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: daemon_logger.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: extr_events_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: conn_timeout.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: request_get_value.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: respond_with_error.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_from.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_add_header.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_settings.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_req_get_items.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: request_auth_get.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
3267
3268
3269
/**
3270
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3271
 * an external event loop with edge triggers.
3272
 * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered
3273
 * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update().
3274
 * @param cb_val the callback for sockets registration
3275
 * @param cb_cls_val the closure for the @a cv_val callback
3276
 * @return the object of struct MHD_WorkModeWithParam with requested values
3277
 */
3278
static MHD_INLINE struct MHD_WorkModeWithParam
3279
MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE (
3280
  MHD_SocketRegistrationUpdateCallback cb_val,
3281
  void *cb_cls_val)
3282
0
{
3283
0
  struct MHD_WorkModeWithParam wm_val;
3284
0
3285
0
  wm_val.mode = MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE;
3286
0
  wm_val.params.v_external_event_loop_cb.reg_cb = cb_val;
3287
0
  wm_val.params.v_external_event_loop_cb.reg_cb_cls = cb_cls_val;
3288
0
3289
0
  return wm_val;
3290
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: connection_helper.cpp:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: daemon_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: request_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_destroy.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_process_states.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_process_request.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: stream_process_reply.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_comm.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_conn.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_in.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_out.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_conn_streams.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_req_fields.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_app_cb.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_reply_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: post_parser_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_auth_digest.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: auth_digest.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: upgrade_proc.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: conn_tls_check.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: tls_gnu_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: mhd_panic.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: http_status_str.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: daemon_logger.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: extr_events_funcs.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: conn_timeout.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: request_get_value.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: respond_with_error.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_from.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: response_add_header.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_proc_settings.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: h2_req_get_items.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
Unexecuted instantiation: request_auth_get.c:MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(void* (*)(void*, int, MHD_FdState, void*, MHD_EventUpdateContext*), void*)
3291
3292
3293
/**
3294
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3295
 * no internal threads and aggregate watch FD.
3296
 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
3297
 * that gets triggered by any MHD event.
3298
 * This FD can be watched as an aggregate indicator for all MHD events.
3299
 * This mode is available only on selected platforms (currently
3300
 * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
3301
 * When the FD is triggered, #MHD_daemon_process_nonblocking() should
3302
 * be called.
3303
 * @return the object of struct MHD_WorkModeWithParam with requested values
3304
 */
3305
static MHD_INLINE struct MHD_WorkModeWithParam
3306
MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH (void)
3307
0
{
3308
0
  struct MHD_WorkModeWithParam wm_val;
3309
0
3310
0
  wm_val.mode = MHD_WM_EXTERNAL_SINGLE_FD_WATCH;
3311
0
3312
0
  return wm_val;
3313
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: connection_helper.cpp:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: daemon_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: request_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: response_destroy.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: response_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: stream_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: stream_process_states.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: stream_process_request.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: stream_process_reply.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_comm.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_proc_conn.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_proc_in.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_proc_out.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_conn_streams.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_req_fields.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_app_cb.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_reply_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: post_parser_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: response_auth_digest.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: auth_digest.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: upgrade_proc.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: conn_tls_check.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: tls_gnu_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: mhd_panic.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: http_status_str.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: daemon_logger.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: extr_events_funcs.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: conn_timeout.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: request_get_value.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: respond_with_error.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: response_from.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: response_add_header.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_proc_settings.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: h2_req_get_items.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
Unexecuted instantiation: request_auth_get.c:MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH()
3314
3315
3316
/**
3317
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3318
 * one or more worker threads.
3319
 * If number of threads is one, then daemon starts with single worker thread
3320
 * that handles all connections.
3321
 * If number of threads is larger than one, then that number of worker threads,
3322
 * and handling of connection is distributed among the workers.
3323
 * @param num_workers the number of worker threads, zero is treated as one
3324
 * @return the object of struct MHD_WorkModeWithParam with requested values
3325
 */
3326
static MHD_INLINE struct MHD_WorkModeWithParam
3327
MHD_WM_OPTION_WORKER_THREADS (unsigned int num_workers)
3328
0
{
3329
0
  struct MHD_WorkModeWithParam wm_val;
3330
0
3331
0
  wm_val.mode = MHD_WM_WORKER_THREADS;
3332
0
  wm_val.params.num_worker_threads = num_workers;
3333
0
3334
0
  return wm_val;
3335
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: connection_helper.cpp:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: daemon_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: request_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: response_destroy.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: response_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: stream_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: stream_process_states.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: stream_process_request.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: stream_process_reply.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_comm.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_proc_conn.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_proc_in.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_proc_out.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_conn_streams.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_req_fields.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_app_cb.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_reply_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: post_parser_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: response_auth_digest.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: auth_digest.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: upgrade_proc.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: conn_tls_check.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: tls_gnu_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: mhd_panic.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: http_status_str.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: daemon_logger.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: extr_events_funcs.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: conn_timeout.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: request_get_value.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: respond_with_error.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: response_from.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: response_add_header.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_proc_settings.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: h2_req_get_items.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
Unexecuted instantiation: request_auth_get.c:MHD_WM_OPTION_WORKER_THREADS(unsigned int)
3336
3337
3338
/**
3339
 * Create parameter for #MHD_D_O_WORK_MODE() for work mode with
3340
 * one internal thread for listening and additional threads per every
3341
 * connection.  Use this if handling requests is CPU-intensive or blocking,
3342
 * your application is thread-safe and you have plenty of memory (per
3343
 * connection).
3344
 * @return the object of struct MHD_WorkModeWithParam with requested values
3345
 */
3346
static MHD_INLINE struct MHD_WorkModeWithParam
3347
MHD_WM_OPTION_THREAD_PER_CONNECTION (void)
3348
0
{
3349
0
  struct MHD_WorkModeWithParam wm_val;
3350
0
3351
0
  wm_val.mode = MHD_WM_THREAD_PER_CONNECTION;
3352
0
3353
0
  return wm_val;
3354
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: connection_helper.cpp:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: daemon_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: request_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: response_destroy.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: response_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: stream_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: stream_process_states.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: stream_process_request.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: stream_process_reply.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_comm.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_proc_conn.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_proc_in.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_proc_out.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_conn_streams.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_req_fields.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_app_cb.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_reply_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: post_parser_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: response_auth_digest.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: auth_digest.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: upgrade_proc.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: conn_tls_check.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: tls_gnu_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: mhd_panic.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: http_status_str.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: daemon_logger.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: extr_events_funcs.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: conn_timeout.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: request_get_value.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: respond_with_error.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: response_from.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: response_add_header.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_proc_settings.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: h2_req_get_items.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
Unexecuted instantiation: request_auth_get.c:MHD_WM_OPTION_THREAD_PER_CONNECTION()
3355
3356
3357
MHD_RESTORE_WARN_UNUSED_FUNC_
3358
#endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
3359
3360
/**
3361
 * @defgroup logging Log events and control
3362
 */
3363
3364
3365
/**
3366
 * Type of a callback function used for logging by MHD.
3367
 *
3368
 * @param cls closure
3369
 * @param sc status code of the event
3370
 * @param fm format string (`printf()`-style)
3371
 * @param ap arguments to @a fm
3372
 * @ingroup logging
3373
 */
3374
typedef void
3375
(MHD_FN_PAR_NONNULL_ (3)
3376
 MHD_FN_PAR_CSTR_ (3)
3377
 *MHD_LoggingCallback)(void *cls,
3378
                       enum MHD_StatusCode sc,
3379
                       const char *fm,
3380
                       va_list ap);
3381
3382
/**
3383
 * Parameter for listen socket binding type
3384
 */
3385
enum MHD_FIXED_ENUM_APP_SET_ MHD_DaemonOptionBindType
3386
{
3387
  /**
3388
   * The listen socket bind to the networks address with sharing the address.
3389
   * Several sockets can bind to the same address.
3390
   */
3391
  MHD_D_OPTION_BIND_TYPE_SHARED = -1
3392
  ,
3393
  /**
3394
   * The listen socket bind to the networks address without sharing the address,
3395
   * except allowing binding to port/address which has TIME_WAIT state (the
3396
   * state after closing connection).
3397
   * On some platforms it may also allow to bind to specific address if other
3398
   * socket already bond to the same port of wildcard address (or bind to
3399
   * wildcard address when other socket already bond to specific address
3400
   * with the same port).
3401
   * Typically achieved by enabling 'SO_REUSEADDR' socket option.
3402
   * Default.
3403
   */
3404
  MHD_D_OPTION_BIND_TYPE_NOT_SHARED = 0
3405
  ,
3406
  /**
3407
   * The listen socket bind to the networks address without sharing the address.
3408
   * The daemon way fail to start when any sockets still in "TIME_WAIT" state
3409
   * on the same port, which effectively prevents quick restart of the daemon
3410
   * on the same port.
3411
   * On W32 systems it works like #MHD_D_OPTION_BIND_TYPE_NOT_SHARED due to
3412
   * the OS limitations.
3413
   */
3414
  MHD_D_OPTION_BIND_TYPE_NOT_SHARED_STRICTER = 1
3415
  ,
3416
  /**
3417
   * The list socket bind to the networks address in explicit exclusive mode.
3418
   * Works as #MHD_D_OPTION_BIND_TYPE_NOT_SHARED_STRICTER on platforms without
3419
   * support for the explicit exclusive socket use.
3420
   */
3421
  MHD_D_OPTION_BIND_TYPE_EXCLUSIVE = 2
3422
};
3423
3424
3425
/**
3426
 * Possible levels of enforcement for TCP_FASTOPEN.
3427
 */
3428
enum MHD_FIXED_ENUM_APP_SET_ MHD_TCPFastOpenType
3429
{
3430
  /**
3431
   * Disable use of TCP_FASTOPEN.
3432
   */
3433
  MHD_FOM_DISABLE = -1
3434
  ,
3435
  /**
3436
   * Enable TCP_FASTOPEN where supported.
3437
   * On GNU/Linux it works with a kernel >= 3.6.
3438
   * This is the default.
3439
   */
3440
  MHD_FOM_AUTO = 0
3441
  ,
3442
  /**
3443
   * Require TCP_FASTOPEN.
3444
   * Also causes #MHD_daemon_start() to fail if TCP_FASTOPEN cannot be enabled.
3445
   */
3446
  MHD_FOM_REQUIRE = 1
3447
};
3448
3449
3450
/**
3451
 * Address family to be used by MHD.
3452
 */
3453
enum MHD_FIXED_ENUM_APP_SET_ MHD_AddressFamily
3454
{
3455
  /**
3456
   * Option not given, do not listen at all
3457
   * (unless listen socket or address specified by
3458
   * other means).
3459
   */
3460
  MHD_AF_NONE = 0
3461
  ,
3462
  /**
3463
   * Pick "best" available method automatically.
3464
   */
3465
  MHD_AF_AUTO = 1
3466
  ,
3467
  /**
3468
   * Use IPv4 only.
3469
   */
3470
  MHD_AF_INET4 = 2
3471
  ,
3472
  /**
3473
   * Use IPv6 only.
3474
   */
3475
  MHD_AF_INET6 = 3
3476
  ,
3477
  /**
3478
   * Use dual stack (IPv4 and IPv6 on the same socket).
3479
   */
3480
  MHD_AF_DUAL = 4
3481
  ,
3482
  /**
3483
   * Use dual stack (IPv4 and IPv6 on the same socket),
3484
   * fallback to pure IPv6 if dual stack is not possible.
3485
   */
3486
  MHD_AF_DUAL_v4_OPTIONAL = 5
3487
  ,
3488
  /**
3489
   * Use dual stack (IPv4 and IPv6 on the same socket),
3490
   * fallback to pure IPv4 if dual stack is not possible.
3491
   */
3492
  MHD_AF_DUAL_v6_OPTIONAL = 6
3493
3494
};
3495
3496
3497
/**
3498
 * Sockets polling internal syscalls used by MHD.
3499
 */
3500
enum MHD_FIXED_ENUM_APP_SET_ MHD_SockPollSyscall
3501
{
3502
  /**
3503
   * Automatic selection of best-available method. This is also the
3504
   * default.
3505
   */
3506
  MHD_SPS_AUTO = 0
3507
  ,
3508
  /**
3509
   * Use select().
3510
   */
3511
  MHD_SPS_SELECT = 1
3512
  ,
3513
  /**
3514
   * Use poll().
3515
   */
3516
  MHD_SPS_POLL = 2
3517
  ,
3518
  /**
3519
   * Use epoll.
3520
   */
3521
  MHD_SPS_EPOLL = 3
3522
  ,
3523
  /**
3524
   * Use kqueue.
3525
   */
3526
  MHD_SPS_KQUEUE = 4
3527
};
3528
3529
3530
/**
3531
 * Protocol strictness levels enforced by MHD on clients.
3532
 * Each level applies different parsing settings for HTTP headers and other
3533
 * protocol elements.
3534
 */
3535
enum MHD_FIXED_ENUM_APP_SET_ MHD_ProtocolStrictLevel
3536
{
3537
3538
  /* * Basic levels * */
3539
  /**
3540
   * A sane default level of protocol enforcement for production use.
3541
   * Provides a balance between enhanced security and broader compatibility,
3542
   * as permitted by RFCs for HTTP servers.
3543
   */
3544
  MHD_PSL_DEFAULT = 0
3545
  ,
3546
  /**
3547
   * Apply stricter protocol interpretation while remaining within
3548
   * RFC-defined limits for HTTP servers.
3549
   *
3550
   * At this level (and stricter), using a bare LF instead of CRLF is forbidden,
3551
   * and requests that include both a "Transfer-Encoding:" and
3552
   * a "Content-Length:" headers are rejected.
3553
   *
3554
   * Suitable for public servers.
3555
   */
3556
  MHD_PSL_STRICT = 1
3557
  ,
3558
  /**
3559
   * Be more permissive in interpreting the protocol, while still
3560
   * operating within the RFC-defined limits for HTTP servers.
3561
   */
3562
  MHD_PSL_PERMISSIVE = -1
3563
  ,
3564
  /* * Special levels * */
3565
  /**
3566
   * A stricter protocol interpretation than what is allowed by RFCs for HTTP
3567
   * servers. However, it should remain fully compatible with clients correctly
3568
   * following all RFC "MUST" requirements for HTTP clients.
3569
   *
3570
   * For chunked encoding, this level (and more restrictive ones) forbids
3571
   * whitespace in chunk extensions.
3572
   * For cookie parsing, this level (and more restrictive ones) rejects
3573
   * the entire cookie if even a single value within it is incorrectly encoded.
3574
   *
3575
   * Recommended for testing clients against MHD. Can also be used for
3576
   * security-centric applications, though doing so slightly violates
3577
   * relevant RFC requirements for HTTP servers.
3578
   */
3579
  MHD_PSL_VERY_STRICT = 2
3580
  ,
3581
  /**
3582
   * The strictest interpretation of the HTTP protocol, even stricter than
3583
   * allowed by RFCs for HTTP servers.
3584
   * However, it should remain fully compatible with clients complying with both
3585
   * RFC "SHOULD" and "MUST" requirements for HTTP clients.
3586
   *
3587
   * This level can be used for testing clients against MHD.
3588
   * It is not recommended for public services, as it may reject legitimate
3589
   * clients that do not follow RFC "SHOULD" requirements.
3590
   */
3591
  MHD_PSL_EXTRA_STRICT = 3
3592
  ,
3593
  /**
3594
   * A more relaxed protocol interpretation that violates some RFC "SHOULD"
3595
   * restrictions for HTTP servers.
3596
   * For cookie parsing, this level (and more permissive levels) allows
3597
   * whitespace in cookie values.
3598
   *
3599
   * This level may be used in isolated environments.
3600
   */
3601
  MHD_PSL_VERY_PERMISSIVE = -2
3602
  ,
3603
  /**
3604
   * The most flexible protocol interpretation, going beyond RFC "MUST"
3605
   * requirements for HTTP servers.
3606
   *
3607
   * This level allows HTTP/1.1 requests without a "Host:" header.
3608
   * For cookie parsing, whitespace is allowed before and after
3609
   * the '=' character.
3610
   *
3611
   * Not recommended unless absolutely necessary to communicate with clients
3612
   * that have severely broken HTTP implementations.
3613
   */
3614
  MHD_PSL_EXTRA_PERMISSIVE = -3
3615
};
3616
3617
/**
3618
 * The way Strict Level is enforced.
3619
 * MHD can be compiled with limited set of strictness levels.
3620
 * These values instructs MHD how to apply the request level.
3621
 */
3622
enum MHD_FIXED_ENUM_APP_SET_ MHD_UseStictLevel
3623
{
3624
  /**
3625
   * Use requested level if available or the nearest stricter
3626
   * level.
3627
   * Fail if only more permissive levels available.
3628
   * Recommended value.
3629
   */
3630
  MHD_USL_THIS_OR_STRICTER = 0
3631
  ,
3632
  /**
3633
   * Use requested level only.
3634
   * Fail if this level is not available.
3635
   */
3636
  MHD_USL_PRECISE = 1
3637
  ,
3638
  /**
3639
   * Use requested level if available or the nearest level (stricter
3640
   * or more permissive).
3641
   */
3642
  MHD_USL_NEAREST = 2
3643
};
3644
3645
3646
/**
3647
 * Connection memory buffer zeroing mode.
3648
 * Works as a hardening measure.
3649
 */
3650
enum MHD_FIXED_ENUM_APP_SET_ MHD_ConnBufferZeroingMode
3651
{
3652
  /**
3653
   * Do not perform zeroing of connection memory buffer.
3654
   * Default mode.
3655
   */
3656
  MHD_CONN_BUFFER_ZEROING_DISABLED = 0
3657
  ,
3658
  /**
3659
   * Perform connection memory buffer zeroing before processing request.
3660
   */
3661
  MHD_CONN_BUFFER_ZEROING_BASIC = 1
3662
  ,
3663
  /**
3664
   * Perform connection memory buffer zeroing before processing request and
3665
   * when reusing buffer memory areas during processing request.
3666
   */
3667
  MHD_CONN_BUFFER_ZEROING_HEAVY = 2
3668
};
3669
3670
3671
/* ********************** (d) TLS support ********************** */
3672
3673
/**
3674
 * The TLS backend choice
3675
 */
3676
enum MHD_FIXED_ENUM_APP_SET_ MHD_TlsBackend
3677
{
3678
  /**
3679
   * Disable TLS, use plain TCP connections (default)
3680
   */
3681
  MHD_TLS_BACKEND_NONE = 0
3682
  ,
3683
  /**
3684
   * Use best available TLS backend.
3685
   */
3686
  MHD_TLS_BACKEND_ANY = 1
3687
  ,
3688
  /**
3689
   * Use GnuTLS as TLS backend.
3690
   */
3691
  MHD_TLS_BACKEND_GNUTLS = 2
3692
  ,
3693
  /**
3694
   * Use OpenSSL as TLS backend.
3695
   */
3696
  MHD_TLS_BACKEND_OPENSSL = 3
3697
  ,
3698
  /**
3699
   * Use MbedTLS as TLS backend.
3700
   */
3701
  MHD_TLS_BACKEND_MBEDTLS = 4
3702
};
3703
3704
/**
3705
 * Values for #MHD_D_O_DAUTH_NONCE_BIND_TYPE.
3706
 *
3707
 * These values can limit the scope of validity of MHD-generated nonces.
3708
 * Values can be combined with bitwise OR.
3709
 * Any value, except #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_NONE, enforce function
3710
 * #MHD_digest_auth_check() (and similar functions) to check nonce by
3711
 * re-generating it again with the same parameters, which is CPU-intensive
3712
 * operation.
3713
 */
3714
enum MHD_FIXED_FLAGS_ENUM_APP_SET_ MHD_DaemonOptionValueDAuthBindNonce
3715
{
3716
  /**
3717
   * Generated nonces are valid for any request from any client until expired.
3718
   * This is default and recommended value.
3719
   * #MHD_digest_auth_check() (and similar functions) would check only whether
3720
   * the nonce value that is used by client has been generated by MHD and not
3721
   * expired yet.
3722
   * It is recommended because RFC 7616 allows clients to use the same nonce
3723
   * for any request in the same "protection space".
3724
   * When checking client's authorisation requests CPU is loaded less if this
3725
   * value is used.
3726
   * This mode gives MHD maximum flexibility for nonces generation and can
3727
   * prevent possible nonce collisions (and corresponding log warning messages)
3728
   * when clients' requests are intensive.
3729
   * This value cannot be biwise-OR combined with other values.
3730
   */
3731
  MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_NONE = 0
3732
  ,
3733
  /**
3734
   * Generated nonces are valid only for the same realm.
3735
   */
3736
  MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_REALM = (1 << 0)
3737
  ,
3738
  /**
3739
   * Generated nonces are valid only for the same URI (excluding parameters
3740
   * after '?' in URI) and request method (GET, POST etc).
3741
   * Not recommended unless "protection space" is limited to a single URI as
3742
   * RFC 7616 allows clients to reuse server-generated nonces for any URI
3743
   * in the same "protection space" which by default consists of all server
3744
   * URIs.
3745
   */
3746
  MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI = (1 << 1)
3747
  ,
3748
3749
  /**
3750
   * Generated nonces are valid only for the same URI including URI parameters
3751
   * and request method (GET, POST etc).
3752
   * This value implies #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI.
3753
   * Not recommended for that same reasons as
3754
   * #MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI.
3755
   */
3756
  MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_URI_PARAMS = (1 << 2)
3757
  ,
3758
3759
  /**
3760
   * Generated nonces are valid only for the single client's IP.
3761
   * While it looks like security improvement, in practice the same client may
3762
   * jump from one IP to another (mobile or Wi-Fi handover, DHCP re-assignment,
3763
   * Multi-NAT, different proxy chain and other reasons), while IP address
3764
   * spoofing could be used relatively easily.
3765
   */
3766
  MHD_D_OPTION_VALUE_DAUTH_BIND_NONCE_CLIENT_IP = (1 << 3)
3767
};
3768
3769
3770
struct MHD_ServerCredentialsContext;
3771
3772
3773
/**
3774
 * Context required to provide a pre-shared key to the
3775
 * server.
3776
 *
3777
 * @param mscc the context
3778
 * @param psk_size the number of bytes in @a psk
3779
 * @param psk the pre-shared-key; should be allocated with malloc(),
3780
 *                 will be freed by MHD
3781
 */
3782
MHD_EXTERN_ enum MHD_StatusCode
3783
MHD_connection_set_psk (
3784
  struct MHD_ServerCredentialsContext *mscc,
3785
  size_t psk_size,
3786
  const /*void? */ char psk[MHD_FN_PAR_DYN_ARR_SIZE_ (psk_size)]);
3787
3788
#define MHD_connection_set_psk_unavailable(mscc) \
3789
        MHD_connection_set_psk (mscc, 0, NULL)
3790
3791
3792
/**
3793
 * Function called to lookup the pre-shared key (PSK) for a given
3794
 * HTTP connection based on the @a username.  MHD will suspend handling of
3795
 * the @a connection until the application calls #MHD_connection_set_psk().
3796
 * If looking up the PSK fails, the application must still call
3797
 * #MHD_connection_set_psk_unavailable().
3798
 *
3799
 * @param cls closure
3800
 * @param connection the HTTPS connection
3801
 * @param username the user name claimed by the other side
3802
 * @param mscc context to pass to #MHD_connection_set_psk().
3803
 */
3804
typedef void
3805
(*MHD_PskServerCredentialsCallback)(
3806
  void *cls,
3807
  const struct MHD_Connection *MHD_RESTRICT connection,
3808
  const struct MHD_String *MHD_RESTRICT username,
3809
  struct MHD_ServerCredentialsContext *mscc);
3810
3811
3812
/**
3813
 * The specified callback will be called one time,
3814
 * after network initialisation, TLS pre-initialisation, but before
3815
 * the start of the internal threads (if allowed).
3816
 *
3817
 * This callback may use introspection call to retrieve and adjust
3818
 * some of the daemon aspects. For example, TLS backend handler can be used
3819
 * to configure some TLS aspects.
3820
 * @param cls the callback closure
3821
 */
3822
typedef void
3823
(*MHD_DaemonReadyCallback)(void *cls);
3824
3825
3826
/**
3827
 * Allow or deny a client to connect.
3828
 *
3829
 * @param cls closure
3830
 * @param addr_len length of @a addr
3831
 * @param addr address information from the client
3832
 * @see #MHD_D_OPTION_ACCEPT_POLICY()
3833
 * @return #MHD_YES if connection is allowed, #MHD_NO if not
3834
 */
3835
typedef enum MHD_Bool
3836
(*MHD_AcceptPolicyCallback)(void *cls,
3837
                            size_t addr_len,
3838
                            const struct sockaddr *addr);
3839
3840
3841
/**
3842
 * The data for the #MHD_EarlyUriLogCallback
3843
 */
3844
struct MHD_EarlyUriCbData
3845
{
3846
  /**
3847
   * The request handle.
3848
   * Headers are not yet available.
3849
   */
3850
  struct MHD_Request *request;
3851
3852
  /**
3853
   * The full URI ("request target") from the HTTP request, including URI
3854
   * parameters (the part after '?')
3855
   */
3856
  struct MHD_String full_uri;
3857
3858
  /**
3859
   * The request HTTP method
3860
   */
3861
  enum MHD_HTTP_Method method;
3862
};
3863
3864
/**
3865
 * Function called by MHD to allow the application to log the @a full_uri
3866
 * of the new request.
3867
 * This is the only moment when unmodified URI is provided.
3868
 * After this callback MHD parses the URI and modifies it by extracting
3869
 * GET parameters in-place.
3870
 *
3871
 * If this callback is set then it is the first application function called
3872
 * for the new request.
3873
 *
3874
 * If #MHD_RequestEndedCallback is also set then it is guaranteed that
3875
 * #MHD_RequestEndedCallback is called for the same request. Application
3876
 * may allocate request specific data in this callback and de-allocate
3877
 * the data in #MHD_RequestEndedCallback.
3878
 *
3879
 * @param cls client-defined closure
3880
 * @param req_data the request data
3881
 * @param request_app_context_ptr the pointer to variable that can be set to
3882
 *                                the application context for the request;
3883
 *                                initially the variable set to NULL
3884
 */
3885
typedef void
3886
(MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (3)
3887
 *MHD_EarlyUriLogCallback)(void *cls,
3888
                           const struct MHD_EarlyUriCbData *req_data,
3889
                           void **request_app_context_ptr);
3890
3891
3892
/**
3893
 * The `enum MHD_ConnectionNotificationCode` specifies types
3894
 * of connection notifications.
3895
 * @ingroup request
3896
 */
3897
enum MHD_FIXED_ENUM_MHD_SET_ MHD_ConnectionNotificationCode
3898
{
3899
3900
  /**
3901
   * A new connection has been started.
3902
   * @ingroup request
3903
   */
3904
  MHD_CONNECTION_NOTIFY_STARTED = 0
3905
  ,
3906
  /**
3907
   * A connection is closed.
3908
   * @ingroup request
3909
   */
3910
  MHD_CONNECTION_NOTIFY_CLOSED = 1
3911
3912
};
3913
3914
/**
3915
 * Extra details for connection notifications.
3916
 * Currently not used
3917
 */
3918
union MHD_ConnectionNotificationDetails
3919
{
3920
  /**
3921
   * Unused
3922
   */
3923
  int reserved1;
3924
};
3925
3926
3927
/**
3928
 * The connection notification data structure
3929
 */
3930
struct MHD_ConnectionNotificationData
3931
{
3932
  /**
3933
   * The connection handle
3934
   */
3935
  struct MHD_Connection *connection;
3936
  /**
3937
   * The connection-specific application context data (opaque for MHD).
3938
   * Initially set to NULL (for connections added by MHD) or set by
3939
   * @a connection_cntx parameter for connections added by
3940
   * #MHD_daemon_add_connection().
3941
   */
3942
  void *application_context;
3943
  /**
3944
   * The code of the event
3945
   */
3946
  enum MHD_ConnectionNotificationCode code;
3947
  /**
3948
   * Event details
3949
   */
3950
  union MHD_ConnectionNotificationDetails details;
3951
};
3952
3953
3954
/**
3955
 * Signature of the callback used by MHD to notify the
3956
 * application about started/stopped network connections
3957
 *
3958
 * @param cls client-defined closure
3959
 * @param[in,out]  data the details about the event
3960
 * @see #MHD_D_OPTION_NOTIFY_CONNECTION()
3961
 * @ingroup request
3962
 */
3963
typedef void
3964
(MHD_FN_PAR_NONNULL_ (2)
3965
 *MHD_NotifyConnectionCallback)(void *cls,
3966
                                struct MHD_ConnectionNotificationData *data);
3967
3968
3969
/**
3970
 * The type of stream notifications.
3971
 * @ingroup request
3972
 */
3973
enum MHD_FIXED_ENUM_MHD_SET_ MHD_StreamNotificationCode
3974
{
3975
  /**
3976
   * A new stream has been started.
3977
   * @ingroup request
3978
   */
3979
  MHD_STREAM_NOTIFY_STARTED = 0
3980
  ,
3981
  /**
3982
   * A stream is closed.
3983
   * @ingroup request
3984
   */
3985
  MHD_STREAM_NOTIFY_CLOSED = 1
3986
};
3987
3988
/**
3989
 * Additional information about stream started event
3990
 */
3991
struct MHD_StreamNotificationDetailStarted
3992
{
3993
  /**
3994
   * Set to #MHD_YES of the stream was started by client
3995
   */
3996
  enum MHD_Bool by_client;
3997
};
3998
3999
/**
4000
 * Additional information about stream events
4001
 */
4002
union MHD_StreamNotificationDetail
4003
{
4004
  /**
4005
   * Information for event #MHD_STREAM_NOTIFY_STARTED
4006
   */
4007
  struct MHD_StreamNotificationDetailStarted started;
4008
};
4009
4010
/**
4011
 * Stream notification data structure
4012
 */
4013
struct MHD_StreamNotificationData
4014
{
4015
  /**
4016
   * The handle of the stream
4017
   */
4018
  struct MHD_Stream *stream;
4019
  /**
4020
   * The code of the event
4021
   */
4022
  enum MHD_StreamNotificationCode code;
4023
  /**
4024
   * Detailed information about notification event
4025
   */
4026
  union MHD_StreamNotificationDetail details;
4027
};
4028
4029
4030
/**
4031
 * Signature of the callback used by MHD to notify the
4032
 * application about started/stopped data stream
4033
 * For HTTP/1.1 it is the same like network connection
4034
 * with 1:1 match.
4035
 *
4036
 * @param cls client-defined closure
4037
 * @param data the details about the event
4038
 * @see #MHD_D_OPTION_NOTIFY_STREAM()
4039
 * @ingroup request
4040
 */
4041
typedef void
4042
(MHD_FN_PAR_NONNULL_ (2)
4043
 *MHD_NotifyStreamCallback)(
4044
  void *cls,
4045
  const struct MHD_StreamNotificationData *data);
4046
4047
#include "microhttpd2_generated_daemon_options.h"
4048
4049
4050
/**
4051
 * The `enum MHD_RequestEndedCode` specifies reasons
4052
 * why a request has been ended.
4053
 * @ingroup request
4054
 */
4055
enum MHD_FIXED_ENUM_MHD_SET_ MHD_RequestEndedCode
4056
{
4057
4058
  /**
4059
   * The response was successfully sent.
4060
   * @ingroup request
4061
   */
4062
  MHD_REQUEST_ENDED_COMPLETED_OK = 0
4063
  ,
4064
  /**
4065
   * The response was successfully sent and connection is being switched
4066
   * to another protocol.
4067
   * @ingroup request
4068
   */
4069
  MHD_REQUEST_ENDED_COMPLETED_OK_UPGRADE = 1
4070
  ,
4071
  /**
4072
   * No activity on the connection for the number of seconds specified using
4073
   * #MHD_C_OPTION_TIMEOUT().
4074
   * @ingroup request
4075
   */
4076
  MHD_REQUEST_ENDED_TIMEOUT_REACHED = 10
4077
  ,
4078
  /**
4079
   * The connection was broken or TLS protocol error.
4080
   * @ingroup request
4081
   */
4082
  MHD_REQUEST_ENDED_CONNECTION_ERROR = 20
4083
  ,
4084
  /**
4085
   * The client terminated the connection by closing the socket either
4086
   * completely or for writing (TCP half-closed) before sending complete
4087
   * request.
4088
   * @ingroup request
4089
   */
4090
  MHD_REQUEST_ENDED_CLIENT_ABORT = 30
4091
  ,
4092
  /**
4093
   * The request is not valid according to HTTP specifications.
4094
   * @ingroup request
4095
   */
4096
  MHD_REQUEST_ENDED_HTTP_PROTOCOL_ERROR = 31
4097
  ,
4098
  /**
4099
   * The application aborted request without response.
4100
   * @ingroup request
4101
   */
4102
  MHD_REQUEST_ENDED_BY_APP_ABORT = 40
4103
  ,
4104
  /**
4105
   * The request was aborted due to the application failed to provide a valid
4106
   * response.
4107
   * @ingroup request
4108
   */
4109
  MHD_REQUEST_ENDED_BY_APP_ERROR = 41
4110
  ,
4111
  /**
4112
   * The request was aborted due to the application failed to register external
4113
   * event monitoring for the connection.
4114
   * @ingroup request
4115
   */
4116
  MHD_REQUEST_ENDED_BY_EXT_EVENT_ERROR = 42
4117
  ,
4118
  /**
4119
   * Error handling the connection due to resources exhausted.
4120
   * @ingroup request
4121
   */
4122
  MHD_REQUEST_ENDED_NO_RESOURCES = 50
4123
  ,
4124
  /**
4125
   * The request was aborted due to error reading file for file-backed response
4126
   * @ingroup request
4127
   */
4128
  MHD_REQUEST_ENDED_FILE_ERROR = 51
4129
  ,
4130
  /**
4131
   * The request was aborted due to error generating valid nonce for Digest Auth
4132
   * @ingroup request
4133
   */
4134
  MHD_REQUEST_ENDED_NONCE_ERROR = 52
4135
  ,
4136
  /**
4137
   * Closing the session since MHD is being shut down.
4138
   * @ingroup request
4139
   */
4140
  MHD_REQUEST_ENDED_DAEMON_SHUTDOWN = 60
4141
};
4142
4143
/**
4144
 * Additional information about request ending
4145
 */
4146
union MHD_RequestEndedDetail
4147
{
4148
  /**
4149
   * Reserved member.
4150
   * Do not use.
4151
   */
4152
  void *reserved;
4153
};
4154
4155
/**
4156
 * Request termination data structure
4157
 */
4158
struct MHD_RequestEndedData
4159
{
4160
  /**
4161
   * The request handle.
4162
   * Note that most of the request data may be already unvailable.
4163
   */
4164
  struct MHD_Request *req;
4165
  /**
4166
   * The code of the event
4167
   */
4168
  enum MHD_RequestEndedCode code;
4169
  /**
4170
   * Detailed information about the event
4171
   */
4172
  union MHD_RequestEndedDetail details;
4173
};
4174
4175
4176
/**
4177
 * Signature of the callback used by MHD to notify the application
4178
 * about completed requests.
4179
 *
4180
 * This is the last callback called for any request (if provided by
4181
 * the application).
4182
 *
4183
 * @param cls client-defined closure
4184
 * @param data the details about the event
4185
 * @param request_app_context the application request context, as possibly set
4186
                              by the #MHD_EarlyUriLogCallback
4187
 * @see #MHD_R_OPTION_TERMINATION_CALLBACK()
4188
 * @ingroup request
4189
 */
4190
typedef void
4191
(*MHD_RequestEndedCallback)(void *cls,
4192
                            const struct MHD_RequestEndedData *data,
4193
                            void *request_app_context);
4194
4195
4196
#include "microhttpd2_generated_response_options.h"
4197
/* Beginning of generated code documenting how to use options.
4198
   You should treat the following functions *as if* they were
4199
   part of the header/API. The actual declarations are more
4200
   complex, so these here are just for documentation!
4201
   We do not actually *build* this code... */
4202
#if 0
4203
4204
/**
4205
 * Set MHD work (threading and polling) mode.
4206
 * Consider use of #MHD_D_OPTION_WM_EXTERNAL_PERIODIC(), #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(), #MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(), #MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH(), #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION() instead of direct use of this parameter.
4207
 * @param wmp the object created by one of the next functions/macros: #MHD_WM_OPTION_EXTERNAL_PERIODIC(), #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(), #MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(), #MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH(), #MHD_WM_OPTION_WORKER_THREADS(), #MHD_WM_OPTION_THREAD_PER_CONNECTION()
4208
 * @return structure with the requested setting
4209
 */
4210
struct MHD_DaemonOptionAndValue
4211
MHD_D_OPTION_WORK_MODE (
4212
  struct MHD_WorkModeWithParam wmp
4213
  );
4214
4215
/**
4216
 * Select a sockets watch system call used for internal polling.
4217
 * @param els FIXME
4218
 * @return structure with the requested setting
4219
 */
4220
struct MHD_DaemonOptionAndValue
4221
MHD_D_OPTION_POLL_SYSCALL (
4222
  enum MHD_SockPollSyscall els
4223
  );
4224
4225
/**
4226
 * Instruct MHD to register all sockets every processing round.
4227
 *
4228
By default (this options is not enabled) every processing round (every time
4229
 * when #MHD_daemon_event_update() is called) MHD calls
4230
 * #MHD_SocketRegistrationUpdateCallback only for the new sockets, for
4231
 * the removed sockets and for the updated sockets.
4232
 * Some sockets are registered when #MHD_daemon_start() is called.
4233
 *
4234
If this options is enabled, then #MHD_SocketRegistrationUpdateCallback is
4235
 * called for every socket each processing round. No sockets are registered when
4236
 * the daemon is being started.
4237
 * @param value the value of the parameter * @return structure with the requested setting
4238
 */
4239
struct MHD_DaemonOptionAndValue
4240
MHD_D_OPTION_REREGISTER_ALL (
4241
  enum MHD_Bool value
4242
  );
4243
4244
/**
4245
 * Set a callback to use for logging
4246
 * @param log_cb the callback to use for logging,
4247
 *   NULL to disable logging.
4248
 *   The logging to stderr is enabled by default.
4249
 * @param log_cb_cls the closure for the logging callback
4250
 * @return structure with the requested setting
4251
 */
4252
struct MHD_DaemonOptionAndValue
4253
MHD_D_OPTION_LOG_CALLBACK (
4254
  MHD_LoggingCallback log_cb,
4255
  void *log_cb_cls
4256
  );
4257
4258
/**
4259
 * Bind to the given TCP port and address family.
4260
 *
4261
Does not work with #MHD_D_OPTION_BIND_SA() or #MHD_D_OPTION_LISTEN_SOCKET().
4262
 *
4263
If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
4264
 * @param af the address family to use,
4265
 *   the #MHD_AF_NONE to disable listen socket (the same effect as if this option is not used)
4266
 * @param port port to use, 0 to let system assign any free port,
4267
 *   ignored if @a af is #MHD_AF_NONE
4268
 * @return structure with the requested setting
4269
 */
4270
struct MHD_DaemonOptionAndValue
4271
MHD_D_OPTION_BIND_PORT (
4272
  enum MHD_AddressFamily af,
4273
  uint_least16_t port
4274
  );
4275
4276
/**
4277
 * Bind to the given socket address.
4278
 *
4279
Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_LISTEN_SOCKET().
4280
 *
4281
If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
4282
 * @param sa_len the size of the socket address pointed by @a sa.
4283
 * @param sa the address to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6) or even a UNIX domain socket (AF_UNIX)
4284
 * @param dual When a previous version of the protocol exist (like IPv4 when @a v_sa is IPv6) bind to both protocols (IPv6 and IPv4).
4285
 * @return structure with the requested setting
4286
 */
4287
struct MHD_DaemonOptionAndValue
4288
MHD_D_OPTION_BIND_SA (
4289
  size_t sa_len,
4290
  /* const */ struct sockaddr *sa,
4291
  enum MHD_Bool dual
4292
  );
4293
4294
/**
4295
 * Accept connections from the given socket.  Socket
4296
 * must be a TCP or UNIX domain (SOCK_STREAM) socket.
4297
 *
4298
Does not work with #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA().
4299
 *
4300
If no listen socket optins (#MHD_D_OPTION_BIND_PORT(), #MHD_D_OPTION_BIND_SA(), #MHD_D_OPTION_LISTEN_SOCKET()) are used, MHD does not listen for incoming connection.
4301
 * @param listen_fd the listen socket to use, ignored if set to #MHD_INVALID_SOCKET
4302
 * @return structure with the requested setting
4303
 */
4304
struct MHD_DaemonOptionAndValue
4305
MHD_D_OPTION_LISTEN_SOCKET (
4306
  MHD_Socket listen_fd
4307
  );
4308
4309
/**
4310
 * Select mode of reusing address:port listen address.
4311
 *
4312
Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
4313
 * @param reuse_type FIXME
4314
 * @return structure with the requested setting
4315
 */
4316
struct MHD_DaemonOptionAndValue
4317
MHD_D_OPTION_LISTEN_ADDR_REUSE (
4318
  enum MHD_DaemonOptionBindType reuse_type
4319
  );
4320
4321
/**
4322
 * Configure TCP_FASTOPEN option, including setting a
4323
 * custom @a queue_length.
4324
 *
4325
Note that having a larger queue size can cause resource exhaustion
4326
 * attack as the TCP stack has to now allocate resources for the SYN
4327
 * packet along with its DATA.
4328
 *
4329
Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
4330
 * @param option the type use of of TCP FastOpen
4331
 * @param queue_length the length of the queue, zero to use system or MHD default,
4332
 *   silently ignored on platforms without support for custom queue size
4333
 * @return structure with the requested setting
4334
 */
4335
struct MHD_DaemonOptionAndValue
4336
MHD_D_OPTION_TCP_FASTOPEN (
4337
  enum MHD_TCPFastOpenType option,
4338
  unsigned int queue_length
4339
  );
4340
4341
/**
4342
 * Use the given backlog for the listen() call.
4343
 *
4344
Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
4345
 * Zero parameter treated as MHD/system default.
4346
 * @param backlog_size FIXME
4347
 * @return structure with the requested setting
4348
 */
4349
struct MHD_DaemonOptionAndValue
4350
MHD_D_OPTION_LISTEN_BACKLOG (
4351
  unsigned int backlog_size
4352
  );
4353
4354
/**
4355
 * Inform that SIGPIPE is suppressed or handled by application.
4356
 * If suppressed/handled, MHD uses network functions that could generate SIGPIPE, like `sendfile()`.
4357
 * Silently ignored when MHD creates internal threads as for them SIGPIPE is suppressed automatically.
4358
 * @param value the value of the parameter * @return structure with the requested setting
4359
 */
4360
struct MHD_DaemonOptionAndValue
4361
MHD_D_OPTION_SIGPIPE_SUPPRESSED (
4362
  enum MHD_Bool value
4363
  );
4364
4365
/**
4366
 * Enable TLS (HTTPS) and select TLS backend
4367
 * @param backend the TLS backend to use,
4368
 *   #MHD_TLS_BACKEND_NONE for non-TLS (plain TCP) connections
4369
 * @return structure with the requested setting
4370
 */
4371
struct MHD_DaemonOptionAndValue
4372
MHD_D_OPTION_TLS (
4373
  enum MHD_TlsBackend backend
4374
  );
4375
4376
/**
4377
 * Provide TLS key and certificate data in-memory.
4378
 * Works only if TLS mode is enabled.
4379
 * @param mem_cert The X.509 certificates chain in PEM format loaded into memory (not a filename).
4380
 *   The first certificate must be the server certificate, following by the chain of signing
4381
 *   certificates up to (but not including) CA root certificate.
4382
 * @param mem_key the private key in PEM format loaded into memory (not a filename)
4383
 * @param mem_pass the option passphrase phrase to decrypt the private key,
4384
 *   could be NULL if private key does not need a password
4385
 * @return structure with the requested setting
4386
 */
4387
struct MHD_DaemonOptionAndValue
4388
MHD_D_OPTION_TLS_CERT_KEY (
4389
  /* const */ char *mem_cert,
4390
  const char *mem_key,
4391
  const char *mem_pass
4392
  );
4393
4394
/**
4395
 * Provide the certificate of the certificate authority (CA) to be used by the MHD daemon for client authentication.
4396
 * Works only if TLS mode is enabled.
4397
 * @param mem_client_ca the CA certificate in memory (not a filename)
4398
 * @return structure with the requested setting
4399
 */
4400
struct MHD_DaemonOptionAndValue
4401
MHD_D_OPTION_TLS_CLIENT_CA (
4402
  const char *mem_client_ca
4403
  );
4404
4405
/**
4406
 * Configure PSK to use for the TLS key exchange.
4407
 * @param psk_cb the function to call to obtain pre-shared key
4408
 * @param psk_cb_cls the closure for @a psk_cb
4409
 * @return structure with the requested setting
4410
 */
4411
struct MHD_DaemonOptionAndValue
4412
MHD_D_OPTION_TLS_PSK_CALLBACK (
4413
  MHD_PskServerCredentialsCallback psk_cb,
4414
  void *psk_cb_cls
4415
  );
4416
4417
/**
4418
 * Control ALPN for TLS connection.
4419
 * Silently ignored for non-TLS.
4420
 * By default ALPN is automatically used for TLS connections.
4421
 * @param value the value of the parameter * @return structure with the requested setting
4422
 */
4423
struct MHD_DaemonOptionAndValue
4424
MHD_D_OPTION_NO_ALPN (
4425
  enum MHD_Bool value
4426
  );
4427
4428
/**
4429
 * Provide application name to load dedicated section in TLS backend's configuration file.
4430
 * Search for "System-wide configuration of the library" for GnuTLS documentation or
4431
 * for "config, OPENSSL LIBRARY CONFIGURATION" for OpenSSL documentation.
4432
 * If not specified the default backend configuration is used:
4433
 * "@LIBMICROHTTPD" (if available), then "@SYSTEM" (if available) then default priorities, then "NORMAL" for GnuTLS;
4434
 * "libmicrohttpd" (if available), then default name ("openssl_conf") for OpenSSL.
4435
 * Ignored when MbedTLS is used as daemon's TLS backend.
4436
 * @param app_name the name of the application, used as converted to
4437
 *   uppercase (with '@'-prefixed) for GnuTLS and as converted to
4438
 *   lowercase for OpenSSL; must not be longer than 127 characters
4439
 * @param disable_fallback forbid use fallback/default configuration if specified
4440
 *   configuration is not found; also forbid ignoring errors in the
4441
 *   configuration on TLS backends, which may ignoring configuration
4442
 *   errors
4443
 * @return structure with the requested setting
4444
 */
4445
struct MHD_DaemonOptionAndValue
4446
MHD_D_OPTION_TLS_APP_NAME (
4447
  char *app_name,
4448
  enum MHD_Bool disable_fallback
4449
  );
4450
4451
/**
4452
 * Set the configuration pathname for OpenSSL configuration file
4453
 * Ignored OpenSSL is not used as daemon's TLS backend.
4454
 * @param pathname the path and the name of the OpenSSL configuration file,
4455
 *   if only the name is provided then standard path for
4456
 *   configuration files is used,
4457
 *   could be NULL to use default configuration file pathname
4458
 *   or an empty (zero-size) string to disable file loading
4459
 * @param disable_fallback forbid use of fallback/default location and name of
4460
 *   the OpenSSL configuration file; also forbid initialisation without
4461
 *   configuration file
4462
 * @return structure with the requested setting
4463
 */
4464
struct MHD_DaemonOptionAndValue
4465
MHD_D_OPTION_TLS_OPENSSL_DEF_FILE (
4466
  char *pathname,
4467
  enum MHD_Bool disable_fallback
4468
  );
4469
4470
/**
4471
 * Specify the inactivity timeout for a connection in milliseconds.
4472
 * If a connection remains idle (no activity) for this many
4473
 * milliseconds, it is closed automatically.
4474
 * Use zero for no timeout; this is also the (unsafe!)
4475
 * default.
4476
 * Values larger than 1209600000 (two weeks) are silently
4477
 * clamped to 1209600000.
4478
 * Precise closing time is not guaranteed and depends on
4479
 * system clock granularity and amount of time spent on
4480
 * processing other connections. Typical precision is
4481
 * within +/- 30 milliseconds, while the worst case could
4482
 * be greater than +/- 1 second.
4483
 * Values below 1500 milliseconds are risky as they
4484
 * may cause valid connections to be aborted and may
4485
 * increase load the server load due to clients' repetitive
4486
 * automatic retries.
4487
 * @param timeout the timeout in milliseconds, zero for no timeout
4488
 * @return structure with the requested setting
4489
 */
4490
struct MHD_DaemonOptionAndValue
4491
MHD_D_OPTION_DEFAULT_TIMEOUT_MILSEC (
4492
  uint_fast32_t timeout
4493
  );
4494
4495
/**
4496
 * Maximum number of (concurrent) network connections served by daemon.
4497
 * @note The real maximum number of network connections could be smaller
4498
 *       than requested due to the system limitations, like FD_SETSIZE when
4499
 *       polling by select() is used.
4500
 * @param glob_limit FIXME
4501
 * @return structure with the requested setting
4502
 */
4503
struct MHD_DaemonOptionAndValue
4504
MHD_D_OPTION_GLOBAL_CONNECTION_LIMIT (
4505
  unsigned int glob_limit
4506
  );
4507
4508
/**
4509
 * Limit on the number of (concurrent) network connections made to the server from the same IP address.
4510
 * Can be used to prevent one IP from taking over all of the allowed connections. If the same IP tries to establish more than the specified number of connections, they will be immediately rejected.
4511
 * @param limit FIXME
4512
 * @return structure with the requested setting
4513
 */
4514
struct MHD_DaemonOptionAndValue
4515
MHD_D_OPTION_PER_IP_LIMIT (
4516
  unsigned int limit
4517
  );
4518
4519
/**
4520
 * Set a policy callback that accepts/rejects connections based on the client's IP address.  The callbeck function will be called before servicing any new incoming connection.
4521
 * @param apc the accept policy callback
4522
 * @param apc_cls the closure for the callback
4523
 * @return structure with the requested setting
4524
 */
4525
struct MHD_DaemonOptionAndValue
4526
MHD_D_OPTION_ACCEPT_POLICY (
4527
  MHD_AcceptPolicyCallback apc,
4528
  void *apc_cls
4529
  );
4530
4531
/**
4532
 * Set mode of connection memory buffer zeroing
4533
 * @param buff_zeroing buffer zeroing mode
4534
 * @return structure with the requested setting
4535
 */
4536
struct MHD_DaemonOptionAndValue
4537
MHD_D_OPTION_CONN_BUFF_ZEROING (
4538
  enum MHD_ConnBufferZeroingMode buff_zeroing
4539
  );
4540
4541
/**
4542
 * Set how strictly MHD will enforce the HTTP protocol.
4543
 * @param sl the level of strictness
4544
 * @param how the way how to use the requested level
4545
 * @return structure with the requested setting
4546
 */
4547
struct MHD_DaemonOptionAndValue
4548
MHD_D_OPTION_PROTOCOL_STRICT_LEVEL (
4549
  enum MHD_ProtocolStrictLevel sl,
4550
  enum MHD_UseStictLevel how
4551
  );
4552
4553
/**
4554
 * Set a callback to be called first for every request when the request line is received (before any parsing of the header).
4555
 * This callback is the only way to get raw (unmodified) request URI as URI is parsed and modified by MHD in-place.
4556
 * Mandatory URI modification may apply before this call, like binary zero replacement, as required by RFCs.
4557
 * @param cb the early URI callback
4558
 * @param cls the closure for the callback
4559
 * @return structure with the requested setting
4560
 */
4561
struct MHD_DaemonOptionAndValue
4562
MHD_D_OPTION_EARLY_URI_LOGGER (
4563
  MHD_EarlyUriLogCallback cb,
4564
  void *cls
4565
  );
4566
4567
/**
4568
 * Disable converting plus ('+') character to space in GET parameters (URI part after '?').
4569
 * Plus conversion is not required by HTTP RFCs, however it required by HTML specifications, see https://url.spec.whatwg.org/#application/x-www-form-urlencoded for details.
4570
 * By default plus is converted to space in the query part of URI.
4571
 * @param value the value of the parameter * @return structure with the requested setting
4572
 */
4573
struct MHD_DaemonOptionAndValue
4574
MHD_D_OPTION_DISABLE_URI_QUERY_PLUS_AS_SPACE (
4575
  enum MHD_Bool value
4576
  );
4577
4578
/**
4579
 * Suppresse use of 'Date:' header.
4580
 * According to RFC should be suppressed only if the system has no RTC.
4581
 * The 'Date:' is not suppressed (the header is enabled) by default.
4582
 * @param value the value of the parameter * @return structure with the requested setting
4583
 */
4584
struct MHD_DaemonOptionAndValue
4585
MHD_D_OPTION_SUPPRESS_DATE_HEADER (
4586
  enum MHD_Bool value
4587
  );
4588
4589
/**
4590
 * Use SHOUTcast for responses.
4591
 * This will cause *all* responses to begin with the SHOUTcast 'ICY' line instead of 'HTTP'.
4592
 * @param value the value of the parameter * @return structure with the requested setting
4593
 */
4594
struct MHD_DaemonOptionAndValue
4595
MHD_D_OPTION_ENABLE_SHOUTCAST (
4596
  enum MHD_Bool value
4597
  );
4598
4599
/**
4600
 * Maximum memory size per connection.
4601
 * Default is 32kb.
4602
 * Values above 128kb are unlikely to result in much performance benefit, as half of the memory will be typically used for IO, and TCP buffers are unlikely to support window sizes above 64k on most systems.
4603
 * The size should be large enough to fit all request headers (together with internal parsing information).
4604
 * @param value the value of the parameter * @return structure with the requested setting
4605
 */
4606
struct MHD_DaemonOptionAndValue
4607
MHD_D_OPTION_CONN_MEMORY_LIMIT (
4608
  size_t value
4609
  );
4610
4611
/**
4612
 * The size of the shared memory pool for accamulated upload processing.
4613
 * The same large pool is shared for all connections server by MHD and used when application requests avoiding of incremental upload processing to accamulate complete content upload before giving it to the application.
4614
 * Default is 8Mb.
4615
 * Can be set to zero to disable share pool.
4616
 * @param value the value of the parameter * @return structure with the requested setting
4617
 */
4618
struct MHD_DaemonOptionAndValue
4619
MHD_D_OPTION_LARGE_POOL_SIZE (
4620
  size_t value
4621
  );
4622
4623
/**
4624
 * Desired size of the stack for the threads started by MHD.
4625
 * Use 0 for system default, which is also MHD default.
4626
 * Works only with #MHD_D_OPTION_WM_WORKER_THREADS() or #MHD_D_OPTION_WM_THREAD_PER_CONNECTION().
4627
 * @param value the value of the parameter * @return structure with the requested setting
4628
 */
4629
struct MHD_DaemonOptionAndValue
4630
MHD_D_OPTION_STACK_SIZE (
4631
  size_t value
4632
  );
4633
4634
/**
4635
 * The the maximum FD value.
4636
 * The limit is applied to all sockets used by MHD.
4637
 * If listen socket FD is equal or higher that specified value, the daemon fail to start.
4638
 * If new connection FD is equal or higher that specified value, the connection is rejected.
4639
 * Useful if application uses select() for polling the sockets, system FD_SETSIZE is good value for this option in such case.
4640
 * Silently ignored on W32 (WinSock sockets).
4641
 * @param max_fd FIXME
4642
 * @return structure with the requested setting
4643
 */
4644
struct MHD_DaemonOptionAndValue
4645
MHD_D_OPTION_FD_NUMBER_LIMIT (
4646
  MHD_Socket max_fd
4647
  );
4648
4649
/**
4650
 * Enable `turbo`.
4651
 * Disables certain calls to `shutdown()`, enables aggressive non-blocking optimistic reads and other potentially unsafe optimisations.
4652
 * Most effects only happen with internal threads with epoll.
4653
 * The 'turbo' mode is not enabled (mode is disabled) by default.
4654
 * @param value the value of the parameter * @return structure with the requested setting
4655
 */
4656
struct MHD_DaemonOptionAndValue
4657
MHD_D_OPTION_TURBO (
4658
  enum MHD_Bool value
4659
  );
4660
4661
/**
4662
 * Disable some internal thread safety.
4663
 * Indicates that MHD daemon will be used by application in single-threaded mode only.  When this flag is set then application must call any MHD function only within a single thread.
4664
 * This flag turns off some internal thread-safety and allows MHD making some of the internal optimisations suitable only for single-threaded environment.
4665
 * Not compatible with any internal threads modes.
4666
 * If MHD is compiled with custom configuration for embedded projects without threads support, this option is mandatory.
4667
 * Thread safety is not disabled (safety is enabled) by default.
4668
 * @param value the value of the parameter * @return structure with the requested setting
4669
 */
4670
struct MHD_DaemonOptionAndValue
4671
MHD_D_OPTION_DISABLE_THREAD_SAFETY (
4672
  enum MHD_Bool value
4673
  );
4674
4675
/**
4676
 * You need to set this option if you want to disable use of HTTP Upgrade.
4677
 * Upgrade may require usage of additional internal resources, which we can avoid providing if they will not be used.
4678
 * You should only use this option if you do not use upgrade functionality and need a generally minor boost in performance and resources saving.
4679
 * The upgrade is not disallowed (upgrade is allowed) by default.
4680
 * @param value the value of the parameter * @return structure with the requested setting
4681
 */
4682
struct MHD_DaemonOptionAndValue
4683
MHD_D_OPTION_DISALLOW_UPGRADE (
4684
  enum MHD_Bool value
4685
  );
4686
4687
/**
4688
 * Disable #MHD_action_suspend() functionality.
4689
 *
4690
You should only use this function if you do not use suspend functionality and need a generally minor boost in performance.
4691
 * The suspend is not disallowed (suspend is allowed) by default.
4692
 * @param value the value of the parameter * @return structure with the requested setting
4693
 */
4694
struct MHD_DaemonOptionAndValue
4695
MHD_D_OPTION_DISALLOW_SUSPEND_RESUME (
4696
  enum MHD_Bool value
4697
  );
4698
4699
/**
4700
 * Disable cookies parsing.
4701
 *
4702
Disable automatic cookies processing if cookies are not used.
4703
 * Cookies are automatically parsed by default.
4704
 * @param value the value of the parameter * @return structure with the requested setting
4705
 */
4706
struct MHD_DaemonOptionAndValue
4707
MHD_D_OPTION_DISABLE_COOKIES (
4708
  enum MHD_Bool value
4709
  );
4710
4711
/**
4712
 * Set a callback to be called for pre-start finalisation.
4713
 *
4714
The specified callback will be called one time, after network initialisation, TLS pre-initialisation, but before the start of the internal threads (if allowed)
4715
 * @param cb the pre-start callback
4716
 * @param cb_cls the closure for the callback
4717
 * @return structure with the requested setting
4718
 */
4719
struct MHD_DaemonOptionAndValue
4720
MHD_D_OPTION_DAEMON_READY_CALLBACK (
4721
  MHD_DaemonReadyCallback cb,
4722
  void *cb_cls
4723
  );
4724
4725
/**
4726
 * Set a function that should be called whenever a connection is started or closed.
4727
 * @param ncc the callback for notifications
4728
 * @param cls the closure for the callback
4729
 * @return structure with the requested setting
4730
 */
4731
struct MHD_DaemonOptionAndValue
4732
MHD_D_OPTION_NOTIFY_CONNECTION (
4733
  MHD_NotifyConnectionCallback ncc,
4734
  void *cls
4735
  );
4736
4737
/**
4738
 * Register a function that should be called whenever a stream is started or closed.
4739
 * For HTTP/1.1 this callback is called one time for every connection.
4740
 * @param nsc the callback for notifications
4741
 * @param cls the closure for the callback
4742
 * @return structure with the requested setting
4743
 */
4744
struct MHD_DaemonOptionAndValue
4745
MHD_D_OPTION_NOTIFY_STREAM (
4746
  MHD_NotifyStreamCallback nsc,
4747
  void *cls
4748
  );
4749
4750
/**
4751
 * Set strong random data to be used by MHD.
4752
 * Currently the data is only needed for Digest Auth module.
4753
 * Daemon support for Digest Auth is enabled automatically if this option is used.
4754
 * The recommended size is between 8 and 32 bytes. Security can be lower for sizes less or equal four.
4755
 * Sizes larger then 32 (or, probably, larger than 16 - debatable) will not increase the security.
4756
 * @param buf_size the size of the buffer
4757
 * @param buf the buffer with strong random data, the content will be copied by MHD
4758
 * @return structure with the requested setting
4759
 */
4760
struct MHD_DaemonOptionAndValue
4761
MHD_D_OPTION_RANDOM_ENTROPY (
4762
  size_t buf_size,
4763
  /* const */ void *buf
4764
  );
4765
4766
/**
4767
 * Specify the size of the internal hash map array that tracks generated digest nonces usage.
4768
 * When the size of the map is too small then need to handle concurrent DAuth requests, a lot of stale nonce results will be produced.
4769
 * By default the size is 1000 entries.
4770
 * @param size the size of the map array
4771
 * @return structure with the requested setting
4772
 */
4773
struct MHD_DaemonOptionAndValue
4774
MHD_D_OPTION_AUTH_DIGEST_MAP_SIZE (
4775
  size_t size
4776
  );
4777
4778
/**
4779
 * Nonce validity time (in seconds) used for Digest Auth.
4780
 * If followed by zero value the value is silently ignored.
4781
 * @see #MHD_digest_auth_check(), MHD_digest_auth_check_digest()
4782
 * @param timeout FIXME
4783
 * @return structure with the requested setting
4784
 */
4785
struct MHD_DaemonOptionAndValue
4786
MHD_D_OPTION_AUTH_DIGEST_NONCE_TIMEOUT (
4787
  unsigned int timeout
4788
  );
4789
4790
/**
4791
 * Default maximum nc (nonce count) value used for Digest Auth.
4792
 * If followed by zero value the value is silently ignored.
4793
 * @see #MHD_digest_auth_check(), MHD_digest_auth_check_digest()
4794
 * @param max_nc FIXME
4795
 * @return structure with the requested setting
4796
 */
4797
struct MHD_DaemonOptionAndValue
4798
MHD_D_OPTION_AUTH_DIGEST_DEF_MAX_NC (
4799
  uint_fast32_t max_nc
4800
  );
4801
4802
/* End of generated code documenting how to use options */
4803
#endif
4804
4805
/* Beginning of generated code documenting how to use options.
4806
   You should treat the following functions *as if* they were
4807
   part of the header/API. The actual declarations are more
4808
   complex, so these here are just for documentation!
4809
   We do not actually *build* this code... */
4810
#if 0
4811
4812
/**
4813
 * Make the response object re-usable.
4814
 * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
4815
 * Useful if the same response is often used to reply.
4816
 * @param value the value of the parameter * @return structure with the requested setting
4817
 */
4818
struct MHD_ResponseOptionAndValue
4819
MHD_R_OPTION_REUSABLE (
4820
  enum MHD_Bool value
4821
  );
4822
4823
/**
4824
 * Enable special processing of the response as body-less (with undefined body size). No automatic 'Content-Length' or 'Transfer-Encoding: chunked' headers are added when the response is used with #MHD_HTTP_STATUS_NOT_MODIFIED code or to respond to HEAD request.
4825
 * The flag also allow to set arbitrary 'Content-Length' by #MHD_response_add_header() function.
4826
 * This flag value can be used only with responses created without body (zero-size body).
4827
 * Responses with this flag enabled cannot be used in situations where reply body must be sent to the client.
4828
 * This flag is primarily intended to be used when automatic 'Content-Length' header is undesirable in response to HEAD requests.
4829
 * @param value the value of the parameter * @return structure with the requested setting
4830
 */
4831
struct MHD_ResponseOptionAndValue
4832
MHD_R_OPTION_HEAD_ONLY_RESPONSE (
4833
  enum MHD_Bool value
4834
  );
4835
4836
/**
4837
 * Force use of chunked encoding even if the response content size is known.
4838
 * Ignored when the reply cannot have body/content.
4839
 * @param value the value of the parameter * @return structure with the requested setting
4840
 */
4841
struct MHD_ResponseOptionAndValue
4842
MHD_R_OPTION_CHUNKED_ENC (
4843
  enum MHD_Bool value
4844
  );
4845
4846
/**
4847
 * Force close connection after sending the response, prevents keep-alive connections and adds 'Connection: close' header.
4848
 * @param value the value of the parameter * @return structure with the requested setting
4849
 */
4850
struct MHD_ResponseOptionAndValue
4851
MHD_R_OPTION_CONN_CLOSE (
4852
  enum MHD_Bool value
4853
  );
4854
4855
/**
4856
 * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
4857
 * Response still use HTTP/1.1 version in header, but always close the connection after sending the response and do not use chunked encoding for the response.
4858
 * You can also set the #MHD_R_O_HTTP_1_0_SERVER flag to force HTTP/1.0 version in the response.
4859
 * Responses are still compatible with HTTP/1.1.
4860
 * Summary:
4861
 * + declared reply version: HTTP/1.1
4862
 * + keep-alive: no
4863
 * + chunked: no
4864
 *
4865
This option can be used to communicate with some broken client, which does not implement HTTP/1.1 features, but advertises HTTP/1.1 support.
4866
 * @param value the value of the parameter * @return structure with the requested setting
4867
 */
4868
struct MHD_ResponseOptionAndValue
4869
MHD_R_OPTION_HTTP_1_0_COMPATIBLE_STRICT (
4870
  enum MHD_Bool value
4871
  );
4872
4873
/**
4874
 * Only respond in HTTP/1.0-mode.
4875
 * Contrary to the #MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT flag, the response's HTTP version will always be set to 1.0 and keep-alive connections will be used if explicitly requested by the client.
4876
 * The 'Connection:' header will be added for both 'close' and 'keep-alive' connections.
4877
 * Chunked encoding will not be used for the response.
4878
 * Due to backward compatibility, responses still can be used with HTTP/1.1 clients.
4879
 * This option can be used to emulate HTTP/1.0 server (for response part only as chunked encoding in requests (if any) is processed by MHD).
4880
 * Summary:
4881
 * + declared reply version: HTTP/1.0
4882
 * + keep-alive: possible
4883
 * + chunked: no
4884
 *
4885
With this option HTTP/1.0 server is emulated (with support for 'keep-alive' connections).
4886
 * @param value the value of the parameter * @return structure with the requested setting
4887
 */
4888
struct MHD_ResponseOptionAndValue
4889
MHD_R_OPTION_HTTP_1_0_SERVER (
4890
  enum MHD_Bool value
4891
  );
4892
4893
/**
4894
 * Disable sanity check preventing clients from manually setting the HTTP content length option.
4895
 * Allow to set several 'Content-Length' headers. These headers will be used even with replies without body.
4896
 * @param value the value of the parameter * @return structure with the requested setting
4897
 */
4898
struct MHD_ResponseOptionAndValue
4899
MHD_R_OPTION_INSANITY_HEADER_CONTENT_LENGTH (
4900
  enum MHD_Bool value
4901
  );
4902
4903
/**
4904
 * Set a function to be called once MHD is finished with the request.
4905
 * @param ended_cb the function to call,
4906
 *   NULL to not use the callback
4907
 * @param ended_cb_cls the closure for the callback
4908
 * @return structure with the requested setting
4909
 */
4910
struct MHD_ResponseOptionAndValue
4911
MHD_R_OPTION_TERMINATION_CALLBACK (
4912
  MHD_RequestEndedCallback ended_cb,
4913
  void *ended_cb_cls
4914
  );
4915
4916
/* End of generated code documenting how to use options */
4917
#endif
4918
4919
/**
4920
 * Create parameter for #MHD_daemon_set_options() for work mode with
4921
 * no internal threads.
4922
 * The application periodically calls #MHD_daemon_process_blocking(), where
4923
 * MHD internally checks all sockets automatically.
4924
 * This is the default mode.
4925
 * @return the object of struct MHD_DaemonOptionAndValue with requested values
4926
 */
4927
#define MHD_D_OPTION_WM_EXTERNAL_PERIODIC() \
4928
        MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_EXTERNAL_PERIODIC ())
4929
4930
/**
4931
* Create parameter for #MHD_daemon_set_options() for work mode with
4932
* an external event loop with level triggers.
4933
* Application uses #MHD_SocketRegistrationUpdateCallback, level triggered
4934
* sockets polling (like select() or poll()) and #MHD_daemon_event_update().
4935
* @param cb_val the callback for sockets registration
4936
* @param cb_cls_val the closure for the @a cv_val callback
4937
* @return the object of struct MHD_DaemonOptionAndValue with requested values
4938
*/
4939
#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \
4940
        MHD_D_OPTION_WORK_MODE ( \
4941
          MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL ((cb_val),(cb_cls_val)))
4942
4943
/**
4944
 * Create parameter for #MHD_daemon_set_options() for work mode with
4945
 * an external event loop with edge triggers.
4946
 * Application uses #MHD_SocketRegistrationUpdateCallback, edge triggered
4947
 * sockets polling (like epoll with EPOLLET) and #MHD_daemon_event_update().
4948
 * @param cb_val the callback for sockets registration
4949
 * @param cb_cls_val the closure for the @a cv_val callback
4950
 * @return the object of struct MHD_DaemonOptionAndValue with requested values
4951
 */
4952
#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \
4953
        MHD_D_OPTION_WORK_MODE ( \
4954
          MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE ((cb_val),(cb_cls_val)))
4955
4956
/**
4957
 * Create parameter for #MHD_daemon_set_options() for work mode with
4958
 * no internal threads and aggregate watch FD.
4959
 * Application uses #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD to get single FD
4960
 * that gets triggered by any MHD event.
4961
 * This FD can be watched as an aggregate indicator for all MHD events.
4962
 * This mode is available only on selected platforms (currently
4963
 * GNU/Linux only), see #MHD_LIB_INFO_FIXED_HAS_AGGREGATE_FD.
4964
 * When the FD is triggered, #MHD_daemon_process_nonblocking() should
4965
 * be called.
4966
 * @return the object of struct MHD_DaemonOptionAndValue with requested values
4967
 */
4968
#define MHD_D_OPTION_WM_EXTERNAL_SINGLE_FD_WATCH() \
4969
        MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH ())
4970
4971
/**
4972
 * Create parameter for #MHD_daemon_set_options() for work mode with
4973
 * one or more worker threads.
4974
 * If number of threads is one, then daemon starts with single worker thread
4975
 * that handles all connections.
4976
 * If number of threads is larger than one, then that number of worker threads,
4977
 * and handling of connection is distributed among the workers.
4978
 * @param num_workers the number of worker threads, zero is treated as one
4979
 * @return the object of struct MHD_DaemonOptionAndValue with requested values
4980
 */
4981
#define MHD_D_OPTION_WM_WORKER_THREADS(num_workers) \
4982
        MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_WORKER_THREADS (num_workers))
4983
4984
/**
4985
 * Create parameter for #MHD_daemon_set_options() for work mode with
4986
 * one internal thread for listening and additional threads per every
4987
 * connection.  Use this if handling requests is CPU-intensive or blocking,
4988
 * your application is thread-safe and you have plenty of memory (per
4989
 * connection).
4990
 * @return the object of struct MHD_DaemonOptionAndValue with requested values
4991
 */
4992
#define MHD_D_OPTION_WM_THREAD_PER_CONNECTION() \
4993
        MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_THREAD_PER_CONNECTION ())
4994
4995
/**
4996
 * Set the requested options for the daemon.
4997
 *
4998
 * If any option fail other options may be or may be not applied.
4999
 * @param daemon the daemon to set the options
5000
 * @param[in] options the pointer to the array with the options;
5001
 *                    the array processing stops at the first ::MHD_D_O_END
5002
 *                    option, but not later than after processing
5003
 *                    @a options_max_num entries
5004
 * @param options_max_num the maximum number of entries in the @a options,
5005
 *                        use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing
5006
 *                        must stop only at zero-termination option
5007
 * @return ::MHD_SC_OK on success,
5008
 *         error code otherwise
5009
 */
5010
MHD_EXTERN_ enum MHD_StatusCode
5011
MHD_daemon_set_options (
5012
  struct MHD_Daemon *MHD_RESTRICT daemon,
5013
  const struct MHD_DaemonOptionAndValue *MHD_RESTRICT options,
5014
  size_t options_max_num)
5015
MHD_FN_PAR_NONNULL_ALL_;
5016
5017
5018
/**
5019
 * Set the requested single option for the daemon.
5020
 *
5021
 * @param daemon the daemon to set the option
5022
 * @param[in] option_ptr the pointer to the option
5023
 * @return ::MHD_SC_OK on success,
5024
 *         error code otherwise
5025
 */
5026
#define MHD_daemon_set_option(daemon, option_ptr) \
5027
        MHD_daemon_set_options (daemon, option_ptr, 1)
5028
5029
5030
/* *INDENT-OFF* */
5031
#ifdef MHD_USE_VARARG_MACROS
5032
MHD_NOWARN_VARIADIC_MACROS_
5033
#  if defined(MHD_USE_COMPOUND_LITERALS) && \
5034
  defined(MHD_USE_COMP_LIT_FUNC_PARAMS)
5035
/**
5036
 * Set the requested options for the daemon.
5037
 *
5038
 * If any option fail other options may be or may be not applied.
5039
 *
5040
 * It should be used with helpers that creates required options, for example:
5041
 *
5042
 * MHD_DAEMON_SET_OPTIONS(d, MHD_D_OPTION_SUPPRESS_DATE_HEADER(MHD_YES),
5043
 *                        MHD_D_OPTION_SOCK_ADDR(sa_len, sa))
5044
 *
5045
 * @param daemon the daemon to set the options
5046
 * @param ... the list of the options, each option must be created
5047
 *            by helpers MHD_D_OPTION_NameOfOption(option_value)
5048
 * @return ::MHD_SC_OK on success,
5049
 *         error code otherwise
5050
 */
5051
#    define MHD_DAEMON_SET_OPTIONS(daemon,...)          \
5052
            MHD_NOWARN_COMPOUND_LITERALS_                   \
5053
            MHD_NOWARN_AGGR_DYN_INIT_                       \
5054
            MHD_daemon_set_options (                        \
5055
              daemon,                                       \
5056
              ((const struct MHD_DaemonOptionAndValue[])    \
5057
               {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}),   \
5058
              MHD_OPTIONS_ARRAY_MAX_SIZE)                   \
5059
            MHD_RESTORE_WARN_AGGR_DYN_INIT_                 \
5060
            MHD_RESTORE_WARN_COMPOUND_LITERALS_
5061
#  elif defined(MHD_USE_CPP_INIT_LIST)
5062
MHD_C_DECLARATIONS_FINISH_HERE_
5063
#    include <vector>
5064
MHD_C_DECLARATIONS_START_HERE_
5065
/**
5066
 * Set the requested options for the daemon.
5067
 *
5068
 * If any option fail other options may be or may be not applied.
5069
 *
5070
 * It should be used with helpers that creates required options, for example:
5071
 *
5072
 * MHD_DAEMON_SET_OPTIONS(d, MHD_D_OPTION_SUPPRESS_DATE_HEADER(MHD_YES),
5073
 *                        MHD_D_OPTION_SOCK_ADDR(sa_len, sa))
5074
 *
5075
 * @param daemon the daemon to set the options
5076
 * @param ... the list of the options, each option must be created
5077
 *            by helpers MHD_D_OPTION_NameOfOption(option_value)
5078
 * @return ::MHD_SC_OK on success,
5079
 *         error code otherwise
5080
 */
5081
#    define MHD_DAEMON_SET_OPTIONS(daemon,...)                  \
5082
            MHD_NOWARN_CPP_INIT_LIST_                               \
5083
            MHD_daemon_set_options (                                \
5084
              daemon,                                               \
5085
              (std::vector<struct MHD_DaemonOptionAndValue>         \
5086
               {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (),    \
5087
              MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
5088
            MHD_RESTORE_WARN_CPP_INIT_LIST_
5089
#  endif
5090
MHD_RESTORE_WARN_VARIADIC_MACROS_
5091
#endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */
5092
/* *INDENT-ON* */
5093
5094
5095
/* ******************* Event loop ************************ */
5096
5097
5098
/**
5099
 * Run websever operation with possible blocking.
5100
 *
5101
 * Supported only in #MHD_WM_EXTERNAL_PERIODIC and
5102
 * #MHD_WM_EXTERNAL_SINGLE_FD_WATCH modes.
5103
 *
5104
 * This function does the following: waits for any network event not more than
5105
 * specified number of microseconds, processes all incoming and outgoing data,
5106
 * processes new connections, processes any timed-out connection, and does
5107
 * other things required to run webserver.
5108
 * Once all connections are processed, function returns.
5109
 *
5110
 * This function is useful for quick and simple (lazy) webserver implementation
5111
 * if application needs to run a single thread only and does not have any other
5112
 * network activity.
5113
 *
5114
 * In #MHD_WM_EXTERNAL_PERIODIC mode if @a microsec parameter is not zero
5115
 * this function determines the internal daemon timeout and use returned value
5116
 * as maximum wait time if it less than value of @a microsec parameter.
5117
 *
5118
 * @param daemon the daemon to run
5119
 * @param microsec the maximum time in microseconds to wait for network and
5120
 *                 other events. Note: there is no guarantee that function
5121
 *                 blocks for the specified amount of time. The real processing
5122
 *                 time can be shorter (if some data or connection timeout
5123
 *                 comes earlier) or longer (if data processing requires more
5124
 *                 time, especially in user callbacks).
5125
 *                 If set to '0' then function does not block and processes
5126
 *                 only already available data (if any). Zero value is
5127
 *                 recommended when used in #MHD_WM_EXTERNAL_SINGLE_FD_WATCH
5128
 *                 and the watched FD has been triggered.
5129
 *                 If set to #MHD_WAIT_INDEFINITELY then function waits
5130
 *                 for events indefinitely (blocks until next network activity
5131
 *                 or connection timeout).
5132
 *                 Always used as zero value in
5133
 *                 #MHD_WM_EXTERNAL_SINGLE_FD_WATCH mode.
5134
 * @return #MHD_SC_OK on success, otherwise
5135
 *         an error code
5136
 * @ingroup event
5137
 */
5138
MHD_EXTERN_ enum MHD_StatusCode
5139
MHD_daemon_process_blocking (struct MHD_Daemon *daemon,
5140
                             uint_fast64_t microsec)
5141
MHD_FN_PAR_NONNULL_ (1);
5142
5143
/**
5144
 * Run webserver operations (without blocking unless in client
5145
 * callbacks).
5146
 *
5147
 * Supported only in #MHD_WM_EXTERNAL_SINGLE_FD_WATCH mode.
5148
 *
5149
 * This function does the following: processes all incoming and outgoing data,
5150
 * processes new connections, processes any timed-out connection, and does
5151
 * other things required to run webserver.
5152
 * Once all connections are processed, function returns.
5153
 *
5154
 * @param daemon the daemon to run
5155
 * @return #MHD_SC_OK on success, otherwise
5156
 *         an error code
5157
 * @ingroup event
5158
 */
5159
#define MHD_daemon_process_nonblocking(daemon) \
5160
        MHD_daemon_process_blocking (daemon, 0)
5161
5162
5163
/**
5164
 * Add another client connection to the set of connections managed by
5165
 * MHD.  This API is usually not needed (since MHD will accept inbound
5166
 * connections on the server socket).  Use this API in special cases,
5167
 * for example if your HTTP server is behind NAT and needs to connect
5168
 * out to the HTTP client, or if you are building a proxy.
5169
 *
5170
 * The given client socket will be managed (and closed!) by MHD after
5171
 * this call and must no longer be used directly by the application
5172
 * afterwards.
5173
 * The client socket will be closed by MHD even if error returned.
5174
 *
5175
 * @param daemon daemon that manages the connection
5176
 * @param new_socket socket to manage (MHD will expect to receive an
5177
                     HTTP request from this socket next).
5178
 * @param addr_size number of bytes in @a addr
5179
 * @param addr IP address of the client, ignored when @a addrlen is zero
5180
 * @param connection_cntx meta data the application wants to
5181
 *        associate with the new connection object
5182
 * @return #MHD_SC_OK on success,
5183
 *         error on failure (the @a new_socket is closed)
5184
 * @ingroup specialized
5185
 */
5186
MHD_EXTERN_ enum MHD_StatusCode
5187
MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon,
5188
                           MHD_Socket new_socket,
5189
                           size_t addr_size,
5190
                           const struct sockaddr *MHD_RESTRICT addr,
5191
                           void *connection_cntx)
5192
MHD_FN_PAR_NONNULL_ (1)
5193
MHD_FN_PAR_IN_ (4);
5194
5195
5196
/* ********************* connection options ************** */
5197
5198
enum MHD_FIXED_ENUM_APP_SET_ MHD_ConnectionOption
5199
{
5200
  /**
5201
   * Not a real option.
5202
   * Should not be used directly.
5203
   * This value indicates the end of the list of the options.
5204
   */
5205
  MHD_C_O_END = 0
5206
  ,
5207
  /**
5208
   * Set custom timeout for the given connection.
5209
   * Specified as the number of seconds.  Use zero for no timeout.
5210
   * Setting this option resets connection timeout timer.
5211
   */
5212
  MHD_C_O_TIMEOUT = 1
5213
  ,
5214
5215
5216
  /* * Sentinel * */
5217
  /**
5218
   * The sentinel value.
5219
   * This value enforces specific underlying integer type for the enum.
5220
   * Do not use.
5221
   */
5222
  MHD_C_O_SENTINEL = 65535
5223
};
5224
5225
5226
/**
5227
 * Dummy-struct for space allocation.
5228
 * Do not use in application logic.
5229
 */
5230
struct MHD_ReservedStruct
5231
{
5232
  uint_fast64_t reserved1;
5233
  void *reserved2;
5234
};
5235
5236
5237
/**
5238
 * Parameters for MHD connection options
5239
 */
5240
union MHD_ConnectionOptionValue
5241
{
5242
  /**
5243
   * Value for #MHD_C_O_TIMEOUT
5244
   */
5245
  unsigned int v_timeout;
5246
  /**
5247
   * Reserved member. Do not use.
5248
   */
5249
  struct MHD_ReservedStruct reserved;
5250
};
5251
5252
/**
5253
 * Combination of MHD connection option with parameters values
5254
 */
5255
struct MHD_ConnectionOptionAndValue
5256
{
5257
  /**
5258
   * The connection configuration option
5259
   */
5260
  enum MHD_ConnectionOption opt;
5261
  /**
5262
   * The value for the @a opt option
5263
   */
5264
  union MHD_ConnectionOptionValue val;
5265
};
5266
5267
#if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT)
5268
/**
5269
 * Set custom timeout for the given connection.
5270
 * Specified as the number of seconds.  Use zero for no timeout.
5271
 * Setting this option resets connection timeout timer.
5272
 * @param timeout the in seconds, zero for no timeout
5273
 * @return the object of struct MHD_ConnectionOptionAndValue with the requested
5274
 *         values
5275
 */
5276
#  define MHD_C_OPTION_TIMEOUT(timeout)         \
5277
          MHD_NOWARN_COMPOUND_LITERALS_                 \
5278
            (const struct MHD_ConnectionOptionAndValue) \
5279
          {                                             \
5280
            .opt = (MHD_C_O_TIMEOUT),                   \
5281
            .val.v_timeout = (timeout)                  \
5282
          }                                             \
5283
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
5284
5285
/**
5286
 * Terminate the list of the options
5287
 * @return the terminating object of struct MHD_ConnectionOptionAndValue
5288
 */
5289
#  define MHD_C_OPTION_TERMINATE()              \
5290
          MHD_NOWARN_COMPOUND_LITERALS_                 \
5291
            (const struct MHD_ConnectionOptionAndValue) \
5292
          {                                             \
5293
            .opt = (MHD_C_O_END)                        \
5294
          }                                             \
5295
          MHD_RESTORE_WARN_COMPOUND_LITERALS_
5296
5297
#else  /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
5298
MHD_NOWARN_UNUSED_FUNC_
5299
5300
/**
5301
 * Set custom timeout for the given connection.
5302
 * Specified as the number of seconds.  Use zero for no timeout.
5303
 * Setting this option resets connection timeout timer.
5304
 * @param timeout the in seconds, zero for no timeout
5305
 * @return the object of struct MHD_ConnectionOptionAndValue with the requested
5306
 *         values
5307
 */
5308
static MHD_INLINE struct MHD_ConnectionOptionAndValue
5309
MHD_C_OPTION_TIMEOUT (unsigned int timeout)
5310
0
{
5311
0
  struct MHD_ConnectionOptionAndValue opt_val;
5312
0
5313
0
  opt_val.opt = MHD_C_O_TIMEOUT;
5314
0
  opt_val.val.v_timeout = timeout;
5315
0
5316
0
  return opt_val;
5317
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: connection_helper.cpp:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: daemon_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: request_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: response_destroy.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: response_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: stream_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: stream_process_states.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: stream_process_request.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: stream_process_reply.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_comm.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_proc_conn.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_proc_in.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_proc_out.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_conn_streams.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_req_fields.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_app_cb.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_reply_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: post_parser_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: response_auth_digest.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: auth_digest.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: upgrade_proc.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: conn_tls_check.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: tls_gnu_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: mhd_panic.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: http_status_str.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: daemon_logger.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: extr_events_funcs.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: conn_timeout.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: request_get_value.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: respond_with_error.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: response_from.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: response_add_header.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_proc_settings.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: h2_req_get_items.c:MHD_C_OPTION_TIMEOUT(unsigned int)
Unexecuted instantiation: request_auth_get.c:MHD_C_OPTION_TIMEOUT(unsigned int)
5318
5319
5320
/**
5321
 * Terminate the list of the options
5322
 * @return the terminating object of struct MHD_ConnectionOptionAndValue
5323
 */
5324
static MHD_INLINE struct MHD_ConnectionOptionAndValue
5325
MHD_C_OPTION_TERMINATE (void)
5326
0
{
5327
0
  struct MHD_ConnectionOptionAndValue opt_val;
5328
0
5329
0
  opt_val.opt = MHD_C_O_END;
5330
0
5331
0
  return opt_val;
5332
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: connection_helper.cpp:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: daemon_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: request_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: response_destroy.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: response_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: stream_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: stream_process_states.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: stream_process_request.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: stream_process_reply.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_comm.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_proc_conn.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_proc_in.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_proc_out.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_conn_streams.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_req_fields.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_app_cb.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_reply_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: post_parser_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: response_auth_digest.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: auth_digest.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: upgrade_proc.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: conn_tls_check.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: tls_gnu_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: mhd_panic.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: http_status_str.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: daemon_logger.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: extr_events_funcs.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: conn_timeout.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: request_get_value.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: respond_with_error.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: response_from.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: response_add_header.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_proc_settings.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: h2_req_get_items.c:MHD_C_OPTION_TERMINATE()
Unexecuted instantiation: request_auth_get.c:MHD_C_OPTION_TERMINATE()
5333
5334
5335
MHD_RESTORE_WARN_UNUSED_FUNC_
5336
#endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
5337
5338
/**
5339
 * Set the requested options for the connection.
5340
 *
5341
 * If any option fail other options may be or may be not applied.
5342
 * @param connection the connection to set the options
5343
 * @param[in] options the pointer to the array with the options;
5344
 *                    the array processing stops at the first ::MHD_D_O_END
5345
 *                    option, but not later than after processing
5346
 *                    @a options_max_num entries
5347
 * @param options_max_num the maximum number of entries in the @a options,
5348
 *                        use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing
5349
 *                        must stop only at zero-termination option
5350
 * @return ::MHD_SC_OK on success,
5351
 *         error code otherwise
5352
 */
5353
MHD_EXTERN_ enum MHD_StatusCode
5354
MHD_connection_set_options (
5355
  struct MHD_Connection *MHD_RESTRICT connection,
5356
  const struct MHD_ConnectionOptionAndValue *MHD_RESTRICT options,
5357
  size_t options_max_num)
5358
MHD_FN_PAR_NONNULL_ALL_;
5359
5360
5361
/**
5362
 * Set the requested single option for the connection.
5363
 *
5364
 * @param connection the connection to set the options
5365
 * @param[in] option_ptr the pointer to the option
5366
 * @return ::MHD_SC_OK on success,
5367
 *         error code otherwise
5368
 */
5369
#define MHD_connection_set_option(connection, option_ptr) \
5370
        MHD_connection_set_options (connection, options_ptr, 1)
5371
5372
5373
/* *INDENT-OFF* */
5374
#ifdef MHD_USE_VARARG_MACROS
5375
MHD_NOWARN_VARIADIC_MACROS_
5376
#  if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_COMP_LIT_FUNC_PARAMS \
5377
                                                    )
5378
/**
5379
 * Set the requested options for the connection.
5380
 *
5381
 * If any option fail other options may be or may be not applied.
5382
 *
5383
 * It should be used with helpers that creates required options, for example:
5384
 *
5385
 * MHD_CONNECTION_SET_OPTIONS(d, MHD_C_OPTION_TIMEOUT(30))
5386
 *
5387
 * @param connection the connection to set the options
5388
 * @param ... the list of the options, each option must be created
5389
 *            by helpers MHD_C_OPTION_NameOfOption(option_value)
5390
 * @return ::MHD_SC_OK on success,
5391
 *         error code otherwise
5392
 */
5393
#    define MHD_CONNECTION_SET_OPTIONS(connection,...)          \
5394
            MHD_NOWARN_COMPOUND_LITERALS_                           \
5395
            MHD_connection_set_options (                            \
5396
              daemon,                                               \
5397
              ((const struct MHD_ConnectionOptionAndValue [])       \
5398
               {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}),           \
5399
              MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
5400
            MHD_RESTORE_WARN_COMPOUND_LITERALS_
5401
#  elif defined(MHD_USE_CPP_INIT_LIST)
5402
MHD_C_DECLARATIONS_FINISH_HERE_
5403
#    include <vector>
5404
MHD_C_DECLARATIONS_START_HERE_
5405
/**
5406
 * Set the requested options for the connection.
5407
 *
5408
 * If any option fail other options may be or may be not applied.
5409
 *
5410
 * It should be used with helpers that creates required options, for example:
5411
 *
5412
 * MHD_CONNECTION_SET_OPTIONS(d, MHD_C_OPTION_TIMEOUT(30))
5413
 *
5414
 * @param connection the connection to set the options
5415
 * @param ... the list of the options, each option must be created
5416
 *            by helpers MHD_C_OPTION_NameOfOption(option_value)
5417
 * @return ::MHD_SC_OK on success,
5418
 *         error code otherwise
5419
 */
5420
#    define MHD_CONNECTION_SET_OPTIONS(daemon,...)              \
5421
            MHD_NOWARN_CPP_INIT_LIST_                               \
5422
            MHD_daemon_set_options (                                \
5423
              daemon,                                               \
5424
              (std::vector<struct MHD_ConnectionOptionAndValue>     \
5425
               {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (),    \
5426
              MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
5427
            MHD_RESTORE_WARN_CPP_INIT_LIST_
5428
#  endif
5429
MHD_RESTORE_WARN_VARIADIC_MACROS_
5430
#endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */
5431
/* *INDENT-ON* */
5432
5433
5434
/* **************** Request handling functions ***************** */
5435
5436
5437
/**
5438
 * The `enum MHD_ValueKind` specifies the source of
5439
 * the name-value pairs in the HTTP protocol.
5440
 */
5441
enum MHD_FLAGS_ENUM_ MHD_ValueKind
5442
{
5443
5444
  /**
5445
   * HTTP header.
5446
   * The 'value' for this kind is mandatory.
5447
   */
5448
  MHD_VK_HEADER = (1u << 0)
5449
  ,
5450
  /**
5451
   * Cookies.  Note that the original HTTP header containing
5452
   * the cookie(s) will still be available and intact.
5453
   * The 'value' for this kind is optional.
5454
   */
5455
  MHD_VK_COOKIE = (1u << 1)
5456
  ,
5457
  /**
5458
   * URI query parameter.
5459
   * The 'value' for this kind is optional.
5460
   */
5461
  MHD_VK_URI_QUERY_PARAM = (1u << 2)
5462
  ,
5463
  /**
5464
   * POST data.
5465
   * This is available only if #MHD_action_parse_post() action is used,
5466
   * a content encoding is supported by MHD, and only if the posted content
5467
   * fits within the specified memory buffers.
5468
   *
5469
   * @warning The encoding "multipart/form-data" has more fields than just
5470
   * "name" and "value". See #MHD_request_get_post_data_cb() and
5471
   * #MHD_request_get_post_data_list(). In particular it could be important
5472
   * to check used "Transfer-Encoding". While it is deprecated and not used
5473
   * by modern clients, formally it can be used.
5474
   */
5475
  MHD_VK_POSTDATA = (1u << 3)
5476
  ,
5477
  /**
5478
   * HTTP trailer (only for HTTP 1.1 chunked encodings, "footer").
5479
   * The 'value' for this kind is mandatory.
5480
   */
5481
  MHD_VK_TRAILER = (1u << 4)
5482
  ,
5483
  /**
5484
   * Header and trailer values.
5485
   */
5486
  MHD_VK_HEADER_TRAILER = MHD_VK_HEADER | MHD_VK_TRAILER
5487
  ,
5488
  /**
5489
   * Values from URI query parameters or post data.
5490
   */
5491
  MHD_VK_URI_QUERY_POST = MHD_VK_POSTDATA | MHD_VK_URI_QUERY_PARAM
5492
};
5493
5494
/**
5495
 * Name with value pair
5496
 */
5497
struct MHD_NameAndValue
5498
{
5499
  /**
5500
   * The name (key) of the field.
5501
   * The pointer to the C string must never be NULL.
5502
   * Some types (kinds) allow empty strings.
5503
   */
5504
  struct MHD_String name;
5505
  /**
5506
   * The value of the field.
5507
   * Some types (kinds) allow absence of the value. The absence is indicated
5508
   * by NULL pointer to the C string.
5509
   */
5510
  struct MHD_StringNullable value;
5511
};
5512
5513
/**
5514
 * Name, value and kind (type) of data
5515
 */
5516
struct MHD_NameValueKind
5517
{
5518
  /**
5519
   * The name and the value of the field
5520
   */
5521
  struct MHD_NameAndValue nv;
5522
  /**
5523
   * The kind (type) of the field
5524
   */
5525
  enum MHD_ValueKind kind;
5526
};
5527
5528
/**
5529
 * Iterator over name-value pairs.  This iterator can be used to
5530
 * iterate over all of the cookies, headers, footers or POST-data fields
5531
 * of a request.
5532
 *
5533
 * The @a nv pointer is valid only until return from this function.
5534
 *
5535
 * The strings in @a nv are valid until any MHD_Action or MHD_UploadAction
5536
 * is provided.
5537
 * If the data is needed beyond this point, it should be copied.
5538
 *
5539
 * @param cls closure
5540
 * @param nv the name and the value of the element, the pointer is valid only until
5541
 *           return from this function
5542
 * @param kind the type (kind) of the element
5543
 * @return #MHD_YES to continue iterating,
5544
 *         #MHD_NO to abort the iteration
5545
 * @ingroup request
5546
 */
5547
typedef enum MHD_Bool
5548
(MHD_FN_PAR_NONNULL_ (3)
5549
 *MHD_NameValueIterator)(void *cls,
5550
                         enum MHD_ValueKind kind,
5551
                         const struct MHD_NameAndValue *nv);
5552
5553
5554
/**
5555
 * Get all of the headers (or other kind of request data) via callback.
5556
 *
5557
 * @param[in,out] request request to get values from
5558
 * @param kind types of values to iterate over, can be a bitmask
5559
 * @param iterator callback to call on each header;
5560
 *        maybe NULL (then just count headers)
5561
 * @param iterator_cls extra argument to @a iterator
5562
 * @return number of entries iterated over
5563
 * @ingroup request
5564
 */
5565
MHD_EXTERN_ size_t
5566
MHD_request_get_values_cb (struct MHD_Request *request,
5567
                           enum MHD_ValueKind kind,
5568
                           MHD_NameValueIterator iterator,
5569
                           void *iterator_cls)
5570
MHD_FN_PAR_NONNULL_ (1);
5571
5572
5573
/**
5574
 * Get all of the headers (or other kind of request data) from the request.
5575
 *
5576
 * The pointers to the strings in @a elements are valid until any
5577
 * MHD_Action or MHD_UploadAction is provided. If the data is needed beyond
5578
 * this point, it should be copied.
5579
 *
5580
 * @param[in] request request to get values from
5581
 * @param kind the types of values to get, can be a bitmask
5582
 * @param num_elements the number of elements in @a elements array
5583
 * @param[out] elements the array of @a num_elements strings to be filled with
5584
 *                      the key-value pairs; if @a request has more elements
5585
 *                      than @a num_elements than any @a num_elements are
5586
 *                      stored
5587
 * @return the number of elements stored in @a elements, the
5588
 *         number cannot be larger then @a num_elements,
5589
 *         zero if there is no such values or any error occurs
5590
 */
5591
MHD_EXTERN_ size_t
5592
MHD_request_get_values_list (
5593
  struct MHD_Request *request,
5594
  enum MHD_ValueKind kind,
5595
  size_t num_elements,
5596
  struct MHD_NameValueKind elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)])
5597
MHD_FN_PAR_NONNULL_ (1)
5598
MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4, 3);
5599
5600
5601
/**
5602
 * Get a particular header (or other kind of request data) value.
5603
 * If multiple values match the kind, return any one of them.
5604
 *
5605
 * The data in the @a value_out is valid until any MHD_Action or
5606
 * MHD_UploadAction is provided. If the data is needed beyond this point,
5607
 * it should be copied.
5608
 *
5609
 * @param request request to get values from
5610
 * @param kind what kind of value are we looking for
5611
 * @param key the name of the value looking for (used for case-insensetive
5612
 *            match), empty to lookup 'trailing' value without a key
5613
 * @param[out] value_out set to the value of the header if succeed,
5614
 *                       the @a cstr pointer could be NULL even if succeed
5615
 *                       if the requested item found, but has no value
5616
 * @return #MHD_YES if succeed, the @a value_out is set;
5617
 *         #MHD_NO if no such item was found, the @a value_out string pointer
5618
 *                 set to NULL
5619
 * @ingroup request
5620
 */
5621
MHD_EXTERN_ enum MHD_Bool
5622
MHD_request_get_value (struct MHD_Request *MHD_RESTRICT request,
5623
                       enum MHD_ValueKind kind,
5624
                       const char *MHD_RESTRICT key,
5625
                       struct MHD_StringNullable *MHD_RESTRICT value_out)
5626
MHD_FN_PAR_NONNULL_ (1)
5627
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3)
5628
MHD_FN_PAR_OUT_ (4);
5629
5630
5631
/**
5632
 * @brief Status codes defined for HTTP responses.
5633
 *
5634
 * @defgroup httpcode HTTP response codes
5635
 * @{
5636
 */
5637
/* Registry export date: 2023-09-29 */
5638
/* See http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */
5639
enum MHD_FIXED_ENUM_APP_SET_ MHD_HTTP_StatusCode
5640
{
5641
  /* 100 "Continue".            RFC9110, Section 15.2.1. */
5642
  MHD_HTTP_STATUS_CONTINUE =                    100
5643
  ,
5644
  /* 101 "Switching Protocols". RFC9110, Section 15.2.2. */
5645
  MHD_HTTP_STATUS_SWITCHING_PROTOCOLS =         101
5646
  ,
5647
  /* 102 "Processing".          RFC2518. */
5648
  MHD_HTTP_STATUS_PROCESSING =                  102
5649
  ,
5650
  /* 103 "Early Hints".         RFC8297. */
5651
  MHD_HTTP_STATUS_EARLY_HINTS =                 103
5652
  ,
5653
5654
  /* 200 "OK".                  RFC9110, Section 15.3.1. */
5655
  MHD_HTTP_STATUS_OK =                          200
5656
  ,
5657
  /* 201 "Created".             RFC9110, Section 15.3.2. */
5658
  MHD_HTTP_STATUS_CREATED =                     201
5659
  ,
5660
  /* 202 "Accepted".            RFC9110, Section 15.3.3. */
5661
  MHD_HTTP_STATUS_ACCEPTED =                    202
5662
  ,
5663
  /* 203 "Non-Authoritative Information". RFC9110, Section 15.3.4. */
5664
  MHD_HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203
5665
  ,
5666
  /* 204 "No Content".          RFC9110, Section 15.3.5. */
5667
  MHD_HTTP_STATUS_NO_CONTENT =                  204
5668
  ,
5669
  /* 205 "Reset Content".       RFC9110, Section 15.3.6. */
5670
  MHD_HTTP_STATUS_RESET_CONTENT =               205
5671
  ,
5672
  /* 206 "Partial Content".     RFC9110, Section 15.3.7. */
5673
  MHD_HTTP_STATUS_PARTIAL_CONTENT =             206
5674
  ,
5675
  /* 207 "Multi-Status".        RFC4918. */
5676
  MHD_HTTP_STATUS_MULTI_STATUS =                207
5677
  ,
5678
  /* 208 "Already Reported".    RFC5842. */
5679
  MHD_HTTP_STATUS_ALREADY_REPORTED =            208
5680
  ,
5681
5682
  /* 226 "IM Used".             RFC3229. */
5683
  MHD_HTTP_STATUS_IM_USED =                     226
5684
  ,
5685
5686
  /* 300 "Multiple Choices".    RFC9110, Section 15.4.1. */
5687
  MHD_HTTP_STATUS_MULTIPLE_CHOICES =            300
5688
  ,
5689
  /* 301 "Moved Permanently".   RFC9110, Section 15.4.2. */
5690
  MHD_HTTP_STATUS_MOVED_PERMANENTLY =           301
5691
  ,
5692
  /* 302 "Found".               RFC9110, Section 15.4.3. */
5693
  MHD_HTTP_STATUS_FOUND =                       302
5694
  ,
5695
  /* 303 "See Other".           RFC9110, Section 15.4.4. */
5696
  MHD_HTTP_STATUS_SEE_OTHER =                   303
5697
  ,
5698
  /* 304 "Not Modified".        RFC9110, Section 15.4.5. */
5699
  MHD_HTTP_STATUS_NOT_MODIFIED =                304
5700
  ,
5701
  /* 305 "Use Proxy".           RFC9110, Section 15.4.6. */
5702
  MHD_HTTP_STATUS_USE_PROXY =                   305
5703
  ,
5704
  /* 306 "Switch Proxy".        Not used! RFC9110, Section 15.4.7. */
5705
  MHD_HTTP_STATUS_SWITCH_PROXY =                306
5706
  ,
5707
  /* 307 "Temporary Redirect".  RFC9110, Section 15.4.8. */
5708
  MHD_HTTP_STATUS_TEMPORARY_REDIRECT =          307
5709
  ,
5710
  /* 308 "Permanent Redirect".  RFC9110, Section 15.4.9. */
5711
  MHD_HTTP_STATUS_PERMANENT_REDIRECT =          308
5712
  ,
5713
5714
  /* 400 "Bad Request".         RFC9110, Section 15.5.1. */
5715
  MHD_HTTP_STATUS_BAD_REQUEST =                 400
5716
  ,
5717
  /* 401 "Unauthorized".        RFC9110, Section 15.5.2. */
5718
  MHD_HTTP_STATUS_UNAUTHORIZED =                401
5719
  ,
5720
  /* 402 "Payment Required".    RFC9110, Section 15.5.3. */
5721
  MHD_HTTP_STATUS_PAYMENT_REQUIRED =            402
5722
  ,
5723
  /* 403 "Forbidden".           RFC9110, Section 15.5.4. */
5724
  MHD_HTTP_STATUS_FORBIDDEN =                   403
5725
  ,
5726
  /* 404 "Not Found".           RFC9110, Section 15.5.5. */
5727
  MHD_HTTP_STATUS_NOT_FOUND =                   404
5728
  ,
5729
  /* 405 "Method Not Allowed".  RFC9110, Section 15.5.6. */
5730
  MHD_HTTP_STATUS_METHOD_NOT_ALLOWED =          405
5731
  ,
5732
  /* 406 "Not Acceptable".      RFC9110, Section 15.5.7. */
5733
  MHD_HTTP_STATUS_NOT_ACCEPTABLE =              406
5734
  ,
5735
  /* 407 "Proxy Authentication Required". RFC9110, Section 15.5.8. */
5736
  MHD_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407
5737
  ,
5738
  /* 408 "Request Timeout".     RFC9110, Section 15.5.9. */
5739
  MHD_HTTP_STATUS_REQUEST_TIMEOUT =             408
5740
  ,
5741
  /* 409 "Conflict".            RFC9110, Section 15.5.10. */
5742
  MHD_HTTP_STATUS_CONFLICT =                    409
5743
  ,
5744
  /* 410 "Gone".                RFC9110, Section 15.5.11. */
5745
  MHD_HTTP_STATUS_GONE =                        410
5746
  ,
5747
  /* 411 "Length Required".     RFC9110, Section 15.5.12. */
5748
  MHD_HTTP_STATUS_LENGTH_REQUIRED =             411
5749
  ,
5750
  /* 412 "Precondition Failed". RFC9110, Section 15.5.13. */
5751
  MHD_HTTP_STATUS_PRECONDITION_FAILED =         412
5752
  ,
5753
  /* 413 "Content Too Large".   RFC9110, Section 15.5.14. */
5754
  MHD_HTTP_STATUS_CONTENT_TOO_LARGE =           413
5755
  ,
5756
  /* 414 "URI Too Long".        RFC9110, Section 15.5.15. */
5757
  MHD_HTTP_STATUS_URI_TOO_LONG =                414
5758
  ,
5759
  /* 415 "Unsupported Media Type". RFC9110, Section 15.5.16. */
5760
  MHD_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE =      415
5761
  ,
5762
  /* 416 "Range Not Satisfiable". RFC9110, Section 15.5.17. */
5763
  MHD_HTTP_STATUS_RANGE_NOT_SATISFIABLE =       416
5764
  ,
5765
  /* 417 "Expectation Failed".  RFC9110, Section 15.5.18. */
5766
  MHD_HTTP_STATUS_EXPECTATION_FAILED =          417
5767
  ,
5768
5769
5770
  /* 421 "Misdirected Request". RFC9110, Section 15.5.20. */
5771
  MHD_HTTP_STATUS_MISDIRECTED_REQUEST =         421
5772
  ,
5773
  /* 422 "Unprocessable Content". RFC9110, Section 15.5.21. */
5774
  MHD_HTTP_STATUS_UNPROCESSABLE_CONTENT =       422
5775
  ,
5776
  /* 423 "Locked".              RFC4918. */
5777
  MHD_HTTP_STATUS_LOCKED =                      423
5778
  ,
5779
  /* 424 "Failed Dependency".   RFC4918. */
5780
  MHD_HTTP_STATUS_FAILED_DEPENDENCY =           424
5781
  ,
5782
  /* 425 "Too Early".           RFC8470. */
5783
  MHD_HTTP_STATUS_TOO_EARLY =                   425
5784
  ,
5785
  /* 426 "Upgrade Required".    RFC9110, Section 15.5.22. */
5786
  MHD_HTTP_STATUS_UPGRADE_REQUIRED =            426
5787
  ,
5788
5789
  /* 428 "Precondition Required". RFC6585. */
5790
  MHD_HTTP_STATUS_PRECONDITION_REQUIRED =       428
5791
  ,
5792
  /* 429 "Too Many Requests".   RFC6585. */
5793
  MHD_HTTP_STATUS_TOO_MANY_REQUESTS =           429
5794
  ,
5795
5796
  /* 431 "Request Header Fields Too Large". RFC6585. */
5797
  MHD_HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431
5798
  ,
5799
5800
  /* 451 "Unavailable For Legal Reasons". RFC7725. */
5801
  MHD_HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451
5802
  ,
5803
5804
  /* 500 "Internal Server Error". RFC9110, Section 15.6.1. */
5805
  MHD_HTTP_STATUS_INTERNAL_SERVER_ERROR =       500
5806
  ,
5807
  /* 501 "Not Implemented".     RFC9110, Section 15.6.2. */
5808
  MHD_HTTP_STATUS_NOT_IMPLEMENTED =             501
5809
  ,
5810
  /* 502 "Bad Gateway".         RFC9110, Section 15.6.3. */
5811
  MHD_HTTP_STATUS_BAD_GATEWAY =                 502
5812
  ,
5813
  /* 503 "Service Unavailable". RFC9110, Section 15.6.4. */
5814
  MHD_HTTP_STATUS_SERVICE_UNAVAILABLE =         503
5815
  ,
5816
  /* 504 "Gateway Timeout".     RFC9110, Section 15.6.5. */
5817
  MHD_HTTP_STATUS_GATEWAY_TIMEOUT =             504
5818
  ,
5819
  /* 505 "HTTP Version Not Supported". RFC9110, Section 15.6.6. */
5820
  MHD_HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED =  505
5821
  ,
5822
  /* 506 "Variant Also Negotiates". RFC2295. */
5823
  MHD_HTTP_STATUS_VARIANT_ALSO_NEGOTIATES =     506
5824
  ,
5825
  /* 507 "Insufficient Storage". RFC4918. */
5826
  MHD_HTTP_STATUS_INSUFFICIENT_STORAGE =        507
5827
  ,
5828
  /* 508 "Loop Detected".       RFC5842. */
5829
  MHD_HTTP_STATUS_LOOP_DETECTED =               508
5830
  ,
5831
5832
  /* 510 "Not Extended".        (OBSOLETED) RFC2774; status-change-http-experiments-to-historic. */
5833
  MHD_HTTP_STATUS_NOT_EXTENDED =                510
5834
  ,
5835
  /* 511 "Network Authentication Required". RFC6585. */
5836
  MHD_HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511
5837
  ,
5838
5839
5840
  /* Not registered non-standard codes */
5841
  /* 449 "Reply With".          MS IIS extension. */
5842
  MHD_HTTP_STATUS_RETRY_WITH =                  449
5843
  ,
5844
5845
  /* 450 "Blocked by Windows Parental Controls". MS extension. */
5846
  MHD_HTTP_STATUS_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS = 450
5847
  ,
5848
5849
  /* 509 "Bandwidth Limit Exceeded". Apache extension. */
5850
  MHD_HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED =    509
5851
};
5852
5853
5854
/**
5855
 * Returns the string status for a response code.
5856
 *
5857
 * This function works for @b HTTP status code, not for @b MHD error codes/
5858
 * @param code the HTTP code to get text representation for
5859
 * @return the pointer to the text representation,
5860
 *         NULL if HTTP status code in not known.
5861
 */
5862
MHD_EXTERN_ const struct MHD_String *
5863
MHD_HTTP_status_code_to_string (enum MHD_HTTP_StatusCode code)
5864
MHD_FN_CONST_;
5865
5866
/**
5867
 * Get the pointer to the C string for the HTTP response code, never NULL.
5868
 */
5869
#define MHD_HTTP_status_code_to_string_lazy(code) \
5870
        (MHD_HTTP_status_code_to_string ((code)) ? \
5871
         ((MHD_HTTP_status_code_to_string (code))->cstr) : ("[No status]") )
5872
5873
5874
/** @} */ /* end of group httpcode */
5875
5876
#ifndef MHD_HTTP_PROTOCOL_VER_DEFINED
5877
5878
/**
5879
 * @brief HTTP protocol versions
5880
 * @defgroup versions HTTP versions
5881
 * @{
5882
 */
5883
enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_ProtocolVersion
5884
{
5885
  MHD_HTTP_VERSION_INVALID = 0  /**< Invalid/unrecognised HTTP version */
5886
  ,
5887
  MHD_HTTP_VERSION_1_0 = 10     /**< HTTP/1.0 */
5888
  ,
5889
  MHD_HTTP_VERSION_1_1 = 11     /**< HTTP/1.1 */
5890
  ,
5891
  MHD_HTTP_VERSION_1_2P = 19    /**< HTTP/1.2 - HTTP/1.9 */
5892
  ,
5893
  MHD_HTTP_VERSION_2 = 20       /**< HTTP/2 */
5894
  ,
5895
  MHD_HTTP_VERSION_3 = 30       /**< HTTP/3 */
5896
  ,
5897
  MHD_HTTP_VERSION_FUTURE = 255 /**< Future HTTP version */
5898
};
5899
5900
#  define MHD_HTTP_PROTOCOL_VER_DEFINED 1
5901
#endif /* ! MHD_HTTP_PROTOCOL_VER_DEFINED */
5902
5903
/**
5904
 * Return the string representation of the requested HTTP version.
5905
 * Note: this is suitable mainly for logging and similar purposes as
5906
 * HTTP/2 (and later) is not used inside the HTTP protocol.
5907
 * @param pv the protocol version
5908
 * @return the string representation of the protocol version,
5909
 *         NULL for invalid values
5910
 */
5911
MHD_EXTERN_ const struct MHD_String *
5912
MHD_protocol_version_to_string (enum MHD_HTTP_ProtocolVersion pv)
5913
MHD_FN_CONST_;
5914
5915
/**
5916
 * HTTP/1.0 identification string
5917
 */
5918
#define MHD_HTTP_VERSION_1_0_STR "HTTP/1.0"
5919
/**
5920
 * HTTP/1.1 identification string
5921
 */
5922
#define MHD_HTTP_VERSION_1_1_STR "HTTP/1.1"
5923
/**
5924
 * Identification string for clients claiming HTTP/1.2 - HTTP/1.9
5925
 * Not used by the HTTP protocol, useful for logs and similar purposes.
5926
 */
5927
#define MHD_HTTP_VERSION_1_2P_STR "HTTP/1.2+"
5928
/**
5929
 * HTTP/2 identification string.
5930
 * Not used by the HTTP protocol (except non-TLS handshake), useful for logs and
5931
 * similar purposes.
5932
 */
5933
#define MHD_HTTP_VERSION_2_STR "HTTP/2"
5934
/**
5935
 * HTTP/3 identification string.
5936
 * Not used by the HTTP protocol, useful for logs and similar purposes.
5937
 */
5938
#define MHD_HTTP_VERSION_3_STR "HTTP/3"
5939
5940
/** @} */ /* end of group versions */
5941
5942
5943
/**
5944
 * Resume handling of network data for suspended request.
5945
 * It is safe to resume a suspended request at any time.
5946
 * Calling this function on a request that was not previously suspended will
5947
 * result in undefined behaviour.
5948
 *
5949
 * @param[in,out] request the request to resume
5950
 */
5951
MHD_EXTERN_ void
5952
MHD_request_resume (struct MHD_Request *request)
5953
MHD_FN_PAR_NONNULL_ALL_;
5954
5955
5956
/* ************** Action and Response manipulation functions **************** */
5957
5958
/**
5959
 * @defgroup response Response objects control
5960
 */
5961
5962
5963
/**
5964
 * Name with value pair as C strings
5965
 */
5966
struct MHD_NameValueCStr
5967
{
5968
  /**
5969
   * The name (key) of the field.
5970
   * Must never be NULL.
5971
   * Some types (kinds) allow empty strings.
5972
   */
5973
  const char *name;
5974
  /**
5975
   * The value of the field.
5976
   * Some types (kinds) allow absence of the value. The absence is indicated
5977
   * by NULL pointer.
5978
   */
5979
  const char *value;
5980
};
5981
5982
/**
5983
 * Data transmitted in response to an HTTP request.
5984
 * Usually the final action taken in response to
5985
 * receiving a request.
5986
 */
5987
struct MHD_Response;
5988
5989
5990
/**
5991
 * Suspend handling of network data for a given request.  This can
5992
 * be used to dequeue a request from MHD's event loop for a while.
5993
 *
5994
 * Suspended requests continue to count against the total number of
5995
 * requests allowed (per daemon, as well as per IP, if such limits
5996
 * are set).  Suspended requests will NOT time out; timeouts will
5997
 * restart when the request handling is resumed.  While a
5998
 * request is suspended, MHD may not detect disconnects by the
5999
 * client.
6000
 *
6001
 * At most one action can be created for any request.
6002
 *
6003
 * @param[in,out] request the request for which the action is generated
6004
 * @return action to cause a request to be suspended,
6005
 *         NULL if any action has been already created for the @a request
6006
 * @ingroup action
6007
 */
6008
MHD_EXTERN_ const struct MHD_Action *
6009
MHD_action_suspend (struct MHD_Request *request)
6010
MHD_FN_PAR_NONNULL_ALL_;
6011
6012
6013
/**
6014
 * Converts a @a response to an action.  If #MHD_R_O_REUSABLE
6015
 * is not set, the reference to the @a response is consumed
6016
 * by the conversion. If #MHD_R_O_REUSABLE is #MHD_YES,
6017
 * then the @a response can be used again to create actions in
6018
 * the future.
6019
 * However, the @a response is frozen by this step and
6020
 * must no longer be modified (i.e. by setting headers).
6021
 *
6022
 * At most one action can be created for any request.
6023
 *
6024
 * @param request the request to create the action for
6025
 * @param[in] response the response to convert,
6026
 *                     if NULL then this function is equivalent to
6027
 *                     #MHD_action_abort_connection() call
6028
 * @return pointer to the action, the action must be consumed
6029
 *         otherwise response object may leak;
6030
 *         NULL if failed (no memory) or if any action has been already
6031
 *         created for the @a request;
6032
 *         when failed the response object is consumed and need not
6033
 *         to be "destroyed"
6034
 * @ingroup action
6035
 */
6036
MHD_EXTERN_ const struct MHD_Action *
6037
MHD_action_from_response (struct MHD_Request *MHD_RESTRICT request,
6038
                          struct MHD_Response *MHD_RESTRICT response)
6039
MHD_FN_PAR_NONNULL_ (1);
6040
6041
6042
/**
6043
 * Action telling MHD to close the connection hard
6044
 * (kind-of breaking HTTP specification).
6045
 *
6046
 * @param req the request to make an action
6047
 * @return action operation, always NULL
6048
 * @ingroup action
6049
 */
6050
#define MHD_action_abort_request(req) \
6051
        MHD_STATIC_CAST_ (const struct MHD_Action *, NULL)
6052
6053
6054
/**
6055
 * Set the requested options for the response.
6056
 *
6057
 * If any option fail other options may be or may be not applied.
6058
 * @param response the response to set the options
6059
 * @param[in] options the pointer to the array with the options;
6060
 *                    the array processing stops at the first ::MHD_D_O_END
6061
 *                    option, but not later than after processing
6062
 *                    @a options_max_num entries
6063
 * @param options_max_num the maximum number of entries in the @a options,
6064
 *                        use #MHD_OPTIONS_ARRAY_MAX_SIZE if options processing
6065
 *                        must stop only at zero-termination option
6066
 * @return ::MHD_SC_OK on success,
6067
 *         error code otherwise
6068
 */
6069
MHD_EXTERN_ enum MHD_StatusCode
6070
MHD_response_set_options (
6071
  struct MHD_Response *MHD_RESTRICT response,
6072
  const struct MHD_ResponseOptionAndValue *MHD_RESTRICT options,
6073
  size_t options_max_num)
6074
MHD_FN_PAR_NONNULL_ALL_;
6075
6076
6077
/**
6078
 * Set the requested single option for the response.
6079
 *
6080
 * @param response the response to set the option
6081
 * @param[in] option_ptr the pointer to the option
6082
 * @return ::MHD_SC_OK on success,
6083
 *         error code otherwise
6084
 * @ingroup response
6085
 */
6086
#define MHD_response_set_option(response, option_ptr) \
6087
        MHD_response_set_options (response,option_ptr,1)
6088
6089
6090
/* *INDENT-OFF* */
6091
#ifdef MHD_USE_VARARG_MACROS
6092
MHD_NOWARN_VARIADIC_MACROS_
6093
#  if defined(MHD_USE_COMPOUND_LITERALS) && \
6094
  defined(MHD_USE_COMP_LIT_FUNC_PARAMS)
6095
/**
6096
 * Set the requested options for the response.
6097
 *
6098
 * If any option fail other options may be or may be not applied.
6099
 *
6100
 * It should be used with helpers that creates required options, for example:
6101
 *
6102
 * MHD_RESPONSE_SET_OPTIONS(r, MHD_R_OPTION_REUSABLE(MHD_YES),
6103
 *                          MHD_R_OPTION_TERMINATION_CALLBACK(func, cls))
6104
 *
6105
 * @param response the response to set the option
6106
 * @param ... the list of the options, each option must be created
6107
 *            by helpers MHD_RESPONSE_OPTION_NameOfOption(option_value)
6108
 * @return ::MHD_SC_OK on success,
6109
 *         error code otherwise
6110
 */
6111
#    define MHD_RESPONSE_SET_OPTIONS(response,...)              \
6112
            MHD_NOWARN_COMPOUND_LITERALS_                           \
6113
            MHD_response_set_options (                              \
6114
              response,                                             \
6115
              ((const struct MHD_ResponseOptionAndValue[])          \
6116
               {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}),           \
6117
              MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
6118
            MHD_RESTORE_WARN_COMPOUND_LITERALS_
6119
#  elif defined(MHD_USE_CPP_INIT_LIST)
6120
MHD_C_DECLARATIONS_FINISH_HERE_
6121
#    include <vector>
6122
MHD_C_DECLARATIONS_START_HERE_
6123
/**
6124
 * Set the requested options for the response.
6125
 *
6126
 * If any option fail other options may be or may be not applied.
6127
 *
6128
 * It should be used with helpers that creates required options, for example:
6129
 *
6130
 * MHD_RESPONSE_SET_OPTIONS(r, MHD_R_OPTION_REUSABLE(MHD_YES),
6131
 *                          MHD_R_OPTION_TERMINATION_CALLBACK(func, cls))
6132
 *
6133
 * @param response the response to set the option
6134
 * @param ... the list of the options, each option must be created
6135
 *            by helpers MHD_RESPONSE_OPTION_NameOfOption(option_value)
6136
 * @return ::MHD_SC_OK on success,
6137
 *         error code otherwise
6138
 */
6139
#    define MHD_RESPONSE_SET_OPTIONS(response,...)              \
6140
            MHD_NOWARN_CPP_INIT_LIST_                               \
6141
            MHD_response_set_options (                              \
6142
              response,                                             \
6143
              (std::vector<struct MHD_ResponseOptionAndValue>       \
6144
               {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (),    \
6145
              MHD_OPTIONS_ARRAY_MAX_SIZE)                           \
6146
            MHD_RESTORE_WARN_CPP_INIT_LIST_
6147
#  endif
6148
MHD_RESTORE_WARN_VARIADIC_MACROS_
6149
#endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */
6150
/* *INDENT-ON* */
6151
6152
#ifndef MHD_FREECALLBACK_DEFINED
6153
6154
/**
6155
 * This method is called by libmicrohttpd when response with dynamic content
6156
 * is being destroyed.  It should be used to free resources associated
6157
 * with the dynamic content.
6158
 *
6159
 * @param[in] free_cls closure
6160
 * @ingroup response
6161
 */
6162
typedef void
6163
(*MHD_FreeCallback)(void *free_cls);
6164
6165
#  define MHD_FREECALLBACK_DEFINED 1
6166
#endif /* ! MHD_FREECALLBACK_DEFINED */
6167
#ifndef MHD_DYNCONTENTZCIOVEC_DEFINED
6168
6169
6170
/**
6171
 * Structure for iov type of the response.
6172
 * Used for zero-copy response content data.
6173
 */
6174
struct MHD_DynContentZCIoVec
6175
{
6176
  /**
6177
   * The number of elements in @a iov
6178
   */
6179
  unsigned int iov_count;
6180
  /**
6181
   * The pointer to the array with @a iov_count elements.
6182
   */
6183
  const struct MHD_IoVec *iov;
6184
  /**
6185
   * The callback to free resources.
6186
   * It is called once the full array of iov elements is sent.
6187
   * No callback is called if NULL.
6188
   */
6189
  MHD_FreeCallback iov_fcb;
6190
  /**
6191
   * The parameter for @a iov_fcb
6192
   */
6193
  void *iov_fcb_cls;
6194
};
6195
6196
#  define MHD_DYNCONTENTZCIOVEC_DEFINED 1
6197
#endif /* ! MHD_DYNCONTENTZCIOVEC_DEFINED */
6198
6199
/**
6200
 * The action type returned by Dynamic Content Creator callback
6201
 */
6202
struct MHD_DynamicContentCreatorAction;
6203
6204
/**
6205
 * The context used for Dynamic Content Creator callback
6206
 */
6207
struct MHD_DynamicContentCreatorContext;
6208
6209
6210
/**
6211
 * Create "continue processing" action with optional chunk-extension.
6212
 * The data is provided in the buffer and/or in the zero-copy @a iov_data.
6213
 *
6214
 * If data is provided both in the buffer and @a ivo_data then
6215
 * data in the buffer sent first, following the iov data.
6216
 * The total size of the data in the buffer and in @a iov_data must
6217
 * be non-zero.
6218
 * If response content size is known and total size of content provided earlier
6219
 * for this request combined with the size provided by this action is larger
6220
 * then known response content size, then NULL is returned.
6221
 *
6222
 * At most one DCC action can be created for one content callback.
6223
 *
6224
 * @param[in,out] ctx the pointer the context as provided to the callback
6225
 * @param data_size the amount of the data placed to the provided buffer,
6226
 *                  cannot be larger than provided buffer size,
6227
 *                  must be non-zero if @a iov_data is NULL or has no data,
6228
 * @param iov_data the optional pointer to the iov data,
6229
 *                 must not be NULL and have non-zero size data if @a data_size
6230
 *                 is zero,
6231
 * @param chunk_ext the optional pointer to chunk extension string,
6232
 *                  can be NULL to not use chunk extension,
6233
 *                  ignored if chunked encoding is not used
6234
 * @return the pointer to the action if succeed,
6235
 *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
6236
 */
6237
MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction *
6238
MHD_DCC_action_continue_zc (
6239
  struct MHD_DynamicContentCreatorContext *ctx,
6240
  size_t data_size,
6241
  const struct MHD_DynContentZCIoVec *iov_data,
6242
  const char *MHD_RESTRICT chunk_ext)
6243
MHD_FN_PAR_NONNULL_ (1)
6244
MHD_FN_PAR_CSTR_ (4);
6245
6246
6247
/**
6248
 * Create "continue processing" action with optional chunk-extension.
6249
 * The data is provided in the buffer.
6250
 *
6251
 * At most one DCC action can be created for one content callback.
6252
 *
6253
 * @param[in,out] ctx the pointer the context as provided to the callback
6254
 * @param data_size the amount of the data placed to the provided buffer (not @a iov_data),
6255
 *                  cannot be larger than provided buffer size,
6256
 *                  must be non-zero.
6257
 * @param chunk_ext the optional pointer to chunk extension string,
6258
 *                  can be NULL to not use chunk extension,
6259
 *                  ignored if chunked encoding is not used
6260
 * @return the pointer to the action if succeed,
6261
 *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
6262
 */
6263
#define MHD_DCC_action_continue_ce(ctx, data_size, chunk_ext) \
6264
        MHD_DCC_action_continue_zc ((ctx), (data_size), NULL, (chunk_ext))
6265
6266
6267
/**
6268
 * Create "continue processing" action, the data is provided in the buffer.
6269
 *
6270
 * At most one DCC action can be created for one content callback.
6271
 *
6272
 * @param[in,out] ctx the pointer the context as provided to the callback
6273
 * @param data_size the amount of the data placed to the provided buffer;
6274
 *                  cannot be larger than provided buffer size,
6275
 *                  must be non-zero.
6276
 *
6277
 * @return the pointer to the action if succeed,
6278
 *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
6279
 */
6280
#define MHD_DCC_action_continue(ctx, data_size) \
6281
        MHD_DCC_action_continue_ce ((ctx), (data_size), NULL)
6282
6283
6284
/**
6285
 * Create "finished" action with optional footers.
6286
 * If function failed for any reason, the action is automatically
6287
 * set to "stop with error".
6288
 *
6289
 * At most one DCC action can be created for one content callback.
6290
 *
6291
 * @param[in,out] ctx the pointer the context as provided to the callback
6292
 * @param num_footers number of elements in the @a footers array,
6293
 *                    must be zero if @a footers is NULL
6294
 * @param footers the optional pointer to the array of the footers (the strings
6295
 *                are copied and does not need to be valid after return from
6296
 *                this function),
6297
 *                can be NULL if @a num_footers is zero
6298
 * @return the pointer to the action if succeed,
6299
 *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
6300
 */
6301
MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction *
6302
MHD_DCC_action_finish_with_footer (
6303
  struct MHD_DynamicContentCreatorContext *ctx,
6304
  size_t num_footers,
6305
  const struct MHD_NameValueCStr *MHD_RESTRICT footers)
6306
MHD_FN_PAR_NONNULL_ (1);
6307
6308
6309
/**
6310
 * Create "finished" action.
6311
 * If function failed for any reason, the action is automatically
6312
 * set to "stop with error".
6313
 *
6314
 * At most one DCC action can be created for one content callback.
6315
 *
6316
 * @param[in,out] ctx the pointer the context as provided to the callback
6317
 * @return the pointer to the action if succeed,
6318
 *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
6319
 */
6320
#define MHD_DCC_action_finish(ctx) \
6321
        MHD_DCC_action_finish_with_footer ((ctx), 0, NULL)
6322
6323
6324
/**
6325
 * Create "suspend" action.
6326
 * If function failed for any reason, the action is automatically
6327
 * set to "stop with error".
6328
 *
6329
 * At most one DCC action can be created for one content callback.
6330
 *
6331
 * @param[in,out] ctx the pointer the context as provided to the callback
6332
 * @return the pointer to the action if succeed,
6333
 *         NULL (equivalent of MHD_DCC_action_abort())in case of any error
6334
 */
6335
MHD_EXTERN_ const struct MHD_DynamicContentCreatorAction *
6336
MHD_DCC_action_suspend (struct MHD_DynamicContentCreatorContext *ctx)
6337
MHD_FN_PAR_NONNULL_ (1);
6338
6339
/**
6340
 * Create "stop with error" action.
6341
 * @param[in,out] ctx the pointer the context as provided to the callback
6342
 * @return always NULL (the action "stop with error")
6343
 */
6344
#define MHD_DCC_action_abort(ctx) \
6345
        MHD_STATIC_CAST_ (const struct MHD_DynamicContentCreatorAction *, NULL)
6346
6347
/**
6348
 * Callback used by libmicrohttpd in order to obtain content.  The
6349
 * callback is to copy at most @a max bytes of content into @a buf or
6350
 * provide zero-copy data for #MHD_DCC_action_continue_zc().
6351
 *
6352
 * @param dyn_cont_cls closure argument to the callback
6353
 * @param ctx the context to produce the action to return,
6354
 *            the pointer is only valid until the callback returns
6355
 * @param pos position in the datastream to access;
6356
 *        note that if a `struct MHD_Response` object is re-used,
6357
 *        it is possible for the same content reader to
6358
 *        be queried multiple times for the same data;
6359
 *        however, if a `struct MHD_Response` is not re-used,
6360
 *        libmicrohttpd guarantees that "pos" will be
6361
 *        the sum of all data sizes provided by this callback
6362
 * @param[out] buf where to copy the data
6363
 * @param max maximum number of bytes to copy to @a buf (size of @a buf),
6364
              if the size of the content of the response is known then size
6365
              of the buffer is never larger than amount of the content left
6366
 * @return action to use,
6367
 *         NULL in case of any error (the response will be aborted)
6368
 */
6369
typedef const struct MHD_DynamicContentCreatorAction *
6370
(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (4)
6371
 *MHD_DynamicContentCreator)(void *dyn_cont_cls,
6372
                             struct MHD_DynamicContentCreatorContext *ctx,
6373
                             uint_fast64_t pos,
6374
                             void *buf,
6375
                             size_t max);
6376
6377
6378
/**
6379
 * Create a response.  The response object can be extended with
6380
 * header information.
6381
 *
6382
 * @param sc status code to return
6383
 * @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
6384
 * @param dyn_cont callback to use to obtain response data
6385
 * @param dyn_cont_cls extra argument to @a crc
6386
 * @param dyn_cont_fc callback to call to free @a dyn_cont_cls resources
6387
 * @return NULL on error (i.e. invalid arguments, out of memory)
6388
 * FIXME: Call free callback on error?
6389
 * @ingroup response
6390
 */
6391
MHD_EXTERN_ struct MHD_Response *
6392
MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
6393
                            uint_fast64_t size,
6394
                            MHD_DynamicContentCreator dyn_cont,
6395
                            void *dyn_cont_cls,
6396
                            MHD_FreeCallback dyn_cont_fc);
6397
6398
6399
/**
6400
 * Create a response object.  The response object can be extended with
6401
 * header information.
6402
 *
6403
 * @param sc status code to use for the response;
6404
 *           #MHD_HTTP_STATUS_NO_CONTENT is only valid if @a size is 0;
6405
 * @param buffer_size the size of the data portion of the response
6406
 * @param buffer the @a size bytes containing the response's data portion,
6407
 *               needs to be valid while the response is used
6408
 * @param free_cb the callback to free any allocated data, called
6409
 *                when response is being destroyed, can be NULL
6410
 *                to skip the free/cleanup callback;
6411
 * @param free_cb_cls the parameter for @a free_cb
6412
 * @return NULL on error (i.e. invalid arguments, out of memory)
6413
 *   on error, @a free_cb is NOT called
6414
 * @ingroup response
6415
 */
6416
MHD_EXTERN_ struct MHD_Response *
6417
MHD_response_from_buffer (
6418
  enum MHD_HTTP_StatusCode sc,
6419
  size_t buffer_size,
6420
  const char *buffer,
6421
  MHD_FreeCallback free_cb,
6422
  void *free_cb_cls)
6423
MHD_FN_PAR_IN_SIZE_ (3, 2);
6424
6425
6426
/**
6427
 * Create a response object with body that is a
6428
 * statically allocated buffer that never needs to
6429
 * be freed as its lifetime exceeds that of the
6430
 * daemon.
6431
 *
6432
 * The response object can be extended with header information and then be used
6433
 * any number of times.
6434
 * @param sc status code to use for the response
6435
 * @param len number of bytes in @a buf
6436
 * @param buf buffer with response payload
6437
 */
6438
#define MHD_response_from_buffer_static(sc, len, buf)       \
6439
        MHD_response_from_buffer (sc, len, buf, NULL, NULL)
6440
6441
6442
/**
6443
 * Create a response object with empty (zero size) body.
6444
 *
6445
 * The response object can be extended with header information and then be used
6446
 * any number of times.
6447
 * @param sc status code to use for the response
6448
 */
6449
#define MHD_response_from_empty(sc) \
6450
        MHD_response_from_buffer_static (sc, 0, "")
6451
6452
6453
/**
6454
 * Create a response object.  The response object can be extended with
6455
 * header information.
6456
 *
6457
 * @param sc status code to use for the response
6458
 * @param buffer_size the size of the data portion of the response
6459
 * @param buffer the @a size bytes containing the response's data portion,
6460
 *               an internal copy will be made, there is no need to
6461
 *               keep this data after return from this function
6462
 * @return NULL on error (i.e. invalid arguments, out of memory)
6463
 * FIXME: Call free callback on error?
6464
 * @ingroup response
6465
 */
6466
MHD_EXTERN_ struct MHD_Response *
6467
MHD_response_from_buffer_copy (
6468
  enum MHD_HTTP_StatusCode sc,
6469
  size_t buffer_size,
6470
  const char buffer[MHD_FN_PAR_DYN_ARR_SIZE_ (buffer_size)])
6471
MHD_FN_PAR_IN_SIZE_ (3, 2);
6472
6473
6474
/**
6475
 * I/O vector type. Provided for use with #MHD_response_from_iovec().
6476
 * @ingroup response
6477
 */
6478
struct MHD_IoVec
6479
{
6480
  /**
6481
   * The pointer to the memory region for I/O.
6482
   */
6483
  const void *iov_base;
6484
6485
  /**
6486
   * The size in bytes of the memory region for I/O.
6487
   */
6488
  size_t iov_len;
6489
};
6490
6491
6492
/**
6493
 * Create a response object with an array of memory buffers
6494
 * used as the response body.
6495
 *
6496
 * The response object can be extended with header information.
6497
 *
6498
 * If response object is used to answer HEAD request then the body
6499
 * of the response is not used, while all headers (including automatic
6500
 * headers) are used.
6501
 *
6502
 * @param sc status code to use for the response
6503
 * @param iov_count the number of elements in @a iov
6504
 * @param iov the array for response data buffers, an internal copy of this
6505
 *        will be made
6506
 * @param free_cb the callback to clean up any data associated with @a iov when
6507
 *        the response is destroyed.
6508
 * @param free_cb_cls the argument passed to @a free_cb
6509
 * @return NULL on error (i.e. invalid arguments, out of memory)
6510
 * FIXME: Call free callback on error?
6511
 * @ingroup response
6512
 */
6513
MHD_EXTERN_ struct MHD_Response *
6514
MHD_response_from_iovec (
6515
  enum MHD_HTTP_StatusCode sc,
6516
  unsigned int iov_count,
6517
  const struct MHD_IoVec iov[MHD_FN_PAR_DYN_ARR_SIZE_ (iov_count)],
6518
  MHD_FreeCallback free_cb,
6519
  void *free_cb_cls);
6520
6521
6522
/**
6523
 * Create a response object based on an @a fd from which
6524
 * data is read.  The response object can be extended with
6525
 * header information.
6526
 *
6527
 * @param sc status code to return
6528
 * @param fd file descriptor referring to a file on disk with the
6529
 *        data; will be closed when response is destroyed;
6530
 *        fd should be in 'blocking' mode
6531
 * @param offset offset to start reading from in the file;
6532
 *        reading file beyond 2 GiB may be not supported by OS or
6533
 *        MHD build; see #MHD_LIB_INFO_FIXED_HAS_LARGE_FILE
6534
 * @param size size of the data portion of the response;
6535
 *        sizes larger than 2 GiB may be not supported by OS or
6536
 *        MHD build; see #MHD_LIB_INFO_FIXED_HAS_LARGE_FILE
6537
 * @return NULL on error (i.e. invalid arguments, out of memory)
6538
 * FIXME: Close FD on error?
6539
 * @ingroup response
6540
 */
6541
MHD_EXTERN_ struct MHD_Response *
6542
MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,
6543
                      int fd,
6544
                      uint_fast64_t offset,
6545
                      uint_fast64_t size)
6546
MHD_FN_PAR_FD_READ_ (2);
6547
6548
/**
6549
 * Create a response object with the response body created by reading
6550
 * the provided pipe.
6551
 *
6552
 * The response object can be extended with header information and
6553
 * then be used ONLY ONCE.
6554
 *
6555
 * If response object is used to answer HEAD request then the body
6556
 * of the response is not used, while all headers (including automatic
6557
 * headers) are used.
6558
 *
6559
 * @param sc status code to use for the response
6560
 * @param fd file descriptor referring to a read-end of a pipe with the
6561
 *        data; will be closed when response is destroyed;
6562
 *        fd should be in 'blocking' mode
6563
 * @return NULL on error (i.e. invalid arguments, out of memory)
6564
 * FIXME: Close pipe FD on error?
6565
 * @ingroup response
6566
 */
6567
MHD_EXTERN_ struct MHD_Response *
6568
MHD_response_from_pipe (enum MHD_HTTP_StatusCode sc,
6569
                        int fd)
6570
MHD_FN_PAR_FD_READ_ (2);
6571
6572
6573
/**
6574
 * Destroy response.
6575
 * Should be called if response was created but not consumed.
6576
 * Also must be called if response has #MHD_R_O_REUSABLE set.
6577
 * The actual destroy can be happen later, if the response
6578
 * is still being used in any request.
6579
 * The function does not block.
6580
 *
6581
 * @param[in] response the response to destroy
6582
 * @ingroup response
6583
 */
6584
MHD_EXTERN_ void
6585
MHD_response_destroy (struct MHD_Response *response)
6586
MHD_FN_PAR_NONNULL_ (1);
6587
6588
6589
/**
6590
 * Add a header line to the response.
6591
 *
6592
 * @param response response to add a header to, NULL is tolerated
6593
 * @param name the name of the header to add,
6594
 *             an internal copy of the string will be made
6595
 * @param value the value of the header to add,
6596
 *              an internal copy of the string will be made
6597
 * @return #MHD_SC_OK on success,
6598
 *         error code otherwise
6599
 * @ingroup response
6600
 */
6601
MHD_EXTERN_ enum MHD_StatusCode
6602
MHD_response_add_header (struct MHD_Response *MHD_RESTRICT response,
6603
                         const char *MHD_RESTRICT name,
6604
                         const char *MHD_RESTRICT value)
6605
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
6606
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3);
6607
6608
6609
/**
6610
 * Add a header with predefined (standard) name to the response.
6611
 *
6612
 * @param response response to add a header to
6613
 * @param stk the code of the predefined header
6614
 * @param content the value of the header to add,
6615
 *              an internal copy of the string will be made
6616
 * @return #MHD_SC_OK on success,
6617
 *         error code otherwise
6618
 * @ingroup response
6619
 */
6620
MHD_EXTERN_ enum MHD_StatusCode
6621
MHD_response_add_predef_header (struct MHD_Response *MHD_RESTRICT response,
6622
                                enum MHD_PredefinedHeader stk,
6623
                                const char *MHD_RESTRICT content)
6624
MHD_FN_PAR_NONNULL_ (1)
6625
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_CSTR_ (3);
6626
6627
6628
/* ************ (b) Upload and PostProcessor functions ********************** */
6629
6630
6631
/**
6632
 * Suspend handling of network data for a given request.  This can
6633
 * be used to dequeue a request from MHD's event loop for a while.
6634
 *
6635
 * Suspended requests continue to count against the total number of
6636
 * requests allowed (per daemon, as well as per IP, if such limits
6637
 * are set).  Suspended requests will NOT time out; timeouts will
6638
 * restart when the request handling is resumed.  While a
6639
 * request is suspended, MHD may not detect disconnects by the
6640
 * client.
6641
 *
6642
 * At most one upload action can be created for one upload callback.
6643
 *
6644
 * @param[in,out] request the request for which the action is generated
6645
 * @return action to cause a request to be suspended,
6646
 *         NULL if any action has been already created for the @a request
6647
 * @ingroup action
6648
 */
6649
MHD_EXTERN_ const struct MHD_UploadAction *
6650
MHD_upload_action_suspend (struct MHD_Request *request)
6651
MHD_FN_PAR_NONNULL_ALL_;
6652
6653
/**
6654
 * Converts a @a response to an action.  If #MHD_R_O_REUSABLE
6655
 * is not set, the reference to the @a response is consumed
6656
 * by the conversion. If #MHD_R_O_REUSABLE is #MHD_YES,
6657
 * then the @a response can be used again to create actions in
6658
 * the future.
6659
 * However, the @a response is frozen by this step and
6660
 * must no longer be modified (i.e. by setting headers).
6661
 *
6662
 * At most one upload action can be created for one upload callback.
6663
 *
6664
 * @param request the request to create the action for
6665
 * @param[in] response the response to convert,
6666
 *                     if NULL then this function is equivalent to
6667
 *                     #MHD_upload_action_abort_request() call
6668
 * @return pointer to the action, the action must be consumed
6669
 *         otherwise response object may leak;
6670
 *         NULL if failed (no memory) or if any action has been already
6671
 *         created for the @a request;
6672
 *         when failed the response object is consumed and need not
6673
 *         to be "destroyed"
6674
 * @ingroup action
6675
 */
6676
MHD_EXTERN_ const struct MHD_UploadAction *
6677
MHD_upload_action_from_response (struct MHD_Request *MHD_RESTRICT request,
6678
                                 struct MHD_Response *MHD_RESTRICT response)
6679
MHD_FN_PAR_NONNULL_ (1);
6680
6681
/**
6682
 * Action telling MHD to continue processing the upload.
6683
 * Valid only for incremental upload processing.
6684
 * Works as #MHD_upload_action_abort_request() if used for full upload callback
6685
 * or for the final (with zero data) incremental callback.
6686
 *
6687
 * At most one upload action can be created for one upload callback.
6688
 *
6689
 * @param request the request to make an action
6690
 * @return action operation,
6691
 *         NULL if any action has been already created for the @a request
6692
 * @ingroup action
6693
 */
6694
MHD_EXTERN_ const struct MHD_UploadAction *
6695
MHD_upload_action_continue (struct MHD_Request *request)
6696
MHD_FN_PAR_NONNULL_ (1);
6697
6698
6699
/**
6700
 * Action telling MHD to close the connection hard
6701
 * (kind-of breaking HTTP specification).
6702
 *
6703
 * @param req the request to make an action
6704
 * @return action operation, always NULL
6705
 * @ingroup action
6706
 */
6707
#define MHD_upload_action_abort_request(req) \
6708
        MHD_STATIC_CAST_ (const struct MHD_UploadAction *, NULL)
6709
6710
#ifndef MHD_UPLOADCALLBACK_DEFINED
6711
6712
/**
6713
 * Function to process data uploaded by a client.
6714
 *
6715
 * @param upload_cls the argument given together with the function
6716
 *                   pointer when the handler was registered with MHD
6717
 * @param request the request is being processed
6718
 * @param content_data_size the size of the @a content_data,
6719
 *                          zero when all data have been processed
6720
 * @param[in] content_data the uploaded content data,
6721
 *                         may be modified in the callback,
6722
 *                         valid only until return from the callback,
6723
 *                         NULL when all data have been processed
6724
 * @return action specifying how to proceed:
6725
 *         #MHD_upload_action_continue() to continue upload (for incremental
6726
 *         upload processing only),
6727
 *         #MHD_upload_action_suspend() to stop reading the upload until
6728
 *         the request is resumed,
6729
 *         #MHD_upload_action_abort_request() to close the socket,
6730
 *         or a response to discard the rest of the upload and transmit
6731
 *         the response
6732
 * @ingroup action
6733
 */
6734
typedef const struct MHD_UploadAction *
6735
(MHD_FN_PAR_NONNULL_ (2)  MHD_FN_PAR_INOUT_SIZE_ (4, 3)
6736
 *MHD_UploadCallback)(void *upload_cls,
6737
                      struct MHD_Request *request,
6738
                      size_t content_data_size,
6739
                      void *content_data);
6740
6741
#  define MHD_UPLOADCALLBACK_DEFINED 1
6742
#endif /* ! MHD_UPLOADCALLBACK_DEFINED */
6743
6744
/**
6745
 * Create an action that handles an upload.
6746
 *
6747
 * If @a uc_inc is NULL and upload cannot fit the allocated buffer
6748
 * then request is aborted without response.
6749
 *
6750
 * At most one action can be created for any request.
6751
 *
6752
 * @param request the request to create action for
6753
 * @param large_buffer_size how large should the upload buffer be.
6754
 *                          May allocate memory from the shared "large"
6755
 *                          memory pool if necessary and non-zero is given.
6756
 *                          Must be zero if @a uc_full is NULL.
6757
 * @param uc_full the function to call when complete upload
6758
 *                is received (only if fit @a upload_buffer_size),
6759
 *                can be NULL if uc_inc is not NULL,
6760
 *                must be NULL is @a upload_buffer_size is zero.
6761
 * @param uc_full_cls closure for @a uc_full
6762
 * @param uc_inc the function to incrementally process the upload data
6763
 *               if the upload if larger than @a upload_buffer_size or
6764
 *               @a upload_buffer_size cannot be allocated or
6765
 *               @a uc_full is NULL,
6766
 *               can be NULL if uc_full is not NULL
6767
 * @param uc_inc_cls closure for @a uc_inc
6768
 * @return NULL on error (out of memory, invalid parameters)
6769
 * @return pointer to the action,
6770
 *         NULL if failed (no memory) or if any action has been already
6771
 *         created for the @a request.
6772
 * @sa #MHD_D_OPTION_LARGE_POOL_SIZE()
6773
 * @ingroup action
6774
 */
6775
MHD_EXTERN_ const struct MHD_Action *
6776
MHD_action_process_upload (
6777
  struct MHD_Request *request,
6778
  size_t large_buffer_size,
6779
  MHD_UploadCallback uc_full,
6780
  void *uc_full_cls,
6781
  MHD_UploadCallback uc_inc,
6782
  void *uc_inc_cls)
6783
MHD_FN_PAR_NONNULL_ (1);
6784
6785
/**
6786
 * Create an action that handles an upload as full upload data.
6787
 *
6788
 * @param request the request to create action for
6789
 * @param buff_size how large should the upload buffer be. May allocate memory
6790
 *                  from the large memory pool if necessary. Must not be zero.
6791
 * @param uc the function to call when complete upload
6792
 *           is received (only if fit @a upload_buffer_size)
6793
 * @param uc_cls closure for @a uc
6794
 * @return NULL on error (out of memory. both @a uc is NULL)
6795
 * @ingroup action
6796
 */
6797
#define MHD_action_process_upload_full(request, buff_size, uc, uc_cls) \
6798
        MHD_action_process_upload (request, buff_size, uc, uc_cls, NULL, NULL)
6799
6800
/**
6801
 * Create an action that handles an upload incrementally.
6802
 *
6803
 * @param request the request to create action for
6804
 * @param uc the function to incrementally process the upload data
6805
 * @param uc_cls closure for @a uc
6806
 * @return NULL on error (out of memory. both @a uc is NULL)
6807
 * @ingroup action
6808
 */
6809
#define MHD_action_process_upload_inc(request, uc, uc_cls) \
6810
        MHD_action_process_upload (request, 0, NULL, NULL, uc, uc_cls)
6811
6812
#ifndef MHD_POST_PARSE_RESULT_DEFINED
6813
6814
/**
6815
 * The result of POST data parsing
6816
 */
6817
enum MHD_FIXED_ENUM_MHD_SET_ MHD_PostParseResult
6818
{
6819
  /**
6820
   * The POST data parsed successfully and completely.
6821
   */
6822
  MHD_POST_PARSE_RES_OK = 0
6823
  ,
6824
  /**
6825
   * The POST request has no content or zero-length content.
6826
   */
6827
  MHD_POST_PARSE_RES_REQUEST_EMPTY = 1
6828
  ,
6829
  /**
6830
   * The POST data parsed successfully, but has missing or incorrect
6831
   * termination.
6832
   * The last parsed field may have incorrect data.
6833
   */
6834
  MHD_POST_PARSE_RES_OK_BAD_TERMINATION = 2
6835
  ,
6836
  /**
6837
   * Parsing of the POST data is incomplete because client used incorrect
6838
   * format of POST encoding.
6839
   * The last parsed field may have incorrect data.
6840
   * Some POST data is available or has been provided via callback.
6841
   */
6842
  MHD_POST_PARSE_RES_PARTIAL_INVALID_POST_FORMAT = 3
6843
  ,
6844
  /**
6845
   * The POST data cannot be parsed completely because the stream has
6846
   * no free pool memory.
6847
   * Some POST data may be parsed.
6848
   */
6849
  MHD_POST_PARSE_RES_FAILED_NO_POOL_MEM = 60
6850
  ,
6851
  /**
6852
   * The POST data cannot be parsed completely because no "large shared buffer"
6853
   * space is available.
6854
   * Some POST data may be parsed.
6855
   */
6856
  MHD_POST_PARSE_RES_FAILED_NO_LARGE_BUF_MEM = 61
6857
  ,
6858
  /**
6859
   * The POST data cannot be parsed because 'Content-Type:' is unknown.
6860
   */
6861
  MHD_POST_PARSE_RES_FAILED_UNKNOWN_CNTN_TYPE = 80
6862
  ,
6863
  /**
6864
   * The POST data cannot be parsed because 'Content-Type:' header is not set.
6865
   */
6866
  MHD_POST_PARSE_RES_FAILED_NO_CNTN_TYPE = 81
6867
  ,
6868
  /**
6869
   * The POST data cannot be parsed because "Content-Type:" request header has
6870
   * no "boundary" parameter for "multipart/form-data"
6871
   */
6872
  MHD_POST_PARSE_RES_FAILED_HEADER_NO_BOUNDARY = 82
6873
  ,
6874
  /**
6875
   * The POST data cannot be parsed because "Content-Type: multipart/form-data"
6876
   * request header is misformed
6877
   */
6878
  MHD_POST_PARSE_RES_FAILED_HEADER_MISFORMED = 83
6879
  ,
6880
  /**
6881
   * The application set POST encoding to "multipart/form-data", but the request
6882
   * has no "Content-Type: multipart/form-data" header which is required
6883
   * to find "boundary" used in this encoding
6884
   */
6885
  MHD_POST_PARSE_RES_FAILED_HEADER_NOT_MPART = 84
6886
  ,
6887
  /**
6888
   * The POST data cannot be parsed because client used incorrect format
6889
   * of POST encoding.
6890
   */
6891
  MHD_POST_PARSE_RES_FAILED_INVALID_POST_FORMAT = 90
6892
6893
};
6894
6895
#  define MHD_POST_PARSE_RESULT_DEFINED 1
6896
#endif /* ! MHD_POST_PARSE_RESULT_DEFINED */
6897
6898
#ifndef MHD_POST_DATA_READER_DEFINED
6899
6900
/**
6901
 * "Stream" reader for POST data.
6902
 * This callback is called to incrementally process parsed POST data sent by
6903
 * the client.
6904
 * The pointers to the MHD_String and MHD_StringNullable are valid only until
6905
 * return from this callback.
6906
 * The pointers to the strings and the @a data are valid only until return from
6907
 * this callback.
6908
 *
6909
 * @param req the request
6910
 * @param cls user-specified closure
6911
 * @param name the name of the POST field
6912
 * @param filename the name of the uploaded file, @a cstr member is NULL if not
6913
 *                 known / not provided
6914
 * @param content_type the mime-type of the data, cstr member is NULL if not
6915
 *                     known / not provided
6916
 * @param encoding the encoding of the data, cstr member is NULL if not known /
6917
 *                 not provided
6918
 * @param size the number of bytes in @a data available, may be zero if
6919
 *             the @a final_data is #MHD_YES
6920
 * @param data the pointer to @a size bytes of data at the specified
6921
 *             @a off offset, NOT zero-terminated
6922
 * @param off the offset of @a data in the overall value, always equal to
6923
 *            the sum of sizes of previous calls for the same field / file;
6924
 *            client may provide more than one field with the same name and
6925
 *            the same filename, the new filed (or file) is indicated by zero
6926
 *            value of @a off (and the end is indicated by @a final_data)
6927
 * @param final_data if set to #MHD_YES then full field data is provided,
6928
 *                   if set to #MHD_NO then more field data may be provided
6929
 * @return action specifying how to proceed:
6930
 *         #MHD_upload_action_continue() if all is well,
6931
 *         #MHD_upload_action_suspend() to stop reading the upload until
6932
 *         the request is resumed,
6933
 *         #MHD_upload_action_abort_request() to close the socket,
6934
 *         or a response to discard the rest of the upload and transmit
6935
 *         the response
6936
 * @ingroup action
6937
 */
6938
typedef const struct MHD_UploadAction *
6939
(MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_NONNULL_ (4)
6940
 MHD_FN_PAR_NONNULL_ (5) MHD_FN_PAR_NONNULL_ (6)
6941
 *MHD_PostDataReader) (struct MHD_Request *req,
6942
                       void *cls,
6943
                       const struct MHD_String *name,
6944
                       const struct MHD_StringNullable *filename,
6945
                       const struct MHD_StringNullable *content_type,
6946
                       const struct MHD_StringNullable *encoding,
6947
                       size_t size,
6948
                       const void *data,
6949
                       uint_fast64_t off,
6950
                       enum MHD_Bool final_data);
6951
6952
6953
/**
6954
 * The callback to be called when finished with processing
6955
 * of the postprocessor upload data.
6956
 * @param req the request
6957
 * @param cls the closure
6958
 * @param parsing_result the result of POST data parsing
6959
 * @return the action to proceed
6960
 */
6961
typedef const struct MHD_UploadAction *
6962
(MHD_FN_PAR_NONNULL_ (1)
6963
 *MHD_PostDataFinished) (struct MHD_Request *req,
6964
                         void *cls,
6965
                         enum MHD_PostParseResult parsing_result);
6966
6967
#  define MHD_POST_DATA_READER_DEFINED 1
6968
#endif /* ! MHD_POST_DATA_READER_DEFINED */
6969
6970
/**
6971
 * Create an action to parse the POSTed content from the client.
6972
 *
6973
 * The action starts parsing of the POST data. Any value that does not fit
6974
 * @a buffer_size or larger that @a auto_stream_size is given to
6975
 * @a stream_reader (if it is not NULL).
6976
 *
6977
 * If @a buffer_size is zero, then buffers will be limited to the connection's
6978
 * memory pool. To force all POST data process via @a stream_reader
6979
 * set @a auto_stream_size to zero.
6980
 *
6981
 * At most one action can be created for any request.
6982
 *
6983
 * @param request the request to create action for
6984
 * @param buffer_size the maximum size allowed for the buffers to parse this
6985
 *                    request POST data. Within the set limit the buffer is
6986
 *                    allocated automatically from the "large" shared memory
6987
 *                    pool if necessary.
6988
 * @param max_nonstream_size the size of the field (in encoded form) above which
6989
 *                           values are not buffered and provided for
6990
 *                           the @a steam_reader automatically;
6991
 *                           useful to have large data (like file uploads)
6992
 *                           processed incrementally, while keeping buffer space
6993
 *                           for small fields only;
6994
 *                           ignored if @a stream_reader is NULL
6995
 * @param enc the data encoding to use,
6996
 *            use #MHD_HTTP_POST_ENCODING_OTHER to detect automatically
6997
 * @param stream_reader the function to call for "oversize" values in
6998
 *                      the stream; can be NULL if @a auto_stream_size is
6999
 *                      not zero
7000
 * @param reader_cls the closure for the @a stream_reader
7001
 * @param done_cb called once all data has been processed for
7002
 *   the final action; values smaller than @a auto_stream_size that
7003
 *   fit into @a buffer_size will be available via
7004
 *   #MHD_request_get_values_cb(), #MHD_request_get_values_list() and
7005
 *   #MHD_request_get_post_data_cb(), #MHD_request_get_post_data_list()
7006
 * @param done_cb_cls the closure for the @a done_cb
7007
 * @return pointer to the action,
7008
 *         NULL if failed (no memory) or if any action has been already
7009
 *         created for the @a request.
7010
 * @sa #MHD_D_OPTION_LARGE_POOL_SIZE()
7011
 * @ingroup action
7012
 */
7013
MHD_EXTERN_ const struct MHD_Action *
7014
MHD_action_parse_post (struct MHD_Request *request,
7015
                       size_t buffer_size,
7016
                       size_t max_nonstream_size,
7017
                       enum MHD_HTTP_PostEncoding enc,
7018
                       MHD_PostDataReader stream_reader,
7019
                       void *reader_cls,
7020
                       MHD_PostDataFinished done_cb,
7021
                       void *done_cb_cls)
7022
MHD_FN_PAR_NONNULL_ (1);
7023
7024
7025
#ifndef MHD_POSTFILED_DEFINED
7026
7027
/**
7028
 * Post data element.
7029
 * If any member is not provided/set then pointer to C string is NULL.
7030
 * If any member is set to empty string then pointer to C string not NULL,
7031
 * but the length is zero.
7032
 */
7033
struct MHD_PostField
7034
{
7035
  /**
7036
   * The name of the field
7037
   */
7038
  struct MHD_String name;
7039
  /**
7040
   * The field data
7041
   * If not set or defined then to C string is NULL.
7042
   * If set to empty string then pointer to C string not NULL,
7043
   * but the length is zero.
7044
   */
7045
  struct MHD_StringNullable value;
7046
  /**
7047
   * The filename if provided (only for "multipart/form-data")
7048
   * If not set or defined then to C string is NULL.
7049
   * If set to empty string then pointer to C string not NULL,
7050
   * but the length is zero.
7051
   */
7052
  struct MHD_StringNullable filename;
7053
  /**
7054
   * The Content-Type if provided (only for "multipart/form-data")
7055
   * If not set or defined then to C string is NULL.
7056
   * If set to empty string then pointer to C string not NULL,
7057
   * but the length is zero.
7058
   */
7059
  struct MHD_StringNullable content_type;
7060
  /**
7061
   * The Transfer-Encoding if provided (only for "multipart/form-data")
7062
   * If not set or defined then to C string is NULL.
7063
   * If set to empty string then pointer to C string not NULL,
7064
   * but the length is zero.
7065
   */
7066
  struct MHD_StringNullable transfer_encoding;
7067
};
7068
7069
#  define MHD_POSTFILED_DEFINED 1
7070
#endif /* ! MHD_POSTFILED_DEFINED */
7071
7072
7073
/**
7074
 * Iterator over POST data.
7075
 *
7076
 * The @a data pointer is valid only until return from this function.
7077
 *
7078
 * The pointers to the strings in @a data are valid until any MHD_UploadAction
7079
 * is provided. If the data is needed beyond this point, it should be copied.
7080
 *
7081
 * @param cls closure
7082
 * @param data the element of the post data, the pointer is valid only until
7083
 *             return from this function
7084
 * @return #MHD_YES to continue iterating,
7085
 *         #MHD_NO to abort the iteration
7086
 * @ingroup request
7087
 */
7088
typedef enum MHD_Bool
7089
(MHD_FN_PAR_NONNULL_ (2)
7090
 *MHD_PostDataIterator)(void *cls,
7091
                        const struct MHD_PostField *data);
7092
7093
/**
7094
 * Get all of the post data from the request via request.
7095
 *
7096
 * @param request the request to get data for
7097
 * @param iterator callback to call on each header;
7098
 *        maybe NULL (then just count headers)
7099
 * @param iterator_cls extra argument to @a iterator
7100
 * @return number of entries iterated over
7101
 * @ingroup request
7102
 */
7103
MHD_EXTERN_ size_t
7104
MHD_request_get_post_data_cb (struct MHD_Request *request,
7105
                              MHD_PostDataIterator iterator,
7106
                              void *iterator_cls)
7107
MHD_FN_PAR_NONNULL_ (1);
7108
7109
/**
7110
 * Get all of the post data from the request.
7111
 *
7112
 * The pointers to the strings in @a elements are valid until any
7113
 * MHD_UploadAction is provided. If the data is needed beyond this point,
7114
 * it should be copied.
7115
 * @param request the request to get data for
7116
 * @param num_elements the number of elements in @a elements array
7117
 * @param[out] elements the array of @a num_elements to get the data
7118
 * @return the number of elements stored in @a elements,
7119
 *         zero if no data or postprocessor was not used.
7120
 * @ingroup request
7121
 */
7122
MHD_EXTERN_ size_t
7123
MHD_request_get_post_data_list (
7124
  struct MHD_Request *request,
7125
  size_t num_elements,
7126
  struct MHD_PostField elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)])
7127
MHD_FN_PAR_NONNULL_ (1)
7128
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3, 2);
7129
7130
/* ***************** (c) WebSocket support ********** */
7131
7132
/**
7133
 * Handle given to the application to manage special
7134
 * actions relating to MHD responses that "upgrade"
7135
 * the HTTP protocol (i.e. to WebSockets).
7136
 */
7137
struct MHD_UpgradedHandle;
7138
7139
7140
#ifndef MHD_UPGRADEHANDLER_DEFINED
7141
7142
/**
7143
 * Function called after a protocol "upgrade" response was sent successfully
7144
 * and the connection is being switched to other protocol.
7145
 *
7146
 * The newly provided handle @a urh can be used to send and receive the data
7147
 * by #MHD_upgraded_send() and #MHD_upgraded_recv(). The handle must be closed
7148
 * by #MHD_upgraded_close() before destroying the daemon.
7149
 *
7150
 * "Upgraded" connection will not time out, but still counted for daemon
7151
 * global connections limit and for per-IP limit (if set).
7152
 *
7153
 * Except when in 'thread-per-connection' mode, implementations
7154
 * of this function should never block (as it will still be called
7155
 * from within the main event loop).
7156
 *
7157
 * @param cls closure, whatever was given to #MHD_action_upgrade().
7158
 * @param request original HTTP request handle,
7159
 *                giving the function a last chance
7160
 *                to inspect the original HTTP request
7161
 * @param urh argument for #MHD_upgrade_operation() on this @a response.
7162
 *        Applications must eventually use this callback to (indirectly)
7163
 *        perform the close() action on the @a sock.
7164
 */
7165
typedef void
7166
(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_NONNULL_ (3)
7167
 *MHD_UpgradeHandler)(void *cls,
7168
                      struct MHD_Request *MHD_RESTRICT request,
7169
                      struct MHD_UpgradedHandle *MHD_RESTRICT urh);
7170
7171
#  define MHD_UPGRADEHANDLER_DEFINED 1
7172
#endif /* ! MHD_UPGRADEHANDLER_DEFINED */
7173
7174
7175
/**
7176
 * Create a action object that can be used for 101 Upgrade
7177
 * responses, for example to implement WebSockets.  After sending the
7178
 * response, control over the data stream is given to the callback (which
7179
 * can then, for example, start some bi-directional communication).
7180
 * The callback will ONLY be called after the response header was successfully
7181
 * passed to the OS; if there are communication errors before, the usual MHD
7182
 * connection error handling code will be performed.
7183
 *
7184
 * At most one action can be created for any request.
7185
 *
7186
 * @param request the request to create action for
7187
 * @param upgrade_hdr_value the value of the "Upgrade:" header, mandatory
7188
                            string
7189
 * @param upgrade_handler function to call with the "upgraded" socket
7190
 * @param upgrade_handler_cls closure for @a upgrade_handler
7191
 * @param num_headers number of elements in the @a headers array,
7192
 *                    must be zero if @a headers is NULL
7193
 * @param headers the optional pointer to the array of the headers (the strings
7194
 *                are copied and does not need to be valid after return from
7195
 *                this function),
7196
 *                can be NULL if @a num_headers is zero
7197
 * @return NULL on error (i.e. invalid arguments, out of memory)
7198
 * @ingroup action
7199
 */
7200
MHD_EXTERN_ const struct MHD_Action *
7201
MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request,
7202
                    const char *MHD_RESTRICT upgrade_hdr_value,
7203
                    MHD_UpgradeHandler upgrade_handler,
7204
                    void *upgrade_handler_cls,
7205
                    size_t num_headers,
7206
                    const struct MHD_NameValueCStr *MHD_RESTRICT headers)
7207
MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
7208
MHD_FN_PAR_IN_SIZE_ (6, 5);
7209
7210
7211
/**
7212
 * Create a action object that can be used for 101 Upgrade
7213
 * responses, for example to implement WebSockets.  After sending the
7214
 * response, control over the data stream is given to the callback (which
7215
 * can then, for example, start some bi-directional communication).
7216
 * The callback will ONLY be called after the response header was successfully
7217
 * passed to the OS; if there are communication errors before, the usual MHD
7218
 * connection error handling code will be performed.
7219
 *
7220
 * At most one action can be created for any request.
7221
 *
7222
 * @param request the request to create action for
7223
 * @param upgrade_hdr_value the value of the "Upgrade:" header, mandatory
7224
                            string
7225
 * @param upgrade_handler function to call with the "upgraded" socket
7226
 * @param upgrade_handler_cls closure for @a upgrade_handler
7227
 * @param num_headers number of elements in the @a headers array,
7228
 *                    must be zero if @a headers is NULL
7229
 * @param headers the optional pointer to the array of the headers (the strings
7230
 *                are copied and does not need to be valid after return from
7231
 *                this function),
7232
 *                can be NULL if @a num_headers is zero
7233
 * @return NULL on error (i.e. invalid arguments, out of memory)
7234
 * @ingroup action
7235
 */
7236
MHD_EXTERN_ const struct MHD_UploadAction *
7237
MHD_upload_action_upgrade (
7238
  struct MHD_Request *MHD_RESTRICT request,
7239
  const char *MHD_RESTRICT upgrade_hdr_value,
7240
  MHD_UpgradeHandler upgrade_handler,
7241
  void *upgrade_handler_cls,
7242
  size_t num_headers,
7243
  const struct MHD_NameValueCStr *MHD_RESTRICT headers)
7244
MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
7245
MHD_FN_PAR_IN_SIZE_ (6, 5);
7246
7247
7248
/**
7249
 * Receive data on the HTTP-Upgraded connection.
7250
 *
7251
 * The function finished if one of the following happens:
7252
 * + ANY amount of data has been received,
7253
 * + timeout reached,
7254
 * + network error occurs
7255
 *
7256
 * @param urh the HTTP-Upgraded handle
7257
 * @param recv_buf_size the size of the @a recv_buf
7258
 * @param recv_buf the buffer to receive the data
7259
 * @param received_size the pointer to variable to get amount of received data
7260
 * @param max_wait_millisec the maximum wait time for the data,
7261
 *                          non-blocking operation if set to zero,
7262
 *                          wait indefinitely if larger or equal to
7263
 *                          #MHD_WAIT_INDEFINITELY,
7264
 *                          the function may return earlier if waiting is
7265
 *                          interrupted or by other reasons
7266
 * @return #MHD_SC_OK if ANY data received (check the @a received_size) or
7267
 *                    remote shut down send side (indicated by @a received_size
7268
 *                    set to zero),
7269
 *         #MHD_SC_UPGRADED_NET_TIMEOUT if NO data received but timeout expired,
7270
 *         #MHD_SC_UPGRADED_NET_CONN_CLOSED if network connection has been
7271
 *                                          closed,
7272
 *         #MHD_SC_UPGRADED_NET_CONN_BROKEN if broken network connection has
7273
 *                                          been detected,
7274
 *         #MHD_SC_UPGRADED_TLS_ERROR if TLS error occurs (only for TLS),
7275
 *         #MHD_SC_UPGRADED_NET_HARD_ERROR if any other network or sockets
7276
 *                                         unrecoverable error occurs,
7277
 *         #MHD_SC_UPGRADED_HANDLE_INVALID if @a urh is invalid,
7278
 *         #MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED if timed wait is not supported
7279
 *                                                by this MHD build or platform
7280
 */
7281
MHD_EXTERN_ enum MHD_StatusCode
7282
MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
7283
                   size_t recv_buf_size,
7284
                   void *MHD_RESTRICT recv_buf,
7285
                   size_t *MHD_RESTRICT received_size,
7286
                   uint_fast64_t max_wait_millisec)
7287
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2)
7288
MHD_FN_PAR_OUT_ (4);
7289
7290
7291
/**
7292
 * Send data on the HTTP-Upgraded connection.
7293
 *
7294
 * The function finished if one of the following happens:
7295
 * + ALL provided data has been sent,
7296
 * + timeout reached,
7297
 * + network error occurs
7298
 *
7299
 * Parameter @a more_data_to_come controls network buffering. When set to
7300
 * #MHD_YES, the OS waits shortly for additional data and tries to use
7301
 * the network more effeciently delaying the last network packet, if it is
7302
 * incomplete, to combine it with the next data provided.
7303
 *
7304
 * @param urh the HTTP-Upgraded handle
7305
 * @param send_buf_size the amount of data in the @a send_buf
7306
 * @param send_buf the buffer with the data to send
7307
 * @param sent_size the pointer to get the amout of sent data
7308
 * @param max_wait_millisec the maximum wait time for the data,
7309
 *                          non-blocking operation if set to zero,
7310
 *                          wait indefinitely if larger or equal to
7311
 *                          #MHD_WAIT_INDEFINITELY
7312
 * @param more_data_to_come set to #MHD_YES if the provided data in
7313
 *                          the @a send_buf is part of a larger data package,
7314
 *                          like an incomplete message or streamed
7315
 *                          (not the final) part of some file, and more data
7316
 *                          expected to be sent soon over the same connection,
7317
 *                          set to #MHD_NO the data in the @a send_buf is
7318
 *                          the complete message or the final part of
7319
 *                          the message (or file) and it should be pushed
7320
 *                          to the network (and to the client) as soon
7321
 *                          as possible
7322
 * @return #MHD_SC_OK if ANY data sent (check the @a sent_size),
7323
 *         #MHD_SC_UPGRADED_NET_TIMEOUT if NO data sent but timeout expired,
7324
 *         #MHD_SC_UPGRADED_NET_CONN_CLOSED if network connection has been
7325
 *                                          closed,
7326
 *         #MHD_SC_UPGRADED_NET_CONN_BROKEN if broken network connection has
7327
 *                                          been detected,
7328
 *         #MHD_SC_UPGRADED_TLS_ERROR if TLS error occurs (only for TLS),
7329
 *         #MHD_SC_UPGRADED_NET_HARD_ERROR if any other network or sockets
7330
 *                                         unrecoverable error occurs,
7331
 *         #MHD_SC_UPGRADED_HANDLE_INVALID if @a urh is invalid,
7332
 *         #MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED if timed wait is not supported
7333
 *                                                by this MHD build or platform
7334
 */
7335
MHD_EXTERN_ enum MHD_StatusCode
7336
MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh,
7337
                   size_t send_buf_size,
7338
                   const void *MHD_RESTRICT send_buf,
7339
                   size_t *MHD_RESTRICT sent_size,
7340
                   uint_fast64_t max_wait_millisec,
7341
                   enum MHD_Bool more_data_to_come)
7342
MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2)
7343
MHD_FN_PAR_OUT_ (4);
7344
7345
7346
/**
7347
 * Close HTTP-Upgraded connection handle.
7348
 *
7349
 * The handle cannot be used after successful return from this function.
7350
 *
7351
 * The function cannot fail if called correctly (the daemon is not destroyed
7352
 * and the upgraded connection has not been closed yet).
7353
 *
7354
 * @param urh the handle to close
7355
 * @return #MHD_SC_OK on success,
7356
 *         error code otherwise
7357
 */
7358
MHD_EXTERN_ enum MHD_StatusCode
7359
MHD_upgraded_close (struct MHD_UpgradedHandle *urh)
7360
MHD_FN_PAR_NONNULL_ (1);
7361
7362
7363
/* ********************** (e) Client auth ********************** */
7364
7365
7366
/**
7367
 * Length of the binary output of the MD5 hash function.
7368
 * @sa #MHD_digest_get_hash_size()
7369
 * @ingroup authentication
7370
 */
7371
0
#define MHD_MD5_DIGEST_SIZE 16
7372
7373
/**
7374
 * Length of the binary output of the SHA-256 hash function.
7375
 * @sa #MHD_digest_get_hash_size()
7376
 * @ingroup authentication
7377
 */
7378
0
#define MHD_SHA256_DIGEST_SIZE 32
7379
7380
/**
7381
 * Length of the binary output of the SHA-512/256 hash function.
7382
 * @warning While this value is the same as the #MHD_SHA256_DIGEST_SIZE,
7383
 *          the calculated digests for SHA-256 and SHA-512/256 are different.
7384
 * @sa #MHD_digest_get_hash_size()
7385
 * @ingroup authentication
7386
 */
7387
#define MHD_SHA512_256_DIGEST_SIZE 32
7388
7389
/**
7390
 * Base type of hash calculation.
7391
 * Used as part of #MHD_DigestAuthAlgo values.
7392
 *
7393
 * @warning Not used directly by MHD API.
7394
 */
7395
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestBaseAlgo
7396
{
7397
  /**
7398
   * Invalid hash algorithm value
7399
   */
7400
  MHD_DIGEST_BASE_ALGO_INVALID = 0
7401
  ,
7402
  /**
7403
   * MD5 hash algorithm.
7404
   * As specified by RFC1321
7405
   */
7406
  MHD_DIGEST_BASE_ALGO_MD5 = (1u << 0)
7407
  ,
7408
  /**
7409
   * SHA-256 hash algorithm.
7410
   * As specified by FIPS PUB 180-4
7411
   */
7412
  MHD_DIGEST_BASE_ALGO_SHA256 = (1u << 1)
7413
  ,
7414
  /**
7415
   * SHA-512/256 hash algorithm.
7416
   * As specified by FIPS PUB 180-4
7417
   */
7418
  MHD_DIGEST_BASE_ALGO_SHA512_256 = (1u << 2)
7419
};
7420
7421
/**
7422
 * The flag indicating non-session algorithm types,
7423
 * like 'MD5', 'SHA-256' or 'SHA-512-256'.
7424
 */
7425
0
#define MHD_DIGEST_AUTH_ALGO_NON_SESSION    (1u << 6)
7426
7427
/**
7428
 * The flag indicating session algorithm types,
7429
 * like 'MD5-sess', 'SHA-256-sess' or 'SHA-512-256-sess'.
7430
 */
7431
0
#define MHD_DIGEST_AUTH_ALGO_SESSION        (1u << 7)
7432
7433
/**
7434
 * Digest algorithm identification
7435
 */
7436
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthAlgo
7437
{
7438
  /**
7439
   * Unknown or wrong algorithm type.
7440
   * Used in struct MHD_AuthDigestInfo to indicate client value that
7441
   * cannot by identified.
7442
   */
7443
  MHD_DIGEST_AUTH_ALGO_INVALID = 0
7444
  ,
7445
  /**
7446
   * The 'MD5' algorithm, non-session version.
7447
   */
7448
  MHD_DIGEST_AUTH_ALGO_MD5 =
7449
    MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO_NON_SESSION
7450
  ,
7451
  /**
7452
   * The 'MD5-sess' algorithm.
7453
   * Not supported by MHD for authentication.
7454
   */
7455
  MHD_DIGEST_AUTH_ALGO_MD5_SESSION =
7456
    MHD_DIGEST_BASE_ALGO_MD5 | MHD_DIGEST_AUTH_ALGO_SESSION
7457
  ,
7458
  /**
7459
   * The 'SHA-256' algorithm, non-session version.
7460
   */
7461
  MHD_DIGEST_AUTH_ALGO_SHA256 =
7462
    MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_NON_SESSION
7463
  ,
7464
  /**
7465
   * The 'SHA-256-sess' algorithm.
7466
   * Not supported by MHD for authentication.
7467
   */
7468
  MHD_DIGEST_AUTH_ALGO_SHA256_SESSION =
7469
    MHD_DIGEST_BASE_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_SESSION
7470
  ,
7471
  /**
7472
   * The 'SHA-512-256' (SHA-512/256) algorithm.
7473
   */
7474
  MHD_DIGEST_AUTH_ALGO_SHA512_256 =
7475
    MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO_NON_SESSION
7476
  ,
7477
  /**
7478
   * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
7479
   * Not supported by MHD for authentication.
7480
   */
7481
  MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION =
7482
    MHD_DIGEST_BASE_ALGO_SHA512_256 | MHD_DIGEST_AUTH_ALGO_SESSION
7483
};
7484
7485
7486
/**
7487
 * Get digest size in bytes for specified algorithm.
7488
 *
7489
 * The size of the digest specifies the size of the userhash, userdigest
7490
 * and other parameters which size depends on used hash algorithm.
7491
 * @param algo the algorithm to check
7492
 * @return the size (in bytes) of the digest (either #MHD_MD5_DIGEST_SIZE or
7493
 *         #MHD_SHA256_DIGEST_SIZE/MHD_SHA512_256_DIGEST_SIZE)
7494
 *         or zero if the input value is not supported or not valid
7495
 * @sa #MHD_digest_auth_calc_userdigest()
7496
 * @sa #MHD_digest_auth_calc_userhash(), #MHD_digest_auth_calc_userhash_hex()
7497
 * @ingroup authentication
7498
 */
7499
MHD_EXTERN_ size_t
7500
MHD_digest_get_hash_size (enum MHD_DigestAuthAlgo algo)
7501
MHD_FN_CONST_;
7502
7503
/**
7504
 * Digest algorithm identification, allow multiple selection.
7505
 *
7506
 * #MHD_DigestAuthAlgo always can be casted to #MHD_DigestAuthMultiAlgo, but
7507
 * not vice versa.
7508
 */
7509
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthMultiAlgo
7510
{
7511
  /**
7512
   * Unknown or wrong algorithm type.
7513
   */
7514
  MHD_DIGEST_AUTH_MULT_ALGO_INVALID = MHD_DIGEST_AUTH_ALGO_INVALID
7515
  ,
7516
  /**
7517
   * The 'MD5' algorithm, non-session version.
7518
   */
7519
  MHD_DIGEST_AUTH_MULT_ALGO_MD5 = MHD_DIGEST_AUTH_ALGO_MD5
7520
  ,
7521
  /**
7522
   * The 'MD5-sess' algorithm.
7523
   * Not supported by MHD for authentication.
7524
   * Reserved value.
7525
   */
7526
  MHD_DIGEST_AUTH_MULT_ALGO_MD5_SESSION = MHD_DIGEST_AUTH_ALGO_MD5_SESSION
7527
  ,
7528
  /**
7529
   * The 'SHA-256' algorithm, non-session version.
7530
   */
7531
  MHD_DIGEST_AUTH_MULT_ALGO_SHA256 = MHD_DIGEST_AUTH_ALGO_SHA256
7532
  ,
7533
  /**
7534
   * The 'SHA-256-sess' algorithm.
7535
   * Not supported by MHD for authentication.
7536
   * Reserved value.
7537
   */
7538
  MHD_DIGEST_AUTH_MULT_ALGO_SHA256_SESSION =
7539
    MHD_DIGEST_AUTH_ALGO_SHA256_SESSION
7540
  ,
7541
  /**
7542
   * The 'SHA-512-256' (SHA-512/256) algorithm, non-session version.
7543
   */
7544
  MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256 = MHD_DIGEST_AUTH_ALGO_SHA512_256
7545
  ,
7546
  /**
7547
   * The 'SHA-512-256-sess' (SHA-512/256 session) algorithm.
7548
   * Not supported by MHD for authentication.
7549
   * Reserved value.
7550
   */
7551
  MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_SESSION =
7552
    MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION
7553
  ,
7554
  /**
7555
   * SHA-256 or SHA-512/256 non-session algorithm, MHD will choose
7556
   * the preferred or the matching one.
7557
   */
7558
  MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_NON_SESSION =
7559
    MHD_DIGEST_AUTH_ALGO_SHA256 | MHD_DIGEST_AUTH_ALGO_SHA512_256
7560
  ,
7561
  /**
7562
   * Any non-session algorithm, MHD will choose the preferred or
7563
   * the matching one.
7564
   */
7565
  MHD_DIGEST_AUTH_MULT_ALGO_ANY_NON_SESSION =
7566
    (0x3F) | MHD_DIGEST_AUTH_ALGO_NON_SESSION
7567
  ,
7568
  /**
7569
   * The SHA-256 or SHA-512/256 session algorithm.
7570
   * Not supported by MHD.
7571
   * Reserved value.
7572
   */
7573
  MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_SESSION =
7574
    MHD_DIGEST_AUTH_ALGO_SHA256_SESSION
7575
    | MHD_DIGEST_AUTH_ALGO_SHA512_256_SESSION
7576
  ,
7577
  /**
7578
   * Any session algorithm.
7579
   * Not supported by MHD.
7580
   * Reserved value.
7581
   */
7582
  MHD_DIGEST_AUTH_MULT_ALGO_ANY_SESSION =
7583
    (0x3F) | MHD_DIGEST_AUTH_ALGO_SESSION
7584
  ,
7585
  /**
7586
   * The MD5 algorithm, session or non-session.
7587
   * Currently supported as non-session only.
7588
   */
7589
  MHD_DIGEST_AUTH_MULT_ALGO_MD5_ANY =
7590
    MHD_DIGEST_AUTH_MULT_ALGO_MD5 | MHD_DIGEST_AUTH_MULT_ALGO_MD5_SESSION
7591
  ,
7592
  /**
7593
   * The SHA-256 algorithm, session or non-session.
7594
   * Currently supported as non-session only.
7595
   */
7596
  MHD_DIGEST_AUTH_MULT_ALGO_SHA256_ANY =
7597
    MHD_DIGEST_AUTH_MULT_ALGO_SHA256
7598
    | MHD_DIGEST_AUTH_MULT_ALGO_SHA256_SESSION
7599
  ,
7600
  /**
7601
   * The SHA-512/256 algorithm, session or non-session.
7602
   * Currently supported as non-session only.
7603
   */
7604
  MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_ANY =
7605
    MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256
7606
    | MHD_DIGEST_AUTH_MULT_ALGO_SHA512_256_SESSION
7607
  ,
7608
  /**
7609
   * The SHA-256 or SHA-512/256 algorithm, session or non-session.
7610
   * Currently supported as non-session only.
7611
   */
7612
  MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_ANY =
7613
    MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_NON_SESSION
7614
    | MHD_DIGEST_AUTH_MULT_ALGO_SHA_ANY_SESSION
7615
  ,
7616
  /**
7617
   * Any algorithm, MHD will choose the preferred or the matching one.
7618
   */
7619
  MHD_DIGEST_AUTH_MULT_ALGO_ANY =
7620
    (0x3F) | MHD_DIGEST_AUTH_ALGO_NON_SESSION | MHD_DIGEST_AUTH_ALGO_SESSION
7621
};
7622
7623
7624
/**
7625
 * Calculate "userhash", return it as binary data.
7626
 *
7627
 * The "userhash" is the hash of the string "username:realm".
7628
 *
7629
 * The "userhash" could be used to avoid sending username in cleartext in Digest
7630
 * Authorization client's header.
7631
 *
7632
 * Userhash is not designed to hide the username in local database or files,
7633
 * as username in cleartext is required for #MHD_digest_auth_check() function
7634
 * to check the response, but it can be used to hide username in HTTP headers.
7635
 *
7636
 * This function could be used when the new username is added to the username
7637
 * database to save the "userhash" alongside with the username (preferably) or
7638
 * when loading list of the usernames to generate the userhash for every loaded
7639
 * username (this will cause delays at the start with the long lists).
7640
 *
7641
 * Once "userhash" is generated it could be used to identify users by clients
7642
 * with "userhash" support.
7643
 * Avoid repetitive usage of this function for the same username/realm
7644
 * combination as it will cause excessive CPU load; save and reuse the result
7645
 * instead.
7646
 *
7647
 * @param algo the algorithm for userhash calculations
7648
 * @param username the username
7649
 * @param realm the realm
7650
 * @param[out] userhash_bin the output buffer for userhash as binary data;
7651
 *                          if this function succeeds, then this buffer has
7652
 *                          #MHD_digest_get_hash_size() bytes of userhash
7653
 *                          upon return
7654
 * @param bin_buf_size the size of the @a userhash_bin buffer, must be
7655
 *                     at least #MHD_digest_get_hash_size() bytes long
7656
 * @return #MHD_SC_OK on success,
7657
 *         #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small,
7658
 *         #MHD_SC_HASH_FAILED if hashing failed,
7659
 *         #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is
7660
 *                                                unknown or unsupported.
7661
 * @sa #MHD_digest_auth_calc_userhash_hex()
7662
 * @ingroup authentication
7663
 */
7664
MHD_EXTERN_ enum MHD_StatusCode
7665
MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo,
7666
                               const char *MHD_RESTRICT username,
7667
                               const char *MHD_RESTRICT realm,
7668
                               size_t bin_buf_size,
7669
                               void *MHD_RESTRICT userhash_bin)
7670
MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2)
7671
MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4);
7672
7673
7674
/**
7675
 * Calculate "userhash", return it as hexadecimal string.
7676
 *
7677
 * The "userhash" is the hash of the string "username:realm".
7678
 *
7679
 * The "userhash" could be used to avoid sending username in cleartext in Digest
7680
 * Authorization client's header.
7681
 *
7682
 * Userhash is not designed to hide the username in local database or files,
7683
 * as username in cleartext is required for #MHD_digest_auth_check() function
7684
 * to check the response, but it can be used to hide username in HTTP headers.
7685
 *
7686
 * This function could be used when the new username is added to the username
7687
 * database to save the "userhash" alongside with the username (preferably) or
7688
 * when loading list of the usernames to generate the userhash for every loaded
7689
 * username (this will cause delays at the start with the long lists).
7690
 *
7691
 * Once "userhash" is generated it could be used to identify users by clients
7692
 * with "userhash" support.
7693
 * Avoid repetitive usage of this function for the same username/realm
7694
 * combination as it will cause excessive CPU load; save and reuse the result
7695
 * instead.
7696
 *
7697
 * @param algo the algorithm for userhash calculations
7698
 * @param username the username
7699
 * @param realm the realm
7700
 * @param hex_buf_size the size of the @a userhash_hex buffer, must be
7701
 *                     at least #MHD_digest_get_hash_size()*2+1 chars long
7702
 * @param[out] userhash_hex the output buffer for userhash as hex string;
7703
 *                          if this function succeeds, then this buffer has
7704
 *                          #MHD_digest_get_hash_size()*2 chars long
7705
 *                          userhash string plus one zero-termination char
7706
 * @return #MHD_SC_OK on success,
7707
 *         #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small,
7708
 *         #MHD_SC_HASH_FAILED if hashing failed,
7709
 *         #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is
7710
 *                                                unknown or unsupported.
7711
 * @sa #MHD_digest_auth_calc_userhash()
7712
 * @ingroup authentication
7713
 */
7714
MHD_EXTERN_ enum MHD_StatusCode
7715
MHD_digest_auth_calc_userhash_hex (
7716
  enum MHD_DigestAuthAlgo algo,
7717
  const char *MHD_RESTRICT username,
7718
  const char *MHD_RESTRICT realm,
7719
  size_t hex_buf_size,
7720
  char userhash_hex[MHD_FN_PAR_DYN_ARR_SIZE_ (hex_buf_size)])
7721
MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2)
7722
MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4);
7723
7724
7725
/**
7726
 * The type of username used by client in Digest Authorization header
7727
 *
7728
 * Values are sorted so simplified checks could be used.
7729
 * For example:
7730
 * * (value <= MHD_DIGEST_AUTH_UNAME_TYPE_INVALID) is true if no valid username
7731
 *   is provided by the client (not used currently)
7732
 * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH) is true if username is
7733
 *   provided in any form
7734
 * * (value >= MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD) is true if username is
7735
 *   provided in clear text (no userhash matching is needed)
7736
 */
7737
enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthUsernameType
7738
{
7739
  /**
7740
   * No username parameter is in Digest Authorization header.
7741
   * Not used currently. Value #MHD_SC_REQ_AUTH_DATA_BROKEN is returned
7742
   * by #MHD_request_get_info_dynamic_sz() if the request has no username.
7743
   */
7744
  MHD_DIGEST_AUTH_UNAME_TYPE_MISSING = 0
7745
  ,
7746
  /**
7747
   * The 'username' parameter is used to specify the username.
7748
   */
7749
  MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD = (1u << 2)
7750
  ,
7751
  /**
7752
   * The username is specified by 'username*' parameter with
7753
   * the extended notation (see RFC 5987, section-3.2.1).
7754
   * The only difference between standard and extended types is
7755
   * the way how username value is encoded in the header.
7756
   */
7757
  MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED = (1u << 3)
7758
  ,
7759
  /**
7760
   * The username provided in form of 'userhash' as
7761
   * specified by RFC 7616, section-3.4.4.
7762
   * @sa #MHD_digest_auth_calc_userhash_hex(), #MHD_digest_auth_calc_userhash()
7763
   */
7764
  MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH = (1u << 1)
7765
  ,
7766
  /**
7767
   * The invalid combination of username parameters are used by client.
7768
   * Either:
7769
   * + both 'username' and 'username*' are used
7770
   * + 'username*' is used with 'userhash=true'
7771
   * + 'username*' used with invalid extended notation
7772
   * + 'username' is not hexadecimal string, while 'userhash' set to 'true'
7773
   * Not used currently. Value #MHD_SC_REQ_AUTH_DATA_BROKEN is returned
7774
   * by #MHD_request_get_info_dynamic_sz() if the request has broken username.
7775
   */
7776
  MHD_DIGEST_AUTH_UNAME_TYPE_INVALID = (1u << 0)
7777
};
7778
7779
/**
7780
 * The QOP ('quality of protection') types.
7781
 */
7782
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthQOP
7783
{
7784
  /**
7785
   * Invalid/unknown QOP.
7786
   * Used in struct MHD_AuthDigestInfo to indicate client value that
7787
   * cannot by identified.
7788
   */
7789
  MHD_DIGEST_AUTH_QOP_INVALID = 0
7790
  ,
7791
  /**
7792
   * No QOP parameter.
7793
   * As described in old RFC 2069 original specification.
7794
   * This mode is not allowed by latest RFCs and should be used only to
7795
   * communicate with clients that do not support more modern modes (with QOP
7796
   * parameter).
7797
   * This mode is less secure than other modes and inefficient.
7798
   */
7799
  MHD_DIGEST_AUTH_QOP_NONE = (1u << 0)
7800
  ,
7801
  /**
7802
   * The 'auth' QOP type.
7803
   */
7804
  MHD_DIGEST_AUTH_QOP_AUTH = (1u << 1)
7805
  ,
7806
  /**
7807
   * The 'auth-int' QOP type.
7808
   * Not supported by MHD for authentication.
7809
   */
7810
  MHD_DIGEST_AUTH_QOP_AUTH_INT = (1u << 2)
7811
};
7812
7813
/**
7814
 * The QOP ('quality of protection') types, multiple selection.
7815
 *
7816
 * #MHD_DigestAuthQOP always can be casted to #MHD_DigestAuthMultiQOP, but
7817
 * not vice versa.
7818
 */
7819
enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_DigestAuthMultiQOP
7820
{
7821
  /**
7822
   * Invalid/unknown QOP.
7823
   */
7824
  MHD_DIGEST_AUTH_MULT_QOP_INVALID = MHD_DIGEST_AUTH_QOP_INVALID
7825
  ,
7826
  /**
7827
   * No QOP parameter.
7828
   * As described in old RFC 2069 original specification.
7829
   * This mode is not allowed by latest RFCs and should be used only to
7830
   * communicate with clients that do not support more modern modes (with QOP
7831
   * parameter).
7832
   * This mode is less secure than other modes and inefficient.
7833
   */
7834
  MHD_DIGEST_AUTH_MULT_QOP_NONE = MHD_DIGEST_AUTH_QOP_NONE
7835
  ,
7836
  /**
7837
   * The 'auth' QOP type.
7838
   */
7839
  MHD_DIGEST_AUTH_MULT_QOP_AUTH = MHD_DIGEST_AUTH_QOP_AUTH
7840
  ,
7841
  /**
7842
   * The 'auth-int' QOP type.
7843
   * Not supported by MHD.
7844
   * Reserved value.
7845
   */
7846
  MHD_DIGEST_AUTH_MULT_QOP_AUTH_INT = MHD_DIGEST_AUTH_QOP_AUTH_INT
7847
  ,
7848
  /**
7849
   * The 'auth' QOP type OR the old RFC2069 (no QOP) type.
7850
   * In other words: any types except 'auth-int'.
7851
   * RFC2069-compatible mode is allowed, thus this value should be used only
7852
   * when it is really necessary.
7853
   */
7854
  MHD_DIGEST_AUTH_MULT_QOP_ANY_NON_INT =
7855
    MHD_DIGEST_AUTH_QOP_NONE | MHD_DIGEST_AUTH_QOP_AUTH
7856
  ,
7857
  /**
7858
   * Any 'auth' QOP type ('auth' or 'auth-int').
7859
   * Currently supported as 'auth' QOP type only.
7860
   */
7861
  MHD_DIGEST_AUTH_MULT_QOP_AUTH_ANY =
7862
    MHD_DIGEST_AUTH_QOP_AUTH | MHD_DIGEST_AUTH_QOP_AUTH_INT
7863
};
7864
7865
/**
7866
 * The type of 'nc' (nonce count) value provided in the request
7867
 */
7868
enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthNC
7869
{
7870
  /**
7871
   * Readable hexdecimal non-zero number.
7872
   * The decoded value is placed in @a nc member of struct MHD_AuthDigestInfo
7873
   */
7874
  MHD_DIGEST_AUTH_NC_NUMBER = 1
7875
  ,
7876
  /**
7877
   * Readable zero number.
7878
   * Compliant clients should not use such values.
7879
   * Can be treated as invalid request.
7880
   */
7881
  MHD_DIGEST_AUTH_NC_ZERO = 2
7882
  ,
7883
  /**
7884
   * 'nc' value is not provided by the client.
7885
   * Unless old RFC 2069 mode is allowed, this should be treated as invalid
7886
   * request.
7887
   */
7888
  MHD_DIGEST_AUTH_NC_NONE = 3
7889
  ,
7890
  /**
7891
   * 'nc' value is too long to be decoded.
7892
   * Compliant clients should not use such values.
7893
   * Can be treated as invalid request.
7894
   */
7895
  MHD_DIGEST_AUTH_NC_TOO_LONG = 4
7896
  ,
7897
  /**
7898
   * 'nc' value is too large for uint32_t.
7899
   * Compliant clients should not use such values.
7900
   * Can be treated as request with a stale nonce or as invalid request.
7901
   */
7902
  MHD_DIGEST_AUTH_NC_TOO_LARGE = 5
7903
};
7904
7905
7906
/**
7907
 * Information from Digest Authorization client's header.
7908
 *
7909
 * @see #MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO
7910
 */
7911
struct MHD_AuthDigestInfo
7912
{
7913
  /**
7914
   * The algorithm as defined by client.
7915
   * Set automatically to MD5 if not specified by client.
7916
   */
7917
  enum MHD_DigestAuthAlgo algo;
7918
7919
  /**
7920
   * The type of username used by client.
7921
   */
7922
  enum MHD_DigestAuthUsernameType uname_type;
7923
7924
  /**
7925
   * The username string.
7926
   * Used only if username type is standard or extended, always NULL otherwise.
7927
   * If extended notation is used, this string is pct-decoded string
7928
   * with charset and language tag removed (i.e. it is original username
7929
   * extracted from the extended notation).
7930
   * When userhash is used by the client, the string pointer is NULL and
7931
   * @a userhash_hex and @a userhash_bin are set.
7932
   */
7933
  struct MHD_StringNullable username;
7934
7935
  /**
7936
   * The userhash string.
7937
   * Valid only if username type is userhash.
7938
   * This is unqoted string without decoding of the hexadecimal
7939
   * digits (as provided by the client).
7940
   * @sa #MHD_digest_auth_calc_userhash_hex()
7941
   */
7942
  struct MHD_StringNullable userhash_hex;
7943
7944
  /**
7945
   * The userhash decoded to binary form.
7946
   * Used only if username type is userhash, always NULL otherwise.
7947
   * When not NULL, this points to binary sequence @a userhash_bin_size bytes
7948
   * long.
7949
   * The valid size should be #MHD_digest_get_hash_size() bytes.
7950
   * @warning This is a binary data, no zero termination.
7951
   * @warning To avoid buffer overruns, always check the size of the data before
7952
   *          use, because @a userhash_bin can point even to zero-sized
7953
   *          data.
7954
   * @sa #MHD_digest_auth_calc_userhash()
7955
   */
7956
  const uint8_t *userhash_bin;
7957
7958
  /**
7959
   * The size of the data pointed by @a userhash_bin.
7960
   * Always zero when @a userhash_bin is NULL.
7961
   */
7962
  size_t userhash_bin_size;
7963
7964
  /**
7965
   * The 'opaque' parameter value, as specified by client.
7966
   * If not specified by client then string pointer is NULL.
7967
   */
7968
  struct MHD_StringNullable opaque;
7969
7970
  /**
7971
   * The 'realm' parameter value, as specified by client.
7972
   * If not specified by client then string pointer is NULL.
7973
   */
7974
  struct MHD_StringNullable realm;
7975
7976
  /**
7977
   * The 'qop' parameter value.
7978
   */
7979
  enum MHD_DigestAuthQOP qop;
7980
7981
  /**
7982
   * The length of the 'cnonce' parameter value, including possible
7983
   * backslash-escape characters.
7984
   * 'cnonce' is used in hash calculation, which is CPU-intensive procedure.
7985
   * An application may want to reject too large cnonces to limit the CPU load.
7986
   * A few kilobytes is a reasonable limit, typically cnonce is just 32-160
7987
   * characters long.
7988
   */
7989
  size_t cnonce_len;
7990
7991
  /**
7992
   * The type of 'nc' (nonce count) value provided in the request.
7993
   */
7994
  enum MHD_DigestAuthNC nc_type;
7995
7996
  /**
7997
   * The nc (nonce count) parameter value.
7998
   * Can be used by application to limit the number of nonce re-uses. If @a nc
7999
   * is higher than application wants to allow, then "auth required" response
8000
   * with 'stale=true' could be used to force client to retry with the fresh
8001
   * 'nonce'.
8002
   * Set to zero when @a nc_type is not set to #MHD_DIGEST_AUTH_NC_NUMBER.
8003
   */
8004
  uint_fast32_t nc;
8005
};
8006
8007
/**
8008
 * The result of digest authentication of the client.
8009
 *
8010
 * All error values are zero or negative.
8011
 */
8012
enum MHD_FIXED_ENUM_MHD_SET_ MHD_DigestAuthResult
8013
{
8014
  /**
8015
   * Authentication OK.
8016
   */
8017
  MHD_DAUTH_OK = 1
8018
  ,
8019
  /**
8020
   * General error, like "out of memory".
8021
   * Authentication may be valid, but cannot be checked.
8022
   */
8023
  MHD_DAUTH_ERROR = 0
8024
  ,
8025
  /**
8026
   * No "Authorization" header for Digest Authentication.
8027
   */
8028
  MHD_DAUTH_HEADER_MISSING = -1
8029
  ,
8030
  /**
8031
   * Wrong format of the header.
8032
   * Also returned if required parameters in Authorization header are missing
8033
   * or broken (in invalid format).
8034
   */
8035
  MHD_DAUTH_HEADER_BROKEN = -9
8036
  ,
8037
  /**
8038
   * Unsupported algorithm.
8039
   */
8040
  MHD_DAUTH_UNSUPPORTED_ALGO = -10
8041
  ,
8042
  /**
8043
   * Unsupported 'qop'.
8044
   */
8045
  MHD_DAUTH_UNSUPPORTED_QOP = -11
8046
  ,
8047
  /**
8048
   * Incorrect userdigest size.
8049
   */
8050
  MHD_DAUTH_INVALID_USERDIGEST_SIZE = -15
8051
  ,
8052
  /**
8053
   * Wrong 'username'.
8054
   */
8055
  MHD_DAUTH_WRONG_USERNAME = -17
8056
  ,
8057
  /**
8058
   * Wrong 'realm'.
8059
   */
8060
  MHD_DAUTH_WRONG_REALM = -18
8061
  ,
8062
  /**
8063
   * Wrong 'URI' (or URI parameters).
8064
   */
8065
  MHD_DAUTH_WRONG_URI = -19
8066
  ,
8067
  /**
8068
   * Wrong 'qop'.
8069
   */
8070
  MHD_DAUTH_WRONG_QOP = -20
8071
  ,
8072
  /**
8073
   * Wrong 'algorithm'.
8074
   */
8075
  MHD_DAUTH_WRONG_ALGO = -21
8076
  ,
8077
  /**
8078
   * Too large (>64 KiB) Authorization parameter value.
8079
   */
8080
  MHD_DAUTH_TOO_LARGE = -22
8081
  ,
8082
  /* The different form of naming is intentionally used for the results below,
8083
   * as they are more important */
8084
8085
  /**
8086
   * The 'nonce' is too old. Suggest the client to retry with the same
8087
   * username and password to get the fresh 'nonce'.
8088
   * The validity of the 'nonce' may be not checked.
8089
   */
8090
  MHD_DAUTH_NONCE_STALE = -25
8091
  ,
8092
  /**
8093
   * The 'nonce' is wrong. May indicate an attack attempt.
8094
   */
8095
  MHD_DAUTH_NONCE_WRONG = -33
8096
  ,
8097
  /**
8098
   * The 'response' is wrong. May indicate a wrong password used or
8099
   * an attack attempt.
8100
   */
8101
  MHD_DAUTH_RESPONSE_WRONG = -34
8102
};
8103
8104
8105
/**
8106
 * Authenticates the authorization header sent by the client.
8107
 *
8108
 * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
8109
 * @a mqop and the client uses this mode, then server generated nonces are
8110
 * used as one-time nonces because nonce-count is not supported in this old RFC.
8111
 * Communication in this mode is very inefficient, especially if the client
8112
 * requests several resources one-by-one as for every request a new nonce must
8113
 * be generated and client repeats all requests twice (first time to get a new
8114
 * nonce and second time to perform an authorised request).
8115
 *
8116
 * @param request the request
8117
 * @param realm the realm for authorization of the client
8118
 * @param username the username to be authenticated, must be in clear text
8119
 *                 even if userhash is used by the client
8120
 * @param password the password matching the @a username (and the @a realm)
8121
 * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
8122
 *               exceeds the specified value then MHD_DAUTH_NONCE_STALE is
8123
 *               returned;
8124
 *               if zero is specified then daemon default value is used.
8125
 * @param mqop the QOP to use
8126
 * @param malgo digest algorithms allowed to use, fail if algorithm used
8127
 *               by the client is not allowed by this parameter
8128
 * @return #MHD_DAUTH_OK if authenticated,
8129
 *         the error code otherwise
8130
 * @ingroup authentication
8131
 */
8132
MHD_EXTERN_ enum MHD_DigestAuthResult
8133
MHD_digest_auth_check (struct MHD_Request *MHD_RESTRICT request,
8134
                       const char *MHD_RESTRICT realm,
8135
                       const char *MHD_RESTRICT username,
8136
                       const char *MHD_RESTRICT password,
8137
                       uint_fast32_t max_nc,
8138
                       enum MHD_DigestAuthMultiQOP mqop,
8139
                       enum MHD_DigestAuthMultiAlgo malgo)
8140
MHD_FN_PAR_NONNULL_ALL_
8141
MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4);
8142
8143
8144
/**
8145
 * Calculate userdigest, return it as a binary data.
8146
 *
8147
 * The "userdigest" is the hash of the "username:realm:password" string.
8148
 *
8149
 * The "userdigest" can be used to avoid storing the password in clear text
8150
 * in database/files
8151
 *
8152
 * This function is designed to improve security of stored credentials,
8153
 * the "userdigest" does not improve security of the authentication process.
8154
 *
8155
 * The results can be used to store username & userdigest pairs instead of
8156
 * username & password pairs. To further improve security, application may
8157
 * store username & userhash & userdigest triplets.
8158
 *
8159
 * @param algo the digest algorithm
8160
 * @param username the username
8161
 * @param realm the realm
8162
 * @param password the password
8163
 * @param bin_buf_size the size of the @a userdigest_bin buffer, must be
8164
 *                     at least #MHD_digest_get_hash_size() bytes long
8165
 * @param[out] userdigest_bin the output buffer for userdigest;
8166
 *                            if this function succeeds, then this buffer has
8167
 *                            #MHD_digest_get_hash_size() bytes of
8168
 *                            userdigest upon return
8169
 * @return #MHD_SC_OK on success,
8170
 *         #MHD_SC_OUT_BUFF_TOO_SMALL if @a bin_buf_size is too small,
8171
 *         #MHD_SC_HASH_FAILED if hashing failed,
8172
 *         #MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED if requested @a algo is
8173
 *                                                unknown or unsupported.
8174
 * @sa #MHD_digest_auth_check_digest()
8175
 * @ingroup authentication
8176
 */
8177
MHD_EXTERN_ enum MHD_StatusCode
8178
MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo,
8179
                                 const char *MHD_RESTRICT username,
8180
                                 const char *MHD_RESTRICT realm,
8181
                                 const char *MHD_RESTRICT password,
8182
                                 size_t bin_buf_size,
8183
                                 void *MHD_RESTRICT userdigest_bin)
8184
MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_
8185
MHD_FN_PAR_CSTR_ (2)
8186
MHD_FN_PAR_CSTR_ (3)
8187
MHD_FN_PAR_CSTR_ (4)
8188
MHD_FN_PAR_OUT_SIZE_ (6, 5);
8189
8190
8191
/**
8192
 * Authenticates the authorization header sent by the client by using
8193
 * hash of "username:realm:password".
8194
 *
8195
 * If RFC2069 mode is allowed by setting bit #MHD_DIGEST_AUTH_QOP_NONE in
8196
 * @a mqop and the client uses this mode, then server generated nonces are
8197
 * used as one-time nonces because nonce-count is not supported in this old RFC.
8198
 * Communication in this mode is very inefficient, especially if the client
8199
 * requests several resources one-by-one as for every request a new nonce must
8200
 * be generated and client repeats all requests twice (first time to get a new
8201
 * nonce and second time to perform an authorised request).
8202
 *
8203
 * @param request the request
8204
 * @param realm the realm for authorization of the client
8205
 * @param username the username to be authenticated, must be in clear text
8206
 *                 even if userhash is used by the client
8207
 * @param userdigest_size the size of the @a userdigest in bytes, must match the
8208
 *                        hashing algorithm (see #MHD_MD5_DIGEST_SIZE,
8209
 *                        #MHD_SHA256_DIGEST_SIZE, #MHD_SHA512_256_DIGEST_SIZE,
8210
 *                        #MHD_digest_get_hash_size())
8211
 * @param userdigest the precalculated binary hash of the string
8212
 *                   "username:realm:password",
8213
 *                   see #MHD_digest_auth_calc_userdigest()
8214
 * @param max_nc the maximum allowed nc (Nonce Count) value, if client's nc
8215
 *               exceeds the specified value then MHD_DAUTH_NONCE_STALE is
8216
 *               returned;
8217
 *               if zero is specified then daemon default value is used.
8218
 * @param mqop the QOP to use
8219
 * @param malgo digest algorithms allowed to use, fail if algorithm used
8220
 *              by the client is not allowed by this parameter;
8221
 *              more than one base algorithms (MD5, SHA-256, SHA-512/256)
8222
 *              cannot be used at the same time for this function
8223
 *              as @a userdigest must match specified algorithm
8224
 * @return #MHD_DAUTH_OK if authenticated,
8225
 *         the error code otherwise
8226
 * @sa #MHD_digest_auth_calc_userdigest()
8227
 * @ingroup authentication
8228
 */
8229
MHD_EXTERN_ enum MHD_DigestAuthResult
8230
MHD_digest_auth_check_digest (struct MHD_Request *MHD_RESTRICT request,
8231
                              const char *MHD_RESTRICT realm,
8232
                              const char *MHD_RESTRICT username,
8233
                              size_t userdigest_size,
8234
                              const void *MHD_RESTRICT userdigest,
8235
                              uint_fast32_t max_nc,
8236
                              enum MHD_DigestAuthMultiQOP mqop,
8237
                              enum MHD_DigestAuthMultiAlgo malgo)
8238
MHD_FN_PAR_NONNULL_ALL_
8239
MHD_FN_PAR_CSTR_ (2)
8240
MHD_FN_PAR_CSTR_ (3)
8241
MHD_FN_PAR_IN_SIZE_ (5, 4);
8242
8243
8244
/**
8245
 * Add Digest Authentication "challenge" to the response.
8246
 *
8247
 * The response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8248
 *
8249
 * If @a mqop allows both RFC 2069 (#MHD_DIGEST_AUTH_QOP_NONE) and other QOP
8250
 * values, then the "challenge" is formed like if MHD_DIGEST_AUTH_QOP_NONE bit
8251
 * was not set, because such "challenge" should be backward-compatible with
8252
 * RFC 2069.
8253
 *
8254
 * If @a mqop allows only MHD_DIGEST_AUTH_MULT_QOP_NONE, then the response is
8255
 * formed in strict accordance with RFC 2069 (no 'qop', no 'userhash', no
8256
 * 'charset'). For better compatibility with clients, it is recommended (but
8257
 * not required) to set @a domain to NULL in this mode.
8258
 *
8259
 * New nonces are generated each time when the resulting response is used.
8260
 *
8261
 * See RFC 7616, section 3.3 for details.
8262
 *
8263
 * @param response the response to update; should contain the "access denied"
8264
 *                 body;
8265
 *                 note: this function sets the "WWW Authenticate" header and
8266
 *                 the caller should not set this header;
8267
 *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8268
 *                 code;
8269
 *                 the NULL is tolerated (the result is
8270
 *                 #MHD_SC_RESP_POINTER_NULL)
8271
 * @param realm the realm presented to the client
8272
 * @param opaque the string for opaque value, can be NULL, but NULL is
8273
 *               not recommended for better compatibility with clients;
8274
 *               the recommended format is hex or Base64 encoded string
8275
 * @param domain the optional space-separated list of URIs for which the
8276
 *               same authorisation could be used, URIs can be in form
8277
 *               "path-absolute" (the path for the same host with initial slash)
8278
 *               or in form "absolute-URI" (the full path with protocol), in
8279
 *               any case client may assume that URI is in the same "protection
8280
 *               space" if it starts with any of values specified here;
8281
 *               could be NULL (clients typically assume that the same
8282
 *               credentials could be used for any URI on the same host);
8283
 *               this list provides information for the client only and does
8284
 *               not actually restrict anything on the server side
8285
 * @param indicate_stale if set to #MHD_YES then indication of stale nonce used
8286
 *                       in the client's request is indicated by adding
8287
 *                       'stale=true' to the authentication header, this
8288
 *                       instructs the client to retry immediately with the new
8289
 *                       nonce and the same credentials, without asking user
8290
 *                       for the new password
8291
 * @param mqop the QOP to use
8292
 * @param malgo digest algorithm to use; if several algorithms are allowed
8293
 *              then one challenge for each allowed algorithm is added
8294
 * @param userhash_support if set to #MHD_YES then support of userhash is
8295
 *                         indicated, allowing client to provide
8296
 *                         hash("username:realm") instead of the username in
8297
 *                         clear text;
8298
 *                         note that clients are allowed to provide the username
8299
 *                         in cleartext even if this parameter set to non-zero;
8300
 *                         when userhash is used, application must be ready to
8301
 *                         identify users by provided userhash value instead of
8302
 *                         username; see #MHD_digest_auth_calc_userhash() and
8303
 *                         #MHD_digest_auth_calc_userhash_hex()
8304
 * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is
8305
 *                    added, indicating for the client that UTF-8 encoding for
8306
 *                    the username is preferred
8307
 * @return #MHD_SC_OK if succeed,
8308
 *         #MHD_SC_TOO_LATE if the response has been already "frozen" (used to
8309
 *         create an action),
8310
 *         #MHD_SC_RESP_HEADERS_CONFLICT if Digest Authentication "challenge"
8311
 *         has been added already,
8312
 *         #MHD_SC_RESP_POINTER_NULL if @a response is NULL,
8313
 *         #MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE is response status code is wrong,
8314
 *         #MHD_SC_RESP_HEADER_VALUE_INVALID if @a realm, @a opaque or @a domain
8315
 *         have wrong characters or zero length (for @a realm),
8316
 *         #MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED if memory allocation failed,
8317
 *         or other error code if failed
8318
 * @ingroup authentication
8319
 */
8320
MHD_EXTERN_ enum MHD_StatusCode
8321
MHD_response_add_auth_digest_challenge (
8322
  struct MHD_Response *MHD_RESTRICT response,
8323
  const char *MHD_RESTRICT realm,
8324
  const char *MHD_RESTRICT opaque,
8325
  const char *MHD_RESTRICT domain,
8326
  enum MHD_Bool indicate_stale,
8327
  enum MHD_DigestAuthMultiQOP mqop,
8328
  enum MHD_DigestAuthMultiAlgo malgo,
8329
  enum MHD_Bool userhash_support,
8330
  enum MHD_Bool prefer_utf8)
8331
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
8332
MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4);
8333
8334
8335
/* Application may define MHD_NO_STATIC_INLINE macro before including
8336
   libmicrohttpd headers to disable static inline functions in the headers. */
8337
#ifndef MHD_NO_STATIC_INLINE
8338
8339
/**
8340
 * Create action to reply with Digest Authentication "challenge".
8341
 *
8342
 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8343
 *
8344
 * See RFC 7616, section 3.3 for details.
8345
 *
8346
 * @param request the request to create the action for
8347
 * @param realm the realm presented to the client
8348
 * @param opaque the string for opaque value, can be NULL, but NULL is
8349
 *               not recommended for better compatibility with clients;
8350
 *               the recommended format is hex or Base64 encoded string
8351
 * @param domain the optional space-separated list of URIs for which the
8352
 *               same authorisation could be used, URIs can be in form
8353
 *               "path-absolute" (the path for the same host with initial slash)
8354
 *               or in form "absolute-URI" (the full path with protocol), in
8355
 *               any case client may assume that URI is in the same "protection
8356
 *               space" if it starts with any of values specified here;
8357
 *               could be NULL (clients typically assume that the same
8358
 *               credentials could be used for any URI on the same host);
8359
 *               this list provides information for the client only and does
8360
 *               not actually restrict anything on the server side
8361
 * @param indicate_stale if set to #MHD_YES then indication of stale nonce used
8362
 *                       in the client's request is indicated by adding
8363
 *                       'stale=true' to the authentication header, this
8364
 *                       instructs the client to retry immediately with the new
8365
 *                       nonce and the same credentials, without asking user
8366
 *                       for the new password
8367
 * @param mqop the QOP to use
8368
 * @param malgo digest algorithm to use; if several algorithms are allowed
8369
 *              then one challenge for each allowed algorithm is added
8370
 * @param userhash_support if set to #MHD_YES then support of userhash is
8371
 *                         indicated, allowing client to provide
8372
 *                         hash("username:realm") instead of the username in
8373
 *                         clear text;
8374
 *                         note that clients are allowed to provide the username
8375
 *                         in cleartext even if this parameter set to non-zero;
8376
 *                         when userhash is used, application must be ready to
8377
 *                         identify users by provided userhash value instead of
8378
 *                         username; see #MHD_digest_auth_calc_userhash() and
8379
 *                         #MHD_digest_auth_calc_userhash_hex()
8380
 * @param prefer_utf8 if not set to #MHD_NO, parameter 'charset=UTF-8' is
8381
 *                    added, indicating for the client that UTF-8 encoding for
8382
 *                    the username is preferred
8383
 * @param response the response to update; should contain the "access denied"
8384
 *                 body;
8385
 *                 note: this function sets the "WWW Authenticate" header and
8386
 *                 the caller should not set this header;
8387
 *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8388
 *                 code;
8389
 *                 the NULL is tolerated (the result is
8390
 *                 #MHD_SC_RESP_POINTER_NULL)
8391
 * @param abort_if_failed if set to #MHD_NO the response will be used even if
8392
 *                        failed to add Basic Authentication "challenge",
8393
 *                        if not set to #MHD_NO the request will be aborted
8394
 *                        if the "challenge" could not be added.
8395
 * @return pointer to the action, the action must be consumed
8396
 *         otherwise response object may leak;
8397
 *         NULL if failed or if any action has been already created for
8398
 *         the @a request;
8399
 *         when failed the response object is consumed and need not
8400
 *         to be "destroyed"
8401
 * @ingroup authentication
8402
 */
8403
MHD_STATIC_INLINE_
8404
MHD_FN_PAR_NONNULL_ (1)
8405
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
8406
const struct MHD_Action *
8407
MHD_action_digest_auth_challenge (struct MHD_Request *MHD_RESTRICT request,
8408
                                  const char *MHD_RESTRICT realm,
8409
                                  const char *MHD_RESTRICT opaque,
8410
                                  const char *MHD_RESTRICT domain,
8411
                                  enum MHD_Bool indicate_stale,
8412
                                  enum MHD_DigestAuthMultiQOP mqop,
8413
                                  enum MHD_DigestAuthMultiAlgo malgo,
8414
                                  enum MHD_Bool userhash_support,
8415
                                  enum MHD_Bool prefer_utf8,
8416
                                  struct MHD_Response *MHD_RESTRICT response,
8417
                                  enum MHD_Bool abort_if_failed)
8418
0
{
8419
0
  if ((MHD_SC_OK !=
8420
0
       MHD_response_add_auth_digest_challenge (response, realm, opaque, domain,
8421
0
                                               indicate_stale, mqop, malgo,
8422
0
                                               userhash_support, prefer_utf8))
8423
0
      && (MHD_NO != abort_if_failed))
8424
0
  {
8425
0
    MHD_response_destroy (response);
8426
0
    return MHD_action_abort_request (request);
8427
0
  }
8428
0
  return MHD_action_from_response (request, response);
8429
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: connection_helper.cpp:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: daemon_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: request_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_destroy.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_process_states.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_process_request.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_process_reply.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_comm.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_conn.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_in.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_out.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_conn_streams.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_req_fields.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_app_cb.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_reply_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: post_parser_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_auth_digest.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: auth_digest.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: upgrade_proc.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: conn_tls_check.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: tls_gnu_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: mhd_panic.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: http_status_str.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: daemon_logger.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: extr_events_funcs.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: conn_timeout.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: request_get_value.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: respond_with_error.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_from.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_add_header.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_settings.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_req_get_items.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: request_auth_get.c:MHD_action_digest_auth_challenge(MHD_Request*, char const*, char const*, char const*, MHD_Bool, MHD_DigestAuthMultiQOP, MHD_DigestAuthMultiAlgo, MHD_Bool, MHD_Bool, MHD_Response*, MHD_Bool)
8430
8431
8432
MHD_STATIC_INLINE_END_
8433
8434
/**
8435
 * Create action to reply with Digest Authentication "challenge".
8436
 *
8437
 * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8438
 *
8439
 * If the @a r response object cannot be extended with the "challenge",
8440
 * the @a r response is used to reply without the "challenge".
8441
 *
8442
 * @param rq the request to create the action for
8443
 * @param l the realm presented to the client
8444
 * @param o the string for opaque value, can be NULL, but NULL is
8445
 *          not recommended for better compatibility with clients;
8446
 *          the recommended format is hex or Base64 encoded string
8447
 * @param d the optional space-separated list of URIs for which the
8448
 *          same authorisation could be used, URIs can be in form
8449
 *          "path-absolute" (the path for the same host with initial slash)
8450
 *          or in form "absolute-URI" (the full path with protocol), in
8451
 *          any case client may assume that URI is in the same "protection
8452
 *          space" if it starts with any of values specified here;
8453
 *          could be NULL (clients typically assume that the same
8454
 *          credentials could be used for any URI on the same host);
8455
 *          this list provides information for the client only and does
8456
 *          not actually restrict anything on the server side
8457
 * @param s if set to #MHD_YES then indication of stale nonce used
8458
 *          in the client's request is indicated by adding
8459
 *          'stale=true' to the authentication header, this
8460
 *          instructs the client to retry immediately with the new
8461
 *          nonce and the same credentials, without asking user
8462
 *          for the new password
8463
 * @param q the QOP to use
8464
 * @param a digest algorithm to use; if several algorithms are allowed
8465
 *          then one challenge for each allowed algorithm is added
8466
 * @param h if set to #MHD_YES then support of userhash is
8467
 *          indicated, allowing client to provide
8468
 *          hash("username:realm") instead of the username in
8469
 *          clear text;
8470
 *          note that clients are allowed to provide the username
8471
 *          in cleartext even if this parameter set to non-zero;
8472
 *          when userhash is used, application must be ready to
8473
 *          identify users by provided userhash value instead of
8474
 *          username; see #MHD_digest_auth_calc_userhash() and
8475
 *          #MHD_digest_auth_calc_userhash_hex()
8476
 * @param u if not set to #MHD_NO, parameter 'charset=UTF-8' is
8477
 *          added, indicating for the client that UTF-8 encoding for
8478
 *          the username is preferred
8479
 * @param r the response to update; should contain the "access denied"
8480
 *          body;
8481
 *          note: this function sets the "WWW Authenticate" header and
8482
 *          the caller should not set this header;
8483
 *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8484
 *          code;
8485
 *          the NULL is tolerated (the result is
8486
 *          #MHD_SC_RESP_POINTER_NULL)
8487
 * @return pointer to the action, the action must be consumed
8488
 *         otherwise response object may leak;
8489
 *         NULL if failed or if any action has been already created for
8490
 *         the @a rq request;
8491
 *         when failed the response object is consumed and need not
8492
 *         to be "destroyed"
8493
 * @ingroup authentication
8494
 */
8495
#  define MHD_action_digest_auth_challenge_p(rq, l, o, d, s, q, a, h, u, r) \
8496
          MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \
8497
                                            (a),(h),(u),(r),MHD_NO)
8498
8499
8500
/**
8501
 * Create action to reply with Digest Authentication "challenge".
8502
 *
8503
 * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8504
 *
8505
 * If the @a r response object cannot be extended with the "challenge",
8506
 * the @a r response is aborted.
8507
 *
8508
 * @param rq the request to create the action for
8509
 * @param l the realm presented to the client
8510
 * @param o the string for opaque value, can be NULL, but NULL is
8511
 *          not recommended for better compatibility with clients;
8512
 *          the recommended format is hex or Base64 encoded string
8513
 * @param d the optional space-separated list of URIs for which the
8514
 *          same authorisation could be used, URIs can be in form
8515
 *          "path-absolute" (the path for the same host with initial slash)
8516
 *          or in form "absolute-URI" (the full path with protocol), in
8517
 *          any case client may assume that URI is in the same "protection
8518
 *          space" if it starts with any of values specified here;
8519
 *          could be NULL (clients typically assume that the same
8520
 *          credentials could be used for any URI on the same host);
8521
 *          this list provides information for the client only and does
8522
 *          not actually restrict anything on the server side
8523
 * @param s if set to #MHD_YES then indication of stale nonce used
8524
 *          in the client's request is indicated by adding
8525
 *          'stale=true' to the authentication header, this
8526
 *          instructs the client to retry immediately with the new
8527
 *          nonce and the same credentials, without asking user
8528
 *          for the new password
8529
 * @param q the QOP to use
8530
 * @param a digest algorithm to use; if several algorithms are allowed
8531
 *          then one challenge for each allowed algorithm is added
8532
 * @param h if set to #MHD_YES then support of userhash is
8533
 *          indicated, allowing client to provide
8534
 *          hash("username:realm") instead of the username in
8535
 *          clear text;
8536
 *          note that clients are allowed to provide the username
8537
 *          in cleartext even if this parameter set to non-zero;
8538
 *          when userhash is used, application must be ready to
8539
 *          identify users by provided userhash value instead of
8540
 *          username; see #MHD_digest_auth_calc_userhash() and
8541
 *          #MHD_digest_auth_calc_userhash_hex()
8542
 * @param u if not set to #MHD_NO, parameter 'charset=UTF-8' is
8543
 *          added, indicating for the client that UTF-8 encoding for
8544
 *          the username is preferred
8545
 * @param r the response to update; should contain the "access denied"
8546
 *          body;
8547
 *          note: this function sets the "WWW Authenticate" header and
8548
 *          the caller should not set this header;
8549
 *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8550
 *          code;
8551
 *          the NULL is tolerated (the result is
8552
 *          #MHD_SC_RESP_POINTER_NULL)
8553
 * @return pointer to the action, the action must be consumed
8554
 *         otherwise response object may leak;
8555
 *         NULL if failed or if any action has been already created for
8556
 *         the @a rq request;
8557
 *         when failed the response object is consumed and need not
8558
 *         to be "destroyed"
8559
 * @ingroup authentication
8560
 */
8561
#  define MHD_action_digest_auth_challenge_a(rq, l, o, d, s, q, a, h, u, r) \
8562
          MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \
8563
                                            (a),(h),(u),(r),MHD_YES)
8564
8565
#endif /* ! MHD_NO_STATIC_INLINE */
8566
8567
8568
/**
8569
 * Add Basic Authentication "challenge" to the response.
8570
 *
8571
 * The response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8572
 *
8573
 * If access to any resource should be limited to specific users, authenticated
8574
 * by Basic Authentication mechanism, and the request for this resource does not
8575
 * have Basic Authentication information (see #MHD_AuthBasicCreds), then response
8576
 * with Basic Authentication "challenge" should be sent. This works as
8577
 * an indication that Basic Authentication should be used for the access.
8578
 *
8579
 * See RFC 7617, section-2 for details.
8580
 *
8581
 * @param response the reply to send; should contain the "access denied"
8582
 *                 body;
8583
 *                 note: this function sets the "WWW Authenticate" header and
8584
 *                 the caller should not set this header;
8585
 *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8586
 *                 code;
8587
 *                 the NULL is tolerated (the result is
8588
 *                 #MHD_SC_RESP_POINTER_NULL)
8589
 * @param realm the realm presented to the client
8590
 * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
8591
 *                    be added, indicating for client that UTF-8 encoding
8592
 *                    is preferred
8593
 * @return #MHD_SC_OK if succeed,
8594
 *         #MHD_SC_TOO_LATE if the response has been already "frozen" (used to
8595
 *         create an action),
8596
 *         #MHD_SC_RESP_HEADERS_CONFLICT if Basic Authentication "challenge"
8597
 *         has been added already,
8598
 *         #MHD_SC_RESP_POINTER_NULL if @a response is NULL,
8599
 *         #MHD_SC_RESP_HTTP_CODE_NOT_SUITABLE is response status code is wrong,
8600
 *         #MHD_SC_RESP_HEADER_VALUE_INVALID if realm is zero-length or has CR
8601
 *         or LF characters,
8602
 *         #MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED if memory allocation failed,
8603
 *         or other error code if failed
8604
 * @ingroup authentication
8605
 */
8606
MHD_EXTERN_ enum MHD_StatusCode
8607
MHD_response_add_auth_basic_challenge (
8608
  struct MHD_Response *MHD_RESTRICT response,
8609
  const char *MHD_RESTRICT realm,
8610
  enum MHD_Bool prefer_utf8)
8611
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2);
8612
8613
/* Application may define MHD_NO_STATIC_INLINE macro before including
8614
   libmicrohttpd headers to disable static inline functions in the headers. */
8615
#ifndef MHD_NO_STATIC_INLINE
8616
8617
/**
8618
 * Create action to reply with Basic Authentication "challenge".
8619
 *
8620
 * The @a response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8621
 *
8622
 * If access to any resource should be limited to specific users, authenticated
8623
 * by Basic Authentication mechanism, and the request for this resource does not
8624
 * have Basic Authentication information (see #MHD_AuthBasicCreds), then response
8625
 * with Basic Authentication "challenge" should be sent. This works as
8626
 * an indication that Basic Authentication should be used for the access.
8627
 *
8628
 * See RFC 7617, section-2 for details.
8629
 *
8630
 * @param request the request to create the action for
8631
 * @param realm the realm presented to the client
8632
 * @param prefer_utf8 if not set to #MHD_NO, parameter'charset="UTF-8"' will
8633
 *                    be added, indicating for client that UTF-8 encoding
8634
 *                    is preferred
8635
 * @param response the reply to send; should contain the "access denied"
8636
 *                 body;
8637
 *                 note: this function adds the "WWW Authenticate" header in
8638
 *                 the response and the caller should not set this header;
8639
 *                 the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8640
 *                 code;
8641
 *                 the NULL is tolerated (the result is
8642
 *                 #MHD_action_abort_request())
8643
 * @param abort_if_failed if set to #MHD_NO the response will be used even if
8644
 *                        failed to add Basic Authentication "challenge",
8645
 *                        if not set to #MHD_NO the request will be aborted
8646
 *                        if the "challenge" could not be added.
8647
 * @return pointer to the action, the action must be consumed
8648
 *         otherwise response object may leak;
8649
 *         NULL if failed or if any action has been already created for
8650
 *         the @a request;
8651
 *         when failed the response object is consumed and need not
8652
 *         to be "destroyed"
8653
 * @ingroup authentication
8654
 */
8655
MHD_STATIC_INLINE_
8656
MHD_FN_PAR_NONNULL_ (1)
8657
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2)
8658
const struct MHD_Action *
8659
MHD_action_basic_auth_challenge (struct MHD_Request *MHD_RESTRICT request,
8660
                                 const char *MHD_RESTRICT realm,
8661
                                 enum MHD_Bool prefer_utf8,
8662
                                 struct MHD_Response *MHD_RESTRICT response,
8663
                                 enum MHD_Bool abort_if_failed)
8664
0
{
8665
0
  if ((MHD_SC_OK !=
8666
0
       MHD_response_add_auth_basic_challenge (response, realm, prefer_utf8))
8667
0
      && (MHD_NO != abort_if_failed))
8668
0
  {
8669
0
    MHD_response_destroy (response);
8670
0
    return MHD_action_abort_request (request);
8671
0
  }
8672
0
  return MHD_action_from_response (request, response);
8673
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: connection_helper.cpp:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: daemon_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: request_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_destroy.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_process_states.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_process_request.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: stream_process_reply.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_comm.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_conn.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_in.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_out.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_conn_streams.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_req_fields.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_app_cb.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_reply_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: post_parser_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_auth_digest.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: auth_digest.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: upgrade_proc.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: conn_tls_check.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: tls_gnu_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: mhd_panic.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: http_status_str.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: daemon_logger.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: extr_events_funcs.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: conn_timeout.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: request_get_value.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: respond_with_error.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_from.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: response_add_header.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_proc_settings.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: h2_req_get_items.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
Unexecuted instantiation: request_auth_get.c:MHD_action_basic_auth_challenge(MHD_Request*, char const*, MHD_Bool, MHD_Response*, MHD_Bool)
8674
8675
8676
MHD_STATIC_INLINE_END_
8677
8678
8679
/**
8680
 * Create action to reply with Basic Authentication "challenge".
8681
 *
8682
 * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8683
 *
8684
 * If the @a r response object cannot be extended with the "challenge",
8685
 * the @a r response will be used to reply without the "challenge".
8686
 *
8687
 * @param rq the request to create the action for
8688
 * @param l the realm presented to the client
8689
 * @param u if not set to #MHD_NO, parameter'charset="UTF-8"' will
8690
 *          be added, indicating for client that UTF-8 encoding
8691
 *          is preferred
8692
 * @param r the reply to send; should contain the "access denied"
8693
 *          body;
8694
 *          note: this function adds the "WWW Authenticate" header in
8695
 *          the response and the caller should not set this header;
8696
 *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8697
 *          code;
8698
 *          the NULL is tolerated (the result is
8699
 *          #MHD_action_abort_request())
8700
 * @return pointer to the action, the action must be consumed
8701
 *         otherwise response object may leak;
8702
 *         NULL if failed or if any action has been already created for
8703
 *         the @a rq request;
8704
 *         when failed the response object is consumed and need not
8705
 *         to be "destroyed"
8706
 * @ingroup authentication
8707
 */
8708
#  define MHD_action_basic_auth_challenge_p(rq, l, u, r) \
8709
          MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_NO)
8710
8711
/**
8712
 * Create action to reply with Basic Authentication "challenge".
8713
 *
8714
 * The @a r response must have #MHD_HTTP_STATUS_UNAUTHORIZED status code.
8715
 *
8716
 * If the @a r response object cannot be extended with the "challenge",
8717
 * the request will be aborted.
8718
 *
8719
 * @param rq the request to create the action for
8720
 * @param l the realm presented to the client
8721
 * @param u if not set to #MHD_NO, parameter'charset="UTF-8"' will
8722
 *          be added, indicating for client that UTF-8 encoding
8723
 *          is preferred
8724
 * @param r the reply to send; should contain the "access denied"
8725
 *          body;
8726
 *          note: this function adds the "WWW Authenticate" header in
8727
 *          the response and the caller should not set this header;
8728
 *          the response must have #MHD_HTTP_STATUS_UNAUTHORIZED status
8729
 *          code;
8730
 *          the NULL is tolerated (the result is
8731
 *          #MHD_action_abort_request())
8732
 * @return pointer to the action, the action must be consumed
8733
 *         otherwise response object may leak;
8734
 *         NULL if failed or if any action has been already created for
8735
 *         the @a rq request;
8736
 *         when failed the response object is consumed and need not
8737
 *         to be "destroyed"
8738
 * @ingroup authentication
8739
 */
8740
#  define MHD_action_basic_auth_challenge_a(rq, l, u, r) \
8741
          MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_YES)
8742
8743
#endif /* ! MHD_NO_STATIC_INLINE */
8744
8745
8746
/**
8747
 * Information decoded from Basic Authentication client's header.
8748
 *
8749
 * @see #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS
8750
 */
8751
struct MHD_AuthBasicCreds
8752
{
8753
  /**
8754
   * The username
8755
   */
8756
  struct MHD_String username;
8757
8758
  /**
8759
   * The password, string pointer may be NULL if password is not encoded
8760
   * by the client.
8761
   */
8762
  struct MHD_StringNullable password;
8763
};
8764
8765
/* ********************** (f) Introspection ********************** */
8766
8767
8768
/**
8769
 * Types of information about MHD, used by #MHD_lib_get_info_fixed_sz().
8770
 * This information is not changed at run-time.
8771
 */
8772
enum MHD_FIXED_ENUM_APP_SET_ MHD_LibInfoFixed
8773
{
8774
  /* * Basic MHD information * */
8775
8776
  /**
8777
   * Get the MHD version as a number.
8778
   * The result is placed in @a v_version_num_uint32 member.
8779
   */
8780
  MHD_LIB_INFO_FIXED_VERSION_NUM = 0
8781
  ,
8782
  /**
8783
   * Get the MHD version as a string.
8784
   * The result is placed in @a v_version_string member.
8785
   */
8786
  MHD_LIB_INFO_FIXED_VERSION_STRING = 1
8787
  ,
8788
8789
  /* * Basic MHD features, buid-time configurable * */
8790
  /* These features should be always available unless the library was
8791
   * not compiled specifically for some embedded project.
8792
   * Exceptions are marked explicitly in the description. */
8793
8794
  /**
8795
   * Get whether messages are supported. If supported then messages can be
8796
   * printed to stderr or to an external logger.
8797
   * The result is placed in @a v_support_log_messages_bool member.
8798
   */
8799
  MHD_LIB_INFO_FIXED_SUPPORT_LOG_MESSAGES = 11
8800
  ,
8801
  /**
8802
   * Get whether detailed automatic HTTP reply messages are supported.
8803
   * If supported then automatic responses have bodies with text explaining
8804
   * the error details.
8805
   * Automatic responses are sent by MHD automatically when client is violating
8806
   * HTTP specification, for example, the request header has whitespace in
8807
   * header name or request's "Content-Length" header has non-number value.
8808
   * The result is placed in @a v_support_auto_replies_bodies_bool member.
8809
   */
8810
  MHD_LIB_INFO_FIXED_SUPPORT_AUTO_REPLIES_BODIES = 12
8811
  ,
8812
  /**
8813
   * Get whether MHD was built with debug asserts disabled.
8814
   * These asserts enabled only on special debug builds.
8815
   * For debug builds the error log is always enabled.
8816
   * The result is placed in @a v_is_non_debug_bool member.
8817
   */
8818
  MHD_LIB_INFO_FIXED_IS_NON_DEBUG = 13
8819
  ,
8820
  /**
8821
   * Get whether MHD supports threads.
8822
   * The result is placed in @a v_support_threads_bool member.
8823
   */
8824
  MHD_LIB_INFO_FIXED_SUPPORT_THREADS = 14
8825
  ,
8826
  /**
8827
   * Get whether automatic parsing of HTTP Cookie header is supported.
8828
   * If disabled, no #MHD_VK_COOKIE will be generated by MHD.
8829
   * The result is placed in @a v_support_cookie_parser_bool member.
8830
   */
8831
  MHD_LIB_INFO_FIXED_SUPPORT_COOKIE_PARSER = 15
8832
  ,
8833
  /**
8834
   * Get whether postprocessor is supported. If supported then
8835
   * #MHD_action_post_processor() can be used.
8836
   * The result is placed in @a v_support_post_parser_bool member.
8837
   */
8838
  MHD_LIB_INFO_FIXED_SUPPORT_POST_PARSER = 16
8839
  ,
8840
  /**
8841
   * Get whether HTTP "Upgrade" is supported.
8842
   * If supported then #MHD_action_upgrade() can be used.
8843
   * The result is placed in @a v_support_upgrade_bool member.
8844
   */
8845
  MHD_LIB_INFO_FIXED_SUPPORT_UPGRADE = 17
8846
  ,
8847
  /**
8848
   * Get whether HTTP Basic authorization is supported. If supported
8849
   * then functions #MHD_action_basic_auth_required_response ()
8850
   * and #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS can be used.
8851
   * The result is placed in @a v_support_auth_basic_bool member.
8852
   */
8853
  MHD_LIB_INFO_FIXED_SUPPORT_AUTH_BASIC = 20
8854
  ,
8855
  /**
8856
   * Get whether HTTP Digest authorization is supported. If
8857
   * supported then options #MHD_D_O_RANDOM_ENTROPY,
8858
   * #MHD_D_O_DAUTH_MAP_SIZE and functions
8859
   * #MHD_action_digest_auth_required_response () and
8860
   * #MHD_digest_auth_check() can be used.
8861
   * The result is placed in @a v_support_auth_digest_bool member.
8862
   */
8863
  MHD_LIB_INFO_FIXED_SUPPORT_AUTH_DIGEST = 21
8864
  ,
8865
  /**
8866
   * Get whether the early version the Digest Authorization (RFC 2069) is
8867
   * supported (digest authorisation without QOP parameter).
8868
   * Currently it is always supported if Digest Auth module is built.
8869
   * The result is placed in @a v_support_digest_auth_rfc2069_bool member.
8870
   */
8871
  MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_RFC2069 = 22
8872
  ,
8873
  /**
8874
   * Get whether the MD5-based hashing algorithms are supported for Digest
8875
   * Authorization and the type of the implementation if supported.
8876
   * Currently it is always supported if Digest Auth module is built
8877
   * unless manually disabled in a custom build.
8878
   * The result is placed in @a v_type_digest_auth_md5_algo_type member.
8879
   */
8880
  MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5 = 23
8881
  ,
8882
  /**
8883
   * Get whether the SHA-256-based hashing algorithms are supported for Digest
8884
   * Authorization and the type of the implementation if supported.
8885
   * Currently it is always supported if Digest Auth module is built
8886
   * unless manually disabled in a custom build.
8887
   * The result is placed in @a v_type_digest_auth_sha256_algo_type member.
8888
   */
8889
  MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA256 = 24
8890
  ,
8891
  /**
8892
   * Get whether the SHA-512/256-based hashing algorithms are supported
8893
   * Authorization and the type of the implementation if supported.
8894
   * Currently it is always supported if Digest Auth module is built
8895
   * unless manually disabled in a custom build.
8896
   * The result is placed in @a v_type_digest_auth_sha512_256_algo_type member.
8897
   */
8898
  MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA512_256 = 25
8899
  ,
8900
  /**
8901
   * Get whether QOP with value 'auth-int' (authentication with integrity
8902
   * protection) is supported for Digest Authorization.
8903
   * Currently it is always not supported.
8904
   * The result is placed in @a v_support_digest_auth_auth_int_bool member.
8905
   */
8906
  MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_AUTH_INT = 28
8907
  ,
8908
  /**
8909
   * Get whether 'session' algorithms (like 'MD5-sess') are supported for Digest
8910
   * Authorization.
8911
   * Currently it is always not supported.
8912
   * The result is placed in @a v_support_digest_auth_algo_session_bool member.
8913
   */
8914
  MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_ALGO_SESSION = 29
8915
  ,
8916
  /**
8917
   * Get whether 'userhash' is supported for Digest Authorization.
8918
   * Currently it is always supported if Digest Auth module is built.
8919
   * The result is placed in @a v_support_digest_auth_userhash_bool member.
8920
   */
8921
  MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_USERHASH = 30
8922
  ,
8923
8924
  /* * Platform-dependent features, some are configurable at build-time * */
8925
  /* These features depends on the platform, third-party libraries and
8926
   * the toolchain.
8927
   * Some of the features can be disabled or selected at build-time. */
8928
  /**
8929
   * Get sockets polling functions/techniques supported by this MHD build.
8930
   * Some functions can be disabled (like epoll) in kernel, this is not
8931
   * checked.
8932
   * The result is placed in @a v_types_sockets_polling member.
8933
   */
8934
  MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING = 60
8935
  ,
8936
  /**
8937
   * Get whether aggregate FD external polling is supported.
8938
   * The result is placed in @a v_support_aggregate_fd_bool member.
8939
   */
8940
  MHD_LIB_INFO_FIXED_SUPPORT_AGGREGATE_FD = 61
8941
  ,
8942
  /**
8943
   * Get whether IPv6 is supported on the platform and IPv6-only listen socket
8944
   * can be used.
8945
   * The result is placed in @a v_ipv6 member.
8946
   * @note The platform may have disabled IPv6 at run-time, it is not checked
8947
   *       by this information type.
8948
   */
8949
  MHD_LIB_INFO_FIXED_TYPE_IPV6 = 62
8950
  ,
8951
  /**
8952
   * Get whether TCP Fast Open is supported by MHD build.
8953
   * If supported then option #MHD_D_O_TCP_FASTOPEN can be used.
8954
   * The result is placed in @a v_support_tcp_fastopen_bool member.
8955
   */
8956
  MHD_LIB_INFO_FIXED_SUPPORT_TCP_FASTOPEN = 64
8957
  ,
8958
  /**
8959
   * Get whether MHD support automatic detection of bind port number.
8960
   * @sa #MHD_D_O_BIND_PORT
8961
   * The result is placed in @a v_has_autodetect_bind_port_bool member.
8962
   */
8963
  MHD_LIB_INFO_FIXED_HAS_AUTODETECT_BIND_PORT = 65
8964
  ,
8965
  /**
8966
   * Get whether MHD use system's sendfile() function to send
8967
   * file-FD based responses over non-TLS connections.
8968
   * The result is placed in @a v_has_sendfile_bool member.
8969
   */
8970
  MHD_LIB_INFO_FIXED_HAS_SENDFILE = 66
8971
  ,
8972
  /**
8973
   * Get whether MHD supports automatic SIGPIPE suppression within internal
8974
   * events loop (MHD's managed threads).
8975
   * If SIGPIPE suppression is not supported, application must handle
8976
   * SIGPIPE signal by itself whem using MHD with internal events loop.
8977
   * If the platform does not have SIGPIPE the result is #MHD_YES.
8978
   * The result is placed in @a v_has_autosuppress_sigpipe_int_bool member.
8979
   */
8980
  MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_INT = 80
8981
  ,
8982
  /**
8983
   * Get whether MHD supports automatic SIGPIPE suppression when used with
8984
   * extenal events loop (in application thread).
8985
   * If SIGPIPE suppression is not supported, application must handle
8986
   * SIGPIPE signal by itself whem using MHD with external events loop.
8987
   * If the platform does not have SIGPIPE the result is #MHD_YES.
8988
   * The result is placed in @a v_has_autosuppress_sigpipe_ext_bool member.
8989
   */
8990
  MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_EXT = 81
8991
  ,
8992
  /**
8993
   * Get whether MHD sets names on generated threads.
8994
   * The result is placed in @a v_has_thread_names_bool member.
8995
   */
8996
  MHD_LIB_INFO_FIXED_HAS_THREAD_NAMES = 82
8997
  ,
8998
  /**
8999
   * Get the type of supported inter-thread communication.
9000
   * The result is placed in @a v_type_itc member.
9001
   */
9002
  MHD_LIB_INFO_FIXED_TYPE_ITC = 83
9003
  ,
9004
  /**
9005
   * Get whether reading files beyond 2 GiB boundary is supported.
9006
   * If supported then #MHD_response_from_fd() can be used with sizes and
9007
   * offsets larger than 2 GiB. If not supported value of size+offset could be
9008
   * limited to 2 GiB.
9009
   * The result is placed in @a v_support_large_file_bool member.
9010
   */
9011
  MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE = 84
9012
  ,
9013
9014
  /* * Platform-dependent features, some set on startup and some are
9015
   *   configurable at build-time * */
9016
  /* These features depends on the platform, third-party libraries availability
9017
   * and configuration. The features can be enabled/disabled during startup
9018
   * of the library depending on conditions.
9019
   * Some of the features can be disabled or selected at build-time. */
9020
  /**
9021
   * Get whether HTTPS and which types of TLS backend(s) supported by
9022
   * this build.
9023
   * The result is placed in @a v_tls_backends member.
9024
   */
9025
  MHD_LIB_INFO_FIXED_TLS_BACKENDS = 100
9026
  ,
9027
  /**
9028
  * Get whether password encrypted private key for HTTPS daemon is
9029
  * supported by TLS backends.
9030
  * If supported then option #MHD_D_OPTION_TLS_KEY_CERT can be used with
9031
  * non-NULL @a mem_pass.
9032
  * The result is placed in @a v_tls_key_password_backends member.
9033
  */
9034
  MHD_LIB_INFO_FIXED_TLS_KEY_PASSWORD_BACKENDS = 102
9035
  ,
9036
9037
  /* * Sentinel * */
9038
  /**
9039
   * The sentinel value.
9040
   * This value enforces specific underlying integer type for the enum.
9041
   * Do not use.
9042
   */
9043
  MHD_LIB_INFO_FIXED_SENTINEL = 65535
9044
};
9045
9046
/**
9047
 * The type of the data for digest algorithm implementations.
9048
 */
9049
enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedDigestAlgoType
9050
{
9051
  /**
9052
   * The algorithm is not implemented or disabled at the build time.
9053
   */
9054
  MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_NOT_AVAILABLE = 0
9055
  ,
9056
  /**
9057
   * The algorithm is implemented by MHD internal code.
9058
   * MHD implementation of hashing can never fail.
9059
   */
9060
  MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_BUILT_IN = 1
9061
  ,
9062
  /**
9063
   * The algorithm is implemented by external code that never fails.
9064
   */
9065
  MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_NEVER_FAIL = 2
9066
  ,
9067
  /**
9068
   * The algorithm is implemented by external code that may hypothetically fail.
9069
   */
9070
  MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_MAY_FAIL = 3
9071
};
9072
9073
/**
9074
 * The types of the sockets polling functions/techniques supported
9075
 */
9076
struct MHD_LibInfoFixedPollingFunc
9077
{
9078
  /**
9079
   * select() function for sockets polling
9080
   */
9081
  enum MHD_Bool func_select;
9082
  /**
9083
   * poll() function for sockets polling
9084
   */
9085
  enum MHD_Bool func_poll;
9086
  /**
9087
   * epoll technique for sockets polling
9088
   */
9089
  enum MHD_Bool tech_epoll;
9090
  /**
9091
   * kqueue technique for sockets polling
9092
   */
9093
  enum MHD_Bool tech_kqueue;
9094
};
9095
9096
/**
9097
 * The types of IPv6 supported
9098
 */
9099
enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedIPv6Type
9100
{
9101
  /**
9102
   * IPv6 is not supported by this MHD build
9103
   */
9104
  MHD_LIB_INFO_FIXED_IPV6_TYPE_NONE = 0
9105
  ,
9106
  /**
9107
   * IPv6 is supported only as "dual stack".
9108
   * IPv4 connections can be received by IPv6 listen socket.
9109
   */
9110
  MHD_LIB_INFO_FIXED_IPV6_TYPE_DUAL_ONLY = 1
9111
  ,
9112
  /**
9113
   * IPv6 can be used as IPv6-only (without getting IPv4 incoming connections).
9114
   * The platform may support "dual stack" too.
9115
   */
9116
  MHD_LIB_INFO_FIXED_IPV6_TYPE_IPV6_PURE = 2
9117
};
9118
9119
/**
9120
 * The types of inter-thread communication
9121
 * @note the enum can be extended in future versions with new values
9122
 */
9123
enum MHD_FIXED_ENUM_MHD_SET_ MHD_LibInfoFixedITCType
9124
{
9125
  /**
9126
   * No ITC used.
9127
   * This value is returned if MHD is built without threads support
9128
   */
9129
  MHD_LIB_INFO_FIXED_ITC_TYPE_NONE = 0
9130
  ,
9131
  /**
9132
   * The pair of sockets are used as inter-thread communication.
9133
   * The is the least efficient method of communication.
9134
   */
9135
  MHD_LIB_INFO_FIXED_ITC_TYPE_SOCKETPAIR = 1
9136
  ,
9137
  /**
9138
   * The pipe is used as inter-thread communication.
9139
   */
9140
  MHD_LIB_INFO_FIXED_ITC_TYPE_PIPE = 2
9141
  ,
9142
  /**
9143
   * The EventFD is used as inter-thread communication.
9144
   * This is the most efficient method of communication.
9145
   */
9146
  MHD_LIB_INFO_FIXED_ITC_TYPE_EVENTFD = 3
9147
};
9148
9149
9150
/**
9151
 * The types of the TLS (or TLS feature) backend supported/available/enabled
9152
 * @note the enum can be extended in future versions with new members
9153
 */
9154
struct MHD_LibInfoTLSType
9155
{
9156
  /**
9157
   * The TLS (or TLS feature) is supported/enabled.
9158
   * Set to #MHD_YES if any other member is #MHD_YES.
9159
   */
9160
  enum MHD_Bool tls_supported;
9161
  /**
9162
   * The GnuTLS backend is supported/available/enabled.
9163
   */
9164
  enum MHD_Bool backend_gnutls;
9165
  /**
9166
   * The OpenSSL backend is supported/available/enabled.
9167
   */
9168
  enum MHD_Bool backend_openssl;
9169
  /**
9170
   * The MbedTLS backend is supported/available/enabled.
9171
   */
9172
  enum MHD_Bool backend_mbedtls;
9173
};
9174
9175
/**
9176
 * The data provided by #MHD_lib_get_info_fixed_sz()
9177
 */
9178
union MHD_LibInfoFixedData
9179
{
9180
  /**
9181
   * The data for the #MHD_LIB_INFO_FIXED_VERSION_NUM query
9182
   */
9183
  uint_fast32_t v_version_num_uint32;
9184
  /**
9185
   * The data for the #MHD_LIB_INFO_FIXED_VERSION_STR query
9186
   */
9187
  struct MHD_String v_version_string;
9188
  /**
9189
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_LOG_MESSAGES query
9190
   */
9191
  enum MHD_Bool v_support_log_messages_bool;
9192
  /**
9193
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTO_REPLIES_BODIES query
9194
   */
9195
  enum MHD_Bool v_support_auto_replies_bodies_bool;
9196
  /**
9197
   * The data for the #MHD_LIB_INFO_FIXED_IS_NON_DEBUG query
9198
   */
9199
  enum MHD_Bool v_is_non_debug_bool;
9200
  /**
9201
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_THREADS query
9202
   */
9203
  enum MHD_Bool v_support_threads_bool;
9204
  /**
9205
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_COOKIE_PARSER query
9206
   */
9207
  enum MHD_Bool v_support_cookie_parser_bool;
9208
  /**
9209
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_POST_PARSER query
9210
   */
9211
  enum MHD_Bool v_support_post_parser_bool;
9212
  /**
9213
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_UPGRADE query
9214
   */
9215
  enum MHD_Bool v_support_upgrade_bool;
9216
  /**
9217
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTH_BASIC query
9218
   */
9219
  enum MHD_Bool v_support_auth_basic_bool;
9220
  /**
9221
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AUTH_DIGEST query
9222
   */
9223
  enum MHD_Bool v_support_auth_digest_bool;
9224
  /**
9225
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_RFC2069 query
9226
   */
9227
  enum MHD_Bool v_support_digest_auth_rfc2069_bool;
9228
  /**
9229
   * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5 query
9230
   */
9231
  enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_md5_algo_type;
9232
  /**
9233
   * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA256 query
9234
   */
9235
  enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_sha256_algo_type;
9236
  /**
9237
   * The data for the #MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_SHA512_256 query
9238
   */
9239
  enum MHD_LibInfoFixedDigestAlgoType v_type_digest_auth_sha512_256_algo_type;
9240
  /**
9241
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_AUTH_INT query
9242
   */
9243
  enum MHD_Bool v_support_digest_auth_auth_int_bool;
9244
  /**
9245
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_ALGO_SESSION query
9246
   */
9247
  enum MHD_Bool v_support_digest_auth_algo_session_bool;
9248
  /**
9249
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_DIGEST_AUTH_USERHASH query
9250
   */
9251
  enum MHD_Bool v_support_digest_auth_userhash_bool;
9252
  /**
9253
   * The data for the #MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING query
9254
   */
9255
  struct MHD_LibInfoFixedPollingFunc v_types_sockets_polling;
9256
  /**
9257
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_AGGREGATE_FD query
9258
   */
9259
  enum MHD_Bool v_support_aggregate_fd_bool;
9260
  /**
9261
   * The data for the #MHD_LIB_INFO_FIXED_TYPE_IPV6 query
9262
   */
9263
  enum MHD_LibInfoFixedIPv6Type v_ipv6;
9264
  /**
9265
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_TCP_FASTOPEN query
9266
   */
9267
  enum MHD_Bool v_support_tcp_fastopen_bool;
9268
  /**
9269
   * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTODETECT_BIND_PORT query
9270
   */
9271
  enum MHD_Bool v_has_autodetect_bind_port_bool;
9272
  /**
9273
   * The data for the #MHD_LIB_INFO_FIXED_HAS_SENDFILE query
9274
   */
9275
  enum MHD_Bool v_has_sendfile_bool;
9276
  /**
9277
   * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_INT query
9278
   */
9279
  enum MHD_Bool v_has_autosuppress_sigpipe_int_bool;
9280
  /**
9281
   * The data for the #MHD_LIB_INFO_FIXED_HAS_AUTOSUPPRESS_SIGPIPE_EXT query
9282
   */
9283
  enum MHD_Bool v_has_autosuppress_sigpipe_ext_bool;
9284
  /**
9285
   * The data for the #MHD_LIB_INFO_FIXED_HAS_THREAD_NAMES query
9286
   */
9287
  enum MHD_Bool v_has_thread_names_bool;
9288
  /**
9289
   * The data for the #MHD_LIB_INFO_FIXED_TYPE_ITC query
9290
   */
9291
  enum MHD_LibInfoFixedITCType v_type_itc;
9292
  /**
9293
   * The data for the #MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE query
9294
   */
9295
  enum MHD_Bool v_support_large_file_bool;
9296
  /**
9297
   * The data for the #MHD_LIB_INFO_FIXED_TLS_BACKENDS query
9298
   */
9299
  struct MHD_LibInfoTLSType v_tls_backends;
9300
  /**
9301
   * The data for the #MHD_LIB_INFO_FIXED_TLS_KEY_PASSWORD_BACKENDS query
9302
   */
9303
  struct MHD_LibInfoTLSType v_tls_key_password_backends;
9304
};
9305
9306
/**
9307
 * Get fixed information about MHD that is not changed at run-time.
9308
 * The returned information can be cached by application as it will be not
9309
 * changed at run-time.
9310
 *
9311
 * For any valid @a info_type the only possible returned error value is
9312
 * #MHD_SC_INFO_GET_BUFF_TOO_SMALL. If the buffer is large enough and
9313
 * the requested type of information is valid, the function always succeeds
9314
 * and returns #MHD_SC_OK.
9315
 *
9316
 * The wrapper macro #MHD_lib_get_info_fixed() may be more convenient.
9317
 *
9318
 * @param info_type the type of requested information
9319
 * @param[out] output_buf the pointer to union to be set to the requested
9320
 *                        information
9321
 * @param output_buf_size the size of the memory area pointed by @a output_buf
9322
 *                        (provided by the caller for storing the requested
9323
 *                        information), in bytes
9324
 * @return #MHD_SC_OK if succeed,
9325
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9326
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small
9327
 * @ingroup specialized
9328
 */
9329
MHD_EXTERN_ enum MHD_StatusCode
9330
MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type,
9331
                           union MHD_LibInfoFixedData *MHD_RESTRICT output_buf,
9332
                           size_t output_buf_size)
9333
MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2);
9334
9335
/**
9336
 * Get fixed information about MHD that is not changed at run-time.
9337
 * The returned information can be cached by application as it will be not
9338
 * changed at run-time.
9339
 *
9340
 * @param info the type of requested information
9341
 * @param[out] output_buf the pointer to union to be set to the requested
9342
 *                        information
9343
 * @return #MHD_SC_OK if succeed,
9344
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9345
 *         or other error code
9346
 * @ingroup specialized
9347
 */
9348
#define MHD_lib_get_info_fixed(info, output_buf) \
9349
        MHD_lib_get_info_fixed_sz ((info),(output_buf),sizeof(*(output_buf)))
9350
9351
/* Application may define MHD_NO_STATIC_INLINE macro before including
9352
   libmicrohttpd headers to disable static inline functions in the headers. */
9353
#ifndef MHD_NO_STATIC_INLINE
9354
9355
/*
9356
 * A helper below can be used in a simple check preventing use of downgraded
9357
 * library version.
9358
 * As new library version may introduce new functionality, and the application
9359
 * may detect some functionality available at application build-time, use of
9360
 * previous versions may lead to run-time failures.
9361
 * To prevent run-time failures, application may use a check like:
9362
9363
 if (MHD_lib_get_info_ver_num() < ((uint_fast32_t) MHD_VERSION))
9364
   handle_init_failure();
9365
9366
 */
9367
/**
9368
 * Get the library version number.
9369
 * @return the library version number.
9370
 */
9371
MHD_STATIC_INLINE_ MHD_FN_PURE_ uint_fast32_t
9372
MHD_lib_get_info_ver_num (void)
9373
0
{
9374
0
  union MHD_LibInfoFixedData data;
9375
0
  data.v_version_num_uint32 = 0; /* Not really necessary */
9376
0
  (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \
9377
0
                                &data);  /* Never fail */
9378
0
  return data.v_version_num_uint32;
9379
0
}
Unexecuted instantiation: fuzz_daemon_connection.cpp:MHD_lib_get_info_ver_num()
Unexecuted instantiation: connection_helper.cpp:MHD_lib_get_info_ver_num()
Unexecuted instantiation: daemon_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: request_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: response_destroy.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: response_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: stream_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: stream_process_states.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: stream_process_request.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: stream_process_reply.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_comm.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_proc_conn.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_proc_in.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_proc_out.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_conn_streams.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_req_fields.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_app_cb.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_reply_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: post_parser_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: response_auth_digest.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: auth_digest.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: upgrade_proc.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: conn_tls_check.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: tls_gnu_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: mhd_panic.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: http_status_str.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: daemon_logger.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: extr_events_funcs.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: conn_timeout.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: request_get_value.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: respond_with_error.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: response_from.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: response_add_header.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_proc_settings.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: h2_req_get_items.c:MHD_lib_get_info_ver_num()
Unexecuted instantiation: request_auth_get.c:MHD_lib_get_info_ver_num()
9380
9381
9382
MHD_STATIC_INLINE_END_
9383
9384
#endif /* ! MHD_NO_STATIC_INLINE */
9385
9386
/**
9387
 * Types of information about MHD, used by #MHD_lib_get_info_dynamic_sz().
9388
 * This information may vary over time.
9389
 */
9390
enum MHD_FIXED_ENUM_APP_SET_ MHD_LibInfoDynamic
9391
{
9392
  /* * Basic MHD information * */
9393
9394
  /**
9395
   * Get whether MHD has been successfully fully initialised.
9396
   * MHD uses lazy initialisation: a minimal initialisation is performed at
9397
   * startup, complete initialisation is performed when any daemon is created
9398
   * (or when called some function which requires full initialisation).
9399
   * The result is #MHD_NO when the library has been not yet initialised
9400
   * completely since startup.
9401
   * The result is placed in @a v_inited_fully_once_bool member.
9402
   */
9403
  MHD_LIB_INFO_DYNAMIC_INITED_FULLY_ONCE = 0
9404
  ,
9405
  /**
9406
   * Get whether MHD is fully initialised.
9407
   * MHD uses lazy initialisation: a minimal initialisation is performed at
9408
   * startup, complete initialisation is perfromed when any daemon is created
9409
   * (or when called some function which requires full initialisation).
9410
   * The result is #MHD_YES if library is initialised state now (meaning
9411
   * that at least one daemon is created and not destroyed or some function
9412
   * required full initialisation is running).
9413
   * The result is placed in @a v_inited_fully_now_bool member.
9414
   */
9415
  MHD_LIB_INFO_DYNAMIC_INITED_FULLY_NOW = 1
9416
  ,
9417
9418
  /**
9419
   * Get whether HTTPS and which types of TLS backend(s) currently available.
9420
   * If any MHD daemons active (created and not destroyed, not necessary
9421
   * running) the result reflects the current backends availability.
9422
   * If no MHD daemon is active, then this function would try to temporarily
9423
   * enable backends to check for their availability.
9424
   * If global library initialisation failed, the function returns
9425
   * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE error code.
9426
   * The result is placed in @a v_tls_backends member.
9427
   */
9428
  MHD_LIB_INFO_DYNAMIC_TYPE_TLS = 100
9429
  ,
9430
9431
  /* * Sentinel * */
9432
  /**
9433
   * The sentinel value.
9434
   * This value enforces specific underlying integer type for the enum.
9435
   * Do not use.
9436
   */
9437
  MHD_LIB_INFO_DYNAMIC_SENTINEL = 65535
9438
};
9439
9440
9441
/**
9442
 * The data provided by #MHD_lib_get_info_dynamic_sz().
9443
 * The resulting value may vary over time.
9444
 */
9445
union MHD_LibInfoDynamicData
9446
{
9447
  /**
9448
   * The data for the #MHD_LIB_INFO_DYNAMIC_INITED_FULLY_ONCE query
9449
   */
9450
  enum MHD_Bool v_inited_fully_once_bool;
9451
9452
  /**
9453
   * The data for the #MHD_LIB_INFO_DYNAMIC_INITED_FULLY_NOW query
9454
   */
9455
  enum MHD_Bool v_inited_fully_now_bool;
9456
9457
  /**
9458
   * The data for the #MHD_LIB_INFO_DYNAMIC_TYPE_TLS query
9459
   */
9460
  struct MHD_LibInfoTLSType v_tls_backends;
9461
9462
  /**
9463
   * Unused member.
9464
   * Help enforcing future-proof alignment of the union.
9465
   * Do not use.
9466
   */
9467
  void *reserved;
9468
};
9469
9470
/**
9471
 * Get dynamic information about MHD that may be changed at run-time.
9472
 * The wrapper macro #MHD_lib_get_info_dynamic() could be more convenient.
9473
 *
9474
 * @param info_type the type of requested information
9475
 * @param[out] output_buf the pointer to union to be set to the requested
9476
 *                        information
9477
 * @param output_buf_size the size of the memory area pointed by @a output_buf
9478
 *                        (provided by the caller for storing the requested
9479
 *                        information), in bytes
9480
 * @return #MHD_SC_OK if succeed,
9481
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9482
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
9483
 *         or other error code
9484
 * @ingroup specialized
9485
 */
9486
MHD_EXTERN_ enum MHD_StatusCode
9487
MHD_lib_get_info_dynamic_sz (
9488
  enum MHD_LibInfoDynamic info_type,
9489
  union MHD_LibInfoDynamicData *MHD_RESTRICT output_buf,
9490
  size_t output_buf_size)
9491
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2);
9492
9493
/**
9494
 * Get dynamic information about MHD that may be changed at run-time.
9495
 *
9496
 * @param info the type of requested information
9497
 * @param[out] output_buf the pointer to union to be set to the requested
9498
 *                        information
9499
 * @return #MHD_SC_OK if succeed,
9500
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9501
 *         or other error code
9502
 * @ingroup specialized
9503
 */
9504
#define MHD_lib_get_info_dynamic(info, output_buf) \
9505
        MHD_lib_get_info_dynamic_sz ((info),(output_buf),sizeof(*(output_buf)))
9506
9507
9508
/**
9509
 * Values of this enum are used to specify what information about a daemon is
9510
 * requested.
9511
 * These types of information do not change after the start of the daemon
9512
 * until the daemon is destroyed.
9513
 */
9514
enum MHD_DaemonInfoFixedType
9515
{
9516
9517
  /**
9518
   * Get the type of system call used for sockets polling.
9519
   * The value #MHD_SPS_AUTO is never set in the returned data.
9520
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
9521
   * does not use internal sockets polling.
9522
   * The result is placed in @a v_poll_syscall member.
9523
   */
9524
  MHD_DAEMON_INFO_FIXED_POLL_SYSCALL = 41
9525
  ,
9526
  /**
9527
   * Get the file descriptor for the single FD that triggered when
9528
   * any MHD event happens.
9529
   * This FD can be watched as aggregate indicator for all MHD events.
9530
   * The provided socket must be used as 'read-only': only select() or similar
9531
   * functions should be used. Any modifications (changing socket attributes,
9532
   * calling accept(), closing it etc.) will lead to undefined behaviour.
9533
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD if the library
9534
   * does not support mode with agregate FD.
9535
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
9536
   * is not configured to use this mode.
9537
   * The result is placed in @a v_aggreagate_fd member.
9538
   */
9539
  MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 46
9540
  ,
9541
  /**
9542
   * Get the number of worker threads when used in MHD_WM_WORKER_THREADS mode.
9543
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
9544
   * does not use worker threads mode.
9545
   * The result is placed in @a v_num_work_threads_uint member.
9546
   */
9547
  MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS = 47
9548
  ,
9549
  /**
9550
   * Get the port number of daemon's listen socket.
9551
   * Note: if port '0' (auto port) was specified for #MHD_D_OPTION_BIND_PORT(),
9552
   * returned value will be the real port number.
9553
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
9554
   * does not have listening socket or if listening socket is non-IP.
9555
   * The function returns #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the port number
9556
   * detection failed or not supported by the platform.
9557
   * If the function succeed, the returned port number is never zero.
9558
   * The result is placed in @a v_bind_port_uint16 member.
9559
   */
9560
  MHD_DAEMON_INFO_FIXED_BIND_PORT = 80
9561
  ,
9562
  /**
9563
   * Get the file descriptor for the listening socket.
9564
   * The provided socket must be used as 'read-only': only select() or similar
9565
   * functions should be used. Any modifications (changing socket attributes,
9566
   * calling accept(), closing it etc.) will lead to undefined behaviour.
9567
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
9568
   * does not have listening socket.
9569
   * The result is placed in @a v_listen_socket member.
9570
   */
9571
  MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET = 82
9572
  ,
9573
  /**
9574
   * Get the TLS backend used by the daemon.
9575
   * The value #MHD_TLS_BACKEND_ANY is never set in the returned data.
9576
   * The value #MHD_TLS_BACKEND_NONE is set if the daemon does not use TLS.
9577
   * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set.
9578
   * The result is placed in @a v_tls_backend member.
9579
   */
9580
  MHD_DAEMON_INFO_FIXED_TLS_BACKEND = 120
9581
  ,
9582
  /**
9583
   * Get the default inactivity timeout for connections in milliseconds.
9584
   * The result is placed in @a v_default_timeout_milsec_uint32 member.
9585
   */
9586
  MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC = 160
9587
  ,
9588
  /**
9589
   * Get the limit of number of simutaneous network connections served by
9590
   * the daemon.
9591
   * The result is placed in @a v_global_connection_limit_uint member.
9592
   */
9593
  MHD_DAEMON_INFO_FIXED_GLOBAL_CONNECTION_LIMIT = 161
9594
  ,
9595
  /**
9596
   * Get the limit of number of simutaneous network connections served by
9597
   * the daemon for any single IP address.
9598
   * The result is placed in @a v_per_ip_limit_uint member.
9599
   */
9600
  MHD_DAEMON_INFO_FIXED_PER_IP_LIMIT = 162
9601
  ,
9602
  /**
9603
   * Get the setting for suppression of the 'Date:' header in replies.
9604
   * The result is placed in @a v_suppress_date_header_bool member.
9605
   */
9606
  MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER = 240
9607
  ,
9608
  /**
9609
   * Get the size of buffer unsed per connection.
9610
   * The result is placed in @a v_conn_memory_limit_sizet member.
9611
   */
9612
  MHD_DAEMON_INFO_FIXED_CONN_MEMORY_LIMIT = 280
9613
  ,
9614
  /**
9615
   * Get the limit of maximum FD value for the daemon.
9616
   * The daemon rejects (closes) any sockets with FD equal or higher
9617
   * the resulting number.
9618
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon
9619
   * is built for W32.
9620
   * The result is placed in @a v_fd_number_limit_uint member.
9621
   */
9622
  MHD_DAEMON_INFO_FIXED_FD_NUMBER_LIMIT = 283
9623
  ,
9624
9625
  /* * Sentinel * */
9626
  /**
9627
   * The sentinel value.
9628
   * This value enforces specific underlying integer type for the enum.
9629
   * Do not use.
9630
   */
9631
  MHD_DAEMON_INFO_FIXED_SENTINEL = 65535
9632
9633
};
9634
9635
9636
/**
9637
 * Information about an MHD daemon.
9638
 */
9639
union MHD_DaemonInfoFixedData
9640
{
9641
  /**
9642
   * The data for the #MHD_DAEMON_INFO_FIXED_POLL_SYSCALL query
9643
   */
9644
  enum MHD_SockPollSyscall v_poll_syscall;
9645
9646
  /**
9647
   * The data for the #MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS query
9648
   */
9649
  unsigned int v_num_work_threads_uint;
9650
9651
  /**
9652
   * The data for the #MHD_DAEMON_INFO_FIXED_BIND_PORT query
9653
   */
9654
  uint_least16_t v_bind_port_uint16;
9655
9656
  /**
9657
   * The data for the #MHD_DAEMON_INFO_FIXED_LISTEN_SOCKET query
9658
   */
9659
  MHD_Socket v_listen_socket;
9660
9661
  /**
9662
   * The data for the #MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD query
9663
   */
9664
  int v_aggreagate_fd;
9665
9666
  /**
9667
   * The data for the #MHD_DAEMON_INFO_FIXED_TLS_BACKEND query
9668
   */
9669
  enum MHD_TlsBackend v_tls_backend;
9670
9671
  /**
9672
   * The data for the #MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC query
9673
   */
9674
  uint_fast32_t v_default_timeout_milsec_uint32;
9675
9676
  /**
9677
   * The data for the #MHD_DAEMON_INFO_FIXED_GLOBAL_CONNECTION_LIMIT query
9678
   */
9679
  unsigned int v_global_connection_limit_uint;
9680
9681
  /**
9682
   * The data for the #MHD_DAEMON_INFO_FIXED_PER_IP_LIMIT query
9683
   */
9684
  unsigned int v_per_ip_limit_uint;
9685
9686
  /**
9687
   * The data for the #MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER query
9688
   */
9689
  enum MHD_Bool v_suppress_date_header_bool;
9690
9691
  /**
9692
   * The data for the #MHD_DAEMON_INFO_FIXED_CONN_MEMORY_LIMIT query
9693
   */
9694
  size_t v_conn_memory_limit_sizet;
9695
9696
  /**
9697
   * The data for the #MHD_DAEMON_INFO_FIXED_FD_NUMBER_LIMIT query
9698
   */
9699
  MHD_Socket v_fd_number_limit_socket;
9700
9701
  /**
9702
   * Unused member.
9703
   * Help enforcing future-proof alignment of the union.
9704
   * Do not use.
9705
   */
9706
  void *reserved;
9707
};
9708
9709
9710
/**
9711
 * Obtain fixed information about the given daemon.
9712
 * This information is not changed at after start of the daemon until
9713
 * the daemon is destroyed.
9714
 * The wrapper macro #MHD_daemon_get_info_fixed() may be more convenient.
9715
 *
9716
 * @param daemon the daemon to get information about
9717
 * @param info_type the type of information requested
9718
 * @param[out] output_buf pointer to union where requested information will
9719
 *                        be stored
9720
 * @param output_buf_size the size of the memory area pointed by @a output_buf
9721
 *                        (provided by the caller for storing the requested
9722
 *                        information), in bytes
9723
 * @return #MHD_SC_OK if succeed,
9724
 *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
9725
 *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
9726
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9727
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
9728
 *                                              is not available for this
9729
 *                                              daemon due to the daemon
9730
 *                                              configuration/mode,
9731
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
9732
 *                                            should be available for
9733
 *                                            the daemon, but cannot be provided
9734
 *                                            due to some error or other
9735
 *                                            reasons,
9736
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
9737
 *         other error codes in case of other errors
9738
 * @ingroup specialized
9739
 */
9740
MHD_EXTERN_ enum MHD_StatusCode
9741
MHD_daemon_get_info_fixed_sz (
9742
  struct MHD_Daemon *MHD_RESTRICT daemon,
9743
  enum MHD_DaemonInfoFixedType info_type,
9744
  union MHD_DaemonInfoFixedData *MHD_RESTRICT output_buf,
9745
  size_t output_buf_size)
9746
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
9747
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
9748
9749
/**
9750
 * Obtain fixed information about the given daemon.
9751
 * This types of information are not changed at after start of the daemon until
9752
 * the daemon is destroyed.
9753
 *
9754
 * @param daemon the daemon to get information about
9755
 * @param info_type the type of information requested
9756
 * @param[out] output_buf pointer to union where requested information will
9757
 *                          be stored
9758
 * @return #MHD_SC_OK if succeed,
9759
 *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
9760
 *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
9761
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9762
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
9763
 *                                              is not available for this
9764
 *                                              daemon due to the daemon
9765
 *                                              configuration/mode,
9766
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
9767
 *                                            should be available for
9768
 *                                            the daemon, but cannot be provided
9769
 *                                            due to some error or other
9770
 *                                            reasons,
9771
 *         other error codes in case of other errors
9772
 * @ingroup specialized
9773
 */
9774
#define MHD_daemon_get_info_fixed(daemon, info_type, output_buf) \
9775
        MHD_daemon_get_info_fixed_sz ((daemon), (info_type), (output_buf), \
9776
                                      sizeof(*(output_buf)))
9777
9778
9779
/**
9780
 * Values of this enum are used to specify what
9781
 * information about a daemon is desired.
9782
 * This types of information may be changed after the start of the daemon.
9783
 */
9784
enum MHD_DaemonInfoDynamicType
9785
{
9786
  /**
9787
   * The the maximum number of millisecond from the current moment until
9788
   * the mandatory call of the daemon data processing function (like
9789
   * #MHD_daemon_process_reg_events(), #MHD_daemon_process_blocking()).
9790
   * If resulting value is zero then daemon data processing function should be
9791
   * called as soon as possible as some data processing is already pending.
9792
   * The data processing function can also be called earlier as well.
9793
   * Available only for daemons stated in #MHD_WM_EXTERNAL_PERIODIC,
9794
   * #MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL, #MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE
9795
   * or #MHD_WM_EXTERNAL_SINGLE_FD_WATCH modes.
9796
   * The function returns #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the daemon has
9797
   * internal handling of events (internal threads).
9798
   * The result is placed in @a v_max_time_to_wait_uint64 member.
9799
   */
9800
  MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT = 1
9801
  ,
9802
  /**
9803
   * Check whether the daemon has any connected network clients.
9804
   * The result is placed in @a v_has_connections_bool member.
9805
   */
9806
  MHD_DAEMON_INFO_DYNAMIC_HAS_CONNECTIONS = 20
9807
  ,
9808
  /* * Sentinel * */
9809
  /**
9810
   * The sentinel value.
9811
   * This value enforces specific underlying integer type for the enum.
9812
   * Do not use.
9813
   */
9814
  MHD_DAEMON_INFO_DYNAMIC_SENTINEL = 65535
9815
};
9816
9817
9818
/**
9819
 * Information about an MHD daemon.
9820
 */
9821
union MHD_DaemonInfoDynamicData
9822
{
9823
  /**
9824
   * The data for the #MHD_DAEMON_INFO_DYNAMIC_MAX_TIME_TO_WAIT query
9825
   */
9826
  uint_fast64_t v_max_time_to_wait_uint64;
9827
9828
  /**
9829
   * The data for the #MHD_DAEMON_INFO_DYNAMIC_HAS_CONNECTIONS query
9830
   */
9831
  enum MHD_Bool v_has_connections_bool;
9832
9833
  /**
9834
   * Unused member.
9835
   * Help enforcing future-proof alignment of the union.
9836
   * Do not use.
9837
   */
9838
  void *reserved;
9839
};
9840
9841
9842
/**
9843
 * Obtain dynamic information about the given daemon.
9844
 * This information may be changed after the start of the daemon.
9845
 * The wrapper macro #MHD_daemon_get_info_dynamic() could be more convenient.
9846
 *
9847
 * @param daemon the daemon to get information about
9848
 * @param info_type the type of information requested
9849
 * @param[out] output_buf the pointer to union to be set to the requested
9850
 *                        information
9851
 * @param output_buf_size the size of the memory area pointed by @a output_buf
9852
 *                        (provided by the caller for storing the requested
9853
 *                        information), in bytes
9854
 * @return #MHD_SC_OK if succeed,
9855
 *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
9856
 *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
9857
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9858
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
9859
 *                                              is not available for this
9860
 *                                              daemon due to the daemon
9861
 *                                              configuration/mode,
9862
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
9863
 *                                            should be available for
9864
 *                                            the daemon, but cannot be provided
9865
 *                                            due to some error or other
9866
 *                                            reasons,
9867
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
9868
 *         other error codes in case of other errors
9869
 * @ingroup specialized
9870
 */
9871
MHD_EXTERN_ enum MHD_StatusCode
9872
MHD_daemon_get_info_dynamic_sz (
9873
  struct MHD_Daemon *MHD_RESTRICT daemon,
9874
  enum MHD_DaemonInfoDynamicType info_type,
9875
  union MHD_DaemonInfoDynamicData *MHD_RESTRICT output_buf,
9876
  size_t output_buf_size)
9877
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
9878
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
9879
9880
/**
9881
 * Obtain dynamic information about the given daemon.
9882
 * This types of information may be changed after the start of the daemon.
9883
 *
9884
 * @param daemon the daemon to get information about
9885
 * @param info_type the type of information requested
9886
 * @param[out] output_buf the pointer to union to be set to the requested
9887
 *                        information
9888
 * @return #MHD_SC_OK if succeed,
9889
 *         #MHD_SC_TOO_EARLY if the daemon has not been started yet,
9890
 *         #MHD_SC_TOO_LATE if the daemon is being stopped or has failed,
9891
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
9892
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
9893
 *                                              is not available for this
9894
 *                                              daemon due to the daemon
9895
 *                                              configuration/mode,
9896
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
9897
 *                                            should be available for
9898
 *                                            the daemon, but cannot be provided
9899
 *                                            due to some error or other
9900
 *                                            reasons,
9901
 *         other error codes in case of other errors
9902
 * @ingroup specialized
9903
 */
9904
#define MHD_daemon_get_info_dynamic(daemon, info_type, output_buf) \
9905
        MHD_daemon_get_info_dynamic_sz ((daemon), (info_type), (output_buf), \
9906
                                        sizeof(*(output_buf)))
9907
9908
9909
/**
9910
 * Select which fixed information about connection is desired.
9911
 * This information is not changed during the lifetime of the connection.
9912
 */
9913
enum MHD_ConnectionInfoFixedType
9914
{
9915
  /**
9916
   * Get the network address of the client.
9917
   * If the connection does not have known remote address (was not provided
9918
   * by the system or by the application in case of externally added
9919
   * connection) then error code #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE is
9920
   * returned if connection is IP type or unknown type or error code
9921
   * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if connection type is non-IP.
9922
   * The @a sa pointer is never NULL if the function succeed (#MHD_SC_OK
9923
   * returned).
9924
   * The result is placed in @a v_client_address_sa_info member.
9925
   * @ingroup request
9926
   */
9927
  MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS = 1
9928
  ,
9929
  /**
9930
   * Get the file descriptor for the connection socket.
9931
   * The provided socket must be used as 'read-only': only select() or similar
9932
   * functions should be used. Any modifications (changing socket attributes,
9933
   * calling send() or recv(), closing it etc.) will lead to undefined
9934
   * behaviour.
9935
   * The result is placed in @a v_connection_socket member.
9936
   * @ingroup request
9937
   */
9938
  MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET = 2
9939
  ,
9940
  /**
9941
   * Get the `struct MHD_Daemon *` responsible for managing this connection.
9942
   * The result is placed in @a v_daemon member.
9943
   * @ingroup request
9944
   */
9945
  MHD_CONNECTION_INFO_FIXED_DAEMON = 20
9946
  ,
9947
  /**
9948
   * Returns the pointer to a variable pointing to connection-specific
9949
   * application context data that was (possibly) set during
9950
   * a #MHD_NotifyConnectionCallback or provided via @a connection_cntx
9951
   * parameter of #MHD_daemon_add_connection().
9952
   * By using provided pointer application may get or set the pointer to
9953
   * any data specific for the particular connection.
9954
   * Note: resulting data is NOT the context pointer itself.
9955
   * The result is placed in @a v_app_context_ppvoid member.
9956
   * @ingroup request
9957
   */
9958
  MHD_CONNECTION_INFO_FIXED_APP_CONTEXT = 30
9959
  ,
9960
9961
  /* * Sentinel * */
9962
  /**
9963
   * The sentinel value.
9964
   * This value enforces specific underlying integer type for the enum.
9965
   * Do not use.
9966
   */
9967
  MHD_CONNECTION_INFO_FIXED_SENTINEL = 65535
9968
};
9969
9970
/**
9971
 * Socket address information data
9972
 */
9973
struct MHD_ConnInfoFixedSockAddr
9974
{
9975
  /**
9976
   * The size of the @a sa
9977
   */
9978
  size_t sa_size;
9979
9980
  /**
9981
   * Socket Address type
9982
   */
9983
  const struct sockaddr *sa;
9984
};
9985
9986
/**
9987
 * Information about a connection.
9988
 */
9989
union MHD_ConnectionInfoFixedData
9990
{
9991
9992
  /**
9993
   * The data for the #MHD_CONNECTION_INFO_FIXED_CLIENT_ADDRESS query
9994
   */
9995
  struct MHD_ConnInfoFixedSockAddr v_client_address_sa_info;
9996
9997
  /**
9998
   * The data for the #MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET query
9999
   */
10000
  MHD_Socket v_connection_socket;
10001
10002
  /**
10003
   * The data for the #MHD_CONNECTION_INFO_FIXED_DAEMON query
10004
   */
10005
  struct MHD_Daemon *v_daemon;
10006
10007
  /**
10008
   * The data for the #MHD_CONNECTION_INFO_FIXED_APP_CONTEXT query
10009
   */
10010
  void **v_app_context_ppvoid;
10011
};
10012
10013
10014
/**
10015
 * Obtain fixed information about the given connection.
10016
 * This information is not changed for the lifetime of the connection.
10017
 * The wrapper macro #MHD_connection_get_info_fixed() may be more convenient.
10018
 *
10019
 * @param connection the connection to get information about
10020
 * @param info_type the type of information requested
10021
 * @param[out] output_buf the pointer to union to be set to the requested
10022
 *                        information
10023
 * @param output_buf_size the size of the memory area pointed by @a output_buf
10024
 *                        (provided by the caller for storing the requested
10025
 *                        information), in bytes
10026
 * @return #MHD_SC_OK if succeed,
10027
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10028
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
10029
 *                                              is not available for this
10030
 *                                              connection due to the connection
10031
 *                                              configuration/mode,
10032
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
10033
 *                                            should be available for
10034
 *                                            the connection, but cannot be
10035
 *                                            provided due to some error or
10036
 *                                            other reasons,
10037
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
10038
 *         other error codes in case of other errors
10039
 * @ingroup specialized
10040
 */
10041
MHD_EXTERN_ enum MHD_StatusCode
10042
MHD_connection_get_info_fixed_sz (
10043
  struct MHD_Connection *MHD_RESTRICT connection,
10044
  enum MHD_ConnectionInfoFixedType info_type,
10045
  union MHD_ConnectionInfoFixedData *MHD_RESTRICT output_buf,
10046
  size_t output_buf_size)
10047
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
10048
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
10049
10050
10051
/**
10052
 * Obtain fixed information about the given connection.
10053
 * This information is not changed for the lifetime of the connection.
10054
 *
10055
 * @param connection the connection to get information about
10056
 * @param info_type the type of information requested
10057
 * @param[out] output_buf the pointer to union to be set to the requested
10058
 *                        information
10059
 * @return #MHD_SC_OK if succeed,
10060
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10061
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
10062
 *                                              is not available for this
10063
 *                                              connection due to the connection
10064
 *                                              configuration/mode,
10065
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
10066
 *                                            should be available for
10067
 *                                            the connection, but cannot be
10068
 *                                            provided due to some error or
10069
 *                                            other reasons,
10070
 *         other error codes in case of other errors
10071
 * @ingroup specialized
10072
 */
10073
#define MHD_connection_get_info_fixed(connection, info_type, output_buf) \
10074
        MHD_connection_get_info_fixed_sz ((connection),(info_type), \
10075
                                          (output_buf), sizeof(*(output_buf)))
10076
10077
10078
/**
10079
 * Select which dynamic information about connection is desired.
10080
 * This information may be changed during the lifetime of the connection.
10081
 */
10082
enum MHD_ConnectionInfoDynamicType
10083
{
10084
  /**
10085
   * Get current version of HTTP protocol used for connection.
10086
   * If connection is handling HTTP/1.x requests the function may return
10087
   * error code #MHD_SC_TOO_EARLY if the full request line has not been received
10088
   * yet for the current request.
10089
   * The result is placed in @a v_http_ver member.
10090
   * @ingroup request
10091
   */
10092
  MHD_CONNECTION_INFO_DYNAMIC_HTTP_VER = 1
10093
  ,
10094
  /**
10095
   * Get connection timeout value.
10096
   * This is the total number of milliseconds after which the idle
10097
   * connection is automatically disconnected.
10098
   * Note: the value set is NOT the number of milliseconds left before
10099
   * automatic disconnection.
10100
   * The result is placed in @a v_connection_timeout_uint32 member.
10101
   * @ingroup request
10102
   */
10103
  MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_TIMEOUT_MILSEC = 10
10104
  ,
10105
  /**
10106
   * Check whether the connection is suspended.
10107
   * The result is placed in @a v_connection_suspended_bool member.
10108
   * @ingroup request
10109
   */
10110
  MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED = 11
10111
  ,
10112
  /**
10113
   * Get current version of TLS transport protocol used for connection
10114
   * If plain TCP connection is used then #MHD_TLS_VERSION_NO_TLS set in
10115
   * the data.
10116
   * It TLS handshake is not yet finished then error code #MHD_SC_TOO_EARLY is
10117
   * returned. If TLS has failed or being closed then #MHD_SC_TOO_LATE error
10118
   * code is returned.
10119
   * If TLS version cannot be detected for any reason then error code
10120
   * #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE is returned.
10121
   * The result is placed in @a v_tls_ver member.
10122
   * @ingroup request
10123
   */
10124
  MHD_CONNECTION_INFO_DYNAMIC_TLS_VER = 105
10125
  ,
10126
  /**
10127
   * Get the TLS backend session handle.
10128
   * If plain TCP connection is used then the function returns error code
10129
   * #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE.
10130
   * The resulting union has only one valid member.
10131
   * The result is placed in @a v_tls_session member.
10132
   * @ingroup request
10133
   */
10134
  MHD_CONNECTION_INFO_DYNAMIC_TLS_SESSION = 140
10135
  ,
10136
10137
  /* * Sentinel * */
10138
  /**
10139
   * The sentinel value.
10140
   * This value enforces specific underlying integer type for the enum.
10141
   * Do not use.
10142
   */
10143
  MHD_CONNECTION_INFO_DYNAMIC_SENTINEL = 65535
10144
};
10145
10146
10147
/**
10148
 * The versions of TLS protocol
10149
 */
10150
enum MHD_FIXED_ENUM_MHD_SET_ MHD_TlsVersion
10151
{
10152
10153
  /**
10154
   * No TLS / plain socket connection
10155
   */
10156
  MHD_TLS_VERSION_NO_TLS = 0
10157
  ,
10158
  /**
10159
   * Not supported/failed to negotiate/failed to handshake TLS
10160
   */
10161
  MHD_TLS_VERSION_BROKEN = 1
10162
  ,
10163
  /**
10164
   * TLS version 1.0
10165
   */
10166
  MHD_TLS_VERSION_1_0 = 2
10167
  ,
10168
  /**
10169
   * TLS version 1.1
10170
   */
10171
  MHD_TLS_VERSION_1_1 = 3
10172
  ,
10173
  /**
10174
   * TLS version 1.2
10175
   */
10176
  MHD_TLS_VERSION_1_2 = 4
10177
  ,
10178
  /**
10179
   * TLS version 1.3
10180
   */
10181
  MHD_TLS_VERSION_1_3 = 5
10182
  ,
10183
  /**
10184
   * Some unknown TLS version.
10185
   * The TLS version is supported by TLS backend, but unknown to MHD.
10186
   */
10187
  MHD_TLS_VERSION_UNKNOWN = 1999
10188
};
10189
10190
/**
10191
 * Connection TLS session information.
10192
 * Only one member is valid. Use #MHD_DAEMON_INFO_FIXED_TLS_TYPE to find out
10193
 * which member should be used.
10194
 */
10195
union MHD_ConnInfoDynamicTlsSess
10196
{
10197
  /* Include <gnutls/gnutls.h> before this header to get a better type safety */
10198
  /**
10199
   * GnuTLS session handle, of type "gnutls_session_t".
10200
   */
10201
#if defined(GNUTLS_VERSION_MAJOR) && GNUTLS_VERSION_MAJOR >= 3
10202
  gnutls_session_t v_gnutls_session;
10203
#else
10204
  void * /* gnutls_session_t */ v_gnutls_session;
10205
#endif
10206
10207
  /* Include <openssl/types.h> or <openssl/crypto.h> before this header to get
10208
     a better type safety */
10209
  /**
10210
   * OpenSSL session handle, of type "SSL*".
10211
   */
10212
#if defined(OPENSSL_TYPES_H) && OPENSSL_VERSION_MAJOR >= 3
10213
  SSL *v_openssl_session;
10214
#else
10215
  void /* SSL */ *v_openssl_session;
10216
#endif
10217
10218
  /* Include <mbedtls/ssl.h> before this header to get a better type safety */
10219
  /**
10220
   * MbedTLS session handle, of type "mbedtls_ssl_context*".
10221
   */
10222
#if defined(MBEDTLS_SSL_H)
10223
  mbedtls_ssl_context *v_mbedtls_session;
10224
#else
10225
  void /* mbedtls_ssl_context */ *v_mbedtls_session;
10226
#endif
10227
};
10228
10229
/**
10230
 * Information about a connection.
10231
 */
10232
union MHD_ConnectionInfoDynamicData
10233
{
10234
  /**
10235
   * The data for the #MHD_CONNECTION_INFO_DYNAMIC_HTTP_VER query
10236
   */
10237
  enum MHD_HTTP_ProtocolVersion v_http_ver;
10238
10239
  /**
10240
   * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_TIMEOUT_MILSEC
10241
   * query
10242
   */
10243
  uint_fast32_t v_connection_timeout_uint32;
10244
10245
  /**
10246
   * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED query
10247
   */
10248
  enum MHD_Bool v_connection_suspended_bool;
10249
10250
  /**
10251
   * The data for the #MHD_CONNECTION_INFO_DYNAMIC_CONNECTION_SUSPENDED query
10252
   */
10253
  enum MHD_TlsVersion v_tls_ver;
10254
10255
  /**
10256
   * Connection TLS session information.
10257
   * Only one member is valid. Use #MHD_DAEMON_INFO_FIXED_TLS_TYPE to find out
10258
   * which member should be used.
10259
   */
10260
  union MHD_ConnInfoDynamicTlsSess v_tls_session;
10261
};
10262
10263
/**
10264
 * Obtain dynamic information about the given connection.
10265
 * This information may be changed during the lifetime of the connection.
10266
 *
10267
 * The wrapper macro #MHD_connection_get_info_dynamic() may be more convenient.
10268
 *
10269
 * @param connection the connection to get information about
10270
 * @param info_type the type of information requested
10271
 * @param[out] output_buf the pointer to union to be set to the requested
10272
 *                        information
10273
 * @param output_buf_size the size of the memory area pointed by @a output_buf
10274
 *                        (provided by the caller for storing the requested
10275
 *                        information), in bytes
10276
 * @return #MHD_SC_OK if succeed,
10277
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10278
 *         #MHD_SC_TOO_EARLY if the connection has not reached yet required
10279
 *                           state,
10280
 *         #MHD_SC_TOO_LATE if the connection is already in state where
10281
 *                          the requested information is not available,
10282
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
10283
 *                                              is not available for this
10284
 *                                              connection due to the connection
10285
 *                                              configuration/mode,
10286
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
10287
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
10288
 *                                            should be available for
10289
 *                                            the connection, but cannot be
10290
 *                                            provided due to some error or
10291
 *                                            other reasons,
10292
 *         other error codes in case of other errors
10293
 * @ingroup specialized
10294
 */
10295
MHD_EXTERN_ enum MHD_StatusCode
10296
MHD_connection_get_info_dynamic_sz (
10297
  struct MHD_Connection *MHD_RESTRICT connection,
10298
  enum MHD_ConnectionInfoDynamicType info_type,
10299
  union MHD_ConnectionInfoDynamicData *MHD_RESTRICT output_buf,
10300
  size_t output_buf_size)
10301
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
10302
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
10303
10304
10305
/**
10306
 * Obtain dynamic information about the given connection.
10307
 * This information may be changed during the lifetime of the connection.
10308
 *
10309
 * @param connection the connection to get information about
10310
 * @param info_type the type of information requested
10311
 * @param[out] output_buf the pointer to union to be set to the requested
10312
 *                        information
10313
 * @return #MHD_SC_OK if succeed,
10314
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10315
 *         #MHD_SC_TOO_EARLY if the connection has not reached yet required
10316
 *                           state,
10317
 *         #MHD_SC_TOO_LATE if the connection is already in state where
10318
 *                          the requested information is not available,
10319
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information
10320
 *                                              is not available for this
10321
 *                                              connection due to the connection
10322
 *                                              configuration/mode,
10323
 *         #MHD_SC_INFO_GET_TYPE_UNOBTAINABLE if the requested information
10324
 *                                            should be available for
10325
 *                                            the connection, but cannot be
10326
 *                                            provided due to some error or
10327
 *                                            other reasons,
10328
 *         other error codes in case of other errors
10329
 * @ingroup specialized
10330
 */
10331
#define MHD_connection_get_info_dynamic(connection, info_type, output_buf) \
10332
        MHD_connection_get_info_dynamic_sz ((connection),(info_type), \
10333
                                            (output_buf),sizeof(*(output_buf)))
10334
10335
10336
/**
10337
 * Select which fixed information about stream is desired.
10338
 * This information is not changed during the lifetime of the connection.
10339
 */
10340
enum MHD_FIXED_ENUM_APP_SET_ MHD_StreamInfoFixedType
10341
{
10342
  /**
10343
   * Get the `struct MHD_Daemon *` responsible for managing connection which
10344
   * is responsible for this stream.
10345
   * The result is placed in @a v_daemon member.
10346
   * @ingroup request
10347
   */
10348
  MHD_STREAM_INFO_FIXED_DAEMON = 20
10349
  ,
10350
  /**
10351
   * Get the `struct MHD_Connection *` responsible for managing this stream.
10352
   * The result is placed in @a v_connection member.
10353
   * @ingroup request
10354
   */
10355
  MHD_STREAM_INFO_FIXED_CONNECTION = 21
10356
  ,
10357
10358
  /* * Sentinel * */
10359
  /**
10360
   * The sentinel value.
10361
   * This value enforces specific underlying integer type for the enum.
10362
   * Do not use.
10363
   */
10364
  MHD_STREAM_INFO_FIXED_SENTINEL = 65535
10365
};
10366
10367
10368
/**
10369
 * Fixed information about a stream.
10370
 */
10371
union MHD_StreamInfoFixedData
10372
{
10373
  /**
10374
   * The data for the #MHD_STREAM_INFO_FIXED_DAEMON query
10375
   */
10376
  struct MHD_Daemon *v_daemon;
10377
  /**
10378
   * The data for the #MHD_STREAM_INFO_FIXED_CONNECTION query
10379
   */
10380
  struct MHD_Connection *v_connection;
10381
};
10382
10383
10384
/**
10385
 * Obtain fixed information about the given stream.
10386
 * This information is not changed for the lifetime of the stream.
10387
 *
10388
 * The wrapper macro #MHD_stream_get_info_fixed() may be more convenient.
10389
 *
10390
 * @param stream the stream to get information about
10391
 * @param info_type the type of information requested
10392
 * @param[out] output_buf the pointer to union to be set to the requested
10393
 *                        information
10394
 * @param output_buf_size the size of the memory area pointed by @a output_buf
10395
 *                        (provided by the caller for storing the requested
10396
 *                        information), in bytes
10397
 * @return #MHD_SC_OK if succeed,
10398
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10399
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
10400
 *         other error codes in case of other errors
10401
 * @ingroup specialized
10402
 */
10403
MHD_EXTERN_ enum MHD_StatusCode
10404
MHD_stream_get_info_fixed_sz (
10405
  struct MHD_Stream *MHD_RESTRICT stream,
10406
  enum MHD_StreamInfoFixedType info_type,
10407
  union MHD_StreamInfoFixedData *MHD_RESTRICT output_buf,
10408
  size_t output_buf_size)
10409
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
10410
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
10411
10412
10413
/**
10414
 * Obtain fixed information about the given stream.
10415
 * This information is not changed for the lifetime of the tream.
10416
 *
10417
 * @param stream the stream to get information about
10418
 * @param info_type the type of information requested
10419
 * @param[out] output_buf the pointer to union to be set to the requested
10420
 *                        information
10421
 * @return #MHD_SC_OK if succeed,
10422
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10423
 *         other error codes in case of other errors
10424
 * @ingroup specialized
10425
 */
10426
#define MHD_stream_get_info_fixed(stream, info_type, output_buf) \
10427
        MHD_stream_get_info_fixed_sz ((stream),(info_type),(output_buf), \
10428
                                      sizeof(*(output_buf)))
10429
10430
10431
/**
10432
 * Select which fixed information about stream is desired.
10433
 * This information may be changed during the lifetime of the stream.
10434
 */
10435
enum MHD_FIXED_ENUM_APP_SET_ MHD_StreamInfoDynamicType
10436
{
10437
  /**
10438
   * Get the `struct MHD_Request *` for current request processed by the stream.
10439
   * If no request is being processed, the error code #MHD_SC_TOO_EARLY is
10440
   * returned.
10441
   * The result is placed in @a v_request member.
10442
   * @ingroup request
10443
   */
10444
  MHD_STREAM_INFO_DYNAMIC_REQUEST = 20
10445
  ,
10446
10447
  /* * Sentinel * */
10448
  /**
10449
   * The sentinel value.
10450
   * This value enforces specific underlying integer type for the enum.
10451
   * Do not use.
10452
   */
10453
  MHD_STREAM_INFO_DYNAMIC_SENTINEL = 65535
10454
};
10455
10456
10457
/**
10458
 * Dynamic information about stream.
10459
 * This information may be changed during the lifetime of the connection.
10460
 */
10461
union MHD_StreamInfoDynamicData
10462
{
10463
  /**
10464
   * The data for the #MHD_STREAM_INFO_DYNAMIC_REQUEST query
10465
   */
10466
  struct MHD_Request *v_request;
10467
};
10468
10469
/**
10470
 * Obtain dynamic information about the given stream.
10471
 * This information may be changed during the lifetime of the stream.
10472
 *
10473
 * The wrapper macro #MHD_stream_get_info_dynamic() may be more convenient.
10474
 *
10475
 * @param stream the stream to get information about
10476
 * @param info_type the type of information requested
10477
 * @param[out] output_buf the pointer to union to be set to the requested
10478
 *                        information
10479
 * @param output_buf_size the size of the memory area pointed by @a output_buf
10480
 *                        (provided by the caller for storing the requested
10481
 *                        information), in bytes
10482
 * @return #MHD_SC_OK if succeed,
10483
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10484
 *         #MHD_SC_TOO_EARLY if the stream has not reached yet required state,
10485
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
10486
 *         other error codes in case of other errors
10487
 * @ingroup specialized
10488
 */
10489
MHD_EXTERN_ enum MHD_StatusCode
10490
MHD_stream_get_info_dynamic_sz (
10491
  struct MHD_Stream *MHD_RESTRICT stream,
10492
  enum MHD_StreamInfoDynamicType info_type,
10493
  union MHD_StreamInfoDynamicData *MHD_RESTRICT output_buf,
10494
  size_t output_buf_size)
10495
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
10496
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
10497
10498
10499
/**
10500
 * Obtain dynamic information about the given stream.
10501
 * This information may be changed during the lifetime of the stream.
10502
 *
10503
 * @param stream the stream to get information about
10504
 * @param info_type the type of information requested
10505
 * @param[out] output_buf the pointer to union to be set to the requested
10506
 *                        information
10507
 * @return #MHD_SC_OK if succeed,
10508
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10509
 *         #MHD_SC_TOO_EARLY if the stream has not reached yet required state,
10510
 *         other error codes in case of other errors
10511
 * @ingroup specialized
10512
 */
10513
#define MHD_stream_get_info_dynamic(stream, info_type, output_buf) \
10514
        MHD_stream_get_info_dynamic_sz ((stream),(info_type),(output_buf), \
10515
                                        sizeof(*(output_buf)))
10516
10517
10518
/**
10519
 * Select which fixed information about request is desired.
10520
 * This information is not changed during the lifetime of the request.
10521
 */
10522
enum MHD_FIXED_ENUM_APP_SET_ MHD_RequestInfoFixedType
10523
{
10524
  /**
10525
   * Get the version of HTTP protocol used for the request.
10526
   * If request line has not been fully received yet then #MHD_SC_TOO_EARLY
10527
   * error code is returned.
10528
   * The result is placed in @a v_http_ver member.
10529
   * @ingroup request
10530
   */
10531
  MHD_REQUEST_INFO_FIXED_HTTP_VER = 1
10532
  ,
10533
  /**
10534
   * Get the HTTP method used for the request (as a enum).
10535
   * The result is placed in @a v_http_method member.
10536
   * @sa #MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STR
10537
   * @ingroup request
10538
   */
10539
  MHD_REQUEST_INFO_FIXED_HTTP_METHOD = 2
10540
  ,
10541
  /**
10542
   * Return MHD daemon to which the request belongs to.
10543
   * The result is placed in @a v_daemon member.
10544
   */
10545
  MHD_REQUEST_INFO_FIXED_DAEMON = 20
10546
  ,
10547
  /**
10548
   * Return which connection is associated with the stream which is associated
10549
   * with the request.
10550
   * The result is placed in @a v_connection member.
10551
   */
10552
  MHD_REQUEST_INFO_FIXED_CONNECTION = 21
10553
  ,
10554
  /**
10555
   * Return which stream the request is associated with.
10556
   * The result is placed in @a v_stream member.
10557
   */
10558
  MHD_REQUEST_INFO_FIXED_STREAM = 22
10559
  ,
10560
  /**
10561
   * Returns the pointer to a variable pointing to request-specific
10562
   * application context data. The same data is provided for
10563
   * #MHD_EarlyUriLogCallback and #MHD_RequestTerminationCallback.
10564
   * By using provided pointer application may get or set the pointer to
10565
   * any data specific for the particular request.
10566
   * Note: resulting data is NOT the context pointer itself.
10567
   * The result is placed in @a v_app_context_ppvoid member.
10568
   * @ingroup request
10569
   */
10570
  MHD_REQUEST_INFO_FIXED_APP_CONTEXT = 30
10571
  ,
10572
10573
  /* * Sentinel * */
10574
  /**
10575
   * The sentinel value.
10576
   * This value enforces specific underlying integer type for the enum.
10577
   * Do not use.
10578
   */
10579
  MHD_REQUEST_INFO_FIXED_SENTINEL = 65535
10580
};
10581
10582
10583
/**
10584
 * Fixed information about a request.
10585
 */
10586
union MHD_RequestInfoFixedData
10587
{
10588
10589
  /**
10590
   * The data for the #MHD_REQUEST_INFO_FIXED_HTTP_VER query
10591
   */
10592
  enum MHD_HTTP_ProtocolVersion v_http_ver;
10593
10594
  /**
10595
   * The data for the #MHD_REQUEST_INFO_FIXED_HTTP_METHOD query
10596
   */
10597
  enum MHD_HTTP_Method v_http_method;
10598
10599
  /**
10600
   * The data for the #MHD_REQUEST_INFO_FIXED_DAEMON query
10601
   */
10602
  struct MHD_Daemon *v_daemon;
10603
10604
  /**
10605
   * The data for the #MHD_REQUEST_INFO_FIXED_CONNECTION query
10606
   */
10607
  struct MHD_Connection *v_connection;
10608
10609
  /**
10610
   * The data for the #MHD_REQUEST_INFO_FIXED_STREAM query
10611
   */
10612
  struct MHD_Stream *v_stream;
10613
10614
  /**
10615
   * The data for the #MHD_REQUEST_INFO_FIXED_APP_CONTEXT query
10616
   */
10617
  void **v_app_context_ppvoid;
10618
};
10619
10620
/**
10621
 * Obtain fixed information about the given request.
10622
 * This information is not changed for the lifetime of the request.
10623
 *
10624
 * The wrapper macro #MHD_request_get_info_fixed() may be more convenient.
10625
 *
10626
 * @param request the request to get information about
10627
 * @param info_type the type of information requested
10628
 * @param[out] output_buf the pointer to union to be set to the requested
10629
 *                        information
10630
 * @param output_buf_size the size of the memory area pointed by @a output_buf
10631
 *                        (provided by the caller for storing the requested
10632
 *                        information), in bytes
10633
 * @return #MHD_SC_OK if succeed,
10634
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10635
 *         #MHD_SC_TOO_EARLY if the request processing has not reached yet
10636
 *                           the required state,
10637
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
10638
 *         other error codes in case of other errors
10639
 * @ingroup specialized
10640
 */
10641
MHD_EXTERN_ enum MHD_StatusCode
10642
MHD_request_get_info_fixed_sz (
10643
  struct MHD_Request *MHD_RESTRICT request,
10644
  enum MHD_RequestInfoFixedType info_type,
10645
  union MHD_RequestInfoFixedData *MHD_RESTRICT output_buf,
10646
  size_t output_buf_size)
10647
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
10648
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
10649
10650
10651
/**
10652
 * Obtain fixed information about the given request.
10653
 * This information is not changed for the lifetime of the request.
10654
 *
10655
 * @param request the request to get information about
10656
 * @param info_type the type of information requested
10657
 * @param[out] output_buf the pointer to union to be set to the requested
10658
 *                        information
10659
 * @return #MHD_SC_OK if succeed,
10660
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if @a info_type value is unknown,
10661
 *         #MHD_SC_TOO_EARLY if the request processing has not reached yet
10662
 *                           the required state,
10663
 *         other error codes in case of other errors
10664
 * @ingroup specialized
10665
 */
10666
#define MHD_request_get_info_fixed(request, info_type, output_buf) \
10667
        MHD_request_get_info_fixed_sz ((request), (info_type), (output_buf), \
10668
                                       sizeof(*(output_buf)))
10669
10670
10671
/**
10672
 * Select which dynamic information about request is desired.
10673
 * This information may be changed during the lifetime of the request.
10674
 * Any returned string pointers are valid only until a response is provided.
10675
 */
10676
enum MHD_FIXED_ENUM_APP_SET_ MHD_RequestInfoDynamicType
10677
{
10678
  /**
10679
   * Get the HTTP method used for the request (as a MHD_String).
10680
   * The resulting string pointer in valid only until a response is provided.
10681
   * The result is placed in @a v_http_method_string member.
10682
   * @sa #MHD_REQUEST_INFO_FIXED_HTTP_METHOD
10683
   * @ingroup request
10684
   */
10685
  MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING = 1
10686
  ,
10687
  /**
10688
   * Get the URI used for the request (as a MHD_String), excluding
10689
   * the parameter part (anything after '?').
10690
   * The resulting string pointer in valid only until a response is provided.
10691
   * The result is placed in @a v_uri_string member.
10692
   * @ingroup request
10693
   */
10694
  MHD_REQUEST_INFO_DYNAMIC_URI = 2
10695
  ,
10696
  /**
10697
   * Get the number of URI parameters (the decoded part of the original
10698
   * URI string after '?'). Sometimes it is called "GET parameters".
10699
   * The result is placed in @a v_number_uri_params_sizet member.
10700
   * @ingroup request
10701
   */
10702
  MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS = 3
10703
  ,
10704
  /**
10705
   * Get the number of cookies in the request.
10706
   * The result is placed in @a v_number_cookies_sizet member.
10707
   * If cookies parsing is disabled in MHD build then the function returns
10708
   * error code #MHD_SC_FEATURE_DISABLED.
10709
   * If cookies parsing is disabled this daemon then the function returns
10710
   * error code #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE.
10711
   * @ingroup request
10712
   */
10713
  MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES = 4
10714
  ,
10715
  /**
10716
   * Return length of the client's HTTP request header.
10717
   * This is a total raw size of the header (after TLS decipher if any)
10718
   * The result is placed in @a v_header_size_sizet member.
10719
   * @ingroup request
10720
   */
10721
  MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE = 5
10722
  ,
10723
  /**
10724
   * Get the number of decoded POST entries in the request.
10725
   * The result is placed in @a v_number_post_params_sizet member.
10726
   * @ingroup request
10727
   */
10728
  MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS = 6
10729
  ,
10730
  /**
10731
   * Get whether the upload content is present in the request.
10732
   * The result is #MHD_YES if any upload content is present, even
10733
   * if the upload content size is zero.
10734
   * The result is placed in @a v_upload_present_bool member.
10735
   * @ingroup request
10736
   */
10737
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT = 10
10738
  ,
10739
  /**
10740
   * Get whether the chunked upload content is present in the request.
10741
   * The result is #MHD_YES if chunked upload content is present.
10742
   * The result is placed in @a v_upload_chunked_bool member.
10743
   * @ingroup request
10744
   */
10745
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED = 11
10746
  ,
10747
  /**
10748
   * Get the total content upload size.
10749
   * Resulted in zero if no content upload or upload content size is zero,
10750
   * #MHD_SIZE_UNKNOWN if size is not known (chunked upload).
10751
   * The result is placed in @a v_upload_size_total_uint64 member.
10752
   * @ingroup request
10753
   */
10754
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL = 12
10755
  ,
10756
  /**
10757
   * Get the total size of the content upload already received from the client.
10758
   * This is the total size received, could be not yet fully processed by the
10759
   * application.
10760
   * The result is placed in @a v_upload_size_recieved_uint64 member.
10761
   * @ingroup request
10762
   */
10763
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED = 13
10764
  ,
10765
  /**
10766
   * Get the total size of the content upload left to be received from
10767
   * the client.
10768
   * Resulted in #MHD_SIZE_UNKNOWN if total size is not known (chunked upload).
10769
   * The result is placed in @a v_upload_size_to_recieve_uint64 member.
10770
   * @ingroup request
10771
   */
10772
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_RECIEVE = 14
10773
  ,
10774
  /**
10775
   * Get the total size of the content upload already processed (upload callback
10776
   * called and completed (if any)).
10777
   * If the value is requested from #MHD_UploadCallback, then result does NOT
10778
   * include the current data being processed by the callback.
10779
   * The result is placed in @a v_upload_size_processed_uint64 member.
10780
   * @ingroup request
10781
   */
10782
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_PROCESSED = 15
10783
  ,
10784
  /**
10785
   * Get the total size of the content upload left to be processed.
10786
   * The resulting value includes the size of the data not yet received from
10787
   * the client.
10788
   * If the value is requested from #MHD_UploadCallback, then result includes
10789
   * the current data being processed by the callback.
10790
   * Resulted in #MHD_SIZE_UNKNOWN if total size is not known (chunked upload).
10791
   * The result is placed in @a v_upload_size_to_process_uint64 member.
10792
   * @ingroup request
10793
   */
10794
  MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_PROCESS = 16
10795
  ,
10796
  /**
10797
   * Returns pointer to information about digest auth in client request.
10798
   * The resulting pointer is NULL if no digest auth header is set by
10799
   * the client or the format of the digest auth header is broken.
10800
   * Pointers in the returned structure (if any) are valid until response
10801
   * is provided for the request.
10802
   * The result is placed in @a v_auth_digest_info member.
10803
   */
10804
  MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO = 42
10805
  ,
10806
  /**
10807
   * Returns information about Basic Authentication credentials in the request.
10808
   * Pointers in the returned structure (if any) are valid until any MHD_Action
10809
   * or MHD_UploadAction is provided. If the data is needed beyond this point,
10810
   * it should be copied.
10811
   * If #MHD_request_get_info_dynamic_sz() returns #MHD_SC_OK then
10812
   * @a v_auth_basic_creds is NOT NULL and at least the username data
10813
   * is provided.
10814
   * The result is placed in @a v_auth_basic_creds member.
10815
   */
10816
  MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS = 51
10817
  ,
10818
  /* * Sentinel * */
10819
  /**
10820
   * The sentinel value.
10821
   * This value enforces specific underlying integer type for the enum.
10822
   * Do not use.
10823
   */
10824
  MHD_REQUEST_INFO_DYNAMIC_SENTINEL = 65535
10825
};
10826
10827
10828
/**
10829
 * Dynamic information about a request.
10830
 */
10831
union MHD_RequestInfoDynamicData
10832
{
10833
10834
  /**
10835
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_HTTP_METHOD_STRING query
10836
   */
10837
  struct MHD_String v_http_method_string;
10838
10839
  /**
10840
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_URI query
10841
   */
10842
  struct MHD_String v_uri_string;
10843
10844
  /**
10845
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_URI_PARAMS query
10846
   */
10847
  size_t v_number_uri_params_sizet;
10848
10849
  /**
10850
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES query
10851
   */
10852
  size_t v_number_cookies_sizet;
10853
10854
  /**
10855
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_HEADER_SIZE query
10856
   */
10857
  size_t v_header_size_sizet;
10858
10859
  /**
10860
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_NUMBER_POST_PARAMS query
10861
   */
10862
  size_t v_number_post_params_sizet;
10863
10864
  /**
10865
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_PRESENT query
10866
   */
10867
  enum MHD_Bool v_upload_present_bool;
10868
10869
  /**
10870
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_CHUNKED query
10871
   */
10872
  enum MHD_Bool v_upload_chunked_bool;
10873
10874
  /**
10875
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TOTAL query
10876
   */
10877
  uint_fast64_t v_upload_size_total_uint64;
10878
10879
  /**
10880
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_RECIEVED query
10881
   */
10882
  uint_fast64_t v_upload_size_recieved_uint64;
10883
10884
  /**
10885
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_RECIEVE query
10886
   */
10887
  uint_fast64_t v_upload_size_to_recieve_uint64;
10888
10889
  /**
10890
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_PROCESSED query
10891
   */
10892
  uint_fast64_t v_upload_size_processed_uint64;
10893
10894
  /**
10895
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_UPLOAD_SIZE_TO_PROCESS query
10896
   */
10897
  uint_fast64_t v_upload_size_to_process_uint64;
10898
10899
  /**
10900
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_AUTH_DIGEST_INFO query
10901
   */
10902
  const struct MHD_AuthDigestInfo *v_auth_digest_info;
10903
10904
  /**
10905
   * The data for the #MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS query
10906
   */
10907
  const struct MHD_AuthBasicCreds *v_auth_basic_creds;
10908
};
10909
10910
10911
/**
10912
 * Obtain dynamic information about the given request.
10913
 * This information may be changed during the lifetime of the request.
10914
 * Most of the data provided is available only when the request line or complete
10915
 * request headers are processed and not available if responding has been
10916
 * started.
10917
 *
10918
 * The wrapper macro #MHD_request_get_info_dynamic() may be more convenient.
10919
 *
10920
 * Any pointers in the returned data are valid until any MHD_Action or
10921
 * MHD_UploadAction is provided. If the data is needed beyond this point,
10922
 * it should be copied.
10923
 *
10924
 * @param request the request to get information about
10925
 * @param info_type the type of information requested
10926
 * @param[out] output_buf the pointer to union to be set to the requested
10927
 *                        information
10928
 * @param output_buf_size the size of the memory area pointed by @a output_buf
10929
 *                        (provided by the caller for storing the requested
10930
 *                        information), in bytes
10931
 * @return #MHD_SC_OK if succeed,
10932
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if requested information type is
10933
 *                                       not recognized by MHD,
10934
 *         #MHD_SC_TOO_LATE if request is already being closed or the response
10935
 *                          is being sent
10936
 *         #MHD_SC_TOO_EARLY if requested data is not yet ready (for example,
10937
 *                           headers are not yet received),
10938
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information is
10939
 *                                              not available for this request
10940
 *                                              due to used configuration/mode,
10941
 *         #MHD_SC_FEATURE_DISABLED if requested functionality is not supported
10942
 *                                  by this MHD build,
10943
 *         #MHD_SC_INFO_GET_BUFF_TOO_SMALL if @a output_buf_size is too small,
10944
 *         #MHD_SC_AUTH_ABSENT if request does not have particular Auth data,
10945
 *         #MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA if connection memory pool
10946
 *                                                  has no space to put decoded
10947
 *                                                  authentication data,
10948
 *         #MHD_SC_REQ_AUTH_DATA_BROKEN if the format of authentication data is
10949
 *                                      incorrect or broken,
10950
 *         other error codes in case of other errors
10951
 * @ingroup specialized
10952
 */
10953
MHD_EXTERN_ enum MHD_StatusCode
10954
MHD_request_get_info_dynamic_sz (
10955
  struct MHD_Request *MHD_RESTRICT request,
10956
  enum MHD_RequestInfoDynamicType info_type,
10957
  union MHD_RequestInfoDynamicData *MHD_RESTRICT output_buf,
10958
  size_t output_buf_size)
10959
MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (1)
10960
MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3);
10961
10962
10963
/**
10964
 * Obtain dynamic information about the given request.
10965
 * This information may be changed during the lifetime of the request.
10966
 * Most of the data provided is available only when the request line or complete
10967
 * request headers are processed and not available if responding has been
10968
 * started.
10969
 *
10970
 * Any pointers in the returned data are valid until any MHD_Action or
10971
 * MHD_UploadAction is provided. If the data is needed beyond this point,
10972
 * it should be copied.
10973
 *
10974
 * @param request the request to get information about
10975
 * @param info_type the type of information requested
10976
 * @param[out] output_buf the pointer to union to be set to the requested
10977
 *                        information
10978
 * @return #MHD_SC_OK if succeed,
10979
 *         #MHD_SC_INFO_GET_TYPE_UNKNOWN if requested information type is
10980
 *                                       not recognized by MHD,
10981
 *         #MHD_SC_TOO_LATE if request is already being closed or the response
10982
 *                          is being sent
10983
 *         #MHD_SC_TOO_EARLY if requested data is not yet ready (for example,
10984
 *                           headers are not yet received),
10985
 *         #MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE if the requested information is
10986
 *                                              not available for this request
10987
 *                                              due to used configuration/mode,
10988
 *         #MHD_SC_FEATURE_DISABLED if requested functionality is not supported
10989
 *                                  by this MHD build,
10990
 *         #MHD_SC_AUTH_ABSENT if request does not have particular Auth data,
10991
 *         #MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA if connection memory pool
10992
 *                                                  has no space to put decoded
10993
 *                                                  authentication data,
10994
 *         #MHD_SC_REQ_AUTH_DATA_BROKEN if the format of authentication data is
10995
 *                                      incorrect or broken,
10996
 *         other error codes in case of other errors
10997
 * @ingroup specialized
10998
 */
10999
#define MHD_request_get_info_dynamic(request, info_type, output_buf) \
11000
        MHD_request_get_info_dynamic_sz ((request), (info_type), \
11001
                                         (output_buf), \
11002
                                         sizeof(*(output_buf)))
11003
11004
/**
11005
 * Callback for serious error condition. The default action is to print
11006
 * an error message and `abort()`.
11007
 * The callback should not return.
11008
 * Some parameters could be empty strings (the strings with zero-termination at
11009
 * zero position) if MHD built without log messages (only for embedded
11010
 * projects).
11011
 *
11012
 * @param cls user specified value
11013
 * @param file where the error occurred, could be empty
11014
 * @param func the name of the function, where the error occurred, may be empty
11015
 * @param line where the error occurred
11016
 * @param message the error details, could be empty
11017
 * @ingroup logging
11018
 */
11019
typedef void
11020
(*MHD_PanicCallback)(void *cls,
11021
                     const char *file,
11022
                     const char *func,
11023
                     unsigned int line,
11024
                     const char *message);
11025
11026
11027
/**
11028
 * Sets the global error handler to a different implementation.
11029
 * The @a cb will only be called in the case of typically fatal, serious
11030
 * internal consistency issues.
11031
 * These issues should only arise in the case of serious memory corruption or
11032
 * similar problems with the architecture.
11033
 * The @a cb should not return.
11034
 *
11035
 * The default implementation that is used if no panic function is set
11036
 * simply prints an error message and calls `abort()`.  Alternative
11037
 * implementations might call `exit()` or other similar functions.
11038
 *
11039
 * @param cb new error handler, NULL to reset to default handler
11040
 * @param cls passed to @a cb
11041
 * @ingroup logging
11042
 */
11043
MHD_EXTERN_ void
11044
MHD_lib_set_panic_func (MHD_PanicCallback cb,
11045
                        void *cls);
11046
11047
#define MHD_lib_set_panic_func_default() \
11048
        MHD_lib_set_panic_func (MHD_STATIC_CAST_ (MHD_PanicCallback,NULL),NULL)
11049
MHD_C_DECLARATIONS_FINISH_HERE_
11050
11051
#endif /* ! MICROHTTPD2_H */