Merge branch 'develop' into rbtree-dict

This commit is contained in:
Willem Toorop 2013-10-31 10:26:42 +01:00
commit 6adb49b8d5
4 changed files with 80 additions and 9 deletions

View File

@ -29,6 +29,11 @@
*/
#include <getdns/getdns.h>
#include "context.h"
#include "general.h"
#include "util-internal.h"
#include <string.h>
/* stuff to make it compile pedantically */
#define UNUSED_PARAM(x) ((void)(x))
@ -47,13 +52,27 @@ getdns_hostname(
getdns_callback_t callback
)
{
UNUSED_PARAM(context);
UNUSED_PARAM(address);
UNUSED_PARAM(extensions);
UNUSED_PARAM(userarg);
UNUSED_PARAM(transaction_id);
UNUSED_PARAM(callback);
struct getdns_bindata *address_data;
struct getdns_bindata *address_type;
uint16_t req_type;
char *name;
getdns_return_t retval;
if ((retval = getdns_dict_get_bindata(address, "address_data", &address_data)) != GETDNS_RETURN_GOOD)
return retval;
if ((retval = getdns_dict_get_bindata(address, "address_type", &address_type)) != GETDNS_RETURN_GOOD)
return retval;
if ((strncmp(GETDNS_STR_IPV4, (char *)address_type->data, strlen(GETDNS_STR_IPV4)) == 0) ||
(strncmp(GETDNS_STR_IPV6, (char *)address_type->data, strlen(GETDNS_STR_IPV6)) == 0))
req_type = GETDNS_RRTYPE_PTR;
else
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
if ((name = reverse_address((char *)address_data->data)) == 0)
return GETDNS_RETURN_GENERIC_ERROR;
return getdns_general(context, name, req_type, extensions,
userarg, transaction_id, callback);
return GETDNS_RETURN_GOOD;
} /* getdns_hostname */

View File

@ -102,8 +102,29 @@ getdns_hostname_sync(
uint32_t *response_length,
struct getdns_dict **response
)
{ UNUSED_PARAM(context); UNUSED_PARAM(address); UNUSED_PARAM(extensions);
UNUSED_PARAM(response_length); UNUSED_PARAM(response); return GETDNS_RETURN_GOOD; }
{
struct getdns_bindata *address_data;
struct getdns_bindata *address_type;
uint16_t req_type;
char *name;
getdns_return_t retval;
if ((retval = getdns_dict_get_bindata(address, "address_data", &address_data)) != GETDNS_RETURN_GOOD)
return retval;
if ((retval = getdns_dict_get_bindata(address, "address_type", &address_type)) != GETDNS_RETURN_GOOD)
return retval;
if ((strncmp(GETDNS_STR_IPV4, (char *)address_type->data, strlen(GETDNS_STR_IPV4)) == 0) ||
(strncmp(GETDNS_STR_IPV6, (char *)address_type->data, strlen(GETDNS_STR_IPV6)) == 0))
req_type = GETDNS_RRTYPE_PTR;
else
return GETDNS_RETURN_WRONG_TYPE_REQUESTED;
if ((name = reverse_address((char *)address_data)) == 0)
return GETDNS_RETURN_GENERIC_ERROR;
return getdns_general_sync(context, name, req_type, extensions,
response_length, response);
}
getdns_return_t
getdns_service_sync(

View File

@ -462,3 +462,33 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
return result;
}
/*
* temporary, cheesy function to reverse an IPv4 address
* and slap "in-addr.arpa" on it. Will replace
* XXX
*/
char *
reverse_address(char *addr_str)
{
char *res_buf;
char *src_start = 0;
char *dest_start;
/* magic number 9 = 3 '.' + 5 'in-addr.arpa' + null terminator */
if ((res_buf = (char *)malloc(strlen(addr_str)+17)) == (char *)0)
return 0;
dest_start=res_buf;
while ((src_start = strrchr(addr_str, '.')) != 0) {
strcpy(dest_start, src_start+1);
*src_start = 0;
dest_start = dest_start + strlen(dest_start);
*dest_start++ = '.';
}
strcpy(dest_start, addr_str);
dest_start = dest_start + strlen(dest_start);
strcpy(dest_start, ".in-addr.arpa");
return res_buf;
}

View File

@ -51,3 +51,4 @@ getdns_return_t getdns_dict_util_set_string(getdns_dict* dict, char* name,
/* get a string from a dict. result is valid as long as dict is valid */
getdns_return_t getdns_dict_util_get_string(getdns_dict* dict, char* name,
char** result);
char *reverse_address(char *addr_str);