Coverage Report

Created: 2025-08-26 06:29

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