GNU libmicrohttpd  0.9.5
internal.c
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  (C) 2007 Daniel Pittman and Christian Grothoff
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
27 #include "internal.h"
28 
29 #if HAVE_MESSAGES
30 #if DEBUG_STATES
31 
34 const char *
35 MHD_state_to_string (enum MHD_CONNECTION_STATE state)
36 {
37  switch (state)
38  {
40  return "connection init";
42  return "connection url received";
44  return "header partially received";
46  return "headers received";
48  return "headers processed";
50  return "continue sending";
52  return "continue sent";
54  return "body received";
56  return "footer partially received";
58  return "footers received";
60  return "headers sending";
62  return "headers sent";
64  return "normal body ready";
66  return "normal body unready";
68  return "chunked body ready";
70  return "chunked body unready";
72  return "body sent";
74  return "footers sending";
76  return "footers sent";
78  return "closed";
80  return "secure connection init";
81  default:
82  return "unrecognized connection state";
83  }
84 }
85 #endif
86 #endif
87 
88 #if HAVE_MESSAGES
89 
93 void
94 MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...)
95 {
96  va_list va;
97 
98  if ((daemon->options & MHD_USE_DEBUG) == 0)
99  return;
100  va_start (va, format);
101  daemon->custom_error_log (daemon->custom_error_log_cls, format, va);
102  va_end (va);
103 }
104 #endif
105 
106 
117 size_t
118 MHD_http_unescape (void *cls,
119  struct MHD_Connection *connection,
120  char *val)
121 {
122  char *rpos = val;
123  char *wpos = val;
124  unsigned int num;
125 
126  while ('\0' != *rpos)
127  {
128  switch (*rpos)
129  {
130  case '+':
131  *wpos = ' ';
132  wpos++;
133  rpos++;
134  break;
135  case '%':
136  if ( (1 == SSCANF (&rpos[1],
137  "%2x", &num)) ||
138  (1 == SSCANF (&rpos[1],
139  "%2X", &num)) )
140  {
141  *wpos = (unsigned char) num;
142  wpos++;
143  rpos += 3;
144  break;
145  }
146  /* intentional fall through! */
147  default:
148  *wpos = *rpos;
149  wpos++;
150  rpos++;
151  }
152  }
153  *wpos = '\0'; /* add 0-terminator */
154  return wpos - val; /* = strlen(val) */
155 }
156 
157 /* end of internal.c */