aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_common.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-06-27 15:02:11 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-06-27 15:02:11 +0000
commite7e99d8571ea6f90626a41fdea321e19d6426578 (patch)
treede68652672d48408991509be4cb15613e8b0e1b9 /src/transport/plugin_transport_http_common.c
parent67ba272f86ae7aed754aeb94ba2aa19477a4e9e4 (diff)
downloadgnunet-e7e99d8571ea6f90626a41fdea321e19d6426578.tar.gz
gnunet-e7e99d8571ea6f90626a41fdea321e19d6426578.zip
Implementing bug 0002910
- extended plugin to contain option field in addresses Implementing bug 0002677 - adding ssl verification for external hostname having - the server send the HTTP_OPTIONS_VERIFY_CERTIFICATE option - client use this option to enable ssl verification
Diffstat (limited to 'src/transport/plugin_transport_http_common.c')
-rw-r--r--src/transport/plugin_transport_http_common.c199
1 files changed, 162 insertions, 37 deletions
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index bf983302e..5830ab63c 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -202,19 +202,49 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type,
202 GNUNET_TRANSPORT_AddressStringCallback 202 GNUNET_TRANSPORT_AddressStringCallback
203 asc, void *asc_cls) 203 asc, void *asc_cls)
204{ 204{
205 const char *saddr = (const char *) addr; 205 const struct HttpAddress *address = addr;
206 206
207 if ( (NULL == saddr) || 207 if (NULL == http_common_plugin_address_to_string (NULL, (char *) type, address, addrlen))
208 (0 >= addrlen) ||
209 ('\0' != saddr[addrlen-1]) )
210 { 208 {
211 asc (asc_cls, NULL); 209 asc (asc_cls, NULL);
212 return; 210 return;
213 } 211 }
214 asc (asc_cls, saddr); 212 asc (asc_cls, http_common_plugin_address_to_string (NULL, (char *) type, address, addrlen));
215 asc (asc_cls, NULL); 213 asc (asc_cls, NULL);
216} 214}
217 215
216const char *
217http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen)
218{
219 static char rbuf[1024];
220 const struct HttpAddress *address = addr;
221 const char * addr_str;
222
223
224
225 if (NULL == addr)
226 {
227 GNUNET_break (0);
228 return NULL;
229 }
230 if (0 >= addrlen)
231 {
232 GNUNET_break (0);
233 return NULL;
234 }
235 if (addrlen != http_common_address_get_size (address))
236 {
237 GNUNET_break (0);
238 return NULL;
239 }
240 addr_str = (char *) &address[1];
241
242 if (addr_str[ntohl(address->urlen) -1] != '\0')
243 return NULL;
244
245 memcpy (rbuf, &address[1], ntohl(address->urlen));
246 return rbuf;
247}
218 248
219/** 249/**
220 * Function called for a quick conversion of the binary address to 250 * Function called for a quick conversion of the binary address to
@@ -228,16 +258,35 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type,
228 * @return string representing the same address 258 * @return string representing the same address
229 */ 259 */
230const char * 260const char *
231http_common_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 261http_common_plugin_address_to_string (void *cls, char *plugin, const void *addr, size_t addrlen)
232{ 262{
233 const char *saddr = (const char *) addr; 263 static char rbuf[1024];
234 if (NULL == saddr) 264 const struct HttpAddress *address = addr;
265 const char * addr_str;
266 char *res;
267
268
269 if (NULL == addr)
235 return NULL; 270 return NULL;
236 if (0 >= addrlen) 271 if (0 >= addrlen)
237 return NULL; 272 return NULL;
238 if (saddr[addrlen-1] != '\0') 273 if (addrlen != http_common_address_get_size (address))
274 return NULL;
275 addr_str = (char *) &address[1];
276
277 if (addr_str[ntohl(address->urlen) -1] != '\0')
239 return NULL; 278 return NULL;
240 return saddr; 279
280 GNUNET_asprintf (&res, "%s.%u.%s", plugin, address->options, &address[1]);
281 if (strlen(res) + 1 < 500)
282 {
283 memcpy (rbuf, res, strlen(res) + 1);
284 GNUNET_free (res);
285 return rbuf;
286 }
287 GNUNET_break (0);
288 GNUNET_free (res);
289 return NULL;
241} 290}
242 291
243/** 292/**
@@ -259,15 +308,63 @@ http_common_plugin_string_to_address (void *cls,
259 void **buf, 308 void **buf,
260 size_t *added) 309 size_t *added)
261{ 310{
262 if (NULL == addr) 311 struct HttpAddress *a;
263 return GNUNET_SYSERR; 312 char *address;
264 if (0 >= addrlen) 313 char *plugin;
314 char *optionstr;
315 size_t urlen;
316 uint32_t options;
317
318 /* Format protocol.options.address:port */
319 address = NULL;
320 plugin = NULL;
321 optionstr = NULL;
322 options = 0;
323 if ((NULL == addr) || (addrlen == 0))
324 {
325 GNUNET_break (0);
265 return GNUNET_SYSERR; 326 return GNUNET_SYSERR;
266 if (addr[addrlen-1] != '\0') 327 }
328 if ('\0' != addr[addrlen - 1])
329 {
330 GNUNET_break (0);
267 return GNUNET_SYSERR; 331 return GNUNET_SYSERR;
268 332 }
269 (*buf) = strdup (addr); 333 if (strlen (addr) != addrlen - 1)
270 (*added) = strlen (addr) + 1; 334 {
335 GNUNET_break (0);
336 return GNUNET_SYSERR;
337 }
338 plugin = GNUNET_strdup (addr);
339 optionstr = strchr (plugin, '.');
340 if (NULL == optionstr)
341 {
342 GNUNET_break (0);
343 GNUNET_free (plugin);
344 return GNUNET_SYSERR;
345 }
346 optionstr[0] = '\0';
347 optionstr ++;
348 options = atol (optionstr);
349 address = strchr (optionstr, '.');
350 if (NULL == address)
351 {
352 GNUNET_break (0);
353 GNUNET_free (plugin);
354 return GNUNET_SYSERR;
355 }
356 address[0] = '\0';
357 address ++;
358 urlen = strlen (address) + 1;
359
360 a = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
361 a->options = htonl(options);
362 a->urlen = htonl(urlen);
363 memcpy (&a[1], address, urlen);
364
365 (*buf) = a;
366 (*added) = sizeof (struct HttpAddress) + urlen;
367 GNUNET_free (plugin);
271 return GNUNET_OK; 368 return GNUNET_OK;
272} 369}
273 370
@@ -277,14 +374,25 @@ http_common_plugin_string_to_address (void *cls,
277 * @param protocol protocol 374 * @param protocol protocol
278 * @param addr sockaddr * address 375 * @param addr sockaddr * address
279 * @param addrlen length of the address 376 * @param addrlen length of the address
280 * @return the string 377 * @return the HttpAddress
281 */ 378 */
282char * 379struct HttpAddress *
283http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen) 380http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen)
284{ 381{
382 struct HttpAddress *address = NULL;
285 char *res; 383 char *res;
384 size_t len;
385
286 GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen)); 386 GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen));
287 return res; 387 len = strlen (res)+1;
388
389 address = GNUNET_malloc (sizeof (struct HttpAddress) + len);
390 address->options = htonl (HTTP_OPTIONS_NONE);
391 address->urlen = htonl (len);
392 memcpy (&address[1], res, len);
393 GNUNET_free (res);
394
395 return address;
288} 396}
289 397
290/** 398/**
@@ -301,28 +409,39 @@ http_common_address_from_socket (const char *protocol, const struct sockaddr *ad
301struct sockaddr * 409struct sockaddr *
302http_common_socket_from_address (const void *addr, size_t addrlen, int *res) 410http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
303{ 411{
412 const struct HttpAddress *ha;
304 struct SplittedHTTPAddress * spa; 413 struct SplittedHTTPAddress * spa;
305 struct sockaddr_storage *s; 414 struct sockaddr_storage *s;
306 (*res) = GNUNET_SYSERR; 415 (*res) = GNUNET_SYSERR;
307 char * to_conv; 416 char * to_conv;
308 417
418 ha = (const struct HttpAddress *) addr;
309 if (NULL == addr) 419 if (NULL == addr)
310 { 420 {
311 GNUNET_break (0); 421 GNUNET_break (0);
312 return NULL; 422 return NULL;
313 } 423 }
314 if (0 >= addrlen) 424 if (0 >= addrlen)
315 { 425 {
316 GNUNET_break (0); 426 GNUNET_break (0);
317 return NULL; 427 return NULL;
318 } 428 }
429 if (addrlen < sizeof (struct HttpAddress))
430 {
431 GNUNET_break (0);
432 return NULL;
433 }
434 if (addrlen < sizeof (struct HttpAddress) + ntohl (ha->urlen))
435 {
436 /* This is a legacy addresses */
437 return NULL;
438 }
319 if (((char *) addr)[addrlen-1] != '\0') 439 if (((char *) addr)[addrlen-1] != '\0')
320 { 440 {
321 GNUNET_break (0); 441 GNUNET_break (0);
322 return NULL; 442 return NULL;
323 } 443 }
324 444 spa = http_split_address ((const char *) &ha[1]);
325 spa = http_split_address (addr);
326 if (NULL == spa) 445 if (NULL == spa)
327 { 446 {
328 (*res) = GNUNET_SYSERR; 447 (*res) = GNUNET_SYSERR;
@@ -361,9 +480,9 @@ http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
361 * @return the size 480 * @return the size
362 */ 481 */
363size_t 482size_t
364http_common_address_get_size (const void *addr) 483http_common_address_get_size (const struct HttpAddress * addr)
365{ 484{
366 return strlen (addr) + 1; 485 return sizeof (struct HttpAddress) + ntohl(addr->urlen);
367} 486}
368 487
369/** 488/**
@@ -378,8 +497,12 @@ http_common_address_get_size (const void *addr)
378size_t 497size_t
379http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2) 498http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2, size_t addrlen2)
380{ 499{
500 const struct HttpAddress *ha1;
501 const struct HttpAddress *ha2;
381 const char *a1 = (const char *) addr1; 502 const char *a1 = (const char *) addr1;
382 const char *a2 = (const char *) addr2; 503 const char *a2 = (const char *) addr2;
504 ha1 = (const struct HttpAddress *) a1;
505 ha2 = (const struct HttpAddress *) a2;
383 506
384 if (NULL == a1) 507 if (NULL == a1)
385 return GNUNET_SYSERR; 508 return GNUNET_SYSERR;
@@ -397,8 +520,10 @@ http_common_cmp_addresses (const void *addr1, size_t addrlen1, const void *addr2
397 520
398 if (addrlen1 != addrlen2) 521 if (addrlen1 != addrlen2)
399 return GNUNET_NO; 522 return GNUNET_NO;
523 if (ha1->urlen != ha2->urlen)
524 return GNUNET_NO;
400 525
401 if (0 == strcmp (addr1, addr2)) 526 if (0 == strcmp ((const char *) &ha1[1],(const char *) &ha2[1]))
402 return GNUNET_YES; 527 return GNUNET_YES;
403 return GNUNET_NO; 528 return GNUNET_NO;
404} 529}