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 
00033 char *
00034 MHD_state_to_string (enum MHD_CONNECTION_STATE state)
00035 {
00036   switch (state)
00037     {
00038     case MHD_CONNECTION_INIT:
00039       return "connection init";
00040     case MHD_CONNECTION_URL_RECEIVED:
00041       return "connection url received";
00042     case MHD_CONNECTION_HEADER_PART_RECEIVED:
00043       return "header partially received";
00044     case MHD_CONNECTION_HEADERS_RECEIVED:
00045       return "headers received";
00046     case MHD_CONNECTION_HEADERS_PROCESSED:
00047       return "headers processed";
00048     case MHD_CONNECTION_CONTINUE_SENDING:
00049       return "continue sending";
00050     case MHD_CONNECTION_CONTINUE_SENT:
00051       return "continue sent";
00052     case MHD_CONNECTION_BODY_RECEIVED:
00053       return "body received";
00054     case MHD_CONNECTION_FOOTER_PART_RECEIVED:
00055       return "footer partially received";
00056     case MHD_CONNECTION_FOOTERS_RECEIVED:
00057       return "footers received";
00058     case MHD_CONNECTION_HEADERS_SENDING:
00059       return "headers sending";
00060     case MHD_CONNECTION_HEADERS_SENT:
00061       return "headers sent";
00062     case MHD_CONNECTION_NORMAL_BODY_READY:
00063       return "normal body ready";
00064     case MHD_CONNECTION_NORMAL_BODY_UNREADY:
00065       return "normal body unready";
00066     case MHD_CONNECTION_CHUNKED_BODY_READY:
00067       return "chunked body ready";
00068     case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
00069       return "chunked body unready";
00070     case MHD_CONNECTION_BODY_SENT:
00071       return "body sent";
00072     case MHD_CONNECTION_FOOTERS_SENDING:
00073       return "footers sending";
00074     case MHD_CONNECTION_FOOTERS_SENT:
00075       return "footers sent";
00076     case MHD_CONNECTION_CLOSED:
00077       return "closed";
00078     case MHD_TLS_CONNECTION_INIT:
00079       return "secure connection init";
00080     case MHD_TLS_HELLO_REQUEST:
00081       return "secure hello request";
00082     case MHD_TLS_HANDSHAKE_FAILED:
00083       return "secure handshake failed";
00084     case MHD_TLS_HANDSHAKE_COMPLETE:
00085       return "secure handshake _complete";
00086     default:
00087       return "unrecognized connection state";
00088     }
00089 }
00090 #endif
00091 
00092 #if HAVE_MESSAGES
00093 
00097 void
00098 MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...)
00099 {
00100   va_list va;
00101 
00102   if ((daemon->options & MHD_USE_DEBUG) == 0)
00103     return;
00104   va_start (va, format);
00105   daemon->custom_error_log (daemon->custom_error_log_cls, format, va);
00106   va_end (va);
00107 }
00108 #endif
00109 
00110 void
00111 MHD_tls_log_func (int level, const char *str)
00112 {
00113 #ifdef HAVE_MESSAGES
00114   FPRINTF (stderr, "|<%d>| %s", level, str);
00115 #endif
00116 }
00117 
00121 size_t
00122 MHD_http_unescape (char *val)
00123 {
00124   char *rpos = val;
00125   char *wpos = val;
00126   unsigned int num;
00127 
00128   while ('\0' != *rpos)
00129     {
00130       switch (*rpos)
00131         {
00132         case '+':
00133           *wpos = ' ';
00134           wpos++;
00135           rpos++;
00136           break;
00137         case '%':
00138           if ( (1 == SSCANF (&rpos[1],
00139                              "%2x", &num)) ||
00140                (1 == SSCANF (&rpos[1],
00141                              "%2X", &num)) )
00142             {
00143               *wpos = (unsigned char) num;
00144               wpos++;
00145               rpos += 3;
00146               break;
00147             }
00148           /* intentional fall through! */
00149         default:
00150           *wpos = *rpos;
00151           wpos++;
00152           rpos++;
00153         }
00154     }
00155   *wpos = '\0'; /* add 0-terminator */
00156   return wpos - val; /* = strlen(val) */
00157 }
00158 
00159 /* end of internal.c */
Generated by  doxygen 1.6.2-20100208