Fixed bug in PJSUA API re: account selection and Contact header for accounts
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@597 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
973d3f9b39
commit
b4a17c942d
|
@ -21,7 +21,7 @@
|
|||
#include <pj/ioqueue.h>
|
||||
|
||||
static const char *id = "config.c";
|
||||
const char *PJ_VERSION = "0.5.6.1";
|
||||
const char *PJ_VERSION = "0.5.6.5";
|
||||
|
||||
PJ_DEF(void) pj_dump_config(void)
|
||||
{
|
||||
|
|
|
@ -467,7 +467,7 @@ static pj_status_t parse_args(int argc, char *argv[],
|
|||
"in contact argument", pj_optarg));
|
||||
return PJ_EINVAL;
|
||||
}
|
||||
cur_acc->contact = pj_str(pj_optarg);
|
||||
cur_acc->force_contact = pj_str(pj_optarg);
|
||||
break;
|
||||
|
||||
case OPT_NEXT_ACCOUNT: /* Add more account. */
|
||||
|
@ -714,10 +714,10 @@ static void write_account_settings(int acc_index, pj_str_t *result)
|
|||
}
|
||||
|
||||
/* Contact */
|
||||
if (acc_cfg->contact.slen) {
|
||||
if (acc_cfg->force_contact.slen) {
|
||||
pj_ansi_sprintf(line, "--contact %.*s\n",
|
||||
(int)acc_cfg->contact.slen,
|
||||
acc_cfg->contact.ptr);
|
||||
(int)acc_cfg->force_contact.slen,
|
||||
acc_cfg->force_contact.ptr);
|
||||
pj_strcat2(result, line);
|
||||
}
|
||||
|
||||
|
|
|
@ -1022,7 +1022,7 @@ typedef struct pjsua_acc_config
|
|||
* that this field is left empty, so that the value will be calculated
|
||||
* automatically based on the transport address.
|
||||
*/
|
||||
pj_str_t contact;
|
||||
pj_str_t force_contact;
|
||||
|
||||
/**
|
||||
* Number of proxies in the proxy array below.
|
||||
|
|
|
@ -80,9 +80,11 @@ typedef struct pjsua_acc
|
|||
|
||||
int index; /**< Index in accounts array. */
|
||||
pj_str_t user_part; /**< User part of local URI. */
|
||||
pj_str_t host_part; /**< Host part of local URI. */
|
||||
pj_str_t real_contact; /**< Real contact address. */
|
||||
|
||||
pj_str_t srv_domain; /**< Host part of reg server. */
|
||||
int srv_port; /**< Port number of reg server. */
|
||||
|
||||
pjsip_regc *regc; /**< Client registration session. */
|
||||
pj_timer_entry reg_timer; /**< Registration timer. */
|
||||
pj_status_t reg_last_err; /**< Last registration error. */
|
||||
|
|
|
@ -55,7 +55,7 @@ static void copy_acc_config(pj_pool_t *pool,
|
|||
|
||||
pj_strdup_with_null(pool, &dst->id, &src->id);
|
||||
pj_strdup_with_null(pool, &dst->reg_uri, &src->reg_uri);
|
||||
pj_strdup_with_null(pool, &dst->contact, &src->contact);
|
||||
pj_strdup_with_null(pool, &dst->force_contact, &src->force_contact);
|
||||
|
||||
dst->proxy_cnt = src->proxy_cnt;
|
||||
for (i=0; i<src->proxy_cnt; ++i)
|
||||
|
@ -103,7 +103,7 @@ static pj_status_t initialize_acc(unsigned acc_id)
|
|||
pjsua_acc_config *acc_cfg = &pjsua_var.acc[acc_id].cfg;
|
||||
pjsua_acc *acc = &pjsua_var.acc[acc_id];
|
||||
pjsip_uri *uri;
|
||||
pjsip_sip_uri *sip_uri;
|
||||
pjsip_sip_uri *sip_uri, *sip_reg_uri;
|
||||
unsigned i;
|
||||
|
||||
/* Need to parse local_uri to get the elements: */
|
||||
|
@ -128,20 +128,52 @@ static pj_status_t initialize_acc(unsigned acc_id)
|
|||
|
||||
|
||||
/* Get the SIP URI object: */
|
||||
|
||||
sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(uri);
|
||||
|
||||
|
||||
/* Parse registrar URI, if any */
|
||||
if (acc_cfg->reg_uri.slen) {
|
||||
pjsip_uri *reg_uri;
|
||||
|
||||
reg_uri = pjsip_parse_uri(pjsua_var.pool, acc_cfg->reg_uri.ptr,
|
||||
acc_cfg->reg_uri.slen, 0);
|
||||
if (reg_uri == NULL) {
|
||||
pjsua_perror(THIS_FILE, "Invalid registrar URI",
|
||||
PJSIP_EINVALIDURI);
|
||||
return PJSIP_EINVALIDURI;
|
||||
}
|
||||
|
||||
/* Registrar URI MUST be a SIP or SIPS: */
|
||||
if (!PJSIP_URI_SCHEME_IS_SIP(reg_uri) &&
|
||||
!PJSIP_URI_SCHEME_IS_SIPS(reg_uri))
|
||||
{
|
||||
pjsua_perror(THIS_FILE, "Invalid registar URI",
|
||||
PJSIP_EINVALIDSCHEME);
|
||||
return PJSIP_EINVALIDSCHEME;
|
||||
}
|
||||
|
||||
sip_reg_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(reg_uri);
|
||||
|
||||
} else {
|
||||
sip_reg_uri = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Save the user and domain part. These will be used when finding an
|
||||
* account for incoming requests.
|
||||
*/
|
||||
acc->user_part = sip_uri->user;
|
||||
acc->host_part = sip_uri->host;
|
||||
acc->srv_domain = sip_uri->host;
|
||||
acc->srv_port = 0;
|
||||
|
||||
if (sip_reg_uri) {
|
||||
acc->srv_port = sip_reg_uri->port;
|
||||
}
|
||||
|
||||
/* Create Contact header if not present. */
|
||||
if (acc_cfg->contact.slen == 0) {
|
||||
acc_cfg->contact = acc_cfg->id;
|
||||
}
|
||||
//if (acc_cfg->contact.slen == 0) {
|
||||
// acc_cfg->contact = acc_cfg->id;
|
||||
//}
|
||||
|
||||
PJ_TODO(attach_account_to_transport);
|
||||
if (pjsua_var.tpdata[0].data.ptr)
|
||||
|
@ -703,14 +735,26 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url)
|
|||
|
||||
sip_uri = pjsip_uri_get_uri(uri);
|
||||
|
||||
/* Find matching domain */
|
||||
/* Find matching domain AND port */
|
||||
for (acc_id=0; acc_id<PJ_ARRAY_SIZE(pjsua_var.acc); ++acc_id) {
|
||||
if (!pjsua_var.acc[acc_id].valid)
|
||||
continue;
|
||||
if (pj_stricmp(&pjsua_var.acc[acc_id].host_part, &sip_uri->host)==0)
|
||||
if (pj_stricmp(&pjsua_var.acc[acc_id].srv_domain, &sip_uri->host)==0 &&
|
||||
pjsua_var.acc[acc_id].srv_port == sip_uri->port)
|
||||
break;
|
||||
}
|
||||
|
||||
/* If no match, try to match the domain part only */
|
||||
if (acc_id == PJ_ARRAY_SIZE(pjsua_var.acc)) {
|
||||
/* Just use default account */
|
||||
for (acc_id=0; acc_id<PJ_ARRAY_SIZE(pjsua_var.acc); ++acc_id) {
|
||||
if (!pjsua_var.acc[acc_id].valid)
|
||||
continue;
|
||||
if (pj_stricmp(&pjsua_var.acc[acc_id].srv_domain, &sip_uri->host)==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (acc_id == PJ_ARRAY_SIZE(pjsua_var.acc)) {
|
||||
/* Just use default account */
|
||||
acc_id = pjsua_var.default_acc;
|
||||
|
@ -753,7 +797,7 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
|
|||
pjsua_acc *acc = &pjsua_var.acc[acc_id];
|
||||
|
||||
if (pj_stricmp(&acc->user_part, &sip_uri->user)==0 &&
|
||||
pj_stricmp(&acc->host_part, &sip_uri->host)==0)
|
||||
pj_stricmp(&acc->srv_domain, &sip_uri->host)==0)
|
||||
{
|
||||
/* Match ! */
|
||||
PJSUA_UNLOCK();
|
||||
|
@ -766,7 +810,7 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
|
|||
|
||||
pjsua_acc *acc = &pjsua_var.acc[acc_id];
|
||||
|
||||
if (pj_stricmp(&acc->host_part, &sip_uri->host)==0) {
|
||||
if (pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) {
|
||||
/* Match ! */
|
||||
PJSUA_UNLOCK();
|
||||
return acc_id;
|
||||
|
|
|
@ -234,7 +234,7 @@ PJ_DEF(pj_status_t) pjsua_call_make_call( pjsua_acc_id acc_id,
|
|||
|
||||
/* Create outgoing dialog: */
|
||||
status = pjsip_dlg_create_uac( pjsip_ua_instance(),
|
||||
&acc->cfg.id, &acc->cfg.contact,
|
||||
&acc->cfg.id, &acc->real_contact,
|
||||
dest_uri, dest_uri, &dlg);
|
||||
if (status != PJ_SUCCESS) {
|
||||
pjsua_perror(THIS_FILE, "Dialog creation failed", status);
|
||||
|
@ -441,7 +441,7 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata)
|
|||
|
||||
/* Create dialog: */
|
||||
status = pjsip_dlg_create_uas( pjsip_ua_instance(), rdata,
|
||||
&pjsua_var.acc[acc_id].cfg.contact,
|
||||
&pjsua_var.acc[acc_id].real_contact,
|
||||
&dlg);
|
||||
if (status != PJ_SUCCESS) {
|
||||
pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL,
|
||||
|
|
|
@ -68,13 +68,15 @@ static void init_data()
|
|||
/* Notification on incoming messages */
|
||||
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
|
||||
{
|
||||
PJ_LOG(4,(THIS_FILE, "RX %d bytes %s from %s:%d:\n"
|
||||
"%s\n"
|
||||
PJ_LOG(4,(THIS_FILE, "RX %d bytes %s from %s %s:%d:\n"
|
||||
"%.*s\n"
|
||||
"--end msg--",
|
||||
rdata->msg_info.len,
|
||||
pjsip_rx_data_get_info(rdata),
|
||||
rdata->tp_info.transport->type_name,
|
||||
rdata->pkt_info.src_name,
|
||||
rdata->pkt_info.src_port,
|
||||
(int)rdata->msg_info.len,
|
||||
rdata->msg_info.msg_buf));
|
||||
|
||||
/* Always return false, otherwise messages will not get processed! */
|
||||
|
@ -91,13 +93,15 @@ static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
|
|||
* has lower priority than transport layer.
|
||||
*/
|
||||
|
||||
PJ_LOG(4,(THIS_FILE, "TX %d bytes %s to %s:%d:\n"
|
||||
"%s\n"
|
||||
PJ_LOG(4,(THIS_FILE, "TX %d bytes %s to %s %s:%d:\n"
|
||||
"%.*s\n"
|
||||
"--end msg--",
|
||||
(tdata->buf.cur - tdata->buf.start),
|
||||
pjsip_tx_data_get_info(tdata),
|
||||
tdata->tp_info.transport->type_name,
|
||||
tdata->tp_info.dst_name,
|
||||
tdata->tp_info.dst_port,
|
||||
(int)(tdata->buf.cur - tdata->buf.start),
|
||||
tdata->buf.start));
|
||||
|
||||
/* Always return success, otherwise message will not get sent! */
|
||||
|
|
|
@ -440,7 +440,7 @@ PJ_DEF(pj_status_t) pjsua_im_send( pjsua_acc_id acc_id,
|
|||
pjsip_msg_add_hdr( tdata->msg, (pjsip_hdr*)
|
||||
pjsip_generic_string_hdr_create(tdata->pool,
|
||||
&STR_CONTACT,
|
||||
&pjsua_var.acc[acc_id].cfg.contact));
|
||||
&pjsua_var.acc[acc_id].real_contact));
|
||||
|
||||
/* Create IM data to keep message details and give it back to
|
||||
* application on the callback
|
||||
|
@ -521,7 +521,7 @@ PJ_DEF(pj_status_t) pjsua_im_typing( pjsua_acc_id acc_id,
|
|||
pjsip_msg_add_hdr( tdata->msg, (pjsip_hdr*)
|
||||
pjsip_generic_string_hdr_create(tdata->pool,
|
||||
&STR_CONTACT,
|
||||
&pjsua_var.acc[acc_id].cfg.contact));
|
||||
&pjsua_var.acc[acc_id].real_contact));
|
||||
|
||||
|
||||
/* Create "application/im-iscomposing+xml" msg body. */
|
||||
|
|
|
@ -465,7 +465,7 @@ static pj_bool_t pres_on_rx_request(pjsip_rx_data *rdata)
|
|||
|
||||
/* Create UAS dialog: */
|
||||
status = pjsip_dlg_create_uas(pjsip_ua_instance(), rdata,
|
||||
&acc->cfg.contact,
|
||||
&acc->real_contact,
|
||||
&dlg);
|
||||
if (status != PJ_SUCCESS) {
|
||||
pjsua_perror(THIS_FILE,
|
||||
|
@ -770,10 +770,13 @@ static void subscribe_buddy_presence(unsigned index)
|
|||
|
||||
acc = &pjsua_var.acc[acc_id];
|
||||
|
||||
PJ_LOG(4,(THIS_FILE, "Using account %d for buddy %d subscription",
|
||||
acc_id, index));
|
||||
|
||||
/* Create UAC dialog */
|
||||
status = pjsip_dlg_create_uac( pjsip_ua_instance(),
|
||||
&acc->cfg.id,
|
||||
&acc->cfg.contact,
|
||||
&acc->real_contact,
|
||||
&buddy->uri,
|
||||
NULL, &dlg);
|
||||
if (status != PJ_SUCCESS) {
|
||||
|
|
Loading…
Reference in New Issue