Add condition matching capability to only account for one or more subset of channel directions to radius.
This commit is contained in:
parent
51691d4c9a
commit
aad07c6243
|
@ -594,16 +594,63 @@ static switch_xml_t mod_xml_radius_directory_search(const char *section, const c
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_status_t mod_xml_radius_check_conditions(switch_channel_t *channel, switch_xml_t conditions) {
|
||||||
|
switch_xml_t condition, param;
|
||||||
|
char *channel_var = NULL;
|
||||||
|
char *regex = NULL;
|
||||||
|
int all_matched = 1;
|
||||||
|
|
||||||
|
if ( (condition = switch_xml_child(conditions, "condition")) == NULL) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to locate a condition under the conditions section\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; condition; condition = condition->next) {
|
||||||
|
|
||||||
|
if ( (param = switch_xml_child(condition, "param")) == NULL) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to locate a param under this condition\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
all_matched = 1;
|
||||||
|
for (; param && all_matched; param = param->next) {
|
||||||
|
channel_var = (char *) switch_xml_attr(param, "var");
|
||||||
|
regex = (char *) switch_xml_attr(param, "regex");
|
||||||
|
|
||||||
|
if ( channel_var == NULL || regex == NULL ) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Improperly constructed mod_radius condition: %s %s\n", channel_var, regex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( switch_regex_match( switch_channel_get_variable(channel, channel_var), regex) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
all_matched = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( all_matched ) {
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
switch_status_t mod_xml_radius_accounting_start(switch_core_session_t *session){
|
switch_status_t mod_xml_radius_accounting_start(switch_core_session_t *session){
|
||||||
VALUE_PAIR *send = NULL;
|
VALUE_PAIR *send = NULL;
|
||||||
uint32_t service = PW_STATUS_START;
|
uint32_t service = PW_STATUS_START;
|
||||||
rc_handle *new_handle = NULL;
|
rc_handle *new_handle = NULL;
|
||||||
switch_xml_t fields;
|
switch_xml_t fields, conditions;
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
|
|
||||||
if (GLOBAL_DEBUG ) {
|
if (GLOBAL_DEBUG ) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting accounting start\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting accounting start\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If there are conditions defined, and none of them pass, then skip this accounting */
|
||||||
|
if ((conditions = switch_xml_child(globals.acct_start_configs, "conditions")) != NULL &&
|
||||||
|
mod_xml_radius_check_conditions(channel, conditions) != SWITCH_STATUS_SUCCESS ) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
mod_xml_radius_new_handle(&new_handle, globals.acct_start_configs);
|
mod_xml_radius_new_handle(&new_handle, globals.acct_start_configs);
|
||||||
|
|
||||||
if ((fields = switch_xml_child(globals.acct_start_configs, "fields")) == NULL ) {
|
if ((fields = switch_xml_child(globals.acct_start_configs, "fields")) == NULL ) {
|
||||||
|
@ -628,7 +675,9 @@ switch_status_t mod_xml_radius_accounting_start(switch_core_session_t *session){
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
if ( new_handle ) {
|
||||||
rc_destroy(new_handle);
|
rc_destroy(new_handle);
|
||||||
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -637,13 +686,20 @@ switch_status_t mod_xml_radius_accounting_end(switch_core_session_t *session){
|
||||||
VALUE_PAIR *send = NULL;
|
VALUE_PAIR *send = NULL;
|
||||||
uint32_t service = PW_STATUS_STOP;
|
uint32_t service = PW_STATUS_STOP;
|
||||||
rc_handle *new_handle = NULL;
|
rc_handle *new_handle = NULL;
|
||||||
switch_xml_t fields;
|
switch_xml_t fields = NULL, conditions = NULL;
|
||||||
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
|
|
||||||
if (GLOBAL_DEBUG ) {
|
if (GLOBAL_DEBUG ) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting accounting stop\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting accounting stop\n");
|
||||||
switch_core_session_execute_application(session, "info", NULL);
|
switch_core_session_execute_application(session, "info", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If there are conditions defined, and none of them pass, then skip this accounting */
|
||||||
|
if ((conditions = switch_xml_child(globals.acct_start_configs, "conditions")) != NULL &&
|
||||||
|
mod_xml_radius_check_conditions(channel, conditions) != SWITCH_STATUS_SUCCESS ) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
mod_xml_radius_new_handle(&new_handle, globals.acct_end_configs);
|
mod_xml_radius_new_handle(&new_handle, globals.acct_end_configs);
|
||||||
|
|
||||||
if ((fields = switch_xml_child(globals.acct_end_configs, "fields")) == NULL ) {
|
if ((fields = switch_xml_child(globals.acct_end_configs, "fields")) == NULL ) {
|
||||||
|
|
|
@ -74,6 +74,11 @@
|
||||||
<param name="Called-Station-Id" variable="sip_to_user" format="%s"/>
|
<param name="Called-Station-Id" variable="sip_to_user" format="%s"/>
|
||||||
<param name="Calling-Station-Id" variable="sip_from_user" format="%s"/>
|
<param name="Calling-Station-Id" variable="sip_from_user" format="%s"/>
|
||||||
</fields>
|
</fields>
|
||||||
|
<conditions>
|
||||||
|
<condition>
|
||||||
|
<param var="direction" regex="inbound"/>
|
||||||
|
</condition>
|
||||||
|
</conditions>
|
||||||
</acct_start>
|
</acct_start>
|
||||||
<acct_end>
|
<acct_end>
|
||||||
<connection name="testing">
|
<connection name="testing">
|
||||||
|
@ -99,5 +104,10 @@
|
||||||
<param vendor="Cisco" name="Cisco-AVPair" variable="sip_from_user" format="src-number-out=%s"/>
|
<param vendor="Cisco" name="Cisco-AVPair" variable="sip_from_user" format="src-number-out=%s"/>
|
||||||
<param vendor="Cisco" name="Cisco-AVPair" variable="sip_to_user" format="dst-number-out=%s"/>
|
<param vendor="Cisco" name="Cisco-AVPair" variable="sip_to_user" format="dst-number-out=%s"/>
|
||||||
</fields>
|
</fields>
|
||||||
|
<conditions>
|
||||||
|
<condition>
|
||||||
|
<param var="direction" regex="inbound"/>
|
||||||
|
</condition>
|
||||||
|
</conditions>
|
||||||
</acct_end>
|
</acct_end>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
Loading…
Reference in New Issue