Close #1675: Added callback to allow application to specify account to handle incoming message.

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@4534 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Nanang Izzuddin 2013-06-13 08:56:51 +00:00
parent 590f4e221b
commit 5c4b102f97
2 changed files with 47 additions and 13 deletions

View File

@ -1276,6 +1276,27 @@ typedef struct pjsua_callback
pjmedia_transport *base_tp,
unsigned flags);
/**
* This callback can be used by application to override the account
* to be used to handle an incoming message. Initially, the account to
* be used will be calculated automatically by the library. This initial
* account will be used if application does not implement this callback,
* or application sets an invalid account upon returning from this
* callback.
*
* Note that currently the incoming messages requiring account assignment
* are INVITE, MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback
* may be called before the callback of the SIP event itself, i.e:
* incoming call, pager, subscription, or unsolicited-event.
*
* @param rdata The incoming message.
* @param acc_id On input, initial account ID calculated automatically
* by the library. On output, the account ID prefered
* by application to handle the incoming message.
*/
void (*on_acc_find_for_incoming)(const pjsip_rx_data *rdata,
pjsua_acc_id* acc_id);
} pjsua_callback;

View File

@ -2617,6 +2617,7 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
{
pjsip_uri *uri;
pjsip_sip_uri *sip_uri;
pjsua_acc_id id = PJSUA_INVALID_ID;
unsigned i;
/* Check that there's at least one account configured */
@ -2624,6 +2625,8 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
uri = rdata->msg_info.to->uri;
PJSUA_LOCK();
/* Use Req URI if To URI is not SIP */
if (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
!PJSIP_URI_SCHEME_IS_SIPS(uri))
@ -2631,19 +2634,16 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG)
uri = rdata->msg_info.msg->line.req.uri;
else
return pjsua_var.default_acc;
goto on_return;
}
/* Just return default account if both To and Req URI are not SIP: */
if (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
!PJSIP_URI_SCHEME_IS_SIPS(uri))
{
return pjsua_var.default_acc;
goto on_return;
}
PJSUA_LOCK();
sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri);
/* Find account which has matching username and domain. */
@ -2655,8 +2655,8 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
pj_stricmp(&acc->srv_domain, &sip_uri->host)==0)
{
/* Match ! */
PJSUA_UNLOCK();
return acc_id;
id = acc_id;
goto on_return;
}
}
@ -2667,8 +2667,8 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
if (acc->valid && pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) {
/* Match ! */
PJSUA_UNLOCK();
return acc_id;
id = acc_id;
goto on_return;
}
}
@ -2690,14 +2690,27 @@ PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
}
/* Match ! */
PJSUA_UNLOCK();
return acc_id;
id = acc_id;
goto on_return;
}
}
/* Still no match, use default account */
on_return:
PJSUA_UNLOCK();
return pjsua_var.default_acc;
/* Still no match, use default account */
if (id == PJSUA_INVALID_ID)
id = pjsua_var.default_acc;
/* Invoke account find callback */
if (pjsua_var.ua_cfg.cb.on_acc_find_for_incoming)
(*pjsua_var.ua_cfg.cb.on_acc_find_for_incoming)(rdata, &id);
/* Verify if the specified account id is valid */
if (!pjsua_acc_is_valid(id))
id = pjsua_var.default_acc;
return id;
}