Navigation


Changeset 1365:0d951a67648b in freeDiameter


Ignore:
Timestamp:
Jun 9, 2019, 10:43:24 PM (5 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

test_cc: improve

Add all necessary fields. Copy relevant data from request.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/test_cc/test_cc.c

    r1346 r1365  
    3636struct disp_hdl *ccr_handler_hdl;
    3737
     38struct dict_object * aai_avp_do; /* cache the Auth-Application-Id dictionary object */
     39struct dict_object * crn_avp_do; /* cache the CC-Request-Number dictionary object */
     40struct dict_object * crt_avp_do; /* cache the CC-Request-Type dictionary object */
     41
     42#define MODULE_NAME "test_cc"
     43
    3844static int ccr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act)
    3945{
     
    5157                os0_t s;
    5258                size_t sl;
     59                struct avp *avp;
     60                union avp_value val;
     61                struct avp *avp_data;
     62                struct avp_hdr *ahdr;
     63                uint32_t crt, crn;
     64
     65                /* get some necessary information from request */
     66                if (fd_msg_search_avp(*msg, crt_avp_do, &avp_data) < 0 || avp_data == NULL) {
     67                        fd_log_error("[%s] CC-Request-Type not found in CCR", MODULE_NAME);
     68                        return 0;
     69                }
     70                if (fd_msg_avp_hdr(avp_data, &ahdr) < 0) {
     71                        fd_log_error("[%s] error parsing CC-Request-Type in CCR", MODULE_NAME);
     72                        return 0;
     73                }
     74                crt = ahdr->avp_value->i32;
     75                if (fd_msg_search_avp(*msg, crn_avp_do, &avp_data) < 0 || avp_data == NULL) {
     76                        fd_log_error("[%s] CC-Request-Number not found in CCR", MODULE_NAME);
     77                        return 0;
     78                }
     79                if (fd_msg_avp_hdr(avp_data, &ahdr) < 0) {
     80                        fd_log_error("[%s] error parsing CC-Request-Type in CCR", MODULE_NAME);
     81                        return 0;
     82                }
     83                crn = ahdr->avp_value->i32;
    5384
    5485                /* Create the answer message */
    5586                CHECK_FCT(fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0));
    5687                answer = *msg;
    57                 /* TODO copy/fill in AVPs in the answer */
     88
     89                /* TODO copy/fill in more AVPs in the answer */
     90
     91                /* Auth-Application-Id */
     92                fd_msg_avp_new(aai_avp_do, 0, &avp);
     93                memset(&val, 0, sizeof(val));
     94                val.i32 = 4;
     95                if (fd_msg_avp_setvalue(avp, &val) != 0) {
     96                        fd_msg_free(answer);
     97                        fd_log_error("can't set value for 'Auth-Application-Id' for 'Credit-Control-Request' message");
     98                        return 0;
     99                }
     100                fd_msg_avp_add(answer, MSG_BRW_LAST_CHILD, avp);
     101
     102                /* CC-Request-Type */
     103                fd_msg_avp_new(crt_avp_do, 0, &avp);
     104                memset(&val, 0, sizeof(val));
     105                val.i32 = crt;
     106                if (fd_msg_avp_setvalue(avp, &val) != 0) {
     107                        fd_msg_free(answer);
     108                        fd_log_error("can't set value for 'CC-Request-Type' for 'Credit-Control-Request' message");
     109                        return 0;
     110                }
     111                fd_msg_avp_add(answer, MSG_BRW_LAST_CHILD, avp);
     112
     113                /* CC-Request-Number */
     114                fd_msg_avp_new(crn_avp_do, 0, &avp);
     115                memset(&val, 0, sizeof(val));
     116                val.i32 = crn;
     117                if (fd_msg_avp_setvalue(avp, &val) != 0) {
     118                        fd_msg_free(answer);
     119                        fd_log_error("can't set value for 'CC-Request-Number' for 'Credit-Control-Request' message");
     120                        return 0;
     121                }
     122                fd_msg_avp_add(answer, MSG_BRW_LAST_CHILD, avp);
     123
    58124                /* TODO make result configurable (depending on an AVP?) */
    59125                CHECK_FCT(fd_msg_rescode_set(answer, "DIAMETER_SUCCESS", NULL, NULL, 1));
    60126
    61                 fd_log_notice("--------------Received the following Credit Control Request:--------------");
     127                fd_log_debug("--------------Received the following Credit Control Request:--------------");
    62128
    63129                CHECK_FCT(fd_sess_getsid(sess, &s, &sl));
    64                 fd_log_notice("Session: %.*s",(int)sl, s);
     130                fd_log_debug("Session: %.*s",(int)sl, s);
    65131
    66                 fd_log_notice("----------------------------------------------------------------------");
     132                fd_log_debug("----------------------------------------------------------------------");
    67133
    68134                /* Send the answer */
    69135                CHECK_FCT(fd_msg_send(msg, NULL, NULL));
    70 
     136                fd_log_debug("reply sent");
    71137        } else {
    72138                /* We received an answer message, just discard it */
     
    85151        TRACE_ENTRY("%p", conffile);
    86152
     153        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Auth-Application-Id", &aai_avp_do, ENOENT),
     154                     { LOG_E("Unable to find 'Auth-Application-Id' AVP in the loaded dictionaries."); });
     155        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CC-Request-Number", &crn_avp_do, ENOENT),
     156                     { LOG_E("Unable to find 'CC-Request-Number' AVP in the loaded dictionaries."); });
     157        CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "CC-Request-Type", &crt_avp_do, ENOENT),
     158                     { LOG_E("Unable to find 'CC-Request-Type' AVP in the loaded dictionaries."); });
     159
    87160        memset(&data, 0, sizeof(data));
    88161
     
    98171}
    99172
    100 EXTENSION_ENTRY("test_cc", cc_entry);
     173EXTENSION_ENTRY(MODULE_NAME, cc_entry);
Note: See TracChangeset for help on using the changeset viewer.