Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_content_disposition.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 int
29 osip_message_set_content_disposition (osip_message_t * sip,
30                                       const char *hvalue)
31 {
32   osip_content_disposition_t *content_disposition;
33   int i;
34
35   if (hvalue == NULL || hvalue[0] == '\0')
36     return 0;
37
38   i = osip_content_disposition_init (&content_disposition);
39   if (i != 0)
40     return -1;
41   i = osip_content_disposition_parse (content_disposition, hvalue);
42   if (i != 0)
43     {
44       osip_content_disposition_free (content_disposition);
45       return -1;
46     }
47   sip->message_property = 2;
48   osip_list_add (sip->content_dispositions, content_disposition, -1);
49   return 0;
50 }
51
52 int
53 osip_message_get_content_disposition (const osip_message_t * sip, int pos,
54                                       osip_content_disposition_t ** dest)
55 {
56   osip_content_disposition_t *content_disposition;
57
58   *dest = NULL;
59   if (osip_list_size (sip->content_dispositions) <= pos)
60     return -1;                  /* does not exist */
61   content_disposition =
62     (osip_content_disposition_t *) osip_list_get (sip->content_dispositions,
63                                                   pos);
64   *dest = content_disposition;
65   return pos;
66 }
67
68
69
70 int
71 osip_content_disposition_parse (osip_content_disposition_t * cd,
72                                 const char *hvalue)
73 {
74   const char *cd_params;
75
76   cd_params = strchr (hvalue, ';');
77
78   if (cd_params != NULL)
79     {
80       if (__osip_generic_param_parseall (cd->gen_params, cd_params) == -1)
81         return -1;
82     }
83   else
84     cd_params = hvalue + strlen (hvalue);
85
86   if (cd_params - hvalue + 1 < 2)
87     return -1;
88   cd->element = (char *) osip_malloc (cd_params - hvalue + 1);
89   if (cd->element == NULL)
90     return -1;
91   osip_strncpy (cd->element, hvalue, cd_params - hvalue);
92   osip_clrspace (cd->element);
93
94   return 0;
95 }