Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / libosip2 / src / osip2 / fsm_misc.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 <stdio.h>
21
22 #include <osip2/internal.h>
23 #include <osip2/osip_fifo.h>
24 #include <osip2/osip.h>
25 #include "fsm.h"
26
27 static transition_t *fsm_findmethod (type_t type, state_t state,
28                                      osip_statemachine_t * statemachine);
29
30 /* find the transition for state and type in statemachine */
31 /* return NULL; if transition is not found.               */
32 static transition_t *
33 fsm_findmethod (type_t type, state_t state,
34                 osip_statemachine_t * statemachine)
35 {
36   int pos;
37
38   pos = 0;
39   while (!osip_list_eol (statemachine->transitions, pos))
40     {
41       transition_t *transition;
42
43       transition =
44         (transition_t *) osip_list_get (statemachine->transitions, pos);
45       if (transition->type == type && transition->state == state)
46         return transition;
47       pos++;
48     }
49   return NULL;
50 }
51
52
53 /* call the right execution method.          */
54 /*   return -1 when event must be discarded  */
55 int
56 fsm_callmethod (type_t type, state_t state,
57                 osip_statemachine_t * statemachine, void *sipevent,
58                 void *transaction)
59 {
60   transition_t *transition;
61
62   transition = fsm_findmethod (type, state, statemachine);
63   if (transition == NULL)
64     {
65       /* No transition found for this event */
66       return -1;                /* error */
67     }
68   transition->method (transaction, sipevent);
69   return 0;                     /* ok */
70 }