Merge in develop latest

This commit is contained in:
Neel Goyal 2014-01-28 10:04:10 -05:00
commit eb43d9fb02
15 changed files with 914 additions and 7 deletions

View File

@ -31,6 +31,9 @@ uninstall:
doc:
cd doc && $(MAKE) $@
example:
cd src && $(MAKE) $@
test:
cd src && $(MAKE) $@

View File

@ -52,6 +52,12 @@ default: all
all: libgetdns.la
test:
cd test && $(MAKE) $@
example:
cd example && $(MAKE) $@
install: libgetdns.la
$(INSTALL) -m 755 -d $(DESTDIR)$(includedir)
$(INSTALL) -m 755 -d $(DESTDIR)$(includedir)/getdns

View File

@ -320,6 +320,11 @@ getdns_general(struct getdns_context *context,
return GETDNS_RETURN_INVALID_PARAMETER;
}
extcheck = validate_dname(name);
if (extcheck != GETDNS_RETURN_GOOD) {
return extcheck;
}
extcheck = validate_extensions(extensions);
if (extcheck != GETDNS_RETURN_GOOD)
return extcheck;

View File

@ -80,6 +80,11 @@ getdns_general_sync(struct getdns_context *context,
getdns_return_t response_status;
RETURN_IF_NULL(context, GETDNS_RETURN_BAD_CONTEXT);
RETURN_IF_NULL(response, GETDNS_RETURN_INVALID_PARAMETER);
RETURN_IF_NULL(name, GETDNS_RETURN_INVALID_PARAMETER);
response_status = validate_dname(name);
if (response_status != GETDNS_RETURN_GOOD) {
return response_status;
}
response_status = validate_extensions(extensions);
if (response_status == GETDNS_RETURN_GOOD) {
/* for each netreq we call ub_ctx_resolve */

View File

@ -16,6 +16,10 @@
#include "check_getdns_address_sync.h"
#include "check_getdns_list_get_length.h"
#include "check_getdns_list_get_data_type.h"
#include "check_getdns_list_get_dict.h"
#include "check_getdns_list_get_list.h"
#include "check_getdns_list_get_int.h"
#include "check_getdns_list_get_bindata.h"
#include "check_getdns_dict_get_names.h"
#include "check_getdns_dict_get_data_type.h"
#include "check_getdns_dict_get_dict.h"
@ -29,6 +33,7 @@
#include "check_getdns_dict_set_int.h"
#include "check_getdns_convert_ulabel_to_alabel.h"
#include "check_getdns_convert_alabel_to_ulabel.h"
#include "check_getdns_pretty_print_dict.h"
int
main (void)
@ -43,11 +48,16 @@ main (void)
Suite *getdns_context_destroy_suite(void);
Suite *getdns_cancel_callback_suite(void);
Suite *getdns_list_get_length_suite(void);
Suite *getdns_list_get_dict_suite(void);
Suite *getdns_list_get_list_suite(void);
Suite *getdns_list_get_int_suite(void);
Suite *getdns_list_get_data_type_suite(void);
Suite *getdns_list_get_bindata_suite(void);
Suite *getdns_dict_get_names_suite(void);
Suite *getdns_dict_get_data_type_suite(void);
Suite *getdns_dict_get_dict_suite(void);
Suite *getdns_dict_get_list_suite(void);
Suite *getdns_dict_get_dict_suite(void);
Suite *getdns_dict_get_bindata_suite(void);
Suite *getdns_dict_get_int_suite(void);
Suite *getdns_dict_destroy_suite(void);
@ -57,6 +67,7 @@ main (void)
Suite *getdns_dict_set_int_suite(void);
Suite *getdns_convert_ulabel_to_alabel_suite(void);
Suite *getdns_convert_alabel_to_ulabel_suite(void);
Suite *getdns_pretty_print_dict_suite(void);
sr = srunner_create(getdns_general_suite());
srunner_add_suite(sr, getdns_general_sync_suite());
@ -66,6 +77,10 @@ main (void)
srunner_add_suite(sr, getdns_cancel_callback_suite());
srunner_add_suite(sr, getdns_list_get_length_suite());
srunner_add_suite(sr, getdns_list_get_data_type_suite());
srunner_add_suite(sr, getdns_list_get_dict_suite());
srunner_add_suite(sr, getdns_list_get_list_suite());
srunner_add_suite(sr, getdns_list_get_int_suite());
srunner_add_suite(sr, getdns_list_get_bindata_suite());
srunner_add_suite(sr, getdns_dict_get_names_suite());
srunner_add_suite(sr, getdns_dict_get_data_type_suite());
srunner_add_suite(sr, getdns_dict_get_dict_suite());
@ -79,6 +94,7 @@ main (void)
srunner_add_suite(sr, getdns_dict_set_int_suite());
srunner_add_suite(sr, getdns_convert_ulabel_to_alabel_suite());
srunner_add_suite(sr, getdns_convert_alabel_to_ulabel_suite());
srunner_add_suite(sr, getdns_pretty_print_dict_suite());
srunner_set_log(sr, "check_getdns.log");
srunner_run_all(sr, CK_NORMAL);

View File

@ -17,8 +17,8 @@
*/
char *alabel = NULL;
ck_assert_msg(strcmp( getdns_convert_alabel_to_ulabel( alabel ), "nil" ) == 0,
"Was not expecting %s from getdns_convert_alabel_to_ulabel()", getdns_convert_alabel_to_ulabel( alabel ) );
ck_assert_msg( getdns_convert_alabel_to_ulabel( alabel ) == 0,
"Was not expecting %d from getdns_convert_alabel_to_ulabel()", getdns_convert_alabel_to_ulabel( alabel ) );
}
END_TEST

View File

@ -17,8 +17,9 @@
*/
char *ulabel = NULL;
ck_assert_msg(strcmp( getdns_convert_ulabel_to_alabel( ulabel ), "nil" ) == 0,
"Was not expecting %s from getdns_convert_ulabel_to_alabel()", getdns_convert_ulabel_to_alabel( ulabel ) );
ck_assert_msg(( getdns_convert_ulabel_to_alabel( ulabel ) == 0 ),
"Was not expecting %d from getdns_convert_ulabel_to_alabel()", getdns_convert_ulabel_to_alabel( ulabel ) );
}
END_TEST

View File

@ -0,0 +1,145 @@
#ifndef _check_getdns_list_get_bindata_h_
#define _check_getdns_list_get_bindata_h_
/*
**************************************************************************
* *
* T E S T S F O R G E T D N S _ L I S T _ G E T _ N A M E *
* *
**************************************************************************
*/
START_TEST (getdns_list_get_bindata_1)
{
/*
* list = NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
struct getdns_bindata *answer = NULL;
ASSERT_RC(getdns_list_get_bindata(list, index, &answer),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_names()");
}
END_TEST
START_TEST (getdns_list_get_bindata_2)
{
/* index is out of range
* create a list and and set index 0 to an int with a value of 100
* Call getdns_get_list() for index 1
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_int(list, index, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
index++;
ASSERT_RC(getdns_list_get_bindata(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_bindata()");
LIST_DESTROY(list);
}
END_TEST
START_TEST (getdns_list_get_bindata_3)
{
/* data type at index is not int
* create a list and set index 0 to an int with a value of 100
* Call getdns_list_get_bindata() for index 0
* expect: GETDNS_RETURN_WRONG_TYPE_REQUESTED
*/
struct getdns_list *list = NULL;
size_t index = 0;
struct getdns_bindata *answer = NULL;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_int(list, index, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_get_bindata(list, index, &answer),
GETDNS_RETURN_WRONG_TYPE_REQUESTED, "Return code from getdns_list_get_bindata()");
LIST_DESTROY(list);
}
END_TEST
START_TEST (getdns_list_get_bindata_4)
{
/* answer is NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
ASSERT_RC(getdns_list_get_bindata(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_bindata()");
}
END_TEST
START_TEST (getdns_list_get_bindata_5)
{
/*
* create a list
* Create some bindata containing "bindata" and add it to the list with name = "bindata"
* Set list value at index 0 via getdns_list_set_list() to the bindata
* Call getdns_list_get_list() for index 0
* expect: GETDNS_RETURN_GOOD
*/
struct getdns_list *list = NULL;
struct getdns_bindata bindata = { 8, (void *)"bindata" };
size_t index = 0;
struct getdns_bindata *answer = NULL;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_bindata(list, index, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
ASSERT_RC(getdns_list_get_bindata(list, index, &answer),
GETDNS_RETURN_GOOD, "Return code from getdns_list_get_bindata()");
ck_assert_msg(strcmp((char *)answer->data, (char *)bindata.data) == 0,
"Expected bindata data to be \"%s\", got: \"%s\"",
(char *)bindata.data, (char *)answer->data);
LIST_DESTROY(list);
}
END_TEST
Suite *
getdns_list_get_bindata_suite (void)
{
Suite *s = suite_create ("getdns_list_get_bindata()");
/* Negative test caseis */
TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_list_get_bindata_1);
tcase_add_test(tc_neg, getdns_list_get_bindata_2);
tcase_add_test(tc_neg, getdns_list_get_bindata_3);
tcase_add_test(tc_neg, getdns_list_get_bindata_4);
suite_add_tcase(s, tc_neg);
/* Positive test cases */
TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_list_get_bindata_5);
suite_add_tcase(s, tc_pos);
return s;
}
#endif

View File

@ -43,7 +43,7 @@
index++;
ASSERT_RC(getdns_list_get_data_type(list, index, &answer),
GETDNS_RETURN_NO_SUCH_LIST_ITEM, "Return code from getdns_list_get_data_type()");
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_data_type()");
LIST_DESTROY(list);
}
@ -84,7 +84,7 @@
LIST_CREATE(list);
ASSERT_RC(getdns_list_get_data_type(list, index, &answer),
GETDNS_RETURN_NO_SUCH_LIST_ITEM, "Return code from getdns_list_get_data_type()");
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_data_type()");
LIST_DESTROY(list);
}

View File

@ -0,0 +1,162 @@
#ifndef _check_getdns_list_get_dict_h_
#define _check_getdns_list_get_dict_h_
/*
**************************************************************************
* *
* T E S T S F O R G E T D N S _ L I S T _ G E T _ D I C T *
* *
**************************************************************************
*/
START_TEST (getdns_list_get_dict_1)
{
/*
* list = NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
struct getdns_dict *answer = NULL;
ASSERT_RC(getdns_list_get_dict(list, index, &answer),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_dict()");
}
END_TEST
START_TEST (getdns_list_get_dict_2)
{
/*
* index is out of range
* Create a list, add an dict to it, and then attempt
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
struct getdns_dict *answer = NULL;
LIST_CREATE(list);
DICT_CREATE(answer);
ASSERT_RC(getdns_list_set_int(list, index, 1), GETDNS_RETURN_GOOD,
"Return code from getdns_list_set_int()");
index++;
ASSERT_RC(getdns_list_get_dict(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_dict()");
LIST_DESTROY(list);
DICT_DESTROY(answer);
}
END_TEST
START_TEST (getdns_list_get_dict_3)
{
/*
* data type at index is not dict
* create a list
* expect: GETDNS_RETURN_WRONG_TYPE_REQUESTED
*/
struct getdns_list *list = NULL;
struct getdns_dict *answer = NULL;
size_t index = 0;
LIST_CREATE(list);
DICT_CREATE(answer);
ASSERT_RC(getdns_list_set_int(list, index, 10), GETDNS_RETURN_GOOD,
"Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_get_dict(list, index, &answer),
GETDNS_RETURN_WRONG_TYPE_REQUESTED, "Return code from getdns_list_get_dict()");
LIST_DESTROY(list);
DICT_DESTROY(answer);
}
END_TEST
START_TEST (getdns_list_get_dict_4)
{
/*
* answer = NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
ASSERT_RC(getdns_list_get_dict(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_dict()");
}
END_TEST
START_TEST (getdns_list_get_dict_5)
{
/*
* create a list
* Create a dict with one int (name = "ten", value = 10)
* Call getdns_dict_get_list() with name = "ten"
* expect: GETDNS_RETURN_WRONG_TYPE_REQUESTED
*/
struct getdns_dict *dict = NULL;
size_t index = 0;
struct getdns_dict *answer = NULL;
struct getdns_list *list = NULL;
uint32_t value;
LIST_CREATE(list);
DICT_CREATE(dict);
ASSERT_RC(getdns_dict_set_int(dict, "ten", 10),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_list_set_dict(list, index, dict), GETDNS_RETURN_GOOD,
"Return code from getdns_list_set_dict()");
ASSERT_RC(getdns_list_get_dict(list, index, &answer),
GETDNS_RETURN_GOOD, "Return code from getdns_list_get_dict()");
ASSERT_RC(getdns_dict_get_int(answer, "ten", &value),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_get_int()");
ck_assert_msg(value == 10, "Expected retrieved int == 10, got: %d",
value);
LIST_DESTROY(list);
DICT_DESTROY(dict);
}
END_TEST
Suite *
getdns_list_get_dict_suite (void)
{
Suite *s = suite_create ("getdns_list_get_dict()");
/* Negative test caseis */
TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_list_get_dict_1);
tcase_add_test(tc_neg, getdns_list_get_dict_2);
tcase_add_test(tc_neg, getdns_list_get_dict_3);
tcase_add_test(tc_neg, getdns_list_get_dict_4);
suite_add_tcase(s, tc_neg);
/* Positive test cases */
TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_list_get_dict_5);
suite_add_tcase(s, tc_pos);
return s;
}
#endif

View File

@ -0,0 +1,140 @@
#ifndef _check_getdns_list_get_int_h_
#define _check_getdns_list_get_int_h_
/*
**************************************************************************
* *
* T E S T S F O R G E T D N S _ L I S T _ G E T _ I N T *
* *
**************************************************************************
*/
START_TEST (getdns_list_get_int_1)
{
/*
* list = NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
uint32_t answer;
ASSERT_RC(getdns_list_get_int(list, index, &answer),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_int()");
}
END_TEST
START_TEST (getdns_list_get_int_2)
{
/* index is out of range
* create a list and set index 0 to an int with a value of 100
* Call getdns_get_list() for index 1
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_int(list, index, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
index++;
ASSERT_RC(getdns_list_get_list(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_list()");
LIST_DESTROY(list);
}
END_TEST
START_TEST (getdns_list_get_int_3)
{
/* data type at index is not int
* create a list
* Create some bindata containing "bindata" and add it to the list with name = "bindata"
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
struct getdns_bindata bindata = { 8, (void *)"bindata" };
size_t index = 0;
uint32_t answer;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_bindata(list, index, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
ASSERT_RC(getdns_list_get_int(list, index, &answer),
GETDNS_RETURN_WRONG_TYPE_REQUESTED, "Return code from getdns_list_get_list()");
LIST_DESTROY(list);
}
END_TEST
START_TEST (getdns_list_get_int_4)
{
/* answer is NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
ASSERT_RC(getdns_list_get_int(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_int()");
}
END_TEST
START_TEST (getdns_list_get_int_5)
{
/* create a list
* expect: GETDNS_RETURN_GOOD
*/
struct getdns_list *list = NULL;
size_t index = 0;
uint32_t answer;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_int(list, index, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_get_int(list, index, &answer),
GETDNS_RETURN_GOOD, "Return code from getdns_list_get_int()");
ck_assert_msg(answer == 1, "Expected retrieved int == 1, got: %d",
answer);
LIST_DESTROY(list);
}
END_TEST
Suite *
getdns_list_get_int_suite (void)
{
Suite *s = suite_create ("getdns_list_get_int()");
/* Negative test caseis */
TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_list_get_int_1);
tcase_add_test(tc_neg, getdns_list_get_int_2);
tcase_add_test(tc_neg, getdns_list_get_int_3);
tcase_add_test(tc_neg, getdns_list_get_int_4);
suite_add_tcase(s, tc_neg);
/* Positive test cases */
TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_list_get_int_5);
suite_add_tcase(s, tc_pos);
return s;
}
#endif

View File

@ -0,0 +1,150 @@
#ifndef _check_getdns_list_get_list_h_
#define _check_getdns_list_get_list_h_
/*
**************************************************************************
* *
* T E S T S F O R G E T D N S _ L I S T _ G E T _ L I S T *
* *
**************************************************************************
*/
START_TEST (getdns_list_get_list_1)
{
/*
* list = NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
struct getdns_list *answer = NULL;
ASSERT_RC(getdns_list_get_list(list, index, &answer),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_list()");
}
END_TEST
START_TEST (getdns_list_get_list_2)
{
/* index is out of range
* create a list and set index 0 to an int with a value of 100
* Call getdns_get_list() for index 1
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_int(list, index, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
index++;
ASSERT_RC(getdns_list_get_list(list,index,NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_list()");
LIST_DESTROY(list);
}
END_TEST
START_TEST (getdns_list_get_list_3)
{
/* data type at index is not a list
* create a list and set index 0 to an int with a value of 100
* expect: GETDNS_RETURN_WRONG_TYPE_REQUESTED
*/
struct getdns_list *list = NULL;
size_t index = 0;
struct getdns_list *answer = NULL;
LIST_CREATE(list);
ASSERT_RC(getdns_list_set_int(list, index, 1),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_get_list(list, index, &answer),
GETDNS_RETURN_WRONG_TYPE_REQUESTED, "Return code from getdns_list_get_list()");
LIST_DESTROY(list);
}
END_TEST
START_TEST (getdns_list_get_list_4)
{
/* answer == NULL
* expect: GETDNS_RETURN_INVALID_PARAMETER
*/
struct getdns_list *list = NULL;
size_t index = 0;
ASSERT_RC(getdns_list_get_list(list, index, NULL),
GETDNS_RETURN_INVALID_PARAMETER, "Return code from getdns_list_get_list()");
}
END_TEST
START_TEST (getdns_list_get_list_5)
{
/* create a list. Also create a second list
* Set list value at index 0 in the second list via getdns_list_set_int() to 45
* Set list value at index 0 in the first list via getdns_list_set_list() to the second list
* Call getdns_list_get_list() for index 0 against the first list
* Call getdns_list_get_int() for index 0 against retrieved list
* expect: GETDNS_RETURN_GOOD
*/
struct getdns_list *list = NULL;
struct getdns_list *second_list = NULL;
size_t index = 0;
struct getdns_list *answer = NULL;
uint32_t value;
LIST_CREATE(list);
LIST_CREATE(second_list);
ASSERT_RC(getdns_list_set_int(second_list, index, 45),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_set_list(list, index, second_list),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_list()");
ASSERT_RC(getdns_list_get_list(list, index, &answer),
GETDNS_RETURN_GOOD, "Return code from getdns_list_get_list()");
ASSERT_RC(getdns_list_get_int(answer, index, &value),
GETDNS_RETURN_GOOD, "Return code from getdns_list_get_int()");
ck_assert_msg(value == 45, "Expected retrieved int == 45, got: %d",
value);
LIST_DESTROY(list);
LIST_DESTROY(second_list);
}
END_TEST
Suite *
getdns_list_get_list_suite (void)
{
Suite *s = suite_create ("getdns_list_get_list()");
/* Negative test caseis */
TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_list_get_list_1);
tcase_add_test(tc_neg, getdns_list_get_list_2);
tcase_add_test(tc_neg, getdns_list_get_list_3);
tcase_add_test(tc_neg, getdns_list_get_list_4);
suite_add_tcase(s, tc_neg);
/* Positive test cases */
TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_list_get_list_5);
suite_add_tcase(s, tc_pos);
return s;
}
#endif

View File

@ -0,0 +1,224 @@
#ifndef _check_getdns_pretty_print_dict_h_
#define _check_getdns_pretty_print_dict_h_
/*
**************************************************************************
* *
* T E S T S F O R G E T D N S _ D I C T _ D E S T R O Y *
* *
**************************************************************************
*/
START_TEST (getdns_pretty_print_dict_1)
{
/*
* this_dict = NULL
* expect: nothing
*/
struct getdns_dict *some_dict = NULL;
DICT_DESTROY(some_dict);
}
END_TEST
START_TEST (getdns_pretty_print_dict_2)
{
/*
* build a complex dict and then print it
*
* dict1-> "int" = 1
* -> "bindata" = { 8, "bindata" }
* -> "dict" = dict2->"int" = 2
* -> "bindata" = { 8, "bindata" }
* -> "dict" = dict3 -> "int" = 3
* -> "bindata" = { 8, "bindata" }
* -> "dict" = dict4 -> "int" = 4
* -> "list" = list1 0: int = 5
* -> "list" = list2 0: int = 6
* 1: bindata = { 8, "bindata" }
* 2: dict = dict5 -> "bindata" = { 8, "bindata" }
* 3: list = list3 0: bindata = { 8, "bindata" }
* -> "list" = list4 0: int = 6
* 1: bindata = { 8, "bindata" }
* 2: dict6 -> "int" = 8
* -> "bindata" = { 8, "bindata" }
* -> "dict" = dict7 -> "int" = 9
* -> "list" = list5 0: int = 10
* 3: list6 0: int = 11
* 1: bindata = { 8, "bindata" }
* 2: dict8 -> "bindata" = { 8, "bindata" }
* 3: list7 0: bindata = { 8, "bindata" }
*
* expect: nothing
*/
struct getdns_bindata bindata = { 8, (void *)"bindata" };
struct getdns_list *list7;
struct getdns_dict *dict8;
struct getdns_list *list6;
struct getdns_list *list5;
struct getdns_dict *dict7;
struct getdns_dict *dict6;
struct getdns_list *list4;
struct getdns_list *list3;
struct getdns_dict *dict5;
struct getdns_list *list2;
struct getdns_list *list1;
struct getdns_dict *dict4;
struct getdns_dict *dict3;
struct getdns_dict *dict2;
struct getdns_dict *dict1;
/*
* Build it backwards, with the deepest elements first.
*/
LIST_CREATE(list7);
ASSERT_RC(getdns_list_set_bindata(list7, 0, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
DICT_CREATE(dict8);
ASSERT_RC(getdns_dict_set_bindata(dict8, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
LIST_CREATE(list6);
ASSERT_RC(getdns_list_set_int(list6, 0, 11),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_set_bindata(list6, 1, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
ASSERT_RC(getdns_list_set_dict(list6, 2, dict8),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_dict()");
ASSERT_RC(getdns_list_set_list(list6, 3, list7),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_list()");
LIST_CREATE(list5);
ASSERT_RC(getdns_list_set_int(list5, 0, 10),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
DICT_CREATE(dict7);
ASSERT_RC(getdns_dict_set_int(dict7, "int", 9),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
DICT_CREATE(dict6);
ASSERT_RC(getdns_dict_set_int(dict6, "int", 8),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_set_bindata(dict6, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
ASSERT_RC(getdns_dict_set_dict(dict6, "dict", dict7),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_dict()");
ASSERT_RC(getdns_dict_set_list(dict6, "list", list5),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_list()");
LIST_CREATE(list4);
ASSERT_RC(getdns_list_set_int(list4, 0, 7),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_set_bindata(list4, 1, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
ASSERT_RC(getdns_list_set_dict(list4, 2, dict6),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_dict()");
ASSERT_RC(getdns_list_set_list(list4, 3, list5),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_list()");
LIST_CREATE(list3);
ASSERT_RC(getdns_list_set_bindata(list3, 0, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
DICT_CREATE(dict5);
ASSERT_RC(getdns_dict_set_bindata(dict5, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
LIST_CREATE(list2);
ASSERT_RC(getdns_list_set_int(list2, 0, 6),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
ASSERT_RC(getdns_list_set_bindata(list2, 1, &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_bindata()");
ASSERT_RC(getdns_list_set_dict(list2, 2, dict5),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_dict()");
ASSERT_RC(getdns_list_set_list(list2, 3, list3),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_list()");
LIST_CREATE(list1);
ASSERT_RC(getdns_list_set_int(list1, 0, 5),
GETDNS_RETURN_GOOD, "Return code from getdns_list_set_int()");
DICT_CREATE(dict4);
ASSERT_RC(getdns_dict_set_int(dict4, "int", 4),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
DICT_CREATE(dict3);
ASSERT_RC(getdns_dict_set_int(dict3, "int", 3),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_set_bindata(dict3, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
ASSERT_RC(getdns_dict_set_dict(dict3, "dict", dict4),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_dict()");
ASSERT_RC(getdns_dict_set_list(dict3, "list", list1),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_list()");
DICT_CREATE(dict2);
ASSERT_RC(getdns_dict_set_int(dict2, "int", 2),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_set_bindata(dict2, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
ASSERT_RC(getdns_dict_set_dict(dict2, "dict", dict3),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_dict()");
ASSERT_RC(getdns_dict_set_list(dict2, "list", list2),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_list()");
DICT_CREATE(dict1);
ASSERT_RC(getdns_dict_set_int(dict1, "int", 1),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_int()");
ASSERT_RC(getdns_dict_set_bindata(dict1, "bindata", &bindata),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_bindata()");
ASSERT_RC(getdns_dict_set_dict(dict1, "dict", dict2),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_dict()");
ASSERT_RC(getdns_dict_set_list(dict1, "list", list4),
GETDNS_RETURN_GOOD, "Return code from getdns_dict_set_list()");
// ck_assert_msg(answer == 100, "Expected retrieved int == 100, got: %d",
// answer);
/*
* Destroy all of the sub-dicts and sub-lists
*/
LIST_DESTROY(list7);
DICT_DESTROY(dict8);
LIST_DESTROY(list6);
LIST_DESTROY(list5);
DICT_DESTROY(dict7);
DICT_DESTROY(dict6);
LIST_DESTROY(list4);
LIST_DESTROY(list3);
DICT_DESTROY(dict5);
LIST_DESTROY(list2);
LIST_DESTROY(list1);
DICT_DESTROY(dict4);
DICT_DESTROY(dict3);
DICT_DESTROY(dict2);
/*
* And now destroy the mother of all ints, bindata, dicts, and lists
*/
DICT_DESTROY(dict1);
}
END_TEST
Suite *
getdns_pretty_print_dict_suite (void)
{
Suite *s = suite_create ("getdns_pretty_print_dict()");
/* Negative test caseis */
TCase *tc_neg = tcase_create("Negative");
tcase_add_test(tc_neg, getdns_pretty_print_dict_1);
suite_add_tcase(s, tc_neg);
/* Positive test cases */
TCase *tc_pos = tcase_create("Positive");
tcase_add_test(tc_pos, getdns_pretty_print_dict_2);
suite_add_tcase(s, tc_pos);
return s;
}
#endif

View File

@ -678,7 +678,8 @@ validate_extensions(struct getdns_dict * extensions)
return GETDNS_RETURN_GOOD;
} /* validate_extensions */
getdns_return_t getdns_apply_network_result(getdns_network_req* netreq,
getdns_return_t
getdns_apply_network_result(getdns_network_req* netreq,
struct ub_result* ub_res) {
ldns_buffer *result = ldns_buffer_new(ub_res->answer_len);
if (!result) {
@ -690,6 +691,50 @@ getdns_return_t getdns_apply_network_result(getdns_network_req* netreq,
ldns_buffer_free(result);
if (r != LDNS_STATUS_OK) {
return GETDNS_RETURN_GENERIC_ERROR;
}
getdns_return_t
validate_dname(const char* dname) {
int len;
int label_len;
const char* s;
if (dname == NULL) {
return GETDNS_RETURN_INVALID_PARAMETER;
}
len = strlen(dname);
if (len >= GETDNS_MAX_DNAME_LEN || len == 0) {
return GETDNS_RETURN_BAD_DOMAIN_NAME;
}
if (len == 1 && dname[0] == '.') {
/* root is ok */
return GETDNS_RETURN_GOOD;
}
label_len = 0;
for (s = dname; *s; ++s) {
switch (*s) {
case '.':
if (label_len > GETDNS_MAX_LABEL_LEN ||
label_len == 0) {
return GETDNS_RETURN_BAD_DOMAIN_NAME;
}
label_len = 0;
break;
default:
if ((*s >= 'a' && *s <= 'z') ||
(*s >= 'A' && *s <= 'Z') ||
(*s >= '0' && *s <= '9')) {
label_len++;
} else if (*s == '-' && label_len != 0) {
label_len++;
} else {
return GETDNS_RETURN_BAD_DOMAIN_NAME;
}
break;
}
}
if (label_len > GETDNS_MAX_LABEL_LEN) {
return GETDNS_RETURN_BAD_DOMAIN_NAME;
}
return GETDNS_RETURN_GOOD;
}

View File

@ -45,6 +45,9 @@ struct ub_result;
struct getdns_network_req;
getdns_return_t getdns_apply_network_result(getdns_network_req* netreq, struct ub_result* result);
#define GETDNS_MAX_DNAME_LEN 255
#define GETDNS_MAX_LABEL_LEN 63
/**
* add an item to the tail of a list - note that this was not in the getdns API
* description but the list_set functions seem to be designed to modify an existing
@ -100,6 +103,8 @@ getdns_return_t getdns_dict_util_get_string(struct getdns_dict * dict, char *nam
char **result);
char *reverse_address(struct getdns_bindata *address_data);
getdns_return_t validate_dname(const char* dname);
/**
* detect unrecognized extension strings or invalid extension formats
* TODO: this could be optimized by searching a sorted list