libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

microhttpd2_generated_response_options.h (18645B)


      1 /**
      2  * The options (parameters) for MHD response
      3  */
      4 enum MHD_FIXED_ENUM_APP_SET_ MHD_ResponseOption
      5 {  /**
      6    * Not a real option.
      7    * Should not be used directly.
      8    * This value indicates the end of the list of the options.
      9    */
     10   MHD_R_O_END = 0
     11   ,
     12 
     13   /**
     14    * Make the response object re-usable.
     15    * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
     16    * Useful if the same response is often used to reply.
     17    */
     18   MHD_R_O_REUSABLE = 20
     19   ,
     20 
     21   /**
     22    * 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.
     23    * The flag also allow to set arbitrary 'Content-Length' by #MHD_response_add_header() function.
     24    * This flag value can be used only with responses created without body (zero-size body).
     25    * Responses with this flag enabled cannot be used in situations where reply body must be sent to the client.
     26    * This flag is primarily intended to be used when automatic 'Content-Length' header is undesirable in response to HEAD requests.
     27    */
     28   MHD_R_O_HEAD_ONLY_RESPONSE = 40
     29   ,
     30 
     31   /**
     32    * Force use of chunked encoding even if the response content size is known.
     33    * Ignored when the reply cannot have body/content.
     34    */
     35   MHD_R_O_CHUNKED_ENC = 41
     36   ,
     37 
     38   /**
     39    * Force close connection after sending the response, prevents keep-alive connections and adds 'Connection: close' header.
     40    */
     41   MHD_R_O_CONN_CLOSE = 60
     42   ,
     43 
     44   /**
     45    * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
     46    * 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.
     47    * You can also set the #MHD_R_O_HTTP_1_0_SERVER flag to force HTTP/1.0 version in the response.
     48    * Responses are still compatible with HTTP/1.1.
     49    * Summary:
     50    * + declared reply version: HTTP/1.1
     51    * + keep-alive: no
     52    * + chunked: no
     53    *
     54 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.
     55    */
     56   MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT = 80
     57   ,
     58 
     59   /**
     60    * Only respond in HTTP/1.0-mode.
     61    * 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.
     62    * The 'Connection:' header will be added for both 'close' and 'keep-alive' connections.
     63    * Chunked encoding will not be used for the response.
     64    * Due to backward compatibility, responses still can be used with HTTP/1.1 clients.
     65    * 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).
     66    * Summary:
     67    * + declared reply version: HTTP/1.0
     68    * + keep-alive: possible
     69    * + chunked: no
     70    *
     71 With this option HTTP/1.0 server is emulated (with support for 'keep-alive' connections).
     72    */
     73   MHD_R_O_HTTP_1_0_SERVER = 81
     74   ,
     75 
     76   /**
     77    * Disable sanity check preventing clients from manually setting the HTTP content length option.
     78    * Allow to set several 'Content-Length' headers. These headers will be used even with replies without body.
     79    */
     80   MHD_R_O_INSANITY_HEADER_CONTENT_LENGTH = 100
     81   ,
     82 
     83   /**
     84    * Set a function to be called once MHD is finished with the request.
     85    */
     86   MHD_R_O_TERMINATION_CALLBACK = 121
     87   ,
     88 
     89   /**
     90    * The sentinel value.
     91    * This value enforces specific underlying integer type for the enum.
     92    * Do not use.
     93    */
     94   MHD_R_O_SENTINEL = 65535
     95 
     96 };
     97 
     98 /**
     99  * Data for #MHD_R_O_TERMINATION_CALLBACK
    100  */
    101 struct MHD_ResponseOptionValueEndedCB
    102 {
    103   /**
    104    * the function to call,
    105    * NULL to not use the callback
    106    */
    107   MHD_RequestEndedCallback v_ended_cb;
    108 
    109   /**
    110    * the closure for the callback
    111    */
    112   void *v_ended_cb_cls;
    113 
    114 };
    115 
    116 /**
    117  * Parameters for MHD response options
    118  */
    119 union MHD_ResponseOptionValue
    120 {
    121   /**
    122    * Value for #MHD_R_O_REUSABLE.
    123    */
    124   enum MHD_Bool reusable;
    125 
    126   /**
    127    * Value for #MHD_R_O_HEAD_ONLY_RESPONSE.
    128    */
    129   enum MHD_Bool head_only_response;
    130 
    131   /**
    132    * Value for #MHD_R_O_CHUNKED_ENC.
    133    */
    134   enum MHD_Bool chunked_enc;
    135 
    136   /**
    137    * Value for #MHD_R_O_CONN_CLOSE.
    138    */
    139   enum MHD_Bool conn_close;
    140 
    141   /**
    142    * Value for #MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT.
    143    */
    144   enum MHD_Bool http_1_0_compatible_strict;
    145 
    146   /**
    147    * Value for #MHD_R_O_HTTP_1_0_SERVER.
    148    */
    149   enum MHD_Bool http_1_0_server;
    150 
    151   /**
    152    * Value for #MHD_R_O_INSANITY_HEADER_CONTENT_LENGTH.
    153    */
    154   enum MHD_Bool insanity_header_content_length;
    155 
    156   /**
    157    * Value for #MHD_R_O_TERMINATION_CALLBACK.
    158    * the function to call,
    159    * NULL to not use the callback
    160    */
    161   struct MHD_ResponseOptionValueEndedCB termination_callback;
    162 
    163 };
    164 
    165 
    166 struct MHD_ResponseOptionAndValue
    167 {
    168   /**
    169    * The response configuration option
    170    */
    171   enum MHD_ResponseOption opt;
    172 
    173   /**
    174    * The value for the @a opt option
    175    */
    176   union MHD_ResponseOptionValue val;
    177 };
    178 
    179 #if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT)
    180 /**
    181  * Make the response object re-usable.
    182  * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
    183  * Useful if the same response is often used to reply.
    184  * @param value the value of the parameter * @return structure with the requested setting
    185  */
    186 #  define MHD_R_OPTION_REUSABLE(value) \
    187         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    188           (const struct MHD_ResponseOptionAndValue) \
    189         { \
    190           .opt = MHD_R_O_REUSABLE,  \
    191           .val.reusable = (value) \
    192         } \
    193         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    194 /**
    195  * 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.
    196  * The flag also allow to set arbitrary 'Content-Length' by #MHD_response_add_header() function.
    197  * This flag value can be used only with responses created without body (zero-size body).
    198  * Responses with this flag enabled cannot be used in situations where reply body must be sent to the client.
    199  * This flag is primarily intended to be used when automatic 'Content-Length' header is undesirable in response to HEAD requests.
    200  * @param value the value of the parameter * @return structure with the requested setting
    201  */
    202 #  define MHD_R_OPTION_HEAD_ONLY_RESPONSE(value) \
    203         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    204           (const struct MHD_ResponseOptionAndValue) \
    205         { \
    206           .opt = MHD_R_O_HEAD_ONLY_RESPONSE,  \
    207           .val.head_only_response = (value) \
    208         } \
    209         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    210 /**
    211  * Force use of chunked encoding even if the response content size is known.
    212  * Ignored when the reply cannot have body/content.
    213  * @param value the value of the parameter * @return structure with the requested setting
    214  */
    215 #  define MHD_R_OPTION_CHUNKED_ENC(value) \
    216         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    217           (const struct MHD_ResponseOptionAndValue) \
    218         { \
    219           .opt = MHD_R_O_CHUNKED_ENC,  \
    220           .val.chunked_enc = (value) \
    221         } \
    222         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    223 /**
    224  * Force close connection after sending the response, prevents keep-alive connections and adds 'Connection: close' header.
    225  * @param value the value of the parameter * @return structure with the requested setting
    226  */
    227 #  define MHD_R_OPTION_CONN_CLOSE(value) \
    228         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    229           (const struct MHD_ResponseOptionAndValue) \
    230         { \
    231           .opt = MHD_R_O_CONN_CLOSE,  \
    232           .val.conn_close = (value) \
    233         } \
    234         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    235 /**
    236  * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
    237  * 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.
    238  * You can also set the #MHD_R_O_HTTP_1_0_SERVER flag to force HTTP/1.0 version in the response.
    239  * Responses are still compatible with HTTP/1.1.
    240  * Summary:
    241  * + declared reply version: HTTP/1.1
    242  * + keep-alive: no
    243  * + chunked: no
    244  *
    245 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.
    246  * @param value the value of the parameter * @return structure with the requested setting
    247  */
    248 #  define MHD_R_OPTION_HTTP_1_0_COMPATIBLE_STRICT(value) \
    249         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    250           (const struct MHD_ResponseOptionAndValue) \
    251         { \
    252           .opt = MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT,  \
    253           .val.http_1_0_compatible_strict = (value) \
    254         } \
    255         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    256 /**
    257  * Only respond in HTTP/1.0-mode.
    258  * 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.
    259  * The 'Connection:' header will be added for both 'close' and 'keep-alive' connections.
    260  * Chunked encoding will not be used for the response.
    261  * Due to backward compatibility, responses still can be used with HTTP/1.1 clients.
    262  * 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).
    263  * Summary:
    264  * + declared reply version: HTTP/1.0
    265  * + keep-alive: possible
    266  * + chunked: no
    267  *
    268 With this option HTTP/1.0 server is emulated (with support for 'keep-alive' connections).
    269  * @param value the value of the parameter * @return structure with the requested setting
    270  */
    271 #  define MHD_R_OPTION_HTTP_1_0_SERVER(value) \
    272         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    273           (const struct MHD_ResponseOptionAndValue) \
    274         { \
    275           .opt = MHD_R_O_HTTP_1_0_SERVER,  \
    276           .val.http_1_0_server = (value) \
    277         } \
    278         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    279 /**
    280  * Disable sanity check preventing clients from manually setting the HTTP content length option.
    281  * Allow to set several 'Content-Length' headers. These headers will be used even with replies without body.
    282  * @param value the value of the parameter * @return structure with the requested setting
    283  */
    284 #  define MHD_R_OPTION_INSANITY_HEADER_CONTENT_LENGTH(value) \
    285         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    286           (const struct MHD_ResponseOptionAndValue) \
    287         { \
    288           .opt = MHD_R_O_INSANITY_HEADER_CONTENT_LENGTH,  \
    289           .val.insanity_header_content_length = (value) \
    290         } \
    291         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    292 /**
    293  * Set a function to be called once MHD is finished with the request.
    294  * @param ended_cb the function to call,
    295  *   NULL to not use the callback
    296  * @param ended_cb_cls the closure for the callback
    297  * @return structure with the requested setting
    298  */
    299 #  define MHD_R_OPTION_TERMINATION_CALLBACK(ended_cb,ended_cb_cls) \
    300         MHD_NOWARN_COMPOUND_LITERALS_ MHD_NOWARN_AGGR_DYN_INIT_ \
    301           (const struct MHD_ResponseOptionAndValue) \
    302         { \
    303           .opt = MHD_R_O_TERMINATION_CALLBACK,  \
    304           .val.termination_callback.v_ended_cb = (ended_cb), \
    305           .val.termination_callback.v_ended_cb_cls = (ended_cb_cls) \
    306         } \
    307         MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
    308 
    309 /**
    310  * Terminate the list of the options
    311  * @return the terminating object of struct MHD_ResponseOptionAndValue
    312  */
    313 #  define MHD_R_OPTION_TERMINATE() \
    314         MHD_NOWARN_COMPOUND_LITERALS_ \
    315           (const struct MHD_ResponseOptionAndValue) \
    316         { \
    317           .opt = (MHD_R_O_END) \
    318         } \
    319         MHD_RESTORE_WARN_COMPOUND_LITERALS_
    320 
    321 #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
    322 MHD_NOWARN_UNUSED_FUNC_
    323 /**
    324  * Make the response object re-usable.
    325  * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
    326  * Useful if the same response is often used to reply.
    327  * @param value the value of the parameter * @return structure with the requested setting
    328  */
    329 static MHD_INLINE struct MHD_ResponseOptionAndValue
    330 MHD_R_OPTION_REUSABLE (
    331   enum MHD_Bool value
    332   )
    333 {
    334   struct MHD_ResponseOptionAndValue opt_val;
    335 
    336   opt_val.opt = MHD_R_O_REUSABLE;
    337   opt_val.val.reusable = (value); \
    338 
    339   return opt_val;
    340 }
    341 
    342 
    343 /**
    344  * 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.
    345  * The flag also allow to set arbitrary 'Content-Length' by #MHD_response_add_header() function.
    346  * This flag value can be used only with responses created without body (zero-size body).
    347  * Responses with this flag enabled cannot be used in situations where reply body must be sent to the client.
    348  * This flag is primarily intended to be used when automatic 'Content-Length' header is undesirable in response to HEAD requests.
    349  * @param value the value of the parameter * @return structure with the requested setting
    350  */
    351 static MHD_INLINE struct MHD_ResponseOptionAndValue
    352 MHD_R_OPTION_HEAD_ONLY_RESPONSE (
    353   enum MHD_Bool value
    354   )
    355 {
    356   struct MHD_ResponseOptionAndValue opt_val;
    357 
    358   opt_val.opt = MHD_R_O_HEAD_ONLY_RESPONSE;
    359   opt_val.val.head_only_response = (value); \
    360 
    361   return opt_val;
    362 }
    363 
    364 
    365 /**
    366  * Force use of chunked encoding even if the response content size is known.
    367  * Ignored when the reply cannot have body/content.
    368  * @param value the value of the parameter * @return structure with the requested setting
    369  */
    370 static MHD_INLINE struct MHD_ResponseOptionAndValue
    371 MHD_R_OPTION_CHUNKED_ENC (
    372   enum MHD_Bool value
    373   )
    374 {
    375   struct MHD_ResponseOptionAndValue opt_val;
    376 
    377   opt_val.opt = MHD_R_O_CHUNKED_ENC;
    378   opt_val.val.chunked_enc = (value); \
    379 
    380   return opt_val;
    381 }
    382 
    383 
    384 /**
    385  * Force close connection after sending the response, prevents keep-alive connections and adds 'Connection: close' header.
    386  * @param value the value of the parameter * @return structure with the requested setting
    387  */
    388 static MHD_INLINE struct MHD_ResponseOptionAndValue
    389 MHD_R_OPTION_CONN_CLOSE (
    390   enum MHD_Bool value
    391   )
    392 {
    393   struct MHD_ResponseOptionAndValue opt_val;
    394 
    395   opt_val.opt = MHD_R_O_CONN_CLOSE;
    396   opt_val.val.conn_close = (value); \
    397 
    398   return opt_val;
    399 }
    400 
    401 
    402 /**
    403  * Only respond in conservative (dumb) HTTP/1.0-compatible mode.
    404  * 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.
    405  * You can also set the #MHD_R_O_HTTP_1_0_SERVER flag to force HTTP/1.0 version in the response.
    406  * Responses are still compatible with HTTP/1.1.
    407  * Summary:
    408  * + declared reply version: HTTP/1.1
    409  * + keep-alive: no
    410  * + chunked: no
    411  *
    412 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.
    413  * @param value the value of the parameter * @return structure with the requested setting
    414  */
    415 static MHD_INLINE struct MHD_ResponseOptionAndValue
    416 MHD_R_OPTION_HTTP_1_0_COMPATIBLE_STRICT (
    417   enum MHD_Bool value
    418   )
    419 {
    420   struct MHD_ResponseOptionAndValue opt_val;
    421 
    422   opt_val.opt = MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT;
    423   opt_val.val.http_1_0_compatible_strict = (value); \
    424 
    425   return opt_val;
    426 }
    427 
    428 
    429 /**
    430  * Only respond in HTTP/1.0-mode.
    431  * 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.
    432  * The 'Connection:' header will be added for both 'close' and 'keep-alive' connections.
    433  * Chunked encoding will not be used for the response.
    434  * Due to backward compatibility, responses still can be used with HTTP/1.1 clients.
    435  * 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).
    436  * Summary:
    437  * + declared reply version: HTTP/1.0
    438  * + keep-alive: possible
    439  * + chunked: no
    440  *
    441 With this option HTTP/1.0 server is emulated (with support for 'keep-alive' connections).
    442  * @param value the value of the parameter * @return structure with the requested setting
    443  */
    444 static MHD_INLINE struct MHD_ResponseOptionAndValue
    445 MHD_R_OPTION_HTTP_1_0_SERVER (
    446   enum MHD_Bool value
    447   )
    448 {
    449   struct MHD_ResponseOptionAndValue opt_val;
    450 
    451   opt_val.opt = MHD_R_O_HTTP_1_0_SERVER;
    452   opt_val.val.http_1_0_server = (value); \
    453 
    454   return opt_val;
    455 }
    456 
    457 
    458 /**
    459  * Disable sanity check preventing clients from manually setting the HTTP content length option.
    460  * Allow to set several 'Content-Length' headers. These headers will be used even with replies without body.
    461  * @param value the value of the parameter * @return structure with the requested setting
    462  */
    463 static MHD_INLINE struct MHD_ResponseOptionAndValue
    464 MHD_R_OPTION_INSANITY_HEADER_CONTENT_LENGTH (
    465   enum MHD_Bool value
    466   )
    467 {
    468   struct MHD_ResponseOptionAndValue opt_val;
    469 
    470   opt_val.opt = MHD_R_O_INSANITY_HEADER_CONTENT_LENGTH;
    471   opt_val.val.insanity_header_content_length = (value); \
    472 
    473   return opt_val;
    474 }
    475 
    476 
    477 /**
    478  * Set a function to be called once MHD is finished with the request.
    479  * @param ended_cb the function to call,
    480  *   NULL to not use the callback
    481  * @param ended_cb_cls the closure for the callback
    482  * @return structure with the requested setting
    483  */
    484 static MHD_INLINE struct MHD_ResponseOptionAndValue
    485 MHD_R_OPTION_TERMINATION_CALLBACK (
    486   MHD_RequestEndedCallback ended_cb,
    487   void *ended_cb_cls
    488   )
    489 {
    490   struct MHD_ResponseOptionAndValue opt_val;
    491 
    492   opt_val.opt = MHD_R_O_TERMINATION_CALLBACK;
    493   opt_val.val.termination_callback.v_ended_cb = ended_cb;
    494   opt_val.val.termination_callback.v_ended_cb_cls = ended_cb_cls;
    495 
    496   return opt_val;
    497 }
    498 
    499 
    500 /**
    501  * Terminate the list of the options
    502  * @return the terminating object of struct MHD_ResponseOptionAndValue
    503  */
    504 static MHD_INLINE struct MHD_ResponseOptionAndValue
    505 MHD_R_OPTION_TERMINATE (void)
    506 {
    507   struct MHD_ResponseOptionAndValue opt_val;
    508 
    509   opt_val.opt = MHD_R_O_END;
    510 
    511   return opt_val;
    512 }
    513 
    514 
    515 MHD_RESTORE_WARN_UNUSED_FUNC_
    516 #endif /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */