and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_to.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 int
28 osip_to_init (osip_to_t ** to)
29 {
30   return osip_from_init ((osip_from_t **) to);
31 }
32
33 /* adds the to 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. */
37 int
38 osip_message_set_to (osip_message_t * sip, const char *hvalue)
39 {
40   int i;
41
42   if (hvalue == NULL || hvalue[0] == '\0')
43     return 0;
44
45   if (sip->to != NULL)
46     return -1;
47   i = osip_to_init (&(sip->to));
48   if (i != 0)
49     return -1;
50   sip->message_property = 2;
51   i = osip_to_parse (sip->to, hvalue);
52   if (i != 0)
53     {
54       osip_to_free (sip->to);
55       sip->to = NULL;
56       return -1;
57     }
58   return 0;
59 }
60
61 /* returns the to header.            */
62 /* INPUT : osip_message_t *sip | sip message.   */
63 /* returns null on error. */
64 osip_to_t *
65 osip_message_get_to (const osip_message_t * sip)
66 {
67   return sip->to;
68 }
69
70 int
71 osip_to_parse (osip_to_t * to, const char *hvalue)
72 {
73   return osip_from_parse ((osip_from_t *) to, hvalue);
74 }
75
76 /* returns the to header as a string.          */
77 /* INPUT : osip_to_t *to | to header.  */
78 /* returns null on error. */
79 int
80 osip_to_to_str (const osip_to_t * to, char **dest)
81 {
82   return osip_from_to_str ((osip_from_t *) to, dest);
83 }
84
85 /* deallocates a osip_to_t structure.  */
86 /* INPUT : osip_to_t *to | to header. */
87 void
88 osip_to_free (osip_to_t * to)
89 {
90   osip_from_free ((osip_from_t *) to);
91 }
92
93 int
94 osip_to_clone (const osip_to_t * to, osip_to_t ** dest)
95 {
96   return osip_from_clone ((osip_from_t *) to, (osip_from_t **) dest);
97 }
98
99 int
100 osip_to_tag_match (osip_to_t * to1, osip_to_t * to2)
101 {
102   return osip_from_tag_match ((osip_from_t *) to1, (osip_from_t *) to2);
103 }