summaryrefslogtreecommitdiff
path: root/pjsip/src/pjsua-lib/pjsua_acc.c
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2012-06-20 10:39:05 +0000
committerLiong Sauw Ming <ming@teluu.com>2012-06-20 10:39:05 +0000
commit8f176cf7c8af5c681b7b616500b6eb32adb28887 (patch)
treeb4aba22b23c9d59115b0f190e161933c05f6d667 /pjsip/src/pjsua-lib/pjsua_acc.c
parent253bf3c598087e7d4b11d0c0cb3940551becfcdc (diff)
Fixed #1537: Via rewrite: putting the right IP address in Via sent-by for outgoing requests
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4173 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsua-lib/pjsua_acc.c')
-rw-r--r--pjsip/src/pjsua-lib/pjsua_acc.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index 65e52640..f6c97df0 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -624,6 +624,8 @@ PJ_DEF(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id)
/* Invalidate */
acc->valid = PJ_FALSE;
acc->contact.slen = 0;
+ pj_bzero(&acc->via_addr, sizeof(acc->via_addr));
+ acc->via_tp = NULL;
/* Remove from array */
for (i=0; i<pjsua_var.acc_cnt; ++i) {
@@ -1090,6 +1092,25 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id,
cfg->reg_delay_before_refresh);
}
+ /* Allow via rewrite */
+ if (acc->cfg.allow_via_rewrite != cfg->allow_via_rewrite) {
+ if (acc->regc != NULL) {
+ if (cfg->allow_via_rewrite) {
+ pjsip_regc_set_via_sent_by(acc->regc, &acc->via_addr,
+ acc->via_tp);
+ } else
+ pjsip_regc_set_via_sent_by(acc->regc, NULL, NULL);
+ }
+ if (acc->publish_sess != NULL) {
+ if (cfg->allow_via_rewrite) {
+ pjsip_publishc_set_via_sent_by(acc->publish_sess,
+ &acc->via_addr, acc->via_tp);
+ } else
+ pjsip_publishc_set_via_sent_by(acc->publish_sess, NULL, NULL);
+ }
+ acc->cfg.allow_via_rewrite = cfg->allow_via_rewrite;
+ }
+
/* Normalize registration timeout and refresh delay */
if (acc->cfg.reg_uri.slen ) {
if (acc->cfg.reg_timeout == 0) {
@@ -1314,6 +1335,19 @@ static pj_bool_t acc_check_nat_addr(pjsua_acc *acc,
tp = param->rdata->tp_info.transport;
+ /* If allow_via_rewrite is enabled, we save the Via "sent-by" address
+ * from the response.
+ */
+ if (acc->cfg.allow_via_rewrite &&
+ (acc->via_addr.host.slen == 0 || acc->via_tp != tp))
+ {
+ via = param->rdata->msg_info.via;
+ if (pj_strcmp(&acc->via_addr.host, &via->sent_by.host))
+ pj_strdup(acc->pool, &acc->via_addr.host, &via->sent_by.host);
+ acc->via_addr.port = via->sent_by.port;
+ acc->via_tp = tp;
+ }
+
/* Only update if account is configured to auto-update */
if (acc->cfg.allow_contact_rewrite == PJ_FALSE)
return PJ_FALSE;
@@ -2176,6 +2210,14 @@ PJ_DEF(pj_status_t) pjsua_acc_set_registration( pjsua_acc_id acc_id,
}
if (status == PJ_SUCCESS) {
+ if (pjsua_var.acc[acc_id].cfg.allow_via_rewrite &&
+ pjsua_var.acc[acc_id].via_addr.host.slen > 0)
+ {
+ pjsip_regc_set_via_sent_by(pjsua_var.acc[acc_id].regc,
+ &pjsua_var.acc[acc_id].via_addr,
+ pjsua_var.acc[acc_id].via_tp);
+ }
+
//pjsua_process_msg_data(tdata, NULL);
status = pjsip_regc_send( pjsua_var.acc[acc_id].regc, tdata );
}
@@ -2541,6 +2583,14 @@ PJ_DEF(pj_status_t) pjsua_acc_create_request(pjsua_acc_id acc_id,
pjsip_tx_data_set_transport(tdata, &tp_sel);
}
+ /* If via_addr is set, use this address for the Via header. */
+ if (pjsua_var.acc[acc_id].cfg.allow_via_rewrite &&
+ pjsua_var.acc[acc_id].via_addr.host.slen > 0)
+ {
+ tdata->via_addr = pjsua_var.acc[acc_id].via_addr;
+ tdata->via_tp = pjsua_var.acc[acc_id].via_tp;
+ }
+
/* Done */
*p_tdata = tdata;
return PJ_SUCCESS;