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
24 #include <osipparser2/osip_port.h>
25 #include <osipparser2/osip_message.h>
26 #include <osipparser2/osip_parser.h>
28 /* adds the contact header to message. */
29 /* INPUT : const char *hvalue | value of header. */
30 /* OUTPUT: osip_message_t *sip | structure to save results. */
31 /* returns -1 on error. */
33 osip_message_set_contact (osip_message_t * sip, const char *hvalue)
36 osip_contact_t *contact;
38 if (hvalue == NULL || hvalue[0] == '\0')
41 i = osip_contact_init (&contact);
44 i = osip_contact_parse (contact, hvalue);
47 osip_contact_free (contact);
50 sip->message_property = 2;
51 osip_list_add (sip->contacts, contact, -1);
55 /* parses a contact header. */
56 /* INPUT : const char *string | pointer to a contact string.*/
57 /* OUTPUT: osip_contact_t *contact | structure to save results. */
58 /* returns -1 on error. */
60 osip_contact_parse (osip_contact_t * contact, const char *hvalue)
64 if (strncmp (hvalue, "*", 1) == 0)
66 contact->displayname = osip_strdup (hvalue);
69 return osip_from_parse ((osip_from_t *) contact, hvalue);
73 osip_contact_init (osip_contact_t ** contact)
75 return osip_from_init ((osip_from_t **) contact);
78 /* returns the pos of contact header. */
79 /* INPUT : int pos | pos of contact header. */
80 /* INPUT : osip_message_t *sip | sip message. */
81 /* OUTPUT: osip_contact_t *contact | structure to save results. */
82 /* returns -1 on error. */
84 osip_message_get_contact (const osip_message_t * sip, int pos,
85 osip_contact_t ** dest)
90 if (osip_list_size (sip->contacts) <= pos)
91 return -1; /* does not exist */
92 *dest = (osip_contact_t *) osip_list_get (sip->contacts, pos);
96 /* returns the contact header as a string.*/
97 /* INPUT : osip_contact_t *contact | contact. */
98 /* returns null on error. */
100 osip_contact_to_str (const osip_contact_t * contact, char **dest)
104 if (contact->displayname != NULL)
106 if (strncmp (contact->displayname, "*", 1) == 0)
108 *dest = osip_strdup ("*");
112 return osip_from_to_str ((osip_from_t *) contact, dest);
115 /* deallocates a osip_contact_t structure. */
116 /* INPUT : osip_contact_t *| contact. */
118 osip_contact_free (osip_contact_t * contact)
120 osip_from_free ((osip_from_t *) contact);
124 osip_contact_clone (const osip_contact_t * contact, osip_contact_t ** dest)
126 return osip_from_clone ((osip_from_t *) contact, (osip_from_t **) dest);