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

1107 lines
30 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 torture_url.c Test functions for url parser
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Tue Aug 21 15:18:26 2001 ppessi
*/
#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include <assert.h>
#include "sofia-sip/url.h"
#include "sofia-sip/url_tag.h"
static int tstflags = 0;
#define TSTFLAGS tstflags
#include <sofia-sip/tstdef.h>
char const name[] = "torture_url";
unsigned char hash1[16], hash2[16];
/* test unquoting and canonizing */
int test_quote(void)
{
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t *u;
char s[] = "%73ip:q%74est%01:%01%02%00@host%2enokia.com;%70aram=%01%02";
char c[] = "sip:qtest%01:%01%02%00@host.nokia.com;param=%01%02";
char *d;
#define RESERVED ";/?:@&=+$,"
#define DELIMS "<>#%\""
#define UNWISE "{}|\\^[]`"
#define EXCLUDED RESERVED DELIMS UNWISE
char escaped[1 + 3 * 23 + 1];
#define UNRESERVED "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
"abcdefghijklmnopqrstuvwxyz" \
"0123456789" \
"-_.!~*'()"
char unreserved[26 + 26 + 10 + 9 + 1];
BEGIN();
d = url_as_string(home, (url_t *)"sip:joe@example.com");
TEST_S(d, "sip:joe@example.com");
TEST(strlen(EXCLUDED), 23);
TEST(strlen(UNRESERVED), 71);
TEST_1(!url_reserved_p("foo"));
TEST_1(!url_reserved_p(""));
TEST_1(url_reserved_p("foobar:bar"));
TEST_SIZE(url_esclen("a" EXCLUDED, ""),
1 + strlen(RESERVED) + 3 * strlen(DELIMS UNWISE));
TEST_SIZE(url_esclen("a" EXCLUDED, DELIMS UNWISE),
1 + strlen(RESERVED) + 3 * strlen(DELIMS UNWISE));
TEST_SIZE(url_esclen("a" EXCLUDED, EXCLUDED), 1 + 3 * strlen(EXCLUDED));
TEST_SIZE(url_esclen("a" EXCLUDED, NULL), 1 + 3 * strlen(EXCLUDED));
TEST_S(url_escape(escaped, "a" EXCLUDED, NULL),
"a%3B%2F%3F%3A%40%26%3D%2B%24%2C"
"%3C%3E%23%25%22"
"%7B%7D%7C%5C%5E%5B%5D%60");
TEST_S(url_unescape(escaped, escaped), "a" EXCLUDED);
TEST_SIZE(url_esclen(UNRESERVED, NULL), strlen(UNRESERVED));
TEST_S(url_escape(unreserved, UNRESERVED, NULL), UNRESERVED);
TEST_S(url_unescape(unreserved, UNRESERVED), UNRESERVED);
d = "%53ip:%75@%48"; /* Sip:u@H */
u = url_hdup(home, (url_t *)d); TEST_1(u);
url_digest(hash1, sizeof(hash1), u, NULL);
url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
d = "sip:u@h";
u = url_hdup(home, (url_t *)d); TEST_1(u);
url_digest(hash1, sizeof(hash1), u, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
u = url_hdup(home, (url_t *)s); TEST_1(u);
d = url_as_string(home, u); TEST_1(d);
TEST_S(d, c);
d = "sip:&=+$,;?/:&=+$,@[::1]:56001;param=+$,/:@&;another=@%40%2F"
"?header=" RESERVED "&%3b%2f%3f%3a%40%26%3d%2b%24%2c";
u = url_hdup(home, (url_t *)d); TEST_1(u);
TEST_S(u->url_user, "&=+$,;?/");
TEST_S(u->url_host, "[::1]");
TEST_S(u->url_params, "param=+$,/:@&;another=@%40/");
TEST_S(u->url_headers, "header=" RESERVED "&%3B%2F%3F%3A%40%26%3D%2B%24%2C");
url_digest(hash1, sizeof(hash1), u, NULL);
url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
u = url_hdup(home, (url_t *)s); TEST_1(u);
d = url_as_string(home, u); TEST_1(d);
TEST_S(d, c);
d = "http://&=+$,;:&=+$,;@host:8080/foo%2F%3B%3D"
";param=+$,%2f%3b%3d/bar;param=:@&;another=@"
"?query=" RESERVED;
u = url_hdup(home, (url_t *)d); TEST_1(u);
TEST_S(u->url_user, "&=+$,;"); TEST_S(u->url_password, "&=+$,;");
TEST_S(u->url_path, "foo%2F%3B%3D;param=+$,%2F%3B%3D/bar;param=:@&;another=@");
url_digest(hash1, sizeof(hash1), u, NULL);
url_digest(hash2, sizeof(hash2), (url_t const *)d, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
u = url_hdup(home, (url_t *)s); TEST_1(u);
d = url_as_string(home, u); TEST_1(d);
TEST_S(d, c);
url_digest(hash1, sizeof(hash1), u, NULL);
url_digest(hash2, sizeof(hash2), (url_t const *)s, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
url_digest(hash2, sizeof(hash2), (url_t const *)c, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
END();
}
int test_any(void)
{
/* Test any (*) urls */
url_t any[1] = { URL_INIT_AS(any) };
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t *u, url[1];
char *tst;
BEGIN();
TEST_S(url_scheme(url_any), "*");
TEST_S(url_scheme(url_mailto), "mailto");
TEST_S(url_scheme(url_im), "im");
TEST_S(url_scheme(url_cid), "cid");
TEST_S(url_scheme(url_msrp), "msrp");
TEST_S(url_scheme(url_msrps), "msrps");
TEST_1(tst = su_strdup(home, "*"));
TEST(url_d(url, tst), 0);
TEST(url_cmp(any, url), 0);
TEST(url->url_type, url_any);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_any);
TEST(url_cmp(any, u), 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)"*", NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
{
char buf[6];
TEST_1(u = url_hdup(home, (void *)"error"));
TEST_SIZE(url_xtra(u), 6);
TEST_SIZE(url_dup(buf, 6, url, u), 6);
TEST_S(buf, "error");
}
{
TEST_1(u = url_hdup(home, (void *)"scheme:test"));
TEST(u->url_type, url_unknown);
}
{
TEST_1(u = url_hdup(home, (void *)"*;param=foo?query=bar"));
TEST(u->url_type, url_unknown);
TEST_S(u->url_host, "*");
TEST_S(u->url_params, "param=foo");
TEST_S(u->url_headers, "query=bar");
}
{
TEST_1(u = url_hdup(home, (void *)"#foo"));
TEST(u->url_type, url_unknown);
TEST_S(u->url_fragment, "foo");
}
{
url_t u[1];
char b2[6] = "";
memset(u, 0xff, sizeof u);
TEST(url_d(u, b2), 0);
TEST(u->url_type, url_unknown);
}
su_home_deinit(home);
END();
}
int test_sip(void)
{
/* sip urls */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t sip[1] = { URL_INIT_AS(sip) };
url_t *u, url[1];
char *tst, *s;
char sipurl0[] =
"sip:pekka%2Epessi@nokia%2Ecom;method=%4D%45%53%53%41%47%45"
"?body=CANNED%20MSG";
char sipurl[] =
"sip:user:pass@host:32;param=1"
"?From=foo@bar&To=bar@baz#unf";
char sip2url[] =
"sip:user/path;tel-param:pass@host:32;param=1%3d%3d1"
"?From=foo@bar&To=bar@baz#unf";
char sip2[sizeof(sipurl) + 32];
char sipsurl[] =
"sips:user:pass@host:32;param=1"
"?From=foo@bar&To=bar@baz#unf";
size_t i, j;
url_t *a, *b;
BEGIN();
TEST_S(url_scheme(url_sip), "sip");
TEST_S(url_scheme(url_sips), "sips");
memset(url, 255, sizeof url);
TEST(url_d(url, sipurl0), 0);
TEST(url->url_type, url_sip);
TEST(url->url_root, 0);
TEST_S(url->url_scheme, "sip");
TEST_S(url->url_user, "pekka.pessi");
TEST_P(url->url_password, NULL);
TEST_S(url->url_host, "nokia.com");
TEST_P(url->url_port, NULL);
TEST_P(url->url_path, NULL);
TEST_S(url->url_params, "method=MESSAGE");
TEST_S(url->url_headers, "body=CANNED%20MSG");
TEST_P(url->url_fragment, NULL);
TEST_S(url_query_as_header_string(home, url->url_headers),
"\n\nCANNED MSG");
sip->url_user = "user";
sip->url_password = "pass";
sip->url_host = "host";
sip->url_port = "32";
sip->url_params = "param=1";
sip->url_headers = "From=foo@bar&To=bar@baz";
sip->url_fragment = "unf";
memset(url, 255, sizeof url);
TEST_1(tst = su_strdup(home, sipurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(sip, url) == 0);
TEST(url->url_type, url_sip);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_sip);
TEST_1(url_cmp(sip, u) == 0);
TEST(url_e(sip2, sizeof(sip2), u), strlen(sipurl));
TEST_1(strcmp(sip2, sipurl) == 0);
TEST_SIZE(snprintf(sip2, sizeof(sip2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(sip)), strlen(sipurl));
TEST_1(strcmp(sip2, sipurl) == 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t const *)sipurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
TEST_1(tst = su_strdup(home, sip2url));
TEST_1(url_d(url, tst) == 0);
TEST_S(url->url_user, "user/path;tel-param");
TEST_S(url->url_params, "param=1%3D%3D1");
TEST_S(url_query_as_header_string(home, url->url_headers),
"From:foo@bar\nTo:bar@baz");
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)sip2url, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
sip->url_type = url_sips; sip->url_scheme = "sips";
TEST_1(tst = su_strdup(home, sipsurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(sip, url) == 0);
TEST(url->url_type, url_sips);
/* Test url_dup() */
for (i = 0; i <= sizeof(sipsurl); i++) {
char buf[sizeof(sipsurl) + 1];
url_t dst[1];
buf[i] = '\377';
TEST_SIZE(url_dup(buf, i, dst, url), sizeof(sipsurl) - 1 - strlen("sips"));
TEST(buf[i], '\377');
}
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)sipsurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
u = url_hdup(home, (url_t*)"SIP:test@127.0.0.1:55"); TEST_1(u);
TEST(u->url_type, url_sip);
TEST_P(url_hdup(home, (url_t*)"sip:test@127.0.0.1::55"), NULL);
TEST_P(url_hdup(home, (url_t*)"sip:test@127.0.0.1:55:"), NULL);
TEST_P(url_hdup(home, (url_t*)"sip:test@127.0.0.1:sip"), NULL);
u = url_hdup(home, (url_t*)"SIP:#**00**#;foo=/bar@127.0.0.1"); TEST_1(u);
TEST(u->url_type, url_sip);
TEST_S(u->url_user, "#**00**#;foo=/bar");
TEST_1(!url_hdup(home, (url_t*)"SIP:#**00**#;foo=/bar@#127.0.0.1"));
TEST_1(!url_hdup(home, (url_t*)"SIP:#**00**#;foo=/bar;127.0.0.1"));
for (i = 32; i <= 256; i++) {
char pu[512];
char param[512];
for (j = 0; j < i; j++)
param[j] = 'x';
param[j] = '\0';
memcpy(param, "x=", 2);
snprintf(pu, sizeof(pu), "sip:test@host;%s", param);
u = url_hdup(home, (url_t*)pu); TEST_1(u);
s = url_as_string(home, u);
TEST_S(pu, s);
}
s = su_strdup(home, "ttl;transport=tcp;ttl=15;ttl=;method=INVITE;ttl");
TEST_1(s);
s = url_strip_param_string(s, "ttl");
TEST_S(s, "transport=tcp;method=INVITE");
u = url_hdup(home, (void*)"sip:u:p@host:5060;maddr=127.0.0.1;transport=tcp");
TEST_1(u);
TEST_1(url_have_transport(u));
TEST_1(url_strip_transport(u));
TEST_P(u->url_params, NULL);
TEST_1(!url_have_transport(u));
u = url_hdup(home, (void*)"sip:u:p@host:5060;user=phone;ttl=1;isfocus");
TEST_1(u);
TEST_1(url_have_transport(u));
TEST_1(url_strip_transport(u));
TEST_S(u->url_params, "user=phone;isfocus");
TEST_1(!url_have_transport(u));
u = url_hdup(home, (void*)"sip:u:p@host:5060;maddr=127.0.0.1;user=phone");
TEST_1(u);
TEST_1(url_have_transport(u));
TEST_1(url_strip_transport(u));
TEST_S(u->url_params, "user=phone");
TEST_1(!url_have_transport(u));
u = url_hdup(home, (void*)"sip:u:p@host:5060;user=phone;transport=tcp");
TEST_1(u);
TEST_1(url_have_transport(u));
TEST_1(url_strip_transport(u));
TEST_S(u->url_params, "user=phone");
TEST_1(!url_have_transport(u));
u = url_hdup(home, (void*)"sip:u:p@host;user=phone;;");
TEST_1(u);
/* We don't have transport params */
TEST_1(!url_have_transport(u));
/* ...but we still strip empty params */
TEST_1(url_strip_transport(u));
TEST_S(u->url_params, "user=phone");
TEST_1(!url_have_transport(u));
u = url_hdup(home, (void*)"sip:u:p@host:5060;ttl=1;isfocus;transport=udp;");
TEST_1(u);
TEST_1(url_have_transport(u));
TEST_1(url_strip_transport(u));
TEST_S(u->url_params, "isfocus");
TEST_1(!url_have_transport(u));
u = url_hdup(home, (void *)"sip:%22foo%22@172.21.55.55:5060");
TEST_1(u);
TEST_S(u->url_user, "%22foo%22");
a = url_hdup(home, (void *)"sip:172.21.55.55:5060");
b = url_hdup(home, (void *)"sip:172.21.55.55");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) == 0);
TEST(url_cmp_all(a, b), 0);
a = url_hdup(home, (void *)"sips:172.21.55.55:5060");
b = url_hdup(home, (void *)"sips:172.21.55.55");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) != 0);
TEST_1(url_cmp_all(a, b) < 0);
a = url_hdup(home, (void *)"sips:172.21.55.55:5061");
b = url_hdup(home, (void *)"sips:172.21.55.55");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) == 0);
TEST(url_cmp_all(a, b), 0);
a = url_hdup(home, (void *)"sip:my.domain:5060");
b = url_hdup(home, (void *)"sip:my.domain");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) > 0);
TEST_1(url_cmp_all(a, b) > 0);
a = url_hdup(home, (void *)"sips:my.domain:5061");
b = url_hdup(home, (void *)"sips:my.domain");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) > 0);
TEST_1(url_cmp_all(a, b) > 0);
a = url_hdup(home, (void *)"sip:my.domain");
b = url_hdup(home, (void *)"SIP:MY.DOMAIN");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) == 0);
TEST_1(url_cmp_all(a, b) == 0);
su_home_deinit(home);
END();
}
int test_wv(void)
{
/* wv urls */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t wv[1] = { URL_INIT_AS(wv) };
url_t *u, url[1];
char *tst;
char wvurl[] = "wv:+12345678@imps.com";
char wv2[sizeof(wvurl) + 32];
BEGIN();
TEST_S(url_scheme(url_wv), "wv");
wv->url_user = "+12345678";
wv->url_host = "imps.com";
TEST_1(tst = su_strdup(home, wvurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(wv, url) == 0);
TEST_1(url_cmp(url_hdup(home, (void *)"wv:+12345678@imps.com"), url) == 0);
TEST(url->url_type, url_wv);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_wv);
TEST_1(url_cmp(wv, u) == 0);
TEST_SIZE(url_e(wv2, sizeof(wv2), u), strlen(wvurl));
TEST_1(strcmp(wv2, wvurl) == 0);
TEST_SIZE(snprintf(wv2, sizeof(wv2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(wv)), strlen(wvurl));
TEST_1(strcmp(wv2, wvurl) == 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)wvurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
TEST_1(u = url_hdup(home, (void*)"wv:/managers@imps.com"));
TEST_S(u->url_user, "/managers");
su_home_deinit(home);
END();
}
int test_tel(void)
{
/* tel urls: RFC 3906 */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t tel[1] = { URL_INIT_AS(tel) };
url_t *u, url[1];
char *tst;
char telurl[] =
"tel:+12345678"
";param=1;param=2"
"?From=foo@bar&To=bar@baz#unf";
char tel2[sizeof(telurl) + 32];
url_t *a, *b;
BEGIN();
TEST_S(url_scheme(url_tel), "tel");
tel->url_user = "+12345678";
tel->url_params = "param=1;param=2";
tel->url_headers = "From=foo@bar&To=bar@baz";
tel->url_fragment = "unf";
TEST_1(tst = su_strdup(home, telurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(tel, url) == 0);
TEST_1(url_cmp(url_hdup(home, (url_t const *)"tel:+12345678"
";param=1;param=2"
"?From=foo@bar&To=bar@baz#unf"), url) == 0);
TEST(url->url_type, url_tel);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_tel);
TEST_1(url_cmp(tel, u) == 0);
TEST_SIZE(url_e(tel2, sizeof(tel2), u), strlen(telurl));
TEST_1(strcmp(tel2, telurl) == 0);
TEST_SIZE(snprintf(tel2, sizeof(tel2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(tel)), strlen(telurl));
TEST_1(strcmp(tel2, telurl) == 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)telurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
a = url_hdup(home, (void *)"tel:+1.245.62357");
b = url_hdup(home, (void *)"tel:+(1).245.62357");
TEST_1(a); TEST_1(b);
TEST_1(url_cmp(a, b) == 0);
TEST_1(url_cmp_all(a, b) == 0);
su_home_deinit(home);
END();
}
int test_fax(void)
{
/* fax urls */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t fax[1] = { URL_INIT_AS(fax) };
url_t *u, url[1];
char *tst;
char faxurl[] =
"fax:+12345678"
";param=1;param=2"
"?From=foo@bar&To=bar@baz#unf";
char fax2[sizeof(faxurl) + 32];
BEGIN();
TEST_S(url_scheme(url_fax), "fax");
fax->url_user = "+12345678";
fax->url_params = "param=1;param=2";
fax->url_headers = "From=foo@bar&To=bar@baz";
fax->url_fragment = "unf";
TEST_1(tst = su_strdup(home, faxurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(fax, url) == 0);
TEST(url->url_type, url_fax);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_fax);
TEST_1(url_cmp(fax, u) == 0);
TEST_SIZE(url_e(fax2, sizeof(fax2), u), strlen(faxurl));
TEST_1(strcmp(fax2, faxurl) == 0);
TEST_SIZE(snprintf(fax2, sizeof(fax2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(fax)), strlen(faxurl));
TEST_1(strcmp(fax2, faxurl) == 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)faxurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
END();
}
int test_modem(void)
{
/* modem urls */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t modem[1] = { URL_INIT_AS(modem) };
url_t *u, url[1];
char *tst;
char modemurl[] =
"modem:+12345678"
";param=1;param=2"
"?From=foo@bar&To=bar@baz#unf";
char modem2[sizeof(modemurl) + 32];
BEGIN();
TEST_S(url_scheme(url_modem), "modem");
modem->url_user = "+12345678";
modem->url_params = "param=1;param=2";
modem->url_headers = "From=foo@bar&To=bar@baz";
modem->url_fragment = "unf";
TEST_1(tst = su_strdup(home, modemurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(modem, url) == 0);
TEST(url->url_type, url_modem);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_modem);
TEST_1(url_cmp(modem, u) == 0);
TEST_SIZE(url_e(modem2, sizeof(modem2), u), strlen(modemurl));
TEST_1(strcmp(modem2, modemurl) == 0);
TEST_SIZE(snprintf(modem2, sizeof(modem2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(modem)), strlen(modemurl));
TEST_1(strcmp(modem2, modemurl) == 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)modemurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
END();
}
int test_file(void)
{
/* Test a url with path like file:/foo/bar */
char fileurl[] = "file:///foo/bar";
url_t file[1] = { URL_INIT_AS(file) };
su_home_t home[1] = { SU_HOME_INIT(home) };
char *tst;
url_t *u, url[1];
char buf1[sizeof(fileurl) + 32];
char buf2[sizeof(fileurl) + 32];
BEGIN();
TEST_S(url_scheme(url_file), "file");
TEST_1(tst = su_strdup(home, fileurl));
TEST(url_d(url, tst), 0);
TEST_S(url->url_host, "");
file->url_root = '/';
file->url_host = "";
file->url_path = "foo/bar";
TEST(url_cmp(file, url), 0);
TEST(url->url_type, url_file);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_file);
TEST(url_cmp(file, u), 0);
TEST_SIZE(url_e(buf1, sizeof(buf1), u), strlen(fileurl));
TEST_S(buf1, fileurl);
TEST_SIZE(snprintf(buf2, sizeof(buf2), URL_PRINT_FORMAT, URL_PRINT_ARGS(u)),
strlen(fileurl));
TEST_S(buf2, fileurl);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)fileurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
END();
}
int test_ldap(void)
{
/* Test a LDAP url */
char ldapurl[] = "ldap://cn=Manager,o=nokia:secret@localhost:389/ou=devices,o=nokia";
url_t ldap[1] = { URL_INIT_AS(file) };
su_home_t home[1] = { SU_HOME_INIT(home) };
char *tst;
url_t *u, url[1];
char buf1[sizeof(ldapurl) + 32];
char buf2[sizeof(ldapurl) + 32];
BEGIN();
ldap->url_type = url_unknown;
ldap->url_scheme = "ldap";
/* TEST_S(url_scheme(url_ldap), "ldap"); */
TEST_1(tst = su_strdup(home, ldapurl));
TEST(url_d(url, tst), 0);
TEST_S(url->url_user, "cn=Manager,o=nokia:secret");
/* TEST_S(url->url_password, "secret"); */
TEST_S(url->url_host, "localhost");
TEST_S(url->url_port, "389");
TEST_S(url->url_path, "ou=devices,o=nokia");
ldap->url_user = "cn=Manager,o=nokia";
ldap->url_password = "secret";
ldap->url_user = "cn=Manager,o=nokia:secret", ldap->url_password = NULL;
ldap->url_host = "localhost";
ldap->url_port = "389";
ldap->url_path = "ou=devices,o=nokia";
TEST(url_cmp(ldap, url), 0);
TEST(url->url_type, url_unknown);
TEST_S(url->url_scheme, "ldap");
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_unknown);
TEST_S(u->url_scheme, "ldap");
TEST(url_cmp(ldap, u), 0);
TEST_SIZE(url_e(buf1, sizeof(buf1), u), strlen(ldapurl));
TEST_S(buf1, ldapurl);
TEST_SIZE(snprintf(buf2, sizeof(buf2), URL_PRINT_FORMAT, URL_PRINT_ARGS(u)),
strlen(ldapurl));
TEST_S(buf2, ldapurl);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)ldapurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
END();
}
int test_rtsp(void)
{
/* RTSP urls */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t rtsp[1] = { URL_INIT_AS(rtsp) };
url_t *u, url[1];
char *tst;
char rtspurl[] = "rtsp://example.com:42/barfoo.rm";
char rtspuurl[] = "rtspu://example.com:42/barfoo.rm";
char rtsp2[sizeof(rtspurl) + 32];
BEGIN();
TEST_S(url_scheme(url_rtsp), "rtsp");
TEST_S(url_scheme(url_rtspu), "rtspu");
rtsp->url_root = 1;
rtsp->url_host = "example.com";
rtsp->url_port = "42";
rtsp->url_path = "barfoo.rm";
TEST_1(tst = su_strdup(home, rtspurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(rtsp, url) == 0);
TEST(url->url_type, url_rtsp);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_rtsp);
TEST_1(url_cmp(rtsp, u) == 0);
TEST(url_e(rtsp2, sizeof(rtsp2), u), strlen(rtspurl));
TEST_1(strcmp(rtsp2, rtspurl) == 0);
TEST_SIZE(snprintf(rtsp2, sizeof(rtsp2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(rtsp)), strlen(rtspurl));
TEST_1(strcmp(rtsp2, rtspurl) == 0);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)rtspurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
rtsp->url_type = url_rtspu, rtsp->url_scheme = "rtspu";
TEST_1(tst = su_strdup(home, rtspuurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(rtsp, url) == 0);
TEST(url->url_type, url_rtspu);
url_digest(hash1, sizeof(hash1), url, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)rtspuurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
END();
}
int test_http(void)
{
/* http urls */
su_home_t home[1] = { SU_HOME_INIT(home) };
url_t http[1] = { URL_INIT_AS(http) };
url_t *u, url[1];
char *tst;
char httpurl[] =
"http://user:pass@host:32/foo;param=1/bar;param=3"
"?From=foo@bar&To=bar@baz#unf";
char http2[sizeof(httpurl) + 32];
char queryonly[] =
"http://some.host?query";
BEGIN();
TEST_S(url_scheme(url_http), "http");
TEST_S(url_scheme(url_https), "https");
http->url_root = '/';
http->url_user = "user";
http->url_password = "pass";
http->url_host = "host";
http->url_port = "32";
http->url_path = "foo;param=1/bar;param=3";
http->url_headers = "From=foo@bar&To=bar@baz";
http->url_fragment = "unf";
TEST_1(tst = su_strdup(home, httpurl));
TEST_1(url_d(url, tst) == 0);
TEST_1(url_cmp(http, url) == 0);
TEST(url->url_type, url_http);
TEST_1(u = url_hdup(home, url));
TEST(u->url_type, url_http);
TEST_1(url_cmp(http, u) == 0);
TEST_SIZE(url_e(http2, sizeof(http2), u), strlen(httpurl));
TEST_1(strcmp(http2, httpurl) == 0);
TEST_SIZE(snprintf(http2, sizeof(http2), URL_PRINT_FORMAT,
URL_PRINT_ARGS(http)), strlen(httpurl));
TEST_1(strcmp(http2, httpurl) == 0);
url_digest(hash1, sizeof(hash1), http, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)httpurl, NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
memset(url, 0, sizeof url);
TEST_1(tst = su_strdup(home, queryonly));
TEST(url_d(url, tst), 0);
TEST_S(url->url_host, "some.host");
TEST_S(url->url_headers, "query");
TEST_S(url->url_params, NULL);
TEST_1(u = url_hdup(home, (void *)"http://[::1]/test;ing?here"));
TEST_S(u->url_host, "[::1]");
TEST_S(u->url_path, "test;ing");
TEST_S(u->url_headers, "here");
url_digest(hash1, sizeof(hash1), u, NULL);
url_digest(hash2, sizeof(hash2), (url_t *)"http://[::1]/test;ing?here",
NULL);
TEST(memcmp(hash1, hash2, sizeof(hash1)), 0);
su_home_deinit(home);
END();
}
int test_sanitizing(void)
{
url_t url[1];
char www[] = "www.hut.fi";
char ftp[] = "ftp.hut.fi";
char www2[] = "iptel.hut.fi/humppa";
char sip[] = "test.host";
char buf[64];
BEGIN();
TEST_1(url_d(url, www) == 0);
TEST_1(url_sanitize(url) == 0);
TEST(url->url_type, url_http);
snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url));
TEST_S(buf, "http://www.hut.fi");
TEST_1(url_d(url, ftp) == 0);
TEST_1(url_sanitize(url) == 0);
TEST(url->url_type, url_ftp);
snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url));
TEST_S(buf, "ftp://ftp.hut.fi");
TEST_1(url_d(url, www2) == 0);
TEST_1(url_sanitize(url) == 0);
TEST(url->url_type, url_http);
snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url));
TEST_S(buf, "http://iptel.hut.fi/humppa");
TEST_1(url_d(url, sip) == 0);
TEST_1(url_sanitize(url) == 0);
TEST(url->url_type, url_sip);
snprintf(buf, sizeof(buf), URL_PRINT_FORMAT, URL_PRINT_ARGS(url));
TEST_S(buf, "sip:test.host");
END();
}
int test_tags(void)
{
url_t u0[1];
url_t *u1 = NULL;
url_t const *u2 = (void *)-1;
url_t const u3[1] = { URL_INIT_AS(sip) };
char c0[] = "http://www.nokia.com";
char const *c1 = "http://goodfeel.nokia.com";
char *c2 = "http://forum.nokia.com";
char const c3[] = "http://www.research.nokia.com";
url_string_t *us0 = NULL;
tagi_t *lst, *dup;
tag_value_t value;
char *s;
su_home_t home[1] = { SU_HOME_INIT(home) };
BEGIN();
TEST(t_scan(urltag_url, home, c0, &value), 0);
TEST_S(s = url_as_string(home, (url_t *)value), c0);
TEST(t_scan(urltag_url, home, c3, &value), 0);
TEST_S(s = url_as_string(home, (url_t *)value), c3);
TEST_1(url_d(u0, c0) == 0);
lst = tl_list(URLTAG_URL(u0),
URLTAG_URL(u1),
URLTAG_URL(u2),
URLTAG_URL(u3),
URLTAG_URL(c0),
URLTAG_URL(c1),
URLTAG_URL(c2),
URLTAG_URL(c3),
URLTAG_URL(us0),
TAG_NULL());
TEST_1(lst);
dup = tl_adup(home, lst);
tl_vfree(lst);
su_free(home, dup);
su_home_deinit(home);
END();
}
#include <sofia-sip/su_tag_class.h>
int test_tag_filter(void)
{
BEGIN();
#undef TAG_NAMESPACE
#define TAG_NAMESPACE "test"
tag_typedef_t tag_a = STRTAG_TYPEDEF(a);
#define TAG_A(s) tag_a, tag_str_v((s))
tag_typedef_t tag_b = STRTAG_TYPEDEF(b);
#define TAG_B(s) tag_b, tag_str_v((s))
tagi_t filter[2] = {{ URLTAG_ANY() }, { TAG_END() }};
tagi_t *lst, *result;
lst = tl_list(TAG_A("X"),
TAG_SKIP(2),
URLTAG_URL((void *)"urn:foo"),
TAG_B("Y"),
URLTAG_URL((void *)"urn:bar"),
TAG_NULL());
TEST_1(lst);
result = tl_afilter(NULL, filter, lst);
TEST_1(result);
TEST_P(result[0].t_tag, urltag_url);
TEST_P(result[1].t_tag, urltag_url);
tl_vfree(lst);
free(result);
END();
}
#if 0
/* This is just a spike. How we can get
* register_printf_function('U', printf_url, printf_url_info)
* run while initializing?
*/
#include <printf.h>
int printf_url(FILE *fp,
const struct printf_info *info,
const void * const *args)
{
url_t const *url = *(url_t **)args[0];
return fprintf(fp, URL_PRINT_FORMAT, URL_PRINT_ARGS(url));
}
/* This is the appropriate argument information function for `printf_url'. */
int printf_url_info(const struct printf_info *info,
size_t n, int *argtypes)
{
if (n > 0) {
argtypes[0] = PA_POINTER;
return 1;
}
return 0;
}
#endif
int test_print(void)
{
#if 0
url_t u0[1];
url_t *u1 = NULL;
url_t const *u2 = (void *)-1;
url_t const u3[1] = { URL_INIT_AS(sip) };
char c0[] = "http://www.nokia.com/";
char c1[] = "http://goodfeel.nokia.com/test";
char c2[] = "/test2/";
char c3[] = "///file/";
tagi_t *lst;
BEGIN();
TEST(register_printf_function('U', printf_url, printf_url_info), 0);
TEST(url_d(u0, c0), 0);
printf("URL is %U\n", u0);
TEST(url_d(u0, c1), 0);
printf("URL is %U\n", u0);
TEST(url_d(u0, c2), 0);
printf("URL is %U\n", u0);
TEST(url_d(u0, c3), 0);
printf("URL is %U\n", u0);
#else
BEGIN();
#endif
END();
}
void usage(int exitcode)
{
fprintf(stderr, "usage: %s [-v] [-a]\n", name);
exit(exitcode);
}
int main(int argc, char *argv[])
{
int retval = 0;
int i;
for (i = 1; argv[i]; i++) {
if (strcmp(argv[i], "-v") == 0)
tstflags |= tst_verbatim;
else if (strcmp(argv[i], "-a") == 0)
tstflags |= tst_abort;
else
usage(1);
}
#if HAVE_OPEN_C
tstflags |= tst_verbatim;
#endif
retval |= test_quote(); fflush(stdout);
retval |= test_any(); fflush(stdout);
retval |= test_sip(); fflush(stdout);
retval |= test_wv(); fflush(stdout);
retval |= test_tel(); fflush(stdout);
retval |= test_fax(); fflush(stdout);
retval |= test_modem(); fflush(stdout);
retval |= test_file(); fflush(stdout);
retval |= test_ldap(); fflush(stdout);
retval |= test_rtsp(); fflush(stdout);
retval |= test_http(); fflush(stdout);
retval |= test_sanitizing(); fflush(stdout);
retval |= test_tags(); fflush(stdout);
retval |= test_print(); fflush(stdout);
retval |= test_tag_filter(); fflush(stdout);
return retval;
}