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 __osip_ist_init (osip_ist_t ** ist, osip_t * osip, osip_message_t * invite)
30 OSIP_TRACE (osip_trace
31 (__FILE__, __LINE__, OSIP_INFO2, NULL,
32 "allocating IST context\n"));
34 *ist = (osip_ist_t *) osip_malloc (sizeof (osip_ist_t));
37 memset (*ist, 0, sizeof (osip_ist_t));
38 /* for INVITE retransmissions */
43 i = osip_message_get_via (invite, 0, &via); /* get top via */
46 proto = via_get_protocol (via);
50 i = osip_strncasecmp (proto, "TCP", 3);
52 { /* for other reliable protocol than TCP, the timer
53 must be desactived by the external application */
54 (*ist)->timer_g_length = DEFAULT_T1;
55 (*ist)->timer_i_length = DEFAULT_T4;
56 (*ist)->timer_g_start.tv_sec = -1; /* not started */
57 (*ist)->timer_i_start.tv_sec = -1; /* not started */
61 (*ist)->timer_g_length = -1; /* A is not ACTIVE */
62 (*ist)->timer_i_length = 0; /* MUST do the transition immediatly */
63 (*ist)->timer_g_start.tv_sec = -1; /* not started */
64 (*ist)->timer_i_start.tv_sec = -1; /* not started */
68 (*ist)->timer_h_length = 64 * DEFAULT_T1;
69 (*ist)->timer_h_start.tv_sec = -1; /* not started */
79 __osip_ist_free (osip_ist_t * ist)
83 OSIP_TRACE (osip_trace
84 (__FILE__, __LINE__, OSIP_INFO2, NULL, "free ist ressource\n"));
90 __osip_ist_need_timer_g_event (osip_ist_t * ist, state_t state, int transactionid)
93 gettimeofday (&now, NULL);
97 if (state == IST_COMPLETED)
99 if (ist->timer_g_start.tv_sec == -1)
101 if (timercmp (&now, &ist->timer_g_start, >))
102 return __osip_event_new (TIMEOUT_G, transactionid);
108 __osip_ist_need_timer_h_event (osip_ist_t * ist, state_t state,
112 gettimeofday (&now, NULL);
116 if (state == IST_COMPLETED)
118 /* may need timer H */
119 if (ist->timer_h_start.tv_sec == -1)
121 if (timercmp (&now, &ist->timer_h_start, >))
122 return __osip_event_new (TIMEOUT_H, transactionid);
128 __osip_ist_need_timer_i_event (osip_ist_t * ist, state_t state,
132 gettimeofday (&now, NULL);
136 if (state == IST_CONFIRMED)
138 /* may need timer I */
139 if (ist->timer_i_start.tv_sec == -1)
141 if (timercmp (&now, &ist->timer_i_start, >))
142 return __osip_event_new (TIMEOUT_I, transactionid);