提交 d7e4b509 authored 作者: Kapil's avatar Kapil

integrating term/context alloc/delete api to megaco command handler code

上级 63c53a85
......@@ -167,6 +167,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha
term->pool = pool;
term->type = termtype;
term->active_events = NULL;
term->profile = profile;
if (termtype == MG_TERM_RTP) {
/* Fill in local address and reserve an rtp port */
......@@ -212,6 +213,23 @@ void megaco_termination_destroy(mg_termination_t *term)
switch_core_destroy_memory_pool(&term->pool);
}
switch_status_t megaco_context_is_term_present(mg_context_t *ctx, mg_termination_t *term)
{
switch_assert(ctx != NULL);
switch_assert(term != NULL);
if (ctx->terminations[0] && (term == ctx->terminations[0])) {
return SWITCH_STATUS_SUCCESS;
}
if (ctx->terminations[1] && (term == ctx->terminations[1])) {
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination_t *term)
{
......@@ -247,6 +265,21 @@ switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination
}
switch_status_t megaco_context_sub_all_termination(mg_context_t *ctx)
{
switch_assert(ctx != NULL);
/* Channels will automatically go to park once the bridge ends */
if (ctx->terminations[0]) {
megaco_termination_destroy(ctx->terminations[0]);
ctx->terminations[0] = NULL;
} else if (ctx->terminations[1]) {
megaco_termination_destroy(ctx->terminations[1]);
}
return SWITCH_STATUS_SUCCESS;
}
switch_status_t megaco_context_sub_termination(mg_context_t *ctx, mg_termination_t *term)
{
switch_assert(ctx != NULL);
......@@ -315,7 +348,8 @@ mg_context_t *megaco_get_context(megaco_profile_t *profile, uint32_t context_id)
mg_context_t *megaco_choose_context(megaco_profile_t *profile)
{
mg_context_t *ctx;
int i = 0x0;;
int i = 0x0;
int j = 0x0;
switch_thread_rwlock_wrlock(profile->contexts_rwlock);
/* Try the next one */
......@@ -332,6 +366,9 @@ mg_context_t *megaco_choose_context(megaco_profile_t *profile)
ctx = malloc(sizeof *ctx);
ctx->context_id = profile->next_context_id;
ctx->profile = profile;
for(j = 0; j< MG_CONTEXT_MAX_TERMS; j++){
ctx->terminations[j] = NULL;
}
if (!profile->contexts[i]) {
profile->contexts[i] = ctx;
......
......@@ -132,6 +132,7 @@ void handle_mg_alarm(Pst *pst, MgMngmt *sta);
void handle_tucl_alarm(Pst *pst, HiMngmt *sta);
int mg_enable_logging(void);
int mg_disable_logging(void);
void mg_util_set_err_string ( MgStr *errTxt, char* str);
switch_status_t sng_mgco_cfg(megaco_profile_t* profile);
......
......@@ -318,6 +318,13 @@ void mg_util_set_txn_string(MgStr *errTxt, U32 *txnId)
}
/*****************************************************************************************************************************/
void mg_util_set_err_string ( MgStr *errTxt, char* str)
{
MG_ZERO((errTxt->val), sizeof(errTxt->val));
errTxt->len = strlen(str);
strcpy((char*)&errTxt->val, str);
}
/*****************************************************************************************************************************/
void mg_util_set_ctxt_string ( MgStr *errTxt, MgMgcoContextId *ctxtId)
{
......
......@@ -500,7 +500,7 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
/*If term type is other then check if that term is configured with us..for term type CHOOSE/ALL , no need to check */
if (MGT_TERMID_OTHER == termId->type.val){
if(SWITCH_STATUS_FALSE != mg_stack_termination_is_in_service((char*)termId->name.lcl.val, termId->name.lcl.len)){
if(SWITCH_STATUS_FALSE == mg_stack_termination_is_in_service((char*)termId->name.lcl.val, termId->name.lcl.len)){
mg_util_set_term_string(&errTxt, termId);
err_code = MGT_MGCO_RSP_CODE_UNKNOWN_TERM_ID;
goto error;
......
......@@ -210,6 +210,8 @@ void mg_rtp_release_id(megaco_profile_t *profile, uint32_t id);
mg_context_t *megaco_get_context(megaco_profile_t *profile, uint32_t context_id);
mg_context_t *megaco_choose_context(megaco_profile_t *profile);
void megaco_release_context(mg_context_t *ctx);
switch_status_t megaco_context_sub_termination(mg_context_t *ctx, mg_termination_t *term);
switch_status_t megaco_context_sub_all_termination(mg_context_t *ctx);
mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix);
mg_termination_t *megaco_find_termination(megaco_profile_t *profile, const char *name);
......@@ -225,6 +227,8 @@ switch_status_t mg_config_cleanup(megaco_profile_t* profile);
switch_status_t mg_peer_config_cleanup(mg_peer_profile_t* profile);
switch_status_t megaco_peer_profile_destroy(mg_peer_profile_t **profile);
switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stream);
switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination_t *term);
switch_status_t megaco_context_is_term_present(mg_context_t *ctx, mg_termination_t *term);
#endif /* MOD_MEGACO_H */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论