libmicrohttpd2

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

mhd_enum_to_str.c (4831B)


      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 = mhd_MSTR_INIT ("HTTP/1.0");
     69       return &ret;
     70     }
     71     break;
     72   case MHD_HTTP_VERSION_1_1:
     73     if (1)
     74     {
     75       static const struct MHD_String ret = mhd_MSTR_INIT ("HTTP/1.1");
     76       return &ret;
     77     }
     78     break;
     79   case MHD_HTTP_VERSION_2:
     80     if (1)
     81     {
     82       static const struct MHD_String ret = mhd_MSTR_INIT ("HTTP/2");
     83       return &ret;
     84     }
     85     break;
     86   case MHD_HTTP_VERSION_3:
     87     if (1)
     88     {
     89       static const struct MHD_String ret = mhd_MSTR_INIT ("HTTP/3");
     90       return &ret;
     91     }
     92     break;
     93   case MHD_HTTP_VERSION_FUTURE:
     94     if (1)
     95     {
     96       static const struct MHD_String ret = mhd_MSTR_INIT ("[future version]");
     97       return &ret;
     98     }
     99     break;
    100   default:
    101     break;
    102   }
    103 
    104   return NULL;
    105 }
    106 
    107 
    108 MHD_EXTERN_ MHD_FN_CONST_ const struct MHD_String *
    109 MHD_http_method_to_string (enum MHD_HTTP_Method method)
    110 {
    111   switch (method)
    112   {
    113   case MHD_HTTP_METHOD_GET:
    114     if (1)
    115     {
    116       static const struct MHD_String ret = mhd_MSTR_INIT ("GET");
    117       return &ret;
    118     }
    119     break;
    120   case MHD_HTTP_METHOD_HEAD:
    121     if (1)
    122     {
    123       static const struct MHD_String ret = mhd_MSTR_INIT ("HEAD");
    124       return &ret;
    125     }
    126     break;
    127   case MHD_HTTP_METHOD_POST:
    128     if (1)
    129     {
    130       static const struct MHD_String ret = mhd_MSTR_INIT ("POST");
    131       return &ret;
    132     }
    133     break;
    134   case MHD_HTTP_METHOD_PUT:
    135     if (1)
    136     {
    137       static const struct MHD_String ret = mhd_MSTR_INIT ("PUT");
    138       return &ret;
    139     }
    140     break;
    141   case MHD_HTTP_METHOD_DELETE:
    142     if (1)
    143     {
    144       static const struct MHD_String ret = mhd_MSTR_INIT ("DELETE");
    145       return &ret;
    146     }
    147     break;
    148   case MHD_HTTP_METHOD_CONNECT:
    149     if (1)
    150     {
    151       static const struct MHD_String ret = mhd_MSTR_INIT ("CONNECT");
    152       return &ret;
    153     }
    154     break;
    155   case MHD_HTTP_METHOD_OPTIONS:
    156     if (1)
    157     {
    158       static const struct MHD_String ret = mhd_MSTR_INIT ("OPTIONS");
    159       return &ret;
    160     }
    161     break;
    162   case MHD_HTTP_METHOD_TRACE:
    163     if (1)
    164     {
    165       static const struct MHD_String ret = mhd_MSTR_INIT ("TRACE");
    166       return &ret;
    167     }
    168     break;
    169   case MHD_HTTP_METHOD_ASTERISK:
    170     if (1)
    171     {
    172       static const struct MHD_String ret = mhd_MSTR_INIT ("*");
    173       return &ret;
    174     }
    175     break;
    176   case MHD_HTTP_METHOD_OTHER: /* Handled as unknown value */
    177   default:
    178     break;
    179   }
    180 
    181   return NULL;
    182 }