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_content_length_init (osip_content_length_t ** cl)
31 (osip_content_length_t *) osip_malloc (sizeof (osip_content_length_t));
38 /* adds the content_length 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. */
43 osip_message_set_content_length (osip_message_t * sip, const char *hvalue)
47 if (hvalue == NULL || hvalue[0] == '\0')
50 if (sip->content_length != NULL)
52 i = osip_content_length_init (&(sip->content_length));
55 sip->message_property = 2;
56 i = osip_content_length_parse (sip->content_length, hvalue);
59 osip_content_length_free (sip->content_length);
60 sip->content_length = NULL;
68 osip_content_length_parse (osip_content_length_t * content_length,
71 if (strlen (hvalue) + 1 < 2)
73 content_length->value = (char *) osip_malloc (strlen (hvalue) + 1);
74 if (content_length->value == NULL)
76 osip_strncpy (content_length->value, hvalue, strlen (hvalue));
80 /* returns the content_length header. */
81 /* INPUT : osip_message_t *sip | sip message. */
82 /* returns null on error. */
83 osip_content_length_t *
84 osip_message_get_content_length (const osip_message_t * sip)
86 return sip->content_length;
89 /* returns the content_length header as a string. */
90 /* INPUT : osip_content_length_t *content_length | content_length header. */
91 /* returns null on error. */
93 osip_content_length_to_str (const osip_content_length_t * cl, char **dest)
97 *dest = osip_strdup (cl->value);
101 /* deallocates a osip_content_length_t strcture. */
102 /* INPUT : osip_content_length_t *content_length | content_length header. */
104 osip_content_length_free (osip_content_length_t * content_length)
106 if (content_length == NULL)
108 osip_free (content_length->value);
109 osip_free (content_length);
113 osip_content_length_clone (const osip_content_length_t * ctl,
114 osip_content_length_t ** dest)
117 osip_content_length_t *cl;
123 empty headers are allowed:
124 if (ctl->value==NULL) return -1;
126 i = osip_content_length_init (&cl);
127 if (i == -1) /* allocation failed */
129 if (ctl->value != NULL)
130 cl->value = osip_strdup (ctl->value);