]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fixing modify mid code
authorkapil <kgupta@sangoma.com>
Mon, 2 Jul 2012 04:25:36 +0000 (09:55 +0530)
committerkapil <kgupta@sangoma.com>
Mon, 2 Jul 2012 04:25:36 +0000 (09:55 +0530)
src/mod/endpoints/mod_media_gateway/media_gateway_xml.c

index 5acba0d9548ab8fd3a0c5550456ad780111e6e95..64caa13a99de238b97108d6508f30d11c7a73c77 100644 (file)
@@ -215,23 +215,25 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
 
 static switch_status_t modify_mid(char* mid)
 {
-       char*                   dup = NULL;
+       char                    dup[64];
        char*                   val[10];
        int                     count;
 
        switch_assert(mid);
 
+       memset(&dup[0],0,sizeof(dup));
+
        /* 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);
+       strcpy(&dup[0],mid);
+       count = switch_split(&dup[0], '.', 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);
+               memset(&dup[0],0,sizeof(dup));
+               strcpy(&dup[0],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;
@@ -239,29 +241,27 @@ static switch_status_t modify_mid(char* mid)
        }
 
        if(('<' == val[0][0]) || ('[' == val[0][0])){
-               free(dup);
-               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;
        }
        
        /*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);
+               memset(&dup[0],0,sizeof(dup));
+               strcpy(&dup[0],mid);
                sprintf(mid,"<%s>",dup);
        }else if(4 == count){
                /* IP address in xxx.xxx.xxx.xxx format */
-               free(dup);
-               dup = strdup(mid);
+               memset(&dup[0],0,sizeof(dup));
+               strcpy(&dup[0],mid);
                sprintf(mid,"[%s]",dup);
        }else {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
-               free(dup);
                return SWITCH_STATUS_FALSE;
        }
 
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added proper brackets to MID = %s \n",mid);
 
-       free(dup);
        return SWITCH_STATUS_SUCCESS;
 }