and added files
[bcm963xx.git] / userapps / opensource / libosip2 / src / osip2 / fsm.h
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 #ifndef _FSM_H_
21 #define _FSM_H_
22
23 #include <osipparser2/osip_message.h>
24 #include <osip2/osip.h>
25
26 #include "xixt.h"
27
28 void add_gettimeofday (struct timeval *atv, int ms);
29 void min_timercmp (struct timeval *tv1, struct timeval *tv2);
30 #ifdef WIN32
31 int gettimeofday(struct timeval *tp, void *tz);
32 #endif
33
34 typedef struct osip_statemachine osip_statemachine_t;
35
36 struct osip_statemachine
37 {
38   osip_list_t *transitions;
39 };
40
41 /**
42  * Allocate a sipevent.
43  * NOTE: THIS IS AN INTERNAL METHOD ONLY
44  * @param type The type of the event.
45  * @param transactionid The transaction id for this event.
46  */
47 osip_event_t *__osip_event_new (type_t type, int transactionid);
48
49
50 /* This is for internal use only.                      */
51 type_t evt_set_type_incoming_sipmessage (osip_message_t * sip);
52 type_t evt_set_type_outgoing_sipmessage (osip_message_t * sip);
53
54 /* send a request on UDP.                       */
55 int udp_send_request (osip_message_t * request, osip_uri_t * proxy);
56
57 /* send a response on UDP.                       */
58 int udp_send_response (osip_message_t * response);
59
60 void __ict_load_fsm (void);
61 void __ist_load_fsm (void);
62 void __nict_load_fsm (void);
63 void __nist_load_fsm (void);
64
65 void __ict_unload_fsm (void);
66 void __ist_unload_fsm (void);
67 void __nict_unload_fsm (void);
68 void __nist_unload_fsm (void);
69
70 /* load state machine structure for (UAC || UAS) for (INVITE || REQUEST) */
71 osip_statemachine_t *__ict_get_fsm (void);
72 osip_statemachine_t *__ist_get_fsm (void);
73
74 osip_statemachine_t *__nict_get_fsm (void);
75 osip_statemachine_t *__nist_get_fsm (void);
76
77 typedef struct _transition_t
78 {
79   state_t state;
80   type_t type;
81   void (*method) (void *, void *);
82 }
83 transition_t;
84
85 int fsm_callmethod (type_t type, state_t state,
86                     osip_statemachine_t * statemachine,
87                     void *sipevent, void *transaction);
88
89
90 /*!! THESE ARE FOR INTERNAL USE ONLY!! */
91 /* These methods are the "exection method" for the finite */
92 /* state machine.                                         */
93
94 /************************/
95 /* FSM  ---- > ICT      */
96 /************************/
97
98 void ict_snd_invite (osip_transaction_t * ict, osip_event_t * evt);
99 void osip_ict_timeout_a_event (osip_transaction_t * ict, osip_event_t * evt);
100 void osip_ict_timeout_b_event (osip_transaction_t * ict, osip_event_t * evt);
101 void osip_ict_timeout_d_event (osip_transaction_t * ict, osip_event_t * evt);
102 void ict_rcv_1xx (osip_transaction_t * ict, osip_event_t * evt);
103 void ict_rcv_2xx (osip_transaction_t * ict, osip_event_t * evt);
104 osip_message_t *ict_create_ack (osip_transaction_t * ict,
105                                 osip_message_t * response);
106 void ict_rcv_3456xx (osip_transaction_t * ict, osip_event_t * evt);
107 void ict_retransmit_ack (osip_transaction_t * ict, osip_event_t * evt);
108
109 /************************/
110 /* FSM  ---- > IST      */
111 /************************/
112
113 osip_message_t *ist_create_resp_100 (osip_transaction_t * ist,
114                                      osip_message_t * request);
115 void ist_rcv_invite (osip_transaction_t * ist, osip_event_t * evt);
116 void osip_ist_timeout_g_event (osip_transaction_t * ist, osip_event_t * evt);
117 void osip_ist_timeout_h_event (osip_transaction_t * ist, osip_event_t * evt);
118 void osip_ist_timeout_i_event (osip_transaction_t * ist, osip_event_t * evt);
119 void ist_snd_1xx (osip_transaction_t * ist, osip_event_t * evt);
120 void ist_snd_2xx (osip_transaction_t * ist, osip_event_t * evt);
121 void ist_snd_3456xx (osip_transaction_t * ist, osip_event_t * evt);
122 void ist_rcv_ack (osip_transaction_t * ist, osip_event_t * evt);
123
124 /***********************/
125 /* FSM  ---- > NICT    */
126 /***********************/
127
128 void nict_snd_request (osip_transaction_t * nict, osip_event_t * evt);
129 void osip_nict_timeout_e_event (osip_transaction_t * nict,
130                                 osip_event_t * evt);
131 void osip_nict_timeout_f_event (osip_transaction_t * nict,
132                                 osip_event_t * evt);
133 void osip_nict_timeout_k_event (osip_transaction_t * nict,
134                                 osip_event_t * evt);
135 void nict_rcv_1xx (osip_transaction_t * nict, osip_event_t * evt);
136 void nict_rcv_23456xx (osip_transaction_t * nict, osip_event_t * evt);
137
138 /* void nict_rcv_23456xx2(osip_transaction_t *nict, osip_event_t *evt); */
139
140 /************************/
141 /* FSM  ---- > NIST     */
142 /************************/
143
144 void nist_rcv_request (osip_transaction_t * nist, osip_event_t * evt);
145 void nist_snd_1xx (osip_transaction_t * nist, osip_event_t * evt);
146 void nist_snd_23456xx (osip_transaction_t * nist, osip_event_t * evt);
147 void osip_nist_timeout_j_event (osip_transaction_t * nist,
148                                 osip_event_t * evt);
149
150 /************************/
151 /* Internal Methods     */
152 /************************/
153
154
155 void __osip_message_callback (int type, osip_transaction_t *,
156                               osip_message_t *);
157 void __osip_kill_transaction_callback (int type, osip_transaction_t *);
158 void __osip_transport_error_callback (int type, osip_transaction_t *,
159                                       int error);
160
161 /**
162  * Set the state of the transaction.
163  * NOTE: THIS IS AN INTERNAL METHOD ONLY
164  * @param transaction The element to work on.
165  * @param state The new state.
166  */
167 int __osip_transaction_set_state (osip_transaction_t * transaction,
168                                   state_t state);
169
170 /**
171  * Check if the response match a server transaction.
172  * NOTE: THIS IS AN INTERNAL METHOD ONLY
173  * @param tr The transaction.
174  * @param resp The SIP response received.
175  */
176 int
177 __osip_transaction_matching_response_osip_to_xict_17_1_3 (osip_transaction_t *
178                                                           tr,
179                                                           osip_message_t *
180                                                           resp);
181
182 /**
183  * Check if the request match a client transaction.
184  * NOTE: THIS IS AN INTERNAL METHOD ONLY
185  * @param tr The transaction.
186  * @param request The SIP request received.
187  */
188 int
189 __osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t *
190                                                          tr,
191                                                          osip_message_t *
192                                                          request);
193
194 #endif