Changeset 1365:0d951a67648b in freeDiameter
- Timestamp:
- Jun 9, 2019, 10:43:24 PM (5 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/test_cc/test_cc.c
r1346 r1365 36 36 struct disp_hdl *ccr_handler_hdl; 37 37 38 struct dict_object * aai_avp_do; /* cache the Auth-Application-Id dictionary object */ 39 struct dict_object * crn_avp_do; /* cache the CC-Request-Number dictionary object */ 40 struct dict_object * crt_avp_do; /* cache the CC-Request-Type dictionary object */ 41 42 #define MODULE_NAME "test_cc" 43 38 44 static int ccr_handler(struct msg ** msg, struct avp * avp, struct session * sess, void * data, enum disp_action * act) 39 45 { … … 51 57 os0_t s; 52 58 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; 53 84 54 85 /* Create the answer message */ 55 86 CHECK_FCT(fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0)); 56 87 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 58 124 /* TODO make result configurable (depending on an AVP?) */ 59 125 CHECK_FCT(fd_msg_rescode_set(answer, "DIAMETER_SUCCESS", NULL, NULL, 1)); 60 126 61 fd_log_ notice("--------------Received the following Credit Control Request:--------------");127 fd_log_debug("--------------Received the following Credit Control Request:--------------"); 62 128 63 129 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); 65 131 66 fd_log_ notice("----------------------------------------------------------------------");132 fd_log_debug("----------------------------------------------------------------------"); 67 133 68 134 /* Send the answer */ 69 135 CHECK_FCT(fd_msg_send(msg, NULL, NULL)); 70 136 fd_log_debug("reply sent"); 71 137 } else { 72 138 /* We received an answer message, just discard it */ … … 85 151 TRACE_ENTRY("%p", conffile); 86 152 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 87 160 memset(&data, 0, sizeof(data)); 88 161 … … 98 171 } 99 172 100 EXTENSION_ENTRY( "test_cc", cc_entry);173 EXTENSION_ENTRY(MODULE_NAME, cc_entry);
Note: See TracChangeset
for help on using the changeset viewer.