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_nict_init (osip_nict_t ** nict, osip_t * osip,
28 osip_message_t * request)
34 OSIP_TRACE (osip_trace
35 (__FILE__, __LINE__, OSIP_INFO2, NULL,
36 "allocating NICT context\n"));
38 *nict = (osip_nict_t *) osip_malloc (sizeof (osip_nict_t));
42 memset (*nict, 0, sizeof (osip_nict_t));
43 /* for REQUEST retransmissions */
48 i = osip_message_get_via (request, 0, &via); /* get top via */
51 proto = via_get_protocol (via);
55 i = osip_strncasecmp (proto, "TCP", 3);
58 (*nict)->timer_e_length = DEFAULT_T1;
59 (*nict)->timer_k_length = DEFAULT_T4;
60 gettimeofday (&(*nict)->timer_e_start, NULL);
61 add_gettimeofday (&(*nict)->timer_e_start, (*nict)->timer_e_length);
62 (*nict)->timer_k_start.tv_sec = -1; /* not started */
66 (*nict)->timer_e_length = -1; /* E is not ACTIVE */
67 (*nict)->timer_k_length = 0; /* MUST do the transition immediatly */
68 (*nict)->timer_e_start.tv_sec = -1;
69 (*nict)->timer_k_start.tv_sec = -1; /* not started */
73 /* for PROXY, the destination MUST be set by the application layer,
74 this one may not be correct. */
75 osip_message_get_route (request, 0, &route);
80 if (route->url->port != NULL)
81 port = osip_atoi (route->url->port);
82 osip_nict_set_destination ((*nict), osip_strdup (route->url->host),
88 (*nict)->timer_f_length = 64 * DEFAULT_T1;
89 gettimeofday (&(*nict)->timer_f_start, NULL);
90 add_gettimeofday (&(*nict)->timer_f_start, (*nict)->timer_f_length);
93 /* (*nict)->port = 5060; */
103 __osip_nict_free (osip_nict_t * nict)
107 OSIP_TRACE (osip_trace
108 (__FILE__, __LINE__, OSIP_INFO2, NULL,
109 "free nict ressource\n"));
111 osip_free (nict->destination);
117 osip_nict_set_destination (osip_nict_t * nict, char *destination, int port)
121 if (nict->destination != NULL)
122 osip_free (nict->destination);
123 nict->destination = destination;
129 __osip_nict_need_timer_e_event (osip_nict_t * nict, state_t state, int transactionid)
132 gettimeofday (&now, NULL);
136 if (state == NICT_PROCEEDING || state == NICT_TRYING)
138 if (nict->timer_e_start.tv_sec == -1)
140 if (timercmp (&now, &nict->timer_e_start, >))
141 return __osip_event_new (TIMEOUT_E, transactionid);
147 __osip_nict_need_timer_f_event (osip_nict_t * nict, state_t state,
151 gettimeofday (&now, NULL);
155 if (state == NICT_PROCEEDING || state == NICT_TRYING)
157 if (nict->timer_f_start.tv_sec == -1)
159 if (timercmp (&now, &nict->timer_f_start, >))
160 return __osip_event_new (TIMEOUT_F, transactionid);
166 __osip_nict_need_timer_k_event (osip_nict_t * nict, state_t state,
170 gettimeofday (&now, NULL);
174 if (state == NICT_COMPLETED)
176 if (nict->timer_k_start.tv_sec == -1)
178 if (timercmp (&now, &nict->timer_k_start, >))
179 return __osip_event_new (TIMEOUT_K, transactionid);