changeset 769:99136ec7d9d4

Fixed fd_dict_getlistof function, added a simple test
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 25 Oct 2011 21:48:52 +0200
parents a5a82d50c25e
children 27fef2ca2cf6
files include/freeDiameter/libfdproto.h libfdproto/dictionary.c tests/testdict.c
diffstat 3 files changed, 50 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/include/freeDiameter/libfdproto.h	Mon Oct 24 22:14:33 2011 +0200
+++ b/include/freeDiameter/libfdproto.h	Tue Oct 25 21:48:52 2011 +0200
@@ -848,7 +848,7 @@
 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);
 
 
 /*
--- a/libfdproto/dictionary.c	Mon Oct 24 22:14:33 2011 +0200
+++ b/libfdproto/dictionary.c	Tue Oct 25 21:48:52 2011 +0200
@@ -1840,7 +1840,7 @@
 
 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 @@
   ** 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 @@
 	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 @@
 			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:
--- a/tests/testdict.c	Mon Oct 24 22:14:33 2011 +0200
+++ b/tests/testdict.c	Tue Oct 25 21:48:52 2011 +0200
@@ -128,6 +128,35 @@
 		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();
"Welcome to our mercurial repository"