2 The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
3 Copyright (C) 2001 Aymeric MOIZARD jack@atosc.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <osip2/internal.h>
29 #include <osipparser2/osip_uri.h>
31 int osip_uri_test_accessor_api (osip_uri_t * url);
35 main (int argc, char **argv)
45 urls_file = fopen (argv[1], "r");
46 if (urls_file == NULL)
48 fprintf (stdout, "Failed to open %s file.\nUsage: turls urls.txt\n",
53 a_url = (char *) osip_malloc (200);
54 res = fgets (a_url, 200, urls_file); /* lines are under 200 */
59 /* remove the last '\n' before parsing */
60 osip_strncpy (a_url + strlen (a_url) - 1, "\0", 1);
62 if (0 != strncmp (a_url, "#", 1))
64 /* allocate & init url */
66 printf ("=================================================\n");
67 printf ("URL TO PARSE: |%s|\n", a_url);
68 errcode = osip_uri_parse (url, a_url);
71 if (osip_uri_to_str (url, &dest) != -1)
73 printf ("result: |%s|\n", dest);
74 osip_uri_test_accessor_api (url);
79 printf ("Bad url format: %s\n", a_url);
81 printf ("=================================================\n");
83 res = fgets (a_url, 200, urls_file); /* lines are under 200 */
90 osip_uri_test_accessor_api (osip_uri_t * url)
92 if (url->scheme != NULL)
93 fprintf (stdout, "%s:", url->scheme);
94 if (url->string != NULL)
96 fprintf (stdout, "|%s", url->string);
97 fprintf (stdout, "\n");
100 if (url->username != NULL)
101 fprintf (stdout, "%s|", url->username);
103 if ((url->password != NULL) && (url->username != NULL))
104 fprintf (stdout, ":%s|", url->password);
105 if (url->username != NULL)
106 fprintf (stdout, "@|");
107 /* if (url->host!=NULL) mandatory */
108 if (strchr (url->host, ':') != NULL)
109 fprintf (stdout, "[%s]|", url->host);
111 fprintf (stdout, "%s|", url->host);
112 if (url->port != NULL)
113 fprintf (stdout, ":%s|", url->port);
115 fprintf (stdout, "\nuri-params\n");
119 osip_uri_param_t *u_param;
121 while (!osip_list_eol (url->url_params, pos))
123 u_param = (osip_uri_param_t *) osip_list_get (url->url_params, pos);
124 if (u_param->gvalue != NULL)
125 fprintf (stdout, ";%s|=|%s|", u_param->gname, u_param->gvalue);
127 fprintf (stdout, ";%s|", u_param->gname);
132 fprintf (stdout, "\nheaders\n");
136 osip_uri_header_t *u_header;
138 while (!osip_list_eol (url->url_headers, pos))
141 (osip_uri_header_t *) osip_list_get (url->url_headers, pos);
143 fprintf (stdout, "?%s|=|%s|", u_header->gname, u_header->gvalue);
145 fprintf (stdout, "&%s|=|%s|", u_header->gname, u_header->gvalue);
149 fprintf (stdout, "\n");