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 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)
profile->total_peers++;
}
+ if(SWITCH_STATUS_FALSE == (status = modify_mid(profile->mid))){
+ goto done;
+ }
+
profile->idx = ++mg_sap_id;
/* we should break from here , profile name should be unique */
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",
peer_profile->name, peer_profile->ipaddr, peer_profile->port,peer_profile->mid, peer_profile->transport_type, peer_profile->encoding_type);
}
/****************************************************************************************************************************/
+
+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;
+}