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
23 #include <osipparser2/osip_port.h>
24 #include <osipparser2/osip_message.h>
25 #include <osipparser2/osip_parser.h>
27 /* fills the call_id of message. */
28 /* INPUT : const char *hvalue | value of header. */
29 /* OUTPUT: osip_message_t *sip | structure to save results. */
30 /* returns -1 on error. */
32 osip_message_set_call_id (osip_message_t * sip, const char *hvalue)
36 if (hvalue == NULL || hvalue[0] == '\0')
39 if (sip->call_id != NULL)
41 i = osip_call_id_init (&(sip->call_id));
44 sip->message_property = 2;
45 i = osip_call_id_parse (sip->call_id, hvalue);
48 osip_call_id_free (sip->call_id);
55 /* returns the call_id. */
56 /* INPUT : osip_message_t *sip | sip message. */
58 osip_message_get_call_id (const osip_message_t * sip)
64 osip_call_id_init (osip_call_id_t ** callid)
66 *callid = (osip_call_id_t *) osip_malloc (sizeof (osip_call_id_t));
69 (*callid)->number = NULL;
70 (*callid)->host = NULL;
75 /* deallocates a osip_call_id_t structure. */
76 /* INPUT : osip_call_id_t *| callid. */
78 osip_call_id_free (osip_call_id_t * callid)
82 osip_free (callid->number);
83 osip_free (callid->host);
85 callid->number = NULL;
91 /* fills the call_id structure. */
92 /* INPUT : char *hvalue | value of header. */
93 /* OUTPUT: osip_call_id_t *callid | structure to save results. */
94 /* returns -1 on error. */
96 osip_call_id_parse (osip_call_id_t * callid, const char *hvalue)
101 callid->number = NULL;
104 host = strchr (hvalue, '@'); /* SEARCH FOR '@' */
105 end = hvalue + strlen (hvalue);
111 if (end - host + 1 < 2)
113 callid->host = (char *) osip_malloc (end - host);
114 if (callid->host == NULL)
116 osip_strncpy (callid->host, host + 1, end - host - 1);
117 osip_clrspace (callid->host);
119 if (host - hvalue + 1 < 2)
121 callid->number = (char *) osip_malloc (host - hvalue + 1);
122 if (callid->number == NULL)
124 osip_strncpy (callid->number, hvalue, host - hvalue);
125 osip_clrspace (callid->number);
130 /* returns the call_id as a string. */
131 /* INPUT : osip_call_id_t *call_id | call_id. */
132 /* returns null on error. */
134 osip_call_id_to_str (const osip_call_id_t * callid, char **dest)
137 if ((callid == NULL) || (callid->number == NULL))
140 if (callid->host == NULL)
142 *dest = (char *) osip_malloc (strlen (callid->number) + 1);
145 sprintf (*dest, "%s", callid->number);
150 (char *) osip_malloc (strlen (callid->number) +
151 strlen (callid->host) + 2);
154 sprintf (*dest, "%s@%s", callid->number, callid->host);
160 osip_call_id_get_number (osip_call_id_t * callid)
164 return callid->number;
168 osip_call_id_get_host (osip_call_id_t * callid)
176 osip_call_id_set_number (osip_call_id_t * callid, char *number)
178 callid->number = number;
182 osip_call_id_set_host (osip_call_id_t * callid, char *host)
188 osip_call_id_clone (const osip_call_id_t * callid, osip_call_id_t ** dest)
196 if (callid->number == NULL)
199 i = osip_call_id_init (&ci);
200 if (i == -1) /* allocation failed */
202 ci->number = osip_strdup (callid->number);
203 if (callid->host != NULL)
204 ci->host = osip_strdup (callid->host);
211 osip_call_id_match (osip_call_id_t * callid1, osip_call_id_t * callid2)
214 if (callid1 == NULL || callid2 == NULL)
216 if (callid1->number == NULL || callid2->number == NULL)
219 if (0 != strcmp (callid1->number, callid2->number))
222 if ((callid1->host == NULL) && (callid2->host == NULL))
224 if ((callid1->host == NULL) && (callid2->host != NULL))
226 if ((callid1->host != NULL) && (callid2->host == NULL))
228 if (0 != strcmp (callid1->host, callid2->host))