Commit 9a12f8dd authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Fixed fd_dict_getlistof function, added a simple test

parent 0ce67403
......@@ -848,7 +848,7 @@ void fd_dict_dump_object(struct dict_object * obj);
void fd_dict_dump(struct dictionary * dict);
/* Function to access full contents of the dictionary, see doc in dictionary.c */
int fd_dict_getlistof(int criteria, void * parent, struct fd_list * sentinel);
int fd_dict_getlistof(int criteria, void * parent, struct fd_list ** sentinel);
/*
......
......@@ -1840,7 +1840,7 @@ int fd_dict_search ( struct dictionary * dict, enum dict_object_type type, int c
All returned list must be accessed like this:
for (li = sentinel->next; li=li->next; li != sentinel) {
for (li = sentinel->next; li != sentinel; li=li->next) {
struct dict_object * obj = li->o;
...
}
......@@ -1853,18 +1853,18 @@ APPLICATION_BY_ID : (parent = dictionary) returns list of applications ordered b
** for these two lists, the Vendor with id 0 and applciation with id 0 are excluded.
You must resolve them separatly with dict_search.
TYPE_BY_NAME : (parent = dictionary) returns list of types ordered by name
ENUMVAL_BY_NAME : (parent = type object) return list of constants for this type ordered by name
TYPE_BY_NAME : (parent = dictionary) returns list of types ordered by name (osstring order)
ENUMVAL_BY_NAME : (parent = type object) return list of constants for this type ordered by name (osstring order)
ENUMVAL_BY_VALUE : (parent = type object) return list of constants for this type ordered by values
AVP_BY_NAME : (parent = vendor object) return list of AVP for this vendor ordered by name
AVP_BY_NAME : (parent = vendor object) return list of AVP for this vendor ordered by name (osstring order)
AVP_BY_CODE : (parent = vendor object) return list of AVP for this vendor ordered by code
CMD_BY_NAME : (parent = dictionary) returns list of commands ordered by name
CMD_BY_NAME : (parent = dictionary) returns list of commands ordered by name (osstring order)
CMD_BY_CODE_R : (parent = dictionary) returns list of commands ordered by code
RULE_BY_AVP_AND_PARENT: (parent = command or grouped AVP object) return list of rules for this object ordered by AVP vendor/code
All other criteria are rejected.
*/
int fd_dict_getlistof(int criteria, void * parent, struct fd_list * sentinel)
int fd_dict_getlistof(int criteria, void * parent, struct fd_list ** sentinel)
{
struct dictionary * dict = parent;
struct dict_object * obj_parent = parent;
......@@ -1876,47 +1876,47 @@ int fd_dict_getlistof(int criteria, void * parent, struct fd_list * sentinel)
switch(criteria) {
case VENDOR_BY_ID: /* parent must be the dictionary */
CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
sentinel = &dict->dict_vendors.list[0];
*sentinel = &dict->dict_vendors.list[0];
break;
case APPLICATION_BY_ID: /* parent must be the dictionary */
CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
sentinel = &dict->dict_applications.list[0];
*sentinel = &dict->dict_applications.list[0];
break;
case TYPE_BY_NAME: /* parent must be the dictionary */
CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
sentinel = &dict->dict_types;
*sentinel = &dict->dict_types;
break;
case ENUMVAL_BY_NAME: /* parent must be a type object */
CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE));
sentinel = &obj_parent->list[1];
*sentinel = &obj_parent->list[1];
break;
case ENUMVAL_BY_VALUE: /* parent must be a type object */
CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_TYPE));
sentinel = &obj_parent->list[2];
*sentinel = &obj_parent->list[2];
break;
case AVP_BY_NAME: /* parent must be a AVP object */
CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_AVP));
sentinel = &obj_parent->list[2];
case AVP_BY_NAME: /* parent must be a VENDOR object */
CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_VENDOR));
*sentinel = &obj_parent->list[2];
break;
case AVP_BY_CODE: /* parent must be a AVP object */
CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_AVP));
sentinel = &obj_parent->list[1];
case AVP_BY_CODE: /* parent must be a VENDOR object */
CHECK_PARAMS(verify_object(obj_parent) && (obj_parent->type == DICT_VENDOR));
*sentinel = &obj_parent->list[1];
break;
case CMD_BY_NAME: /* parent must be the dictionary */
CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
sentinel = &dict->dict_cmd_name;
*sentinel = &dict->dict_cmd_name;
break;
case CMD_BY_CODE_R: /* parent must be the dictionary */
CHECK_PARAMS(dict->dict_eyec == DICT_EYECATCHER);
sentinel = &dict->dict_cmd_code;
*sentinel = &dict->dict_cmd_code;
break;
case RULE_BY_AVP_AND_PARENT: /* parent must be command or grouped AVP */
......@@ -1924,7 +1924,7 @@ int fd_dict_getlistof(int criteria, void * parent, struct fd_list * sentinel)
CHECK_PARAMS( (obj_parent->type == DICT_COMMAND) ||
((obj_parent->type == DICT_AVP)
&& (obj_parent->data.avp.avp_basetype == AVP_TYPE_GROUPED)) );
sentinel = &obj_parent->list[2];
*sentinel = &obj_parent->list[2];
break;
default:
......
......@@ -128,6 +128,35 @@ int main(int argc, char *argv[])
CHECK( 0, fd_dict_iterate_rules ( example_avp_avp, &nbr, iter_test) );
CHECK( 2, nbr );
}
/* Test list function */
{
struct fd_list * li = NULL;
struct fd_list * sentinel = NULL;
enum dict_object_type type;
struct dict_object * defvnd=NULL;
vendor_id_t vid = 0;
CHECK( 0, fd_dict_getlistof(VENDOR_BY_ID, fd_g_config->cnf_dict, &sentinel));
for (li = sentinel->next; li != sentinel; li = li->next) {
CHECK(0, fd_dict_gettype(li->o, &type));
CHECK(DICT_VENDOR, type);
}
CHECK( 0, fd_dict_search(fd_g_config->cnf_dict, DICT_VENDOR, VENDOR_BY_ID, &vid, &defvnd, ENOENT) );
CHECK( 0, fd_dict_getlistof(AVP_BY_NAME, defvnd, &sentinel));
for (li = sentinel->next; li != sentinel; li = li->next) {
CHECK(0, fd_dict_gettype(li->o, &type));
CHECK(DICT_AVP, type);
#if 0
struct dict_avp_data data;
CHECK( 0, fd_dict_getval(li->o, &data) );
printf("%d : %s\n", data.avp_code, data.avp_name);
#endif
}
}
/* That's all for the tests yet */
PASSTEST();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment