00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00118 size_t
00119 MHD_http_unescape (void *cls,
00120 struct MHD_Connection *connection,
00121 char *val)
00122 {
00123 char *rpos = val;
00124 char *wpos = val;
00125 char *end;
00126 unsigned int num;
00127 char buf3[3];
00128
00129 while ('\0' != *rpos)
00130 {
00131 switch (*rpos)
00132 {
00133 case '+':
00134 *wpos = ' ';
00135 wpos++;
00136 rpos++;
00137 break;
00138 case '%':
00139 if ( ('\0' == rpos[1]) ||
00140 ('\0' == rpos[2]) )
00141 {
00142 *wpos = '\0';
00143 return wpos - val;
00144 }
00145 buf3[0] = rpos[1];
00146 buf3[1] = rpos[2];
00147 buf3[2] = '\0';
00148 num = strtoul (buf3, &end, 16);
00149 if ('\0' == *end)
00150 {
00151 *wpos = (unsigned char) num;
00152 wpos++;
00153 rpos += 3;
00154 break;
00155 }
00156
00157 default:
00158 *wpos = *rpos;
00159 wpos++;
00160 rpos++;
00161 }
00162 }
00163 *wpos = '\0';
00164 return wpos - val;
00165 }
00166
00167
00168 time_t
00169 MHD_monotonic_time (void)
00170 {
00171 #ifdef HAVE_CLOCK_GETTIME
00172 #ifdef CLOCK_MONOTONIC
00173 struct timespec ts;
00174
00175 if (0 == clock_gettime (CLOCK_MONOTONIC, &ts))
00176 return ts.tv_sec;
00177 #endif
00178 #endif
00179 return time (NULL);
00180 }
00181
00182