and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_proxy_authorization.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
21 #include <stdlib.h>
22 #include <stdio.h>
23
24 #include <osipparser2/osip_port.h>
25 #include <osipparser2/osip_message.h>
26 #include <osipparser2/osip_parser.h>
27 #include "parser.h"
28
29
30 /* fills the proxy_authorization header of message.               */
31 /* INPUT :  char *hvalue | value of header.   */
32 /* OUTPUT: osip_message_t *sip | structure to save results. */
33 /* returns -1 on error. */
34 int
35 osip_message_set_proxy_authorization (osip_message_t * sip,
36                                       const char *hvalue)
37 {
38   osip_proxy_authorization_t *proxy_authorization;
39   int i;
40
41   if (hvalue == NULL || hvalue[0] == '\0')
42     return 0;
43
44   i = osip_proxy_authorization_init (&proxy_authorization);
45   if (i != 0)
46     return -1;
47   i = osip_proxy_authorization_parse (proxy_authorization, hvalue);
48   if (i != 0)
49     {
50       osip_proxy_authorization_free (proxy_authorization);
51       return -1;
52     }
53   sip->message_property = 2;
54   osip_list_add (sip->proxy_authorizations, proxy_authorization, -1);
55   return 0;
56 }
57
58 int
59 osip_message_get_proxy_authorization (const osip_message_t * sip, int pos,
60                                       osip_proxy_authorization_t ** dest)
61 {
62   osip_proxy_authorization_t *proxy_authorization;
63
64   *dest = NULL;
65   if (osip_list_size (sip->proxy_authorizations) <= pos)
66     return -1;                  /* does not exist */
67   proxy_authorization =
68     (osip_proxy_authorization_t *) osip_list_get (sip->proxy_authorizations,
69                                                   pos);
70   *dest = proxy_authorization;
71   return pos;
72 }