]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
adding "<>" or "[]" from the code itself , instead of passing from
authorkapil <kgupta@sangoma.com>
Wed, 20 Jun 2012 06:31:04 +0000 (12:01 +0530)
committerkapil <kgupta@sangoma.com>
Wed, 20 Jun 2012 06:31:04 +0000 (12:01 +0530)
config xml for MID field

src/mod/endpoints/mod_media_gateway/media_gateway_xml.c

index 2d584ed0edd9d895bf51c6df347c32aa61acd262..ba5c20aabb823f825dfa179f3b8fe88832b16c21 100644 (file)
@@ -12,6 +12,7 @@
 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)
@@ -57,6 +58,10 @@ 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 */
@@ -92,6 +97,10 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
                                        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);
 
@@ -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;
+}