and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_content_encoding.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 #include "parser.h"
27
28 /* content-Encoding = token
29    token possible values are gzip,compress,deflate
30 */
31 int
32 osip_message_set_content_encoding (osip_message_t * sip, const char *hvalue)
33 {
34   osip_content_encoding_t *content_encoding;
35   int i;
36
37   if (hvalue == NULL || hvalue[0] == '\0')
38     return 0;
39
40   i = osip_content_encoding_init (&content_encoding);
41   if (i != 0)
42     return -1;
43   i = osip_content_encoding_parse (content_encoding, hvalue);
44   if (i != 0)
45     {
46       osip_content_encoding_free (content_encoding);
47       return -1;
48     }
49   sip->message_property = 2;
50   osip_list_add (sip->content_encodings, content_encoding, -1);
51   return 0;
52 }
53
54 int
55 osip_message_get_content_encoding (const osip_message_t * sip, int pos,
56                                    osip_content_encoding_t ** dest)
57 {
58   osip_content_encoding_t *ce;
59
60   *dest = NULL;
61   if (osip_list_size (sip->content_encodings) <= pos)
62     return -1;                  /* does not exist */
63   ce =
64     (osip_content_encoding_t *) osip_list_get (sip->content_encodings, pos);
65   *dest = ce;
66   return pos;
67 }