Navigation



Ignore:
Timestamp:
Apr 30, 2010, 5:55:16 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Added a test case for the app_acct extension

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_acct/acct_records.c

    r284 r285  
    7474}
    7575
     76/* Find the AVPs from configuration inside a received message */
    7677int acct_rec_map(struct acct_record_list * records, struct msg * msg)
    7778{
     79        struct avp * avp;
     80       
    7881        TRACE_ENTRY("%p %p", records, msg);
    7982       
    8083        /* For each AVP in the message, search if we have a corresponding unmap'd record */
     84        CHECK_FCT(  fd_msg_browse(msg, MSG_BRW_FIRST_CHILD, &avp, NULL)  );
     85        while (avp) {
     86                struct fd_list * li;
     87                struct dict_object * model;
     88               
     89                CHECK_FCT( fd_msg_model(avp, &model) );
     90                if (model != NULL) {    /* we ignore the AVPs we don't recognize */
     91               
     92                        /* Search this model in the list */
     93                        for (li = records->unmaped.next; li != &records->unmaped; li = li->next) {
     94                                struct acct_record_item * r = (struct acct_record_item *)(li->o);
     95                                if (r->param->avpobj == model) {
     96                                        /* It matches: save the AVP value and unlink this record from the unmap'd list */
     97                                        struct avp_hdr * h;
     98                                        CHECK_FCT( fd_msg_avp_hdr( avp, &h ) );
     99                                        r->value = h->avp_value;
     100                                        fd_list_unlink(&r->unmapd);
     101                                        records->nbunmap -= 1;
     102                                        break;
     103                                }
     104                        }
     105
     106                        /* Continue only while there are some AVPs to map */
     107                        if (FD_IS_LIST_EMPTY(&records->unmaped))
     108                                break;
     109                }
     110               
     111                /* Go to next AVP in the message */
     112                CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) );
     113        }
    81114       
    82         return ENOTSUP;
     115        /* Done */
     116        return 0;
    83117}
     118
     119/* Check that a mapped list is not empty and no required AVP is missing. Free the record list in case of error */
     120int acct_rec_validate(struct acct_record_list * records)
     121{
     122        struct fd_list * li;
     123        TRACE_ENTRY("%p", records);
     124        CHECK_PARAMS( records );
     125       
     126        /* Check at least one AVP was mapped */
     127        if (records->nball == records->nbunmap) {
     128                fd_log_debug("The received ACR does not contain any AVP from the configuration file.\n"
     129                                "This is an invalid situation. Please fix your configuration file.\n"
     130                                "One way to ensure this does not happen is to include Session-Id in the database.\n");
     131                acct_rec_empty(records);
     132                return EINVAL;
     133        }
     134       
     135        /* Now, check there is no required AVP unmap'd */
     136        for (li = records->unmaped.next; li != &records->unmaped; li = li->next) {
     137                struct acct_record_item * r = (struct acct_record_item *)(li->o);
     138                if (r->param->required && (r->index <= 1)) {
     139                        fd_log_debug("The received ACR does not contain the required AVP '%s'.\n", r->param->avpname);
     140                        acct_rec_empty(records);
     141                        return EINVAL;
     142                }
     143        }
     144       
     145        /* The record list is OK */
     146        return 0;
     147}
     148
     149/* Free all the items in an acct_record_list returned by acct_rec_prepare */
     150void acct_rec_empty(struct acct_record_list * records)
     151{
     152        TRACE_ENTRY("%p", records);
     153        CHECK_PARAMS_DO( records, return );
     154       
     155        while (!FD_IS_LIST_EMPTY(&records->all)) {
     156                struct acct_record_item * r = (struct acct_record_item *)(records->all.next);
     157                fd_list_unlink( &r->chain );
     158                fd_list_unlink( &r->unmapd );
     159                free(r);
     160        }
     161}
Note: See TracChangeset for help on using the changeset viewer.