add nua_handle_by_call_id

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8280 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-05-06 22:28:20 +00:00
parent e0e04b9f9c
commit b48ee12c1c
6 changed files with 88 additions and 0 deletions

View File

@ -4022,6 +4022,27 @@ nta_leg_t *nta_leg_by_replaces(nta_agent_t *sa, sip_replaces_t const *rp)
return leg;
}
/** Get dialog leg by @CallID.
*
* @since New in @VERSION_1_12_9.
*/
SOFIAPUBFUN
nta_leg_t *nta_leg_by_call_id(nta_agent_t *sa, const char *call_id)
{
nta_leg_t *leg = NULL;
if (call_id) {
sip_call_id_t id[1];
sip_call_id_init(id);
id->i_hash = msg_hash_string(id->i_id = call_id);
leg = leg_find(sa, NULL, NULL, id, NULL, NULL);
}
return leg;
}
/** Calculate a simple case-insensitive hash over a string */
su_inline
hash_value_t hash_istring(char const *s, char const *term, hash_value_t hash)

View File

@ -253,6 +253,10 @@ SOFIAPUBFUN sip_replaces_t *nta_leg_make_replaces(nta_leg_t *leg,
SOFIAPUBFUN
nta_leg_t *nta_leg_by_replaces(nta_agent_t *, sip_replaces_t const *);
/** Get dialog leg by CallID */
SOFIAPUBFUN
nta_leg_t *nta_leg_by_call_id(nta_agent_t *sa, const char *call_id);
/* ----------------------------------------------------------------------
* 6) Prototypes for incoming transactions
*/

View File

@ -1005,6 +1005,21 @@ static int nua_stack_handle_by_replaces_call(void *arg)
return 0;
}
struct nua_stack_handle_by_call_id_args {
nua_handle_t *retval;
nua_t *nua;
const char *call_id;
};
static int nua_stack_handle_by_call_id_call(void *arg)
{
struct nua_stack_handle_by_call_id_args *a = arg;
a->retval = nua_stack_handle_by_call_id(a->nua, a->call_id);
return 0;
}
/** Obtain a new reference to an existing handle based on @Replaces header.
*
* @since New in @VERSION_1_12_4.
@ -1039,3 +1054,38 @@ nua_handle_t *nua_handle_by_replaces(nua_t *nua, sip_replaces_t const *r)
}
return NULL;
}
/** Obtain a new reference to an existing handle based on @CallID.
*
* @since New in @VERSION_1_12_9.
*
* @note
* You should release the reference with nua_handle_unref() when you are
* done with the handle.
*
* @sa nua_handle_make_replaces(), @Replaces, @RFC3891, nua_refer(),
* #nua_i_refer, @ReferTo, nta_leg_by_replaces()
*/
nua_handle_t *nua_handle_by_call_id(nua_t *nua, const char *call_id)
{
if (nua) {
#if HAVE_OPEN_C
struct nua_stack_handle_by_call_id_args a;
a.retval = NULL;
a.nua = nua;
a.call_id = call_id;
#else
struct nua_stack_handle_by_call_id_args a = { NULL, nua, call_id };
#endif
if (su_task_execute(nua->nua_server,
nua_stack_handle_by_call_id_call, (void *)&a,
NULL) == 0) {
nua_handle_t *nh = a.retval;
if (nh && !NH_IS_DEFAULT(nh) && nh->nh_valid)
return nua_handle_ref(nh);
}
}
return NULL;
}

View File

@ -1115,6 +1115,15 @@ nua_handle_t *nua_stack_handle_by_replaces(nua_t *nua,
return NULL;
}
nua_handle_t *nua_stack_handle_by_call_id(nua_t *nua, const char *call_id)
{
if (nua) {
nta_leg_t *leg = nta_leg_by_call_id(nua->nua_nta, call_id);
if (leg)
return nta_leg_magic(leg, nua_stack_process_request);
}
return NULL;
}
/** @internal Add authorization data */
int nh_authorize(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...)

View File

@ -380,6 +380,9 @@ sip_replaces_t *nua_stack_handle_make_replaces(nua_handle_t *handle,
nua_handle_t *nua_stack_handle_by_replaces(nua_t *nua,
sip_replaces_t const *r);
nua_handle_t *nua_stack_handle_by_call_id(nua_t *nua, const char *call_id);
/* ---------------------------------------------------------------------- */
int nua_stack_set_defaults(nua_handle_t *nh, nua_handle_preferences_t *nhp);

View File

@ -384,6 +384,7 @@ SOFIAPUBFUN sip_replaces_t *nua_handle_make_replaces(nua_handle_t *nh,
SOFIAPUBFUN nua_handle_t *nua_handle_by_replaces(nua_t *nua,
sip_replaces_t const *rp);
nua_handle_t *nua_handle_by_call_id(nua_t *nua, const char *call_id);
SOFIA_END_DECLS