libmicrohttpd2

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

mhd_enum_to_str.c (5096B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2025 Christian Grothoff
      5   Copyright (C) 2025 Evgeny Grin (Karlson2k)
      6 
      7   GNU libmicrohttpd is free software; you can redistribute it and/or
      8   modify it under the terms of the GNU Lesser General Public
      9   License as published by the Free Software Foundation; either
     10   version 2.1 of the License, or (at your option) any later version.
     11 
     12   GNU libmicrohttpd is distributed in the hope that it will be useful,
     13   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15   Lesser General Public License for more details.
     16 
     17   Alternatively, you can redistribute GNU libmicrohttpd and/or
     18   modify it under the terms of the GNU General Public License as
     19   published by the Free Software Foundation; either version 2 of
     20   the License, or (at your option) any later version, together
     21   with the eCos exception, as follows:
     22 
     23     As a special exception, if other files instantiate templates or
     24     use macros or inline functions from this file, or you compile this
     25     file and link it with other works to produce a work based on this
     26     file, this file does not by itself cause the resulting work to be
     27     covered by the GNU General Public License. However the source code
     28     for this file must still be made available in accordance with
     29     section (3) of the GNU General Public License v2.
     30 
     31     This exception does not invalidate any other reasons why a work
     32     based on this file might be covered by the GNU General Public
     33     License.
     34 
     35   You should have received copies of the GNU Lesser General Public
     36   License and the GNU General Public License along with this library;
     37   if not, see <https://www.gnu.org/licenses/>.
     38 */
     39 
     40 /**
     41  * @file src/mhd2/mhd_enum_to_str.c
     42  * @brief convenience functions returning constant string values
     43  * @author Christian Grothoff, Karlson2k (Evgeny Grin)
     44  */
     45 
     46 #include "mhd_sys_options.h"
     47 
     48 #include "mhd_str_macros.h"
     49 
     50 #include "sys_null_macro.h"
     51 #include "mhd_public_api.h"
     52 
     53 MHD_EXTERN_ MHD_FN_CONST_ const struct MHD_String *
     54 MHD_protocol_version_to_string (enum MHD_HTTP_ProtocolVersion pv)
     55 {
     56   switch (pv)
     57   {
     58   case MHD_HTTP_VERSION_INVALID:
     59     if (1)
     60     {
     61       static const struct MHD_String ret = mhd_MSTR_INIT ("[invalid]");
     62       return &ret;
     63     }
     64     break;
     65   case MHD_HTTP_VERSION_1_0:
     66     if (1)
     67     {
     68       static const struct MHD_String ret =
     69         mhd_MSTR_INIT (MHD_HTTP_VERSION_1_0_STR);
     70       return &ret;
     71     }
     72     break;
     73   case MHD_HTTP_VERSION_1_1:
     74     if (1)
     75     {
     76       static const struct MHD_String ret =
     77         mhd_MSTR_INIT (MHD_HTTP_VERSION_1_1_STR);
     78       return &ret;
     79     }
     80     break;
     81   case MHD_HTTP_VERSION_1_2P:
     82     if (1)
     83     {
     84       static const struct MHD_String ret =
     85         mhd_MSTR_INIT (MHD_HTTP_VERSION_1_2P_STR);
     86       return &ret;
     87     }
     88     break;
     89   case MHD_HTTP_VERSION_2:
     90     if (1)
     91     {
     92       static const struct MHD_String ret =
     93         mhd_MSTR_INIT (MHD_HTTP_VERSION_2_STR);
     94       return &ret;
     95     }
     96     break;
     97   case MHD_HTTP_VERSION_3:
     98     if (1)
     99     {
    100       static const struct MHD_String ret =
    101         mhd_MSTR_INIT (MHD_HTTP_VERSION_3_STR);
    102       return &ret;
    103     }
    104     break;
    105   case MHD_HTTP_VERSION_FUTURE:
    106     if (1)
    107     {
    108       static const struct MHD_String ret = mhd_MSTR_INIT ("[future version]");
    109       return &ret;
    110     }
    111     break;
    112   default:
    113     break;
    114   }
    115 
    116   return NULL;
    117 }
    118 
    119 
    120 MHD_EXTERN_ MHD_FN_CONST_ const struct MHD_String *
    121 MHD_http_method_to_string (enum MHD_HTTP_Method method)
    122 {
    123   switch (method)
    124   {
    125   case MHD_HTTP_METHOD_GET:
    126     if (1)
    127     {
    128       static const struct MHD_String ret = mhd_MSTR_INIT ("GET");
    129       return &ret;
    130     }
    131     break;
    132   case MHD_HTTP_METHOD_HEAD:
    133     if (1)
    134     {
    135       static const struct MHD_String ret = mhd_MSTR_INIT ("HEAD");
    136       return &ret;
    137     }
    138     break;
    139   case MHD_HTTP_METHOD_POST:
    140     if (1)
    141     {
    142       static const struct MHD_String ret = mhd_MSTR_INIT ("POST");
    143       return &ret;
    144     }
    145     break;
    146   case MHD_HTTP_METHOD_PUT:
    147     if (1)
    148     {
    149       static const struct MHD_String ret = mhd_MSTR_INIT ("PUT");
    150       return &ret;
    151     }
    152     break;
    153   case MHD_HTTP_METHOD_DELETE:
    154     if (1)
    155     {
    156       static const struct MHD_String ret = mhd_MSTR_INIT ("DELETE");
    157       return &ret;
    158     }
    159     break;
    160   case MHD_HTTP_METHOD_CONNECT:
    161     if (1)
    162     {
    163       static const struct MHD_String ret = mhd_MSTR_INIT ("CONNECT");
    164       return &ret;
    165     }
    166     break;
    167   case MHD_HTTP_METHOD_OPTIONS:
    168     if (1)
    169     {
    170       static const struct MHD_String ret = mhd_MSTR_INIT ("OPTIONS");
    171       return &ret;
    172     }
    173     break;
    174   case MHD_HTTP_METHOD_TRACE:
    175     if (1)
    176     {
    177       static const struct MHD_String ret = mhd_MSTR_INIT ("TRACE");
    178       return &ret;
    179     }
    180     break;
    181   case MHD_HTTP_METHOD_ASTERISK:
    182     if (1)
    183     {
    184       static const struct MHD_String ret = mhd_MSTR_INIT ("*");
    185       return &ret;
    186     }
    187     break;
    188   case MHD_HTTP_METHOD_OTHER: /* Handled as unknown value */
    189   default:
    190     break;
    191   }
    192 
    193   return NULL;
    194 }