Skip to content

Commit

Permalink
uac: coherent indentation of code for replace from/to values
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Oct 31, 2016
1 parent 1a2918e commit 00571fd
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions modules/uac/replace.c
Expand Up @@ -290,13 +290,16 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
avp_value.s.len = p - body->body.s + ((p[i]=='>') ? (i+1) : 0) ;
avp_value.s.s=body->body.s;

LM_DBG("value to store is is '%.*s' and len is '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("value to store is is '%.*s' and len is '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);

if(check_from) {
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_from_avp_type, restore_from_avp_name, avp_value);
} else {
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_to_avp_type, restore_to_avp_name, avp_value);
}
}
Expand All @@ -309,9 +312,10 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
/* first remove the existing display */
if ( body->display.len)
{
LM_DBG("removing display [%.*s]\n", body->display.len,body->display.s);
LM_DBG("removing display [%.*s]\n",
body->display.len, body->display.s);
/* build del lump */
l = del_lump( msg, body->display.s-msg->buf, body->display.len, 0);
l = del_lump(msg, body->display.s-msg->buf, body->display.len, 0);
if (l==0)
{
LM_ERR("display del lump failed\n");
Expand Down Expand Up @@ -404,10 +408,13 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
goto error;
}
LM_DBG("Stored <%.*s> var in dialog with value %.*s\n",
dlgvar_names[0].len, dlgvar_names[0].s, body->uri.len, body->uri.s);
dlgvar_names[0].len, dlgvar_names[0].s,
body->uri.len, body->uri.s);

if (dlg_api.register_dlgcb(dlg, DLGCB_REQ_WITHIN|DLGCB_CONFIRMED|DLGCB_TERMINATED,
(void*)(unsigned long)replace_callback, (void*)(unsigned long)uac_flag, 0) != 0) {
if (dlg_api.register_dlgcb(dlg,
DLGCB_REQ_WITHIN|DLGCB_CONFIRMED|DLGCB_TERMINATED,
(void*)(unsigned long)replace_callback,
(void*)(unsigned long)uac_flag, 0) != 0) {
LM_ERR("cannot register callback\n");
dlg_api.release_dlg(dlg);
goto error;
Expand Down Expand Up @@ -513,7 +520,8 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
* return 0 - restored
* -1 - not restored or error
*/
int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check_from)
int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp,
int check_from)
{
struct lump* l;
str param_val;
Expand Down Expand Up @@ -552,7 +560,8 @@ int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check
LM_ERR("no more pkg mem\n");
goto failed;
}
add_to_rr.len = sprintf(add_to_rr.s, ";%.*s=%.*s", rr_param->len,rr_param->s,param_val.len,param_val.s);
add_to_rr.len = sprintf(add_to_rr.s, ";%.*s=%.*s",
rr_param->len, rr_param->s, param_val.len, param_val.s);

if ( uac_rrb.add_rr_param(msg, &add_to_rr)!=0 ) {
LM_ERR("add rr param failed\n");
Expand Down Expand Up @@ -598,10 +607,12 @@ int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check
avp_value.s.s=old_body->body.s;

if(flag==FL_USE_UAC_FROM) {
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_from_avp_type, restore_from_avp_name, avp_value);
} else {
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_to_avp_type, restore_to_avp_name, avp_value);
}
}
Expand Down Expand Up @@ -770,7 +781,8 @@ void restore_uris_reply(struct cell* t, int type, struct tmcb_params *p)

avp_value.s.len=0;
if(restore_from_avp.s) {
search_first_avp(restore_from_avp_type, restore_from_avp_name, &avp_value,0);
search_first_avp(restore_from_avp_type, restore_from_avp_name,
&avp_value,0);
}

if (restore_uri_reply( rpl, rpl->from, req->from, &avp_value.s)) {
Expand All @@ -789,7 +801,8 @@ void restore_uris_reply(struct cell* t, int type, struct tmcb_params *p)

avp_value.s.len=0;
if(restore_to_avp.s) {
search_first_avp(restore_to_avp_type, restore_to_avp_name, &avp_value,0);
search_first_avp(restore_to_avp_type, restore_to_avp_name,
&avp_value, 0);
}

if (restore_uri_reply( rpl, rpl->to, req->to, &avp_value.s)) {
Expand Down Expand Up @@ -825,8 +838,9 @@ static void replace_callback(struct dlg_cell *dlg, int type,
dlgvar_names = (uac_flag==FL_USE_UAC_FROM)?from_dlgvar:to_dlgvar;

/* check the request direction */
if ( ((uac_flag == FL_USE_UAC_TO) && _params->direction == DLG_DIR_DOWNSTREAM) ||
((uac_flag != FL_USE_UAC_TO) && _params->direction == DLG_DIR_UPSTREAM) ) {
if ( ((uac_flag == FL_USE_UAC_TO) && _params->direction == DLG_DIR_DOWNSTREAM)
|| ((uac_flag != FL_USE_UAC_TO)
&& _params->direction == DLG_DIR_UPSTREAM) ) {
/* replace the TO URI */
if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {
LM_ERR("failed to parse TO hdr\n");
Expand Down Expand Up @@ -880,7 +894,8 @@ static void replace_callback(struct dlg_cell *dlg, int type,
goto free;
}

/* register tm callback to change replies but only if not registered earlier */
/* register tm callback to change replies,
* but only if not registered earlier */
if (!(msg->msg_flags & (FL_USE_UAC_FROM|FL_USE_UAC_TO)) &&
uac_tmb.register_tmcb( msg, 0, TMCB_RESPONSE_IN,
restore_uris_reply, 0, 0) != 1 ) {
Expand Down

0 comments on commit 00571fd

Please sign in to comment.