Added retransmission detection.
[sip-router] / modules / tm / t_fork.c
1 /*
2  * $Id$
3  *
4  * forking requests
5  */
6
7 #include "../../dprint.h"
8 #include "../../config.h"
9 #include "../../parser/parser_f.h"
10 #include "../../ut.h"
11 #include "hash_func.h"
12 #include "t_funcs.h"
13 #include "t_fork.h"
14
15
16
17 unsigned int     nr_forks;
18 struct fork      t_forks[ NR_OF_CLIENTS ];
19
20
21 int t_add_fork( union sockaddr_union to, char* uri_s,
22                         unsigned int uri_len, enum fork_type type, 
23                         unsigned char free_flag)
24 {
25         unsigned int pos=0;
26         char         *foo=0;
27
28         switch (type)
29         {
30                 case DEFAULT:
31                         if (nr_forks+1>=MAX_FORK)
32                         {
33                                 LOG(L_ERR,"ERROR:t_add_fork: trying to add new fork ->"
34                                         " MAX_FORK exceded\n");
35                                 return -1;
36                         }
37                         pos = ++nr_forks;
38                         break;
39                 case NO_RESPONSE:
40                         /* v6; -Jiri
41                         if (t_forks[NO_RPL_BRANCH].ip)
42                         */
43                         if (!t_forks[NO_RPL_BRANCH].inactive)
44                                 LOG(L_WARN,"WARNING:t_add_fork: trying to add NO_RPL fork ->"
45                                         " it was set before -> overriding\n");
46                         if (uri_s && uri_len)
47                         {
48                                 foo = (char*)shm_malloc(uri_len);
49                                 if (!foo)
50                                 {
51                                         LOG(L_ERR,"ERROR:t_add_fork: cannot get free memory\n");
52                                         return -1;
53                                 }
54                                 memcpy(foo,uri_s,uri_len);
55                         }
56                         if (free_flag && uri_s)
57                                 pkg_free(uri_s);
58                         uri_s = foo;
59                         free_flag = 0;
60                         pos = NO_RPL_BRANCH;
61         }
62         /* -v6
63         t_forks[pos].ip = ip;
64         t_forks[pos].port = port;
65         */
66         t_forks[pos].to=to;
67
68         if (uri_s && uri_len)
69         {
70                 t_forks[pos].free_flag = free_flag;
71                 t_forks[pos].uri.len = uri_len;
72                 t_forks[pos].uri.s = uri_s;
73         }
74
75         return 1;
76 }
77
78
79
80
81 int t_clear_forks( )
82 {
83         int i;
84
85         DBG("DEBUG: t_clear_forks: clearing tabel...\n");
86         for(i=1;i<nr_forks;i++)
87                 if (t_forks[i].free_flag && t_forks[i].uri.s)
88                         pkg_free(t_forks[i].uri.s);
89         memset( t_forks, 0, sizeof(t_forks));
90         nr_forks = 0;
91         return 1;
92 }
93
94
95