Navigation


Changeset 1093:44f3e48dfe27 in freeDiameter for libfdproto/dictionary.c


Ignore:
Timestamp:
May 6, 2013, 5:33:22 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Align the behavior of all fd_*dump functions wrt final \n

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/dictionary.c

    r1085 r1093  
    719719}
    720720
     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
    721736static int search_vendor ( struct dictionary * dict, int criteria, const void * what, struct dict_object **result )
    722737{
     
    740755                        /* "what" should be an application object */
    741756                        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 );
    742762                        break;
    743763               
     
    12481268        struct fd_list * li = sentinel;
    12491269        /* We don't lock here, the caller must have taken the dictionary lock for reading already */
    1250         while (li->next != sentinel)
    1251         {
    1252                 li = li->next;
    1253                 CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, _O(li->o), parents, depth, indent ), return NULL);
     1270        if (FD_IS_LIST_EMPTY(sentinel)) {
     1271                CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n%*s{empty list}", indent, ""), return NULL);
     1272        } else {
     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                }
    12541279        }
    12551280}
     
    12601285       
    12611286        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);
    12631288                return *buf;
    12641289        }
     
    12741299        }
    12751300       
    1276         CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n"), return NULL);
    1277        
    12781301        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);
    12801303                CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, obj->parent, parents-1, 0, 0 ), return NULL);
    12811304        }
     
    12851308                for (i=0; i<NB_LISTS_PER_OBJ; i++) {
    12861309                        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);
    12881310                                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 */
    12891312                        }
    12901313                }
     
    12961319DECLARE_FD_DUMP_PROTOTYPE(fd_dict_dump_object, struct dict_object * obj)
    12971320{
    1298         size_t o = 0;
    1299 
    1300         if (!offset)
    1301                 offset = &o;
     1321        FD_DUMP_HANDLE_OFFSET();
    13021322       
    13031323        CHECK_MALLOC_DO( dump_object(FD_DUMP_STD_PARAMS, obj, 1, 2, 0), return NULL);
     
    13101330        int i;
    13111331        struct fd_list * li;
    1312         size_t o = 0;
    1313 
    1314         if (!offset)
    1315                 offset = &o;
     1332       
     1333        FD_DUMP_HANDLE_OFFSET();
    13161334               
    13171335        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{dictionary}(@%p): ", dict), return NULL);
    13181336       
    13191337        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");
    13211339        }
    13221340       
    13231341        CHECK_POSIX_DO(  pthread_rwlock_rdlock( &dict->dict_lock ), /* ignore */  );
    13241342       
    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);
    13261344        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);
    13281347                CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 3, 3 ), goto error);
    1329        
    1330         CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {dict:%p > applications}\n", dict), goto error);
     1348        }
     1349       
     1350        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : APPLICATIONS}\n", dict), goto error);
    13311351        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);
    13331354                CHECK_MALLOC_DO( dump_object (FD_DUMP_STD_PARAMS, li->o, 0, 1, 3 ), goto error);
    1334        
    1335         CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " {dict:%p > types}\n", dict), goto error);
     1355        }
     1356       
     1357        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n {dict(%p) : TYPES / ENUMVAL}", dict), goto error);
    13361358        CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_types, 0, 2, 3 ), goto error);
    13371359       
    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);
    13391361        CHECK_MALLOC_DO( dump_list(FD_DUMP_STD_PARAMS, &dict->dict_cmd_code, 0, 0, 3 ), goto error);
    13401362       
    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);
    13421364        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);
    13441366       
    13451367        CHECK_POSIX_DO(  pthread_rwlock_unlock( &dict->dict_lock ), /* ignore */  );
     
    14851507        char * type_name = NULL;
    14861508        char * const_name = NULL;
    1487         size_t o = 0;
    1488        
    1489         if (!offset)
    1490                 offset = &o;
     1509       
     1510        FD_DUMP_HANDLE_OFFSET();
    14911511       
    14921512        /* Check the parameters are correct */
Note: See TracChangeset for help on using the changeset viewer.