Michael Jerris 274a956f00 Merge up to the most recent sofia-sip darcs tree. Includes the following patches from darcs:
Tue Aug 21 09:38:59 EDT 2007  Pekka.Pessi@nokia.com
  * tport_type_udp.c: checking error while checking that MSG_TRUNC works.
Shall I pull this patch? (1/43)  [ynWvpxqadjk], or ? for help: y

Tue Aug 21 10:49:33 EDT 2007  Pekka.Pessi@nokia.com
  * nua_params.c: NUTAG_SIPS_URL() now sets the handle target, too.

  Problem reported by Jari Tenhunen.
Shall I pull this patch? (2/43)  [ynWvpxqadjk], or ? for help: y

Thu Aug 23 11:22:42 EDT 2007  Pekka.Pessi@nokia.com
  * nta.c: do not destroy INVITE transaction if it has been CANCELed

  Handle gracefully cases where the INVITE transaction is destroyed
  immediately after canceling it. The old behaviour was to left it up to the
  application to ACK the final response returned to INVITE.

  Thanks for Fabio Margarido for reporting this problem.
Shall I pull this patch? (3/43)  [ynWvpxqadjk], or ? for help: y

Thu Aug 23 13:02:01 EDT 2007  Pekka.Pessi@nokia.com
  * test_soa.c: added test with user SDP containing already rejected media
Shall I pull this patch? (4/43)  [ynWvpxqadjk], or ? for help: y

Fri Aug 24 09:41:20 EDT 2007  Pekka.Pessi@nokia.com
  * nta: added option for processing orphan responses matching with a dialog

  The orphan responses matching with the dialog can now be processed by the
  response callback.The dialog leg can be created with
  NTATAG_RESPONSE_CALLBACK() or a response callback can be later bound to the
  leg with nta_leg_bind_response().

  This is practically useful only with 200 OK responses to the INVITE that are
  retransmitted by the UAS. By default, the retransmission are catched by the
  ACK transaction (which then retransmits the ACK request message). However,
  after ACK transaction times out, the retransmitted 200 OK indicates most
  probably that the ACK request messages do not reach UAS.

  Partially fixes the sf.net bug #1750691 reported by Mikhail Zabaluev.
Shall I pull this patch? (5/43)  [ynWvpxqadjk], or ? for help: y

Fri Aug 24 09:41:20 EDT 2007  Pekka.Pessi@nokia.com
  UNDO: nta: added option for processing orphan responses matching with a dialog

  The orphan responses matching with the dialog can now be processed by the
  response callback.The dialog leg can be created with
  NTATAG_RESPONSE_CALLBACK() or a response callback can be later bound to the
  leg with nta_leg_bind_response().

  This is practically useful only with 200 OK responses to the INVITE that are
  retransmitted by the UAS. By default, the retransmission are catched by the
  ACK transaction (which then retransmits the ACK request message). However,
  after ACK transaction times out, the retransmitted 200 OK indicates most
  probably that the ACK request messages do not reach UAS.

  Partially fixes the sf.net bug #1750691 reported by Mikhail Zabaluev.
Shall I pull this patch? (6/43)  [ynWvpxqadjk], or ? for help: y

Thu Aug 30 07:00:10 EDT 2007  Pekka.Pessi@nokia.com
  * nta.c: disabled nta_msg_ackbye(). Fix for sf.net bug #1750691

  Thanks for Mikhail Zabaluev for reporting this bug.
Shall I pull this patch? (7/43)  [ynWvpxqadjk], or ? for help: y

Thu Aug 30 06:54:38 EDT 2007  Pekka.Pessi@nokia.com
  * test_nua: added test for sf.net bug #1750691
Shall I pull this patch? (8/43)  [ynWvpxqadjk], or ? for help: y

Thu Aug 30 07:03:45 EDT 2007  Pekka.Pessi@nokia.com
  * test_nua: added test for nua_bye() sending CANCEL
Shall I pull this patch? (9/43)  [ynWvpxqadjk], or ? for help: y

Fri Aug 31 12:08:09 EDT 2007  Pekka.Pessi@nokia.com
  * url.c: fixed escaping of '/' %2F, ';' %3B and '=' %3D in URL path/params

  Thanks for Fabio Margarido for reporting this bug.
Shall I pull this patch? (10/43)  [ynWvpxqadjk], or ? for help: y

Mon Sep  3 10:14:55 EDT 2007  Pekka.Pessi@nokia.com
  * url.c: do not un-escape %40 in URI parameters.

  Do not unescape %2C, %3B, %3D, or %40 in URI parameters, nor
  %2C, %2F, %3B, %3D, or %40 in URI path.

  The @ sign can be ambiguous in the SIP URL, e.g.,

  <sip:test.info;p=value@test.com>

  can be parsed in two ways:
  1) username contains test.info;param=value and host part has test.com
  2) empty username, host part test.info, URI parameter p=value@test.com

  Previously Sofia URL parser converted escaped '@' at signs (%40) in the URI
  parameters to the unescaped form. The resulting URI could be ambiguous and
  sometimes fail the syntax check if there was no '@' sign before the
  unescaped one.

  Thanks for Jan van den Bosch and Mikhail Zabaluev for reporting this bug.
Shall I pull this patch? (11/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 04:59:57 EDT 2007  Pekka.Pessi@nokia.com
  * tport.c: fixed indenting, logging
Shall I pull this patch? (12/43)  [ynWvpxqadjk], or ? for help: y

Fri Jul 13 12:47:33 EDT 2007  Pekka.Pessi@nokia.com
  * nua/test_proxy.h, nua/test_proxy.c: added support for multiple domains

  Each domain has its own registrar and authentication module.
Shall I pull this patch? (13/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 11:19:33 EDT 2007  Pekka.Pessi@nokia.com
  * test_ops.c: added timestamp to event logging
Shall I pull this patch? (14/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 11:20:12 EDT 2007  Pekka.Pessi@nokia.com
  * test_nua: fixed timing problems in testing.
Shall I pull this patch? (15/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 11:31:04 EDT 2007  Pekka.Pessi@nokia.com
  * test_ops.c: reduce su_root_step() delay to 0.1 seconds
Shall I pull this patch? (16/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 11:31:22 EDT 2007  Pekka.Pessi@nokia.com
  * test_register.c: fixed timing problem
Shall I pull this patch? (17/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 17:03:46 EDT 2007  Pekka.Pessi@nokia.com
  * test_100rel.c: fixed timing problems resulting in events being reordered
Shall I pull this patch? (18/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:40:53 EDT 2007  Pekka.Pessi@nokia.com
  * nua (test_init.c, test_register.c): using test_proxy domains
Shall I pull this patch? (19/43)  [ynWvpxqadjk], or ? for help: y

Thu Aug 23 12:12:32 EDT 2007  Pekka.Pessi@nokia.com
  * test_soa.c: added cleanup code
Shall I pull this patch? (20/43)  [ynWvpxqadjk], or ? for help: y

Fri Aug 24 09:35:35 EDT 2007  Pekka.Pessi@nokia.com
  * nta.c: increase lifetime of ACK transaction from T4 to T1 x 64

  nta.c creates a ACK transaction in order to restransmit ACK requests when
  ever a retransmitted 2XX response to INVITE is received. The UAS retransmits
  the 2XX responses for 64 x T1 (32 second by default).

  Partially fixes the sf.net bug #1750691 reported by Mikhail Zabaluev.
Shall I pull this patch? (21/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 10:21:04 EDT 2007  Pekka.Pessi@nokia.com
  * Makefile.am: generating libsofia-sip-ua/docs/Doxyfile.rfc before making manpages
Shall I pull this patch? (22/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:05:33 EDT 2007  Pekka.Pessi@nokia.com
  * sofia-sip/tport_tag.h: added TPTAG_KEEPALIVE(), TPTAG_PINGPONG(), TPTAG_PONG2PING()
Shall I pull this patch? (23/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:09:06 EDT 2007  Pekka.Pessi@nokia.com
  * tport: added ping-pong keepalive on TCP. replaced single tick with connection-specific timer

  Now detecting closed connections on TLS, too.

  Added tests for idle timeout, receive timeout, ping-pong timeout.
Shall I pull this patch? (24/43)  [ynWvpxqadjk], or ? for help: y

Fri Jul  6 10:19:32 EDT 2007  Pekka.Pessi@nokia.com
  * nta.c: added nta_incoming_received()
Shall I pull this patch? (25/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 11:29:56 EDT 2007  Pekka.Pessi@nokia.com
  * nua_session.c: delay transition to ready when O/A is incomplete

  Delay sending ACK and subsequent transition of call to the ready state when
  the 200 OK response to the INVITE is received if the SDP Offer/Answer
  exchange using UPDATE/PRACK was still incomplete.

  Previously, if the O/A using UPDATE or PRACK was incomplete and an 200 OK
  was received, the call setup logic regarded this as a fatal error and
  terminated the call.

  Thanks for Mike Jerris for detecting and reporting this bug.
Shall I pull this patch? (26/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:22:46 EDT 2007  Pekka.Pessi@nokia.com
  * test_call_reject.c: testing Retry-After
Shall I pull this patch? (27/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:42:51 EDT 2007  Pekka.Pessi@nokia.com
  * test_nua: using rudimentary outbound support in B's proxy.
Shall I pull this patch? (28/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:48:33 EDT 2007  Pekka.Pessi@nokia.com
  * nua_register.c: added some logging to nua_register_connection_closed()
Shall I pull this patch? (29/43)  [ynWvpxqadjk], or ? for help: y

Wed Jul 25 12:43:57 EDT 2007  Pekka.Pessi@nokia.com
  * test_nua: using AUTHTAG_MAX_NCOUNT(1) for Mr. C

  C is now challenged every time.
Shall I pull this patch? (30/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 11:05:19 EDT 2007  Pekka.Pessi@nokia.com
  * nua/test_100rel.c: fixed timing problem re response to PRACK and ACK
Shall I pull this patch? (31/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 06:02:50 EDT 2007  Mikhail Zabaluev <mikhail.zabaluev@nokia.com>
  * DIST_SUBDIRS must include everything unconditionally
Shall I pull this patch? (32/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 13:53:04 EDT 2007  Pekka.Pessi@nokia.com
  * test_soa.c: silenced warnings
Shall I pull this patch? (33/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 16:59:48 EDT 2007  Pekka.Pessi@nokia.com
  * nua: refactored dialog refresh code
Shall I pull this patch? (34/43)  [ynWvpxqadjk], or ? for help: y

Mon Jul 23 16:59:48 EDT 2007  Pekka.Pessi@nokia.com
  UNDO: nua: refactored dialog refresh code
Shall I pull this patch? (35/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 12:01:25 EDT 2007  Pekka.Pessi@nokia.com
  * nua_dialog.[hc]: renamed functions setting refresh interval

Shall I pull this patch? (36/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 12:15:03 EDT 2007  Pekka.Pessi@nokia.com
  * nua_dialog.[hc], nua_stack.c: added nua_dialog_repeat_shutdown()
Shall I pull this patch? (37/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 12:19:20 EDT 2007  Pekka.Pessi@nokia.com
  * nua_dialog.h: renamed nua_remote_t as nua_dialog_peer_info_t
Shall I pull this patch? (38/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 12:23:04 EDT 2007  Pekka.Pessi@nokia.com
  * nua_stack.c: added timer to client request in order to implement Retry-After
Shall I pull this patch? (39/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 12:33:53 EDT 2007  Pekka.Pessi@nokia.com
  * nua: added backpointers to nua_dialog_usage_t and nua_dialog_state_t
Shall I pull this patch? (40/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 13:56:48 EDT 2007  Pekka.Pessi@nokia.com
  * test_nua.c: abort() in timeout alarm function if -a is given
Shall I pull this patch? (41/43)  [ynWvpxqadjk], or ? for help: y

Thu Sep  6 17:13:18 EDT 2007  Pekka.Pessi@nokia.com
  * nua_subnotref.c: include SIPTAG_EVENT() in the nua_i_notify tag list
Shall I pull this patch? (42/43)  [ynWvpxqadjk], or ? for help: y

Mon Sep 10 12:27:53 EDT 2007  Pekka.Pessi@nokia.com
  * nua: save Contact from target refresh request or response.

  Save the Contact header which the application has added to the target
  refresh requests or responses and use the saved contact in subsequent target
  refresh requests or responses.

  Previously the application had no way of specifying the Contact included in
  the automatic responses to target refresh requests.

  Thanks for Anthony Minessale for reporting this problem.
Shall I pull this patch? (43/43)  [ynWvpxqadjk], or ? for help: y




git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5692 d0543943-73ff-0310-b7d9-9358b9ac24b2
2007-09-10 20:45:25 +00:00

561 lines
14 KiB
C

/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@CFILE test_ops.c
* @brief High-level test framework for Sofia SIP User Agent Engine
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Martti Mela <Martti Mela@nokia.com>
*
* @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
*/
#include "config.h"
#include "test_nua.h"
#if HAVE_FUNC
#elif HAVE_FUNCTION
#define __func__ __FUNCTION__
#else
#define __func__ name
#endif
int save_events(CONDITION_PARAMS)
{
return save_event_in_list(ctx, event, ep, call) == event_is_normal;
}
int until_final_response(CONDITION_PARAMS)
{
return status >= 200;
}
int save_until_final_response(CONDITION_PARAMS)
{
save_event_in_list(ctx, event, ep, call);
return
nua_r_set_params <= event && event < nua_i_network_changed
&& status >= 200;
}
/** Save events.
*
* Terminate when a event is saved.
*/
int save_until_received(CONDITION_PARAMS)
{
return save_event_in_list(ctx, event, ep, call) == event_is_normal;
}
/** Save events until nua_i_outbound is received. */
int save_until_special(CONDITION_PARAMS)
{
return save_event_in_list(ctx, event, ep, call) == event_is_special;
}
/* Return call state from event tag list */
int callstate(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, nutag_callstate);
return ti ? ti->t_value : -1;
}
/* Return true if offer is sent */
int is_offer_sent(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, nutag_offer_sent);
return ti ? ti->t_value : 0;
}
/* Return true if answer is sent */
int is_answer_sent(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, nutag_answer_sent);
return ti ? ti->t_value : 0;
}
/* Return true if offer is recv */
int is_offer_recv(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, nutag_offer_recv);
return ti ? ti->t_value : 0;
}
/* Return true if answer is recv */
int is_answer_recv(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, nutag_answer_recv);
return ti ? ti->t_value : 0;
}
/* Return true if offer/answer is sent/recv */
int is_offer_answer_done(tagi_t const *tags)
{
tagi_t const *ti;
return
((ti = tl_find(tags, nutag_answer_recv)) && ti->t_value) ||
((ti = tl_find(tags, nutag_offer_sent)) && ti->t_value) ||
((ti = tl_find(tags, nutag_offer_recv)) && ti->t_value) ||
((ti = tl_find(tags, nutag_answer_sent)) && ti->t_value);
}
/* Return audio state from event tag list */
int audio_activity(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, soatag_active_audio);
return ti ? ti->t_value : -1;
}
/* Return video state from event tag list */
int video_activity(tagi_t const *tags)
{
tagi_t const *ti = tl_find(tags, soatag_active_video);
return ti ? ti->t_value : -1;
}
void print_event(nua_event_t event,
char const *operation,
int status, char const *phrase,
nua_t *nua, struct context *ctx,
struct endpoint *ep,
nua_handle_t *nh, struct call *call,
sip_t const *sip,
tagi_t tags[])
{
tagi_t const *t;
static su_nanotime_t started = 0;
su_nanotime_t now;
char timestamp[32];
su_nanotime(&now);
if (started == 0) started = now;
now -= started; now /= 1000000;
snprintf(timestamp, sizeof timestamp, "%03u.%03u",
(unsigned)(now / 1000), (unsigned)(now % 1000));
if (event == nua_i_state) {
fprintf(stderr, "%s %s.nua(%p): event %s %s\n", timestamp,
ep->name, (void *)nh, nua_event_name(event),
nua_callstate_name(callstate(tags)));
}
else if ((int)event >= nua_r_set_params) {
t = tl_find(tags, nutag_substate);
if (t) {
fprintf(stderr, "%s %s.nua(%p): event %s status %u %s (%s)\n", timestamp,
ep->name, (void*)nh, nua_event_name(event), status, phrase,
nua_substate_name(t->t_value));
}
else {
fprintf(stderr, "%s %s.nua(%p): event %s status %u %s\n", timestamp,
ep->name, (void *)nh, nua_event_name(event), status, phrase);
}
}
else if (event == nua_i_notify) {
t = tl_find(tags, nutag_substate);
fprintf(stderr, "%s %s.nua(%p): event %s %s (%s)\n", timestamp,
ep->name, (void *)nh, nua_event_name(event), phrase,
nua_substate_name(t ? t->t_value : 0));
}
else if ((int)event >= 0) {
fprintf(stderr, "%s %s.nua(%p): event %s %s\n", timestamp,
ep->name, (void *)nh, nua_event_name(event), phrase);
}
else if (status > 0) {
fprintf(stderr, "%s %s.nua(%p): call %s() with status %u %s\n", timestamp,
ep->name, (void *)nh, operation, status, phrase);
}
else {
t = tl_find(tags, siptag_subject_str);
if (t && t->t_value) {
char const *subject = (char const *)t->t_value;
fprintf(stderr, "%s %s.nua(%p): call %s() \"%s\"\n", timestamp,
ep->name, (void *)nh, operation, subject);
}
else
fprintf(stderr, "%s %s.nua(%p): call %s()\n", timestamp,
ep->name, (void *)nh, operation);
}
if (tags &&
((tstflags & tst_verbatim) || ctx->print_tags || ep->print_tags))
tl_print(stderr, "", tags);
}
void ep_callback(nua_event_t event,
int status, char const *phrase,
nua_t *nua, struct context *ctx,
struct endpoint *ep,
nua_handle_t *nh, struct call *call,
sip_t const *sip,
tagi_t tags[])
{
if (ep->printer)
ep->printer(event, "", status, phrase, nua, ctx, ep, nh, call, sip, tags);
if (call == NULL && nh) {
for (call = ep->call; call; call = call->next) {
if (!call->nh)
break;
if (nh == call->nh)
break;
}
if (call && call->nh == NULL) {
call->nh = nh;
nua_handle_bind(nh, call);
}
}
if ((ep->next_condition == NULL ||
ep->next_condition(event, status, phrase,
nua, ctx, ep, nh, call, sip, tags))
&&
(ep->next_event == -1 || ep->next_event == event))
ep->running = 0;
ep->last_event = event;
if (call == NULL && nh)
nua_handle_destroy(nh);
}
void a_callback(nua_event_t event,
int status, char const *phrase,
nua_t *nua, struct context *ctx,
nua_handle_t *nh, struct call *call,
sip_t const *sip,
tagi_t tags[])
{
ep_callback(event, status, phrase, nua, ctx, &ctx->a, nh, call, sip, tags);
}
void b_callback(nua_event_t event,
int status, char const *phrase,
nua_t *nua, struct context *ctx,
nua_handle_t *nh, struct call *call,
sip_t const *sip,
tagi_t tags[])
{
ep_callback(event, status, phrase, nua, ctx, &ctx->b, nh, call, sip, tags);
}
void c_callback(nua_event_t event,
int status, char const *phrase,
nua_t *nua, struct context *ctx,
nua_handle_t *nh, struct call *call,
sip_t const *sip,
tagi_t tags[])
{
ep_callback(event, status, phrase, nua, ctx, &ctx->c, nh, call, sip, tags);
}
void run_abc_until(struct context *ctx,
nua_event_t a_event, condition_function *a_condition,
nua_event_t b_event, condition_function *b_condition,
nua_event_t c_event, condition_function *c_condition)
{
struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c;
a->next_event = a_event;
a->next_condition = a_condition;
a->last_event = -1;
a->running = a_condition != NULL && a_condition != save_events;
a->running |= a_event != -1;
memset(&a->flags, 0, sizeof a->flags);
b->next_event = b_event;
b->next_condition = b_condition;
b->last_event = -1;
b->running = b_condition != NULL && b_condition != save_events;
b->running |= b_event != -1;
memset(&b->flags, 0, sizeof b->flags);
c->next_event = c_event;
c->next_condition = c_condition;
c->last_event = -1;
c->running = c_condition != NULL && c_condition != save_events;
c->running |= c_event != -1;
memset(&c->flags, 0, sizeof c->flags);
for (; a->running || b->running || c->running;) {
su_root_step(ctx->root, 100);
}
}
void run_ab_until(struct context *ctx,
nua_event_t a_event, condition_function *a_condition,
nua_event_t b_event, condition_function *b_condition)
{
run_abc_until(ctx, a_event, a_condition, b_event, b_condition, -1, NULL);
}
void run_bc_until(struct context *ctx,
nua_event_t b_event, condition_function *b_condition,
nua_event_t c_event, condition_function *c_condition)
{
run_abc_until(ctx, -1, NULL, b_event, b_condition, c_event, c_condition);
}
int run_a_until(struct context *ctx,
nua_event_t a_event,
condition_function *a_condition)
{
run_abc_until(ctx, a_event, a_condition, -1, NULL, -1, NULL);
return ctx->a.last_event;
}
int run_b_until(struct context *ctx,
nua_event_t b_event,
condition_function *b_condition)
{
run_abc_until(ctx, -1, NULL, b_event, b_condition, -1, NULL);
return ctx->b.last_event;
}
int run_c_until(struct context *ctx,
nua_event_t event,
condition_function *condition)
{
run_abc_until(ctx, -1, NULL, -1, NULL, event, condition);
return ctx->c.last_event;
}
#define OPERATION(X, x) \
int X(struct endpoint *ep, \
struct call *call, nua_handle_t *nh, \
tag_type_t tag, tag_value_t value, \
...) \
{ \
ta_list ta; \
ta_start(ta, tag, value); \
\
if (ep->printer) \
ep->printer(-1, "nua_" #x, 0, "", ep->nua, ep->ctx, ep, \
nh, call, NULL, ta_args(ta)); \
\
nua_##x(nh, ta_tags(ta)); \
\
ta_end(ta); \
return 0; \
} extern int dummy
OPERATION(INVITE, invite);
OPERATION(ACK, ack);
OPERATION(BYE, bye);
OPERATION(CANCEL, cancel);
OPERATION(AUTHENTICATE, authenticate);
OPERATION(UPDATE, update);
OPERATION(INFO, info);
OPERATION(PRACK, prack);
OPERATION(REFER, refer);
OPERATION(MESSAGE, message);
OPERATION(METHOD, method);
OPERATION(OPTIONS, options);
OPERATION(PUBLISH, publish);
OPERATION(UNPUBLISH, unpublish);
OPERATION(REGISTER, register);
OPERATION(UNREGISTER, unregister);
OPERATION(SUBSCRIBE, subscribe);
OPERATION(UNSUBSCRIBE, unsubscribe);
OPERATION(NOTIFY, notify);
OPERATION(NOTIFIER, notifier);
OPERATION(TERMINATE, terminate);
OPERATION(AUTHORIZE, authorize);
/* Respond via endpoint and handle */
int RESPOND(struct endpoint *ep,
struct call *call,
nua_handle_t *nh,
int status, char const *phrase,
tag_type_t tag, tag_value_t value,
...)
{
ta_list ta;
ta_start(ta, tag, value);
if (ep->printer)
ep->printer(-1, "nua_respond", status, phrase, ep->nua, ep->ctx, ep,
nh, call, NULL, ta_args(ta));
nua_respond(nh, status, phrase, ta_tags(ta));
ta_end(ta);
return 0;
}
/* Destroy a handle */
int DESTROY(struct endpoint *ep,
struct call *call,
nua_handle_t *nh)
{
if (ep->printer)
ep->printer(-1, "nua_handle_destroy", 0, "", ep->nua, ep->ctx, ep,
nh, call, NULL, NULL);
nua_handle_destroy(nh);
if (call->nh == nh)
call->nh = NULL;
return 0;
}
/* Reject all but currently used handles */
struct call *check_handle(struct endpoint *ep,
struct call *call,
nua_handle_t *nh,
int status, char const *phrase)
{
if (call)
return call;
if (status)
RESPOND(ep, call, nh, status, phrase, TAG_END());
nua_handle_destroy(nh);
return NULL;
}
/* Save nua event in call-specific list */
int save_event_in_list(struct context *ctx,
nua_event_t nevent,
struct endpoint *ep,
struct call *call)
{
struct eventlist *list;
struct event *e;
int action = ep->is_special(nevent);
if (action == event_is_extra)
return 0;
else if (action == event_is_special || call == NULL)
list = ep->specials;
else if (call->events)
list = call->events;
else
list = ep->events;
e = su_zalloc(ctx->home, sizeof *e);
if (!e) { perror("su_zalloc"), abort(); }
if (!nua_save_event(ep->nua, e->saved_event)) {
su_free(ctx->home, e);
return -1;
}
*(e->prev = list->tail) = e; list->tail = &e->next;
e->call = call;
e->data = nua_event_data(e->saved_event);
return action;
}
/* Free nua events from endpoint list */
void free_events_in_list(struct context *ctx,
struct eventlist *list)
{
struct event *e;
while ((e = list->head)) {
if ((*e->prev = e->next))
e->next->prev = e->prev;
nua_destroy_event(e->saved_event);
su_free(ctx->home, e);
}
list->tail = &list->head;
}
void free_event_in_list(struct context *ctx,
struct eventlist *list,
struct event *e)
{
if (e) {
if ((*e->prev = e->next))
e->next->prev = e->prev;
nua_destroy_event(e->saved_event);
su_free(ctx->home, e);
if (list->head == NULL)
list->tail = &list->head;
}
}
struct event *event_by_type(struct event *e, nua_event_t etype)
{
for (; e; e = e->next) {
if (e->data->e_event == etype)
break;
}
return e;
}
size_t count_events(struct event const *e)
{
size_t n;
for (n = 0; e; e = e->next)
n++;
return n;
}
int is_special(nua_event_t e)
{
if (e == nua_i_active || e == nua_i_terminated)
return event_is_extra;
if (e == nua_i_outbound)
return event_is_special;
return event_is_normal;
}
void
endpoint_init(struct context *ctx, struct endpoint *e, char id)
{
e->name[0] = id;
e->ctx = ctx;
e->is_special = is_special;
call_init(e->call);
call_init(e->reg);
eventlist_init(e->events);
eventlist_init(e->specials);
}
void nolog(void *stream, char const *fmt, va_list ap) {}