OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / lib / osip2 / src / osip2 / nist.c
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3   Copyright (C) 2001,2002,2003  Aymeric MOIZARD jack@atosc.org
4   
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.
9   
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.
14   
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
18 */
19
20 #include <osip2/internal.h>
21 #include <osip2/osip.h>
22
23 #include "fsm.h"
24 #include "xixt.h"
25
26 int
27 __osip_nist_init (osip_nist_t ** nist, osip_t * osip, osip_message_t * invite)
28 {
29   int i;
30
31   OSIP_TRACE (osip_trace
32               (__FILE__, __LINE__, OSIP_INFO2, NULL,
33                "allocating NIST context\n"));
34
35   *nist = (osip_nist_t *) osip_malloc (sizeof (osip_nist_t));
36   if (*nist == NULL)
37     return -1;
38   memset (*nist, 0, sizeof (osip_nist_t));
39   /* for INVITE retransmissions */
40   {
41     osip_via_t *via;
42     char *proto;
43
44     i = osip_message_get_via (invite, 0, &via); /* get top via */
45     if (i != 0)
46       goto ii_error_1;
47     proto = via_get_protocol (via);
48     if (proto == NULL)
49       goto ii_error_1;
50
51     if (osip_strcasecmp (proto, "TCP") != 0
52         && osip_strcasecmp (proto, "TLS") !=0
53         && osip_strcasecmp (proto, "SCTP") !=0)
54       {
55         (*nist)->timer_j_length = 64 * DEFAULT_T1;
56         (*nist)->timer_j_start.tv_sec = -1;     /* not started */
57       }
58     else
59       {                         /* reliable protocol is used: */
60         (*nist)->timer_j_length = 0;    /* MUST do the transition immediatly */
61         (*nist)->timer_j_start.tv_sec = -1;     /* not started */
62       }
63   }
64
65   return 0;
66
67 ii_error_1:
68   osip_free (*nist);
69   return -1;
70 }
71
72 int
73 __osip_nist_free (osip_nist_t * nist)
74 {
75   if (nist == NULL)
76     return -1;
77   OSIP_TRACE (osip_trace
78               (__FILE__, __LINE__, OSIP_INFO2, NULL,
79                "free nist ressource\n"));
80
81   osip_free (nist);
82   return 0;
83 }
84
85
86
87 osip_event_t *
88 __osip_nist_need_timer_j_event (osip_nist_t * nist, state_t state, int transactionid)
89 {
90   struct timeval now;
91   osip_gettimeofday (&now, NULL);
92
93   if (nist == NULL)
94     return NULL;
95   if (state == NIST_COMPLETED)
96     {
97       if (nist->timer_j_start.tv_sec == -1)
98         return NULL;
99       if (osip_timercmp (&now, &nist->timer_j_start, >))
100         return __osip_event_new (TIMEOUT_J, transactionid);
101     }
102   return NULL;
103 }
104