diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-05-21 10:16:03 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-05-21 10:16:03 +0000 |
commit | 6cf5f9bd46389b714bd32421ea64e670e2e2c5db (patch) | |
tree | 7bb5a55b789117fa6214b45b8e71b1b5e575bd24 /src | |
parent | 16d34819087d7fa77bcb6f4b5e9e73d7e3220c4d (diff) | |
download | gnunet-6cf5f9bd46389b714bd32421ea64e670e2e2c5db.tar.gz gnunet-6cf5f9bd46389b714bd32421ea64e670e2e2c5db.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http.c | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 21fc1eb5a..01c09092f 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -140,6 +140,11 @@ struct Session | |||
140 | */ | 140 | */ |
141 | uint32_t quota; | 141 | uint32_t quota; |
142 | 142 | ||
143 | /** | ||
144 | * Is there a HTTP/PUT in progress? | ||
145 | */ | ||
146 | unsigned int is_put_in_progress; | ||
147 | |||
143 | }; | 148 | }; |
144 | 149 | ||
145 | /** | 150 | /** |
@@ -297,6 +302,7 @@ static void requestCompletedCallback (void *cls, struct MHD_Connection * connect | |||
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->sender)); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection from peer `%s' was terminated\n",GNUNET_i2s(&cs->sender)); |
298 | /* session set to inactive */ | 303 | /* session set to inactive */ |
299 | cs->is_active = GNUNET_NO; | 304 | cs->is_active = GNUNET_NO; |
305 | cs->is_put_in_progress = GNUNET_NO; | ||
300 | } | 306 | } |
301 | return; | 307 | return; |
302 | } | 308 | } |
@@ -351,7 +357,6 @@ accessHandlerCallback (void *cls, | |||
351 | MHD_destroy_response (response); | 357 | MHD_destroy_response (response); |
352 | return MHD_YES; | 358 | return MHD_YES; |
353 | } | 359 | } |
354 | |||
355 | conn_info = MHD_get_connection_info(session, MHD_CONNECTION_INFO_CLIENT_ADDRESS ); | 360 | conn_info = MHD_get_connection_info(session, MHD_CONNECTION_INFO_CLIENT_ADDRESS ); |
356 | /* Incoming IPv4 connection */ | 361 | /* Incoming IPv4 connection */ |
357 | if ( AF_INET == conn_info->client_addr->sin_family) | 362 | if ( AF_INET == conn_info->client_addr->sin_family) |
@@ -367,10 +372,7 @@ accessHandlerCallback (void *cls, | |||
367 | addrin6 = (struct sockaddr_in6 *) conn_info->client_addr; | 372 | addrin6 = (struct sockaddr_in6 *) conn_info->client_addr; |
368 | inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN); | 373 | inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN); |
369 | } | 374 | } |
370 | 375 | /* find existing session for address */ | |
371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' request from peer `%s' from `[%s]:%u'\n",method, GNUNET_h2s(&pi_in.hashPubKey),address,conn_info->client_addr->sin_port); | ||
372 | |||
373 | /* find session for address */ | ||
374 | cs = NULL; | 376 | cs = NULL; |
375 | if (plugin->session_count > 0) | 377 | if (plugin->session_count > 0) |
376 | { | 378 | { |
@@ -396,7 +398,7 @@ accessHandlerCallback (void *cls, | |||
396 | cs = cs->next; | 398 | cs = cs->next; |
397 | } | 399 | } |
398 | } | 400 | } |
399 | 401 | /* no existing session, create a new one*/ | |
400 | if (cs == NULL ) | 402 | if (cs == NULL ) |
401 | { | 403 | { |
402 | /* create new session object */ | 404 | /* create new session object */ |
@@ -429,43 +431,54 @@ accessHandlerCallback (void *cls, | |||
429 | } | 431 | } |
430 | /* Set closure */ | 432 | /* Set closure */ |
431 | if (*httpSessionCache == NULL) | 433 | if (*httpSessionCache == NULL) |
434 | { | ||
432 | *httpSessionCache = cs; | 435 | *httpSessionCache = cs; |
436 | } | ||
437 | 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),cs->ip,cs->addr->sin_port); | ||
433 | } | 438 | } |
434 | else | 439 | else |
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Session already known \n"); | 440 | { |
441 | cs = *httpSessionCache; | ||
442 | } | ||
436 | 443 | ||
437 | /* Is it a PUT or a GET request */ | 444 | /* Is it a PUT or a GET request */ |
438 | if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) ) | 445 | if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) ) |
439 | { | 446 | { |
440 | /* PUT method here */ | 447 | /* New */ |
441 | if (*upload_data_size == 0) | 448 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_NO)) |
449 | { | ||
450 | /* not yet ready */ | ||
451 | cs->is_put_in_progress = GNUNET_YES; | ||
442 | return MHD_YES; | 452 | return MHD_YES; |
443 | 453 | } | |
444 | 454 | if ( *upload_data_size > 0 ) | |
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got PUT Request with size %lu \n",(*upload_data_size)); | 455 | { |
446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url); | 456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT URL: `%s'\n",url); |
447 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: `%s'\n",upload_data); | 457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: %lu bytes: `%s' \n", (*upload_data_size), upload_data); |
448 | /* No data left */ | 458 | /* No data left */ |
449 | *upload_data_size = 0; | 459 | *upload_data_size = 0; |
450 | 460 | /* do something with the data */ | |
451 | /* do something with the data */ | 461 | return MHD_YES; |
452 | 462 | } | |
453 | response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); | 463 | if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES)) |
454 | res = MHD_queue_response (session, MHD_HTTP_CONTINUE, response); | 464 | { |
455 | MHD_destroy_response (response); | 465 | cs->is_put_in_progress = GNUNET_NO; |
456 | return res; | 466 | response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); |
467 | res = MHD_queue_response (session, MHD_HTTP_OK, response); | ||
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 200 OK as PUT Response\n",HTTP_PUT_RESPONSE, strlen (HTTP_PUT_RESPONSE), res ); | ||
469 | MHD_destroy_response (response); | ||
470 | return res; | ||
471 | } | ||
457 | } | 472 | } |
458 | if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) | 473 | if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) |
459 | { | 474 | { |
460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n"); | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request\n"); |
461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url); | 476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"URL: `%s'\n",url); |
462 | |||
463 | response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); | 477 | response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO); |
464 | res = MHD_queue_response (session, MHD_HTTP_OK, response); | 478 | res = MHD_queue_response (session, MHD_HTTP_OK, response); |
465 | MHD_destroy_response (response); | 479 | MHD_destroy_response (response); |
466 | return res; | 480 | return res; |
467 | } | 481 | } |
468 | |||
469 | return MHD_NO; | 482 | return MHD_NO; |
470 | } | 483 | } |
471 | 484 | ||