diff options
-rw-r--r-- | src/daemon/daemon.c | 108 | ||||
-rw-r--r-- | src/daemon/daemontest.c | 28 | ||||
-rw-r--r-- | src/daemon/daemontest_get.c | 62 | ||||
-rw-r--r-- | src/daemon/daemontest_post.c | 64 | ||||
-rw-r--r-- | src/daemon/daemontest_put.c | 70 | ||||
-rw-r--r-- | src/daemon/internal.c | 2 | ||||
-rw-r--r-- | src/daemon/internal.h | 22 | ||||
-rw-r--r-- | src/daemon/minimal_example.c | 2 | ||||
-rw-r--r-- | src/daemon/response.c | 38 | ||||
-rw-r--r-- | src/daemon/session.c | 100 | ||||
-rw-r--r-- | src/daemon/session.h | 8 |
11 files changed, 252 insertions, 252 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 8d5c3459..379e3cf9 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -29,26 +29,26 @@ | |||
29 | #include "response.h" | 29 | #include "response.h" |
30 | #include "session.h" | 30 | #include "session.h" |
31 | 31 | ||
32 | #define MHD_MAX_CONNECTIONS FD_SETSIZE -4 | 32 | #define MHD_MAX_CONNECTIONS FD_SETSIZE -4 |
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Register an access handler for all URIs beginning with uri_prefix. | 36 | * Register an access handler for all URIs beginning with uri_prefix. |
37 | * | 37 | * |
38 | * @param uri_prefix | 38 | * @param uri_prefix |
39 | * @return MRI_NO if a handler for this exact prefix | 39 | * @return MRI_NO if a handler for this exact prefix |
40 | * already exists | 40 | * already exists |
41 | */ | 41 | */ |
42 | int | 42 | int |
43 | MHD_register_handler(struct MHD_Daemon * daemon, | 43 | MHD_register_handler(struct MHD_Daemon * daemon, |
44 | const char * uri_prefix, | 44 | const char * uri_prefix, |
45 | MHD_AccessHandlerCallback dh, | 45 | MHD_AccessHandlerCallback dh, |
46 | void * dh_cls) { | 46 | void * dh_cls) { |
47 | struct MHD_Access_Handler * ah; | 47 | struct MHD_Access_Handler * ah; |
48 | 48 | ||
49 | if ( (daemon == NULL) || | 49 | if ( (daemon == NULL) || |
50 | (uri_prefix == NULL) || | 50 | (uri_prefix == NULL) || |
51 | (dh == NULL) ) | 51 | (dh == NULL) ) |
52 | return MHD_NO; | 52 | return MHD_NO; |
53 | ah = daemon->handlers; | 53 | ah = daemon->handlers; |
54 | while (ah != NULL) { | 54 | while (ah != NULL) { |
@@ -71,11 +71,11 @@ MHD_register_handler(struct MHD_Daemon * daemon, | |||
71 | * Unregister an access handler for the URIs beginning with | 71 | * Unregister an access handler for the URIs beginning with |
72 | * uri_prefix. | 72 | * uri_prefix. |
73 | * | 73 | * |
74 | * @param uri_prefix | 74 | * @param uri_prefix |
75 | * @return MHD_NO if a handler for this exact prefix | 75 | * @return MHD_NO if a handler for this exact prefix |
76 | * is not known for this daemon | 76 | * is not known for this daemon |
77 | */ | 77 | */ |
78 | int | 78 | int |
79 | MHD_unregister_handler(struct MHD_Daemon * daemon, | 79 | MHD_unregister_handler(struct MHD_Daemon * daemon, |
80 | const char * uri_prefix, | 80 | const char * uri_prefix, |
81 | MHD_AccessHandlerCallback dh, | 81 | MHD_AccessHandlerCallback dh, |
@@ -83,9 +83,9 @@ MHD_unregister_handler(struct MHD_Daemon * daemon, | |||
83 | struct MHD_Access_Handler * prev; | 83 | struct MHD_Access_Handler * prev; |
84 | struct MHD_Access_Handler * pos; | 84 | struct MHD_Access_Handler * pos; |
85 | 85 | ||
86 | if ( (daemon == NULL) || | 86 | if ( (daemon == NULL) || |
87 | (uri_prefix == NULL) || | 87 | (uri_prefix == NULL) || |
88 | (dh == NULL) ) | 88 | (dh == NULL) ) |
89 | return MHD_NO; | 89 | return MHD_NO; |
90 | pos = daemon->handlers; | 90 | pos = daemon->handlers; |
91 | prev = NULL; | 91 | prev = NULL; |
@@ -114,7 +114,7 @@ MHD_unregister_handler(struct MHD_Daemon * daemon, | |||
114 | * daemon was not started with the right | 114 | * daemon was not started with the right |
115 | * options for this call. | 115 | * options for this call. |
116 | */ | 116 | */ |
117 | int | 117 | int |
118 | MHD_get_fdset(struct MHD_Daemon * daemon, | 118 | MHD_get_fdset(struct MHD_Daemon * daemon, |
119 | fd_set * read_fd_set, | 119 | fd_set * read_fd_set, |
120 | fd_set * write_fd_set, | 120 | fd_set * write_fd_set, |
@@ -123,13 +123,13 @@ MHD_get_fdset(struct MHD_Daemon * daemon, | |||
123 | struct MHD_Session * pos; | 123 | struct MHD_Session * pos; |
124 | 124 | ||
125 | if ( (daemon == NULL) || | 125 | if ( (daemon == NULL) || |
126 | (read_fd_set == NULL) || | 126 | (read_fd_set == NULL) || |
127 | (write_fd_set == NULL) || | 127 | (write_fd_set == NULL) || |
128 | (except_fd_set == NULL) || | 128 | (except_fd_set == NULL) || |
129 | (max_fd == NULL) || | 129 | (max_fd == NULL) || |
130 | ( (daemon->options & MHD_USE_THREAD_PER_CONNECTION) != 0) ) | 130 | ( (daemon->options & MHD_USE_THREAD_PER_CONNECTION) != 0) ) |
131 | return MHD_NO; | 131 | return MHD_NO; |
132 | FD_SET(daemon->socket_fd, | 132 | FD_SET(daemon->socket_fd, |
133 | read_fd_set); | 133 | read_fd_set); |
134 | if ( (*max_fd) < daemon->socket_fd) | 134 | if ( (*max_fd) < daemon->socket_fd) |
135 | *max_fd = daemon->socket_fd; | 135 | *max_fd = daemon->socket_fd; |
@@ -159,14 +159,14 @@ MHD_handle_connection(void * data) { | |||
159 | fd_set ws; | 159 | fd_set ws; |
160 | fd_set es; | 160 | fd_set es; |
161 | int max; | 161 | int max; |
162 | 162 | ||
163 | if (con == NULL) | 163 | if (con == NULL) |
164 | abort(); | 164 | abort(); |
165 | while ( (! con->daemon->shutdown) && | 165 | while ( (! con->daemon->shutdown) && |
166 | (con->socket_fd != -1) ) { | 166 | (con->socket_fd != -1) ) { |
167 | FD_ZERO(&rs); | 167 | FD_ZERO(&rs); |
168 | FD_ZERO(&ws); | 168 | FD_ZERO(&ws); |
169 | FD_ZERO(&es); | 169 | FD_ZERO(&es); |
170 | max = 0; | 170 | max = 0; |
171 | MHD_session_get_fdset(con, | 171 | MHD_session_get_fdset(con, |
172 | &rs, | 172 | &rs, |
@@ -174,9 +174,9 @@ MHD_handle_connection(void * data) { | |||
174 | &es, | 174 | &es, |
175 | &max); | 175 | &max); |
176 | num_ready = SELECT(max + 1, | 176 | num_ready = SELECT(max + 1, |
177 | &rs, | 177 | &rs, |
178 | &ws, | 178 | &ws, |
179 | &es, | 179 | &es, |
180 | NULL); | 180 | NULL); |
181 | if (num_ready <= 0) { | 181 | if (num_ready <= 0) { |
182 | if (errno == EINTR) | 182 | if (errno == EINTR) |
@@ -192,7 +192,7 @@ MHD_handle_connection(void * data) { | |||
192 | if ( (con->headersReceived == 1) && | 192 | if ( (con->headersReceived == 1) && |
193 | (con->response == NULL) ) | 193 | (con->response == NULL) ) |
194 | MHD_call_session_handler(con); | 194 | MHD_call_session_handler(con); |
195 | } | 195 | } |
196 | if (con->socket_fd != -1) { | 196 | if (con->socket_fd != -1) { |
197 | CLOSE(con->socket_fd); | 197 | CLOSE(con->socket_fd); |
198 | con->socket_fd = -1; | 198 | con->socket_fd = -1; |
@@ -214,10 +214,10 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
214 | int s; | 214 | int s; |
215 | 215 | ||
216 | addrlen = sizeof(struct sockaddr); | 216 | addrlen = sizeof(struct sockaddr); |
217 | memset(&addr, | 217 | memset(&addr, |
218 | 0, | 218 | 0, |
219 | sizeof(struct sockaddr)); | 219 | sizeof(struct sockaddr)); |
220 | s = ACCEPT(daemon->socket_fd, | 220 | s = ACCEPT(daemon->socket_fd, |
221 | &addr, | 221 | &addr, |
222 | &addrlen); | 222 | &addrlen); |
223 | if ( (s < 0) || | 223 | if ( (s < 0) || |
@@ -246,8 +246,8 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
246 | session->daemon = daemon; | 246 | session->daemon = daemon; |
247 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) && | 247 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) && |
248 | (0 != pthread_create(&session->pid, | 248 | (0 != pthread_create(&session->pid, |
249 | NULL, | 249 | NULL, |
250 | &MHD_handle_connection, | 250 | &MHD_handle_connection, |
251 | session)) ) { | 251 | session)) ) { |
252 | MHD_DLOG(daemon, | 252 | MHD_DLOG(daemon, |
253 | "Failed to create a thread: %s\n", | 253 | "Failed to create a thread: %s\n", |
@@ -273,7 +273,7 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
273 | * calling the application again with upload data when | 273 | * calling the application again with upload data when |
274 | * the upload data buffer is full). | 274 | * the upload data buffer is full). |
275 | */ | 275 | */ |
276 | static void | 276 | static void |
277 | MHD_cleanup_sessions(struct MHD_Daemon * daemon) { | 277 | MHD_cleanup_sessions(struct MHD_Daemon * daemon) { |
278 | struct MHD_Session * pos; | 278 | struct MHD_Session * pos; |
279 | struct MHD_Session * prev; | 279 | struct MHD_Session * prev; |
@@ -316,14 +316,14 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) { | |||
316 | else | 316 | else |
317 | pos = prev->next; | 317 | pos = prev->next; |
318 | continue; | 318 | continue; |
319 | } | 319 | } |
320 | 320 | ||
321 | if ( (pos->headersReceived == 1) && | 321 | if ( (pos->headersReceived == 1) && |
322 | (pos->response == NULL) ) | 322 | (pos->response == NULL) ) |
323 | MHD_call_session_handler(pos); | 323 | MHD_call_session_handler(pos); |
324 | 324 | ||
325 | prev = pos; | 325 | prev = pos; |
326 | pos = pos->next; | 326 | pos = pos->next; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | 329 | ||
@@ -345,14 +345,14 @@ MHD_select(struct MHD_Daemon * daemon, | |||
345 | int max; | 345 | int max; |
346 | struct timeval timeout; | 346 | struct timeval timeout; |
347 | int ds; | 347 | int ds; |
348 | 348 | ||
349 | timeout.tv_sec = 0; | 349 | timeout.tv_sec = 0; |
350 | timeout.tv_usec = 0; | 350 | timeout.tv_usec = 0; |
351 | if(daemon == NULL) | 351 | if(daemon == NULL) |
352 | abort(); | 352 | abort(); |
353 | FD_ZERO(&rs); | 353 | FD_ZERO(&rs); |
354 | FD_ZERO(&ws); | 354 | FD_ZERO(&ws); |
355 | FD_ZERO(&es); | 355 | FD_ZERO(&es); |
356 | max = 0; | 356 | max = 0; |
357 | 357 | ||
358 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { | 358 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { |
@@ -372,21 +372,21 @@ MHD_select(struct MHD_Daemon * daemon, | |||
372 | &rs, | 372 | &rs, |
373 | &ws, | 373 | &ws, |
374 | &es, | 374 | &es, |
375 | may_block == MHD_NO ? &timeout : NULL); | 375 | may_block == MHD_NO ? &timeout : NULL); |
376 | if (num_ready < 0) { | 376 | if (num_ready < 0) { |
377 | if (errno == EINTR) | 377 | if (errno == EINTR) |
378 | return MHD_YES; | 378 | return MHD_YES; |
379 | MHD_DLOG(daemon, | 379 | MHD_DLOG(daemon, |
380 | "Select failed: %s\n", | 380 | "Select failed: %s\n", |
381 | STRERROR(errno)); | 381 | STRERROR(errno)); |
382 | return MHD_NO; | 382 | return MHD_NO; |
383 | } | 383 | } |
384 | ds = daemon->socket_fd; | 384 | ds = daemon->socket_fd; |
385 | if (ds == -1) | 385 | if (ds == -1) |
386 | return MHD_YES; | 386 | return MHD_YES; |
387 | if (FD_ISSET(ds, | 387 | if (FD_ISSET(ds, |
388 | &rs)) | 388 | &rs)) |
389 | MHD_accept_connection(daemon); | 389 | MHD_accept_connection(daemon); |
390 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { | 390 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { |
391 | /* do not have a thread per connection, process all connections now */ | 391 | /* do not have a thread per connection, process all connections now */ |
392 | pos = daemon->connections; | 392 | pos = daemon->connections; |
@@ -396,7 +396,7 @@ MHD_select(struct MHD_Daemon * daemon, | |||
396 | pos = pos->next; | 396 | pos = pos->next; |
397 | continue; | 397 | continue; |
398 | } | 398 | } |
399 | if (FD_ISSET(ds, &rs)) | 399 | if (FD_ISSET(ds, &rs)) |
400 | MHD_session_handle_read(pos); | 400 | MHD_session_handle_read(pos); |
401 | if (FD_ISSET(ds, &ws)) | 401 | if (FD_ISSET(ds, &ws)) |
402 | MHD_session_handle_write(pos); | 402 | MHD_session_handle_write(pos); |
@@ -411,7 +411,7 @@ MHD_select(struct MHD_Daemon * daemon, | |||
411 | * Run webserver operations (without blocking unless | 411 | * Run webserver operations (without blocking unless |
412 | * in client callbacks). This method should be called | 412 | * in client callbacks). This method should be called |
413 | * by clients in combination with MHD_get_fdset | 413 | * by clients in combination with MHD_get_fdset |
414 | * if the client-controlled select method is used. | 414 | * if the client-controlled select method is used. |
415 | * | 415 | * |
416 | * @return MHD_YES on success, MHD_NO if this | 416 | * @return MHD_YES on success, MHD_NO if this |
417 | * daemon was not started with the right | 417 | * daemon was not started with the right |
@@ -466,12 +466,12 @@ MHD_start_daemon(unsigned int options, | |||
466 | int socket_fd; | 466 | int socket_fd; |
467 | struct sockaddr_in servaddr; | 467 | struct sockaddr_in servaddr; |
468 | 468 | ||
469 | if ((options & MHD_USE_SSL) != 0) | 469 | if ((options & MHD_USE_SSL) != 0) |
470 | return NULL; | 470 | return NULL; |
471 | if ((options & MHD_USE_IPv6) != 0) | 471 | if ((options & MHD_USE_IPv6) != 0) |
472 | return NULL; | 472 | return NULL; |
473 | if ((options & MHD_USE_IPv4) == 0) | 473 | if ((options & MHD_USE_IPv4) == 0) |
474 | return NULL; | 474 | return NULL; |
475 | if ( (port == 0) || | 475 | if ( (port == 0) || |
476 | (dh == NULL) ) | 476 | (dh == NULL) ) |
477 | return NULL; | 477 | return NULL; |
@@ -486,11 +486,11 @@ MHD_start_daemon(unsigned int options, | |||
486 | /* FIXME: setsockopt: SO_REUSEADDR? */ | 486 | /* FIXME: setsockopt: SO_REUSEADDR? */ |
487 | memset(&servaddr, | 487 | memset(&servaddr, |
488 | 0, | 488 | 0, |
489 | sizeof(struct sockaddr_in)); | 489 | sizeof(struct sockaddr_in)); |
490 | servaddr.sin_family = AF_INET; | 490 | servaddr.sin_family = AF_INET; |
491 | servaddr.sin_port = htons(port); | 491 | servaddr.sin_port = htons(port); |
492 | if (BIND(socket_fd, | 492 | if (BIND(socket_fd, |
493 | (struct sockaddr *)&servaddr, | 493 | (struct sockaddr *)&servaddr, |
494 | sizeof(struct sockaddr_in)) < 0) { | 494 | sizeof(struct sockaddr_in)) < 0) { |
495 | if ( (options & MHD_USE_DEBUG) != 0) | 495 | if ( (options & MHD_USE_DEBUG) != 0) |
496 | fprintf(stderr, | 496 | fprintf(stderr, |
@@ -506,7 +506,7 @@ MHD_start_daemon(unsigned int options, | |||
506 | "Failed to listen for connections: %s\n", | 506 | "Failed to listen for connections: %s\n", |
507 | STRERROR(errno)); | 507 | STRERROR(errno)); |
508 | CLOSE(socket_fd); | 508 | CLOSE(socket_fd); |
509 | return NULL; | 509 | return NULL; |
510 | } | 510 | } |
511 | retVal = malloc(sizeof(struct MHD_Daemon)); | 511 | retVal = malloc(sizeof(struct MHD_Daemon)); |
512 | memset(retVal, | 512 | memset(retVal, |
@@ -524,15 +524,15 @@ MHD_start_daemon(unsigned int options, | |||
524 | if ( ( (0 != (options & MHD_USE_THREAD_PER_CONNECTION)) || | 524 | if ( ( (0 != (options & MHD_USE_THREAD_PER_CONNECTION)) || |
525 | (0 != (options & MHD_USE_SELECT_INTERNALLY)) ) && | 525 | (0 != (options & MHD_USE_SELECT_INTERNALLY)) ) && |
526 | (0 != pthread_create(&retVal->pid, | 526 | (0 != pthread_create(&retVal->pid, |
527 | NULL, | 527 | NULL, |
528 | &MHD_select_thread, | 528 | &MHD_select_thread, |
529 | retVal)) ) { | 529 | retVal)) ) { |
530 | MHD_DLOG(retVal, | 530 | MHD_DLOG(retVal, |
531 | "Failed to create listen thread: %s\n", | 531 | "Failed to create listen thread: %s\n", |
532 | STRERROR(errno)); | 532 | STRERROR(errno)); |
533 | free(retVal); | 533 | free(retVal); |
534 | CLOSE(socket_fd); | 534 | CLOSE(socket_fd); |
535 | return NULL; | 535 | return NULL; |
536 | } | 536 | } |
537 | return retVal; | 537 | return retVal; |
538 | } | 538 | } |
@@ -544,12 +544,12 @@ void | |||
544 | MHD_stop_daemon(struct MHD_Daemon * daemon) { | 544 | MHD_stop_daemon(struct MHD_Daemon * daemon) { |
545 | void * unused; | 545 | void * unused; |
546 | 546 | ||
547 | if (daemon == NULL) | 547 | if (daemon == NULL) |
548 | return; | 548 | return; |
549 | daemon->shutdown = 1; | 549 | daemon->shutdown = 1; |
550 | CLOSE(daemon->socket_fd); | 550 | CLOSE(daemon->socket_fd); |
551 | daemon->socket_fd = -1; | 551 | daemon->socket_fd = -1; |
552 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || | 552 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || |
553 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { | 553 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { |
554 | pthread_kill(daemon->pid, SIGALRM); | 554 | pthread_kill(daemon->pid, SIGALRM); |
555 | pthread_join(daemon->pid, &unused); | 555 | pthread_join(daemon->pid, &unused); |
diff --git a/src/daemon/daemontest.c b/src/daemon/daemontest.c index 9e86e389..10e7229d 100644 --- a/src/daemon/daemontest.c +++ b/src/daemon/daemontest.c | |||
@@ -35,7 +35,7 @@ static int testStartError() { | |||
35 | struct MHD_Daemon * d; | 35 | struct MHD_Daemon * d; |
36 | 36 | ||
37 | d = MHD_start_daemon(MHD_USE_DEBUG, 0, NULL, NULL, NULL, NULL); | 37 | d = MHD_start_daemon(MHD_USE_DEBUG, 0, NULL, NULL, NULL, NULL); |
38 | if (d != NULL) | 38 | if (d != NULL) |
39 | return 1; | 39 | return 1; |
40 | return 0; | 40 | return 0; |
41 | } | 41 | } |
@@ -70,8 +70,8 @@ static int testStartStop() { | |||
70 | NULL, | 70 | NULL, |
71 | &ahc_nothing, | 71 | &ahc_nothing, |
72 | NULL); | 72 | NULL); |
73 | if (d == NULL) | 73 | if (d == NULL) |
74 | return 2; | 74 | return 2; |
75 | MHD_stop_daemon(d); | 75 | MHD_stop_daemon(d); |
76 | return 0; | 76 | return 0; |
77 | } | 77 | } |
@@ -89,8 +89,8 @@ static int testExternalRun() { | |||
89 | &ahc_nothing, | 89 | &ahc_nothing, |
90 | NULL); | 90 | NULL); |
91 | 91 | ||
92 | if (d == NULL) | 92 | if (d == NULL) |
93 | return 4; | 93 | return 4; |
94 | i = 0; | 94 | i = 0; |
95 | while(i < 15) { | 95 | while(i < 15) { |
96 | maxfd = 0; | 96 | maxfd = 0; |
@@ -115,9 +115,9 @@ static int testThread() { | |||
115 | &ahc_nothing, | 115 | &ahc_nothing, |
116 | NULL); | 116 | NULL); |
117 | 117 | ||
118 | if (d == NULL) | 118 | if (d == NULL) |
119 | return 16; | 119 | return 16; |
120 | if (MHD_run(d) != MHD_NO) | 120 | if (MHD_run(d) != MHD_NO) |
121 | return 32; | 121 | return 32; |
122 | MHD_stop_daemon(d); | 122 | MHD_stop_daemon(d); |
123 | return 0; | 123 | return 0; |
@@ -132,11 +132,11 @@ static int testMultithread() { | |||
132 | &ahc_nothing, | 132 | &ahc_nothing, |
133 | NULL); | 133 | NULL); |
134 | 134 | ||
135 | if (d == NULL) | 135 | if (d == NULL) |
136 | return 64; | 136 | return 64; |
137 | if (MHD_run(d) != MHD_NO) | 137 | if (MHD_run(d) != MHD_NO) |
138 | return 128; | 138 | return 128; |
139 | MHD_stop_daemon(d); | 139 | MHD_stop_daemon(d); |
140 | return 0; | 140 | return 0; |
141 | } | 141 | } |
142 | 142 | ||
@@ -149,8 +149,8 @@ int main(int argc, | |||
149 | errorCount += testThread(); | 149 | errorCount += testThread(); |
150 | errorCount += testMultithread(); | 150 | errorCount += testMultithread(); |
151 | if (errorCount != 0) | 151 | if (errorCount != 0) |
152 | fprintf(stderr, | 152 | fprintf(stderr, |
153 | "Error (code: %u)\n", | 153 | "Error (code: %u)\n", |
154 | errorCount); | 154 | errorCount); |
155 | return errorCount != 0; /* 0 == pass */ | 155 | return errorCount != 0; /* 0 == pass */ |
156 | } | 156 | } |
diff --git a/src/daemon/daemontest_get.c b/src/daemon/daemontest_get.c index d3b6c5bc..d4030b06 100644 --- a/src/daemon/daemontest_get.c +++ b/src/daemon/daemontest_get.c | |||
@@ -125,18 +125,18 @@ static int testInternalGet() { | |||
125 | // crashes on my system! | 125 | // crashes on my system! |
126 | curl_easy_setopt(c, | 126 | curl_easy_setopt(c, |
127 | CURLOPT_NOSIGNAL, | 127 | CURLOPT_NOSIGNAL, |
128 | 1); | 128 | 1); |
129 | if (CURLE_OK != curl_easy_perform(c)) { | 129 | if (CURLE_OK != curl_easy_perform(c)) { |
130 | curl_easy_cleanup(c); | 130 | curl_easy_cleanup(c); |
131 | MHD_stop_daemon(d); | 131 | MHD_stop_daemon(d); |
132 | return 2; | 132 | return 2; |
133 | } | 133 | } |
134 | curl_easy_cleanup(c); | 134 | curl_easy_cleanup(c); |
135 | if (cbc.pos != strlen("/hello_world")) { | 135 | if (cbc.pos != strlen("/hello_world")) { |
136 | MHD_stop_daemon(d); | 136 | MHD_stop_daemon(d); |
137 | return 4; | 137 | return 4; |
138 | } | 138 | } |
139 | 139 | ||
140 | if (0 != strncmp("/hello_world", | 140 | if (0 != strncmp("/hello_world", |
141 | cbc.buf, | 141 | cbc.buf, |
142 | strlen("/hello_world"))) { | 142 | strlen("/hello_world"))) { |
@@ -144,7 +144,7 @@ static int testInternalGet() { | |||
144 | return 8; | 144 | return 8; |
145 | } | 145 | } |
146 | MHD_stop_daemon(d); | 146 | MHD_stop_daemon(d); |
147 | 147 | ||
148 | return 0; | 148 | return 0; |
149 | } | 149 | } |
150 | 150 | ||
@@ -189,16 +189,16 @@ static int testMultithreadedGet() { | |||
189 | // crashes on my system! | 189 | // crashes on my system! |
190 | curl_easy_setopt(c, | 190 | curl_easy_setopt(c, |
191 | CURLOPT_NOSIGNAL, | 191 | CURLOPT_NOSIGNAL, |
192 | 1); | 192 | 1); |
193 | if (CURLE_OK != curl_easy_perform(c)) { | 193 | if (CURLE_OK != curl_easy_perform(c)) { |
194 | MHD_stop_daemon(d); | 194 | MHD_stop_daemon(d); |
195 | return 32; | 195 | return 32; |
196 | } | 196 | } |
197 | curl_easy_cleanup(c); | 197 | curl_easy_cleanup(c); |
198 | if (cbc.pos != strlen("/hello_world")) { | 198 | if (cbc.pos != strlen("/hello_world")) { |
199 | MHD_stop_daemon(d); | 199 | MHD_stop_daemon(d); |
200 | return 64; | 200 | return 64; |
201 | } | 201 | } |
202 | if (0 != strncmp("/hello_world", | 202 | if (0 != strncmp("/hello_world", |
203 | cbc.buf, | 203 | cbc.buf, |
204 | strlen("/hello_world"))) { | 204 | strlen("/hello_world"))) { |
@@ -206,7 +206,7 @@ static int testMultithreadedGet() { | |||
206 | return 128; | 206 | return 128; |
207 | } | 207 | } |
208 | MHD_stop_daemon(d); | 208 | MHD_stop_daemon(d); |
209 | 209 | ||
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
@@ -263,20 +263,20 @@ static int testExternalGet() { | |||
263 | // crashes on my system! | 263 | // crashes on my system! |
264 | curl_easy_setopt(c, | 264 | curl_easy_setopt(c, |
265 | CURLOPT_NOSIGNAL, | 265 | CURLOPT_NOSIGNAL, |
266 | 1); | 266 | 1); |
267 | 267 | ||
268 | 268 | ||
269 | multi = curl_multi_init(); | 269 | multi = curl_multi_init(); |
270 | if (multi == NULL) { | 270 | if (multi == NULL) { |
271 | curl_easy_cleanup(c); | 271 | curl_easy_cleanup(c); |
272 | MHD_stop_daemon(d); | 272 | MHD_stop_daemon(d); |
273 | return 512; | 273 | return 512; |
274 | } | 274 | } |
275 | mret = curl_multi_add_handle(multi, c); | 275 | mret = curl_multi_add_handle(multi, c); |
276 | if (mret != CURLM_OK) { | 276 | if (mret != CURLM_OK) { |
277 | curl_multi_cleanup(multi); | 277 | curl_multi_cleanup(multi); |
278 | curl_easy_cleanup(c); | 278 | curl_easy_cleanup(c); |
279 | MHD_stop_daemon(d); | 279 | MHD_stop_daemon(d); |
280 | return 1024; | 280 | return 1024; |
281 | } | 281 | } |
282 | start = time(NULL); | 282 | start = time(NULL); |
@@ -295,9 +295,9 @@ static int testExternalGet() { | |||
295 | if (mret != CURLM_OK) { | 295 | if (mret != CURLM_OK) { |
296 | curl_multi_remove_handle(multi, c); | 296 | curl_multi_remove_handle(multi, c); |
297 | curl_multi_cleanup(multi); | 297 | curl_multi_cleanup(multi); |
298 | curl_easy_cleanup(c); | 298 | curl_easy_cleanup(c); |
299 | MHD_stop_daemon(d); | 299 | MHD_stop_daemon(d); |
300 | return 2048; | 300 | return 2048; |
301 | } | 301 | } |
302 | if (MHD_YES != MHD_get_fdset(d, | 302 | if (MHD_YES != MHD_get_fdset(d, |
303 | &rs, | 303 | &rs, |
@@ -306,8 +306,8 @@ static int testExternalGet() { | |||
306 | &max)) { | 306 | &max)) { |
307 | curl_multi_remove_handle(multi, c); | 307 | curl_multi_remove_handle(multi, c); |
308 | curl_multi_cleanup(multi); | 308 | curl_multi_cleanup(multi); |
309 | curl_easy_cleanup(c); | 309 | curl_easy_cleanup(c); |
310 | MHD_stop_daemon(d); | 310 | MHD_stop_daemon(d); |
311 | return 4096; | 311 | return 4096; |
312 | } | 312 | } |
313 | tv.tv_sec = 0; | 313 | tv.tv_sec = 0; |
@@ -316,7 +316,7 @@ static int testExternalGet() { | |||
316 | &rs, | 316 | &rs, |
317 | &ws, | 317 | &ws, |
318 | &es, | 318 | &es, |
319 | &tv); | 319 | &tv); |
320 | curl_multi_perform(multi, &running); | 320 | curl_multi_perform(multi, &running); |
321 | if (running == 0) { | 321 | if (running == 0) { |
322 | msg = curl_multi_info_read(multi, | 322 | msg = curl_multi_info_read(multi, |
@@ -341,15 +341,15 @@ static int testExternalGet() { | |||
341 | } | 341 | } |
342 | if (multi != NULL) { | 342 | if (multi != NULL) { |
343 | curl_multi_remove_handle(multi, c); | 343 | curl_multi_remove_handle(multi, c); |
344 | curl_easy_cleanup(c); | 344 | curl_easy_cleanup(c); |
345 | curl_multi_cleanup(multi); | 345 | curl_multi_cleanup(multi); |
346 | } | 346 | } |
347 | MHD_stop_daemon(d); | 347 | MHD_stop_daemon(d); |
348 | if (cbc.pos != strlen("/hello_world")) | 348 | if (cbc.pos != strlen("/hello_world")) |
349 | return 8192; | 349 | return 8192; |
350 | if (0 != strncmp("/hello_world", | 350 | if (0 != strncmp("/hello_world", |
351 | cbc.buf, | 351 | cbc.buf, |
352 | strlen("/hello_world"))) | 352 | strlen("/hello_world"))) |
353 | return 16384; | 353 | return 16384; |
354 | return 0; | 354 | return 0; |
355 | } | 355 | } |
@@ -360,14 +360,14 @@ int main(int argc, | |||
360 | char * const * argv) { | 360 | char * const * argv) { |
361 | unsigned int errorCount = 0; | 361 | unsigned int errorCount = 0; |
362 | 362 | ||
363 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) | 363 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
364 | return 2; | 364 | return 2; |
365 | errorCount += testInternalGet(); | 365 | errorCount += testInternalGet(); |
366 | errorCount += testMultithreadedGet(); | 366 | errorCount += testMultithreadedGet(); |
367 | errorCount += testExternalGet(); | 367 | errorCount += testExternalGet(); |
368 | if (errorCount != 0) | 368 | if (errorCount != 0) |
369 | fprintf(stderr, | 369 | fprintf(stderr, |
370 | "Error (code: %u)\n", | 370 | "Error (code: %u)\n", |
371 | errorCount); | 371 | errorCount); |
372 | curl_global_cleanup(); | 372 | curl_global_cleanup(); |
373 | return errorCount != 0; /* 0 == pass */ | 373 | return errorCount != 0; /* 0 == pass */ |
diff --git a/src/daemon/daemontest_post.c b/src/daemon/daemontest_post.c index 5e46bac3..c74a3a02 100644 --- a/src/daemon/daemontest_post.c +++ b/src/daemon/daemontest_post.c | |||
@@ -21,7 +21,7 @@ | |||
21 | /** | 21 | /** |
22 | * @file daemontest_post.c | 22 | * @file daemontest_post.c |
23 | * @brief Testcase for libmicrohttpd POST operations | 23 | * @brief Testcase for libmicrohttpd POST operations |
24 | * TODO: use curl_formadd to produce POST data and | 24 | * TODO: use curl_formadd to produce POST data and |
25 | * add that to the CURL operation; then check | 25 | * add that to the CURL operation; then check |
26 | * on the server side if the headers arrive | 26 | * on the server side if the headers arrive |
27 | * nicely (need to implement parsing POST data | 27 | * nicely (need to implement parsing POST data |
@@ -137,18 +137,18 @@ static int testInternalPost() { | |||
137 | // crashes on my system! | 137 | // crashes on my system! |
138 | curl_easy_setopt(c, | 138 | curl_easy_setopt(c, |
139 | CURLOPT_NOSIGNAL, | 139 | CURLOPT_NOSIGNAL, |
140 | 1); | 140 | 1); |
141 | if (CURLE_OK != curl_easy_perform(c)) { | 141 | if (CURLE_OK != curl_easy_perform(c)) { |
142 | curl_easy_cleanup(c); | 142 | curl_easy_cleanup(c); |
143 | MHD_stop_daemon(d); | 143 | MHD_stop_daemon(d); |
144 | return 2; | 144 | return 2; |
145 | } | 145 | } |
146 | curl_easy_cleanup(c); | 146 | curl_easy_cleanup(c); |
147 | if (cbc.pos != strlen("/hello_world")) { | 147 | if (cbc.pos != strlen("/hello_world")) { |
148 | MHD_stop_daemon(d); | 148 | MHD_stop_daemon(d); |
149 | return 4; | 149 | return 4; |
150 | } | 150 | } |
151 | 151 | ||
152 | if (0 != strncmp("/hello_world", | 152 | if (0 != strncmp("/hello_world", |
153 | cbc.buf, | 153 | cbc.buf, |
154 | strlen("/hello_world"))) { | 154 | strlen("/hello_world"))) { |
@@ -156,7 +156,7 @@ static int testInternalPost() { | |||
156 | return 8; | 156 | return 8; |
157 | } | 157 | } |
158 | MHD_stop_daemon(d); | 158 | MHD_stop_daemon(d); |
159 | 159 | ||
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | 162 | ||
@@ -207,17 +207,17 @@ static int testMultithreadedPost() { | |||
207 | // crashes on my system! | 207 | // crashes on my system! |
208 | curl_easy_setopt(c, | 208 | curl_easy_setopt(c, |
209 | CURLOPT_NOSIGNAL, | 209 | CURLOPT_NOSIGNAL, |
210 | 1); | 210 | 1); |
211 | if (CURLE_OK != curl_easy_perform(c)) { | 211 | if (CURLE_OK != curl_easy_perform(c)) { |
212 | curl_easy_cleanup(c); | 212 | curl_easy_cleanup(c); |
213 | MHD_stop_daemon(d); | 213 | MHD_stop_daemon(d); |
214 | return 32; | 214 | return 32; |
215 | } | 215 | } |
216 | curl_easy_cleanup(c); | 216 | curl_easy_cleanup(c); |
217 | if (cbc.pos != strlen("/hello_world")) { | 217 | if (cbc.pos != strlen("/hello_world")) { |
218 | MHD_stop_daemon(d); | 218 | MHD_stop_daemon(d); |
219 | return 64; | 219 | return 64; |
220 | } | 220 | } |
221 | if (0 != strncmp("/hello_world", | 221 | if (0 != strncmp("/hello_world", |
222 | cbc.buf, | 222 | cbc.buf, |
223 | strlen("/hello_world"))) { | 223 | strlen("/hello_world"))) { |
@@ -225,7 +225,7 @@ static int testMultithreadedPost() { | |||
225 | return 128; | 225 | return 128; |
226 | } | 226 | } |
227 | MHD_stop_daemon(d); | 227 | MHD_stop_daemon(d); |
228 | 228 | ||
229 | return 0; | 229 | return 0; |
230 | } | 230 | } |
231 | 231 | ||
@@ -288,20 +288,20 @@ static int testExternalPost() { | |||
288 | // crashes on my system! | 288 | // crashes on my system! |
289 | curl_easy_setopt(c, | 289 | curl_easy_setopt(c, |
290 | CURLOPT_NOSIGNAL, | 290 | CURLOPT_NOSIGNAL, |
291 | 1); | 291 | 1); |
292 | 292 | ||
293 | 293 | ||
294 | multi = curl_multi_init(); | 294 | multi = curl_multi_init(); |
295 | if (multi == NULL) { | 295 | if (multi == NULL) { |
296 | curl_easy_cleanup(c); | 296 | curl_easy_cleanup(c); |
297 | MHD_stop_daemon(d); | 297 | MHD_stop_daemon(d); |
298 | return 512; | 298 | return 512; |
299 | } | 299 | } |
300 | mret = curl_multi_add_handle(multi, c); | 300 | mret = curl_multi_add_handle(multi, c); |
301 | if (mret != CURLM_OK) { | 301 | if (mret != CURLM_OK) { |
302 | curl_multi_cleanup(multi); | 302 | curl_multi_cleanup(multi); |
303 | curl_easy_cleanup(c); | 303 | curl_easy_cleanup(c); |
304 | MHD_stop_daemon(d); | 304 | MHD_stop_daemon(d); |
305 | return 1024; | 305 | return 1024; |
306 | } | 306 | } |
307 | start = time(NULL); | 307 | start = time(NULL); |
@@ -320,9 +320,9 @@ static int testExternalPost() { | |||
320 | if (mret != CURLM_OK) { | 320 | if (mret != CURLM_OK) { |
321 | curl_multi_remove_handle(multi, c); | 321 | curl_multi_remove_handle(multi, c); |
322 | curl_multi_cleanup(multi); | 322 | curl_multi_cleanup(multi); |
323 | curl_easy_cleanup(c); | 323 | curl_easy_cleanup(c); |
324 | MHD_stop_daemon(d); | 324 | MHD_stop_daemon(d); |
325 | return 2048; | 325 | return 2048; |
326 | } | 326 | } |
327 | if (MHD_YES != MHD_get_fdset(d, | 327 | if (MHD_YES != MHD_get_fdset(d, |
328 | &rs, | 328 | &rs, |
@@ -331,8 +331,8 @@ static int testExternalPost() { | |||
331 | &max)) { | 331 | &max)) { |
332 | curl_multi_remove_handle(multi, c); | 332 | curl_multi_remove_handle(multi, c); |
333 | curl_multi_cleanup(multi); | 333 | curl_multi_cleanup(multi); |
334 | curl_easy_cleanup(c); | 334 | curl_easy_cleanup(c); |
335 | MHD_stop_daemon(d); | 335 | MHD_stop_daemon(d); |
336 | return 4096; | 336 | return 4096; |
337 | } | 337 | } |
338 | tv.tv_sec = 0; | 338 | tv.tv_sec = 0; |
@@ -341,7 +341,7 @@ static int testExternalPost() { | |||
341 | &rs, | 341 | &rs, |
342 | &ws, | 342 | &ws, |
343 | &es, | 343 | &es, |
344 | &tv); | 344 | &tv); |
345 | curl_multi_perform(multi, &running); | 345 | curl_multi_perform(multi, &running); |
346 | if (running == 0) { | 346 | if (running == 0) { |
347 | msg = curl_multi_info_read(multi, | 347 | msg = curl_multi_info_read(multi, |
@@ -366,15 +366,15 @@ static int testExternalPost() { | |||
366 | } | 366 | } |
367 | if (multi != NULL) { | 367 | if (multi != NULL) { |
368 | curl_multi_remove_handle(multi, c); | 368 | curl_multi_remove_handle(multi, c); |
369 | curl_easy_cleanup(c); | 369 | curl_easy_cleanup(c); |
370 | curl_multi_cleanup(multi); | 370 | curl_multi_cleanup(multi); |
371 | } | 371 | } |
372 | MHD_stop_daemon(d); | 372 | MHD_stop_daemon(d); |
373 | if (cbc.pos != strlen("/hello_world")) | 373 | if (cbc.pos != strlen("/hello_world")) |
374 | return 8192; | 374 | return 8192; |
375 | if (0 != strncmp("/hello_world", | 375 | if (0 != strncmp("/hello_world", |
376 | cbc.buf, | 376 | cbc.buf, |
377 | strlen("/hello_world"))) | 377 | strlen("/hello_world"))) |
378 | return 16384; | 378 | return 16384; |
379 | return 0; | 379 | return 0; |
380 | } | 380 | } |
@@ -385,14 +385,14 @@ int main(int argc, | |||
385 | char * const * argv) { | 385 | char * const * argv) { |
386 | unsigned int errorCount = 0; | 386 | unsigned int errorCount = 0; |
387 | 387 | ||
388 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) | 388 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
389 | return 2; | 389 | return 2; |
390 | errorCount += testInternalPost(); | 390 | errorCount += testInternalPost(); |
391 | errorCount += testMultithreadedPost(); | 391 | errorCount += testMultithreadedPost(); |
392 | errorCount += testExternalPost(); | 392 | errorCount += testExternalPost(); |
393 | if (errorCount != 0) | 393 | if (errorCount != 0) |
394 | fprintf(stderr, | 394 | fprintf(stderr, |
395 | "Error (code: %u)\n", | 395 | "Error (code: %u)\n", |
396 | errorCount); | 396 | errorCount); |
397 | curl_global_cleanup(); | 397 | curl_global_cleanup(); |
398 | return errorCount != 0; /* 0 == pass */ | 398 | return errorCount != 0; /* 0 == pass */ |
diff --git a/src/daemon/daemontest_put.c b/src/daemon/daemontest_put.c index 822f44a1..00538757 100644 --- a/src/daemon/daemontest_put.c +++ b/src/daemon/daemontest_put.c | |||
@@ -86,11 +86,11 @@ static int ahc_echo(void * cls, | |||
86 | struct MHD_Response * response; | 86 | struct MHD_Response * response; |
87 | int ret; | 87 | int ret; |
88 | 88 | ||
89 | if (0 != strcmp("PUT", method)) | 89 | if (0 != strcmp("PUT", method)) |
90 | return MHD_NO; /* unexpected method */ | 90 | return MHD_NO; /* unexpected method */ |
91 | if ((*done) == 0) { | 91 | if ((*done) == 0) { |
92 | if (*upload_data_size != 8) | 92 | if (*upload_data_size != 8) |
93 | return MHD_YES; /* not yet ready */ | 93 | return MHD_YES; /* not yet ready */ |
94 | if (0 == memcmp(upload_data, | 94 | if (0 == memcmp(upload_data, |
95 | "Hello123", | 95 | "Hello123", |
96 | 8)) { | 96 | 8)) { |
@@ -170,18 +170,18 @@ static int testInternalPut() { | |||
170 | // crashes on my system! | 170 | // crashes on my system! |
171 | curl_easy_setopt(c, | 171 | curl_easy_setopt(c, |
172 | CURLOPT_NOSIGNAL, | 172 | CURLOPT_NOSIGNAL, |
173 | 1); | 173 | 1); |
174 | if (CURLE_OK != curl_easy_perform(c)) { | 174 | if (CURLE_OK != curl_easy_perform(c)) { |
175 | curl_easy_cleanup(c); | 175 | curl_easy_cleanup(c); |
176 | MHD_stop_daemon(d); | 176 | MHD_stop_daemon(d); |
177 | return 2; | 177 | return 2; |
178 | } | 178 | } |
179 | curl_easy_cleanup(c); | 179 | curl_easy_cleanup(c); |
180 | if (cbc.pos != strlen("/hello_world")) { | 180 | if (cbc.pos != strlen("/hello_world")) { |
181 | MHD_stop_daemon(d); | 181 | MHD_stop_daemon(d); |
182 | return 4; | 182 | return 4; |
183 | } | 183 | } |
184 | 184 | ||
185 | if (0 != strncmp("/hello_world", | 185 | if (0 != strncmp("/hello_world", |
186 | cbc.buf, | 186 | cbc.buf, |
187 | strlen("/hello_world"))) { | 187 | strlen("/hello_world"))) { |
@@ -189,7 +189,7 @@ static int testInternalPut() { | |||
189 | return 8; | 189 | return 8; |
190 | } | 190 | } |
191 | MHD_stop_daemon(d); | 191 | MHD_stop_daemon(d); |
192 | 192 | ||
193 | return 0; | 193 | return 0; |
194 | } | 194 | } |
195 | 195 | ||
@@ -248,17 +248,17 @@ static int testMultithreadedPut() { | |||
248 | // crashes on my system! | 248 | // crashes on my system! |
249 | curl_easy_setopt(c, | 249 | curl_easy_setopt(c, |
250 | CURLOPT_NOSIGNAL, | 250 | CURLOPT_NOSIGNAL, |
251 | 1); | 251 | 1); |
252 | if (CURLE_OK != curl_easy_perform(c)) { | 252 | if (CURLE_OK != curl_easy_perform(c)) { |
253 | curl_easy_cleanup(c); | 253 | curl_easy_cleanup(c); |
254 | MHD_stop_daemon(d); | 254 | MHD_stop_daemon(d); |
255 | return 32; | 255 | return 32; |
256 | } | 256 | } |
257 | curl_easy_cleanup(c); | 257 | curl_easy_cleanup(c); |
258 | if (cbc.pos != strlen("/hello_world")) { | 258 | if (cbc.pos != strlen("/hello_world")) { |
259 | MHD_stop_daemon(d); | 259 | MHD_stop_daemon(d); |
260 | return 64; | 260 | return 64; |
261 | } | 261 | } |
262 | if (0 != strncmp("/hello_world", | 262 | if (0 != strncmp("/hello_world", |
263 | cbc.buf, | 263 | cbc.buf, |
264 | strlen("/hello_world"))) { | 264 | strlen("/hello_world"))) { |
@@ -266,7 +266,7 @@ static int testMultithreadedPut() { | |||
266 | return 128; | 266 | return 128; |
267 | } | 267 | } |
268 | MHD_stop_daemon(d); | 268 | MHD_stop_daemon(d); |
269 | 269 | ||
270 | return 0; | 270 | return 0; |
271 | } | 271 | } |
272 | 272 | ||
@@ -337,20 +337,20 @@ static int testExternalPut() { | |||
337 | // crashes on my system! | 337 | // crashes on my system! |
338 | curl_easy_setopt(c, | 338 | curl_easy_setopt(c, |
339 | CURLOPT_NOSIGNAL, | 339 | CURLOPT_NOSIGNAL, |
340 | 1); | 340 | 1); |
341 | 341 | ||
342 | 342 | ||
343 | multi = curl_multi_init(); | 343 | multi = curl_multi_init(); |
344 | if (multi == NULL) { | 344 | if (multi == NULL) { |
345 | curl_easy_cleanup(c); | 345 | curl_easy_cleanup(c); |
346 | MHD_stop_daemon(d); | 346 | MHD_stop_daemon(d); |
347 | return 512; | 347 | return 512; |
348 | } | 348 | } |
349 | mret = curl_multi_add_handle(multi, c); | 349 | mret = curl_multi_add_handle(multi, c); |
350 | if (mret != CURLM_OK) { | 350 | if (mret != CURLM_OK) { |
351 | curl_multi_cleanup(multi); | 351 | curl_multi_cleanup(multi); |
352 | curl_easy_cleanup(c); | 352 | curl_easy_cleanup(c); |
353 | MHD_stop_daemon(d); | 353 | MHD_stop_daemon(d); |
354 | return 1024; | 354 | return 1024; |
355 | } | 355 | } |
356 | start = time(NULL); | 356 | start = time(NULL); |
@@ -369,9 +369,9 @@ static int testExternalPut() { | |||
369 | if (mret != CURLM_OK) { | 369 | if (mret != CURLM_OK) { |
370 | curl_multi_remove_handle(multi, c); | 370 | curl_multi_remove_handle(multi, c); |
371 | curl_multi_cleanup(multi); | 371 | curl_multi_cleanup(multi); |
372 | curl_easy_cleanup(c); | 372 | curl_easy_cleanup(c); |
373 | MHD_stop_daemon(d); | 373 | MHD_stop_daemon(d); |
374 | return 2048; | 374 | return 2048; |
375 | } | 375 | } |
376 | if (MHD_YES != MHD_get_fdset(d, | 376 | if (MHD_YES != MHD_get_fdset(d, |
377 | &rs, | 377 | &rs, |
@@ -380,8 +380,8 @@ static int testExternalPut() { | |||
380 | &max)) { | 380 | &max)) { |
381 | curl_multi_remove_handle(multi, c); | 381 | curl_multi_remove_handle(multi, c); |
382 | curl_multi_cleanup(multi); | 382 | curl_multi_cleanup(multi); |
383 | curl_easy_cleanup(c); | 383 | curl_easy_cleanup(c); |
384 | MHD_stop_daemon(d); | 384 | MHD_stop_daemon(d); |
385 | return 4096; | 385 | return 4096; |
386 | } | 386 | } |
387 | tv.tv_sec = 0; | 387 | tv.tv_sec = 0; |
@@ -390,7 +390,7 @@ static int testExternalPut() { | |||
390 | &rs, | 390 | &rs, |
391 | &ws, | 391 | &ws, |
392 | &es, | 392 | &es, |
393 | &tv); | 393 | &tv); |
394 | curl_multi_perform(multi, &running); | 394 | curl_multi_perform(multi, &running); |
395 | if (running == 0) { | 395 | if (running == 0) { |
396 | msg = curl_multi_info_read(multi, | 396 | msg = curl_multi_info_read(multi, |
@@ -415,15 +415,15 @@ static int testExternalPut() { | |||
415 | } | 415 | } |
416 | if (multi != NULL) { | 416 | if (multi != NULL) { |
417 | curl_multi_remove_handle(multi, c); | 417 | curl_multi_remove_handle(multi, c); |
418 | curl_easy_cleanup(c); | 418 | curl_easy_cleanup(c); |
419 | curl_multi_cleanup(multi); | 419 | curl_multi_cleanup(multi); |
420 | } | 420 | } |
421 | MHD_stop_daemon(d); | 421 | MHD_stop_daemon(d); |
422 | if (cbc.pos != strlen("/hello_world")) | 422 | if (cbc.pos != strlen("/hello_world")) |
423 | return 8192; | 423 | return 8192; |
424 | if (0 != strncmp("/hello_world", | 424 | if (0 != strncmp("/hello_world", |
425 | cbc.buf, | 425 | cbc.buf, |
426 | strlen("/hello_world"))) | 426 | strlen("/hello_world"))) |
427 | return 16384; | 427 | return 16384; |
428 | return 0; | 428 | return 0; |
429 | } | 429 | } |
@@ -434,14 +434,14 @@ int main(int argc, | |||
434 | char * const * argv) { | 434 | char * const * argv) { |
435 | unsigned int errorCount = 0; | 435 | unsigned int errorCount = 0; |
436 | 436 | ||
437 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) | 437 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
438 | return 2; | 438 | return 2; |
439 | errorCount += testInternalPut(); | 439 | errorCount += testInternalPut(); |
440 | errorCount += testMultithreadedPut(); | 440 | errorCount += testMultithreadedPut(); |
441 | errorCount += testExternalPut(); | 441 | errorCount += testExternalPut(); |
442 | if (errorCount != 0) | 442 | if (errorCount != 0) |
443 | fprintf(stderr, | 443 | fprintf(stderr, |
444 | "Error (code: %u)\n", | 444 | "Error (code: %u)\n", |
445 | errorCount); | 445 | errorCount); |
446 | curl_global_cleanup(); | 446 | curl_global_cleanup(); |
447 | return errorCount != 0; /* 0 == pass */ | 447 | return errorCount != 0; /* 0 == pass */ |
diff --git a/src/daemon/internal.c b/src/daemon/internal.c index 9ec1f623..eed1acba 100644 --- a/src/daemon/internal.c +++ b/src/daemon/internal.c | |||
@@ -36,7 +36,7 @@ void MHD_DLOG(const struct MHD_Daemon * daemon, | |||
36 | const char * format, | 36 | const char * format, |
37 | ...) { | 37 | ...) { |
38 | va_list va; | 38 | va_list va; |
39 | 39 | ||
40 | if ( (daemon->options & MHD_USE_DEBUG) == 0) | 40 | if ( (daemon->options & MHD_USE_DEBUG) == 0) |
41 | return; | 41 | return; |
42 | va_start(va, format); | 42 | va_start(va, format); |
diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 971ebb00..8d125a01 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h | |||
@@ -90,7 +90,7 @@ struct MHD_Access_Handler { | |||
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Representation of a response. | 92 | * Representation of a response. |
93 | */ | 93 | */ |
94 | struct MHD_Response { | 94 | struct MHD_Response { |
95 | 95 | ||
96 | /** | 96 | /** |
@@ -109,9 +109,9 @@ struct MHD_Response { | |||
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. |
@@ -135,7 +135,7 @@ struct MHD_Response { | |||
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 | */ |
@@ -151,7 +151,7 @@ struct MHD_Response { | |||
151 | * beginning of data located? | 151 | * beginning of data located? |
152 | */ | 152 | */ |
153 | size_t data_start; | 153 | size_t data_start; |
154 | 154 | ||
155 | }; | 155 | }; |
156 | 156 | ||
157 | 157 | ||
@@ -162,7 +162,7 @@ struct MHD_Session { | |||
162 | struct MHD_Daemon * daemon; | 162 | struct MHD_Daemon * daemon; |
163 | 163 | ||
164 | struct MHD_HTTP_Header * headers_received; | 164 | struct MHD_HTTP_Header * headers_received; |
165 | 165 | ||
166 | struct MHD_Response * response; | 166 | struct MHD_Response * response; |
167 | 167 | ||
168 | /** | 168 | /** |
@@ -184,7 +184,7 @@ struct MHD_Session { | |||
184 | * Buffer for writing response. | 184 | * Buffer for writing response. |
185 | */ | 185 | */ |
186 | char * write_buffer; | 186 | char * write_buffer; |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * Foreign address (of length addr_len). | 189 | * Foreign address (of length addr_len). |
190 | */ | 190 | */ |
@@ -237,19 +237,19 @@ struct MHD_Session { | |||
237 | * we are done sending our response. | 237 | * we are done sending our response. |
238 | */ | 238 | */ |
239 | int read_close; | 239 | int read_close; |
240 | 240 | ||
241 | /** | 241 | /** |
242 | * Have we finished receiving all of the headers yet? | 242 | * Have we finished receiving all of the headers yet? |
243 | * Set to 1 once we are done processing all of the | 243 | * Set to 1 once we are done processing all of the |
244 | * headers. Note that due to pipelining, it is | 244 | * headers. Note that due to pipelining, it is |
245 | * possible that the NEXT request is already | 245 | * possible that the NEXT request is already |
246 | * (partially) waiting in the read buffer. | 246 | * (partially) waiting in the read buffer. |
247 | */ | 247 | */ |
248 | int headersReceived; | 248 | int headersReceived; |
249 | 249 | ||
250 | /** | 250 | /** |
251 | * Have we finished receiving the data from a | 251 | * Have we finished receiving the data from a |
252 | * potential file-upload? | 252 | * potential file-upload? |
253 | */ | 253 | */ |
254 | int bodyReceived; | 254 | int bodyReceived; |
255 | 255 | ||
@@ -275,7 +275,7 @@ struct MHD_Daemon { | |||
275 | struct MHD_Access_Handler default_handler; | 275 | struct MHD_Access_Handler default_handler; |
276 | 276 | ||
277 | struct MHD_Session * connections; | 277 | struct MHD_Session * connections; |
278 | 278 | ||
279 | MHD_AcceptPolicyCallback apc; | 279 | MHD_AcceptPolicyCallback apc; |
280 | 280 | ||
281 | void * apc_cls; | 281 | void * apc_cls; |
diff --git a/src/daemon/minimal_example.c b/src/daemon/minimal_example.c index 6dad8180..b25ad106 100644 --- a/src/daemon/minimal_example.c +++ b/src/daemon/minimal_example.c | |||
@@ -82,7 +82,7 @@ int main(int argc, | |||
82 | if (d == NULL) | 82 | if (d == NULL) |
83 | return 1; | 83 | return 1; |
84 | sleep(atoi(argv[2])); | 84 | sleep(atoi(argv[2])); |
85 | MHD_stop_daemon(d); | 85 | MHD_stop_daemon(d); |
86 | return 0; | 86 | return 0; |
87 | } | 87 | } |
88 | 88 | ||
diff --git a/src/daemon/response.c b/src/daemon/response.c index e0942700..4bbe0f36 100644 --- a/src/daemon/response.c +++ b/src/daemon/response.c | |||
@@ -38,11 +38,11 @@ MHD_add_response_header(struct MHD_Response * response, | |||
38 | const char * header, | 38 | const char * header, |
39 | const char * content) { | 39 | const char * content) { |
40 | struct MHD_HTTP_Header * hdr; | 40 | struct MHD_HTTP_Header * hdr; |
41 | 41 | ||
42 | if ( (response == NULL) || | 42 | if ( (response == NULL) || |
43 | (header == NULL) || | 43 | (header == NULL) || |
44 | (content == NULL) || | 44 | (content == NULL) || |
45 | (strlen(header) == 0) || | 45 | (strlen(header) == 0) || |
46 | (strlen(content) == 0) || | 46 | (strlen(content) == 0) || |
47 | (NULL != strstr(header, "\t")) || | 47 | (NULL != strstr(header, "\t")) || |
48 | (NULL != strstr(header, "\r")) || | 48 | (NULL != strstr(header, "\r")) || |
@@ -72,14 +72,14 @@ MHD_del_response_header(struct MHD_Response * response, | |||
72 | struct MHD_HTTP_Header * pos; | 72 | struct MHD_HTTP_Header * pos; |
73 | struct MHD_HTTP_Header * prev; | 73 | struct MHD_HTTP_Header * prev; |
74 | 74 | ||
75 | if ( (header == NULL) || | 75 | if ( (header == NULL) || |
76 | (content == NULL) ) | 76 | (content == NULL) ) |
77 | return MHD_NO; | 77 | return MHD_NO; |
78 | prev = NULL; | 78 | prev = NULL; |
79 | pos = response->first_header; | 79 | pos = response->first_header; |
80 | while (pos != NULL) { | 80 | while (pos != NULL) { |
81 | if ( (0 == strcmp(header, pos->header)) && | 81 | if ( (0 == strcmp(header, pos->header)) && |
82 | (0 == strcmp(content, pos->value)) ) { | 82 | (0 == strcmp(content, pos->value)) ) { |
83 | free(pos->header); | 83 | free(pos->header); |
84 | free(pos->value); | 84 | free(pos->value); |
85 | if (prev == NULL) | 85 | if (prev == NULL) |
@@ -102,7 +102,7 @@ MHD_del_response_header(struct MHD_Response * response, | |||
102 | * maybe NULL (then just count headers) | 102 | * maybe NULL (then just count headers) |
103 | * @param iterator_cls extra argument to iterator | 103 | * @param iterator_cls extra argument to iterator |
104 | * @return number of entries iterated over | 104 | * @return number of entries iterated over |
105 | */ | 105 | */ |
106 | int | 106 | int |
107 | MHD_get_response_headers(struct MHD_Response * response, | 107 | MHD_get_response_headers(struct MHD_Response * response, |
108 | MHD_KeyValueIterator iterator, | 108 | MHD_KeyValueIterator iterator, |
@@ -129,7 +129,7 @@ MHD_get_response_headers(struct MHD_Response * response, | |||
129 | * | 129 | * |
130 | * @param key which header to get | 130 | * @param key which header to get |
131 | * @return NULL if header does not exist | 131 | * @return NULL if header does not exist |
132 | */ | 132 | */ |
133 | const char * | 133 | const char * |
134 | MHD_get_response_header(struct MHD_Response * response, | 134 | MHD_get_response_header(struct MHD_Response * response, |
135 | const char * key) { | 135 | const char * key) { |
@@ -162,7 +162,7 @@ MHD_create_response_from_callback(size_t size, | |||
162 | MHD_ContentReaderFreeCallback crfc) { | 162 | MHD_ContentReaderFreeCallback crfc) { |
163 | struct MHD_Response * retVal; | 163 | struct MHD_Response * retVal; |
164 | 164 | ||
165 | if (crc == NULL) | 165 | if (crc == NULL) |
166 | return NULL; | 166 | return NULL; |
167 | retVal = malloc(sizeof(struct MHD_Response)); | 167 | retVal = malloc(sizeof(struct MHD_Response)); |
168 | memset(retVal, | 168 | memset(retVal, |
@@ -187,7 +187,7 @@ MHD_create_response_from_callback(size_t size, | |||
187 | * @param size size of the data portion of the response | 187 | * @param size size of the data portion of the response |
188 | * @param data the data itself | 188 | * @param data the data itself |
189 | * @param must_free libmicrohttpd should free data when done | 189 | * @param must_free libmicrohttpd should free data when done |
190 | * @param must_copy libmicrohttpd must make a copy of data | 190 | * @param must_copy libmicrohttpd must make a copy of data |
191 | * right away, the data maybe released anytime after | 191 | * right away, the data maybe released anytime after |
192 | * this call returns | 192 | * this call returns |
193 | * @return NULL on error (i.e. invalid arguments, out of memory) | 193 | * @return NULL on error (i.e. invalid arguments, out of memory) |
@@ -199,7 +199,7 @@ MHD_create_response_from_data(size_t size, | |||
199 | int must_copy) { | 199 | int must_copy) { |
200 | struct MHD_Response * retVal; | 200 | struct MHD_Response * retVal; |
201 | void * tmp; | 201 | void * tmp; |
202 | 202 | ||
203 | if ( (data == NULL) && | 203 | if ( (data == NULL) && |
204 | (size > 0) ) | 204 | (size > 0) ) |
205 | return NULL; | 205 | return NULL; |
@@ -215,11 +215,11 @@ MHD_create_response_from_data(size_t size, | |||
215 | (size > 0) ) { | 215 | (size > 0) ) { |
216 | tmp = malloc(size); | 216 | tmp = malloc(size); |
217 | memcpy(tmp, | 217 | memcpy(tmp, |
218 | data, | 218 | data, |
219 | size); | 219 | size); |
220 | must_free = 1; | 220 | must_free = 1; |
221 | data = tmp; | 221 | data = tmp; |
222 | } | 222 | } |
223 | retVal->crc = NULL; | 223 | retVal->crc = NULL; |
224 | retVal->crfc = must_free ? &free : NULL; | 224 | retVal->crfc = must_free ? &free : NULL; |
225 | retVal->crc_cls = must_free ? data : NULL; | 225 | retVal->crc_cls = must_free ? data : NULL; |
@@ -240,10 +240,10 @@ void | |||
240 | MHD_destroy_response(struct MHD_Response * response) { | 240 | MHD_destroy_response(struct MHD_Response * response) { |
241 | struct MHD_HTTP_Header * pos; | 241 | struct MHD_HTTP_Header * pos; |
242 | 242 | ||
243 | if (response == NULL) | 243 | if (response == NULL) |
244 | return; | 244 | return; |
245 | pthread_mutex_lock(&response->mutex); | 245 | pthread_mutex_lock(&response->mutex); |
246 | if (0 != --response->reference_count) { | 246 | if (0 != --response->reference_count) { |
247 | pthread_mutex_unlock(&response->mutex); | 247 | pthread_mutex_unlock(&response->mutex); |
248 | return; | 248 | return; |
249 | } | 249 | } |
@@ -252,7 +252,7 @@ MHD_destroy_response(struct MHD_Response * response) { | |||
252 | if (response->crfc != NULL) | 252 | if (response->crfc != NULL) |
253 | response->crfc(response->crc_cls); | 253 | response->crfc(response->crc_cls); |
254 | while (response->first_header != NULL) { | 254 | while (response->first_header != NULL) { |
255 | pos = response->first_header; | 255 | pos = response->first_header; |
256 | response->first_header = pos->next; | 256 | response->first_header = pos->next; |
257 | free(pos->header); | 257 | free(pos->header); |
258 | free(pos->value); | 258 | free(pos->value); |
diff --git a/src/daemon/session.c b/src/daemon/session.c index f69ec1ed..edcbb04f 100644 --- a/src/daemon/session.c +++ b/src/daemon/session.c | |||
@@ -37,7 +37,7 @@ | |||
37 | * maybe NULL (then just count headers) | 37 | * maybe NULL (then just count headers) |
38 | * @param iterator_cls extra argument to iterator | 38 | * @param iterator_cls extra argument to iterator |
39 | * @return number of entries iterated over | 39 | * @return number of entries iterated over |
40 | */ | 40 | */ |
41 | int | 41 | int |
42 | MHD_get_session_values(struct MHD_Session * session, | 42 | MHD_get_session_values(struct MHD_Session * session, |
43 | enum MHD_ValueKind kind, | 43 | enum MHD_ValueKind kind, |
@@ -46,7 +46,7 @@ MHD_get_session_values(struct MHD_Session * session, | |||
46 | int ret; | 46 | int ret; |
47 | struct MHD_HTTP_Header * pos; | 47 | struct MHD_HTTP_Header * pos; |
48 | 48 | ||
49 | if (session == NULL) | 49 | if (session == NULL) |
50 | return -1; | 50 | return -1; |
51 | ret = 0; | 51 | ret = 0; |
52 | pos = session->headers_received; | 52 | pos = session->headers_received; |
@@ -54,11 +54,11 @@ MHD_get_session_values(struct MHD_Session * session, | |||
54 | if (0 != (pos->kind & kind)) { | 54 | if (0 != (pos->kind & kind)) { |
55 | ret++; | 55 | ret++; |
56 | if ( (iterator != NULL) && | 56 | if ( (iterator != NULL) && |
57 | (MHD_YES != iterator(iterator_cls, | 57 | (MHD_YES != iterator(iterator_cls, |
58 | kind, | 58 | kind, |
59 | pos->header, | 59 | pos->header, |
60 | pos->value)) ) | 60 | pos->value)) ) |
61 | return ret; | 61 | return ret; |
62 | } | 62 | } |
63 | pos = pos->next; | 63 | pos = pos->next; |
64 | } | 64 | } |
@@ -72,14 +72,14 @@ MHD_get_session_values(struct MHD_Session * session, | |||
72 | * | 72 | * |
73 | * @param key the header to look for | 73 | * @param key the header to look for |
74 | * @return NULL if no such item was found | 74 | * @return NULL if no such item was found |
75 | */ | 75 | */ |
76 | const char * | 76 | const char * |
77 | MHD_lookup_session_value(struct MHD_Session * session, | 77 | MHD_lookup_session_value(struct MHD_Session * session, |
78 | enum MHD_ValueKind kind, | 78 | enum MHD_ValueKind kind, |
79 | const char * key) { | 79 | const char * key) { |
80 | struct MHD_HTTP_Header * pos; | 80 | struct MHD_HTTP_Header * pos; |
81 | 81 | ||
82 | if (session == NULL) | 82 | if (session == NULL) |
83 | return NULL; | 83 | return NULL; |
84 | pos = session->headers_received; | 84 | pos = session->headers_received; |
85 | while (pos != NULL) { | 85 | while (pos != NULL) { |
@@ -95,18 +95,18 @@ MHD_lookup_session_value(struct MHD_Session * session, | |||
95 | /** | 95 | /** |
96 | * Queue a response to be transmitted to the client (as soon as | 96 | * Queue a response to be transmitted to the client (as soon as |
97 | * possible). | 97 | * possible). |
98 | * | 98 | * |
99 | * @param session the session identifying the client | 99 | * @param session the session identifying the client |
100 | * @param status_code HTTP status code (i.e. 200 for OK) | 100 | * @param status_code HTTP status code (i.e. 200 for OK) |
101 | * @param response response to transmit | 101 | * @param response response to transmit |
102 | * @return MHD_NO on error (i.e. reply already sent), | 102 | * @return MHD_NO on error (i.e. reply already sent), |
103 | * MHD_YES on success or if message has been queued | 103 | * MHD_YES on success or if message has been queued |
104 | */ | 104 | */ |
105 | int | 105 | int |
106 | MHD_queue_response(struct MHD_Session * session, | 106 | MHD_queue_response(struct MHD_Session * session, |
107 | unsigned int status_code, | 107 | unsigned int status_code, |
108 | struct MHD_Response * response) { | 108 | struct MHD_Response * response) { |
109 | if ( (session == NULL) || | 109 | if ( (session == NULL) || |
110 | (response == NULL) || | 110 | (response == NULL) || |
111 | (session->response != NULL) || | 111 | (session->response != NULL) || |
112 | (session->bodyReceived == 0) || | 112 | (session->bodyReceived == 0) || |
@@ -124,7 +124,7 @@ MHD_queue_response(struct MHD_Session * session, | |||
124 | * | 124 | * |
125 | * @return MHD_YES on success | 125 | * @return MHD_YES on success |
126 | */ | 126 | */ |
127 | int | 127 | int |
128 | MHD_session_get_fdset(struct MHD_Session * session, | 128 | MHD_session_get_fdset(struct MHD_Session * session, |
129 | fd_set * read_fd_set, | 129 | fd_set * read_fd_set, |
130 | fd_set * write_fd_set, | 130 | fd_set * write_fd_set, |
@@ -135,11 +135,11 @@ MHD_session_get_fdset(struct MHD_Session * session, | |||
135 | fd = session->socket_fd; | 135 | fd = session->socket_fd; |
136 | if (fd == -1) | 136 | if (fd == -1) |
137 | return MHD_YES; | 137 | return MHD_YES; |
138 | if ( (session->read_close == 0) && | 138 | if ( (session->read_close == 0) && |
139 | ( (session->headersReceived == 0) || | 139 | ( (session->headersReceived == 0) || |
140 | (session->readLoc < session->read_buffer_size) ) ) | 140 | (session->readLoc < session->read_buffer_size) ) ) |
141 | FD_SET(fd, read_fd_set); | 141 | FD_SET(fd, read_fd_set); |
142 | if (session->response != NULL) | 142 | if (session->response != NULL) |
143 | FD_SET(fd, write_fd_set); | 143 | FD_SET(fd, write_fd_set); |
144 | if ( (fd > *max_fd) && | 144 | if ( (fd > *max_fd) && |
145 | ( (session->headersReceived == 0) || | 145 | ( (session->headersReceived == 0) || |
@@ -157,7 +157,7 @@ MHD_session_get_fdset(struct MHD_Session * session, | |||
157 | * found (incomplete, buffer too small, line too long), | 157 | * found (incomplete, buffer too small, line too long), |
158 | * return NULL. Otherwise return a copy of the line. | 158 | * return NULL. Otherwise return a copy of the line. |
159 | */ | 159 | */ |
160 | static char * | 160 | static char * |
161 | MHD_get_next_header_line(struct MHD_Session * session) { | 161 | MHD_get_next_header_line(struct MHD_Session * session) { |
162 | char * rbuf; | 162 | char * rbuf; |
163 | size_t pos; | 163 | size_t pos; |
@@ -201,10 +201,10 @@ MHD_get_next_header_line(struct MHD_Session * session) { | |||
201 | session->read_buffer, | 201 | session->read_buffer, |
202 | pos); | 202 | pos); |
203 | rbuf[pos] = '\0'; | 203 | rbuf[pos] = '\0'; |
204 | if ( (session->read_buffer[pos] == '\r') && | 204 | if ( (session->read_buffer[pos] == '\r') && |
205 | (session->read_buffer[pos+1] == '\n') ) | 205 | (session->read_buffer[pos+1] == '\n') ) |
206 | pos++; /* skip both r and n */ | 206 | pos++; /* skip both r and n */ |
207 | pos++; | 207 | pos++; |
208 | memmove(session->read_buffer, | 208 | memmove(session->read_buffer, |
209 | &session->read_buffer[pos], | 209 | &session->read_buffer[pos], |
210 | session->readLoc - pos); | 210 | session->readLoc - pos); |
@@ -212,7 +212,7 @@ MHD_get_next_header_line(struct MHD_Session * session) { | |||
212 | return rbuf; | 212 | return rbuf; |
213 | } | 213 | } |
214 | 214 | ||
215 | static void | 215 | static void |
216 | MHD_session_add_header(struct MHD_Session * session, | 216 | MHD_session_add_header(struct MHD_Session * session, |
217 | const char * key, | 217 | const char * key, |
218 | const char * value, | 218 | const char * value, |
@@ -227,7 +227,7 @@ MHD_session_add_header(struct MHD_Session * session, | |||
227 | session->headers_received = hdr; | 227 | session->headers_received = hdr; |
228 | } | 228 | } |
229 | 229 | ||
230 | static void | 230 | static void |
231 | MHD_http_unescape(char * val) { | 231 | MHD_http_unescape(char * val) { |
232 | char * esc; | 232 | char * esc; |
233 | unsigned int num; | 233 | unsigned int num; |
@@ -248,7 +248,7 @@ MHD_http_unescape(char * val) { | |||
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | static void | 251 | static void |
252 | MHD_parse_arguments(struct MHD_Session * session, | 252 | MHD_parse_arguments(struct MHD_Session * session, |
253 | char * args) { | 253 | char * args) { |
254 | char * equals; | 254 | char * equals; |
@@ -264,7 +264,7 @@ MHD_parse_arguments(struct MHD_Session * session, | |||
264 | if (amper != NULL) { | 264 | if (amper != NULL) { |
265 | amper[0] = '\0'; | 265 | amper[0] = '\0'; |
266 | amper++; | 266 | amper++; |
267 | } | 267 | } |
268 | MHD_http_unescape(args); | 268 | MHD_http_unescape(args); |
269 | MHD_http_unescape(equals); | 269 | MHD_http_unescape(equals); |
270 | MHD_session_add_header(session, | 270 | MHD_session_add_header(session, |
@@ -278,7 +278,7 @@ MHD_parse_arguments(struct MHD_Session * session, | |||
278 | /** | 278 | /** |
279 | * Parse the cookie header (see RFC 2109). | 279 | * Parse the cookie header (see RFC 2109). |
280 | */ | 280 | */ |
281 | static void | 281 | static void |
282 | MHD_parse_cookie_header(struct MHD_Session * session) { | 282 | MHD_parse_cookie_header(struct MHD_Session * session) { |
283 | const char * hdr; | 283 | const char * hdr; |
284 | char * cpy; | 284 | char * cpy; |
@@ -336,7 +336,7 @@ MHD_parse_cookie_header(struct MHD_Session * session) { | |||
336 | * This function is designed to parse the input buffer of a given session. | 336 | * This function is designed to parse the input buffer of a given session. |
337 | * | 337 | * |
338 | * Once the header is complete, it should have set the | 338 | * Once the header is complete, it should have set the |
339 | * headers_received, url and method values and set | 339 | * headers_received, url and method values and set |
340 | * headersReceived to 1. If no body is expected, it should | 340 | * headersReceived to 1. If no body is expected, it should |
341 | * also set "bodyReceived" to 1. Otherwise, it should | 341 | * also set "bodyReceived" to 1. Otherwise, it should |
342 | * set "uploadSize" to the expected size of the body. If the | 342 | * set "uploadSize" to the expected size of the body. If the |
@@ -354,7 +354,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
354 | 354 | ||
355 | if (session->bodyReceived == 1) | 355 | if (session->bodyReceived == 1) |
356 | abort(); | 356 | abort(); |
357 | while (NULL != (line = MHD_get_next_header_line(session))) { | 357 | while (NULL != (line = MHD_get_next_header_line(session))) { |
358 | if (session->url == NULL) { | 358 | if (session->url == NULL) { |
359 | /* line must be request line */ | 359 | /* line must be request line */ |
360 | uri = strstr(line, " "); | 360 | uri = strstr(line, " "); |
@@ -387,7 +387,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
387 | MHD_HEADER_KIND, | 387 | MHD_HEADER_KIND, |
388 | "Content-Length"); | 388 | "Content-Length"); |
389 | if (clen != NULL) { | 389 | if (clen != NULL) { |
390 | if (1 != sscanf(clen, | 390 | if (1 != sscanf(clen, |
391 | "%llu", | 391 | "%llu", |
392 | &cval)) { | 392 | &cval)) { |
393 | MHD_DLOG(session->daemon, | 393 | MHD_DLOG(session->daemon, |
@@ -409,7 +409,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
409 | session->bodyReceived = 0; | 409 | session->bodyReceived = 0; |
410 | } | 410 | } |
411 | } | 411 | } |
412 | break; | 412 | break; |
413 | } | 413 | } |
414 | /* line should be normal header line, find colon */ | 414 | /* line should be normal header line, find colon */ |
415 | colon = strstr(line, ": "); | 415 | colon = strstr(line, ": "); |
@@ -438,8 +438,8 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
438 | 438 | ||
439 | /** | 439 | /** |
440 | * Find the handler responsible for this request. | 440 | * Find the handler responsible for this request. |
441 | */ | 441 | */ |
442 | static struct MHD_Access_Handler * | 442 | static struct MHD_Access_Handler * |
443 | MHD_find_access_handler(struct MHD_Session * session) { | 443 | MHD_find_access_handler(struct MHD_Session * session) { |
444 | struct MHD_Access_Handler * pos; | 444 | struct MHD_Access_Handler * pos; |
445 | 445 | ||
@@ -455,7 +455,7 @@ MHD_find_access_handler(struct MHD_Session * session) { | |||
455 | 455 | ||
456 | /** | 456 | /** |
457 | * Call the handler of the application for this | 457 | * Call the handler of the application for this |
458 | * session. | 458 | * session. |
459 | */ | 459 | */ |
460 | void | 460 | void |
461 | MHD_call_session_handler(struct MHD_Session * session) { | 461 | MHD_call_session_handler(struct MHD_Session * session) { |
@@ -484,7 +484,7 @@ MHD_call_session_handler(struct MHD_Session * session) { | |||
484 | &session->read_buffer[session->readLoc - processed], | 484 | &session->read_buffer[session->readLoc - processed], |
485 | processed); | 485 | processed); |
486 | if (session->uploadSize != -1) | 486 | if (session->uploadSize != -1) |
487 | session->uploadSize -= (session->readLoc - processed); | 487 | session->uploadSize -= (session->readLoc - processed); |
488 | session->readLoc = processed; | 488 | session->readLoc = processed; |
489 | if ( (session->uploadSize == 0) || | 489 | if ( (session->uploadSize == 0) || |
490 | ( (session->readLoc == 0) && | 490 | ( (session->readLoc == 0) && |
@@ -503,13 +503,13 @@ MHD_call_session_handler(struct MHD_Session * session) { | |||
503 | * This function handles a particular connection when it has been | 503 | * This function handles a particular connection when it has been |
504 | * determined that there is data to be read off a socket. All implementations | 504 | * determined that there is data to be read off a socket. All implementations |
505 | * (multithreaded, external select, internal select) call this function | 505 | * (multithreaded, external select, internal select) call this function |
506 | * to handle reads. | 506 | * to handle reads. |
507 | */ | 507 | */ |
508 | int | 508 | int |
509 | MHD_session_handle_read(struct MHD_Session * session) { | 509 | MHD_session_handle_read(struct MHD_Session * session) { |
510 | int bytes_read; | 510 | int bytes_read; |
511 | void * tmp; | 511 | void * tmp; |
512 | 512 | ||
513 | if ( (session->readLoc >= session->read_buffer_size) && | 513 | if ( (session->readLoc >= session->read_buffer_size) && |
514 | (session->headersReceived == 0) ) { | 514 | (session->headersReceived == 0) ) { |
515 | /* need to grow read buffer */ | 515 | /* need to grow read buffer */ |
@@ -526,7 +526,7 @@ MHD_session_handle_read(struct MHD_Session * session) { | |||
526 | MHD_DLOG(session->daemon, | 526 | MHD_DLOG(session->daemon, |
527 | "Unexpected call to %s.\n", | 527 | "Unexpected call to %s.\n", |
528 | __FUNCTION__); | 528 | __FUNCTION__); |
529 | return MHD_NO; | 529 | return MHD_NO; |
530 | } | 530 | } |
531 | bytes_read = RECV(session->socket_fd, | 531 | bytes_read = RECV(session->socket_fd, |
532 | &session->read_buffer[session->readLoc], | 532 | &session->read_buffer[session->readLoc], |
@@ -544,15 +544,15 @@ MHD_session_handle_read(struct MHD_Session * session) { | |||
544 | } | 544 | } |
545 | if (bytes_read == 0) { | 545 | if (bytes_read == 0) { |
546 | /* other side closed connection */ | 546 | /* other side closed connection */ |
547 | if (session->readLoc > 0) | 547 | if (session->readLoc > 0) |
548 | MHD_call_session_handler(session); | 548 | MHD_call_session_handler(session); |
549 | shutdown(session->socket_fd, SHUT_RD); | 549 | shutdown(session->socket_fd, SHUT_RD); |
550 | return MHD_YES; | 550 | return MHD_YES; |
551 | } | 551 | } |
552 | session->readLoc += bytes_read; | 552 | session->readLoc += bytes_read; |
553 | if (session->headersReceived == 0) | 553 | if (session->headersReceived == 0) |
554 | MHD_parse_session_headers(session); | 554 | MHD_parse_session_headers(session); |
555 | if (session->headersReceived == 1) | 555 | if (session->headersReceived == 1) |
556 | MHD_call_session_handler(session); | 556 | MHD_call_session_handler(session); |
557 | return MHD_YES; | 557 | return MHD_YES; |
558 | } | 558 | } |
@@ -561,7 +561,7 @@ MHD_session_handle_read(struct MHD_Session * session) { | |||
561 | * Check if we need to set some additional headers | 561 | * Check if we need to set some additional headers |
562 | * for http-compiliance. | 562 | * for http-compiliance. |
563 | */ | 563 | */ |
564 | static void | 564 | static void |
565 | MHD_add_extra_headers(struct MHD_Session * session) { | 565 | MHD_add_extra_headers(struct MHD_Session * session) { |
566 | const char * have; | 566 | const char * have; |
567 | char buf[128]; | 567 | char buf[128]; |
@@ -600,7 +600,7 @@ MHD_build_header_response(struct MHD_Session * session) { | |||
600 | 600 | ||
601 | MHD_add_extra_headers(session); | 601 | MHD_add_extra_headers(session); |
602 | SPRINTF(code, | 602 | SPRINTF(code, |
603 | "HTTP/1.1 %u\r\n", | 603 | "HTTP/1.1 %u\r\n", |
604 | session->responseCode); | 604 | session->responseCode); |
605 | off = strlen(code); | 605 | off = strlen(code); |
606 | /* estimate size */ | 606 | /* estimate size */ |
@@ -627,10 +627,10 @@ MHD_build_header_response(struct MHD_Session * session) { | |||
627 | sprintf(&data[off], | 627 | sprintf(&data[off], |
628 | "\r\n"); | 628 | "\r\n"); |
629 | off += 2; | 629 | off += 2; |
630 | if (off != size) | 630 | if (off != size) |
631 | abort(); | 631 | abort(); |
632 | session->write_buffer = data; | 632 | session->write_buffer = data; |
633 | session->write_buffer_size = size; | 633 | session->write_buffer_size = size; |
634 | } | 634 | } |
635 | 635 | ||
636 | /** | 636 | /** |
@@ -654,7 +654,7 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
654 | if (! session->headersSent) { | 654 | if (! session->headersSent) { |
655 | if (session->write_buffer == NULL) | 655 | if (session->write_buffer == NULL) |
656 | MHD_build_header_response(session); | 656 | MHD_build_header_response(session); |
657 | ret = SEND(session->socket_fd, | 657 | ret = SEND(session->socket_fd, |
658 | &session->write_buffer[session->writeLoc], | 658 | &session->write_buffer[session->writeLoc], |
659 | session->write_buffer_size - session->writeLoc, | 659 | session->write_buffer_size - session->writeLoc, |
660 | 0); | 660 | 0); |
@@ -678,10 +678,10 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
678 | } | 678 | } |
679 | return MHD_YES; | 679 | return MHD_YES; |
680 | } | 680 | } |
681 | if (response->total_size <= session->messagePos) | 681 | if (response->total_size <= session->messagePos) |
682 | abort(); /* internal error */ | 682 | abort(); /* internal error */ |
683 | if (response->crc != NULL) | 683 | if (response->crc != NULL) |
684 | pthread_mutex_lock(&response->mutex); | 684 | pthread_mutex_lock(&response->mutex); |
685 | 685 | ||
686 | /* prepare send buffer */ | 686 | /* prepare send buffer */ |
687 | if ( (response->data == NULL) || | 687 | if ( (response->data == NULL) || |
@@ -708,16 +708,16 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
708 | response->data_start = session->messagePos; | 708 | response->data_start = session->messagePos; |
709 | response->data_size = ret; | 709 | response->data_size = ret; |
710 | if (ret == 0) | 710 | if (ret == 0) |
711 | return MHD_YES; | 711 | return MHD_YES; |
712 | } | 712 | } |
713 | 713 | ||
714 | /* transmit */ | 714 | /* transmit */ |
715 | ret = SEND(session->socket_fd, | 715 | ret = SEND(session->socket_fd, |
716 | &response->data[session->messagePos - response->data_start], | 716 | &response->data[session->messagePos - response->data_start], |
717 | response->data_size - (session->messagePos - response->data_start), | 717 | response->data_size - (session->messagePos - response->data_start), |
718 | 0); | 718 | 0); |
719 | if (response->crc != NULL) | 719 | if (response->crc != NULL) |
720 | pthread_mutex_unlock(&response->mutex); | 720 | pthread_mutex_unlock(&response->mutex); |
721 | if (ret < 0) { | 721 | if (ret < 0) { |
722 | if (errno == EINTR) | 722 | if (errno == EINTR) |
723 | return MHD_YES; | 723 | return MHD_YES; |
@@ -729,7 +729,7 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
729 | return MHD_YES; | 729 | return MHD_YES; |
730 | } | 730 | } |
731 | session->messagePos += ret; | 731 | session->messagePos += ret; |
732 | if (session->messagePos > response->data_size) | 732 | if (session->messagePos > response->data_size) |
733 | abort(); /* internal error */ | 733 | abort(); /* internal error */ |
734 | if (session->messagePos == response->data_size) { | 734 | if (session->messagePos == response->data_size) { |
735 | if ( (session->bodyReceived == 0) || | 735 | if ( (session->bodyReceived == 0) || |
diff --git a/src/daemon/session.h b/src/daemon/session.h index c3abbd7f..269c2f17 100644 --- a/src/daemon/session.h +++ b/src/daemon/session.h | |||
@@ -34,7 +34,7 @@ | |||
34 | * | 34 | * |
35 | * @return MHD_YES on success | 35 | * @return MHD_YES on success |
36 | */ | 36 | */ |
37 | int | 37 | int |
38 | MHD_session_get_fdset(struct MHD_Session * session, | 38 | MHD_session_get_fdset(struct MHD_Session * session, |
39 | fd_set * read_fd_set, | 39 | fd_set * read_fd_set, |
40 | fd_set * write_fd_set, | 40 | fd_set * write_fd_set, |
@@ -44,7 +44,7 @@ MHD_session_get_fdset(struct MHD_Session * session, | |||
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Call the handler of the application for this | 46 | * Call the handler of the application for this |
47 | * session. | 47 | * session. |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | MHD_call_session_handler(struct MHD_Session * session); | 50 | MHD_call_session_handler(struct MHD_Session * session); |
@@ -53,11 +53,11 @@ MHD_call_session_handler(struct MHD_Session * session); | |||
53 | * This function handles a particular connection when it has been | 53 | * This function handles a particular connection when it has been |
54 | * determined that there is data to be read off a socket. All implementations | 54 | * determined that there is data to be read off a socket. All implementations |
55 | * (multithreaded, external select, internal select) call this function | 55 | * (multithreaded, external select, internal select) call this function |
56 | * to handle reads. | 56 | * to handle reads. |
57 | */ | 57 | */ |
58 | int | 58 | int |
59 | MHD_session_handle_read(struct MHD_Session * session); | 59 | MHD_session_handle_read(struct MHD_Session * session); |
60 | 60 | ||
61 | 61 | ||
62 | /** | 62 | /** |
63 | * This function was created to handle writes to sockets when it has been | 63 | * This function was created to handle writes to sockets when it has been |