adding "<>" or "[]" from the code itself , instead of passing from
config xml for MID field
This commit is contained in:
parent
a54ec05fdb
commit
31d48a8c3a
|
@ -12,6 +12,7 @@
|
||||||
static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) ;
|
static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) ;
|
||||||
static switch_xml_config_item_t *get_peer_instructions(mg_peer_profile_t *profile) ;
|
static switch_xml_config_item_t *get_peer_instructions(mg_peer_profile_t *profile) ;
|
||||||
static int mg_sap_id;
|
static int mg_sap_id;
|
||||||
|
static switch_status_t modify_mid(char* mid);
|
||||||
|
|
||||||
/****************************************************************************************************************************/
|
/****************************************************************************************************************************/
|
||||||
switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
|
switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
|
||||||
|
@ -57,6 +58,10 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
|
||||||
profile->total_peers++;
|
profile->total_peers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SWITCH_STATUS_FALSE == (status = modify_mid(profile->mid))){
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
profile->idx = ++mg_sap_id;
|
profile->idx = ++mg_sap_id;
|
||||||
|
|
||||||
/* we should break from here , profile name should be unique */
|
/* we should break from here , profile name should be unique */
|
||||||
|
@ -92,6 +97,10 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SWITCH_STATUS_FALSE == (status = modify_mid(peer_profile->mid))){
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,"peer_profile name[%s], ipaddr[%s] port[%s], mid[%s] transport_type[%s], encoding_type[%s] \n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,"peer_profile name[%s], ipaddr[%s] port[%s], mid[%s] transport_type[%s], encoding_type[%s] \n",
|
||||||
peer_profile->name, peer_profile->ipaddr, peer_profile->port,peer_profile->mid, peer_profile->transport_type, peer_profile->encoding_type);
|
peer_profile->name, peer_profile->ipaddr, peer_profile->port,peer_profile->mid, peer_profile->transport_type, peer_profile->encoding_type);
|
||||||
|
|
||||||
|
@ -190,3 +199,54 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************************************************/
|
/****************************************************************************************************************************/
|
||||||
|
|
||||||
|
static switch_status_t modify_mid(char* mid)
|
||||||
|
{
|
||||||
|
char* dup = NULL;
|
||||||
|
char* val[10];
|
||||||
|
int count;
|
||||||
|
|
||||||
|
switch_assert(mid);
|
||||||
|
|
||||||
|
/* If MID type is IP then add mid into [] brackets ,
|
||||||
|
* If MID type is domain then add mid into <> brackets *
|
||||||
|
*/
|
||||||
|
|
||||||
|
dup = strdup(mid);
|
||||||
|
count = switch_split(dup, '.', val);
|
||||||
|
|
||||||
|
if(!count) {
|
||||||
|
/* Input string is not separated by '.', check if its separated by '-' as format could be xxx-xx-xxx/xxx-xx-xx-xxx */
|
||||||
|
free(dup);
|
||||||
|
dup = strdup(mid);
|
||||||
|
if(0 == (count = switch_split(dup, '-', val))){
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(('<' == val[0][0]) || ('[' == val[0][0])){
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MID[%s] is already prefixed with proper brackets \n",mid);
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*first check could be if count is 3 means domain name as generally we have xxx-xx-xxx/xxx.xx.xxx domain */
|
||||||
|
if(3 == count){
|
||||||
|
/* domain-type, add value into <> */
|
||||||
|
free(dup);
|
||||||
|
dup = strdup(mid);
|
||||||
|
sprintf(mid,"<%s>",dup);
|
||||||
|
}else if(4 == count){
|
||||||
|
/* IP address in xxx.xxx.xxx.xxx format */
|
||||||
|
free(dup);
|
||||||
|
dup = strdup(mid);
|
||||||
|
sprintf(mid,"[%s]",dup);
|
||||||
|
}else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
free(dup);
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue