- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,188 +0,0 @@ |
1 |
-/* |
|
2 |
- * Script callbacks -- they add the ability to register callback |
|
3 |
- * functions which are always called when script for request |
|
4 |
- * processing is entered or left |
|
5 |
- * |
|
6 |
- * |
|
7 |
- * Copyright (C) 2001-2003 FhG Fokus |
|
8 |
- * |
|
9 |
- * This file is part of Kamailio, a free SIP server. |
|
10 |
- * |
|
11 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
12 |
- * it under the terms of the GNU General Public License as published by |
|
13 |
- * the Free Software Foundation; either version 2 of the License, or |
|
14 |
- * (at your option) any later version |
|
15 |
- * |
|
16 |
- * Kamailio is distributed in the hope that it will be useful, |
|
17 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
- * GNU General Public License for more details. |
|
20 |
- * |
|
21 |
- * You should have received a copy of the GNU General Public License |
|
22 |
- * along with this program; if not, write to the Free Software |
|
23 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
24 |
- * |
|
25 |
- */ |
|
26 |
- |
|
27 |
-/*! |
|
28 |
- * \file |
|
29 |
- * \brief Kamailio core :: Script callbacks |
|
30 |
- * |
|
31 |
- * Script callbacks adds the ability to register callback |
|
32 |
- * functions which are always called when script for request |
|
33 |
- * processing is entered or left |
|
34 |
- * \ingroup core |
|
35 |
- * Module: \ref core |
|
36 |
- */ |
|
37 |
- |
|
38 |
- |
|
39 |
-#include <stdlib.h> |
|
40 |
-#include "script_cb.h" |
|
41 |
-#include "dprint.h" |
|
42 |
-#include "error.h" |
|
43 |
-#include "mem/mem.h" |
|
44 |
- |
|
45 |
-/* Number of cb types = last cb type */ |
|
46 |
-#define SCRIPT_CB_NUM (MAX_CB_TYPE-1) |
|
47 |
- |
|
48 |
-static struct script_cb *pre_script_cb[SCRIPT_CB_NUM]; |
|
49 |
-static struct script_cb *post_script_cb[SCRIPT_CB_NUM]; |
|
50 |
- |
|
51 |
-/* Add a script callback to the beginning of the linked list. |
|
52 |
- * Returns -1 on error |
|
53 |
- */ |
|
54 |
-static inline int add_callback( struct script_cb **list, |
|
55 |
- cb_function f, void *param) |
|
56 |
-{ |
|
57 |
- struct script_cb *new_cb; |
|
58 |
- |
|
59 |
- new_cb=pkg_malloc(sizeof(struct script_cb)); |
|
60 |
- if (new_cb==0) { |
|
61 |
- LM_CRIT("out of memory\n"); |
|
62 |
- return -1; |
|
63 |
- } |
|
64 |
- new_cb->cbf = f; |
|
65 |
- new_cb->param = param; |
|
66 |
- /* link at the beginning of the list */ |
|
67 |
- new_cb->next = *list; |
|
68 |
- *list = new_cb; |
|
69 |
- return 0; |
|
70 |
-} |
|
71 |
- |
|
72 |
-/* Register pre- or post-script callbacks. |
|
73 |
- * Returns -1 on error, 0 on success |
|
74 |
- */ |
|
75 |
-int register_script_cb( cb_function f, unsigned int flags, void *param ) |
|
76 |
-{ |
|
77 |
- struct script_cb **cb_array; |
|
78 |
- int i; |
|
79 |
- |
|
80 |
- /* type checkings */ |
|
81 |
- if ( (flags&((1<<SCRIPT_CB_NUM)-1))==0 ) { |
|
82 |
- LOG(L_BUG, "register_script_cb: callback flag not specified\n"); |
|
83 |
- return -1; |
|
84 |
- } |
|
85 |
- if ( (flags&(~(PRE_SCRIPT_CB|POST_SCRIPT_CB))) >= 1<<SCRIPT_CB_NUM ) { |
|
86 |
- LOG(L_BUG, "register_script_cb: unsupported callback flags: %u\n", |
|
87 |
- flags); |
|
88 |
- return -1; |
|
89 |
- } |
|
90 |
- if ( (flags&(PRE_SCRIPT_CB|POST_SCRIPT_CB))==0 || |
|
91 |
- (flags&PRE_SCRIPT_CB && flags&POST_SCRIPT_CB) ) { |
|
92 |
- LOG(L_BUG, "register_script_cb: callback POST or PRE type must " |
|
93 |
- "be exactly one\n"); |
|
94 |
- return -1; |
|
95 |
- } |
|
96 |
- |
|
97 |
- if (flags&PRE_SCRIPT_CB) |
|
98 |
- cb_array = pre_script_cb; |
|
99 |
- else |
|
100 |
- cb_array = post_script_cb; |
|
101 |
- |
|
102 |
- /* Add the callback to the lists. |
|
103 |
- * (as many times as many flags are set) |
|
104 |
- */ |
|
105 |
- for (i=0; i<SCRIPT_CB_NUM; i++) { |
|
106 |
- if ((flags&(1<<i)) == 0) |
|
107 |
- continue; |
|
108 |
- if (add_callback(&cb_array[i], f, param) < 0) |
|
109 |
- goto add_error; |
|
110 |
- } |
|
111 |
- return 0; |
|
112 |
- |
|
113 |
-add_error: |
|
114 |
- LM_ERR("failed to add callback\n"); |
|
115 |
- return -1; |
|
116 |
-} |
|
117 |
- |
|
118 |
-int init_script_cb() |
|
119 |
-{ |
|
120 |
- memset(pre_script_cb, 0, SCRIPT_CB_NUM * sizeof(struct script_cb *)); |
|
121 |
- memset(post_script_cb, 0, SCRIPT_CB_NUM * sizeof(struct script_cb *)); |
|
122 |
- return 0; |
|
123 |
-} |
|
124 |
- |
|
125 |
-static inline void destroy_cb_list(struct script_cb **list) |
|
126 |
-{ |
|
127 |
- struct script_cb *foo; |
|
128 |
- |
|
129 |
- while( *list ) { |
|
130 |
- foo = *list; |
|
131 |
- *list = (*list)->next; |
|
132 |
- pkg_free( foo ); |
|
133 |
- } |
|
134 |
-} |
|
135 |
- |
|
136 |
-void destroy_script_cb() |
|
137 |
-{ |
|
138 |
- int i; |
|
139 |
- |
|
140 |
- for (i=0; i<SCRIPT_CB_NUM; i++) { |
|
141 |
- destroy_cb_list(&pre_script_cb[i]); |
|
142 |
- destroy_cb_list(&post_script_cb[i]); |
|
143 |
- } |
|
144 |
-} |
|
145 |
- |
|
146 |
-/* Execute pre-script callbacks of a given type. |
|
147 |
- * Returns 0 on error, 1 on success |
|
148 |
- */ |
|
149 |
-int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type) |
|
150 |
-{ |
|
151 |
- struct script_cb *cb; |
|
152 |
- unsigned int flags; |
|
153 |
- |
|
154 |
-#ifdef EXTRA_DEBUG |
|
155 |
- if (type > SCRIPT_CB_NUM) { |
|
156 |
- LOG(L_BUG, "Uknown callback type\n"); |
|
157 |
- abort(); |
|
158 |
- } |
|
159 |
-#endif |
|
160 |
- flags = PRE_SCRIPT_CB | (1<<(type-1)); |
|
161 |
- for (cb=pre_script_cb[type-1]; cb ; cb=cb->next ) { |
|
162 |
- /* stop on error */ |
|
163 |
- if (cb->cbf(msg, flags, cb->param)==0) |
|
164 |
- return 0; |
|
165 |
- } |
|
166 |
- return 1; |
|
167 |
-} |
|
168 |
- |
|
169 |
-/* Execute post-script callbacks of a given type. |
|
170 |
- * Always returns 1, success. |
|
171 |
- */ |
|
172 |
-int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type) |
|
173 |
-{ |
|
174 |
- struct script_cb *cb; |
|
175 |
- unsigned int flags; |
|
176 |
- |
|
177 |
-#ifdef EXTRA_DEBUG |
|
178 |
- if (type > SCRIPT_CB_NUM) { |
|
179 |
- LOG(L_BUG, "exec_pre_script_cb: Uknown callback type\n"); |
|
180 |
- abort(); |
|
181 |
- } |
|
182 |
-#endif |
|
183 |
- flags = POST_SCRIPT_CB | (1<<(type-1)); |
|
184 |
- for (cb=post_script_cb[type-1]; cb ; cb=cb->next){ |
|
185 |
- cb->cbf(msg, flags, cb->param); |
|
186 |
- } |
|
187 |
- return 1; |
|
188 |
-} |
... | ... |
@@ -13,11 +13,6 @@ |
13 | 13 |
* the Free Software Foundation; either version 2 of the License, or |
14 | 14 |
* (at your option) any later version |
15 | 15 |
* |
16 |
- * For a license to use the ser software under conditions |
|
17 |
- * other than those described here, or to purchase support for this |
|
18 |
- * software, please contact iptel.org by e-mail at the following addresses: |
|
19 |
- * info@iptel.org |
|
20 |
- * |
|
21 | 16 |
* Kamailio is distributed in the hope that it will be useful, |
22 | 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
... | ... |
@@ -1,6 +1,4 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 |
- * |
|
4 | 2 |
* Script callbacks -- they add the ability to register callback |
5 | 3 |
* functions which are always called when script for request |
6 | 4 |
* processing is entered or left |
... | ... |
@@ -8,9 +6,9 @@ |
8 | 6 |
* |
9 | 7 |
* Copyright (C) 2001-2003 FhG Fokus |
10 | 8 |
* |
11 |
- * This file is part of ser, a free SIP server. |
|
9 |
+ * This file is part of Kamailio, a free SIP server. |
|
12 | 10 |
* |
13 |
- * ser is free software; you can redistribute it and/or modify |
|
11 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
14 | 12 |
* it under the terms of the GNU General Public License as published by |
15 | 13 |
* the Free Software Foundation; either version 2 of the License, or |
16 | 14 |
* (at your option) any later version |
... | ... |
@@ -20,7 +18,7 @@ |
20 | 18 |
* software, please contact iptel.org by e-mail at the following addresses: |
21 | 19 |
* info@iptel.org |
22 | 20 |
* |
23 |
- * ser is distributed in the hope that it will be useful, |
|
21 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
24 | 22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | 23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 | 24 |
* GNU General Public License for more details. |
... | ... |
@@ -29,18 +27,15 @@ |
29 | 27 |
* along with this program; if not, write to the Free Software |
30 | 28 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
31 | 29 |
* |
32 |
- * History: |
|
33 |
- * -------- |
|
34 |
- * 2003-03-29 cleaning pkg allocation introduced (jiri) |
|
35 |
- * 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei) |
|
36 |
- * 2005-02-13 script callbacks devided into request and reply types (bogdan) |
|
37 |
- * 2009-06-01 Added pre- and post-script callback support for all types |
|
38 |
- * of route blocks. (Miklos) |
|
39 | 30 |
*/ |
40 | 31 |
|
41 | 32 |
/*! |
42 | 33 |
* \file |
43 |
- * \brief SIP-router core :: |
|
34 |
+ * \brief Kamailio core :: Script callbacks |
|
35 |
+ * |
|
36 |
+ * Script callbacks adds the ability to register callback |
|
37 |
+ * functions which are always called when script for request |
|
38 |
+ * processing is entered or left |
|
44 | 39 |
* \ingroup core |
45 | 40 |
* Module: \ref core |
46 | 41 |
*/ |
... | ... |
@@ -68,7 +68,7 @@ static inline int add_callback( struct script_cb **list, |
68 | 68 |
|
69 | 69 |
new_cb=pkg_malloc(sizeof(struct script_cb)); |
70 | 70 |
if (new_cb==0) { |
71 |
- LOG(L_CRIT, "add_script_callback: out of memory\n"); |
|
71 |
+ LM_CRIT("out of memory\n"); |
|
72 | 72 |
return -1; |
73 | 73 |
} |
74 | 74 |
new_cb->cbf = f; |
... | ... |
@@ -121,7 +121,7 @@ int register_script_cb( cb_function f, unsigned int flags, void *param ) |
121 | 121 |
return 0; |
122 | 122 |
|
123 | 123 |
add_error: |
124 |
- LOG(L_ERR,"register_script_cb: failed to add callback\n"); |
|
124 |
+ LM_ERR("failed to add callback\n"); |
|
125 | 125 |
return -1; |
126 | 126 |
} |
127 | 127 |
|
... | ... |
@@ -27,7 +27,7 @@ |
27 | 27 |
* |
28 | 28 |
* You should have received a copy of the GNU General Public License |
29 | 29 |
* along with this program; if not, write to the Free Software |
30 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
30 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
31 | 31 |
* |
32 | 32 |
* History: |
33 | 33 |
* -------- |
- reported by Seudin Kasumovic, FS#388
... | ... |
@@ -162,8 +162,8 @@ int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type) |
162 | 162 |
unsigned int flags; |
163 | 163 |
|
164 | 164 |
#ifdef EXTRA_DEBUG |
165 |
- if (type >= SCRIPT_CB_NUM) { |
|
166 |
- LOG(L_BUG, "exec_pre_script_cb: Uknown callback type\n"); |
|
165 |
+ if (type > SCRIPT_CB_NUM) { |
|
166 |
+ LOG(L_BUG, "Uknown callback type\n"); |
|
167 | 167 |
abort(); |
168 | 168 |
} |
169 | 169 |
#endif |
... | ... |
@@ -185,7 +185,7 @@ int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type) |
185 | 185 |
unsigned int flags; |
186 | 186 |
|
187 | 187 |
#ifdef EXTRA_DEBUG |
188 |
- if (type >= SCRIPT_CB_NUM) { |
|
188 |
+ if (type > SCRIPT_CB_NUM) { |
|
189 | 189 |
LOG(L_BUG, "exec_pre_script_cb: Uknown callback type\n"); |
190 | 190 |
abort(); |
191 | 191 |
} |
... | ... |
@@ -53,7 +53,7 @@ |
53 | 53 |
#include "mem/mem.h" |
54 | 54 |
|
55 | 55 |
/* Number of cb types = last cb type */ |
56 |
-#define SCRIPT_CB_NUM EVENT_CB_TYPE |
|
56 |
+#define SCRIPT_CB_NUM (MAX_CB_TYPE-1) |
|
57 | 57 |
|
58 | 58 |
static struct script_cb *pre_script_cb[SCRIPT_CB_NUM]; |
59 | 59 |
static struct script_cb *post_script_cb[SCRIPT_CB_NUM]; |
Remove new branch_failure_route in favour of an event_route
This reverts commit a5946574cb9917f0a9a90ea547c9357f3f6477bd.
... | ... |
@@ -53,7 +53,7 @@ |
53 | 53 |
#include "mem/mem.h" |
54 | 54 |
|
55 | 55 |
/* Number of cb types = last cb type */ |
56 |
-#define SCRIPT_CB_NUM (CB_TYPE_MAX-1) |
|
56 |
+#define SCRIPT_CB_NUM EVENT_CB_TYPE |
|
57 | 57 |
|
58 | 58 |
static struct script_cb *pre_script_cb[SCRIPT_CB_NUM]; |
59 | 59 |
static struct script_cb *post_script_cb[SCRIPT_CB_NUM]; |
- New branch_failure_route defined
- cfg route is called but xlog() causes segfault
... | ... |
@@ -53,7 +53,7 @@ |
53 | 53 |
#include "mem/mem.h" |
54 | 54 |
|
55 | 55 |
/* Number of cb types = last cb type */ |
56 |
-#define SCRIPT_CB_NUM EVENT_CB_TYPE |
|
56 |
+#define SCRIPT_CB_NUM (CB_TYPE_MAX-1) |
|
57 | 57 |
|
58 | 58 |
static struct script_cb *pre_script_cb[SCRIPT_CB_NUM]; |
59 | 59 |
static struct script_cb *post_script_cb[SCRIPT_CB_NUM]; |
Please fill in after the :: to explain the function of this file.
- callbacks have been tested, bugs found have
been corrected.
... | ... |
@@ -160,8 +160,8 @@ int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type) |
160 | 160 |
abort(); |
161 | 161 |
} |
162 | 162 |
#endif |
163 |
- flags = PRE_SCRIPT_CB & (1<<(type-1)); |
|
164 |
- for (cb=pre_script_cb[type]; cb ; cb=cb->next ) { |
|
163 |
+ flags = PRE_SCRIPT_CB | (1<<(type-1)); |
|
164 |
+ for (cb=pre_script_cb[type-1]; cb ; cb=cb->next ) { |
|
165 | 165 |
/* stop on error */ |
166 | 166 |
if (cb->cbf(msg, flags, cb->param)==0) |
167 | 167 |
return 0; |
... | ... |
@@ -183,8 +183,8 @@ int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type) |
183 | 183 |
abort(); |
184 | 184 |
} |
185 | 185 |
#endif |
186 |
- flags = POST_SCRIPT_CB & (1<<(type-1)); |
|
187 |
- for (cb=post_script_cb[type]; cb ; cb=cb->next){ |
|
186 |
+ flags = POST_SCRIPT_CB | (1<<(type-1)); |
|
187 |
+ for (cb=post_script_cb[type-1]; cb ; cb=cb->next){ |
|
188 | 188 |
cb->cbf(msg, flags, cb->param); |
189 | 189 |
} |
190 | 190 |
return 1; |
- Added pre- and post-script callback support
for all kind of route blocks.
- req/rpl is changed to be a flag, so more callback types
can be registered at once this way. The flag is passed to
the callback function.
... | ... |
@@ -34,6 +34,8 @@ |
34 | 34 |
* 2003-03-29 cleaning pkg allocation introduced (jiri) |
35 | 35 |
* 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei) |
36 | 36 |
* 2005-02-13 script callbacks devided into request and reply types (bogdan) |
37 |
+ * 2009-06-01 Added pre- and post-script callback support for all types |
|
38 |
+ * of route blocks. (Miklos) |
|
37 | 39 |
*/ |
38 | 40 |
|
39 | 41 |
|
... | ... |
@@ -43,15 +45,15 @@ |
43 | 45 |
#include "error.h" |
44 | 46 |
#include "mem/mem.h" |
45 | 47 |
|
46 |
-static struct script_cb *pre_req_cb=0; |
|
47 |
-static struct script_cb *post_req_cb=0; |
|
48 |
- |
|
49 |
-static struct script_cb *pre_rpl_cb=0; |
|
50 |
-static struct script_cb *post_rpl_cb=0; |
|
51 |
- |
|
52 |
-static unsigned int cb_id=0; |
|
48 |
+/* Number of cb types = last cb type */ |
|
49 |
+#define SCRIPT_CB_NUM EVENT_CB_TYPE |
|
53 | 50 |
|
51 |
+static struct script_cb *pre_script_cb[SCRIPT_CB_NUM]; |
|
52 |
+static struct script_cb *post_script_cb[SCRIPT_CB_NUM]; |
|
54 | 53 |
|
54 |
+/* Add a script callback to the beginning of the linked list. |
|
55 |
+ * Returns -1 on error |
|
56 |
+ */ |
|
55 | 57 |
static inline int add_callback( struct script_cb **list, |
56 | 58 |
cb_function f, void *param) |
57 | 59 |
{ |
... | ... |
@@ -59,11 +61,10 @@ static inline int add_callback( struct script_cb **list, |
59 | 61 |
|
60 | 62 |
new_cb=pkg_malloc(sizeof(struct script_cb)); |
61 | 63 |
if (new_cb==0) { |
62 |
- LOG(L_ERR, "ERROR:add_script_callback: out of memory\n"); |
|
64 |
+ LOG(L_CRIT, "add_script_callback: out of memory\n"); |
|
63 | 65 |
return -1; |
64 | 66 |
} |
65 | 67 |
new_cb->cbf = f; |
66 |
- new_cb->id = cb_id++; |
|
67 | 68 |
new_cb->param = param; |
68 | 69 |
/* link at the beginning of the list */ |
69 | 70 |
new_cb->next = *list; |
... | ... |
@@ -71,50 +72,58 @@ static inline int add_callback( struct script_cb **list, |
71 | 72 |
return 0; |
72 | 73 |
} |
73 | 74 |
|
74 |
- |
|
75 |
-int register_script_cb( cb_function f, int type, void *param ) |
|
75 |
+/* Register pre- or post-script callbacks. |
|
76 |
+ * Returns -1 on error, 0 on success |
|
77 |
+ */ |
|
78 |
+int register_script_cb( cb_function f, unsigned int flags, void *param ) |
|
76 | 79 |
{ |
80 |
+ struct script_cb **cb_array; |
|
81 |
+ int i; |
|
82 |
+ |
|
77 | 83 |
/* type checkings */ |
78 |
- if ( (type&(REQ_TYPE_CB|RPL_TYPE_CB))==0 ) { |
|
79 |
- LOG(L_CRIT,"BUG:register_script_cb: REQUEST or REPLY " |
|
80 |
- "type not specified\n"); |
|
81 |
- goto error; |
|
84 |
+ if ( (flags&((1<<SCRIPT_CB_NUM)-1))==0 ) { |
|
85 |
+ LOG(L_BUG, "register_script_cb: callback flag not specified\n"); |
|
86 |
+ return -1; |
|
87 |
+ } |
|
88 |
+ if ( (flags&(~(PRE_SCRIPT_CB|POST_SCRIPT_CB))) >= 1<<SCRIPT_CB_NUM ) { |
|
89 |
+ LOG(L_BUG, "register_script_cb: unsupported callback flags: %u\n", |
|
90 |
+ flags); |
|
91 |
+ return -1; |
|
82 | 92 |
} |
83 |
- if ( (type&(PRE_SCRIPT_CB|POST_SCRIPT_CB))==0 || |
|
84 |
- (type&PRE_SCRIPT_CB && type&POST_SCRIPT_CB) ) { |
|
85 |
- LOG(L_CRIT,"BUG:register_script_cb: callback POST or PRE type must " |
|
93 |
+ if ( (flags&(PRE_SCRIPT_CB|POST_SCRIPT_CB))==0 || |
|
94 |
+ (flags&PRE_SCRIPT_CB && flags&POST_SCRIPT_CB) ) { |
|
95 |
+ LOG(L_BUG, "register_script_cb: callback POST or PRE type must " |
|
86 | 96 |
"be exactly one\n"); |
87 |
- goto error; |
|
97 |
+ return -1; |
|
88 | 98 |
} |
89 | 99 |
|
90 |
- if (type&REQ_TYPE_CB) { |
|
91 |
- /* callback for request script */ |
|
92 |
- if (type&PRE_SCRIPT_CB) { |
|
93 |
- if (add_callback( &pre_req_cb, f, param)<0) |
|
94 |
- goto add_error; |
|
95 |
- } else if (type&POST_SCRIPT_CB) { |
|
96 |
- if (add_callback( &post_req_cb, f, param)<0) |
|
97 |
- goto add_error; |
|
98 |
- } |
|
99 |
- } |
|
100 |
- if (type&RPL_TYPE_CB) { |
|
101 |
- /* callback (also) for reply script */ |
|
102 |
- if (type&PRE_SCRIPT_CB) { |
|
103 |
- if (add_callback( &pre_rpl_cb, f, param)<0) |
|
104 |
- goto add_error; |
|
105 |
- } else if (type&POST_SCRIPT_CB) { |
|
106 |
- if (add_callback( &post_rpl_cb, f, param)<0) |
|
107 |
- goto add_error; |
|
108 |
- } |
|
100 |
+ if (flags&PRE_SCRIPT_CB) |
|
101 |
+ cb_array = pre_script_cb; |
|
102 |
+ else |
|
103 |
+ cb_array = post_script_cb; |
|
104 |
+ |
|
105 |
+ /* Add the callback to the lists. |
|
106 |
+ * (as many times as many flags are set) |
|
107 |
+ */ |
|
108 |
+ for (i=0; i<SCRIPT_CB_NUM; i++) { |
|
109 |
+ if ((flags&(1<<i)) == 0) |
|
110 |
+ continue; |
|
111 |
+ if (add_callback(&cb_array[i], f, param) < 0) |
|
112 |
+ goto add_error; |
|
109 | 113 |
} |
110 |
- |
|
111 | 114 |
return 0; |
115 |
+ |
|
112 | 116 |
add_error: |
113 |
- LOG(L_ERR,"ERROR:register_script_cb: failed to add callback\n"); |
|
114 |
-error: |
|
117 |
+ LOG(L_ERR,"register_script_cb: failed to add callback\n"); |
|
115 | 118 |
return -1; |
116 | 119 |
} |
117 | 120 |
|
121 |
+int init_script_cb() |
|
122 |
+{ |
|
123 |
+ memset(pre_script_cb, 0, SCRIPT_CB_NUM * sizeof(struct script_cb *)); |
|
124 |
+ memset(post_script_cb, 0, SCRIPT_CB_NUM * sizeof(struct script_cb *)); |
|
125 |
+ return 0; |
|
126 |
+} |
|
118 | 127 |
|
119 | 128 |
static inline void destroy_cb_list(struct script_cb **list) |
120 | 129 |
{ |
... | ... |
@@ -127,53 +136,56 @@ static inline void destroy_cb_list(struct script_cb **list) |
127 | 136 |
} |
128 | 137 |
} |
129 | 138 |
|
130 |
- |
|
131 | 139 |
void destroy_script_cb() |
132 | 140 |
{ |
133 |
- destroy_cb_list( &pre_req_cb ); |
|
134 |
- destroy_cb_list( &post_req_cb ); |
|
135 |
- destroy_cb_list( &pre_rpl_cb ); |
|
136 |
- destroy_cb_list( &post_req_cb ); |
|
137 |
-} |
|
141 |
+ int i; |
|
138 | 142 |
|
143 |
+ for (i=0; i<SCRIPT_CB_NUM; i++) { |
|
144 |
+ destroy_cb_list(&pre_script_cb[i]); |
|
145 |
+ destroy_cb_list(&post_script_cb[i]); |
|
146 |
+ } |
|
147 |
+} |
|
139 | 148 |
|
140 |
-static inline int exec_pre_cb( struct sip_msg *msg, struct script_cb *cb) |
|
149 |
+/* Execute pre-script callbacks of a given type. |
|
150 |
+ * Returns 0 on error, 1 on success |
|
151 |
+ */ |
|
152 |
+int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type) |
|
141 | 153 |
{ |
142 |
- for ( ; cb ; cb=cb->next ) { |
|
154 |
+ struct script_cb *cb; |
|
155 |
+ unsigned int flags; |
|
156 |
+ |
|
157 |
+#ifdef EXTRA_DEBUG |
|
158 |
+ if (type >= SCRIPT_CB_NUM) { |
|
159 |
+ LOG(L_BUG, "exec_pre_script_cb: Uknown callback type\n"); |
|
160 |
+ abort(); |
|
161 |
+ } |
|
162 |
+#endif |
|
163 |
+ flags = PRE_SCRIPT_CB & (1<<(type-1)); |
|
164 |
+ for (cb=pre_script_cb[type]; cb ; cb=cb->next ) { |
|
143 | 165 |
/* stop on error */ |
144 |
- if (cb->cbf(msg, cb->param)==0) |
|
166 |
+ if (cb->cbf(msg, flags, cb->param)==0) |
|
145 | 167 |
return 0; |
146 | 168 |
} |
147 | 169 |
return 1; |
148 | 170 |
} |
149 | 171 |
|
150 |
- |
|
151 |
-static inline int exec_post_cb( struct sip_msg *msg, struct script_cb *cb) |
|
172 |
+/* Execute post-script callbacks of a given type. |
|
173 |
+ * Always returns 1, success. |
|
174 |
+ */ |
|
175 |
+int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type) |
|
152 | 176 |
{ |
153 |
- for ( ; cb ; cb=cb->next){ |
|
154 |
- cb->cbf( msg, cb->param); |
|
177 |
+ struct script_cb *cb; |
|
178 |
+ unsigned int flags; |
|
179 |
+ |
|
180 |
+#ifdef EXTRA_DEBUG |
|
181 |
+ if (type >= SCRIPT_CB_NUM) { |
|
182 |
+ LOG(L_BUG, "exec_pre_script_cb: Uknown callback type\n"); |
|
183 |
+ abort(); |
|
184 |
+ } |
|
185 |
+#endif |
|
186 |
+ flags = POST_SCRIPT_CB & (1<<(type-1)); |
|
187 |
+ for (cb=post_script_cb[type]; cb ; cb=cb->next){ |
|
188 |
+ cb->cbf(msg, flags, cb->param); |
|
155 | 189 |
} |
156 | 190 |
return 1; |
157 | 191 |
} |
158 |
- |
|
159 |
- |
|
160 |
-int exec_pre_req_cb( struct sip_msg *msg) |
|
161 |
-{ |
|
162 |
- return exec_pre_cb( msg, pre_req_cb); |
|
163 |
-} |
|
164 |
- |
|
165 |
-int exec_pre_rpl_cb( struct sip_msg *msg) |
|
166 |
-{ |
|
167 |
- return exec_pre_cb( msg, pre_rpl_cb); |
|
168 |
-} |
|
169 |
- |
|
170 |
-int exec_post_req_cb( struct sip_msg *msg) |
|
171 |
-{ |
|
172 |
- return exec_post_cb( msg, post_req_cb); |
|
173 |
-} |
|
174 |
- |
|
175 |
-int exec_post_rpl_cb( struct sip_msg *msg) |
|
176 |
-{ |
|
177 |
- return exec_post_cb( msg, post_rpl_cb); |
|
178 |
-} |
|
179 |
- |
... | ... |
@@ -97,7 +97,7 @@ int register_script_cb( cb_function f, int type, void *param ) |
97 | 97 |
goto add_error; |
98 | 98 |
} |
99 | 99 |
} |
100 |
- if (type&REQ_TYPE_CB) { |
|
100 |
+ if (type&RPL_TYPE_CB) { |
|
101 | 101 |
/* callback (also) for reply script */ |
102 | 102 |
if (type&PRE_SCRIPT_CB) { |
103 | 103 |
if (add_callback( &pre_rpl_cb, f, param)<0) |
... | ... |
@@ -28,11 +28,12 @@ |
28 | 28 |
* You should have received a copy of the GNU General Public License |
29 | 29 |
* along with this program; if not, write to the Free Software |
30 | 30 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
31 |
- */ |
|
32 |
-/* History: |
|
31 |
+ * |
|
32 |
+ * History: |
|
33 | 33 |
* -------- |
34 | 34 |
* 2003-03-29 cleaning pkg allocation introduced (jiri) |
35 | 35 |
* 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei) |
36 |
+ * 2005-02-13 script callbacks devided into request and reply types (bogdan) |
|
36 | 37 |
*/ |
37 | 38 |
|
38 | 39 |
|
... | ... |
@@ -42,61 +43,137 @@ |
42 | 43 |
#include "error.h" |
43 | 44 |
#include "mem/mem.h" |
44 | 45 |
|
45 |
-static struct script_cb *pre_cb=0; |
|
46 |
-static struct script_cb *post_cb=0; |
|
46 |
+static struct script_cb *pre_req_cb=0; |
|
47 |
+static struct script_cb *post_req_cb=0; |
|
48 |
+ |
|
49 |
+static struct script_cb *pre_rpl_cb=0; |
|
50 |
+static struct script_cb *post_rpl_cb=0; |
|
51 |
+ |
|
47 | 52 |
static unsigned int cb_id=0; |
48 | 53 |
|
49 |
-int register_script_cb( cb_function f, callback_t t, void *param ) |
|
54 |
+ |
|
55 |
+static inline int add_callback( struct script_cb **list, |
|
56 |
+ cb_function f, void *param) |
|
50 | 57 |
{ |
51 | 58 |
struct script_cb *new_cb; |
52 | 59 |
|
53 | 60 |
new_cb=pkg_malloc(sizeof(struct script_cb)); |
54 | 61 |
if (new_cb==0) { |
55 |
- LOG(L_ERR, "ERROR: register_script_cb: out of memory\n"); |
|
56 |
- return E_OUT_OF_MEM; |
|
62 |
+ LOG(L_ERR, "ERROR:add_script_callback: out of memory\n"); |
|
63 |
+ return -1; |
|
57 | 64 |
} |
58 |
- new_cb->cbf=f; |
|
59 |
- new_cb->id=cb_id++; |
|
60 |
- new_cb->param=param; |
|
61 |
- /* insert into appropriate list */ |
|
62 |
- if (t==PRE_SCRIPT_CB) { |
|
63 |
- new_cb->next=pre_cb; |
|
64 |
- pre_cb=new_cb; |
|
65 |
- } else if (t==POST_SCRIPT_CB) { |
|
66 |
- new_cb->next=post_cb; |
|
67 |
- post_cb=new_cb; |
|
68 |
- } else { |
|
69 |
- LOG(L_CRIT, "ERROR: register_script_cb: unknown CB type\n"); |
|
70 |
- return E_BUG; |
|
65 |
+ new_cb->cbf = f; |
|
66 |
+ new_cb->id = cb_id++; |
|
67 |
+ new_cb->param = param; |
|
68 |
+ /* link at the beginning of the list */ |
|
69 |
+ new_cb->next = *list; |
|
70 |
+ *list = new_cb; |
|
71 |
+ return 0; |
|
72 |
+} |
|
73 |
+ |
|
74 |
+ |
|
75 |
+int register_script_cb( cb_function f, int type, void *param ) |
|
76 |
+{ |
|
77 |
+ /* type checkings */ |
|
78 |
+ if ( (type&(REQ_TYPE_CB|RPL_TYPE_CB))==0 ) { |
|
79 |
+ LOG(L_CRIT,"BUG:register_script_cb: REQUEST or REPLY " |
|
80 |
+ "type not specified\n"); |
|
81 |
+ goto error; |
|
71 | 82 |
} |
72 |
- /* ok, callback installed */ |
|
73 |
- return 1; |
|
83 |
+ if ( (type&(PRE_SCRIPT_CB|POST_SCRIPT_CB))==0 || |
|
84 |
+ (type&PRE_SCRIPT_CB && type&POST_SCRIPT_CB) ) { |
|
85 |
+ LOG(L_CRIT,"BUG:register_script_cb: callback POST or PRE type must " |
|
86 |
+ "be exactly one\n"); |
|
87 |
+ goto error; |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ if (type&REQ_TYPE_CB) { |
|
91 |
+ /* callback for request script */ |
|
92 |
+ if (type&PRE_SCRIPT_CB) { |
|
93 |
+ if (add_callback( &pre_req_cb, f, param)<0) |
|
94 |
+ goto add_error; |
|
95 |
+ } else if (type&POST_SCRIPT_CB) { |
|
96 |
+ if (add_callback( &post_req_cb, f, param)<0) |
|
97 |
+ goto add_error; |
|
98 |
+ } |
|
99 |
+ } |
|
100 |
+ if (type&REQ_TYPE_CB) { |
|
101 |
+ /* callback (also) for reply script */ |
|
102 |
+ if (type&PRE_SCRIPT_CB) { |
|
103 |
+ if (add_callback( &pre_rpl_cb, f, param)<0) |
|
104 |
+ goto add_error; |
|
105 |
+ } else if (type&POST_SCRIPT_CB) { |
|
106 |
+ if (add_callback( &post_rpl_cb, f, param)<0) |
|
107 |
+ goto add_error; |
|
108 |
+ } |
|
109 |
+ } |
|
110 |
+ |
|
111 |
+ return 0; |
|
112 |
+add_error: |
|
113 |
+ LOG(L_ERR,"ERROR:register_script_cb: failed to add callback\n"); |
|
114 |
+error: |
|
115 |
+ return -1; |
|
74 | 116 |
} |
75 | 117 |
|
76 |
-void destroy_script_cb() |
|
118 |
+ |
|
119 |
+static inline void destroy_cb_list(struct script_cb **list) |
|
77 | 120 |
{ |
78 |
- struct script_cb *cb, *foo; |
|
121 |
+ struct script_cb *foo; |
|
122 |
+ |
|
123 |
+ while( *list ) { |
|
124 |
+ foo = *list; |
|
125 |
+ *list = (*list)->next; |
|
126 |
+ pkg_free( foo ); |
|
127 |
+ } |
|
128 |
+} |
|
79 | 129 |
|
80 |
- cb=pre_cb; |
|
81 |
- while(cb) { foo=cb->next;pkg_free(cb);cb=foo; } |
|
82 |
- cb=post_cb; |
|
83 |
- while(cb) { foo=cb->next;pkg_free(cb);cb=foo; } |
|
130 |
+ |
|
131 |
+void destroy_script_cb() |
|
132 |
+{ |
|
133 |
+ destroy_cb_list( &pre_req_cb ); |
|
134 |
+ destroy_cb_list( &post_req_cb ); |
|
135 |
+ destroy_cb_list( &pre_rpl_cb ); |
|
136 |
+ destroy_cb_list( &post_req_cb ); |
|
84 | 137 |
} |
85 | 138 |
|
86 |
-int exec_pre_cb( struct sip_msg *msg) |
|
139 |
+ |
|
140 |
+static inline int exec_pre_cb( struct sip_msg *msg, struct script_cb *cb) |
|
87 | 141 |
{ |
88 |
- struct script_cb *i; |
|
89 |
- for (i=pre_cb; i; i=i->next) { |
|
142 |
+ for ( ; cb ; cb=cb->next ) { |
|
90 | 143 |
/* stop on error */ |
91 |
- if (i->cbf(msg, i->param)==0) |
|
144 |
+ if (cb->cbf(msg, cb->param)==0) |
|
92 | 145 |
return 0; |
93 | 146 |
} |
94 | 147 |
return 1; |
95 | 148 |
} |
96 | 149 |
|
97 |
-void exec_post_cb( struct sip_msg *msg) |
|
150 |
+ |
|
151 |
+static inline int exec_post_cb( struct sip_msg *msg, struct script_cb *cb) |
|
152 |
+{ |
|
153 |
+ for ( ; cb ; cb=cb->next){ |
|
154 |
+ cb->cbf( msg, cb->param); |
|
155 |
+ } |
|
156 |
+ return 1; |
|
157 |
+} |
|
158 |
+ |
|
159 |
+ |
|
160 |
+int exec_pre_req_cb( struct sip_msg *msg) |
|
161 |
+{ |
|
162 |
+ return exec_pre_cb( msg, pre_req_cb); |
|
163 |
+} |
|
164 |
+ |
|
165 |
+int exec_pre_rpl_cb( struct sip_msg *msg) |
|
166 |
+{ |
|
167 |
+ return exec_pre_cb( msg, pre_rpl_cb); |
|
168 |
+} |
|
169 |
+ |
|
170 |
+int exec_post_req_cb( struct sip_msg *msg) |
|
171 |
+{ |
|
172 |
+ return exec_post_cb( msg, post_req_cb); |
|
173 |
+} |
|
174 |
+ |
|
175 |
+int exec_post_rpl_cb( struct sip_msg *msg) |
|
98 | 176 |
{ |
99 |
- struct script_cb *i; |
|
100 |
- for (i=post_cb; i; i=i->next) i->cbf(msg, i->param); |
|
177 |
+ return exec_post_cb( msg, post_rpl_cb); |
|
101 | 178 |
} |
102 | 179 |
|
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
*/ |
32 | 32 |
/* History: |
33 | 33 |
* -------- |
34 |
+ * 2003-03-29 cleaning pkg allocation introduced (jiri) |
|
34 | 35 |
* 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei) |
35 | 36 |
*/ |
36 | 37 |
|
... | ... |
@@ -72,6 +73,16 @@ int register_script_cb( cb_function f, callback_t t, void *param ) |
72 | 73 |
return 1; |
73 | 74 |
} |
74 | 75 |
|
76 |
+void destroy_script_cb() |
|
77 |
+{ |
|
78 |
+ struct script_cb *cb, *foo; |
|
79 |
+ |
|
80 |
+ cb=pre_cb; |
|
81 |
+ while(cb) { foo=cb->next;pkg_free(cb);cb=foo; } |
|
82 |
+ cb=post_cb; |
|
83 |
+ while(cb) { foo=cb->next;pkg_free(cb);cb=foo; } |
|
84 |
+} |
|
85 |
+ |
|
75 | 86 |
int exec_pre_cb( struct sip_msg *msg) |
76 | 87 |
{ |
77 | 88 |
struct script_cb *i; |
... | ... |
@@ -29,12 +29,17 @@ |
29 | 29 |
* along with this program; if not, write to the Free Software |
30 | 30 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
31 | 31 |
*/ |
32 |
+/* History: |
|
33 |
+ * -------- |
|
34 |
+ * 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei) |
|
35 |
+ */ |
|
32 | 36 |
|
33 | 37 |
|
34 | 38 |
#include <stdlib.h> |
35 | 39 |
#include "script_cb.h" |
36 | 40 |
#include "dprint.h" |
37 | 41 |
#include "error.h" |
42 |
+#include "mem/mem.h" |
|
38 | 43 |
|
39 | 44 |
static struct script_cb *pre_cb=0; |
40 | 45 |
static struct script_cb *post_cb=0; |
... | ... |
@@ -44,7 +49,7 @@ int register_script_cb( cb_function f, callback_t t, void *param ) |
44 | 49 |
{ |
45 | 50 |
struct script_cb *new_cb; |
46 | 51 |
|
47 |
- new_cb=malloc(sizeof(struct script_cb)); |
|
52 |
+ new_cb=pkg_malloc(sizeof(struct script_cb)); |
|
48 | 53 |
if (new_cb==0) { |
49 | 54 |
LOG(L_ERR, "ERROR: register_script_cb: out of memory\n"); |
50 | 55 |
return E_OUT_OF_MEM; |
... | ... |
@@ -67,10 +67,15 @@ int register_script_cb( cb_function f, callback_t t, void *param ) |
67 | 67 |
return 1; |
68 | 68 |
} |
69 | 69 |
|
70 |
-void exec_pre_cb( struct sip_msg *msg) |
|
70 |
+int exec_pre_cb( struct sip_msg *msg) |
|
71 | 71 |
{ |
72 | 72 |
struct script_cb *i; |
73 |
- for (i=pre_cb; i; i=i->next) i->cbf(msg, i->param); |
|
73 |
+ for (i=pre_cb; i; i=i->next) { |
|
74 |
+ /* stop on error */ |
|
75 |
+ if (i->cbf(msg, i->param)==0) |
|
76 |
+ return 0; |
|
77 |
+ } |
|
78 |
+ return 1; |
|
74 | 79 |
} |
75 | 80 |
|
76 | 81 |
void exec_post_cb( struct sip_msg *msg) |
... | ... |
@@ -5,8 +5,32 @@ |
5 | 5 |
* functions which are always called when script for request |
6 | 6 |
* processing is entered or left |
7 | 7 |
* |
8 |
+ * |
|
9 |
+ * Copyright (C) 2001-2003 Fhg Fokus |
|
10 |
+ * |
|
11 |
+ * This file is part of ser, a free SIP server. |
|
12 |
+ * |
|
13 |
+ * ser is free software; you can redistribute it and/or modify |
|
14 |
+ * it under the terms of the GNU General Public License as published by |
|
15 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
16 |
+ * (at your option) any later version |
|
17 |
+ * |
|
18 |
+ * For a license to use the ser software under conditions |
|
19 |
+ * other than those described here, or to purchase support for this |
|
20 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
21 |
+ * info@iptel.org |
|
22 |
+ * |
|
23 |
+ * ser is distributed in the hope that it will be useful, |
|
24 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
25 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
26 |
+ * GNU General Public License for more details. |
|
27 |
+ * |
|
28 |
+ * You should have received a copy of the GNU General Public License |
|
29 |
+ * along with this program; if not, write to the Free Software |
|
30 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
8 | 31 |
*/ |
9 | 32 |
|
33 |
+ |
|