diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-29 14:04:31 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-03-29 14:04:31 +0000 |
commit | 42e814b6e80486c223e62e2dcffe548fe51a2ef0 (patch) | |
tree | e71a9b2fa8e1cfda9e0e234278ae5f61dcefd859 /src/transport/plugin_transport_http.c | |
parent | a8c8084c4930be5ffd458f2fdda98f98b501e3df (diff) | |
download | gnunet-42e814b6e80486c223e62e2dcffe548fe51a2ef0.tar.gz gnunet-42e814b6e80486c223e62e2dcffe548fe51a2ef0.zip |
- implementented string to address
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 5bc7d4f01..ec89393cf 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -151,6 +151,9 @@ append_port (void *cls, const char *hostname) | |||
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | |||
155 | |||
156 | |||
154 | /** | 157 | /** |
155 | * Convert the transports address to a nice, human-readable | 158 | * Convert the transports address to a nice, human-readable |
156 | * format. | 159 | * format. |
@@ -318,6 +321,80 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
318 | return delay; | 321 | return delay; |
319 | } | 322 | } |
320 | 323 | ||
324 | |||
325 | /** | ||
326 | * Function called to convert a string address to | ||
327 | * a binary address. | ||
328 | * | ||
329 | * @param cls closure ('struct Plugin*') | ||
330 | * @param addr string address | ||
331 | * @param addrlen length of the address | ||
332 | * @param buf location to store the buffer | ||
333 | * If the function returns GNUNET_SYSERR, its contents are undefined. | ||
334 | * @param added length of created address | ||
335 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
336 | */ | ||
337 | int http_string_to_address (void *cls, | ||
338 | const char *addr, | ||
339 | uint16_t addrlen, | ||
340 | void **buf, | ||
341 | size_t *added) | ||
342 | { | ||
343 | #if !BUILD_HTTPS | ||
344 | char *protocol = "http"; | ||
345 | #else | ||
346 | char *protocol = "https"; | ||
347 | #endif | ||
348 | char *addr_str = NULL; | ||
349 | struct sockaddr_in addr_4; | ||
350 | struct sockaddr_in6 addr_6; | ||
351 | struct IPv4HttpAddress * http_4addr; | ||
352 | struct IPv6HttpAddress * http_6addr; | ||
353 | GNUNET_break (0); | ||
354 | if ((addr == NULL) || (addrlen == 0) || (buf == NULL)) | ||
355 | return GNUNET_SYSERR; | ||
356 | |||
357 | /* protocoll + "://" + ":" */ | ||
358 | if (addrlen <= strlen (protocol) + 4); | ||
359 | return GNUNET_SYSERR; | ||
360 | |||
361 | if (NULL == (addr = strstr(addr_str, "://"))) | ||
362 | return GNUNET_SYSERR; | ||
363 | |||
364 | addr_str = &addr_str[3]; | ||
365 | |||
366 | if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr, strlen(addr_str), &addr_4)) | ||
367 | { | ||
368 | http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress)); | ||
369 | http_4addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress)); | ||
370 | http_4addr->u4_port = addr_4.sin_port; | ||
371 | http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr; | ||
372 | |||
373 | (*buf) = http_4addr; | ||
374 | (*added) = sizeof (struct IPv4HttpAddress); | ||
375 | GNUNET_break (0); | ||
376 | return GNUNET_OK; | ||
377 | } | ||
378 | else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr, strlen(addr_str), &addr_6)) | ||
379 | { | ||
380 | http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress)); | ||
381 | http_6addr->u6_port = addr_6.sin6_port; | ||
382 | http_6addr->ipv6_addr = addr_6.sin6_addr; | ||
383 | |||
384 | (*buf) = http_6addr; | ||
385 | (*added) = sizeof (struct IPv6HttpAddress); | ||
386 | GNUNET_break (0); | ||
387 | return GNUNET_OK; | ||
388 | |||
389 | } | ||
390 | else | ||
391 | { | ||
392 | return GNUNET_SYSERR; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | |||
397 | |||
321 | /** | 398 | /** |
322 | * Function called for a quick conversion of the binary address to | 399 | * Function called for a quick conversion of the binary address to |
323 | * a numeric address. Note that the caller must not free the | 400 | * a numeric address. Note that the caller must not free the |
@@ -1384,7 +1461,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1384 | api->address_pretty_printer = &http_plugin_address_pretty_printer; | 1461 | api->address_pretty_printer = &http_plugin_address_pretty_printer; |
1385 | api->check_address = &http_plugin_address_suggested; | 1462 | api->check_address = &http_plugin_address_suggested; |
1386 | api->address_to_string = &http_plugin_address_to_string; | 1463 | api->address_to_string = &http_plugin_address_to_string; |
1387 | api->string_to_address = NULL; // FIXME! | 1464 | api->string_to_address = &http_string_to_address; |
1388 | api->get_session = &http_get_session; | 1465 | api->get_session = &http_get_session; |
1389 | api->send = &http_plugin_send; | 1466 | api->send = &http_plugin_send; |
1390 | 1467 | ||