and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_proxy_authenticate.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
28 /* fills the proxy-authenticate header of message.               */
29 /* INPUT :  char *hvalue | value of header.   */
30 /* OUTPUT: osip_message_t *sip | structure to save results. */
31 /* returns -1 on error. */
32 int
33 osip_message_set_proxy_authenticate (osip_message_t * sip, const char *hvalue)
34 {
35   osip_proxy_authenticate_t *proxy_authenticate;
36   int i;
37
38   if (hvalue == NULL || hvalue[0] == '\0')
39     return 0;
40
41   i = osip_proxy_authenticate_init (&(proxy_authenticate));
42   if (i != 0)
43     return -1;
44   i = osip_proxy_authenticate_parse (proxy_authenticate, hvalue);
45   if (i != 0)
46     {
47       osip_proxy_authenticate_free (proxy_authenticate);
48       return -1;
49     }
50   sip->message_property = 2;
51   osip_list_add (sip->proxy_authenticates, proxy_authenticate, -1);
52   return 0;
53 }
54
55
56
57 /* returns the proxy_authenticate header.            */
58 /* INPUT : osip_message_t *sip | sip message.   */
59 /* returns null on error. */
60 int
61 osip_message_get_proxy_authenticate (const osip_message_t * sip, int pos,
62                                      osip_proxy_authenticate_t ** dest)
63 {
64   osip_proxy_authenticate_t *proxy_authenticate;
65
66   *dest = NULL;
67   if (osip_list_size (sip->proxy_authenticates) <= pos)
68     return -1;                  /* does not exist */
69
70   proxy_authenticate = (osip_proxy_authenticate_t *)
71     osip_list_get (sip->proxy_authenticates, pos);
72
73   *dest = proxy_authenticate;
74   return pos;
75 }