aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/plugin_transport_http_server.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 58c8fd215..272ecb645 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -344,8 +344,28 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
344 return bytes_read; 344 return bytes_read;
345} 345}
346 346
347static struct ServerConnection * 347static struct Session *
348server_lookup_session (struct Plugin *plugin, 348server_lookup_session (struct Plugin *plugin,
349 struct ServerConnection * sc)
350{
351 struct Session *s;
352 for (s = plugin->head; NULL != s; s = s->next)
353 {
354 if ((s->server_recv == sc) || (s->server_send == sc))
355 return s;
356 }
357
358 for (s = plugin->server_semi_head; NULL != s; s = s->next)
359 {
360 if ((s->server_recv == sc) || (s->server_send == sc))
361 return s;
362 }
363 return s;
364}
365
366
367static struct ServerConnection *
368server_lookup_serverconnection (struct Plugin *plugin,
349 struct MHD_Connection *mhd_connection, const char *url, 369 struct MHD_Connection *mhd_connection, const char *url,
350 const char *method) 370 const char *method)
351{ 371{
@@ -531,6 +551,9 @@ create:
531 s->inbound = GNUNET_YES; 551 s->inbound = GNUNET_YES;
532 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; 552 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS;
533 s->tag = tag; 553 s->tag = tag;
554 s->server_recv = NULL;
555 s->server_send = NULL;
556
534 GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head, 557 GNUNET_CONTAINER_DLL_insert (plugin->server_semi_head,
535 plugin->server_semi_tail, s); 558 plugin->server_semi_tail, s);
536 goto found; 559 goto found;
@@ -542,6 +565,7 @@ error:
542 565
543found: 566found:
544 sc = GNUNET_malloc (sizeof (struct ServerConnection)); 567 sc = GNUNET_malloc (sizeof (struct ServerConnection));
568 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Create %p\n", sc);
545 sc->mhd_conn = mhd_connection; 569 sc->mhd_conn = mhd_connection;
546 sc->direction = direction; 570 sc->direction = direction;
547 sc->session = s; 571 sc->session = s;
@@ -592,7 +616,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
592 /* new connection */ 616 /* new connection */
593 if (sc == NULL) 617 if (sc == NULL)
594 { 618 {
595 sc = server_lookup_session (plugin, mhd_connection, url, method); 619 sc = server_lookup_serverconnection (plugin, mhd_connection, url, method);
596 if (sc != NULL) 620 if (sc != NULL)
597 (*httpSessionCache) = sc; 621 (*httpSessionCache) = sc;
598 else 622 else
@@ -605,6 +629,15 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
605 return res; 629 return res;
606 } 630 }
607 } 631 }
632 else
633 {
634 if (NULL == server_lookup_session (plugin, sc))
635 {
636 /* Session was already disconnected */
637 GNUNET_break (0);
638 return MHD_NO;
639 }
640 }
608 641
609 /* existing connection */ 642 /* existing connection */
610 sc = (*httpSessionCache); 643 sc = (*httpSessionCache);
@@ -738,6 +771,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
738 if (sc == NULL) 771 if (sc == NULL)
739 return; 772 return;
740 773
774 if (NULL == (s = server_lookup_session (p, sc)))
775 return;
776
741 s = sc->session; 777 s = sc->session;
742 GNUNET_assert (NULL != s); 778 GNUNET_assert (NULL != s);
743 GNUNET_assert (NULL != p); 779 GNUNET_assert (NULL != p);
@@ -752,14 +788,13 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
752 "Server: %X peer `%s' GET on address `%s' disconnected\n", 788 "Server: %X peer `%s' GET on address `%s' disconnected\n",
753 s->server_send, GNUNET_i2s (&s->target), 789 s->server_send, GNUNET_i2s (&s->target),
754 http_plugin_address_to_string (NULL, s->addr, s->addrlen)); 790 http_plugin_address_to_string (NULL, s->addr, s->addrlen));
755 GNUNET_free (s->server_send);
756 s->server_send = NULL; 791 s->server_send = NULL;
757 if (s->server_recv != NULL) 792 if (NULL != (tc = s->server_recv))
758 { 793 {
759 tc = s->server_recv;
760 tc->disconnect = GNUNET_YES; 794 tc->disconnect = GNUNET_YES;
795 GNUNET_assert (NULL != tc->mhd_conn);
761#if MHD_VERSION >= 0x00090E00 796#if MHD_VERSION >= 0x00090E00
762 MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 797 MHD_set_connection_option (tc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
763 1); 798 1);
764#endif 799#endif
765 } 800 }
@@ -770,14 +805,13 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
770 "Server: %X peer `%s' PUT on address `%s' disconnected\n", 805 "Server: %X peer `%s' PUT on address `%s' disconnected\n",
771 s->server_recv, GNUNET_i2s (&s->target), 806 s->server_recv, GNUNET_i2s (&s->target),
772 http_plugin_address_to_string (NULL, s->addr, s->addrlen)); 807 http_plugin_address_to_string (NULL, s->addr, s->addrlen));
773 GNUNET_free (s->server_recv);
774 s->server_recv = NULL; 808 s->server_recv = NULL;
775 if (s->server_send != NULL) 809 if (NULL != (tc = s->server_send))
776 { 810 {
777 tc = s->server_send;
778 tc->disconnect = GNUNET_YES; 811 tc->disconnect = GNUNET_YES;
812 GNUNET_assert (NULL != tc->mhd_conn);
779#if MHD_VERSION >= 0x00090E00 813#if MHD_VERSION >= 0x00090E00
780 MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 814 MHD_set_connection_option (tc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT,
781 1); 815 1);
782#endif 816#endif
783 } 817 }
@@ -787,6 +821,7 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection,
787 s->msg_tk = NULL; 821 s->msg_tk = NULL;
788 } 822 }
789 } 823 }
824
790 GNUNET_free (sc); 825 GNUNET_free (sc);
791 826
792 t = plugin->server_semi_head; 827 t = plugin->server_semi_head;
@@ -1153,8 +1188,6 @@ server_stop (struct Plugin *plugin)
1153 struct Session *s = NULL; 1188 struct Session *s = NULL;
1154 struct Session *t = NULL; 1189 struct Session *t = NULL;
1155 1190
1156 p = NULL;
1157
1158 struct MHD_Daemon *server_v4_tmp = plugin->server_v4; 1191 struct MHD_Daemon *server_v4_tmp = plugin->server_v4;
1159 1192
1160 plugin->server_v4 = NULL; 1193 plugin->server_v4 = NULL;
@@ -1212,6 +1245,8 @@ server_stop (struct Plugin *plugin)
1212 s = t; 1245 s = t;
1213 } 1246 }
1214 1247
1248 p = NULL;
1249
1215#if BUILD_HTTPS 1250#if BUILD_HTTPS
1216 GNUNET_free_non_null (plugin->crypto_init); 1251 GNUNET_free_non_null (plugin->crypto_init);
1217 GNUNET_free_non_null (plugin->cert); 1252 GNUNET_free_non_null (plugin->cert);