diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-01-17 16:21:37 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-01-17 16:21:37 +0000 |
commit | 6c75b8a6af8b2127f36b0286d19e043afe235f77 (patch) | |
tree | b80fa2b600676749b8af173f0395e5fca6b0417e /src/transport | |
parent | 98ff7cc0d495e235024467467c77409ac5359253 (diff) | |
download | gnunet-6c75b8a6af8b2127f36b0286d19e043afe235f77.tar.gz gnunet-6c75b8a6af8b2127f36b0286d19e043afe235f77.zip |
address parsing
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/Makefile.am | 11 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 1 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.c | 75 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_common.h | 7 |
4 files changed, 92 insertions, 2 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index ef5517e01..3cf9f1c14 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -316,6 +316,7 @@ check_PROGRAMS = \ | |||
316 | test_plugin_udp \ | 316 | test_plugin_udp \ |
317 | $(UNIX_TEST) \ | 317 | $(UNIX_TEST) \ |
318 | $(WLAN_PLUGIN_TEST) \ | 318 | $(WLAN_PLUGIN_TEST) \ |
319 | test_http_common \ | ||
319 | $(HTTP_CLIENT_PLUGIN_TEST) \ | 320 | $(HTTP_CLIENT_PLUGIN_TEST) \ |
320 | $(HTTPS_CLIENT_PLUGIN_TEST) \ | 321 | $(HTTPS_CLIENT_PLUGIN_TEST) \ |
321 | $(HTTP_SERVER_PLUGIN_TEST) \ | 322 | $(HTTP_SERVER_PLUGIN_TEST) \ |
@@ -493,6 +494,16 @@ test_plugin_wlan_LDADD = \ | |||
493 | $(top_builddir)/src/util/libgnunetutil.la \ | 494 | $(top_builddir)/src/util/libgnunetutil.la \ |
494 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 495 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
495 | 496 | ||
497 | |||
498 | test_http_common_SOURCES = \ | ||
499 | test_http_common.c plugin_transport_http_common.c | ||
500 | test_http_common_LDADD = \ | ||
501 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
502 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
503 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
504 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
505 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
506 | |||
496 | test_plugin_http_server_SOURCES = \ | 507 | test_plugin_http_server_SOURCES = \ |
497 | test_plugin_transport.c | 508 | test_plugin_transport.c |
498 | test_plugin_http_server_LDADD = \ | 509 | test_plugin_http_server_LDADD = \ |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index f94814d41..bdfcd1e89 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -756,7 +756,6 @@ static void | |||
756 | transmit_address_to_client (void *cls, const char *buf) | 756 | transmit_address_to_client (void *cls, const char *buf) |
757 | { | 757 | { |
758 | struct AddressToStringContext *actx = cls; | 758 | struct AddressToStringContext *actx = cls; |
759 | |||
760 | if (NULL == buf) | 759 | if (NULL == buf) |
761 | { | 760 | { |
762 | GNUNET_SERVER_transmit_context_append_data (actx->tc, NULL, 0, | 761 | GNUNET_SERVER_transmit_context_append_data (actx->tc, NULL, 0, |
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index 5dd3413e1..0c9bfffc8 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -28,6 +28,80 @@ | |||
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | #include "gnunet_transport_plugin.h" | 29 | #include "gnunet_transport_plugin.h" |
30 | 30 | ||
31 | struct SplittedHTTPAddress | ||
32 | { | ||
33 | char *protocoll; | ||
34 | char *host; | ||
35 | char *port; | ||
36 | char *path; | ||
37 | }; | ||
38 | |||
39 | struct SplittedHTTPAddress * | ||
40 | http_split_address (const char * addr) | ||
41 | { | ||
42 | struct SplittedHTTPAddress *sp; | ||
43 | char *src = GNUNET_strdup (addr); | ||
44 | char *protocoll_start = NULL; | ||
45 | char *host_start = NULL; | ||
46 | char *port_start = NULL; | ||
47 | char *path_start = NULL; | ||
48 | |||
49 | protocoll_start = src; | ||
50 | sp = GNUNET_malloc (sizeof (struct SplittedHTTPAddress)); | ||
51 | |||
52 | host_start = strstr (src, "://"); | ||
53 | if (NULL == host_start) | ||
54 | { | ||
55 | GNUNET_free (src); | ||
56 | GNUNET_free (sp); | ||
57 | return NULL; | ||
58 | } | ||
59 | |||
60 | host_start[0] = '\0'; | ||
61 | sp->protocoll = GNUNET_strdup (protocoll_start); | ||
62 | |||
63 | host_start += strlen ("://"); | ||
64 | if (strlen (host_start) == 0) | ||
65 | if (NULL == host_start) | ||
66 | { | ||
67 | GNUNET_free (src); | ||
68 | GNUNET_free (sp); | ||
69 | return NULL; | ||
70 | } | ||
71 | port_start = strstr (host_start, ":"); | ||
72 | if (NULL == port_start) | ||
73 | { | ||
74 | path_start = strstr (host_start, "/"); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | port_start[0] = '\0'; | ||
79 | port_start ++; | ||
80 | sp->host = GNUNET_strdup (host_start); | ||
81 | path_start = strstr (port_start, "/"); | ||
82 | } | ||
83 | |||
84 | if (NULL == path_start) | ||
85 | { | ||
86 | if (NULL != port_start) | ||
87 | sp->port = GNUNET_strdup (port_start); | ||
88 | sp->path = NULL; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | if (NULL != port_start) | ||
93 | { | ||
94 | path_start[0] = '\0'; | ||
95 | sp->port = GNUNET_strdup (port_start); | ||
96 | path_start[0] = '/'; | ||
97 | } | ||
98 | sp->path = GNUNET_strdup(path_start); | ||
99 | } | ||
100 | GNUNET_free (src); | ||
101 | fprintf (stderr, "protocoll: `%s', host `%s' port `%s' path `%s'\n", sp->protocoll, sp->host, sp->port, sp->path); | ||
102 | return sp; | ||
103 | } | ||
104 | |||
31 | /** | 105 | /** |
32 | * Convert the transports address to a nice, human-readable | 106 | * Convert the transports address to a nice, human-readable |
33 | * format. | 107 | * format. |
@@ -59,6 +133,7 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type, | |||
59 | asc (asc_cls, NULL); | 133 | asc (asc_cls, NULL); |
60 | return; | 134 | return; |
61 | } | 135 | } |
136 | http_split_address (addr); | ||
62 | asc (asc_cls, saddr); | 137 | asc (asc_cls, saddr); |
63 | asc (asc_cls, NULL); | 138 | asc (asc_cls, NULL); |
64 | } | 139 | } |
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index 85793ce7f..0cc6de5ee 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h | |||
@@ -26,7 +26,7 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_common.h" | 28 | #include "gnunet_common.h" |
29 | 29 | #include "gnunet_transport_plugin.h" | |
30 | /** | 30 | /** |
31 | * Timeout values for testing | 31 | * Timeout values for testing |
32 | */ | 32 | */ |
@@ -50,6 +50,11 @@ | |||
50 | 50 | ||
51 | #endif | 51 | #endif |
52 | 52 | ||
53 | struct SplittedHTTPAddress; | ||
54 | |||
55 | struct SplittedHTTPAddress * | ||
56 | http_split_address (const char * addr); | ||
57 | |||
53 | /** | 58 | /** |
54 | * Convert the transports address to a nice, human-readable | 59 | * Convert the transports address to a nice, human-readable |
55 | * format. | 60 | * format. |