aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-09-09 09:07:22 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-09-09 09:07:22 +0000
commitb90d29c3ceef065739c46539ec748a71ea83cde3 (patch)
treea7671849cbc78450f220ed286b943722eda6ffc9 /src/transport/plugin_transport_http.c
parent4410e1e63a30aedebf29dbe7649a078c910cc18f (diff)
downloadgnunet-b90d29c3ceef065739c46539ec748a71ea83cde3.tar.gz
gnunet-b90d29c3ceef065739c46539ec748a71ea83cde3.zip
Merging http and https plugin ... first steps
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index f1896b6cc..317cd45b3 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -40,7 +40,17 @@
40#include "microhttpd.h" 40#include "microhttpd.h"
41#include <curl/curl.h> 41#include <curl/curl.h>
42 42
43#define DEBUG_HTTP GNUNET_NO 43#if BUILD_HTTPS
44#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
45#define LIBGNUNET_PLUGIN_TRANSPORT_COMPONENT transport_https
46#define PROTOCOL_PREFIX "https"
47#else
48#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
49#define LIBGNUNET_PLUGIN_TRANSPORT_COMPONENT transport_http
50#define PROTOCOL_PREFIX "http"
51#endif
52
53#define DEBUG_HTTP GNUNET_YES
44#define DEBUG_CURL GNUNET_NO 54#define DEBUG_CURL GNUNET_NO
45#define DEBUG_MHD GNUNET_NO 55#define DEBUG_MHD GNUNET_NO
46#define DEBUG_CONNECTIONS GNUNET_NO 56#define DEBUG_CONNECTIONS GNUNET_NO
@@ -51,7 +61,7 @@
51#define INBOUND GNUNET_NO 61#define INBOUND GNUNET_NO
52#define OUTBOUND GNUNET_YES 62#define OUTBOUND GNUNET_YES
53 63
54#define PROTOCOL_PREFIX "http" 64
55 65
56/** 66/**
57 * Text of the response sent back after the last bytes of a PUT 67 * Text of the response sent back after the last bytes of a PUT
@@ -2443,17 +2453,11 @@ libgnunet_plugin_transport_http_done (void *cls)
2443 GNUNET_free (plugin); 2453 GNUNET_free (plugin);
2444 GNUNET_free (api); 2454 GNUNET_free (api);
2445#if DEBUG_HTTP 2455#if DEBUG_HTTP
2446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unload http plugin complete...\n"); 2456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Unload %s plugin complete...\n", PROTOCOL_PREFIX);
2447#endif 2457#endif
2448 return NULL; 2458 return NULL;
2449} 2459}
2450 2460
2451#if BUILD_HTTPS
2452#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_https_init
2453#else
2454#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_http_init
2455#endif
2456
2457/** 2461/**
2458 * Entry point for the plugin. 2462 * Entry point for the plugin.
2459 */ 2463 */
@@ -2465,10 +2469,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2465 struct GNUNET_TRANSPORT_PluginFunctions *api; 2469 struct GNUNET_TRANSPORT_PluginFunctions *api;
2466 struct GNUNET_TIME_Relative gn_timeout; 2470 struct GNUNET_TIME_Relative gn_timeout;
2467 long long unsigned int port; 2471 long long unsigned int port;
2472 char * component_name;
2468 2473
2469 GNUNET_assert(cls !=NULL); 2474 GNUNET_assert(cls !=NULL);
2470#if DEBUG_HTTP 2475#if DEBUG_HTTP
2471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n"); 2476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting %s plugin...\n", PROTOCOL_PREFIX);
2472#endif 2477#endif
2473 2478
2474 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2479 plugin = GNUNET_malloc (sizeof (struct Plugin));
@@ -2487,48 +2492,49 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2487 api->check_address = &http_plugin_address_suggested; 2492 api->check_address = &http_plugin_address_suggested;
2488 api->address_to_string = &http_plugin_address_to_string; 2493 api->address_to_string = &http_plugin_address_to_string;
2489 2494
2495 GNUNET_asprintf(&component_name,"transport-%s",PROTOCOL_PREFIX);
2490 /* Hashing our identity to use it in URLs */ 2496 /* Hashing our identity to use it in URLs */
2491 GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &plugin->my_ascii_hash_ident); 2497 GNUNET_CRYPTO_hash_to_enc ( &(plugin->env->my_identity->hashPubKey), &plugin->my_ascii_hash_ident);
2492 2498
2493 /* Reading port number from config file */ 2499 /* Reading port number from config file */
2494 if (GNUNET_CONFIGURATION_have_value (env->cfg, 2500 if (GNUNET_CONFIGURATION_have_value (env->cfg,
2495 "transport-http", "USE_IPv6")) 2501 component_name, "USE_IPv6"))
2496 { 2502 {
2497 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2503 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2498 "transport-http", 2504 component_name,
2499 "USE_IPv6"); 2505 "USE_IPv6");
2500 } 2506 }
2501 /* Reading port number from config file */ 2507 /* Reading port number from config file */
2502 if (GNUNET_CONFIGURATION_have_value (env->cfg, 2508 if (GNUNET_CONFIGURATION_have_value (env->cfg,
2503 "transport-http", "USE_IPv4")) 2509 component_name, "USE_IPv4"))
2504 { 2510 {
2505 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 2511 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2506 "transport-http", 2512 component_name,
2507 "USE_IPv4"); 2513 "USE_IPv4");
2508 } 2514 }
2509 /* Reading port number from config file */ 2515 /* Reading port number from config file */
2510 if ((GNUNET_OK != 2516 if ((GNUNET_OK !=
2511 GNUNET_CONFIGURATION_get_value_number (env->cfg, 2517 GNUNET_CONFIGURATION_get_value_number (env->cfg,
2512 "transport-http", 2518 component_name,
2513 "PORT", 2519 "PORT",
2514 &port)) || 2520 &port)) ||
2515 (port > 65535) ) 2521 (port > 65535) )
2516 { 2522 {
2517 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2523 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2518 "http", 2524 component_name,
2519 _("Require valid port number for transport plugin `%s' in configuration!\n"), 2525 _("Require valid port number for transport plugin `%s' in configuration!\n"),
2520 "transport-http"); 2526 PROTOCOL_PREFIX);
2521 libgnunet_plugin_transport_http_done (api); 2527 libgnunet_plugin_transport_http_done (api);
2522 return NULL; 2528 return NULL;
2523 } 2529 }
2524 2530
2525 /* Reading ipv4 addresse to bind to from config file */ 2531 /* Reading ipv4 addresse to bind to from config file */
2526 if ((plugin->use_ipv4==GNUNET_YES) && (GNUNET_CONFIGURATION_have_value (env->cfg, 2532 if ((plugin->use_ipv4==GNUNET_YES) && (GNUNET_CONFIGURATION_have_value (env->cfg,
2527 "transport-http", "BINDTO4"))) 2533 component_name, "BINDTO4")))
2528 { 2534 {
2529 GNUNET_break (GNUNET_OK == 2535 GNUNET_break (GNUNET_OK ==
2530 GNUNET_CONFIGURATION_get_value_string (env->cfg, 2536 GNUNET_CONFIGURATION_get_value_string (env->cfg,
2531 "transport-http", 2537 component_name,
2532 "BINDTO4", 2538 "BINDTO4",
2533 &plugin->bind_hostname)); 2539 &plugin->bind_hostname));
2534 plugin->bind4_address = GNUNET_malloc(sizeof(struct sockaddr_in)); 2540 plugin->bind4_address = GNUNET_malloc(sizeof(struct sockaddr_in));
@@ -2538,9 +2544,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2538 if (inet_pton(AF_INET,plugin->bind_hostname, &plugin->bind4_address->sin_addr)<=0) 2544 if (inet_pton(AF_INET,plugin->bind_hostname, &plugin->bind4_address->sin_addr)<=0)
2539 { 2545 {
2540 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2546 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2541 "http", 2547 component_name,
2542 _("Misconfigured address to bind to in configuration!\n"), 2548 _("Misconfigured address to bind to in configuration!\n"));
2543 "transport-http");
2544 GNUNET_free(plugin->bind4_address); 2549 GNUNET_free(plugin->bind4_address);
2545 GNUNET_free(plugin->bind_hostname); 2550 GNUNET_free(plugin->bind_hostname);
2546 plugin->bind_hostname = NULL; 2551 plugin->bind_hostname = NULL;
@@ -2550,10 +2555,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2550 2555
2551 /* Reading ipv4 addresse to bind to from config file */ 2556 /* Reading ipv4 addresse to bind to from config file */
2552 if ((plugin->use_ipv6==GNUNET_YES) && (GNUNET_CONFIGURATION_have_value (env->cfg, 2557 if ((plugin->use_ipv6==GNUNET_YES) && (GNUNET_CONFIGURATION_have_value (env->cfg,
2553 "transport-http", "BINDTO6"))) 2558 component_name, "BINDTO6")))
2554 { 2559 {
2555 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, 2560 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg,
2556 "transport-http", 2561 component_name,
2557 "BINDTO6", 2562 "BINDTO6",
2558 &plugin->bind_hostname)) 2563 &plugin->bind_hostname))
2559 { 2564 {
@@ -2564,9 +2569,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2564 if (inet_pton(AF_INET6,plugin->bind_hostname, &plugin->bind6_address->sin6_addr)<=0) 2569 if (inet_pton(AF_INET6,plugin->bind_hostname, &plugin->bind6_address->sin6_addr)<=0)
2565 { 2570 {
2566 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2571 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2567 "http", 2572 component_name,
2568 _("Misconfigured address to bind to in configuration!\n"), 2573 _("Misconfigured address to bind to in configuration!\n"));
2569 "transport-http");
2570 GNUNET_free(plugin->bind6_address); 2574 GNUNET_free(plugin->bind6_address);
2571 GNUNET_free(plugin->bind_hostname); 2575 GNUNET_free(plugin->bind_hostname);
2572 plugin->bind_hostname = NULL; 2576 plugin->bind_hostname = NULL;
@@ -2666,9 +2670,9 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2666 if ( NULL == plugin->multi_handle ) 2670 if ( NULL == plugin->multi_handle )
2667 { 2671 {
2668 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2672 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2669 "https", 2673 component_name,
2670 _("Could not initialize curl multi handle, failed to start http plugin!\n"), 2674 _("Could not initialize curl multi handle, failed to start %s plugin!\n"),
2671 "transport-https"); 2675 PROTOCOL_PREFIX);
2672 libgnunet_plugin_transport_http_done (api); 2676 libgnunet_plugin_transport_http_done (api);
2673 return NULL; 2677 return NULL;
2674 } 2678 }