torture_url.c 29.1 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * 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
 *
 */

25
/**@CFILE torture_url.c Test functions for url parser
Pekka Pessi's avatar
Pekka Pessi committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 *
 * @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>

41 42
#include "sofia-sip/url.h"
#include "sofia-sip/url_tag.h"
Pekka Pessi's avatar
Pekka Pessi committed
43

44 45
static int tstflags = 0;

Pekka Pessi's avatar
Pekka Pessi committed
46 47
#define TSTFLAGS tstflags

48
#include <sofia-sip/tstdef.h>
Pekka Pessi's avatar
Pekka Pessi committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

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();

79 80 81
  d = url_as_string(home, (url_t *)"sip:joe@example.com");
  TEST_S(d, "sip:joe@example.com");

Pekka Pessi's avatar
Pekka Pessi committed
82 83 84 85 86 87 88
  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"));

89 90 91 92 93 94
  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));
Pekka Pessi's avatar
Pekka Pessi committed
95 96 97 98 99 100 101

  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);

102
  TEST_SIZE(url_esclen(UNRESERVED, NULL), strlen(UNRESERVED));
Pekka Pessi's avatar
Pekka Pessi committed
103 104 105
  TEST_S(url_escape(unreserved, UNRESERVED, NULL), UNRESERVED);
  TEST_S(url_unescape(unreserved, UNRESERVED), UNRESERVED);

106
  d = "%53ip:%75@%48";		/* Sip:u@H */
Pekka Pessi's avatar
Pekka Pessi committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  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);

123
  d = "sip:&=+$,;?/:&=+$,@[::1]:56001;param=+$,/:@&;another=@"
Pekka Pessi's avatar
Pekka Pessi committed
124 125
    "?header=" RESERVED "&%3b%2f%3f%3a%40%26%3d%2b%24%2c";
  u = url_hdup(home, (url_t *)d); TEST_1(u);
126 127
  TEST_S(u->url_user, "&=+$,;?/");
  TEST_S(u->url_host, "[::1]");
128
  TEST_S(u->url_headers, "header=" RESERVED "&%3B%2F%3F%3A%40%26%3D%2B%24%2C");
Pekka Pessi's avatar
Pekka Pessi committed
129 130 131 132 133 134 135 136
  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);

137 138
  d = "http://&=+$,;:&=+$,;@host:8080/foo;param=+$,/:@&;another=@"
    "?query=" RESERVED;
Pekka Pessi's avatar
Pekka Pessi committed
139
  u = url_hdup(home, (url_t *)d); TEST_1(u);
140
  TEST_S(u->url_user, "&=+$,;"); TEST_S(u->url_password, "&=+$,;");
Pekka Pessi's avatar
Pekka Pessi committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  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");
175
  TEST_S(url_scheme(url_msrps), "msrps");
Pekka Pessi's avatar
Pekka Pessi committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

  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"));
193 194
    TEST_SIZE(url_xtra(u), 6);
    TEST_SIZE(url_dup(buf, 6, url, u), 6);
Pekka Pessi's avatar
Pekka Pessi committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    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");
  }

  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"
    "?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";
242
  size_t i, j;
243
  url_t *a, *b;
Pekka Pessi's avatar
Pekka Pessi committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257

  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");
258
  TEST_P(url->url_password, NULL);
Pekka Pessi's avatar
Pekka Pessi committed
259
  TEST_S(url->url_host, "nokia.com");
260 261
  TEST_P(url->url_port, NULL);
  TEST_P(url->url_path, NULL);
Pekka Pessi's avatar
Pekka Pessi committed
262 263
  TEST_S(url->url_params, "method=MESSAGE");
  TEST_S(url->url_headers, "body=CANNED%20MSG");
264
  TEST_P(url->url_fragment, NULL);
265 266 267

  TEST_S(url_query_as_header_string(home, url->url_headers),
	 "\n\nCANNED MSG");
Pekka Pessi's avatar
Pekka Pessi committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
  
  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);
286
  TEST(url_e(sip2, sizeof(sip2), u), strlen(sipurl));
Pekka Pessi's avatar
Pekka Pessi committed
287
  TEST_1(strcmp(sip2, sipurl) == 0);
288 289
  TEST_SIZE(snprintf(sip2, sizeof(sip2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(sip)), strlen(sipurl));
Pekka Pessi's avatar
Pekka Pessi committed
290 291 292 293 294 295 296 297 298 299
  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");

300 301 302
  TEST_S(url_query_as_header_string(home, url->url_headers),
	 "From:foo@bar\nTo:bar@baz");

Pekka Pessi's avatar
Pekka Pessi committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
  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';
320
    TEST_SIZE(url_dup(buf, i, dst, url), sizeof(sipsurl) - 1 - strlen("sips"));
Pekka Pessi's avatar
Pekka Pessi committed
321 322 323 324 325 326 327 328 329 330
    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);

331 332 333
  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);
Pekka Pessi's avatar
Pekka Pessi committed
334

335 336 337 338
  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");

339 340 341
  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"));

Pekka Pessi's avatar
Pekka Pessi committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
  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);
  }

357 358 359 360 361
  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");

Pekka Pessi's avatar
Pekka Pessi committed
362 363 364 365
  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));
366
  TEST_P(u->url_params, NULL);
Pekka Pessi's avatar
Pekka Pessi committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
  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));

406 407 408 409
  u = url_hdup(home, (void *)"sip:%22foo%22@172.21.55.55:5060");
  TEST_1(u);
  TEST_S(u->url_user, "%22foo%22");

410 411 412 413
  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);
Pekka Pessi's avatar
Pekka Pessi committed
414
  TEST(url_cmp_all(a, b), 0);
415 416 417 418 419

  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);
Pekka Pessi's avatar
Pekka Pessi committed
420
  TEST_1(url_cmp_all(a, b) < 0);
421 422 423 424 425

  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);
Pekka Pessi's avatar
Pekka Pessi committed
426
  TEST(url_cmp_all(a, b), 0);
427 428 429 430

  a = url_hdup(home, (void *)"sip:my.domain:5060");
  b = url_hdup(home, (void *)"sip:my.domain");
  TEST_1(a); TEST_1(b);
Pekka Pessi's avatar
Pekka Pessi committed
431 432
  TEST_1(url_cmp(a, b) > 0);
  TEST_1(url_cmp_all(a, b) > 0);
433 434 435 436

  a = url_hdup(home, (void *)"sips:my.domain:5061");
  b = url_hdup(home, (void *)"sips:my.domain");
  TEST_1(a); TEST_1(b);
Pekka Pessi's avatar
Pekka Pessi committed
437 438 439 440 441 442 443 444
  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);
445

Pekka Pessi's avatar
Pekka Pessi committed
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
  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);
476
  TEST_SIZE(url_e(wv2, sizeof(wv2), u), strlen(wvurl));
Pekka Pessi's avatar
Pekka Pessi committed
477
  TEST_1(strcmp(wv2, wvurl) == 0);
478 479
  TEST_SIZE(snprintf(wv2, sizeof(wv2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(wv)), strlen(wvurl));
Pekka Pessi's avatar
Pekka Pessi committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
  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)
{
Pekka Pessi's avatar
Pekka Pessi committed
497
  /* tel urls: RFC 3906 */
Pekka Pessi's avatar
Pekka Pessi committed
498 499 500 501 502 503 504 505 506
  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];
Pekka Pessi's avatar
Pekka Pessi committed
507
  url_t *a, *b;
Pekka Pessi's avatar
Pekka Pessi committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
  
  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);
528
  TEST_SIZE(url_e(tel2, sizeof(tel2), u), strlen(telurl));
Pekka Pessi's avatar
Pekka Pessi committed
529
  TEST_1(strcmp(tel2, telurl) == 0);
530 531
  TEST_SIZE(snprintf(tel2, sizeof(tel2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(tel)), strlen(telurl));
Pekka Pessi's avatar
Pekka Pessi committed
532 533 534 535 536 537
  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);

Pekka Pessi's avatar
Pekka Pessi committed
538 539 540 541 542 543
  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);

Pekka Pessi's avatar
Pekka Pessi committed
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
  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);
578
  TEST_SIZE(url_e(fax2, sizeof(fax2), u), strlen(faxurl));
Pekka Pessi's avatar
Pekka Pessi committed
579
  TEST_1(strcmp(fax2, faxurl) == 0);
580 581
  TEST_SIZE(snprintf(fax2, sizeof(fax2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(fax)), strlen(faxurl));
Pekka Pessi's avatar
Pekka Pessi committed
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
  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);
623
  TEST_SIZE(url_e(modem2, sizeof(modem2), u), strlen(modemurl));
Pekka Pessi's avatar
Pekka Pessi committed
624
  TEST_1(strcmp(modem2, modemurl) == 0);
625 626
  TEST_SIZE(snprintf(modem2, sizeof(modem2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(modem)), strlen(modemurl));
Pekka Pessi's avatar
Pekka Pessi committed
627 628 629 630 631 632 633 634 635 636 637 638 639 640
  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  */
641
  char fileurl[] = "file:///foo/bar";
Pekka Pessi's avatar
Pekka Pessi committed
642 643 644 645 646 647 648 649 650 651 652 653 654
  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);
655
  TEST_S(url->url_host, "");
Pekka Pessi's avatar
Pekka Pessi committed
656
  file->url_root = '/';
657
  file->url_host = "";
Pekka Pessi's avatar
Pekka Pessi committed
658 659 660 661 662 663
  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);
664
  TEST_SIZE(url_e(buf1, sizeof(buf1), u), strlen(fileurl));
Pekka Pessi's avatar
Pekka Pessi committed
665
  TEST_S(buf1, fileurl);
666 667
  TEST_SIZE(snprintf(buf2, sizeof(buf2), URL_PRINT_FORMAT, URL_PRINT_ARGS(u)), 
	    strlen(fileurl));
Pekka Pessi's avatar
Pekka Pessi committed
668 669 670 671 672 673 674 675 676 677 678
  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();
}

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
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);
720
  TEST_SIZE(url_e(buf1, sizeof(buf1), u), strlen(ldapurl));
721
  TEST_S(buf1, ldapurl);
722 723
  TEST_SIZE(snprintf(buf2, sizeof(buf2), URL_PRINT_FORMAT, URL_PRINT_ARGS(u)), 
	    strlen(ldapurl));
724 725 726 727 728 729 730 731 732 733 734
  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();
}

Pekka Pessi's avatar
Pekka Pessi committed
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
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);
763
  TEST(url_e(rtsp2, sizeof(rtsp2), u), strlen(rtspurl));
Pekka Pessi's avatar
Pekka Pessi committed
764
  TEST_1(strcmp(rtsp2, rtspurl) == 0);
765 766
  TEST_SIZE(snprintf(rtsp2, sizeof(rtsp2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(rtsp)), strlen(rtspurl));
Pekka Pessi's avatar
Pekka Pessi committed
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
  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);
826
  TEST_SIZE(url_e(http2, sizeof(http2), u), strlen(httpurl));
Pekka Pessi's avatar
Pekka Pessi committed
827
  TEST_1(strcmp(http2, httpurl) == 0);
828 829
  TEST_SIZE(snprintf(http2, sizeof(http2), URL_PRINT_FORMAT, 
		     URL_PRINT_ARGS(http)), strlen(httpurl));
Pekka Pessi's avatar
Pekka Pessi committed
830 831 832 833 834 835 836 837 838 839 840 841
  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);
842 843 844 845 846 847 848 849 850 851

  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);
Pekka Pessi's avatar
Pekka Pessi committed
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
    
  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;
910 911 912
  
  tag_value_t value;
  char *s;
Pekka Pessi's avatar
Pekka Pessi committed
913 914 915 916
  su_home_t home[1] = { SU_HOME_INIT(home) };

  BEGIN();

917 918 919 920 921 922
  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);

Pekka Pessi's avatar
Pekka Pessi committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
  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();
}

949
#include <sofia-sip/su_tag_class.h>
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977

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);
978 979
  TEST_P(result[0].t_tag, urltag_url);
  TEST_P(result[1].t_tag, urltag_url);
980 981 982 983 984 985 986

  tl_vfree(lst);
  free(result);

  END();
}

Pekka Pessi's avatar
Pekka Pessi committed
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
#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();
}

1051 1052 1053 1054 1055
void usage(int exitcode)
{
  fprintf(stderr, "usage: %s [-v] [-a]\n", name);
  exit(exitcode);
}
1056 1057 1058 1059 1060 1061 1062 1063 1064

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;
1065 1066
    else if (strcmp(argv[i], "-a") == 0)
      tstflags |= tst_abort;
1067
    else
1068
      usage(1);
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
  }

  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);
1079
  retval |= test_ldap(); fflush(stdout);
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
  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;
}