2 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3 Copyright (C) 2001,2002,2003 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
23 #include <osipparser2/osip_port.h>
24 #include <osipparser2/osip_message.h>
25 #include <osipparser2/osip_parser.h>
28 osip_record_route_init (osip_record_route_t ** record_route)
30 return osip_from_init ((osip_from_t **) record_route);
33 /* adds the record_route header to message. */
34 /* INPUT : const char *hvalue | value of header. */
35 /* OUTPUT: osip_message_t *sip | structure to save results. */
36 /* returns -1 on error. */
38 osip_message_set_record_route (osip_message_t * sip, const char *hvalue)
40 osip_record_route_t *record_route;
43 if (hvalue == NULL || hvalue[0] == '\0')
46 i = osip_record_route_init (&record_route);
49 i = osip_record_route_parse (record_route, hvalue);
52 osip_record_route_free (record_route);
55 sip->message_property = 2;
56 osip_list_add (sip->record_routes, record_route, -1);
60 /* returns the record_route header. */
61 /* INPUT : osip_message_t *sip | sip message. */
62 /* returns null on error. */
64 osip_message_get_record_route (const osip_message_t * sip, int pos,
65 osip_record_route_t ** dest)
67 osip_record_route_t *record_route;
70 if (osip_list_size (sip->record_routes) <= pos)
71 return -1; /* does not exist */
73 (osip_record_route_t *) osip_list_get (sip->record_routes, pos);
79 osip_record_route_parse (osip_record_route_t * record_route,
82 return osip_from_parse ((osip_from_t *) record_route, hvalue);
85 /* returns the record_route header as a string. */
86 /* INPUT : osip_record_route_t *record_route | record_route header. */
87 /* returns -1 on error. */
89 osip_record_route_to_str (const osip_record_route_t * record_route,
98 if ((record_route == NULL) || (record_route->url == NULL))
101 i = osip_uri_to_str (record_route->url, &url);
105 if (record_route->displayname == NULL)
106 len = strlen (url) + 5;
108 len = strlen (url) + strlen (record_route->displayname) + 5;
110 buf = (char *) osip_malloc (len);
117 /* route and record-route always use brackets */
118 if (record_route->displayname != NULL)
119 sprintf (buf, "%s <%s>", record_route->displayname, url);
121 sprintf (buf, "<%s>", url);
126 osip_generic_param_t *u_param;
130 while (!osip_list_eol (record_route->gen_params, pos))
133 (osip_generic_param_t *) osip_list_get (record_route->gen_params,
136 if (u_param->gvalue == NULL)
137 plen = strlen (u_param->gname) + 2;
139 plen = strlen (u_param->gname) + strlen (u_param->gvalue) + 3;
141 buf = (char *) realloc (buf, len);
143 tmp = tmp + strlen (tmp);
144 if (u_param->gvalue == NULL)
145 sprintf (tmp, ";%s", u_param->gname);
147 sprintf (tmp, ";%s=%s", u_param->gname, u_param->gvalue);
155 /* deallocates a osip_record_route_t structure. */
156 /* INPUT : osip_record_route_t *record_route | record_route header. */
158 osip_record_route_free (osip_record_route_t * record_route)
160 osip_from_free ((osip_from_t *) record_route);