diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/daemon.c | 42 | ||||
-rw-r--r-- | src/daemon/internal.c | 2 | ||||
-rw-r--r-- | src/daemon/session.c | 34 |
3 files changed, 39 insertions, 39 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 9aad7593..70d5075f 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -174,7 +174,7 @@ MHD_handle_connection(void * data) { | |||
174 | &ws, | 174 | &ws, |
175 | &es, | 175 | &es, |
176 | &max); | 176 | &max); |
177 | num_ready = select(max + 1, | 177 | num_ready = SELECT(max + 1, |
178 | &rs, | 178 | &rs, |
179 | &ws, | 179 | &ws, |
180 | &es, | 180 | &es, |
@@ -192,7 +192,7 @@ MHD_handle_connection(void * data) { | |||
192 | break; | 192 | break; |
193 | } | 193 | } |
194 | if (con->socket_fd != -1) { | 194 | if (con->socket_fd != -1) { |
195 | close(con->socket_fd); | 195 | CLOSE(con->socket_fd); |
196 | con->socket_fd = -1; | 196 | con->socket_fd = -1; |
197 | } | 197 | } |
198 | return NULL; | 198 | return NULL; |
@@ -215,20 +215,20 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
215 | memset(&addr, | 215 | memset(&addr, |
216 | 0, | 216 | 0, |
217 | sizeof(struct sockaddr)); | 217 | sizeof(struct sockaddr)); |
218 | s = accept(daemon->socket_fd, | 218 | s = ACCEPT(daemon->socket_fd, |
219 | &addr, | 219 | &addr, |
220 | &addrlen); | 220 | &addrlen); |
221 | if ( (s < 0) || | 221 | if ( (s < 0) || |
222 | (addrlen <= 0) ) { | 222 | (addrlen <= 0) ) { |
223 | MHD_DLOG(daemon, | 223 | MHD_DLOG(daemon, |
224 | "Error accepting connection: %s\n", | 224 | "Error accepting connection: %s\n", |
225 | strerror(errno)); | 225 | STRERROR(errno)); |
226 | return MHD_NO; | 226 | return MHD_NO; |
227 | } | 227 | } |
228 | if (MHD_NO == daemon->apc(daemon->apc_cls, | 228 | if (MHD_NO == daemon->apc(daemon->apc_cls, |
229 | &addr, | 229 | &addr, |
230 | addrlen)) { | 230 | addrlen)) { |
231 | close(s); | 231 | CLOSE(s); |
232 | return MHD_YES; | 232 | return MHD_YES; |
233 | } | 233 | } |
234 | session = malloc(sizeof(struct MHD_Session)); | 234 | session = malloc(sizeof(struct MHD_Session)); |
@@ -249,9 +249,9 @@ MHD_accept_connection(struct MHD_Daemon * daemon) { | |||
249 | session)) ) { | 249 | session)) ) { |
250 | MHD_DLOG(daemon, | 250 | MHD_DLOG(daemon, |
251 | "Failed to create a thread: %s\n", | 251 | "Failed to create a thread: %s\n", |
252 | strerror(errno)); | 252 | STRERROR(errno)); |
253 | free(session->addr); | 253 | free(session->addr); |
254 | close(s); | 254 | CLOSE(s); |
255 | free(session); | 255 | free(session); |
256 | return MHD_NO; | 256 | return MHD_NO; |
257 | } | 257 | } |
@@ -367,7 +367,7 @@ MHD_select(struct MHD_Daemon * daemon, | |||
367 | max = daemon->socket_fd; | 367 | max = daemon->socket_fd; |
368 | FD_SET(daemon->socket_fd, &rs); | 368 | FD_SET(daemon->socket_fd, &rs); |
369 | } | 369 | } |
370 | num_ready = select(max + 1, | 370 | num_ready = SELECT(max + 1, |
371 | &rs, | 371 | &rs, |
372 | &ws, | 372 | &ws, |
373 | &es, | 373 | &es, |
@@ -377,7 +377,7 @@ MHD_select(struct MHD_Daemon * daemon, | |||
377 | return MHD_YES; | 377 | return MHD_YES; |
378 | MHD_DLOG(daemon, | 378 | MHD_DLOG(daemon, |
379 | "Select failed: %s\n", | 379 | "Select failed: %s\n", |
380 | strerror(errno)); | 380 | STRERROR(errno)); |
381 | return MHD_NO; | 381 | return MHD_NO; |
382 | } | 382 | } |
383 | ds = daemon->socket_fd; | 383 | ds = daemon->socket_fd; |
@@ -472,12 +472,12 @@ MHD_start_daemon(unsigned int options, | |||
472 | if ( (port == 0) || | 472 | if ( (port == 0) || |
473 | (dh == NULL) ) | 473 | (dh == NULL) ) |
474 | return NULL; | 474 | return NULL; |
475 | socket_fd = socket(AF_INET, SOCK_STREAM, 0); | 475 | socket_fd = SOCKET(AF_INET, SOCK_STREAM, 0); |
476 | if (socket_fd < 0) { | 476 | if (socket_fd < 0) { |
477 | if ((options & MHD_USE_DEBUG) != 0) | 477 | if ((options & MHD_USE_DEBUG) != 0) |
478 | fprintf(stderr, | 478 | fprintf(stderr, |
479 | "Call to socket failed: %s\n", | 479 | "Call to socket failed: %s\n", |
480 | strerror(errno)); | 480 | STRERROR(errno)); |
481 | return NULL; | 481 | return NULL; |
482 | } | 482 | } |
483 | /* FIXME: setsockopt: SO_REUSEADDR? */ | 483 | /* FIXME: setsockopt: SO_REUSEADDR? */ |
@@ -486,23 +486,23 @@ MHD_start_daemon(unsigned int options, | |||
486 | sizeof(struct sockaddr_in)); | 486 | sizeof(struct sockaddr_in)); |
487 | servaddr.sin_family = AF_INET; | 487 | servaddr.sin_family = AF_INET; |
488 | servaddr.sin_port = htons(port); | 488 | servaddr.sin_port = htons(port); |
489 | if (bind(socket_fd, | 489 | if (BIND(socket_fd, |
490 | (struct sockaddr *)&servaddr, | 490 | (struct sockaddr *)&servaddr, |
491 | sizeof(struct sockaddr_in)) < 0) { | 491 | sizeof(struct sockaddr_in)) < 0) { |
492 | if ( (options & MHD_USE_DEBUG) != 0) | 492 | if ( (options & MHD_USE_DEBUG) != 0) |
493 | fprintf(stderr, | 493 | fprintf(stderr, |
494 | "Failed to bind to port %u: %s\n", | 494 | "Failed to bind to port %u: %s\n", |
495 | port, | 495 | port, |
496 | strerror(errno)); | 496 | STRERROR(errno)); |
497 | close(socket_fd); | 497 | CLOSE(socket_fd); |
498 | return NULL; | 498 | return NULL; |
499 | } | 499 | } |
500 | if (listen(socket_fd, 20) < 0) { | 500 | if (LISTEN(socket_fd, 20) < 0) { |
501 | if ((options & MHD_USE_DEBUG) != 0) | 501 | if ((options & MHD_USE_DEBUG) != 0) |
502 | fprintf(stderr, | 502 | fprintf(stderr, |
503 | "Failed to listen for connections: %s\n", | 503 | "Failed to listen for connections: %s\n", |
504 | strerror(errno)); | 504 | STRERROR(errno)); |
505 | close(socket_fd); | 505 | CLOSE(socket_fd); |
506 | return NULL; | 506 | return NULL; |
507 | } | 507 | } |
508 | retVal = malloc(sizeof(struct MHD_Daemon)); | 508 | retVal = malloc(sizeof(struct MHD_Daemon)); |
@@ -526,9 +526,9 @@ MHD_start_daemon(unsigned int options, | |||
526 | retVal)) ) { | 526 | retVal)) ) { |
527 | MHD_DLOG(retVal, | 527 | MHD_DLOG(retVal, |
528 | "Failed to create listen thread: %s\n", | 528 | "Failed to create listen thread: %s\n", |
529 | strerror(errno)); | 529 | STRERROR(errno)); |
530 | free(retVal); | 530 | free(retVal); |
531 | close(socket_fd); | 531 | CLOSE(socket_fd); |
532 | return NULL; | 532 | return NULL; |
533 | } | 533 | } |
534 | return retVal; | 534 | return retVal; |
@@ -544,7 +544,7 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
544 | if (daemon == NULL) | 544 | if (daemon == NULL) |
545 | return; | 545 | return; |
546 | daemon->shutdown = 1; | 546 | daemon->shutdown = 1; |
547 | close(daemon->socket_fd); | 547 | CLOSE(daemon->socket_fd); |
548 | daemon->socket_fd = -1; | 548 | daemon->socket_fd = -1; |
549 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || | 549 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || |
550 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { | 550 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { |
@@ -553,7 +553,7 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
553 | } | 553 | } |
554 | while (daemon->connections != NULL) { | 554 | while (daemon->connections != NULL) { |
555 | if (-1 != daemon->connections->socket_fd) { | 555 | if (-1 != daemon->connections->socket_fd) { |
556 | close(daemon->connections->socket_fd); | 556 | CLOSE(daemon->connections->socket_fd); |
557 | daemon->connections->socket_fd = -1; | 557 | daemon->connections->socket_fd = -1; |
558 | } | 558 | } |
559 | MHD_cleanup_sessions(daemon); | 559 | MHD_cleanup_sessions(daemon); |
diff --git a/src/daemon/internal.c b/src/daemon/internal.c index ce06e2c6..753a216d 100644 --- a/src/daemon/internal.c +++ b/src/daemon/internal.c | |||
@@ -41,7 +41,7 @@ void MHD_DLOG(const struct MHD_Daemon * daemon, | |||
41 | if ( (daemon->options & MHD_USE_DEBUG) == 0) | 41 | if ( (daemon->options & MHD_USE_DEBUG) == 0) |
42 | return; | 42 | return; |
43 | va_start(va, format); | 43 | va_start(va, format); |
44 | vfprintf(stderr, format, va); | 44 | VFPRINTF(stderr, format, va); |
45 | va_end(va); | 45 | va_end(va); |
46 | } | 46 | } |
47 | 47 | ||
diff --git a/src/daemon/session.c b/src/daemon/session.c index f2dd3832..fa19f6b8 100644 --- a/src/daemon/session.c +++ b/src/daemon/session.c | |||
@@ -184,7 +184,7 @@ MHD_get_next_header_line(struct MHD_Session * session) { | |||
184 | MHD_DLOG(session->daemon, | 184 | MHD_DLOG(session->daemon, |
185 | "Received excessively long header line (>%u), closing connection.\n", | 185 | "Received excessively long header line (>%u), closing connection.\n", |
186 | 4 * MHD_MAX_BUF_SIZE); | 186 | 4 * MHD_MAX_BUF_SIZE); |
187 | close(session->socket_fd); | 187 | CLOSE(session->socket_fd); |
188 | session->socket_fd = -1; | 188 | session->socket_fd = -1; |
189 | } | 189 | } |
190 | } | 190 | } |
@@ -345,7 +345,7 @@ MHD_parse_session_headers(struct MHD_Session * session) { | |||
345 | /* FIXME: here: find cookie header and parse that! */ | 345 | /* FIXME: here: find cookie header and parse that! */ |
346 | return; | 346 | return; |
347 | DIE: | 347 | DIE: |
348 | close(session->socket_fd); | 348 | CLOSE(session->socket_fd); |
349 | session->socket_fd = -1; | 349 | session->socket_fd = -1; |
350 | } | 350 | } |
351 | 351 | ||
@@ -389,7 +389,7 @@ MHD_call_session_handler(struct MHD_Session * session) { | |||
389 | /* serios internal error, close connection */ | 389 | /* serios internal error, close connection */ |
390 | MHD_DLOG(session->daemon, | 390 | MHD_DLOG(session->daemon, |
391 | "Internal application error, closing connection."); | 391 | "Internal application error, closing connection."); |
392 | close(session->socket_fd); | 392 | CLOSE(session->socket_fd); |
393 | session->socket_fd = -1; | 393 | session->socket_fd = -1; |
394 | return; | 394 | return; |
395 | } | 395 | } |
@@ -439,7 +439,7 @@ MHD_session_handle_read(struct MHD_Session * session) { | |||
439 | __FUNCTION__); | 439 | __FUNCTION__); |
440 | return MHD_NO; | 440 | return MHD_NO; |
441 | } | 441 | } |
442 | bytes_read = recv(session->socket_fd, | 442 | bytes_read = RECV(session->socket_fd, |
443 | &session->read_buffer[session->readLoc], | 443 | &session->read_buffer[session->readLoc], |
444 | session->read_buffer_size - session->readLoc, | 444 | session->read_buffer_size - session->readLoc, |
445 | 0); | 445 | 0); |
@@ -448,8 +448,8 @@ MHD_session_handle_read(struct MHD_Session * session) { | |||
448 | return MHD_NO; | 448 | return MHD_NO; |
449 | MHD_DLOG(session->daemon, | 449 | MHD_DLOG(session->daemon, |
450 | "Failed to receive data: %s\n", | 450 | "Failed to receive data: %s\n", |
451 | strerror(errno)); | 451 | STRERROR(errno)); |
452 | close(session->socket_fd); | 452 | CLOSE(session->socket_fd); |
453 | session->socket_fd = -1; | 453 | session->socket_fd = -1; |
454 | return MHD_YES; | 454 | return MHD_YES; |
455 | } | 455 | } |
@@ -458,7 +458,7 @@ MHD_session_handle_read(struct MHD_Session * session) { | |||
458 | /* FIXME: proper handling of end of upload! | 458 | /* FIXME: proper handling of end of upload! |
459 | If we were receiving an unbounded upload, | 459 | If we were receiving an unbounded upload, |
460 | we should finish up nicely now! */ | 460 | we should finish up nicely now! */ |
461 | close(session->socket_fd); | 461 | CLOSE(session->socket_fd); |
462 | session->socket_fd = -1; | 462 | session->socket_fd = -1; |
463 | return MHD_YES; | 463 | return MHD_YES; |
464 | } | 464 | } |
@@ -488,7 +488,7 @@ MHD_add_extra_headers(struct MHD_Session * session) { | |||
488 | "close"); | 488 | "close"); |
489 | } else if (NULL == MHD_get_response_header(session->response, | 489 | } else if (NULL == MHD_get_response_header(session->response, |
490 | "Content-length")) { | 490 | "Content-length")) { |
491 | snprintf(buf, | 491 | SNPRINTF(buf, |
492 | 128, | 492 | 128, |
493 | "%llu", | 493 | "%llu", |
494 | (unsigned long long) session->response->total_size); | 494 | (unsigned long long) session->response->total_size); |
@@ -512,7 +512,7 @@ MHD_build_header_response(struct MHD_Session * session) { | |||
512 | char * data; | 512 | char * data; |
513 | 513 | ||
514 | MHD_add_extra_headers(session); | 514 | MHD_add_extra_headers(session); |
515 | sprintf(code, | 515 | SPRINTF(code, |
516 | "HTTP/1.1 %u\r\n", | 516 | "HTTP/1.1 %u\r\n", |
517 | session->responseCode); | 517 | session->responseCode); |
518 | off = strlen(code); | 518 | off = strlen(code); |
@@ -530,7 +530,7 @@ MHD_build_header_response(struct MHD_Session * session) { | |||
530 | off); | 530 | off); |
531 | pos = session->response->first_header; | 531 | pos = session->response->first_header; |
532 | while (pos != NULL) { | 532 | while (pos != NULL) { |
533 | sprintf(&data[off], | 533 | SPRINTF(&data[off], |
534 | "%s: %s\r\n", | 534 | "%s: %s\r\n", |
535 | pos->header, | 535 | pos->header, |
536 | pos->value); | 536 | pos->value); |
@@ -567,7 +567,7 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
567 | if (! session->headersSent) { | 567 | if (! session->headersSent) { |
568 | if (session->write_buffer == NULL) | 568 | if (session->write_buffer == NULL) |
569 | MHD_build_header_response(session); | 569 | MHD_build_header_response(session); |
570 | ret = send(session->socket_fd, | 570 | ret = SEND(session->socket_fd, |
571 | &session->write_buffer[session->writeLoc], | 571 | &session->write_buffer[session->writeLoc], |
572 | session->write_buffer_size - session->writeLoc, | 572 | session->write_buffer_size - session->writeLoc, |
573 | 0); | 573 | 0); |
@@ -576,8 +576,8 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
576 | return MHD_YES; | 576 | return MHD_YES; |
577 | MHD_DLOG(session->daemon, | 577 | MHD_DLOG(session->daemon, |
578 | "Failed to send data: %s\n", | 578 | "Failed to send data: %s\n", |
579 | strerror(errno)); | 579 | STRERROR(errno)); |
580 | close(session->socket_fd); | 580 | CLOSE(session->socket_fd); |
581 | session->socket_fd = -1; | 581 | session->socket_fd = -1; |
582 | return MHD_YES; | 582 | return MHD_YES; |
583 | } | 583 | } |
@@ -614,7 +614,7 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
614 | if (ret == -1) { | 614 | if (ret == -1) { |
615 | /* end of message, signal other side by closing! */ | 615 | /* end of message, signal other side by closing! */ |
616 | response->data_size = session->messagePos; | 616 | response->data_size = session->messagePos; |
617 | close(session->socket_fd); | 617 | CLOSE(session->socket_fd); |
618 | session->socket_fd = -1; | 618 | session->socket_fd = -1; |
619 | return MHD_YES; | 619 | return MHD_YES; |
620 | } | 620 | } |
@@ -625,7 +625,7 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
625 | } | 625 | } |
626 | 626 | ||
627 | /* transmit */ | 627 | /* transmit */ |
628 | ret = send(session->socket_fd, | 628 | ret = SEND(session->socket_fd, |
629 | &response->data[session->messagePos - response->data_start], | 629 | &response->data[session->messagePos - response->data_start], |
630 | response->data_size - (session->messagePos - response->data_start), | 630 | response->data_size - (session->messagePos - response->data_start), |
631 | 0); | 631 | 0); |
@@ -636,8 +636,8 @@ MHD_session_handle_write(struct MHD_Session * session) { | |||
636 | return MHD_YES; | 636 | return MHD_YES; |
637 | MHD_DLOG(session->daemon, | 637 | MHD_DLOG(session->daemon, |
638 | "Failed to send data: %s\n", | 638 | "Failed to send data: %s\n", |
639 | strerror(errno)); | 639 | STRERROR(errno)); |
640 | close(session->socket_fd); | 640 | CLOSE(session->socket_fd); |
641 | session->socket_fd = -1; | 641 | session->socket_fd = -1; |
642 | return MHD_YES; | 642 | return MHD_YES; |
643 | } | 643 | } |