Skip to content

Commit

Permalink
registrar library: Fix nat flag management
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Apr 21, 2017
1 parent adb59dd commit c9901f6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
9 changes: 5 additions & 4 deletions lib/reg/ci.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
/*! \brief
* Fills the common part (for all contacts) of the info structure
*/
ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c,
unsigned int _e, unsigned int _f, unsigned int _flags)
ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c, unsigned int _e,
unsigned int _f, unsigned int _nat_flag, unsigned int _reg_flags)
{
static ucontact_info_t ci;
static str no_ua = str_init("n/a");
Expand Down Expand Up @@ -83,8 +83,8 @@ ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c,
}

/* extract Path headers */
if ( _flags&REG_SAVE_PATH_FLAG ) {
if (build_path_vector(_m, &path, &path_received, _flags) < 0) {
if (_reg_flags & REG_SAVE_PATH_FLAG) {
if (build_path_vector(_m, &path, &path_received, _reg_flags) < 0) {
rerrno = R_PARSE_PATH;
goto error;
}
Expand All @@ -106,6 +106,7 @@ ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c,

/* get received */
if (path_received.len && path_received.s) {
ci.cflags |= _nat_flag;
ci.received = path_received;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/reg/ci.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern unsigned short attr_avp_type;
extern int mct_avp_name;
extern unsigned short mct_avp_type;

ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c,
unsigned int _e, unsigned int _f, unsigned int _flags);
ucontact_info_t *pack_ci(struct sip_msg* _m, contact_t* _c, unsigned int _e,
unsigned int _f, unsigned int _nat_flag, unsigned int _reg_flags);

#endif /* __LIB_REG_CI__ */
26 changes: 12 additions & 14 deletions modules/mid_registrar/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,13 @@ static inline int insert_rpl_contacts(struct sip_msg *req, struct sip_msg* rpl,
update_usrloc:
c = NULL;
/* pack the contact_info */
ci = pack_ci(req, __c, e + get_act_time(), cflags, mri->flags);
ci = pack_ci(req, __c, e + get_act_time(), cflags,
ul_api.nat_flag, mri->flags);
if (ci == NULL) {
LM_ERR("failed to extract contact info\n");
goto error;
}
ci->expires_out = e_out;
ci->cflags |= ul_api.nat_flag;

if ((r->contacts==0 ||
ul_api.get_ucontact(r, &__c->uri, ci->callid, ci->cseq+1, &c)!=0) && e > 0) {
Expand Down Expand Up @@ -1039,13 +1039,13 @@ static inline int insert_req_contacts(struct sip_msg *req, struct sip_msg* rpl,
update_usrloc:
c = NULL;
/* pack the contact_info */
ci = pack_ci(req, __c, e + get_act_time(), cflags, mri->flags);
ci = pack_ci(req, __c, e + get_act_time(), cflags,
ul_api.nat_flag, mri->flags);
if (ci == NULL) {
LM_ERR("failed to extract contact info\n");
goto error;
}
ci->expires_out = e_out;
ci->cflags |= ul_api.nat_flag;

if ((r->contacts == NULL ||
ul_api.get_ucontact(r, &__c->uri, ci->callid, ci->cseq+1, &c) != 0) && e > 0) {
Expand Down Expand Up @@ -1710,11 +1710,10 @@ static int process_contacts_by_ct(struct sip_msg *msg, urecord_t *urec,
cflags = (flags&REG_SAVE_MEMORY_FLAG)?FL_MEM:FL_NONE;

/* pack the contact_info */
if ( (ci=pack_ci(msg, 0, 0, 0, cflags))==0 ) {
if ( (ci=pack_ci(msg, 0, 0, 0, ul_api.nat_flag, cflags))==0 ) {
LM_ERR("failed to initial pack contact info\n");
return -1;
}
ci->cflags |= ul_api.nat_flag;

/* if there are any new contacts, we must return a "forward" code */
for (ct = get_first_contact(msg); ct; ct = get_next_contact(ct)) {
Expand Down Expand Up @@ -1744,14 +1743,14 @@ static int process_contacts_by_ct(struct sip_msg *msg, urecord_t *urec,
return 1;
} else {
/* pack the contact specific info */
ci = pack_ci(msg, ct, e + get_act_time(), 0, cflags);
ci = pack_ci(msg, ct, e + get_act_time(), 0,
ul_api.nat_flag, cflags);
if (!ci) {
LM_ERR("failed to pack contact specific info\n");
rerrno = R_UL_UPD_C;
return -1;
}
ci->expires_out = c->expires_out;
ci->cflags |= ul_api.nat_flag;

if (ul_api.update_ucontact(urec, c, ci, 0) < 0) {
rerrno = R_UL_UPD_C;
Expand Down Expand Up @@ -1832,11 +1831,10 @@ static int process_contacts_by_aor(struct sip_msg *req, urecord_t *urec,
cflags = (flags&REG_SAVE_MEMORY_FLAG)?FL_MEM:FL_NONE;

/* pack the contact_info */
if ( (ci=pack_ci(req, 0, 0, 0, cflags))==0 ) {
if ( (ci=pack_ci(req, 0, 0, 0, ul_api.nat_flag, cflags))==0 ) {
LM_ERR("failed to initial pack contact info\n");
return -1;
}
ci->cflags |= ul_api.nat_flag;

/* if there are any new contacts, we must return a "forward" code */
for (ct = get_first_contact(req); ct; ct = get_next_contact(ct)) {
Expand Down Expand Up @@ -1869,14 +1867,14 @@ static int process_contacts_by_aor(struct sip_msg *req, urecord_t *urec,
set_ct(cinfo);

/* pack the contact specific info */
ci = pack_ci(req, ct, e + get_act_time(), 0, cflags);
ci = pack_ci(req, ct, e + get_act_time(), 0,
ul_api.nat_flag, cflags);
if (!ci) {
LM_ERR("failed to pack contact specific info\n");
rerrno = R_UL_UPD_C;
return -1;
}
ci->expires_out = c->expires_out;
ci->cflags |= ul_api.nat_flag;

if (ul_api.update_ucontact(urec, c, ci, 0) < 0) {
rerrno = R_UL_UPD_C;
Expand All @@ -1893,14 +1891,14 @@ static int process_contacts_by_aor(struct sip_msg *req, urecord_t *urec,
set_ct(cinfo);

/* pack the contact specific info */
ci = pack_ci(req, ct, e + get_act_time(), 0, cflags);
ci = pack_ci(req, ct, e + get_act_time(), 0,
ul_api.nat_flag, cflags);
if (!ci) {
LM_ERR("failed to pack contact specific info\n");
rerrno = R_UL_UPD_C;
return -1;
}
ci->expires_out = e_out;
ci->cflags |= ul_api.nat_flag;

if (ul_api.insert_ucontact(urec, &ct->uri, ci, &c, 0) < 0) {
rerrno = R_UL_INS_C;
Expand Down
11 changes: 5 additions & 6 deletions modules/registrar/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ static inline int insert_contacts(struct sip_msg* _m, contact_t* _c,
}

/* pack the contact_info */
if ( (ci=pack_ci( (ci==0)?_m:0, _c, e, cflags, _sctx->flags))==0 ) {
if ( (ci=pack_ci( (ci==0)?_m:0, _c, e, cflags,
ul.nat_flag, _sctx->flags))==0 ) {
LM_ERR("failed to extract contact info\n");
goto error;
}

ci->cflags |= ul.nat_flag;
set_sock_hdr(_m, ci, _sctx->flags);

if ( r->contacts==0 ||
Expand Down Expand Up @@ -351,12 +351,11 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
cflags = (_sctx->flags&REG_SAVE_MEMORY_FLAG)?FL_MEM:FL_NONE;

/* pack the contact_info */
if ( (ci=pack_ci( _m, 0, 0, cflags, _sctx->flags))==0 ) {
if ( (ci=pack_ci( _m, 0, 0, cflags, ul.nat_flag, _sctx->flags))==0 ) {
LM_ERR("failed to initial pack contact info\n");
goto error;
}

ci->cflags |= ul.nat_flag;
set_sock_hdr(_m, ci, _sctx->flags);

/* count how many contacts we have right now */
Expand Down Expand Up @@ -425,7 +424,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
}

/* pack the contact_info */
if ( (ci=pack_ci( 0, _c, e, 0, _sctx->flags))==0 ) {
if ( (ci=pack_ci( 0, _c, e, 0, ul.nat_flag, _sctx->flags))==0 ) {
LM_ERR("failed to extract contact info\n");
goto error;
}
Expand Down Expand Up @@ -486,7 +485,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
}

/* pack the contact specific info */
if ( (ci=pack_ci( 0, _c, e, 0, _sctx->flags))==0 ) {
if ( (ci=pack_ci( 0, _c, e, 0, ul.nat_flag, _sctx->flags))==0 ) {
LM_ERR("failed to pack contact specific info\n");
goto error;
}
Expand Down

0 comments on commit c9901f6

Please sign in to comment.