adding code to send error response back to MG stack,in case of any app

failure
This commit is contained in:
kapil 2012-06-29 21:51:15 +05:30
parent 8de2568c3e
commit cd61d0b59e
3 changed files with 124 additions and 3 deletions

View File

@ -43,6 +43,35 @@ typedef enum{
(_val == SNG_MG_ENCODING_BINARY)?"SNG_MG_ENCODING_BINARY":\
"SNG_MG_ENCODING_NONE")
typedef struct _mgStr
{
U8 len;
U8 val[128];
} MgStr;
#define MG_TXN_INVALID 0
#define mg_zero(_buf, _size) {cmMemset((U8 *)(_buf), 0, _size);}
/* Set pres field */
#define mg_util_set_pres(_pres) \
(_pres) = PRSNT_NODEF;
/* Set token value */
#define mg_util_set_val_pres(tkn,_val) \
mg_util_set_pres((tkn).pres); \
(tkn).val = _val;
#define mg_mem_copy(_dst, _src, _len) \
cmMemcpy((U8*) (_dst), (const U8*) (_src), _len)
#define mg_get_mem(_memPtr, _size, _allocPtr, ret) \
{ \
(*ret) = cmGetMem((Ptr *)(_memPtr),(_size) ,(Ptr *)&(_allocPtr)); \
}
void handle_sng_log(uint8_t level, char *fmt, ...);
void handle_mgco_sta_ind(Pst *pst, SuId suId, MgMgtSta* msg);

View File

@ -153,7 +153,7 @@ static switch_xml_config_item_t *get_peer_instructions(mg_peer_profile_t *profil
/* parameter name type reloadable pointer default value options structure */
SWITCH_CONFIG_ITEM("ip", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->ipaddr, "", &switch_config_string_strdup, "", "Peer IP"),
SWITCH_CONFIG_ITEM("port", SWITCH_CONFIG_STRING, 0, &profile->port, "", &switch_config_string_strdup, "", "peer port"),
SWITCH_CONFIG_ITEM("encoding-scheme", SWITCH_CONFIG_STRING, 0, &profile->encoding_type, "TEXT", &switch_config_string_strdup, "", "peer encoding type"),
SWITCH_CONFIG_ITEM("encoding-scheme", SWITCH_CONFIG_STRING, 0, &profile->encoding_type, "", &switch_config_string_strdup, "", "peer encoding type"),
SWITCH_CONFIG_ITEM("transport-type", SWITCH_CONFIG_STRING, 0, &profile->transport_type, "", &switch_config_string_strdup, "", "peer transport type "),
SWITCH_CONFIG_ITEM("message-identifier", SWITCH_CONFIG_STRING, 0, &profile->mid, "", &switch_config_string_strdup, "", "peer message identifier "),
SWITCH_CONFIG_ITEM_END()
@ -239,6 +239,7 @@ 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);
return SWITCH_STATUS_SUCCESS;
}
@ -256,7 +257,7 @@ static switch_status_t modify_mid(char* mid)
sprintf(mid,"[%s]",dup);
}else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
free(dup);
free(dup);
return SWITCH_STATUS_FALSE;
}

View File

@ -24,6 +24,8 @@ switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
switch_status_t mg_stack_alloc_mem( Ptr* _memPtr, Size _memSize );
switch_status_t mg_send_add_rsp(SuId suId, MgMgcoCommand *req);
S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, CONSTANT U8 *str, CmMemListCp *memCp);
void mg_util_set_txn_string(MgStr *errTxt, U32 *txnId);
switch_status_t mg_build_mgco_err_request(MgMgcoInd **errcmd,U32 trans_id, MgMgcoContextId *ctxt_id, U32 err, MgStr *errTxt);
/**************************************************************************************************************/
@ -410,6 +412,10 @@ void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg)
void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
{
uint32_t txn_id = 0x00;
MgMgcoInd *mgErr;
MgStr errTxt;
MgMgcoContextId ctxtId;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: Received Command Type[%s] \n", __PRETTY_FUNCTION__, PRNT_MG_CMD_TYPE(cmd->cmdType.val));
@ -419,7 +425,20 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: Transaction Id not present, rejecting\n", __PRETTY_FUNCTION__);
/*TODO - can invoke "MgUiMgtMgcoErrReq" to report error to MEGACO stack */
/*-- Send Error to MG Stack --*/
mg_zero(&ctxtId, sizeof(MgMgcoContextId));
ctxtId.type.pres = NOTPRSNT;
ctxtId.val.pres = NOTPRSNT;
mg_util_set_txn_string(&errTxt, &txn_id);
if (SWITCH_STATUS_FALSE == mg_build_mgco_err_request(&mgErr, txn_id, &ctxtId,
MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER, &errTxt))
{
sng_mgco_send_err(suId, mgErr);
}
/* deallocate the msg */
mg_free_cmd(cmd);
return ;
@ -908,6 +927,78 @@ S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, CONSTANT U8 *str, CmMemListCp
RETVALUE(ROK);
}
switch_status_t mg_build_mgco_err_request(MgMgcoInd **errcmd,U32 trans_id, MgMgcoContextId *ctxt_id, U32 err, MgStr *errTxt)
{
MgMgcoInd *mgErr;
S16 ret;
mgErr = NULLP;
ret = ROK;
/* Allocate for AG error */
mg_stack_alloc_mem((Ptr*)&mgErr, sizeof(MgMgcoInd));
if (NULL == mgErr) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " mg_build_mgco_err_request Failed : memory alloc \n");
return SWITCH_STATUS_FALSE;
}
/* Set transaction Id in the error request */
mg_util_set_val_pres(mgErr->transId, trans_id);
/* Copy the context Id */
mg_mem_copy(&mgErr->cntxtId,
ctxt_id,
sizeof(MgMgcoContextId));
/* Set the peerId */
mgErr->peerId.pres = NOTPRSNT;
/* Set the error code */
mg_util_set_pres(mgErr->err.pres.pres);
mg_util_set_pres(mgErr->err.code.pres);
mg_util_set_val_pres(mgErr->err.code, err);
if(errTxt->len)
{
mg_get_mem(&mgErr->memCp, (errTxt->len)*sizeof(U8), mgErr->err.text.val, &ret);
if (ROK != ret) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " mg_build_mgco_err_request Failed : memory alloc \n");
return SWITCH_STATUS_FALSE;
}
mgErr->err.text.pres = PRSNT_NODEF;
mgErr->err.text.len = errTxt->len;
mg_mem_copy(mgErr->err.text.val, errTxt->val, errTxt->len);
}
/* Set the output value */
*errcmd = mgErr;
return SWITCH_STATUS_SUCCESS;
}
void mg_util_set_txn_string(MgStr *errTxt, U32 *txnId)
{
mg_zero((errTxt->val), sizeof(errTxt->val));
errTxt->len = 0;
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
if (MG_TXN_INVALID == txnId )
{
mg_mem_copy((&errTxt->val[errTxt->len]), "TransactionId=0", 15);
errTxt->len += 15;
}
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s:"
"info, error-text is: %s\n", __PRETTY_FUNCTION__,errTxt->val);
}
/*****************************************************************************************************************************/