Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / libosip2 / src / test / tcallid.c
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
3   Copyright (C) 2001  Aymeric MOIZARD jack@atosc.org
4   
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.
9   
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.
14   
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
18 */
19
20
21 #ifdef ENABLE_MPATROL
22 #include <mpatrol.h>
23 #endif
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <osip2/internal.h>
28 #include <osipparser2/osip_message.h>
29
30 int
31 main (int argc, char **argv)
32 {
33   FILE *callids_file;
34
35
36   osip_call_id_t *callid;
37   char *a_callid;
38   char *dest;
39   char *res;
40
41   callids_file = fopen (argv[1], "r");
42   if (callids_file == NULL)
43     {
44       fprintf (stdout,
45                "Failed to open %s file.\nUsage: tcallid callids.txt\n",
46                argv[1]);
47       exit (0);
48     }
49
50   a_callid = (char *) osip_malloc (200);
51   res = fgets (a_callid, 200, callids_file);    /* lines are under 200 */
52   while (res != NULL)
53     {
54
55       int errcode;
56
57       /* remove the last '\n' before parsing */
58       strncpy (a_callid + strlen (a_callid) - 1, "\0", 1);
59
60       if (0 != strncmp (a_callid, "#", 1))
61         {
62           /* allocate & init callid */
63           osip_call_id_init (&callid);
64           printf ("=================================================\n");
65           printf ("CALLID TO PARSE: |%s|\n", a_callid);
66           errcode = osip_call_id_parse (callid, a_callid);
67           if (errcode != -1)
68             {
69               if (osip_call_id_to_str (callid, &dest) != -1)
70                 {
71                   printf ("result:        |%s|\n", dest);
72                   osip_free (dest);
73                 }
74             }
75           else
76             printf ("Bad callid format: %s\n", a_callid);
77           osip_call_id_free (callid);
78           printf ("=================================================\n");
79         }
80       res = fgets (a_callid, 200, callids_file);        /* lines are under 200 */
81     }
82   osip_free (a_callid);
83   return 0;
84 }