Mercurial > hg > freeDiameter
comparison libfdproto/dictionary.c @ 1093:44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 06 May 2013 16:33:22 +0800 |
parents | 7d7266115a34 |
children | 79dd22145f52 |
comparison
equal
deleted
inserted
replaced
1092:e40374ddfeef | 1093:44f3e48dfe27 |
---|---|
716 *result = NULL; \ | 716 *result = NULL; \ |
717 else \ | 717 else \ |
718 ret = ENOENT; \ | 718 ret = ENOENT; \ |
719 } | 719 } |
720 | 720 |
721 /* For searchs of type "xxx_OF_xxx": if the search object is sentinel list for the "what" object */ | |
722 #define SEARCH_sentinel( type_of_what, what_list_nr, sentinel_list_nr ) { \ | |
723 struct dict_object *__what = (struct dict_object *) what; \ | |
724 CHECK_PARAMS_DO( verify_object(__what) && \ | |
725 (__what->type == (type_of_what)), \ | |
726 { ret = EINVAL; goto end; } ); \ | |
727 ret = 0; \ | |
728 if (result) { \ | |
729 /* this is similar to the "container_of" */ \ | |
730 *result = (struct dict_object *)((char *)(__what->list[what_list_nr].head) - \ | |
731 (size_t)&(((struct dict_object *)0)->list[sentinel_list_nr])); \ | |
732 } \ | |
733 } | |
734 | |
735 | |
721 static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) | 736 static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result ) |
722 { | 737 { |
723 int ret = 0; | 738 int ret = 0; |
724 vendor_id_t id; | 739 vendor_id_t id; |
725 | 740 |
737 break; | 752 break; |
738 | 753 |
739 case VENDOR_OF_APPLICATION: | 754 case VENDOR_OF_APPLICATION: |
740 /* "what" should be an application object */ | 755 /* "what" should be an application object */ |
741 SEARCH_childs_parent( DICT_APPLICATION, &dict->dict_vendors ); | 756 SEARCH_childs_parent( DICT_APPLICATION, &dict->dict_vendors ); |
757 break; | |
758 | |
759 case VENDOR_OF_AVP: | |
760 /* "what" should be an avp object */ | |
761 SEARCH_sentinel( DICT_AVP, 0, 1 ); | |
742 break; | 762 break; |
743 | 763 |
744 default: | 764 default: |
745 /* Invalid criteria */ | 765 /* Invalid criteria */ |
746 CHECK_PARAMS( criteria = 0 ); | 766 CHECK_PARAMS( criteria = 0 ); |
1245 | 1265 |
1246 static DECLARE_FD_DUMP_PROTOTYPE(dump_list, struct fd_list * sentinel, int parents, int depth, int indent ) | 1266 static DECLARE_FD_DUMP_PROTOTYPE(dump_list, struct fd_list * sentinel, int parents, int depth, int indent ) |
1247 { | 1267 { |
1248 struct fd_list * li = sentinel; | 1268 struct fd_list * li = sentinel; |
1249 /* We don't lock here, the caller must have taken the dictionary lock for reading already */ | 1269 /* We don't lock here, the caller must have taken the dictionary lock for reading already */ |
1250 while (li->next != sentinel) | 1270 if (FD_IS_LIST_EMPTY(sentinel)) { |
1251 { | 1271 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n%*s{empty list}", indent, ""), return NULL); |
1252 li = li->next; | 1272 } else { |
1253 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, _O(li->o), parents, depth, indent ), return NULL); | 1273 while (li->next != sentinel) |
1274 { | |
1275 li = li->next; | |
1276 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); | |
1277 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, _O(li->o), parents, depth, indent ), return NULL); | |
1278 } | |
1254 } | 1279 } |
1255 } | 1280 } |
1256 | 1281 |
1257 static DECLARE_FD_DUMP_PROTOTYPE(dump_object, struct dict_object * obj, int parents, int depth, int indent ) | 1282 static DECLARE_FD_DUMP_PROTOTYPE(dump_object, struct dict_object * obj, int parents, int depth, int indent ) |
1258 { | 1283 { |
1259 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*s{dictobj}(@%p): ", indent, "", obj), return NULL); | 1284 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*s{dictobj}(@%p): ", indent, "", obj), return NULL); |
1260 | 1285 |
1261 if (!verify_object(obj)) { | 1286 if (!verify_object(obj)) { |
1262 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL\n"), return NULL); | 1287 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "INVALID/NULL"), return NULL); |
1263 return *buf; | 1288 return *buf; |
1264 } | 1289 } |
1265 | 1290 |
1266 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s p:%p ", | 1291 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s p:%p ", |
1267 _OBINFO(obj).name, | 1292 _OBINFO(obj).name, |
1271 CHECK_MALLOC_DO( dump_enumval_data ( FD_DUMP_STD_PARAMS, &obj->data.enumval, obj->parent->data.type.type_base ), return NULL); | 1296 CHECK_MALLOC_DO( dump_enumval_data ( FD_DUMP_STD_PARAMS, &obj->data.enumval, obj->parent->data.type.type_base ), return NULL); |
1272 } else { | 1297 } else { |
1273 CHECK_MALLOC_DO( _OBINFO(obj).dump_data(FD_DUMP_STD_PARAMS, &obj->data), return NULL); | 1298 CHECK_MALLOC_DO( _OBINFO(obj).dump_data(FD_DUMP_STD_PARAMS, &obj->data), return NULL); |
1274 } | 1299 } |
1275 | 1300 |
1276 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); | |
1277 | |
1278 if (parents) { | 1301 if (parents) { |
1279 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*sparent:", indent + 1, ""), return NULL); | 1302 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n%*sparent:", indent + 1, ""), return NULL); |
1280 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, obj->parent, parents-1, 0, 0 ), return NULL); | 1303 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, obj->parent, parents-1, 0, 0 ), return NULL); |
1281 } | 1304 } |
1282 | 1305 |
1283 if (depth) { | 1306 if (depth) { |
1284 int i; | 1307 int i; |
1285 for (i=0; i<NB_LISTS_PER_OBJ; i++) { | 1308 for (i=0; i<NB_LISTS_PER_OBJ; i++) { |
1286 if ((obj->list[i].o == NULL) && (obj->list[i].next != &obj->list[i])) { | 1309 if ((obj->list[i].o == NULL) && (obj->list[i].next != &obj->list[i])) { |
1287 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%*slist[%d]:\n", indent + 1, "", i), return NULL); | |
1288 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &obj->list[i], 0, depth - 1, indent + 2), return NULL); | 1310 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &obj->list[i], 0, depth - 1, indent + 2), return NULL); |
1311 break; /* we get duplicate information sorted by another criteria otherwise, which is not very useful */ | |
1289 } | 1312 } |
1290 } | 1313 } |
1291 } | 1314 } |
1292 | 1315 |
1293 return *buf; | 1316 return *buf; |
1294 } | 1317 } |
1295 | 1318 |
1296 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump_object, struct dict_object * obj) | 1319 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump_object, struct dict_object * obj) |
1297 { | 1320 { |
1298 size_t o = 0; | 1321 FD_DUMP_HANDLE_OFFSET(); |
1299 | |
1300 if (!offset) | |
1301 offset = &o; | |
1302 | 1322 |
1303 CHECK_MALLOC_DO( dump_object(FD_DUMP_STD_PARAMS, obj, 1, 2, 0), return NULL); | 1323 CHECK_MALLOC_DO( dump_object(FD_DUMP_STD_PARAMS, obj, 1, 2, 0), return NULL); |
1304 | 1324 |
1305 return *buf; | 1325 return *buf; |
1306 } | 1326 } |
1307 | 1327 |
1308 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump, struct dictionary * dict) | 1328 DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump, struct dictionary * dict) |
1309 { | 1329 { |
1310 int i; | 1330 int i; |
1311 struct fd_list * li; | 1331 struct fd_list * li; |
1312 size_t o = 0; | 1332 |
1313 | 1333 FD_DUMP_HANDLE_OFFSET(); |
1314 if (!offset) | |
1315 offset = &o; | |
1316 | 1334 |
1317 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{dictionary}(@%p): ", dict), return NULL); | 1335 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{dictionary}(@%p): ", dict), return NULL); |
1318 | 1336 |
1319 if ((dict == NULL) || (dict->dict_eyec != DICT_EYECATCHER)) { | 1337 if ((dict == NULL) || (dict->dict_eyec != DICT_EYECATCHER)) { |
1320 return fd_dump_extend(FD_DUMP_STD_PARAMS, "INVALID/NULL\n"); | 1338 return fd_dump_extend(FD_DUMP_STD_PARAMS, "INVALID/NULL"); |
1321 } | 1339 } |
1322 | 1340 |
1323 CHECK_POSIX_DO( pthread_rwlock_rdlock( &dict->dict_lock ), /* ignore */ ); | 1341 CHECK_POSIX_DO( pthread_rwlock_rdlock( &dict->dict_lock ), /* ignore */ ); |
1324 | 1342 |
1325 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict:%p > vendors, AVPs and related rules}\n", dict), goto error); | 1343 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : VENDORS / AVP / RULES}\n", dict), goto error); |
1326 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, &dict->dict_vendors, 0, 3, 3 ), goto error); | 1344 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, &dict->dict_vendors, 0, 3, 3 ), goto error); |
1327 for (li = dict->dict_vendors.list[0].next; li != &dict->dict_vendors.list[0]; li = li->next) | 1345 for (li = dict->dict_vendors.list[0].next; li != &dict->dict_vendors.list[0]; li = li->next) { |
1346 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); | |
1328 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 3, 3 ), goto error); | 1347 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 3, 3 ), goto error); |
1329 | 1348 } |
1330 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {dict:%p > applications}\n", dict), goto error); | 1349 |
1350 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : APPLICATIONS}\n", dict), goto error); | |
1331 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, &dict->dict_applications, 0, 1, 3 ), goto error); | 1351 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, &dict->dict_applications, 0, 1, 3 ), goto error); |
1332 for (li = dict->dict_applications.list[0].next; li != &dict->dict_applications.list[0]; li = li->next) | 1352 for (li = dict->dict_applications.list[0].next; li != &dict->dict_applications.list[0]; li = li->next) { |
1353 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL); | |
1333 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 1, 3 ), goto error); | 1354 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 1, 3 ), goto error); |
1334 | 1355 } |
1335 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {dict:%p > types}\n", dict), goto error); | 1356 |
1357 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : TYPES / ENUMVAL}", dict), goto error); | |
1336 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_types, 0, 2, 3 ), goto error); | 1358 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_types, 0, 2, 3 ), goto error); |
1337 | 1359 |
1338 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {dict:%p > commands}\n", dict), goto error); | 1360 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : COMMANDS / RULES}", dict), goto error); |
1339 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_cmd_code, 0, 0, 3 ), goto error); | 1361 CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_cmd_code, 0, 0, 3 ), goto error); |
1340 | 1362 |
1341 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {dict:%p > statistics}\n", dict), goto error); | 1363 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : statistics}", dict), goto error); |
1342 for (i=1; i<=DICT_TYPE_MAX; i++) | 1364 for (i=1; i<=DICT_TYPE_MAX; i++) |
1343 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " %5d: %s\n", dict->dict_count[i], dict_obj_info[i].name), goto error); | 1365 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n %5d: %s", dict->dict_count[i], dict_obj_info[i].name), goto error); |
1344 | 1366 |
1345 CHECK_POSIX_DO( pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */ ); | 1367 CHECK_POSIX_DO( pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */ ); |
1346 return *buf; | 1368 return *buf; |
1347 error: | 1369 error: |
1348 /* Free the rwlock */ | 1370 /* Free the rwlock */ |
1482 { | 1504 { |
1483 DECLARE_FD_DUMP_PROTOTYPE((*dump_val_cb), union avp_value *avp_value) = NULL; | 1505 DECLARE_FD_DUMP_PROTOTYPE((*dump_val_cb), union avp_value *avp_value) = NULL; |
1484 struct dict_object * type = NULL; | 1506 struct dict_object * type = NULL; |
1485 char * type_name = NULL; | 1507 char * type_name = NULL; |
1486 char * const_name = NULL; | 1508 char * const_name = NULL; |
1487 size_t o = 0; | 1509 |
1488 | 1510 FD_DUMP_HANDLE_OFFSET(); |
1489 if (!offset) | |
1490 offset = &o; | |
1491 | 1511 |
1492 /* Check the parameters are correct */ | 1512 /* Check the parameters are correct */ |
1493 CHECK_PARAMS_DO( avp_value && verify_object(model) && (model->type == DICT_AVP), return NULL ); | 1513 CHECK_PARAMS_DO( avp_value && verify_object(model) && (model->type == DICT_AVP), return NULL ); |
1494 | 1514 |
1495 /* Get the type definition of this AVP */ | 1515 /* Get the type definition of this AVP */ |