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>
27 __osip_ict_init (osip_ict_t ** ict, osip_t * osip, osip_message_t * invite)
33 OSIP_TRACE (osip_trace
34 (__FILE__, __LINE__, OSIP_INFO2, NULL,
35 "allocating ICT context\n"));
37 *ict = (osip_ict_t *) osip_malloc (sizeof (osip_ict_t));
42 memset (*ict, 0, sizeof (osip_ict_t));
43 /* for INVITE retransmissions */
48 i = osip_message_get_via (invite, 0, &via); /* get top via */
51 proto = via_get_protocol (via);
55 i = osip_strncasecmp (proto, "TCP", 3);
57 { /* for other reliable protocol than TCP, the timer
58 must be desactived by the external application */
59 (*ict)->timer_a_length = DEFAULT_T1;
60 if (64 * DEFAULT_T1 < 32000)
61 (*ict)->timer_d_length = 32000;
63 (*ict)->timer_d_length = 64 * DEFAULT_T1;
64 gettimeofday (&(*ict)->timer_a_start, NULL);
65 add_gettimeofday (&(*ict)->timer_a_start, (*ict)->timer_a_length);
66 (*ict)->timer_d_start.tv_sec = -1; /* not started */
70 (*ict)->timer_a_length = -1; /* A is not ACTIVE */
71 (*ict)->timer_d_length = 0; /* MUST do the transition immediatly */
72 (*ict)->timer_a_start.tv_sec = -1; /* not started */
73 (*ict)->timer_d_start.tv_sec = -1; /* not started */
77 /* for PROXY, the destination MUST be set by the application layer,
78 this one may not be correct. */
79 osip_message_get_route (invite, 0, &route);
84 if (route->url->port != NULL)
85 port = osip_atoi (route->url->port);
86 osip_ict_set_destination ((*ict), osip_strdup (route->url->host), port);
91 (*ict)->timer_b_length = 64 * DEFAULT_T1;
92 gettimeofday (&(*ict)->timer_b_start, NULL);
93 add_gettimeofday (&(*ict)->timer_b_start, (*ict)->timer_b_length);
96 /* (*ict)->port = 5060; */
106 __osip_ict_free (osip_ict_t * ict)
110 OSIP_TRACE (osip_trace
111 (__FILE__, __LINE__, OSIP_INFO2, NULL, "free ict ressource\n"));
113 osip_free (ict->destination);
119 osip_ict_set_destination (osip_ict_t * ict, char *destination, int port)
123 if (ict->destination != NULL)
124 osip_free (ict->destination);
125 ict->destination = destination;
131 __osip_ict_need_timer_a_event (osip_ict_t * ict, state_t state, int transactionid)
134 gettimeofday (&now, NULL);
138 if (state == ICT_CALLING)
140 /* may need timer A */
141 if (ict->timer_a_start.tv_sec == -1)
143 if (timercmp (&now, &ict->timer_a_start, >))
144 return __osip_event_new (TIMEOUT_A, transactionid);
150 __osip_ict_need_timer_b_event (osip_ict_t * ict, state_t state,
154 gettimeofday (&now, NULL);
158 if (state == ICT_CALLING)
160 /* may need timer B */
161 if (ict->timer_b_start.tv_sec == -1)
163 if (timercmp (&now, &ict->timer_b_start, >))
164 return __osip_event_new (TIMEOUT_B, transactionid);
170 __osip_ict_need_timer_d_event (osip_ict_t * ict, state_t state,
174 gettimeofday (&now, NULL);
178 if (state == ICT_COMPLETED)
180 /* may need timer D */
181 if (ict->timer_d_start.tv_sec == -1)
183 if (timercmp (&now, &ict->timer_d_start, >))
184 return __osip_event_new (TIMEOUT_D, transactionid);