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>
29 osip_cseq_init (osip_cseq_t ** cseq)
31 *cseq = (osip_cseq_t *) osip_malloc (sizeof (osip_cseq_t));
34 (*cseq)->method = NULL;
35 (*cseq)->number = NULL;
39 /* fills the cseq header of message. */
40 /* INPUT : char *hvalue | value of header. */
41 /* OUTPUT: osip_message_t *sip | structure to save results. */
42 /* returns -1 on error. */
44 osip_message_set_cseq (osip_message_t * sip, const char *hvalue)
48 if (hvalue == NULL || hvalue[0] == '\0')
51 if (sip->cseq != NULL)
53 i = osip_cseq_init (&(sip->cseq));
56 sip->message_property = 2;
57 i = osip_cseq_parse (sip->cseq, hvalue);
60 osip_cseq_free (sip->cseq);
67 /* fills the cseq strucuture. */
68 /* INPUT : char *hvalue | value of header. */
69 /* OUTPUT: osip_message_t *sip | structure to save results. */
70 /* returns -1 on error. */
72 osip_cseq_parse (osip_cseq_t * cseq, const char *hvalue)
75 const char *end = NULL;
80 method = strchr (hvalue, ' '); /* SEARCH FOR SPACE */
81 end = hvalue + strlen (hvalue);
86 if (method - hvalue + 1 < 2)
88 cseq->number = (char *) osip_malloc (method - hvalue + 1);
89 if (cseq->number == NULL)
91 osip_strncpy (cseq->number, hvalue, method - hvalue);
92 osip_clrspace (cseq->number);
94 if (end - method + 1 < 2)
96 cseq->method = (char *) osip_malloc (end - method + 1);
97 if (cseq->method == NULL)
99 osip_strncpy (cseq->method, method + 1, end - method);
100 osip_clrspace (cseq->method);
105 /* returns the cseq header. */
106 /* INPUT : osip_message_t *sip | sip message. */
107 /* returns null on error. */
109 osip_message_get_cseq (const osip_message_t * sip)
115 osip_cseq_get_number (osip_cseq_t * cseq)
121 osip_cseq_get_method (osip_cseq_t * cseq)
127 osip_cseq_set_number (osip_cseq_t * cseq, char *number)
129 cseq->number = (char *) number;
133 osip_cseq_set_method (osip_cseq_t * cseq, char *method)
135 cseq->method = (char *) method;
138 /* returns the cseq header as a string. */
139 /* INPUT : osip_cseq_t *cseq | cseq header. */
140 /* returns null on error. */
142 osip_cseq_to_str (const osip_cseq_t * cseq, char **dest)
147 if ((cseq == NULL) || (cseq->number == NULL) || (cseq->method == NULL))
149 len = strlen (cseq->method) + strlen (cseq->number) + 2;
150 *dest = (char *) osip_malloc (len);
153 sprintf (*dest, "%s %s", cseq->number, cseq->method);
157 /* deallocates a osip_cseq_t structure. */
158 /* INPUT : osip_cseq_t *cseq | cseq. */
160 osip_cseq_free (osip_cseq_t * cseq)
164 osip_free (cseq->method);
165 osip_free (cseq->number);
170 osip_cseq_clone (const osip_cseq_t * cseq, osip_cseq_t ** dest)
178 if (cseq->method == NULL)
180 if (cseq->number == NULL)
183 i = osip_cseq_init (&cs);
189 cs->method = osip_strdup (cseq->method);
190 cs->number = osip_strdup (cseq->number);
197 osip_cseq_match (osip_cseq_t * cseq1, osip_cseq_t * cseq2)
199 if (cseq1 == NULL || cseq2 == NULL)
201 if (cseq1->number == NULL || cseq2->number == NULL
202 || cseq1->method == NULL || cseq2->method == NULL)
205 if (0 == strcmp (cseq1->number, cseq2->number))
207 if (0 == strcmp (cseq2->method, "INVITE")
208 || 0 == strcmp (cseq2->method, "ACK"))
210 if (0 == strcmp (cseq1->method, "INVITE") ||
211 0 == strcmp (cseq1->method, "ACK"))
216 if (0 == strcmp (cseq1->method, cseq2->method))