Commit 3155ac6b authored by Michael Jerris's avatar Michael Jerris

nua_handle_by_call_id

darcs-hash:20080507122145-16063-83c7289751e7bac947256286dabeec7db81dec1a.gz
parent 677888c9
......@@ -4048,6 +4048,55 @@ nta_leg_t *nta_leg_by_replaces(nta_agent_t *sa, sip_replaces_t const *rp)
return leg;
}
/**@internal
* Find a leg corresponding to the request message.
*
*/
static
nta_leg_t *leg_find_call_id(nta_agent_t const *sa,
sip_call_id_t const *i)
{
hash_value_t hash = i->i_hash;
leg_htable_t const *lht = sa->sa_dialogs;
nta_leg_t **ll, *leg = NULL;
for (ll = leg_htable_hash(lht, hash);
(leg = *ll);
ll = leg_htable_next(lht, ll)) {
sip_call_id_t const *leg_i = leg->leg_id;
if (leg->leg_hash != hash)
continue;
if (strcmp(leg_i->i_id, i->i_id) != 0)
continue;
return leg;
}
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_call_id(sa, id);
}
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)
......
......@@ -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
*/
......
......@@ -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;
}
......@@ -1123,6 +1123,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, ...)
......
......@@ -382,6 +382,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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment