Navigation


Changeset 285:0daf6fc2b751 in freeDiameter for extensions/app_acct/app_acct.c


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/app_acct.c

    r284 r285  
    3838#include "app_acct.h"
    3939
    40 /* Default callback for the Accounting application. */
    41 static int acct_fallback( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act)
    42 {
    43         /* This CB should never be called */
    44         TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
    45        
    46         fd_log_debug("Unexpected message received!\n");
    47        
    48         return ENOTSUP;
    49 }
     40/* Mandatory AVPs for the Accounting-Answer */
     41static struct {
     42        struct dict_object * Accounting_Record_Number;
     43        struct dict_object * Accounting_Record_Type;
     44} acct_dict;
    5045
    5146
     
    5449{
    5550        struct msg_hdr *hdr = NULL;
    56         struct msg *ans, *qry;
     51        struct msg * m;
    5752        struct avp * a = NULL;
    58         struct avp_hdr * h = NULL;
     53        struct avp_hdr * art=NULL, *arn=NULL; /* We keep a pointer on the Accounting-Record-{Type, Number} AVPs from the query */
    5954        char * s;
     55        struct acct_record_list rl;
    6056       
    6157        TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act);
     
    6359                return EINVAL;
    6460       
    65         qry = *msg;
    66         /* Create the answer message, including the Session-Id AVP */
     61        m = *msg;
     62       
     63        /* Prepare a new record list */
     64        CHECK_FCT( acct_rec_prepare( &rl ) );
     65       
     66        /* Maps the AVPs from the query with this record list */
     67        CHECK_FCT( acct_rec_map( &rl, m ) );
     68       
     69        /* Check that at least one AVP was mapped */
     70        CHECK_FCT( acct_rec_validate( &rl ) );
     71       
     72        /* Now, save these mapped AVPs in the database */
     73        CHECK_FCT( acct_db_insert( &rl ) );
     74       
     75        acct_rec_empty( &rl );
     76       
     77        /* OK, we can send a positive reply now */
     78       
     79        /* Get Accounting-Record-{Number,Type} values */
     80        CHECK_FCT( fd_msg_search_avp ( m, acct_dict.Accounting_Record_Type, &a) );
     81        if (a) {
     82                CHECK_FCT( fd_msg_avp_hdr( a, &art )  );
     83        }
     84        CHECK_FCT( fd_msg_search_avp ( m, acct_dict.Accounting_Record_Number, &a) );
     85        if (a) {
     86                CHECK_FCT( fd_msg_avp_hdr( a, &arn )  );
     87        }
     88       
     89        /* Create the answer message */
    6790        CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) );
    68         ans = *msg;
     91        m = *msg;
    6992
    7093        /* Set the Origin-Host, Origin-Realm, Result-Code AVPs */
    71         CHECK_FCT( fd_msg_rescode_set( ans, "DIAMETER_SUCCESS", NULL, NULL, 1 ) );
    72 
    73         fd_log_debug("--------------Received the following Accounting message:--------------\n");
    74 
    75         CHECK_FCT( fd_sess_getsid ( sess, &s ) );
    76         fd_log_debug("Session: %s\n", s);
    77 
    78         /* We may also dump other data from the message, such as Accounting session Id, number of packets, ...  */
    79 
    80         fd_log_debug("----------------------------------------------------------------------\n");
    81 
     94        CHECK_FCT( fd_msg_rescode_set( m, "DIAMETER_SUCCESS", NULL, NULL, 1 ) );
     95       
     96        /* Add the mandatory AVPs in the ACA */
     97        if (art) {
     98                CHECK_FCT( fd_msg_avp_new ( acct_dict.Accounting_Record_Type, 0, &a ) );
     99                CHECK_FCT( fd_msg_avp_setvalue( a, art->avp_value ) );
     100                CHECK_FCT( fd_msg_avp_add( m, MSG_BRW_LAST_CHILD, a ) );
     101        }
     102        if (arn) {
     103                CHECK_FCT( fd_msg_avp_new ( acct_dict.Accounting_Record_Number, 0, &a ) );
     104                CHECK_FCT( fd_msg_avp_setvalue( a, arn->avp_value ) );
     105                CHECK_FCT( fd_msg_avp_add( m, MSG_BRW_LAST_CHILD, a ) );
     106        }
     107       
    82108        /* Send the answer */
    83         CHECK_FCT( fd_msg_send( msg, NULL, NULL ) );
    84                
     109        *act = DISP_ACT_SEND;
    85110        return 0;
    86111}
     
    94119        TRACE_ENTRY("%p", conffile);
    95120       
     121#ifndef TEST_DEBUG /* We do this differently in the test scenario */
    96122        /* Initialize the configuration and parse the file */
    97123        CHECK_FCT( acct_conf_init() );
    98124        CHECK_FCT( acct_conf_parse(conffile) );
    99125        CHECK_FCT( acct_conf_check(conffile) );
     126#endif /* TEST_DEBUG */
    100127       
    101128        /* Now initialize the database module */
    102129        CHECK_FCT( acct_db_init() );
    103130       
     131        /* Search the AVPs we will need in this file */
     132        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Accounting-Record-Number", &acct_dict.Accounting_Record_Number, ENOENT) );
     133        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Accounting-Record-Type", &acct_dict.Accounting_Record_Type, ENOENT) );
     134       
    104135        /* Register the dispatch callbacks */
    105136        memset(&data, 0, sizeof(data));
    106137        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Base Accounting", &data.app, ENOENT) );
    107         CHECK_FCT( fd_disp_register( acct_fallback, DISP_HOW_APPID, &data, NULL ) );
    108138        CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &data.command, ENOENT) );
    109139        CHECK_FCT( fd_disp_register( acct_cb, DISP_HOW_CC, &data, NULL ) );
Note: See TracChangeset for help on using the changeset viewer.