and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_route.c
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3   Copyright (C) 2001,2002,2003  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 #include <stdlib.h>
21 #include <stdio.h>
22
23 #include <osipparser2/osip_port.h>
24 #include <osipparser2/osip_message.h>
25 #include <osipparser2/osip_parser.h>
26
27 #ifdef __VXWORKS_OS__
28 int
29 osip_route_init2 (osip_route_t ** route)
30 #else
31 int
32 osip_route_init (osip_route_t ** route)
33 #endif
34 {
35   return osip_from_init ((osip_from_t **) route);
36 }
37
38 /* adds the route header to message.         */
39 /* INPUT : const char *hvalue | value of header.    */
40 /* OUTPUT: osip_message_t *sip | structure to save results.  */
41 /* returns -1 on error. */
42 int
43 osip_message_set_route (osip_message_t * sip, const char *hvalue)
44 {
45   osip_route_t *route;
46   int i;
47
48   if (hvalue == NULL || hvalue[0] == '\0')
49     return 0;
50
51 #ifdef __VXWORKS_OS__
52   i = osip_route_init2 (&route);
53 #else
54   i = osip_route_init (&route);
55 #endif
56   if (i != 0)
57     return -1;
58   i = osip_route_parse (route, hvalue);
59   if (i != 0)
60     {
61       osip_route_free (route);
62       return -1;
63     }
64   sip->message_property = 2;
65   osip_list_add (sip->routes, route, -1);
66   return 0;
67 }
68
69 /* returns the route header.    */
70 /* INPUT : osip_message_t *sip | sip message.   */
71 /* returns null on error. */
72 int
73 osip_message_get_route (const osip_message_t * sip, int pos,
74                         osip_route_t ** dest)
75 {
76   osip_route_t *route;
77
78   *dest = NULL;
79   if (osip_list_size (sip->routes) <= pos)
80     return -1;                  /* does not exist */
81   route = (osip_route_t *) osip_list_get (sip->routes, pos);
82   *dest = route;
83   return pos;
84 }
85
86 int
87 osip_route_parse (osip_route_t * route, const char *hvalue)
88 {
89   return osip_from_parse ((osip_from_t *) route, hvalue);
90 }
91
92 /* returns the route header as a string.          */
93 /* INPUT : osip_route_t *route | route header.  */
94 /* returns null on error. */
95 int
96 osip_route_to_str (const osip_route_t * route, char **dest)
97 {
98   /* we can't use osip_from_to_str(): route and record_route */
99   /* always use brackets. */
100   return osip_record_route_to_str ((osip_record_route_t *) route, dest);
101 }
102
103 /* deallocates a osip_route_t structure.  */
104 /* INPUT : osip_route_t *route | route header. */
105 void
106 osip_route_free (osip_route_t * route)
107 {
108   osip_from_free ((osip_from_t *) route);
109 }