aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README1
-rw-r--r--src/daemon/daemon.c32
-rw-r--r--src/daemon/session.c27
3 files changed, 38 insertions, 22 deletions
diff --git a/README b/README
index fd046b25..a91c1055 100644
--- a/README
+++ b/README
@@ -10,7 +10,6 @@ In general:
10=========== 10===========
11daemon.c: 11daemon.c:
12- MHD_cleanup_session: major memory leaks (headers!) 12- MHD_cleanup_session: major memory leaks (headers!)
13- add additional LOG messages for debugging
14 13
15session.c: 14session.c:
16- MHD_session_get_fdset (essentially not implemented) 15- MHD_session_get_fdset (essentially not implemented)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 5a7db531..3935832e 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -415,8 +415,6 @@ MHD_start_daemon(unsigned int options,
415 void * dh_cls) { 415 void * dh_cls) {
416 struct MHD_Daemon * retVal; 416 struct MHD_Daemon * retVal;
417 int socket_fd; 417 int socket_fd;
418 int opt;
419 int res;
420 struct sockaddr_in servaddr; 418 struct sockaddr_in servaddr;
421 419
422 if ((options & MHD_USE_SSL) != 0) 420 if ((options & MHD_USE_SSL) != 0)
@@ -430,7 +428,10 @@ MHD_start_daemon(unsigned int options,
430 return NULL; 428 return NULL;
431 socket_fd = socket(AF_INET, SOCK_STREAM, 0); 429 socket_fd = socket(AF_INET, SOCK_STREAM, 0);
432 if (socket_fd < 0) { 430 if (socket_fd < 0) {
433 /* FIXME: log error */ 431 if ((options & MHD_USE_DEBUG) != 0)
432 fprintf(stderr,
433 "Call to socket failed: %s\n",
434 strerror(errno));
434 return NULL; 435 return NULL;
435 } 436 }
436 memset(&servaddr, 437 memset(&servaddr,
@@ -441,22 +442,22 @@ MHD_start_daemon(unsigned int options,
441 if (bind(socket_fd, 442 if (bind(socket_fd,
442 (struct sockaddr *)&servaddr, 443 (struct sockaddr *)&servaddr,
443 sizeof(struct sockaddr_in)) < 0) { 444 sizeof(struct sockaddr_in)) < 0) {
444 /* FIXME: log error */ 445 if ( (options & MHD_USE_DEBUG) != 0)
446 fprintf(stderr,
447 "Failed to bind to port %u: %s\n",
448 port,
449 strerror(errno));
445 close(socket_fd); 450 close(socket_fd);
446 return NULL; 451 return NULL;
447 } 452 }
448 if (listen(socket_fd, 20) < 0) { 453 if (listen(socket_fd, 20) < 0) {
449 /* FIXME: log error */ 454 if ((options & MHD_USE_DEBUG) != 0)
455 fprintf(stderr,
456 "Failed to listen for connections: %s\n",
457 strerror(errno));
458 close(socket_fd);
450 return NULL; 459 return NULL;
451 } 460 }
452 opt = fcntl(socket_fd, F_GETFL, 0);
453 res = fcntl(socket_fd, F_SETFL, opt | O_NONBLOCK);
454 if (res < 0) {
455 /* FIXME: log error */
456 close(socket_fd);
457 return NULL;
458 }
459
460 retVal = malloc(sizeof(struct MHD_Daemon)); 461 retVal = malloc(sizeof(struct MHD_Daemon));
461 memset(retVal, 462 memset(retVal,
462 0, 463 0,
@@ -476,7 +477,9 @@ MHD_start_daemon(unsigned int options,
476 NULL, 477 NULL,
477 &MHD_select_thread, 478 &MHD_select_thread,
478 daemon)) ) { 479 daemon)) ) {
479 /* FIXME: log error */ 480 MHD_DLOG(retVal,
481 "Failed to create listen thread: %s\n",
482 strerror(errno));
480 free(retVal); 483 free(retVal);
481 close(socket_fd); 484 close(socket_fd);
482 return NULL; 485 return NULL;
@@ -512,3 +515,4 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) {
512 free(daemon); 515 free(daemon);
513} 516}
514 517
518/* end of daemon.c */
diff --git a/src/daemon/session.c b/src/daemon/session.c
index 9e8afa83..b458cad7 100644
--- a/src/daemon/session.c
+++ b/src/daemon/session.c
@@ -175,7 +175,9 @@ MHD_get_next_header_line(struct MHD_Session * session) {
175 session->read_buffer_size *= 2; 175 session->read_buffer_size *= 2;
176 } else { 176 } else {
177 /* die, header far too long to be reasonable */ 177 /* die, header far too long to be reasonable */
178 /* FIXME: log */ 178 MHD_DLOG(session->daemon,
179 "Received excessively long header line (>%u), closing connection.\n",
180 4 * MHD_MAX_BUF_SIZE);
179 close(session->socket_fd); 181 close(session->socket_fd);
180 session->socket_fd = -1; 182 session->socket_fd = -1;
181 } 183 }
@@ -251,7 +253,8 @@ MHD_parse_session_headers(struct MHD_Session * session) {
251 colon = strstr(line, ": "); 253 colon = strstr(line, ": ");
252 if (colon == NULL) { 254 if (colon == NULL) {
253 /* error in header line, die hard */ 255 /* error in header line, die hard */
254 /* FIXME: log */ 256 MHD_DLOG(session->daemon,
257 "Received malformed line (no colon), closing connection.\n");
255 goto DIE; 258 goto DIE;
256 } 259 }
257 /* zero-terminate header */ 260 /* zero-terminate header */
@@ -297,7 +300,9 @@ MHD_session_handle_read(struct MHD_Session * session) {
297 unsigned int processed; 300 unsigned int processed;
298 301
299 if (session->bodyReceived) { 302 if (session->bodyReceived) {
300 /* FIXME: LOG: why are we in select set? */ 303 MHD_DLOG(session->daemon,
304 "Unexpected call to %s.\n",
305 __FUNCTION__);
301 return MHD_NO; 306 return MHD_NO;
302 } 307 }
303 if (session->readLoc >= session->read_buffer_size) { 308 if (session->readLoc >= session->read_buffer_size) {
@@ -315,7 +320,9 @@ MHD_session_handle_read(struct MHD_Session * session) {
315 if (bytes_read < 0) { 320 if (bytes_read < 0) {
316 if (errno == EINTR) 321 if (errno == EINTR)
317 return MHD_NO; 322 return MHD_NO;
318 /* FIXME: log error */ 323 MHD_DLOG(session->daemon,
324 "Failed to receive data: %s\n",
325 strerror(errno));
319 return MHD_NO; 326 return MHD_NO;
320 } 327 }
321 if (bytes_read == 0) { 328 if (bytes_read == 0) {
@@ -409,7 +416,9 @@ MHD_session_handle_write(struct MHD_Session * session) {
409 416
410 response = session->response; 417 response = session->response;
411 if(response == NULL) { 418 if(response == NULL) {
412 /* FIXME: LOG: why are we here? */ 419 MHD_DLOG(session->daemon,
420 "Unexpected call to %s.\n",
421 __FUNCTION__);
413 return MHD_NO; 422 return MHD_NO;
414 } 423 }
415 if (! session->headersSent) { 424 if (! session->headersSent) {
@@ -422,7 +431,9 @@ MHD_session_handle_write(struct MHD_Session * session) {
422 if (ret < 0) { 431 if (ret < 0) {
423 if (errno == EINTR) 432 if (errno == EINTR)
424 return MHD_YES; 433 return MHD_YES;
425 /* FIXME: log error */ 434 MHD_DLOG(session->daemon,
435 "Failed to send data: %s\n",
436 strerror(errno));
426 close(session->socket_fd); 437 close(session->socket_fd);
427 session->socket_fd = -1; 438 session->socket_fd = -1;
428 return MHD_NO; 439 return MHD_NO;
@@ -480,7 +491,9 @@ MHD_session_handle_write(struct MHD_Session * session) {
480 if (ret == -1) { 491 if (ret == -1) {
481 if (errno == EINTR) 492 if (errno == EINTR)
482 return MHD_YES; 493 return MHD_YES;
483 /* FIXME: log */ 494 MHD_DLOG(session->daemon,
495 "Failed to send data: %s\n",
496 strerror(errno));
484 return MHD_NO; 497 return MHD_NO;
485 } 498 }
486 session->messagePos += ret; 499 session->messagePos += ret;