diff options
Diffstat (limited to 'src/daemon/internal.h')
-rw-r--r-- | src/daemon/internal.h | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/src/daemon/internal.h b/src/daemon/internal.h index a06d7ae2..37075bc0 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h | |||
@@ -63,101 +63,101 @@ | |||
63 | * fprintf-like helper function for logging debug | 63 | * fprintf-like helper function for logging debug |
64 | * messages. | 64 | * messages. |
65 | */ | 65 | */ |
66 | void MHD_DLOG(const struct MHD_Daemon *daemon, const char *format, ...); | 66 | void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...); |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * Process escape sequences ('+'=space, %HH). | 70 | * Process escape sequences ('+'=space, %HH). |
71 | * Updates val in place. | 71 | * Updates val in place. |
72 | */ | 72 | */ |
73 | void MHD_http_unescape(char *val); | 73 | void MHD_http_unescape (char *val); |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * Header or cookie in HTTP request or response. | 76 | * Header or cookie in HTTP request or response. |
77 | */ | 77 | */ |
78 | struct MHD_HTTP_Header | 78 | struct MHD_HTTP_Header |
79 | { | 79 | { |
80 | struct MHD_HTTP_Header *next; | 80 | struct MHD_HTTP_Header *next; |
81 | 81 | ||
82 | char *header; | 82 | char *header; |
83 | 83 | ||
84 | char *value; | 84 | char *value; |
85 | 85 | ||
86 | enum MHD_ValueKind kind; | 86 | enum MHD_ValueKind kind; |
87 | 87 | ||
88 | }; | 88 | }; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Representation of a response. | 91 | * Representation of a response. |
92 | */ | 92 | */ |
93 | struct MHD_Response | 93 | struct MHD_Response |
94 | { | 94 | { |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * Headers to send for the response. Initially | 97 | * Headers to send for the response. Initially |
98 | * the linked list is created in inverse order; | 98 | * the linked list is created in inverse order; |
99 | * the order should be inverted before sending! | 99 | * the order should be inverted before sending! |
100 | */ | 100 | */ |
101 | struct MHD_HTTP_Header *first_header; | 101 | struct MHD_HTTP_Header *first_header; |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Buffer pointing to data that we are supposed | 104 | * Buffer pointing to data that we are supposed |
105 | * to send as a response. | 105 | * to send as a response. |
106 | */ | 106 | */ |
107 | char *data; | 107 | char *data; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Closure to give to the content reader | 110 | * Closure to give to the content reader |
111 | * free callback. | 111 | * free callback. |
112 | */ | 112 | */ |
113 | void *crc_cls; | 113 | void *crc_cls; |
114 | 114 | ||
115 | /** | 115 | /** |
116 | * How do we get more data? NULL if we are | 116 | * How do we get more data? NULL if we are |
117 | * given all of the data up front. | 117 | * given all of the data up front. |
118 | */ | 118 | */ |
119 | MHD_ContentReaderCallback crc; | 119 | MHD_ContentReaderCallback crc; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * NULL if data must not be freed, otherwise | 122 | * NULL if data must not be freed, otherwise |
123 | * either user-specified callback or "&free". | 123 | * either user-specified callback or "&free". |
124 | */ | 124 | */ |
125 | MHD_ContentReaderFreeCallback crfc; | 125 | MHD_ContentReaderFreeCallback crfc; |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Mutex to synchronize access to data/size and | 128 | * Mutex to synchronize access to data/size and |
129 | * reference counts. | 129 | * reference counts. |
130 | */ | 130 | */ |
131 | pthread_mutex_t mutex; | 131 | pthread_mutex_t mutex; |
132 | 132 | ||
133 | /** | 133 | /** |
134 | * Reference count for this response. Free | 134 | * Reference count for this response. Free |
135 | * once the counter hits zero. | 135 | * once the counter hits zero. |
136 | */ | 136 | */ |
137 | unsigned int reference_count; | 137 | unsigned int reference_count; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Set to -1 if size is not known. | 140 | * Set to -1 if size is not known. |
141 | */ | 141 | */ |
142 | size_t total_size; | 142 | size_t total_size; |
143 | 143 | ||
144 | /** | 144 | /** |
145 | * Size of data. | 145 | * Size of data. |
146 | */ | 146 | */ |
147 | size_t data_size; | 147 | size_t data_size; |
148 | 148 | ||
149 | /** | 149 | /** |
150 | * Size of the data buffer. | 150 | * Size of the data buffer. |
151 | */ | 151 | */ |
152 | size_t data_buffer_size; | 152 | size_t data_buffer_size; |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * At what offset in the stream is the | 155 | * At what offset in the stream is the |
156 | * beginning of data located? | 156 | * beginning of data located? |
157 | */ | 157 | */ |
158 | size_t data_start; | 158 | size_t data_start; |
159 | 159 | ||
160 | }; | 160 | }; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * States in a state machine for a connection. | 163 | * States in a state machine for a connection. |
@@ -174,151 +174,151 @@ struct MHD_Response | |||
174 | * requires the write to be complete. | 174 | * requires the write to be complete. |
175 | */ | 175 | */ |
176 | enum MHD_CONNECTION_STATE | 176 | enum MHD_CONNECTION_STATE |
177 | { | 177 | { |
178 | /** | 178 | /** |
179 | * Connection just started (no headers received). | 179 | * Connection just started (no headers received). |
180 | * Waiting for the line with the request type, URL and version. | 180 | * Waiting for the line with the request type, URL and version. |
181 | */ | 181 | */ |
182 | MHD_CONNECTION_INIT = 0, | 182 | MHD_CONNECTION_INIT = 0, |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * 1: We got the URL (and request type and version). Wait for a header line. | 185 | * 1: We got the URL (and request type and version). Wait for a header line. |
186 | */ | 186 | */ |
187 | MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1, | 187 | MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1, |
188 | 188 | ||
189 | /** | 189 | /** |
190 | * 2: We got part of a multi-line request header. Wait for the rest. | 190 | * 2: We got part of a multi-line request header. Wait for the rest. |
191 | */ | 191 | */ |
192 | MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1, | 192 | MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1, |
193 | 193 | ||
194 | /** | 194 | /** |
195 | * 3: We got the request headers. Process them. | 195 | * 3: We got the request headers. Process them. |
196 | */ | 196 | */ |
197 | MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1, | 197 | MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1, |
198 | 198 | ||
199 | /** | 199 | /** |
200 | * 4: We have processed the request headers. Send 100 continue. | 200 | * 4: We have processed the request headers. Send 100 continue. |
201 | */ | 201 | */ |
202 | MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1, | 202 | MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1, |
203 | 203 | ||
204 | /** | 204 | /** |
205 | * 5: We have processed the headers and need to send 100 CONTINUE. | 205 | * 5: We have processed the headers and need to send 100 CONTINUE. |
206 | */ | 206 | */ |
207 | MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1, | 207 | MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1, |
208 | 208 | ||
209 | /** | 209 | /** |
210 | * 6: We have sent 100 CONTINUE (or do not need to). Read the message body. | 210 | * 6: We have sent 100 CONTINUE (or do not need to). Read the message body. |
211 | */ | 211 | */ |
212 | MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1, | 212 | MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1, |
213 | 213 | ||
214 | /** | 214 | /** |
215 | * 7: We got the request body. Wait for a line of the footer. | 215 | * 7: We got the request body. Wait for a line of the footer. |
216 | */ | 216 | */ |
217 | MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1, | 217 | MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1, |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * 8: We got part of a line of the footer. Wait for the | 220 | * 8: We got part of a line of the footer. Wait for the |
221 | * rest. | 221 | * rest. |
222 | */ | 222 | */ |
223 | MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1, | 223 | MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1, |
224 | 224 | ||
225 | /** | 225 | /** |
226 | * 9: We received the entire footer. Wait for a response to be queued | 226 | * 9: We received the entire footer. Wait for a response to be queued |
227 | * and prepare the response headers. | 227 | * and prepare the response headers. |
228 | */ | 228 | */ |
229 | MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1, | 229 | MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1, |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * 10: We have prepared the response headers in the writ buffer. | 232 | * 10: We have prepared the response headers in the writ buffer. |
233 | * Send the response headers. | 233 | * Send the response headers. |
234 | */ | 234 | */ |
235 | MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1, | 235 | MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1, |
236 | 236 | ||
237 | /** | 237 | /** |
238 | * 11: We have sent the response headers. Get ready to send the body. | 238 | * 11: We have sent the response headers. Get ready to send the body. |
239 | */ | 239 | */ |
240 | MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1, | 240 | MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1, |
241 | 241 | ||
242 | /** | 242 | /** |
243 | * 12: We are ready to send a part of a non-chunked body. Send it. | 243 | * 12: We are ready to send a part of a non-chunked body. Send it. |
244 | */ | 244 | */ |
245 | MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1, | 245 | MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1, |
246 | 246 | ||
247 | /** | 247 | /** |
248 | * 13: We are waiting for the client to provide more | 248 | * 13: We are waiting for the client to provide more |
249 | * data of a non-chunked body. | 249 | * data of a non-chunked body. |
250 | */ | 250 | */ |
251 | MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1, | 251 | MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1, |
252 | 252 | ||
253 | /** | 253 | /** |
254 | * 14: We are ready to send a chunk. | 254 | * 14: We are ready to send a chunk. |
255 | */ | 255 | */ |
256 | MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1, | 256 | MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1, |
257 | 257 | ||
258 | /** | 258 | /** |
259 | * 15: We are waiting for the client to provide a chunk of the body. | 259 | * 15: We are waiting for the client to provide a chunk of the body. |
260 | */ | 260 | */ |
261 | MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1, | 261 | MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1, |
262 | 262 | ||
263 | /** | 263 | /** |
264 | * 16: We have sent the response body. Prepare the footers. | 264 | * 16: We have sent the response body. Prepare the footers. |
265 | */ | 265 | */ |
266 | MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1, | 266 | MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1, |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * 17: We have prepared the response footer. Send it. | 269 | * 17: We have prepared the response footer. Send it. |
270 | */ | 270 | */ |
271 | MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1, | 271 | MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1, |
272 | 272 | ||
273 | /** | 273 | /** |
274 | * 18: We have sent the response footer. Shutdown or restart. | 274 | * 18: We have sent the response footer. Shutdown or restart. |
275 | */ | 275 | */ |
276 | MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1, | 276 | MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1, |
277 | 277 | ||
278 | /** | 278 | /** |
279 | * 19: This connection is closed (no more activity | 279 | * 19: This connection is closed (no more activity |
280 | * allowed). | 280 | * allowed). |
281 | */ | 281 | */ |
282 | MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1, | 282 | MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1, |
283 | 283 | ||
284 | }; | 284 | }; |
285 | 285 | ||
286 | enum MHDS_CONNECTION_STATE | 286 | enum MHDS_CONNECTION_STATE |
287 | { | 287 | { |
288 | MHDS_CONNECTION_INIT = 0, | 288 | MHDS_CONNECTION_INIT = 0, |
289 | 289 | ||
290 | /** | 290 | /** |
291 | * 1: We got the URL (and request type and version). Wait for a header line. | 291 | * 1: We got the URL (and request type and version). Wait for a header line. |
292 | */ | 292 | */ |
293 | MHDS_HANDSHAKE_COMPLETE = MHDS_CONNECTION_INIT + 1, | 293 | MHDS_HANDSHAKE_COMPLETE = MHDS_CONNECTION_INIT + 1, |
294 | 294 | ||
295 | MHDS_CONNECTION_CONTINUE_SENDING = MHDS_HANDSHAKE_COMPLETE + 1, | 295 | MHDS_CONNECTION_CONTINUE_SENDING = MHDS_HANDSHAKE_COMPLETE + 1, |
296 | 296 | ||
297 | MHDS_CONNECTION_CLOSED = MHDS_CONNECTION_CONTINUE_SENDING + 1 | 297 | MHDS_CONNECTION_CLOSED = MHDS_CONNECTION_CONTINUE_SENDING + 1 |
298 | }; | 298 | }; |
299 | 299 | ||
300 | struct MHD_Connection | 300 | struct MHD_Connection |
301 | { | 301 | { |
302 | 302 | ||
303 | /** | 303 | /** |
304 | * This is a linked list. | 304 | * This is a linked list. |
305 | */ | 305 | */ |
306 | struct MHD_Connection *next; | 306 | struct MHD_Connection *next; |
307 | 307 | ||
308 | /** | 308 | /** |
309 | * Reference to the MHD_Daemon struct. | 309 | * Reference to the MHD_Daemon struct. |
310 | */ | 310 | */ |
311 | struct MHD_Daemon *daemon; | 311 | struct MHD_Daemon *daemon; |
312 | 312 | ||
313 | /** | 313 | /** |
314 | * Linked list of parsed headers. | 314 | * Linked list of parsed headers. |
315 | */ | 315 | */ |
316 | struct MHD_HTTP_Header *headers_received; | 316 | struct MHD_HTTP_Header *headers_received; |
317 | 317 | ||
318 | /** | 318 | /** |
319 | * Response to transmit (initially NULL). | 319 | * Response to transmit (initially NULL). |
320 | */ | 320 | */ |
321 | struct MHD_Response *response; | 321 | struct MHD_Response *response; |
322 | 322 | ||
323 | /** | 323 | /** |
324 | * The memory pool is created whenever we first read | 324 | * The memory pool is created whenever we first read |
@@ -330,7 +330,7 @@ struct MHD_Connection | |||
330 | * connections) and the IP address (which persists | 330 | * connections) and the IP address (which persists |
331 | * across individual requests). | 331 | * across individual requests). |
332 | */ | 332 | */ |
333 | struct MemoryPool *pool; | 333 | struct MemoryPool *pool; |
334 | 334 | ||
335 | /** | 335 | /** |
336 | * We allow the main application to associate some | 336 | * We allow the main application to associate some |
@@ -338,25 +338,25 @@ struct MHD_Connection | |||
338 | * store it. (MHD does not know or care what it | 338 | * store it. (MHD does not know or care what it |
339 | * is). | 339 | * is). |
340 | */ | 340 | */ |
341 | void *client_context; | 341 | void *client_context; |
342 | 342 | ||
343 | /** | 343 | /** |
344 | * Request method. Should be GET/POST/etc. Allocated | 344 | * Request method. Should be GET/POST/etc. Allocated |
345 | * in pool. | 345 | * in pool. |
346 | */ | 346 | */ |
347 | char *method; | 347 | char *method; |
348 | 348 | ||
349 | /** | 349 | /** |
350 | * Requested URL (everything after "GET" only). Allocated | 350 | * Requested URL (everything after "GET" only). Allocated |
351 | * in pool. | 351 | * in pool. |
352 | */ | 352 | */ |
353 | char *url; | 353 | char *url; |
354 | 354 | ||
355 | /** | 355 | /** |
356 | * HTTP version string (i.e. http/1.1). Allocated | 356 | * HTTP version string (i.e. http/1.1). Allocated |
357 | * in pool. | 357 | * in pool. |
358 | */ | 358 | */ |
359 | char *version; | 359 | char *version; |
360 | 360 | ||
361 | /** | 361 | /** |
362 | * Buffer for reading requests. Allocated | 362 | * Buffer for reading requests. Allocated |
@@ -364,20 +364,20 @@ struct MHD_Connection | |||
364 | * read_buffer_size (if non-NULL) to allow for | 364 | * read_buffer_size (if non-NULL) to allow for |
365 | * 0-termination. | 365 | * 0-termination. |
366 | */ | 366 | */ |
367 | char *read_buffer; | 367 | char *read_buffer; |
368 | 368 | ||
369 | /** | 369 | /** |
370 | * Buffer for writing response (headers only). Allocated | 370 | * Buffer for writing response (headers only). Allocated |
371 | * in pool. | 371 | * in pool. |
372 | */ | 372 | */ |
373 | char *write_buffer; | 373 | char *write_buffer; |
374 | 374 | ||
375 | /** | 375 | /** |
376 | * Last incomplete header line during parsing of headers. | 376 | * Last incomplete header line during parsing of headers. |
377 | * Allocated in pool. Only valid if state is | 377 | * Allocated in pool. Only valid if state is |
378 | * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. | 378 | * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. |
379 | */ | 379 | */ |
380 | char *last; | 380 | char *last; |
381 | 381 | ||
382 | /** | 382 | /** |
383 | * Position after the colon on the last incomplete header | 383 | * Position after the colon on the last incomplete header |
@@ -385,19 +385,19 @@ struct MHD_Connection | |||
385 | * Allocated in pool. Only valid if state is | 385 | * Allocated in pool. Only valid if state is |
386 | * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. | 386 | * either HEADER_PART_RECEIVED or FOOTER_PART_RECEIVED. |
387 | */ | 387 | */ |
388 | char *colon; | 388 | char *colon; |
389 | 389 | ||
390 | /** | 390 | /** |
391 | * Foreign address (of length addr_len). MALLOCED (not | 391 | * Foreign address (of length addr_len). MALLOCED (not |
392 | * in pool!). | 392 | * in pool!). |
393 | */ | 393 | */ |
394 | struct sockaddr_in *addr; | 394 | struct sockaddr_in *addr; |
395 | 395 | ||
396 | /** | 396 | /** |
397 | * Thread for this connection (if we are using | 397 | * Thread for this connection (if we are using |
398 | * one thread per connection). | 398 | * one thread per connection). |
399 | */ | 399 | */ |
400 | pthread_t pid; | 400 | pthread_t pid; |
401 | 401 | ||
402 | /** | 402 | /** |
403 | * Size of read_buffer (in bytes). This value indicates | 403 | * Size of read_buffer (in bytes). This value indicates |
@@ -405,66 +405,66 @@ struct MHD_Connection | |||
405 | * the real buffer is one byte longer to allow for | 405 | * the real buffer is one byte longer to allow for |
406 | * adding zero-termination (when needed). | 406 | * adding zero-termination (when needed). |
407 | */ | 407 | */ |
408 | size_t read_buffer_size; | 408 | size_t read_buffer_size; |
409 | 409 | ||
410 | /** | 410 | /** |
411 | * Position where we currently append data in | 411 | * Position where we currently append data in |
412 | * read_buffer (last valid position). | 412 | * read_buffer (last valid position). |
413 | */ | 413 | */ |
414 | size_t read_buffer_offset; | 414 | size_t read_buffer_offset; |
415 | 415 | ||
416 | /** | 416 | /** |
417 | * Size of write_buffer (in bytes). | 417 | * Size of write_buffer (in bytes). |
418 | */ | 418 | */ |
419 | size_t write_buffer_size; | 419 | size_t write_buffer_size; |
420 | 420 | ||
421 | /** | 421 | /** |
422 | * Offset where we are with sending from write_buffer. | 422 | * Offset where we are with sending from write_buffer. |
423 | */ | 423 | */ |
424 | size_t write_buffer_send_offset; | 424 | size_t write_buffer_send_offset; |
425 | 425 | ||
426 | /** | 426 | /** |
427 | * Last valid location in write_buffer (where do we | 427 | * Last valid location in write_buffer (where do we |
428 | * append and up to where is it safe to send?) | 428 | * append and up to where is it safe to send?) |
429 | */ | 429 | */ |
430 | size_t write_buffer_append_offset; | 430 | size_t write_buffer_append_offset; |
431 | 431 | ||
432 | /** | 432 | /** |
433 | * How many more bytes of the body do we expect | 433 | * How many more bytes of the body do we expect |
434 | * to read? "-1" for unknown. | 434 | * to read? "-1" for unknown. |
435 | */ | 435 | */ |
436 | size_t remaining_upload_size; | 436 | size_t remaining_upload_size; |
437 | 437 | ||
438 | /** | 438 | /** |
439 | * Current write position in the actual response | 439 | * Current write position in the actual response |
440 | * (excluding headers, content only; should be 0 | 440 | * (excluding headers, content only; should be 0 |
441 | * while sending headers). | 441 | * while sending headers). |
442 | */ | 442 | */ |
443 | size_t response_write_position; | 443 | size_t response_write_position; |
444 | 444 | ||
445 | /** | 445 | /** |
446 | * Position in the 100 CONTINUE message that | 446 | * Position in the 100 CONTINUE message that |
447 | * we need to send when receiving http 1.1 requests. | 447 | * we need to send when receiving http 1.1 requests. |
448 | */ | 448 | */ |
449 | size_t continue_message_write_offset; | 449 | size_t continue_message_write_offset; |
450 | 450 | ||
451 | /** | 451 | /** |
452 | * Length of the foreign address. | 452 | * Length of the foreign address. |
453 | */ | 453 | */ |
454 | socklen_t addr_len; | 454 | socklen_t addr_len; |
455 | 455 | ||
456 | /** | 456 | /** |
457 | * Last time this connection had any activity | 457 | * Last time this connection had any activity |
458 | * (reading or writing). | 458 | * (reading or writing). |
459 | */ | 459 | */ |
460 | time_t last_activity; | 460 | time_t last_activity; |
461 | 461 | ||
462 | /** | 462 | /** |
463 | * Socket for this connection. Set to -1 if | 463 | * Socket for this connection. Set to -1 if |
464 | * this connection has died (daemon should clean | 464 | * this connection has died (daemon should clean |
465 | * up in that case). | 465 | * up in that case). |
466 | */ | 466 | */ |
467 | int socket_fd; | 467 | int socket_fd; |
468 | 468 | ||
469 | /** | 469 | /** |
470 | * Has this socket been closed for reading (i.e. | 470 | * Has this socket been closed for reading (i.e. |
@@ -473,18 +473,18 @@ struct MHD_Connection | |||
473 | * we are done sending our response (and stop | 473 | * we are done sending our response (and stop |
474 | * trying to read from this socket). | 474 | * trying to read from this socket). |
475 | */ | 475 | */ |
476 | int read_closed; | 476 | int read_closed; |
477 | 477 | ||
478 | /** | 478 | /** |
479 | * State in the FSM for this connection. | 479 | * State in the FSM for this connection. |
480 | */ | 480 | */ |
481 | enum MHD_CONNECTION_STATE state; | 481 | enum MHD_CONNECTION_STATE state; |
482 | 482 | ||
483 | /** | 483 | /** |
484 | * HTTP response code. Only valid if response object | 484 | * HTTP response code. Only valid if response object |
485 | * is already set. | 485 | * is already set. |
486 | */ | 486 | */ |
487 | unsigned int responseCode; | 487 | unsigned int responseCode; |
488 | 488 | ||
489 | /** | 489 | /** |
490 | * Set to MHD_YES if the response's content reader | 490 | * Set to MHD_YES if the response's content reader |
@@ -493,12 +493,12 @@ struct MHD_Connection | |||
493 | * write socket should be marked as unready until | 493 | * write socket should be marked as unready until |
494 | * the CRC call succeeds. | 494 | * the CRC call succeeds. |
495 | */ | 495 | */ |
496 | int response_unready; | 496 | int response_unready; |
497 | 497 | ||
498 | /** | 498 | /** |
499 | * Are we sending with chunked encoding? | 499 | * Are we sending with chunked encoding? |
500 | */ | 500 | */ |
501 | int have_chunked_response; | 501 | int have_chunked_response; |
502 | 502 | ||
503 | /** | 503 | /** |
504 | * Are we receiving with chunked encoding? This will be set to | 504 | * Are we receiving with chunked encoding? This will be set to |
@@ -507,7 +507,7 @@ struct MHD_Connection | |||
507 | * processing the footers; once the footers are also done, this will | 507 | * processing the footers; once the footers are also done, this will |
508 | * be set to MHD_NO again (before the final call to the handler). | 508 | * be set to MHD_NO again (before the final call to the handler). |
509 | */ | 509 | */ |
510 | int have_chunked_upload; | 510 | int have_chunked_upload; |
511 | 511 | ||
512 | /** | 512 | /** |
513 | * If we are receiving with chunked encoding, where are we right | 513 | * If we are receiving with chunked encoding, where are we right |
@@ -515,97 +515,97 @@ struct MHD_Connection | |||
515 | * otherwise, this is the size of the current chunk. A value of | 515 | * otherwise, this is the size of the current chunk. A value of |
516 | * zero is also used when we're at the end of the chunks. | 516 | * zero is also used when we're at the end of the chunks. |
517 | */ | 517 | */ |
518 | unsigned int current_chunk_size; | 518 | unsigned int current_chunk_size; |
519 | 519 | ||
520 | /** | 520 | /** |
521 | * If we are receiving with chunked encoding, where are we currently | 521 | * If we are receiving with chunked encoding, where are we currently |
522 | * with respect to the current chunk (at what offset / position)? | 522 | * with respect to the current chunk (at what offset / position)? |
523 | */ | 523 | */ |
524 | unsigned int current_chunk_offset; | 524 | unsigned int current_chunk_offset; |
525 | 525 | ||
526 | }; | 526 | }; |
527 | 527 | ||
528 | typedef struct MHD_Connection MHD_Connection_t; | 528 | typedef struct MHD_Connection MHD_Connection_t; |
529 | 529 | ||
530 | struct MHD_Daemon | 530 | struct MHD_Daemon |
531 | { | 531 | { |
532 | 532 | ||
533 | /** | 533 | /** |
534 | * Callback function for all requests. | 534 | * Callback function for all requests. |
535 | */ | 535 | */ |
536 | MHD_AccessHandlerCallback default_handler; | 536 | MHD_AccessHandlerCallback default_handler; |
537 | 537 | ||
538 | /** | 538 | /** |
539 | * Closure argument to default_handler. | 539 | * Closure argument to default_handler. |
540 | */ | 540 | */ |
541 | void *default_handler_cls; | 541 | void *default_handler_cls; |
542 | 542 | ||
543 | /** | 543 | /** |
544 | * Linked list of our current connections. | 544 | * Linked list of our current connections. |
545 | */ | 545 | */ |
546 | struct MHD_Connection *connections; | 546 | struct MHD_Connection *connections; |
547 | 547 | ||
548 | /** | 548 | /** |
549 | * Linked list of our current connections. | 549 | * Linked list of our current connections. |
550 | */ | 550 | */ |
551 | // TODO switch to a dedicated tls connection struct | 551 | // TODO switch to a dedicated tls connection struct |
552 | struct MHD_Connection *tls_connections; | 552 | struct MHD_Connection *tls_connections; |
553 | 553 | ||
554 | MHD_AcceptPolicyCallback apc; | 554 | MHD_AcceptPolicyCallback apc; |
555 | 555 | ||
556 | void *apc_cls; | 556 | void *apc_cls; |
557 | 557 | ||
558 | MHD_RequestCompletedCallback notify_completed; | 558 | MHD_RequestCompletedCallback notify_completed; |
559 | 559 | ||
560 | void *notify_completed_cls; | 560 | void *notify_completed_cls; |
561 | 561 | ||
562 | /** | 562 | /** |
563 | * PID of the select thread (if we have internal select) | 563 | * PID of the select thread (if we have internal select) |
564 | */ | 564 | */ |
565 | pthread_t pid; | 565 | pthread_t pid; |
566 | 566 | ||
567 | /** | 567 | /** |
568 | * Listen socket. | 568 | * Listen socket. |
569 | */ | 569 | */ |
570 | int socket_fd; | 570 | int socket_fd; |
571 | 571 | ||
572 | /** | 572 | /** |
573 | * Are we shutting down? | 573 | * Are we shutting down? |
574 | */ | 574 | */ |
575 | int shutdown; | 575 | int shutdown; |
576 | 576 | ||
577 | /** | 577 | /** |
578 | * Size of the per-connection memory pools. | 578 | * Size of the per-connection memory pools. |
579 | */ | 579 | */ |
580 | unsigned int pool_size; | 580 | unsigned int pool_size; |
581 | 581 | ||
582 | /** | 582 | /** |
583 | * Limit on the number of parallel connections. | 583 | * Limit on the number of parallel connections. |
584 | */ | 584 | */ |
585 | unsigned int max_connections; | 585 | unsigned int max_connections; |
586 | 586 | ||
587 | /** | 587 | /** |
588 | * After how many seconds of inactivity should | 588 | * After how many seconds of inactivity should |
589 | * connections time out? Zero for no timeout. | 589 | * connections time out? Zero for no timeout. |
590 | */ | 590 | */ |
591 | unsigned int connection_timeout; | 591 | unsigned int connection_timeout; |
592 | 592 | ||
593 | /** | 593 | /** |
594 | * Maximum number of connections per IP, or 0 for | 594 | * Maximum number of connections per IP, or 0 for |
595 | * unlimited. | 595 | * unlimited. |
596 | */ | 596 | */ |
597 | unsigned int per_ip_connection_limit; | 597 | unsigned int per_ip_connection_limit; |
598 | 598 | ||
599 | /** | 599 | /** |
600 | * Daemon's options. | 600 | * Daemon's options. |
601 | */ | 601 | */ |
602 | enum MHD_OPTION options; | 602 | enum MHD_OPTION options; |
603 | 603 | ||
604 | /** | 604 | /** |
605 | * Listen port. | 605 | * Listen port. |
606 | */ | 606 | */ |
607 | unsigned short port; | 607 | unsigned short port; |
608 | 608 | ||
609 | }; | 609 | }; |
610 | 610 | ||
611 | #endif | 611 | #endif |