Changeset 285:0daf6fc2b751 in freeDiameter for extensions/app_acct/app_acct.c
- Timestamp:
- Apr 30, 2010, 5:55:16 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_acct/app_acct.c
r284 r285 38 38 #include "app_acct.h" 39 39 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 */ 41 static struct { 42 struct dict_object * Accounting_Record_Number; 43 struct dict_object * Accounting_Record_Type; 44 } acct_dict; 50 45 51 46 … … 54 49 { 55 50 struct msg_hdr *hdr = NULL; 56 struct msg * ans, *qry;51 struct msg * m; 57 52 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 */ 59 54 char * s; 55 struct acct_record_list rl; 60 56 61 57 TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act); … … 63 59 return EINVAL; 64 60 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 */ 67 90 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) ); 68 ans= *msg;91 m = *msg; 69 92 70 93 /* 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 82 108 /* Send the answer */ 83 CHECK_FCT( fd_msg_send( msg, NULL, NULL ) ); 84 109 *act = DISP_ACT_SEND; 85 110 return 0; 86 111 } … … 94 119 TRACE_ENTRY("%p", conffile); 95 120 121 #ifndef TEST_DEBUG /* We do this differently in the test scenario */ 96 122 /* Initialize the configuration and parse the file */ 97 123 CHECK_FCT( acct_conf_init() ); 98 124 CHECK_FCT( acct_conf_parse(conffile) ); 99 125 CHECK_FCT( acct_conf_check(conffile) ); 126 #endif /* TEST_DEBUG */ 100 127 101 128 /* Now initialize the database module */ 102 129 CHECK_FCT( acct_db_init() ); 103 130 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 104 135 /* Register the dispatch callbacks */ 105 136 memset(&data, 0, sizeof(data)); 106 137 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 ) );108 138 CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Accounting-Request", &data.command, ENOENT) ); 109 139 CHECK_FCT( fd_disp_register( acct_cb, DISP_HOW_CC, &data, NULL ) );
Note: See TracChangeset
for help on using the changeset viewer.