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
20 #include <osip2/internal.h>
21 #include <osip2/osip.h>
26 /* Create a sipevent according to the SIP message buf. */
27 /* INPUT : char *buf | message as a string. */
28 /* return NULL if message cannot be parsed */
30 osip_parse (char *buf)
32 osip_event_t *se = __osip_event_new (UNKNOWN_EVT, 0);
35 #ifdef TEST_PARSER_SPEED
41 clock_get_time (CLOCK_REALTIME, &tv1);
42 pstime = ((tv1.tv_sec * 1000) + (tv1.tv_nsec / 1000000));
43 for (kk = 0; kk < 10000; kk++)
46 i = osip_message_init (&(se->sip));
48 if (osip_message_parse (se->sip, buf) == -1)
50 fprintf (stdout, "osip_message_parse retrun -1\n");
51 osip_message_free (se->sip);
55 osip_message_free (se->sip);
58 clock_get_time (CLOCK_REALTIME, &tv1);
59 pstime1 = ((tv1.tv_sec * 1000) + (tv1.tv_nsec / 1000000));
60 fprintf (stdout, "CPU clock ticks for 10000 messages - T1: %i - T2: %i\n",
62 fprintf (stdout, "CPU time for 10000 messages - %d\n",
68 /* parse message and set up an event */
69 i = osip_message_init (&(se->sip));
70 if (osip_message_parse (se->sip, buf) == -1)
72 OSIP_TRACE (osip_trace
73 (__FILE__, __LINE__, OSIP_ERROR, NULL,
74 "could not parse message\n"));
75 osip_message_free (se->sip);
81 if (se->sip->call_id != NULL && se->sip->call_id->number != NULL)
83 OSIP_TRACE (osip_trace
84 (__FILE__, __LINE__, OSIP_INFO3, NULL,
85 "MESSAGE REC. CALLID:%s\n", se->sip->call_id->number));
88 if (MSG_IS_REQUEST (se->sip))
90 if (se->sip->sip_method == NULL || se->sip->req_uri == NULL)
92 osip_message_free (se->sip);
98 se->type = evt_set_type_incoming_sipmessage (se->sip);
103 /* allocates an event from retransmitter. */
104 /* USED ONLY BY THE STACK. */
105 /* INPUT : int transactionid | id of the transaction. */
106 /* INPUT : type_t type | type of event. */
107 /* returns null on error. */
109 __osip_event_new (type_t type, int transactionid)
111 osip_event_t *sipevent;
113 sipevent = (osip_event_t *) osip_malloc (sizeof (osip_event_t));
114 if (sipevent == NULL)
116 sipevent->type = type;
117 sipevent->sip = NULL;
118 sipevent->transactionid = transactionid;
122 /* allocates an event from user. */
123 /* USED ONLY BY THE USER. */
124 /* INPUT : osip_message_t *sip | sip message for transaction. */
125 /* returns null on error. */
127 osip_new_outgoing_sipmessage (osip_message_t * sip)
129 osip_event_t *sipevent;
133 if (MSG_IS_REQUEST (sip))
135 if (sip->sip_method == NULL)
137 if (sip->req_uri == NULL)
140 sipevent = (osip_event_t *) osip_malloc (sizeof (osip_event_t));
141 if (sipevent == NULL)
145 sipevent->type = evt_set_type_outgoing_sipmessage (sip);
146 sipevent->transactionid = 0;
151 evt_set_type_incoming_sipmessage (osip_message_t * sip)
153 if (MSG_IS_REQUEST (sip))
155 if (MSG_IS_INVITE (sip))
156 return RCV_REQINVITE;
157 else if (MSG_IS_ACK (sip))
163 if (MSG_IS_STATUS_1XX (sip))
164 return RCV_STATUS_1XX;
165 else if (MSG_IS_STATUS_2XX (sip))
166 return RCV_STATUS_2XX;
167 return RCV_STATUS_3456XX;
172 evt_set_type_outgoing_sipmessage (osip_message_t * sip)
175 if (MSG_IS_REQUEST (sip))
177 if (MSG_IS_INVITE (sip))
178 return SND_REQINVITE;
179 if (MSG_IS_ACK (sip))
185 if (MSG_IS_STATUS_1XX (sip))
186 return SND_STATUS_1XX;
187 else if (MSG_IS_STATUS_2XX (sip))
188 return SND_STATUS_2XX;
189 return SND_STATUS_3456XX;
194 osip_event_free (osip_event_t * event)
198 osip_message_free (event->sip);