GNU libmicrohttpd 0.9.5

internal.c

Go to the documentation of this file.
00001 /*
00002      This file is part of libmicrohttpd
00003      (C) 2007 Daniel Pittman and Christian Grothoff
00004 
00005      This library is free software; you can redistribute it and/or
00006      modify it under the terms of the GNU Lesser General Public
00007      License as published by the Free Software Foundation; either
00008      version 2.1 of the License, or (at your option) any later version.
00009 
00010      This library is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013      Lesser General Public License for more details.
00014 
00015      You should have received a copy of the GNU Lesser General Public
00016      License along with this library; if not, write to the Free Software
00017      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00027 #include "internal.h"
00028 
00029 #if HAVE_MESSAGES
00030 #if DEBUG_STATES
00031 
00034 const char *
00035 MHD_state_to_string (enum MHD_CONNECTION_STATE state)
00036 {
00037   switch (state)
00038     {
00039     case MHD_CONNECTION_INIT:
00040       return "connection init";
00041     case MHD_CONNECTION_URL_RECEIVED:
00042       return "connection url received";
00043     case MHD_CONNECTION_HEADER_PART_RECEIVED:
00044       return "header partially received";
00045     case MHD_CONNECTION_HEADERS_RECEIVED:
00046       return "headers received";
00047     case MHD_CONNECTION_HEADERS_PROCESSED:
00048       return "headers processed";
00049     case MHD_CONNECTION_CONTINUE_SENDING:
00050       return "continue sending";
00051     case MHD_CONNECTION_CONTINUE_SENT:
00052       return "continue sent";
00053     case MHD_CONNECTION_BODY_RECEIVED:
00054       return "body received";
00055     case MHD_CONNECTION_FOOTER_PART_RECEIVED:
00056       return "footer partially received";
00057     case MHD_CONNECTION_FOOTERS_RECEIVED:
00058       return "footers received";
00059     case MHD_CONNECTION_HEADERS_SENDING:
00060       return "headers sending";
00061     case MHD_CONNECTION_HEADERS_SENT:
00062       return "headers sent";
00063     case MHD_CONNECTION_NORMAL_BODY_READY:
00064       return "normal body ready";
00065     case MHD_CONNECTION_NORMAL_BODY_UNREADY:
00066       return "normal body unready";
00067     case MHD_CONNECTION_CHUNKED_BODY_READY:
00068       return "chunked body ready";
00069     case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
00070       return "chunked body unready";
00071     case MHD_CONNECTION_BODY_SENT:
00072       return "body sent";
00073     case MHD_CONNECTION_FOOTERS_SENDING:
00074       return "footers sending";
00075     case MHD_CONNECTION_FOOTERS_SENT:
00076       return "footers sent";
00077     case MHD_CONNECTION_CLOSED:
00078       return "closed";
00079     case MHD_TLS_CONNECTION_INIT:
00080       return "secure connection init";
00081     default:
00082       return "unrecognized connection state";
00083     }
00084 }
00085 #endif
00086 #endif
00087 
00088 #if HAVE_MESSAGES
00089 
00093 void
00094 MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...)
00095 {
00096   va_list va;
00097 
00098   if ((daemon->options & MHD_USE_DEBUG) == 0)
00099     return;
00100   va_start (va, format);
00101   daemon->custom_error_log (daemon->custom_error_log_cls, format, va);
00102   va_end (va);
00103 }
00104 #endif
00105 
00106 
00117 size_t
00118 MHD_http_unescape (void *cls,
00119                    struct MHD_Connection *connection,
00120                    char *val)
00121 {
00122   char *rpos = val;
00123   char *wpos = val;
00124   unsigned int num;
00125 
00126   while ('\0' != *rpos)
00127     {
00128       switch (*rpos)
00129         {
00130         case '+':
00131           *wpos = ' ';
00132           wpos++;
00133           rpos++;
00134           break;
00135         case '%':
00136           if ( (1 == SSCANF (&rpos[1],
00137                              "%2x", &num)) ||
00138                (1 == SSCANF (&rpos[1],
00139                              "%2X", &num)) )
00140             {
00141               *wpos = (unsigned char) num;
00142               wpos++;
00143               rpos += 3;
00144               break;
00145             }
00146           /* intentional fall through! */
00147         default:
00148           *wpos = *rpos;
00149           wpos++;
00150           rpos++;
00151         }
00152     }
00153   *wpos = '\0'; /* add 0-terminator */
00154   return wpos - val; /* = strlen(val) */
00155 }
00156 
00157 /* end of internal.c */