aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_http_common.c18
-rw-r--r--src/transport/test_http_common.c63
2 files changed, 72 insertions, 9 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 817338426..13ac3d043 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -47,7 +47,6 @@ http_split_address (const char * addr)
47 char *v6_end = NULL; 47 char *v6_end = NULL;
48 char *port_start = NULL; 48 char *port_start = NULL;
49 char *path_start = NULL; 49 char *path_start = NULL;
50
51 protocol_start = src; 50 protocol_start = src;
52 sp = GNUNET_malloc (sizeof (struct SplittedHTTPAddress)); 51 sp = GNUNET_malloc (sizeof (struct SplittedHTTPAddress));
53 52
@@ -103,6 +102,14 @@ http_split_address (const char * addr)
103 port_start[0] = '\0'; 102 port_start[0] = '\0';
104 port_start ++; 103 port_start ++;
105 sp->port = atoi (port_start); 104 sp->port = atoi (port_start);
105 if ((0 == sp->port) || (65535 < sp->port))
106 {
107 GNUNET_free (src);
108 GNUNET_free (sp->protocol);
109 GNUNET_free (sp->path);
110 GNUNET_free (sp);
111 return NULL;
112 }
106 } 113 }
107 else 114 else
108 { 115 {
@@ -119,6 +126,14 @@ http_split_address (const char * addr)
119 port_start[0] = '\0'; 126 port_start[0] = '\0';
120 port_start ++; 127 port_start ++;
121 sp->port = atoi (port_start); 128 sp->port = atoi (port_start);
129 if ((0 == sp->port) || (65535 < sp->port))
130 {
131 GNUNET_free (src);
132 GNUNET_free (sp->protocol);
133 GNUNET_free (sp->path);
134 GNUNET_free (sp);
135 return NULL;
136 }
122 } 137 }
123 } 138 }
124 else 139 else
@@ -150,7 +165,6 @@ http_split_address (const char * addr)
150 return NULL; 165 return NULL;
151 } 166 }
152 GNUNET_free (src); 167 GNUNET_free (src);
153 //fprintf (stderr, "addr: `%s' protocol: `%s', host `%s' port `%u' path `%s'\n", addr, sp->protocol, sp->host, sp->port, sp->path);
154 return sp; 168 return sp;
155} 169}
156 170
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c
index d7a203336..c97ae1745 100644
--- a/src/transport/test_http_common.c
+++ b/src/transport/test_http_common.c
@@ -112,7 +112,7 @@ check (struct SplittedHTTPAddress *addr,
112 return GNUNET_OK; 112 return GNUNET_OK;
113} 113}
114 114
115void 115int
116check_pass (char *src, 116check_pass (char *src,
117 char * protocol, 117 char * protocol,
118 char * host, 118 char * host,
@@ -124,33 +124,55 @@ check_pass (char *src,
124 if (NULL == spa) 124 if (NULL == spa)
125 { 125 {
126 GNUNET_break (0); 126 GNUNET_break (0);
127 return GNUNET_SYSERR;
127 } 128 }
128 else 129 else
129 { 130 {
130 if (GNUNET_OK != check(spa, protocol, host, port, path)) 131 if (GNUNET_OK != check(spa, protocol, host, port, path))
131 { 132 {
133 clean (spa);
132 GNUNET_break (0); 134 GNUNET_break (0);
135 return GNUNET_SYSERR;
133 } 136 }
134 clean (spa); 137 clean (spa);
135 } 138 }
139 return GNUNET_OK;
140}
141
142int
143check_fail (char *src)
144{
145 struct SplittedHTTPAddress * spa;
146 spa = http_split_address (src);
147 if (NULL != spa)
148 {
149 GNUNET_break (0);
150 clean (spa);
151 return GNUNET_SYSERR;
152 }
153 return GNUNET_OK;
136} 154}
137 155
156
138void 157void
139test_hostname () 158test_pass_hostname ()
140{ 159{
141 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, ""); 160 check_pass("http://test.local", "http", "test.local", HTTP_DEFAULT_PORT, "");
142 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/"); 161 check_pass("http://test.local/", "http", "test.local", HTTP_DEFAULT_PORT, "/");
143 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path"); 162 check_pass("http://test.local/path", "http", "test.local", HTTP_DEFAULT_PORT, "/path");
144 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/"); 163 check_pass("http://test.local/path/", "http", "test.local", HTTP_DEFAULT_PORT, "/path/");
164 check_pass("http://test.local/path/more", "http", "test.local", HTTP_DEFAULT_PORT, "/path/more");
145 check_pass("http://test.local:81", "http", "test.local", 81, ""); 165 check_pass("http://test.local:81", "http", "test.local", 81, "");
146 check_pass("http://test.local:81/", "http", "test.local", 81, "/"); 166 check_pass("http://test.local:81/", "http", "test.local", 81, "/");
147 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); 167 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path");
148 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); 168 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/");
169 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more");
149 170
150} 171}
151 172
173
152void 174void
153test_ipv4 () 175test_pass_ipv4 ()
154{ 176{
155 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); 177 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
156 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/"); 178 check_pass("http://127.0.0.1/", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "/");
@@ -160,10 +182,11 @@ test_ipv4 ()
160 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/"); 182 check_pass("http://127.0.0.1:81/", "http", "127.0.0.1", 81, "/");
161 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path"); 183 check_pass("http://127.0.0.1:81/path", "http", "127.0.0.1", 81, "/path");
162 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/"); 184 check_pass("http://127.0.0.1:81/path/", "http", "127.0.0.1", 81, "/path/");
185 check_pass("http://127.0.0.1:81/path/more", "http", "127.0.0.1", 81, "/path/more");
163} 186}
164 187
165void 188void
166test_ipv6 () 189test_fail_ipv6 ()
167{ 190{
168 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); 191 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
169 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); 192 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
@@ -173,9 +196,34 @@ test_ipv6 ()
173 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/"); 196 check_pass("http://[::1]:81/", "http", "[::1]", 81, "/");
174 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path"); 197 check_pass("http://[::1]:81/path", "http", "[::1]", 81, "/path");
175 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/"); 198 check_pass("http://[::1]:81/path/", "http", "[::1]", 81, "/path/");
199 check_pass("http://[::1]:81/path/more", "http", "[::1]", 81, "/path/more");
176} 200}
177 201
178 202
203void
204test_fail ()
205{
206 if (GNUNET_SYSERR == check_fail (""))
207 GNUNET_break (0);
208 if (GNUNET_SYSERR == check_fail ("http"))
209 GNUNET_break (0);
210 if (GNUNET_SYSERR == check_fail ("://"))
211 GNUNET_break (0);
212 if (GNUNET_SYSERR == check_fail ("http://"))
213 GNUNET_break (0);
214 if (GNUNET_SYSERR == check_fail ("//localhost"))
215 GNUNET_break (0);
216 if (GNUNET_SYSERR == check_fail ("//:80"))
217 GNUNET_break (0);
218 if (GNUNET_SYSERR == check_fail ("//:80/"))
219 GNUNET_break (0);
220 if (GNUNET_SYSERR == check_fail ("//:80:"))
221 GNUNET_break (0);
222 if (GNUNET_SYSERR == check_fail ("http://localhost:a/"))
223 GNUNET_break (0);
224 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/"))
225 GNUNET_break (0);
226}
179 227
180int 228int
181main (int argc, char *argv[]) 229main (int argc, char *argv[])
@@ -205,9 +253,10 @@ main (int argc, char *argv[])
205 GNUNET_break (0); 253 GNUNET_break (0);
206 } 254 }
207 255
208 test_hostname (); 256 test_pass_hostname ();
209 test_ipv4 (); 257 test_pass_ipv4 ();
210 test_ipv6 (); 258 test_fail_ipv6 ();
259 test_fail ();
211 260
212 return ret; 261 return ret;
213} 262}