internal.c
Go to the documentation of this file.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
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 char *end;
00125 unsigned int num;
00126 char buf3[3];
00127
00128 while ('\0' != *rpos)
00129 {
00130 switch (*rpos)
00131 {
00132 case '+':
00133 *wpos = ' ';
00134 wpos++;
00135 rpos++;
00136 break;
00137 case '%':
00138 buf3[0] = rpos[1];
00139 buf3[1] = rpos[2];
00140 buf3[2] = '\0';
00141 num = strtoul (buf3, &end, 16);
00142 if ('\0' == *end)
00143 {
00144 *wpos = (unsigned char) num;
00145 wpos++;
00146 rpos += 3;
00147 break;
00148 }
00149
00150 default:
00151 *wpos = *rpos;
00152 wpos++;
00153 rpos++;
00154 }
00155 }
00156 *wpos = '\0';
00157 return wpos - val;
00158 }
00159
00160 time_t MHD_monotonic_time(void)
00161 {
00162 #ifdef HAVE_CLOCK_GETTIME
00163 struct timespec ts;
00164 if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
00165 return ts.tv_sec;
00166 #endif
00167 return time(NULL);
00168 }
00169
00170