aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r--src/transport/plugin_transport_http_common.c108
1 files changed, 79 insertions, 29 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 0c9bfffc8..5c6d19791 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -27,13 +27,14 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_transport_plugin.h" 29#include "gnunet_transport_plugin.h"
30#include "plugin_transport_http_common.h"
30 31
31struct SplittedHTTPAddress 32struct SplittedHTTPAddress
32{ 33{
33 char *protocoll; 34 char *protocol;
34 char *host; 35 char *host;
35 char *port;
36 char *path; 36 char *path;
37 int port;
37}; 38};
38 39
39struct SplittedHTTPAddress * 40struct SplittedHTTPAddress *
@@ -41,14 +42,17 @@ http_split_address (const char * addr)
41{ 42{
42 struct SplittedHTTPAddress *sp; 43 struct SplittedHTTPAddress *sp;
43 char *src = GNUNET_strdup (addr); 44 char *src = GNUNET_strdup (addr);
44 char *protocoll_start = NULL; 45 char *protocol_start = NULL;
45 char *host_start = NULL; 46 char *host_start = NULL;
47 char *v6_end = NULL;
46 char *port_start = NULL; 48 char *port_start = NULL;
47 char *path_start = NULL; 49 char *path_start = NULL;
48 50
49 protocoll_start = src; 51 protocol_start = src;
50 sp = GNUNET_malloc (sizeof (struct SplittedHTTPAddress)); 52 sp = GNUNET_malloc (sizeof (struct SplittedHTTPAddress));
51 53
54 /* Address string consists of protocol://host[:port]path*/
55
52 host_start = strstr (src, "://"); 56 host_start = strstr (src, "://");
53 if (NULL == host_start) 57 if (NULL == host_start)
54 { 58 {
@@ -58,47 +62,94 @@ http_split_address (const char * addr)
58 } 62 }
59 63
60 host_start[0] = '\0'; 64 host_start[0] = '\0';
61 sp->protocoll = GNUNET_strdup (protocoll_start); 65 sp->protocol = GNUNET_strdup (protocol_start);
62 66
63 host_start += strlen ("://"); 67 host_start += strlen ("://");
64 if (strlen (host_start) == 0) 68 if (strlen (host_start) == 0)
65 if (NULL == host_start)
66 { 69 {
67 GNUNET_free (src); 70 GNUNET_free (src);
71 GNUNET_free (sp->protocol);
68 GNUNET_free (sp); 72 GNUNET_free (sp);
69 return NULL; 73 return NULL;
70 } 74 }
71 port_start = strstr (host_start, ":"); 75
72 if (NULL == port_start) 76 /* Find path start */
77 path_start = strchr (host_start, '/');
78 if (NULL != path_start)
73 { 79 {
74 path_start = strstr (host_start, "/"); 80 sp->path = GNUNET_strdup (path_start);
81 path_start[0] = '\0';
75 } 82 }
76 else 83 else
84 sp->path = GNUNET_strdup ("");
85
86 if (strlen(host_start) < 1)
77 { 87 {
78 port_start[0] = '\0'; 88 GNUNET_free (src);
79 port_start ++; 89 GNUNET_free (sp->protocol);
80 sp->host = GNUNET_strdup (host_start); 90 GNUNET_free (sp->path);
81 path_start = strstr (port_start, "/"); 91 GNUNET_free (sp);
92 return NULL;
82 } 93 }
83 94
84 if (NULL == path_start) 95 if (NULL != (port_start = strrchr (host_start, ':')))
85 {
86 if (NULL != port_start)
87 sp->port = GNUNET_strdup (port_start);
88 sp->path = NULL;
89 }
90 else
91 { 96 {
92 if (NULL != port_start) 97 /* *We COULD have a port, but also an IPv6 address! */
98 if (NULL != (v6_end = strchr(host_start, ']')))
99 {
100 if (v6_end < port_start)
101 {
102 /* IPv6 address + port */
103 port_start[0] = '\0';
104 port_start ++;
105 sp->port = atoi (port_start);
106 }
107 else
108 {
109 /* IPv6 address + no port */
110 if (0 == strcmp(sp->protocol, "https"))
111 sp->port = HTTPS_DEFAULT_PORT;
112 else if (0 == strcmp(sp->protocol, "http"))
113 sp->port = HTTP_DEFAULT_PORT;
114 }
115 }
116 else
93 { 117 {
94 path_start[0] = '\0'; 118 /* No IPv6 address */
95 sp->port = GNUNET_strdup (port_start); 119 port_start[0] = '\0';
96 path_start[0] = '/'; 120 port_start ++;
121 sp->port = atoi (port_start);
97 } 122 }
98 sp->path = GNUNET_strdup(path_start);
99 } 123 }
100 GNUNET_free (src); 124 else
101 fprintf (stderr, "protocoll: `%s', host `%s' port `%s' path `%s'\n", sp->protocoll, sp->host, sp->port, sp->path); 125 {
126 /* No ':' as port separator, default port for protocol */
127 if (0 == strcmp(sp->protocol, "https"))
128 sp->port = HTTPS_DEFAULT_PORT;
129 else if (0 == strcmp(sp->protocol, "http"))
130 sp->port = HTTP_DEFAULT_PORT;
131 else
132 {
133 GNUNET_break (0);
134 GNUNET_free (src);
135 GNUNET_free (sp->protocol);
136 GNUNET_free (sp->path);
137 GNUNET_free (sp);
138 return NULL;
139 }
140 }
141 if (strlen (host_start) > 0)
142 sp->host = GNUNET_strdup (host_start);
143 else
144 {
145 GNUNET_break (0);
146 GNUNET_free (src);
147 GNUNET_free (sp->protocol);
148 GNUNET_free (sp->path);
149 GNUNET_free (sp);
150 return NULL;
151 }
152 //fprintf (stderr, "addr: `%s' protocol: `%s', host `%s' port `%u' path `%s'\n", addr, sp->protocol, sp->host, sp->port, sp->path);
102 return sp; 153 return sp;
103} 154}
104 155
@@ -133,7 +184,6 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type,
133 asc (asc_cls, NULL); 184 asc (asc_cls, NULL);
134 return; 185 return;
135 } 186 }
136 http_split_address (addr);
137 asc (asc_cls, saddr); 187 asc (asc_cls, saddr);
138 asc (asc_cls, NULL); 188 asc (asc_cls, NULL);
139} 189}
@@ -314,7 +364,7 @@ http_common_address_get_size (const void *addr)
314 * @param addrlen2 address 2 length 364 * @param addrlen2 address 2 length
315 * @return GNUNET_YES if equal, GNUNET_NO if not, GNUNET_SYSERR on error 365 * @return GNUNET_YES if equal, GNUNET_NO if not, GNUNET_SYSERR on error
316 */ 366 */
317int 367size_t
318http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2) 368http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2)
319{ 369{
320 const char *a1 = (const char *) addr1; 370 const char *a1 = (const char *) addr1;