From b1b2bee36268834ad0d7348ed098c6ad446b75fd Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jul 2012 15:02:25 -0400 Subject: [PATCH] fixing local sdp issue --- .../media_gateway_cmd_handler.c | 83 +++++++++++-------- .../mod_media_gateway/media_gateway_utils.c | 13 ++- .../mod_media_gateway/mod_media_gateway.h | 2 +- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 57c8843aee..185f3fb5a9 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -498,6 +498,10 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i /*MgMgcoStreamDesc* inc_strm_desc;*/ MgMgcoAudRetParm *desc; mg_context_t* mg_ctxt; + int mediaId; + MgMgcoLocalDesc *local = NULL; + CmSdpInfoSet *psdp = NULL; + /* TODO - Kapil dummy line , will need to add with proper code */ inc_med_desc = &cmd->dl.descs[0]->u.media; @@ -686,18 +690,25 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i } /* copy media descriptor */ - desc = rsp.u.mgCmdRsp[0]->u.add.audit.parms[rsp.u.mgCmdRsp[0]->u.add.audit.num.val-1]; desc->type.pres = PRSNT_NODEF; desc->type.val = MGT_MEDIADESC; mgUtlCpyMgMgcoMediaDesc(&desc->u.media, inc_med_desc, &rsp.u.mgCmdRsp[0]->memCp); + /* see if we have received local descriptor */ + if((NOTPRSNT != desc->u.media.num.pres) && + (0 != desc->u.media.num.val)) + { + for(mediaId=0; mediaIdu.media.num.val; mediaId++) { + if(MGT_MEDIAPAR_LOCAL == desc->u.media.parms[mediaId]->type.val) { + local = &desc->u.media.parms[mediaId]->u.local; + } + } + } /* only for RTP */ if(is_rtp){ /* build local descriptors */ /*MgMgcoStreamDesc *stream;*/ - MgMgcoLocalDesc *local; - CmSdpInfoSet *psdp; char* ipAddress[4];// = "192.168.1.1"; char* dup = strdup((char*)term->u.rtp.local_addr); MgMgcoMediaDesc* media = &desc->u.media; @@ -705,45 +716,47 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i switch_split(dup,'.',ipAddress); /* Most probably we need to add local descriptor */ + if(!local){ - /* allocating mem for local descriptor */ - if (mgUtlGrowList((void ***)&media->parms, sizeof(MgMgcoMediaPar), - &media->num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + /* allocating mem for local descriptor */ + if (mgUtlGrowList((void ***)&media->parms, sizeof(MgMgcoMediaPar), + &media->num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } #if 0 - /* Kapil - NOT REQUIRED..keeping now just for ref..will delete asap */ - media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; - /*media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_STRPAR;*/ + /* Kapil - NOT REQUIRED..keeping now just for ref..will delete asap */ + media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; + /*media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_STRPAR;*/ - printf("media->num.val[%d]\n",media->num.val); + printf("media->num.val[%d]\n",media->num.val); - stream = &media->parms[media->num.val-1]->u.stream; - stream->pres.pres = PRSNT_NODEF; - stream->pres.val = 0x01; + stream = &media->parms[media->num.val-1]->u.stream; + stream->pres.pres = PRSNT_NODEF; + stream->pres.val = 0x01; #if 0 - if(inc_med_desc->num.pres && inc_med_desc->num.val){ - /* TODO - check stream descriptor type for all medias */ - inc_strm_desc = &inc_med_desc->parms[0]->u.stream; - memcpy(&stream->streamId, &inc_strm_desc->streamId, sizeof(MgMgcoStreamId)); + if(inc_med_desc->num.pres && inc_med_desc->num.val){ + /* TODO - check stream descriptor type for all medias */ + inc_strm_desc = &inc_med_desc->parms[0]->u.stream; + memcpy(&stream->streamId, &inc_strm_desc->streamId, sizeof(MgMgcoStreamId)); + } +#endif + + MG_INIT_TOKEN_VALUE(&(stream->streamId), 1); + + + stream->sl.pres.pres = PRSNT_NODEF; + stream->sl.pres.val = 0x01; + + local = &stream->sl.local; +#endif + media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; + media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_LOCAL; + + local = &media->parms[media->num.val-1]->u.local; } -#endif - - MG_INIT_TOKEN_VALUE(&(stream->streamId), 1); - - - stream->sl.pres.pres = PRSNT_NODEF; - stream->sl.pres.val = 0x01; - - local = &stream->sl.local; -#endif - media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; - media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_LOCAL; - - local = &media->parms[media->num.val-1]->u.local; local->pres.pres = PRSNT_NODEF; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index 908b604118..e5d08c1d84 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -112,8 +112,6 @@ S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, char* term_str, int term_len, C /*MG_GETMEM(termId->name.lcl.val, termId->name.lcl.len , memCp, ret);*/ ret = mg_stack_alloc_mem((Ptr*)&termId->name.lcl.val,term_len); - printf("termId->name.lcl.val[%p]\n",termId->name.lcl.val); - if( ret != ROK) RETVALUE(ret); @@ -121,7 +119,7 @@ S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, char* term_str, int term_len, C strncpy((char*)(termId->name.lcl.val), term_str, termId->name.lcl.len); termId->name.lcl.val[termId->name.lcl.len] = '\0'; - printf("mg_fill_mgco_termid: name.lcl.val[%s], len[%d], term_str[%s], term_len[%d]\n",termId->name.lcl.val, termId->name.lcl.len, term_str,term_len); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"mg_fill_mgco_termid: name.lcl.val[%s], len[%d], term_str[%s], term_len[%d]\n",termId->name.lcl.val, termId->name.lcl.len, term_str,term_len); } @@ -742,8 +740,8 @@ void mgco_print_sdp_attr_set(CmSdpAttrSet *s) void mgco_handle_sdp_c_line(CmSdpConn *s, mg_termination_t* term, mgco_sdp_types_e sdp_type) { - char ipadd[12]; - memset(ipadd, 0, 12); + char ipadd[32]; + memset(ipadd, 0, sizeof(ipadd)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP connection line ****** \n"); @@ -770,11 +768,10 @@ void mgco_handle_sdp_c_line(CmSdpConn *s, mg_termination_t* term, mgco_sdp_types s->u.ip4.u.uniIp.b[1].val, s->u.ip4.u.uniIp.b[2].val, s->u.ip4.u.uniIp.b[3].val); - printf("Remote ip = %s \n", ipadd); /* update remote ip */ if(MG_TERM_RTP == term->type){ - term->u.rtp.remote_addr = strdup(ipadd); - printf("Update remote ip to [%s]\n", term->u.rtp.remote_addr); + term->u.rtp.remote_addr = switch_core_strdup(term->pool,ipadd); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Update remote ip to [%s]\n", term->u.rtp.remote_addr); } } } diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index e0022d8ecd..af53052fbb 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -111,8 +111,8 @@ struct mg_termination_s { megaco_profile_t *profile; /*!< Parent MG profile */ MgMgcoReqEvtDesc *active_events; /* !< active megaco events */ mg_termination_t *next; /*!< List for physical terminations */ - uint32_t flags; mg_context_t* mg_ctxt; + uint32_t flags; union { struct {