/*
This file is part of GNUnet
- (C) 2002-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2002-2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
}
}
+
struct SplittedHTTPAddress *
http_split_address (const char * addr)
{
/**
* Timeout task
*/
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+ struct GNUNET_SCHEDULER_Task * timeout_task;
/**
* Splitted Address
* to override the address again.
*
* @param plugin the name of the plugin
- * @param addr binary address
- * @param addrlen length of the address
- * @return string representing the same address
+ * @param saddr the splitted http address
+ * @param options address options
+ * @param dnsresult dns name to include in address
+ * @return string representing the same address or NULL on error
*/
static const char *
http_common_plugin_dnsresult_to_address (const char *plugin,
- const struct SplittedHTTPAddress *saddr, uint32_t options,
+ const struct SplittedHTTPAddress *saddr,
+ uint32_t options,
const char *dnsresult)
{
static char rbuf[1024];
return NULL ;
}
+
static void
http_common_dns_reverse_lookup_cb (void *cls, const char *hostname)
{
}
}
+
static int
http_common_dns_reverse_lookup (const struct sockaddr *sockaddr,
- socklen_t sockaddr_len, const char *type, struct SplittedHTTPAddress *saddr,
- uint32_t options,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
+ socklen_t sockaddr_len,
+ const char *type,
+ struct SplittedHTTPAddress *saddr,
+ uint32_t options,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback asc,
+ void *asc_cls)
{
struct PrettyPrinterContext *ppc;
- ppc = GNUNET_new (struct PrettyPrinterContext);
- ppc->sucess = GNUNET_NO;
+ ppc = GNUNET_new (struct PrettyPrinterContext);
ppc->saddr = saddr;
ppc->asc = asc;
ppc->asc_cls = asc_cls;
ppc->plugin = GNUNET_strdup (type);
ppc->options = options;
-
- ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr, sockaddr_len,
- GNUNET_YES, timeout, &http_common_dns_reverse_lookup_cb, ppc);
+ ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr,
+ sockaddr_len,
+ GNUNET_YES,
+ timeout,
+ &http_common_dns_reverse_lookup_cb,
+ ppc);
if (NULL == ppc->resolver_handle)
{
GNUNET_free(ppc->plugin);
GNUNET_free(ppc);
return GNUNET_SYSERR;
}
-
- GNUNET_CONTAINER_DLL_insert(dll_ppc_head, dll_ppc_tail, ppc);
+ GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
+ dll_ppc_tail,
+ ppc);
return GNUNET_OK;
}
+
static void
-http_common_dns_ip_lookup_cb (void *cls, const struct sockaddr *addr,
- socklen_t addrlen)
+http_common_dns_ip_lookup_cb (void *cls,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct PrettyPrinterContext *ppc = cls;
}
}
+
static int
-http_common_dns_ip_lookup (const char *name, const char *type,
- struct SplittedHTTPAddress *saddr,
- uint32_t options,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
+http_common_dns_ip_lookup (const char *name,
+ const char *type,
+ struct SplittedHTTPAddress *saddr,
+ uint32_t options,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
{
struct PrettyPrinterContext *ppc;
- ppc = GNUNET_new (struct PrettyPrinterContext);
+ ppc = GNUNET_new (struct PrettyPrinterContext);
ppc->sucess = GNUNET_NO;
ppc->saddr = saddr;
ppc->asc = asc;
ppc->asc_cls = asc_cls;
ppc->plugin = GNUNET_strdup (type);
ppc->options = options;
-
- ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name, AF_UNSPEC, timeout,
- &http_common_dns_ip_lookup_cb, ppc);
+ ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name,
+ AF_UNSPEC,
+ timeout,
+ &http_common_dns_ip_lookup_cb,
+ ppc);
if (NULL == ppc->resolver_handle)
{
GNUNET_free(ppc->plugin);
GNUNET_free(ppc);
return GNUNET_SYSERR;
}
-
- GNUNET_CONTAINER_DLL_insert(dll_ppc_head, dll_ppc_tail, ppc);
+ GNUNET_CONTAINER_DLL_insert (dll_ppc_head,
+ dll_ppc_tail,
+ ppc);
return GNUNET_OK;
}
+
/**
* Convert the transports address to a nice, human-readable
* format.
*/
void
http_common_plugin_address_pretty_printer (void *cls, const char *type,
- const void *addr, size_t addrlen, int numeric,
- struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
+ const void *addr,
+ size_t addrlen,
+ int numeric,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_TRANSPORT_AddressStringCallback asc,
+ void *asc_cls)
{
const struct HttpAddress *address = addr;
struct SplittedHTTPAddress *saddr;
saddr = NULL;
sock_addr = NULL;
- if ((addrlen < sizeof(struct HttpAddress))
- || (addrlen != http_common_address_get_size (address)))
+ if ( (addrlen < sizeof(struct HttpAddress)) ||
+ (addrlen != http_common_address_get_size (address)) )
{
GNUNET_break(0);
goto handle_error;
if (GNUNET_SYSERR == res)
{
/* Malformed address */
- GNUNET_break(0);
+ GNUNET_break (0);
goto handle_error;
}
else if (GNUNET_NO == res)
else
{
/* Must not happen */
- GNUNET_break(0);
+ GNUNET_break (0);
goto handle_error;
}
- if ((GNUNET_YES == numeric) && (GNUNET_YES == have_ip))
+ if ( (GNUNET_YES == numeric) &&
+ (GNUNET_YES == have_ip) )
{
/* No lookup required */
ret = http_common_plugin_address_to_string (type, address, addrlen);
asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
asc (asc_cls, NULL, GNUNET_OK);
http_clean_splitted (saddr);
- GNUNET_free_non_null(sock_addr);
+ GNUNET_free_non_null (sock_addr);
return;
}
- else if ((GNUNET_YES == numeric) && (GNUNET_NO == have_ip))
+ if ( (GNUNET_YES == numeric) &&
+ (GNUNET_NO == have_ip) )
{
/* Forward lookup */
- if (GNUNET_SYSERR
- == http_common_dns_ip_lookup (saddr->host, type, saddr, address->options, timeout, asc,
- asc_cls))
+ if (GNUNET_SYSERR ==
+ http_common_dns_ip_lookup (saddr->host, type, saddr,
+ address->options, timeout,
+ asc, asc_cls))
{
GNUNET_break(0);
goto handle_error;
}
/* Wait for resolver callback */
+ GNUNET_free_non_null (sock_addr);
return;
}
- else if ((GNUNET_NO == numeric) && (GNUNET_YES == have_ip))
+ if ( (GNUNET_NO == numeric) &&
+ (GNUNET_YES == have_ip) )
{
/* Reverse lookup */
- if (GNUNET_SYSERR
- == http_common_dns_reverse_lookup (sock_addr,
- (AF_INET == sock_addr->sa_family) ?
- sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), type,
- saddr, address->options, timeout, asc, asc_cls))
+ if (GNUNET_SYSERR ==
+ http_common_dns_reverse_lookup (sock_addr,
+ (AF_INET == sock_addr->sa_family)
+ ? sizeof(struct sockaddr_in)
+ : sizeof(struct sockaddr_in6),
+ type,
+ saddr,
+ address->options, timeout,
+ asc, asc_cls))
{
GNUNET_break(0);
goto handle_error;
}
/* Wait for resolver callback */
+ GNUNET_free_non_null (sock_addr);
return;
}
- else if ((GNUNET_NO == numeric) && (GNUNET_NO == have_ip))
+ if ( (GNUNET_NO == numeric) &&
+ (GNUNET_NO == have_ip) )
{
/* No lookup required */
ret = http_common_plugin_address_to_string (type, address, addrlen);
asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
asc (asc_cls, NULL, GNUNET_OK);
- GNUNET_free_non_null(sock_addr);
+ GNUNET_free_non_null (sock_addr);
http_clean_splitted (saddr);
return;
}
- else
- {
- /* Error */
- goto handle_error;
- }
- return;
+ /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */
+ GNUNET_break (0);
+ goto handle_error;
- handle_error:
- /* Error */
+ handle_error:
+ /* Report error */
asc (asc_cls, NULL, GNUNET_SYSERR);
asc (asc_cls, NULL, GNUNET_OK);
- GNUNET_free_non_null(sock_addr);
+ GNUNET_free_non_null (sock_addr);
if (NULL != saddr)
http_clean_splitted (saddr);
- return;
-
}
+
/**
* FIXME.
*/
const char *
-http_common_plugin_address_to_url (void *cls, const void *addr, size_t addrlen)
+http_common_plugin_address_to_url (void *cls,
+ const void *addr,
+ size_t addrlen)
{
static char rbuf[1024];
const struct HttpAddress *address = addr;
if (NULL == addr)
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
if (0 >= addrlen)
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
if (addrlen != http_common_address_get_size (address))
{
GNUNET_break(0);
- return NULL ;
+ return NULL;
}
addr_str = (char *) &address[1];
-
if (addr_str[ntohl (address->urlen) - 1] != '\0')
- return NULL ;
+ return NULL;
- memcpy (rbuf, &address[1], ntohl (address->urlen));
+ memcpy (rbuf,
+ &address[1],
+ ntohl (address->urlen));
return rbuf;
}
+
/**
* Function called for a quick conversion of the binary address to
* a numeric address. Note that the caller must not free the
* @return string representing the same address
*/
const char *
-http_common_plugin_address_to_string (const char *plugin, const void *addr,
- size_t addrlen)
+http_common_plugin_address_to_string (const char *plugin,
+ const void *addr,
+ size_t addrlen)
{
static char rbuf[1024];
const struct HttpAddress *address = addr;
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-http_common_plugin_string_to_address (void *cls, const char *addr,
- uint16_t addrlen, void **buf, size_t *added)
+http_common_plugin_string_to_address (void *cls,
+ const char *addr,
+ uint16_t addrlen,
+ void **buf,
+ size_t *added)
{
struct HttpAddress *a;
char *address;
return GNUNET_OK;
}
+
/**
* Create a HTTP address from a socketaddr
*
*/
struct HttpAddress *
http_common_address_from_socket (const char *protocol,
- const struct sockaddr *addr, socklen_t addrlen)
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct HttpAddress *address = NULL;
char *res;
size_t len;
- GNUNET_asprintf (&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen));
+ GNUNET_asprintf (&res,
+ "%s://%s",
+ protocol,
+ GNUNET_a2s (addr,
+ addrlen));
len = strlen (res) + 1;
address = GNUNET_malloc (sizeof (struct HttpAddress) + len);
address->options = htonl (HTTP_OPTIONS_NONE);
return address;
}
+
/**
* Create a socketaddr from a HTTP address
*
* @return the string
*/
struct sockaddr *
-http_common_socket_from_address (const void *addr, size_t addrlen, int *res)
+http_common_socket_from_address (const void *addr,
+ size_t addrlen,
+ int *res)
{
const struct HttpAddress *ha;
struct SplittedHTTPAddress * spa;
ha = (const struct HttpAddress *) addr;
if (NULL == addr)
{
- GNUNET_break(0);
- return NULL ;
+ GNUNET_break (0);
+ return NULL;
}
if (0 >= addrlen)
{
- GNUNET_break(0);
- return NULL ;
+ GNUNET_break (0);
+ return NULL;
}
if (addrlen < sizeof(struct HttpAddress))
{
- GNUNET_break(0);
- return NULL ;
+ GNUNET_break (0);
+ return NULL;
}
urlen = ntohl (ha->urlen);
if (sizeof(struct HttpAddress) + urlen != addrlen)
{
/* This is a legacy addresses */
- return NULL ;
+ return NULL;
}
if (addrlen < sizeof(struct HttpAddress) + urlen)
{
/* This is a legacy addresses */
- return NULL ;
+ return NULL;
}
if (((char *) addr)[addrlen - 1] != '\0')
{
- GNUNET_break(0);
- return NULL ;
+ GNUNET_break (0);
+ return NULL;
}
spa = http_split_address ((const char *) &ha[1]);
if (NULL == spa)
{
(*res) = GNUNET_SYSERR;
- return NULL ;
+ return NULL;
}
s = GNUNET_new (struct sockaddr_storage);
}
else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
{
-
- GNUNET_free(s);
+ GNUNET_free (s);
(*res) = GNUNET_SYSERR;
s = NULL;
}
(*res) = GNUNET_YES;
}
http_clean_splitted (spa);
- GNUNET_free(to_conv);
+ GNUNET_free (to_conv);
return (struct sockaddr *) s;
}
+
/**
* Get the length of an address
*
return sizeof(struct HttpAddress) + ntohl (addr->urlen);
}
+
/**
* Compare addr1 to addr2
*