fixing modify mid issue
This commit is contained in:
parent
5ec258b388
commit
a4c4155232
|
@ -12,7 +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);
|
static switch_status_t modify_mid(char** pmid);
|
||||||
|
|
||||||
/****************************************************************************************************************************/
|
/****************************************************************************************************************************/
|
||||||
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)
|
||||||
|
@ -59,10 +59,11 @@ 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))){
|
if(SWITCH_STATUS_FALSE == (status = modify_mid(&profile->mid))){
|
||||||
goto done;
|
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 */
|
||||||
|
@ -100,7 +101,7 @@ 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))){
|
if(SWITCH_STATUS_FALSE == (status = modify_mid(&peer_profile->mid))){
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,55 +214,57 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
|
||||||
|
|
||||||
/****************************************************************************************************************************/
|
/****************************************************************************************************************************/
|
||||||
|
|
||||||
static switch_status_t modify_mid(char* mid)
|
static switch_status_t modify_mid(char** pmid)
|
||||||
{
|
{
|
||||||
char dup[64];
|
char* mid = *pmid;
|
||||||
|
char* dup;
|
||||||
char* val[10];
|
char* val[10];
|
||||||
int count;
|
int count;
|
||||||
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
switch_assert(mid);
|
switch_assert(mid);
|
||||||
|
|
||||||
memset(&dup[0],0,sizeof(dup));
|
dup = strdup(mid);
|
||||||
|
|
||||||
/* If MID type is IP then add mid into [] brackets ,
|
/* If MID type is IP then add mid into [] brackets ,
|
||||||
* If MID type is domain then add mid into <> brackets *
|
* If MID type is domain then add mid into <> brackets *
|
||||||
*/
|
*/
|
||||||
|
|
||||||
strcpy(&dup[0],mid);
|
count = switch_split(dup, '.', val);
|
||||||
count = switch_split(&dup[0], '.', val);
|
|
||||||
|
|
||||||
if(!count) {
|
if(!count) {
|
||||||
/* Input string is not separated by '.', check if its separated by '-' as format could be xxx-xx-xxx/xxx-xx-xx-xxx */
|
/* Input string is not separated by '.', check if its separated by '-' as format could be xxx-xx-xxx/xxx-xx-xx-xxx */
|
||||||
memset(&dup[0],0,sizeof(dup));
|
|
||||||
strcpy(&dup[0],mid);
|
|
||||||
if(0 == (count = switch_split(dup, '-', val))){
|
if(0 == (count = switch_split(dup, '-', val))){
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
|
||||||
return SWITCH_STATUS_FALSE;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(('<' == val[0][0]) || ('[' == val[0][0])){
|
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);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MID = %s is already prefixed with proper brackets \n",mid);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*first check could be if count is 3 means domain name as generally we have xxx-xx-xxx/xxx.xx.xxx domain */
|
/*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){
|
if(3 == count){
|
||||||
/* domain-type, add value into <> */
|
/* domain-type, add value into <> */
|
||||||
memset(&dup[0],0,sizeof(dup));
|
*pmid = switch_mprintf("<%s>", mid);
|
||||||
strcpy(&dup[0],mid);
|
free(mid);
|
||||||
sprintf(mid,"<%s>",dup);
|
mid = *pmid;
|
||||||
}else if(4 == count){
|
}else if(4 == count){
|
||||||
/* IP address in xxx.xxx.xxx.xxx format */
|
/* IP address in xxx.xxx.xxx.xxx format */
|
||||||
memset(&dup[0],0,sizeof(dup));
|
*pmid = switch_mprintf("[%s]", mid);
|
||||||
strcpy(&dup[0],mid);
|
free(mid);
|
||||||
sprintf(mid,"[%s]",dup);
|
mid = *pmid;
|
||||||
}else {
|
}else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
|
||||||
return SWITCH_STATUS_FALSE;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added proper brackets to MID = %s \n",mid);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added proper brackets to MID = %s \n",mid);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
|
||||||
|
done:
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue