aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/plugin_transport_http.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 628fff100..5b5ef6c49 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -33,6 +33,7 @@
33#include "gnunet_statistics_service.h" 33#include "gnunet_statistics_service.h"
34#include "gnunet_transport_service.h" 34#include "gnunet_transport_service.h"
35#include "gnunet_resolver_service.h" 35#include "gnunet_resolver_service.h"
36#include "gnunet_server_lib.h"
36#include "plugin_transport.h" 37#include "plugin_transport.h"
37#include "gnunet_os_lib.h" 38#include "gnunet_os_lib.h"
38#include "microhttpd.h" 39#include "microhttpd.h"
@@ -236,6 +237,8 @@ struct Session
236 struct HTTP_Message * pending_inbound_msg; 237 struct HTTP_Message * pending_inbound_msg;
237 238
238 CURL *curl_handle; 239 CURL *curl_handle;
240
241 struct GNUNET_SERVER_MessageStreamTokenizer * msgtok;
239}; 242};
240 243
241/** 244/**
@@ -381,6 +384,7 @@ static struct Session * create_session (struct sockaddr_in *addr_in, struct sock
381 ses->pending_inbound_msg->buf = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE); 384 ses->pending_inbound_msg->buf = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE);
382 ses->pending_inbound_msg->len = GNUNET_SERVER_MAX_MESSAGE_SIZE; 385 ses->pending_inbound_msg->len = GNUNET_SERVER_MAX_MESSAGE_SIZE;
383 ses->pending_inbound_msg->pos = 0; 386 ses->pending_inbound_msg->pos = 0;
387 ses->msgtok = NULL;
384 return ses; 388 return ses;
385} 389}
386 390
@@ -402,6 +406,16 @@ static void requestCompletedCallback (void *cls, struct MHD_Connection * connect
402 return; 406 return;
403} 407}
404 408
409
410static void messageTokenizerCallback (void *cls,
411 void *client,
412 const struct
413 GNUNET_MessageHeader *
414 message)
415{
416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"messageTokenizerCallback\n");
417}
418
405/** 419/**
406 * Check if we are allowed to connect to the given IP. 420 * Check if we are allowed to connect to the given IP.
407 */ 421 */
@@ -525,12 +539,14 @@ accessHandlerCallback (void *cls,
525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", GNUNET_i2s(&cs->sender), plugin->session_count); 539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New Session `%s' inserted, count %u \n", GNUNET_i2s(&cs->sender), plugin->session_count);
526 } 540 }
527 541
528 /* Set closure */ 542 /* Set closure and update current session*/
529 if (*httpSessionCache == NULL) 543 if (*httpSessionCache == NULL)
530 { 544 {
531 *httpSessionCache = cs; 545 *httpSessionCache = cs;
532 /* Updating session */ 546 /* Updating session */
533 memcpy(cs->addr_inbound,conn_info->client_addr, sizeof(struct sockaddr_in)); 547 memcpy(cs->addr_inbound,conn_info->client_addr, sizeof(struct sockaddr_in));
548 if (cs->msgtok==NULL)
549 cs->msgtok = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE, cs, &messageTokenizerCallback, NULL);
534 } 550 }
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`[%s]:%u')\n",method, GNUNET_i2s(&cs->sender),address,ntohs(cs->addr_inbound->sin_port)); 551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has new an incoming `%s' request from peer `%s' (`[%s]:%u')\n",method, GNUNET_i2s(&cs->sender),address,ntohs(cs->addr_inbound->sin_port));
536 } 552 }
@@ -603,12 +619,15 @@ accessHandlerCallback (void *cls,
603 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader)) 619 if (cs->pending_inbound_msg->pos >= sizeof (struct GNUNET_MessageHeader))
604 { 620 {
605 cur_msg = (struct GNUNET_MessageHeader *) cs->pending_inbound_msg->buf; 621 cur_msg = (struct GNUNET_MessageHeader *) cs->pending_inbound_msg->buf;
606 unsigned int len = ntohs (cur_msg->size); 622 //unsigned int len = ntohs (cur_msg->size);
607 623
624 res = GNUNET_SERVER_mst_receive(cs->msgtok,cs->pending_inbound_msg->buf,cs->pending_inbound_msg->pos, GNUNET_NO, GNUNET_NO);
625 if ((res != GNUNET_SYSERR) && (res != GNUNET_NO))
626 send_error_to_client = GNUNET_NO;
627#if 0
608 if (len == cs->pending_inbound_msg->pos) 628 if (len == cs->pending_inbound_msg->pos)
609 { 629 {
610 char * tmp = NULL; 630 char * tmp = NULL;
611 /* one message in recieved data, can pass directly*/
612 if ( AF_INET == cs->addr_inbound->sin_family) 631 if ( AF_INET == cs->addr_inbound->sin_family)
613 { 632 {
614 inet_ntop(AF_INET, &(cs->addr_inbound)->sin_addr,address,INET_ADDRSTRLEN); 633 inet_ntop(AF_INET, &(cs->addr_inbound)->sin_addr,address,INET_ADDRSTRLEN);
@@ -663,6 +682,7 @@ accessHandlerCallback (void *cls,
663 break; 682 break;
664 } 683 }
665 } 684 }
685
666 if (send_error_to_client == GNUNET_NO) 686 if (send_error_to_client == GNUNET_NO)
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Forwarded %u messages with %u bytes of data to transport service\n", 687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Forwarded %u messages with %u bytes of data to transport service\n",
668 c_msgs, bytes_proc); 688 c_msgs, bytes_proc);
@@ -676,6 +696,7 @@ accessHandlerCallback (void *cls,
676 /* message size bigger than data recieved -> malformed */ 696 /* message size bigger than data recieved -> malformed */
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved malformed message: size in header %u bytes, recieved: %u \n", len, cs->pending_inbound_msg->pos); 697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved malformed message: size in header %u bytes, recieved: %u \n", len, cs->pending_inbound_msg->pos);
678 } 698 }
699#endif
679 } 700 }
680 701
681 if (send_error_to_client == GNUNET_NO) 702 if (send_error_to_client == GNUNET_NO)
@@ -1640,6 +1661,7 @@ libgnunet_plugin_transport_http_done (void *cls)
1640 GNUNET_free (cur); 1661 GNUNET_free (cur);
1641 cur = tmp; 1662 cur = tmp;
1642 } 1663 }
1664 GNUNET_SERVER_mst_destroy (cs->msgtok);
1643 GNUNET_free (cs->pending_inbound_msg->buf); 1665 GNUNET_free (cs->pending_inbound_msg->buf);
1644 GNUNET_free (cs->pending_inbound_msg); 1666 GNUNET_free (cs->pending_inbound_msg);
1645 GNUNET_free_non_null (cs->addr_inbound); 1667 GNUNET_free_non_null (cs->addr_inbound);