*/
unsigned int is_put_in_progress;
+ /**
+ * Is there a HTTP/PUT in progress?
+ */
+ unsigned int is_bad_request;
+
/**
* Encoded hash
*/
}
+int serror;
+
/**
* Process GET or PUT request received via MHD. For
* GET, queue response that will send back our pending
gn_msg = NULL;
send_error_to_client = GNUNET_NO;
+
if ( NULL == *httpSessionCache)
{
/* check url for peer identity */
cs->is_active = GNUNET_YES;
return MHD_YES;
}
+
+ if (cs->is_bad_request == GNUNET_YES)
+ {
+ *upload_data_size = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Info: size: %u method: %s \n",*upload_data_size,method);
+ response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
+ if (response == NULL)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"response NULL\n");
+ res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response);
+ if (res == MHD_YES)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n");
+ cs->is_bad_request = GNUNET_NO;
+ cs->is_put_in_progress =GNUNET_NO;
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response not sent\n");
+ MHD_destroy_response (response);
+ return MHD_YES;
+ }
+
if ( *upload_data_size > 0 )
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT URL: `%s'\n",url);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: %lu bytes: `%s' \n", (*upload_data_size), upload_data);
- /* No data left */
+
bytes_recv = *upload_data_size ;
*upload_data_size = 0;
if ( ntohs(gn_msg->size) != bytes_recv )
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Message has incorrect size, is %u bytes vs %u recieved'\n",ntohs(gn_msg->size) , bytes_recv);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Malformed GNUnet: message has incorrect size, is %u bytes in header vs %u recieved\n",ntohs(gn_msg->size) , bytes_recv);
send_error_to_client = GNUNET_YES;
}
- if ( GNUNET_YES == send_error_to_client)
+ if (send_error_to_client == GNUNET_YES)
{
- response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
- res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as PUT Response\n",HTTP_PUT_RESPONSE, strlen (HTTP_PUT_RESPONSE), res );
- MHD_destroy_response (response);
- GNUNET_free (gn_msg);
- return MHD_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Malformed GNUnet, should send error\n");
+ cs->is_bad_request = GNUNET_YES;
+ return MHD_YES;
}
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved GNUnet message type %u size %u and payload %u \n",ntohs (gn_msg->type), ntohs (gn_msg->size), ntohs (gn_msg->size)-sizeof(struct GNUNET_MessageHeader));
/* forwarding message to transport */
plugin->env->receive(plugin->env, &(cs->sender), gn_msg, 1, cs , cs->ip, strlen(cs->ip) );
+ GNUNET_free (gn_msg);
return MHD_YES;
}
+
+
if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES))
{
cs->is_put_in_progress = GNUNET_NO;
#include "transport.h"
#include <curl/curl.h>
-#define VERBOSE GNUNET_NO
-#define DEBUG GNUNET_NO
-#define DEBUG_CURL GNUNET_NO
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
+#define DEBUG_CURL GNUNET_YES
#define HTTP_BUFFER_SIZE 2048
#define PLUGIN libgnunet_plugin_transport_template
/**
* buffer
*/
- char *buf;
+ unsigned char buf[HTTP_BUFFER_SIZE];
/**
* current position in buffer
/**
* buffer for http transfers
*/
- unsigned char buf[2048];
+ unsigned char buf[HTTP_BUFFER_SIZE];
/**
* buffer size this transfer
*/
static struct HTTP_Transfer test_too_long_ident;
+/**
+ * Test: connect to peer and send message bigger then content length
+ */
+static struct HTTP_Transfer test_msg_too_big;
+
+/**
+ * Test: connect to peer and send message bigger GNUNET_SERVER_MAX_MESSAGE_SIZE
+ */
+//static struct HTTP_Transfer test_msg_bigger_max;
+
+/**
+ * Test: connect to peer and send message smaller then content length
+ */
+//static struct HTTP_Transfer test_msg_too_small;
/**
* Test: connect to peer with valid peer identification
GNUNET_SCHEDULER_shutdown(sched);
- GNUNET_free (buffer_in.buf);
- GNUNET_free (buffer_out.buf);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
exit(fail);
return;
static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr)
{
unsigned int len;
- struct HTTP_Message * cbc = ptr;
+ struct HTTP_Transfer * test = (struct HTTP_Transfer *) ptr;
- len = cbc->len;
+ len = buffer_out.len;
- if (( cbc->pos == len) && (len < (size * nmemb)))
+ if (test == &test_msg_too_big)
+ {
+ if (buffer_out.pos > len)
+ return 0;
+ if ( (2*len) < (size * nmemb))
+ memcpy(stream, buffer_out.buf, 2* len);
+ buffer_out.pos = 2* len;
+ return 2* len;
+ }
+
+ if (( buffer_out.pos == len) || (len > (size * nmemb)))
return 0;
- memcpy(stream, cbc->buf, len);
- cbc->pos = len;
+ memcpy(stream, buffer_out.buf, len);
+ buffer_out.pos = len;
return len;
}
memcpy(tmp,ptr,len);
if (tmp[len-2] == 13)
tmp[len-2]= '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Header: `%s'\n"),tmp);
if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
{
res->http_result_code=100;
curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
- curl_easy_setopt (curl_handle, CURLOPT_READDATA, &buffer_out);
+ curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
/* Connecting to peer without identification */
host_str = GNUNET_malloc (strlen ("http://localhost:12389/")+1);
GNUNET_asprintf (&host_str, "http://localhost:%u/",port);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"), host_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n"));
test_no_ident.test_executed = GNUNET_YES;
send_data ( &test_no_ident, host_str);
GNUNET_free (host_str);
/* Connecting to peer with too short identification */
host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident));
GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n"), host_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n"));
test_too_short_ident.test_executed = GNUNET_YES;
send_data ( &test_too_short_ident, host_str);
GNUNET_free (host_str);
host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen (ident));
GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"), host_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n"));
test_too_long_ident.test_executed = GNUNET_YES;
send_data ( &test_too_long_ident, host_str);
GNUNET_free (host_str);
host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result));
GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n"), host_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n"));
test_valid_ident.test_executed = GNUNET_YES;
send_data ( &test_valid_ident, host_str);
GNUNET_free (host_str);
return;
}
+/*
+ if (test_msg_too_big.test_executed == GNUNET_NO)
+ {
+ struct GNUNET_CRYPTO_HashAsciiEncoded result;
+ unsigned int c;
+ GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result);
+ host_str = GNUNET_malloc (strlen ("http://localhost:12389/") + strlen ((const char *) &result));
+ GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) &result);
+
+ buffer_out.len = 50;
+ c = 0;
+ for (c=0; c<100; c++)
+ buffer_out.buf[c] = 'A';
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with message bigger content length.\n"));
+ test_msg_too_big.test_executed = GNUNET_YES;
+ send_data ( &test_msg_too_big, host_str);
+ GNUNET_free (host_str);
+
+ return;
+ }
+*/
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
shutdown_clean();
}
/* Setting up buffers */
buffer_in.size = HTTP_BUFFER_SIZE;
- buffer_in.buf = GNUNET_malloc (HTTP_BUFFER_SIZE);
buffer_in.pos = 0;
buffer_in.len = 0;
buffer_out.size = HTTP_BUFFER_SIZE;
- buffer_out.buf = GNUNET_malloc (HTTP_BUFFER_SIZE);
buffer_out.pos = 0;
buffer_out.len = 0;
test_valid_ident.test_executed = GNUNET_NO;
test_valid_ident.test_failed = GNUNET_YES;
+ /* Test: connecting with valid identification */
+ test_msg_too_big.test_executed = GNUNET_NO;
+ test_msg_too_big.test_failed = GNUNET_YES;
+
run_connection_tests();
/* testing finished */