summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-02-22 14:46:55 +0000
committerBenny Prijono <bennylp@teluu.com>2007-02-22 14:46:55 +0000
commitd7bfd38fd9a244a92f74cb2c0cc8ae2bbc056e20 (patch)
tree5b6614cd50960e524e2fc4e12b3f95fac42f5171
parent7adab49c698d7f6d31b22a8afa74bbac0ca74cdf (diff)
Fixed ticket #131: dialog automatically insert Contact header when sending 3xx response (thanks Hozjan Vladimir for reporting)
git-svn-id: http://svn.pjsip.org/repos/pjproject/branches/pjproject-0.5-stable@994 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib/src/pj/config.c2
-rw-r--r--pjsip-apps/src/pjsua/pjsua_app.c24
-rw-r--r--pjsip/src/pjsip/sip_dialog.c29
3 files changed, 47 insertions, 8 deletions
diff --git a/pjlib/src/pj/config.c b/pjlib/src/pj/config.c
index e576b9fe..d317652a 100644
--- a/pjlib/src/pj/config.c
+++ b/pjlib/src/pj/config.c
@@ -21,7 +21,7 @@
#include <pj/ioqueue.h>
static const char *id = "config.c";
-const char *PJ_VERSION = "0.5.10.1";
+const char *PJ_VERSION = "0.5.10.2-pre";
PJ_DEF(void) pj_dump_config(void)
{
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c
index 1417b81f..928ed1c1 100644
--- a/pjsip-apps/src/pjsua/pjsua_app.c
+++ b/pjsip-apps/src/pjsua/pjsua_app.c
@@ -2284,12 +2284,32 @@ void console_app_main(const pj_str_t *uri_to_call)
continue;
} else {
+ int st_code;
+ char contact[120];
+ pj_str_t hname = { "Contact", 7 };
+ pj_str_t hvalue;
+ pjsip_generic_string_hdr hcontact;
+ pjsua_msg_data msg_data;
+
if (!simple_input("Answer with code (100-699)", buf, sizeof(buf)))
continue;
- if (my_atoi(buf) < 100)
+ st_code = my_atoi(buf);
+ if (st_code < 100)
continue;
+ pjsua_msg_data_init(&msg_data);
+
+ if (st_code/100 == 3) {
+ if (!simple_input("Enter URL to be put in Contact",
+ contact, sizeof(contact)))
+ continue;
+ hvalue = pj_str(contact);
+ pjsip_generic_string_hdr_init2(&hcontact, &hname, &hvalue);
+
+ pj_list_push_back(&msg_data.hdr_list, &hcontact);
+ }
+
/*
* Must check again!
* Call may have been disconnected while we're waiting for
@@ -2301,7 +2321,7 @@ void console_app_main(const pj_str_t *uri_to_call)
continue;
}
- pjsua_call_answer(current_call, my_atoi(buf), NULL, NULL);
+ pjsua_call_answer(current_call, st_code, NULL, &msg_data);
}
break;
diff --git a/pjsip/src/pjsip/sip_dialog.c b/pjsip/src/pjsip/sip_dialog.c
index dc9d8ffa..0e4dfc4d 100644
--- a/pjsip/src/pjsip/sip_dialog.c
+++ b/pjsip/src/pjsip/sip_dialog.c
@@ -1150,6 +1150,7 @@ on_error:
/* Add standard headers for certain types of response */
static void dlg_beautify_response(pjsip_dialog *dlg,
+ pj_bool_t add_headers,
int st_code,
pjsip_tx_data *tdata)
{
@@ -1164,13 +1165,17 @@ static void dlg_beautify_response(pjsip_dialog *dlg,
st_class = st_code / 100;
/* Contact, Allow, Supported header. */
- if (pjsip_method_creates_dialog(&cseq->method)) {
+ if (add_headers && pjsip_method_creates_dialog(&cseq->method)) {
/* Add Contact header for 1xx, 2xx, 3xx and 485 response. */
if (st_class==2 || st_class==3 || (st_class==1 && st_code != 100) ||
st_code==485)
{
+ pj_str_t hcontact = { "Contact", 7 };
+
/* Add contact header only if one is not present. */
- if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0) {
+ if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0 &&
+ pjsip_msg_find_hdr_by_name(tdata->msg, &hcontact, NULL) == 0)
+ {
hdr = pjsip_hdr_clone(tdata->pool, dlg->local.contact);
pjsip_msg_add_hdr(tdata->msg, hdr);
}
@@ -1241,7 +1246,7 @@ PJ_DEF(pj_status_t) pjsip_dlg_create_response( pjsip_dialog *dlg,
/* Lock the dialog. */
pjsip_dlg_inc_lock(dlg);
- dlg_beautify_response(dlg, st_code, tdata);
+ dlg_beautify_response(dlg, PJ_FALSE, st_code, tdata);
/* Unlock the dialog. */
pjsip_dlg_dec_lock(dlg);
@@ -1259,7 +1264,8 @@ PJ_DEF(pj_status_t) pjsip_dlg_modify_response( pjsip_dialog *dlg,
int st_code,
const pj_str_t *st_text)
{
-
+ pjsip_hdr *hdr;
+
PJ_ASSERT_RETURN(dlg && tdata && tdata->msg, PJ_EINVAL);
PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_RESPONSE_MSG,
PJSIP_ENOTRESPONSEMSG);
@@ -1276,7 +1282,15 @@ PJ_DEF(pj_status_t) pjsip_dlg_modify_response( pjsip_dialog *dlg,
tdata->msg->line.status.reason = *pjsip_get_status_text(st_code);
}
- dlg_beautify_response(dlg, st_code, tdata);
+ /* Remove existing Contact header (without this, when dialog sent
+ * 180 and then 302, the Contact in 302 will not get updated).
+ */
+ hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
+ if (hdr)
+ pj_list_erase(hdr);
+
+ /* Add tag etc. if necessary */
+ dlg_beautify_response(dlg, PJ_FALSE, st_code, tdata);
/* Must add reference counter, since tsx_send_msg() will decrement it */
@@ -1325,6 +1339,11 @@ PJ_DEF(pj_status_t) pjsip_dlg_send_response( pjsip_dialog *dlg,
/* Must acquire dialog first, to prevent deadlock */
pjsip_dlg_inc_lock(dlg);
+ /* Last chance to add mandatory headers before the response is
+ * sent.
+ */
+ dlg_beautify_response(dlg, PJ_TRUE, tdata->msg->line.status.code, tdata);
+
/* If the dialog is locked to transport, make sure that transaction
* is locked to the same transport too.
*/