Commit b384a05e authored by Pekka Pessi's avatar Pekka Pessi

nua: using nua_stack_set_handle_special() to set handle flags and special event.

darcs-hash:20061003082919-65a35-8665b0f77aa5c0a8c24e3ebbb689446ac120cc68.gz
parent 8d2fe4f7
......@@ -82,7 +82,7 @@ nua_stack_notifier(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *ta
int status = 900;
char const *phrase = nua_internal_error;
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
tl_gets(tags,
NUTAG_URL_REF(url),
......
......@@ -69,7 +69,7 @@ nua_stack_message(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tag
return UA_EVENT2(e, 900, "Request already in progress");
}
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_MESSAGE,
......@@ -117,7 +117,7 @@ int nua_stack_process_message(nua_t *nua,
return 403;
if (nh == NULL)
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, nh_has_nothing, 0)))
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, 0)))
return 500; /* respond with 500 Internal Server Error */
msg = nta_incoming_getrequest(irq);
......
......@@ -228,7 +228,7 @@ int nua_stack_notify(nua_t *nua,
return UA_EVENT2(e, 900, "Request already in progress");
}
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_NOTIFY,
......@@ -369,7 +369,7 @@ int nua_stack_process_refer(nua_t *nua,
int created = 0;
if (nh == NULL) {
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, nh_has_notify, 1)))
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, 1)))
return 500;
created = 1;
}
......
......@@ -68,7 +68,7 @@ nua_stack_options(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tag
return UA_EVENT2(e, 900, "Request already in progress");
}
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_OPTIONS,
......
......@@ -220,14 +220,14 @@ int nua_stack_publish2(nua_t *nua, nua_handle_t *nh, nua_event_t e,
sip_t *sip;
int remove_body = 0;
if (nh->nh_special && nh->nh_special != nua_r_publish) {
if (nua_stack_set_handle_special(nh, nh_has_nothing, nua_r_publish) < 0)
return UA_EVENT2(e, 900, "Invalid handle for PUBLISH");
}
else if (cr->cr_orq) {
if (cr->cr_orq) {
return UA_EVENT2(e, 900, "Request already in progress");
}
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
if (e == nua_r_unpublish) {
du = nua_dialog_usage_get(nh->nh_ds, nua_publish_usage, NULL);
......@@ -287,7 +287,6 @@ int nua_stack_publish2(nua_t *nua, nua_handle_t *nh, nua_event_t e,
if (!cr->cr_orq)
goto error;
nh->nh_special = nua_r_publish;
cr->cr_usage = du;
return cr->cr_event = e;
......@@ -407,7 +406,7 @@ int nua_stack_process_publish(nua_t *nua,
sip_t const *sip)
{
if (nh == NULL)
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, nh_has_nothing, 0)))
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, 0)))
return 500; /* Respond with 500 Internal Server Error */
nua_stack_event(nh->nh_nua, nh, nta_incoming_getrequest(irq),
......
......@@ -521,13 +521,12 @@ nua_stack_register(nua_t *nua, nua_handle_t *nh, nua_event_t e,
sip_t *sip;
int terminating = e != nua_r_register;
if (nh->nh_special && nh->nh_special != nua_r_register)
if (nua_stack_set_handle_special(nh, nh_has_register, nua_r_register) < 0)
return UA_EVENT2(e, 900, "Invalid handle for REGISTER");
if (cr->cr_orq)
return UA_EVENT2(e, 900, "Request already in progress");
nua_stack_init_handle(nua, nh, nh_has_register, "", TAG_NEXT(tags));
nh->nh_special = nua_r_register;
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
du = nua_dialog_usage_add(nh, nh->nh_ds, nua_register_usage, NULL);
if (!du)
......
......@@ -60,7 +60,7 @@ int nua_stack_process_register(nua_t *nua,
sip_t const *sip)
{
if (nh == NULL)
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, nh_has_nothing, 0)))
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, 0)))
return 500; /* Respond with 500 Internal Server Error */
nh->nh_registrar = irq;
......
......@@ -437,8 +437,7 @@ nua_stack_invite(nua_t *nua, nua_handle_t *nh, nua_event_t e,
else if (nh_referral_check(nh, tags) < 0) {
what = "Invalid referral";
}
else if (nua_stack_init_handle(nua, nh, nh_has_invite, NULL,
TAG_NEXT(tags)) < 0) {
else if (nua_stack_init_handle(nua, nh, TAG_NEXT(tags)) < 0) {
what = "Handle initialization failed";
}
else
......@@ -904,7 +903,7 @@ int nua_stack_prack(nua_t *nua, nua_handle_t *nh, nua_event_t e,
else if (cr->cr_orq)
return UA_EVENT2(e, 900, "Request already in progress");
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_PRACK,
......@@ -1298,8 +1297,10 @@ int process_invite1(nua_t *nua,
if (!DNH_PGET(dnh, invite_enable))
return 403;
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, nh_has_invite, 1)))
if (!(nh = nua_stack_incoming_handle(nua, irq, sip, 1)))
return 500;
nua_stack_set_handle_special(nh, nh_has_invite, nua_i_error);
}
have_sdp = session_get_description(msg, sip, &sdp, &len);
......@@ -2187,7 +2188,7 @@ nua_stack_info(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
return UA_EVENT2(e, 900, "Request already in progress");
}
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_INFO ,
......@@ -2255,7 +2256,7 @@ int nua_stack_update(nua_t *nua, nua_handle_t *nh, nua_event_t e,
else if (cr->cr_orq)
return UA_EVENT2(e, 900, "Request already in progress");
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_UPDATE,
......@@ -2542,7 +2543,7 @@ nua_stack_bye(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
return 0;
}
nua_stack_init_handle(nua, nh, nh_has_nothing, NULL, TAG_NEXT(tags));
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, cr->cr_retry_count,
SIP_METHOD_BYE,
......
......@@ -710,8 +710,6 @@ void nua_creq_deinit(struct nua_client_request *cr, nta_outgoing_t *orq)
* @retval 0 when successful
*/
int nua_stack_init_handle(nua_t *nua, nua_handle_t *nh,
enum nh_kind kind,
char const *default_allow,
tag_type_t tag, tag_value_t value, ...)
{
ta_list ta;
......@@ -720,19 +718,6 @@ int nua_stack_init_handle(nua_t *nua, nua_handle_t *nh,
if (nh == NULL)
return -1;
if (kind && !nh_is_special(nh) && !nh->nh_has_invite) {
switch (kind) {
case nh_has_invite: nh->nh_has_invite = 1; break;
case nh_has_subscribe: nh->nh_has_subscribe = 1; break;
case nh_has_notify: nh->nh_has_notify = 1; break;
case nh_has_register: nh->nh_has_register = 1; break;
case nh_has_streaming: nh->nh_has_streaming = 1; break;
case nh_has_nothing:
default:
break;
}
}
assert(nh != nua->nua_dhandle);
ta_start(ta, tag, value);
......@@ -765,12 +750,10 @@ int nua_stack_init_handle(nua_t *nua, nua_handle_t *nh,
nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
nta_incoming_t *irq,
sip_t const *sip,
enum nh_kind kind,
int create_dialog)
{
nua_handle_t *nh;
url_t const *url;
char const *default_allow = NULL; /* XXX - should be argument? */
sip_to_t to[1];
sip_from_t from[1];
......@@ -794,8 +777,7 @@ nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
SIPTAG_FROM(from), /* Remote AoR */
TAG_END());
if (nua_stack_init_handle(nh->nh_nua, nh, kind, default_allow,
TAG_END()) < 0)
if (nua_stack_init_handle(nh->nh_nua, nh, TAG_END()) < 0)
nh_destroy(nua, nh), nh = NULL;
if (nh && create_dialog) {
......@@ -821,6 +803,35 @@ nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
}
int nua_stack_set_handle_special(nua_handle_t *nh,
enum nh_kind kind,
nua_event_t special)
{
if (nh == NULL)
return -1;
if (special && nh->nh_special && nh->nh_special != special)
return -1;
if (!nh_is_special(nh) && !nh->nh_has_invite) {
switch (kind) {
case nh_has_invite: nh->nh_has_invite = 1; break;
case nh_has_subscribe: nh->nh_has_subscribe = 1; break;
case nh_has_notify: nh->nh_has_notify = 1; break;
case nh_has_register: nh->nh_has_register = 1; break;
case nh_has_streaming: nh->nh_has_streaming = 1; break;
case nh_has_nothing:
default:
break;
}
if (special)
nh->nh_special = special;
}
return 0;
}
/** @internal Add authorization data */
int nh_authorize(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...)
{
......
......@@ -218,20 +218,19 @@ struct nua_handle_s
nua_handle_preferences_t *nh_prefs; /**< Preferences */
/* Handle state */
/* Handle type is determined by special event and flags. */
nua_event_t nh_special; /**< Special event */
unsigned nh_ref_by_stack:1; /**< Has stack used the handle? */
unsigned nh_ref_by_user:1; /**< Has user used the handle? */
unsigned nh_init:1; /**< Handle has been initialized */
unsigned nh_used_ptags:1; /**< Ptags has been used */
unsigned nh_has_invite:1; /**< Has call */
unsigned nh_has_subscribe:1; /**< Has watcher */
unsigned nh_has_notify:1; /**< Has notifier */
unsigned nh_has_register:1; /**< Has registration */
unsigned nh_has_streaming:1; /**< Has RTSP-related session */
unsigned nh_ref_by_stack:1; /**< Has stack used the handle? */
unsigned nh_ref_by_user:1; /**< Has user used the handle? */
unsigned nh_init:1; /**< Handle has been initialized */
unsigned nh_used_ptags:1; /**< Ptags has been used */
struct nua_client_request nh_cr[1];
nua_dialog_state_t nh_ds[1];
......@@ -405,12 +404,18 @@ int nua_stack_event(nua_t *nua, nua_handle_t *nh, msg_t *msg,
nua_handle_t *nh_create_handle(nua_t *nua, nua_hmagic_t *hmagic,
tagi_t *tags);
nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
nua_handle_t *nua_stack_incoming_handle(nua_t *nua,
nta_incoming_t *irq,
sip_t const *sip,
enum nh_kind kind,
int create_dialog);
int nua_stack_init_handle(nua_t *nua, nua_handle_t *nh,
tag_type_t tag, tag_value_t value, ...);
int nua_stack_set_handle_special(nua_handle_t *nh,
enum nh_kind kind,
nua_event_t special);
int nua_handle_save_tags(nua_handle_t *h, tagi_t *tags);
void nh_destroy(nua_t *nua, nua_handle_t *nh);
......@@ -423,11 +428,6 @@ int nua_stack_set_from(nua_t *, int initial, tagi_t const *tags);
int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags);
int nua_stack_init_handle(nua_t *nua, nua_handle_t *nh,
enum nh_kind kind,
char const *default_allow,
tag_type_t tag, tag_value_t value, ...);
int nua_stack_process_request(nua_handle_t *nh,
nta_leg_t *leg,
nta_incoming_t *irq,
......
......@@ -129,18 +129,14 @@ nua_stack_subscribe(nua_t *nua, nua_handle_t *nh, nua_event_t e,
msg_t *msg;
sip_t *sip;
if (nh->nh_special && nh->nh_special != nua_r_subscribe)
if (nua_stack_set_handle_special(nh, nh_has_subscribe, nua_r_subscribe) < 0)
return UA_EVENT3(e, 500, "Invalid handle for SUBSCRIBE",
NUTAG_SUBSTATE(nua_substate_terminated));
else if (cr->cr_orq)
return UA_EVENT2(e, 900, "Request already in progress");
/* Initialize allow and auth */
nua_stack_init_handle(nua, nh, nh_has_subscribe, "NOTIFY", TAG_NEXT(tags));
if (nh->nh_has_subscribe)
/* We can re-use existing INVITE handle */
nh->nh_special = nua_r_subscribe;
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
msg = nua_creq_msg(nua, nh, cr, 0,
SIP_METHOD_SUBSCRIBE,
......@@ -655,16 +651,12 @@ nua_stack_refer(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
sip_referred_by_t by[1];
sip_event_t *event = NULL;
if (nh_is_special(nh) && !nua_handle_has_subscribe(nh)) {
if (nua_stack_set_handle_special(nh, nh_has_subscribe, nua_r_subscribe) < 0)
return UA_EVENT2(e, 900, "Invalid handle for REFER");
}
else if (cr->cr_orq) {
else if (cr->cr_orq)
return UA_EVENT2(e, 900, "Request already in progress");
}
nua_stack_init_handle(nua, nh, nh_has_subscribe, "NOTIFY", TAG_NEXT(tags));
if (nh->nh_has_subscribe)
nh->nh_special = nua_r_subscribe;
nua_stack_init_handle(nua, nh, TAG_NEXT(tags));
sip_referred_by_init(by);
by->b_display = nua->nua_from->a_display;
......
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