diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-05-05 18:07:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-05-05 18:07:33 +0000 |
commit | 9eb27c8dbe1939344ccced9c498895f0e92e8197 (patch) | |
tree | a97d1b7caf1e5dc79c22b08d58be70bc8c205cba /src/microhttpd/internal.c | |
parent | 1725bcf3c546fccbf22d7794bf7290fcc28c385d (diff) | |
download | libmicrohttpd-9eb27c8dbe1939344ccced9c498895f0e92e8197.tar.gz libmicrohttpd-9eb27c8dbe1939344ccced9c498895f0e92e8197.zip |
-changing directory name
Diffstat (limited to 'src/microhttpd/internal.c')
-rw-r--r-- | src/microhttpd/internal.c | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c new file mode 100644 index 00000000..1730c0c9 --- /dev/null +++ b/src/microhttpd/internal.c | |||
@@ -0,0 +1,171 @@ | |||
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 | |||
20 | /** | ||
21 | * @file internal.h | ||
22 | * @brief internal shared structures | ||
23 | * @author Daniel Pittman | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "internal.h" | ||
28 | |||
29 | #if HAVE_MESSAGES | ||
30 | #if DEBUG_STATES | ||
31 | /** | ||
32 | * State to string dictionary. | ||
33 | */ | ||
34 | const char * | ||
35 | MHD_state_to_string (enum MHD_CONNECTION_STATE state) | ||
36 | { | ||
37 | switch (state) | ||
38 | { | ||
39 | case MHD_CONNECTION_INIT: | ||
40 | return "connection init"; | ||
41 | case MHD_CONNECTION_URL_RECEIVED: | ||
42 | return "connection url received"; | ||
43 | case MHD_CONNECTION_HEADER_PART_RECEIVED: | ||
44 | return "header partially received"; | ||
45 | case MHD_CONNECTION_HEADERS_RECEIVED: | ||
46 | return "headers received"; | ||
47 | case MHD_CONNECTION_HEADERS_PROCESSED: | ||
48 | return "headers processed"; | ||
49 | case MHD_CONNECTION_CONTINUE_SENDING: | ||
50 | return "continue sending"; | ||
51 | case MHD_CONNECTION_CONTINUE_SENT: | ||
52 | return "continue sent"; | ||
53 | case MHD_CONNECTION_BODY_RECEIVED: | ||
54 | return "body received"; | ||
55 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: | ||
56 | return "footer partially received"; | ||
57 | case MHD_CONNECTION_FOOTERS_RECEIVED: | ||
58 | return "footers received"; | ||
59 | case MHD_CONNECTION_HEADERS_SENDING: | ||
60 | return "headers sending"; | ||
61 | case MHD_CONNECTION_HEADERS_SENT: | ||
62 | return "headers sent"; | ||
63 | case MHD_CONNECTION_NORMAL_BODY_READY: | ||
64 | return "normal body ready"; | ||
65 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: | ||
66 | return "normal body unready"; | ||
67 | case MHD_CONNECTION_CHUNKED_BODY_READY: | ||
68 | return "chunked body ready"; | ||
69 | case MHD_CONNECTION_CHUNKED_BODY_UNREADY: | ||
70 | return "chunked body unready"; | ||
71 | case MHD_CONNECTION_BODY_SENT: | ||
72 | return "body sent"; | ||
73 | case MHD_CONNECTION_FOOTERS_SENDING: | ||
74 | return "footers sending"; | ||
75 | case MHD_CONNECTION_FOOTERS_SENT: | ||
76 | return "footers sent"; | ||
77 | case MHD_CONNECTION_CLOSED: | ||
78 | return "closed"; | ||
79 | case MHD_TLS_CONNECTION_INIT: | ||
80 | return "secure connection init"; | ||
81 | default: | ||
82 | return "unrecognized connection state"; | ||
83 | } | ||
84 | } | ||
85 | #endif | ||
86 | #endif | ||
87 | |||
88 | #if HAVE_MESSAGES | ||
89 | /** | ||
90 | * fprintf-like helper function for logging debug | ||
91 | * messages. | ||
92 | */ | ||
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 | |||
107 | /** | ||
108 | * Process escape sequences ('+'=space, %HH) Updates val in place; the | ||
109 | * result should be UTF-8 encoded and cannot be larger than the input. | ||
110 | * The result must also still be 0-terminated. | ||
111 | * | ||
112 | * @param cls closure (use NULL) | ||
113 | * @param connection handle to connection, not used | ||
114 | * @param val value to unescape (modified in the process) | ||
115 | * @return length of the resulting val (strlen(val) maybe | ||
116 | * shorter afterwards due to elimination of escape sequences) | ||
117 | */ | ||
118 | size_t | ||
119 | MHD_http_unescape (void *cls, | ||
120 | struct MHD_Connection *connection, | ||
121 | char *val) | ||
122 | { | ||
123 | char *rpos = val; | ||
124 | char *wpos = val; | ||
125 | char *end; | ||
126 | unsigned int num; | ||
127 | char buf3[3]; | ||
128 | |||
129 | while ('\0' != *rpos) | ||
130 | { | ||
131 | switch (*rpos) | ||
132 | { | ||
133 | case '+': | ||
134 | *wpos = ' '; | ||
135 | wpos++; | ||
136 | rpos++; | ||
137 | break; | ||
138 | case '%': | ||
139 | buf3[0] = rpos[1]; | ||
140 | buf3[1] = rpos[2]; | ||
141 | buf3[2] = '\0'; | ||
142 | num = strtoul (buf3, &end, 16); | ||
143 | if ('\0' == *end) | ||
144 | { | ||
145 | *wpos = (unsigned char) num; | ||
146 | wpos++; | ||
147 | rpos += 3; | ||
148 | break; | ||
149 | } | ||
150 | /* intentional fall through! */ | ||
151 | default: | ||
152 | *wpos = *rpos; | ||
153 | wpos++; | ||
154 | rpos++; | ||
155 | } | ||
156 | } | ||
157 | *wpos = '\0'; /* add 0-terminator */ | ||
158 | return wpos - val; /* = strlen(val) */ | ||
159 | } | ||
160 | |||
161 | time_t MHD_monotonic_time(void) | ||
162 | { | ||
163 | #ifdef HAVE_CLOCK_GETTIME | ||
164 | struct timespec ts; | ||
165 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) | ||
166 | return ts.tv_sec; | ||
167 | #endif | ||
168 | return time(NULL); | ||
169 | } | ||
170 | |||
171 | /* end of internal.c */ | ||