Browse code

userblacklist(k): add new function 'check_user_whitelist'

- add new function 'check_user whitelist'
- patch from Alexandr Dubovikov, Alexandr dot Dubovikov at qsc dot de
- works like the existing check_user_blacklist, but return -1 when not
the user is not found

Henning Westerholt authored on 04/09/2009 15:44:43
Showing 3 changed files
... ...
@@ -13,62 +13,65 @@ Henning Westerholt
13 13
 
14 14
    Copyright � 2008 1&1 Internet AG
15 15
    Revision History
16
-   Revision $Revision: 4863 $ $Date: 2008-09-05 13:11:33 +0200
17
-                              (Fr, 05 Sep 2008) $
18
-     __________________________________________________________
16
+   Revision $Revision$ $Date$
17
+     __________________________________________________________________
19 18
 
20 19
    Table of Contents
21 20
 
22 21
    1. Admin Guide
23 22
 
24
-        1.1. Overview
25
-        1.2. Dependencies
23
+        1. Overview
24
+        2. Dependencies
26 25
 
27
-              1.2.1. Kamailio Modules
28
-              1.2.2. External Libraries or Applications
26
+              2.1. Kamailio Modules
27
+              2.2. External Libraries or Applications
29 28
 
30
-        1.3. Exported Parameters
29
+        3. Exported Parameters
31 30
 
32
-              1.3.1. use_domain (integer)
31
+              3.1. use_domain (integer)
33 32
 
34
-        1.4. Exported Functions
33
+        4. Exported Functions
35 34
 
36
-              1.4.1. check_user_blacklist (string user, string
37
-                      domain, string number, string table)
35
+              4.1. check_user_blacklist (string user, string domain,
36
+                      string number, string table)
38 37
 
39
-              1.4.2. check_blacklist (string table)
38
+              4.2. check_user_whitelist (string user, string domain,
39
+                      string number, string table)
40 40
 
41
-        1.5. MI Commands
41
+              4.3. check_blacklist (string table)
42 42
 
43
-              1.5.1. reload_blacklist
43
+        5. MI Commands
44 44
 
45
-        1.6. Installation and Running
45
+              5.1. reload_blacklist
46 46
 
47
-              1.6.1. Database setup
47
+        6. Installation and Running
48
+
49
+              6.1. Database setup
48 50
 
49 51
    2. Module parameter for database access.
50 52
 
51
-        2.1. db_url (String)
52
-        2.2. userblacklist_table (String)
53
-        2.3. userblacklist_id_col (string)
54
-        2.4. userblacklist_username_col (string)
55
-        2.5. userblacklist_domain_col (string)
56
-        2.6. userblacklist_prefix_col (string)
57
-        2.7. userblacklist_whitelist_col (string)
58
-        2.8. globalblacklist_table (String)
59
-        2.9. globalblacklist_id_col (string)
60
-        2.10. globalblacklist_prefix_col (string)
61
-        2.11. globalblacklist_whitelist_col (string)
62
-        2.12. globalblacklist_description_col (string)
53
+        1. db_url (String)
54
+        2. userblacklist_table (String)
55
+        3. userblacklist_id_col (string)
56
+        4. userblacklist_username_col (string)
57
+        5. userblacklist_domain_col (string)
58
+        6. userblacklist_prefix_col (string)
59
+        7. userblacklist_whitelist_col (string)
60
+        8. globalblacklist_table (String)
61
+        9. globalblacklist_id_col (string)
62
+        10. globalblacklist_prefix_col (string)
63
+        11. globalblacklist_whitelist_col (string)
64
+        12. globalblacklist_description_col (string)
63 65
 
64 66
    List of Examples
65 67
 
66 68
    1.1. Set use_domain parameter
67 69
    1.2. check_user_blacklist usage
68
-   1.3. check_blacklist usage
69
-   1.4. reload_blacklists usage
70
-   1.5. Example database content - globalblacklist table
71
-   1.6. Example database content - userblacklist table
70
+   1.3. check_user_blacklist usage
71
+   1.4. check_blacklist usage
72
+   1.5. reload_blacklists usage
73
+   1.6. Example database content - globalblacklist table
74
+   1.7. Example database content - userblacklist table
72 75
    2.1. Set db_url parameter
73 76
    2.2. Set userblacklist_table parameter
74 77
    2.3. Set userblacklist_id_col parameter
... ...
@@ -84,55 +87,88 @@ Henning Westerholt
84 87
 
85 88
 Chapter 1. Admin Guide
86 89
 
87
-1.1. Overview
88
-
89
-   The userblacklist module allows Kamailio to handle blacklists
90
-   on a per user basis. This information is stored in a database
91
-   table, which is queried to decide if the number (more exactly,
92
-   the request URI user) is blacklisted or not.
93
-
94
-   An additional functionality that this module provides is the
95
-   ability to handle global blacklists. This lists are loaded on
96
-   startup into memory, thus providing a better performance then
97
-   in the userblacklist case. This global blacklists are useful to
98
-   only allow calls to certain international destinations, i.e.
99
-   block all not whitelisted numbers. They could also used to
100
-   prevent the blacklisting of important numbers, as whitelisting
101
-   is supported too. This is useful for example to prevent the
102
-   customer from blocking emergency call number or service
103
-   hotlines.
104
-
105
-   The module exports two functions, check_blacklist and
106
-   check_user_blacklist for usage in the config file. Furthermore
107
-   its provide a FIFO function to reload the global blacklist
108
-   cache.
109
-
110
-   Please note that only numerical strings for matching are
111
-   supported at the moment (the used library supports this
112
-   already, but its not yet implemented in the module). Non-digits
113
-   on the beginning of the matched string are skipped, any later
114
-   non-digits will stop the matching on this position.
115
-
116
-1.2. Dependencies
117
-
118
-1.2.1. Kamailio Modules
119
-
120
-   The module depends on the following modules (in the other words
121
-   the listed modules must be loaded before this module):
90
+   Table of Contents
91
+
92
+   1. Overview
93
+   2. Dependencies
94
+
95
+        2.1. Kamailio Modules
96
+        2.2. External Libraries or Applications
97
+
98
+   3. Exported Parameters
99
+
100
+        3.1. use_domain (integer)
101
+
102
+   4. Exported Functions
103
+
104
+        4.1. check_user_blacklist (string user, string domain, string
105
+                number, string table)
106
+
107
+        4.2. check_user_whitelist (string user, string domain, string
108
+                number, string table)
109
+
110
+        4.3. check_blacklist (string table)
111
+
112
+   5. MI Commands
113
+
114
+        5.1. reload_blacklist
115
+
116
+   6. Installation and Running
117
+
118
+        6.1. Database setup
119
+
120
+1. Overview
121
+
122
+   The userblacklist module allows Kamailio to handle blacklists on a per
123
+   user basis. This information is stored in a database table, which is
124
+   queried to decide if the number (more exactly, the request URI user) is
125
+   blacklisted or not.
126
+
127
+   An additional functionality that this module provides is the ability to
128
+   handle global blacklists. This lists are loaded on startup into memory,
129
+   thus providing a better performance then in the userblacklist case.
130
+   This global blacklists are useful to only allow calls to certain
131
+   international destinations, i.e. block all not whitelisted numbers.
132
+   They could also used to prevent the blacklisting of important numbers,
133
+   as whitelisting is supported too. This is useful for example to prevent
134
+   the customer from blocking emergency call number or service hotlines.
135
+
136
+   The module exports three functions, check_blacklist
137
+   check_user_blacklist and check_user_whitelist for usage in the config
138
+   file. Furthermore its provide a FIFO function to reload the global
139
+   blacklist cache.
140
+
141
+   Please note that only numerical strings for matching are supported at
142
+   the moment (the used library supports this already, but its not yet
143
+   implemented in the module). Non-digits on the beginning of the matched
144
+   string are skipped, any later non-digits will stop the matching on this
145
+   position.
146
+
147
+2. Dependencies
148
+
149
+   2.1. Kamailio Modules
150
+   2.2. External Libraries or Applications
151
+
152
+2.1. Kamailio Modules
153
+
154
+   The module depends on the following modules (in the other words the
155
+   listed modules must be loaded before this module):
122 156
      * database -- Any database module
123 157
 
124
-1.2.2. External Libraries or Applications
158
+2.2. External Libraries or Applications
125 159
 
126
-   The following libraries or applications must be installed
127
-   before running Kamailio with this module loaded:
160
+   The following libraries or applications must be installed before
161
+   running Kamailio with this module loaded:
128 162
      * none
129 163
 
130
-1.3. Exported Parameters
164
+3. Exported Parameters
131 165
 
132
-1.3.1. use_domain (integer)
166
+   3.1. use_domain (integer)
133 167
 
134
-   If set to non-zero value, the domain column in the
135
-   userblacklist is used.
168
+3.1. use_domain (integer)
169
+
170
+   If set to non-zero value, the domain column in the userblacklist is
171
+   used.
136 172
 
137 173
    Default value is "0".
138 174
 
... ...
@@ -141,19 +177,26 @@ Chapter 1. Admin Guide
141 177
 modparam("userblacklist", "use_domain", 0)
142 178
 ...
143 179
 
144
-1.4. Exported Functions
180
+4. Exported Functions
181
+
182
+   4.1. check_user_blacklist (string user, string domain, string number,
183
+          string table)
145 184
 
146
-1.4.1.  check_user_blacklist (string user, string domain, string
147
-number, string table)
185
+   4.2. check_user_whitelist (string user, string domain, string number,
186
+          string table)
148 187
 
149
-   Finds the longest prefix that matches the request URI user (or
150
-   the number parameter) for the given user and domain name in the
151
-   database. If a match is found and it is not set to whitelist,
152
-   false is returned. Otherwise, true is returned.
153
-   Pseudo-variables or AVPs can be used for the user, domain and
154
-   number parameters. The number and table variables are optional,
155
-   the defaults are used if they are ommited. The number parameter
156
-   can be used to check for example against the from URI user.
188
+   4.3. check_blacklist (string table)
189
+
190
+4.1.  check_user_blacklist (string user, string domain, string number, string
191
+table)
192
+
193
+   Finds the longest prefix that matches the request URI user (or the
194
+   number parameter) for the given user and domain name in the database.
195
+   If a match is found and it is not set to whitelist, false is returned.
196
+   Otherwise, true is returned. Pseudo-variables or AVPs can be used for
197
+   the user, domain and number parameters. The number and table variables
198
+   are optional, the defaults are used if they are ommited. The number
199
+   parameter can be used to check for example against the from URI user.
157 200
 
158 201
    Example 1.2. check_user_blacklist usage
159 202
 ...
... ...
@@ -165,13 +208,34 @@ if (!check_user_blacklist("$avp(i:80)", "$avp(i:82)"))
165 208
 }
166 209
 ...
167 210
 
168
-1.4.2.  check_blacklist (string table)
211
+4.2.  check_user_whitelist (string user, string domain, string number, string
212
+table)
213
+
214
+   Finds the longest prefix that matches the request URI user (or the
215
+   number parameter) for the given user and domain name in the database.
216
+   If a match is found and it is set to whitelist, true is returned.
217
+   Otherwise, false is returned. Pseudo-variables or AVPs can be used for
218
+   the user, domain and number parameters. The number and table variables
219
+   are optional, the defaults are used if they are ommited. The number
220
+   parameter can be used to check for example against the from URI user.
221
+
222
+   Example 1.3. check_user_blacklist usage
223
+...
224
+$avp(i:80) = $rU;
225
+# rewrite the R-URI
226
+if (!check_user_whitelist("$avp(i:80)", "$avp(i:82)"))
227
+        # process request
228
+        exit;
229
+}
230
+...
231
+
232
+4.3.  check_blacklist (string table)
169 233
 
170
-   Finds the longest prefix that matches the request URI for the
171
-   given table. If a match is found and it is not set to
172
-   whitelist, false is returned. Otherwise, true is returned.
234
+   Finds the longest prefix that matches the request URI for the given
235
+   table. If a match is found and it is not set to whitelist, false is
236
+   returned. Otherwise, true is returned.
173 237
 
174
-   Example 1.3. check_blacklist usage
238
+   Example 1.4. check_blacklist usage
175 239
 ...
176 240
 if (!check_blacklist("global_blacklist")))
177 241
         sl_send_reply("403", "Forbidden");
... ...
@@ -179,36 +243,38 @@ if (!check_blacklist("global_blacklist")))
179 243
 }
180 244
 ...
181 245
 
182
-1.5. MI Commands
246
+5. MI Commands
247
+
248
+   5.1. reload_blacklist
183 249
 
184
-1.5.1.  reload_blacklist
250
+5.1.  reload_blacklist
185 251
 
186
-   Reload the internal global blacklist cache. This is necessary
187
-   after the database tables for the global blacklist have been
188
-   changed.
252
+   Reload the internal global blacklist cache. This is necessary after the
253
+   database tables for the global blacklist have been changed.
189 254
 
190
-   Example 1.4. reload_blacklists usage
255
+   Example 1.5. reload_blacklists usage
191 256
 ...
192 257
 kamctl fifo reload_blacklist
193 258
 ...
194 259
 
195
-1.6. Installation and Running
260
+6. Installation and Running
261
+
262
+   6.1. Database setup
196 263
 
197
-1.6.1. Database setup
264
+6.1. Database setup
198 265
 
199
-   Before running Kamailio with userblacklist, you have to setup
200
-   the database table where the module will read the blacklist
201
-   data. For that, if the table was not created by the
202
-   installation script or you choose to install everything by
203
-   yourself you can use the userblacklist-create.sql SQL script in
204
-   the database directories in the kamailio/scripts folder as
205
-   template. Database and table name can be set with module
206
-   parameters so they can be changed, but the name of the columns
207
-   must be as they are in the SQL script. You can also find the
266
+   Before running Kamailio with userblacklist, you have to setup the
267
+   database table where the module will read the blacklist data. For that,
268
+   if the table was not created by the installation script or you choose
269
+   to install everything by yourself you can use the
270
+   userblacklist-create.sql SQL script in the database directories in the
271
+   kamailio/scripts folder as template. Database and table name can be set
272
+   with module parameters so they can be changed, but the name of the
273
+   columns must be as they are in the SQL script. You can also find the
208 274
    complete database documentation on the project webpage,
209 275
    http://www.kamailio.org/docs/db-tables/kamailio-db-devel.html.
210 276
 
211
-   Example 1.5. Example database content - globalblacklist table
277
+   Example 1.6. Example database content - globalblacklist table
212 278
 ...
213 279
 +----+-----------+-----------+
214 280
 | id | prefix    | whitelist |
... ...
@@ -220,12 +286,12 @@ kamctl fifo reload_blacklist
220 286
 +----+-----------+-----------+
221 287
 ...
222 288
 
223
-   This table will setup a global blacklist for all numbers, only
224
-   allowing calls starting with "1". Numbers that starting with
225
-   "123456" and "123455787" are also blacklisted, because the
226
-   longest prefix will be matched.
289
+   This table will setup a global blacklist for all numbers, only allowing
290
+   calls starting with "1". Numbers that starting with "123456" and
291
+   "123455787" are also blacklisted, because the longest prefix will be
292
+   matched.
227 293
 
228
-   Example 1.6. Example database content - userblacklist table
294
+   Example 1.7. Example database content - userblacklist table
229 295
 ...
230 296
 +----+----------------+-------------+-----------+-----------+
231 297
 | id | username       | domain      | prefix    | whitelist |
... ...
@@ -240,28 +306,42 @@ kamctl fifo reload_blacklist
240 306
 +----+----------------+-------------+-----------+-----------+
241 307
 ...
242 308
 
243
-   This table will setup user specific blacklists for certain
244
-   usernames. For example for user "49721123456788" the prefix
245
-   "1234" will be not allowed, but the number "123456788" is
246
-   allowed. Additionally a domain could be specified that is used
247
-   for username matching if the "use_domain" parameter is set.
309
+   This table will setup user specific blacklists for certain usernames.
310
+   For example for user "49721123456788" the prefix "1234" will be not
311
+   allowed, but the number "123456788" is allowed. Additionally a domain
312
+   could be specified that is used for username matching if the
313
+   "use_domain" parameter is set.
248 314
 
249 315
 Chapter 2. Module parameter for database access.
250 316
 
251
-2.1. db_url (String)
317
+   Table of Contents
318
+
319
+   1. db_url (String)
320
+   2. userblacklist_table (String)
321
+   3. userblacklist_id_col (string)
322
+   4. userblacklist_username_col (string)
323
+   5. userblacklist_domain_col (string)
324
+   6. userblacklist_prefix_col (string)
325
+   7. userblacklist_whitelist_col (string)
326
+   8. globalblacklist_table (String)
327
+   9. globalblacklist_id_col (string)
328
+   10. globalblacklist_prefix_col (string)
329
+   11. globalblacklist_whitelist_col (string)
330
+   12. globalblacklist_description_col (string)
331
+
332
+1. db_url (String)
252 333
 
253 334
    URL to the database containing the data.
254 335
 
255
-   Default value is
256
-   "mysql://openserro:openserro@localhost/openser".
336
+   Default value is "mysql://openserro:openserro@localhost/openser".
257 337
 
258 338
    Example 2.1. Set db_url parameter
259 339
 ...
260
-modparam("userblacklist", "db_url", "dbdriver://username:password@dbhost
261
-/dbname")
340
+modparam("userblacklist", "db_url", "dbdriver://username:password@dbhost/dbname"
341
+)
262 342
 ...
263 343
 
264
-2.2. userblacklist_table (String)
344
+2. userblacklist_table (String)
265 345
 
266 346
    Name of the userblacklist table for the userblacklist module.
267 347
 
... ...
@@ -272,7 +352,7 @@ modparam("userblacklist", "db_url", "dbdriver://username:password@dbhost
272 352
 modparam("userblacklist", "userblacklist_table", "userblacklist")
273 353
 ...
274 354
 
275
-2.3. userblacklist_id_col (string)
355
+3. userblacklist_id_col (string)
276 356
 
277 357
    unique ID
278 358
 
... ...
@@ -281,7 +361,7 @@ modparam("userblacklist", "userblacklist_table", "userblacklist")
281 361
 modparam("userblacklist", "userblacklist_id_col", "id")
282 362
 ...
283 363
 
284
-2.4. userblacklist_username_col (string)
364
+4. userblacklist_username_col (string)
285 365
 
286 366
    The user that is used for the blacklist lookup.
287 367
 
... ...
@@ -290,7 +370,7 @@ modparam("userblacklist", "userblacklist_id_col", "id")
290 370
 modparam("userblacklist", "userblacklist_username_col", "username")
291 371
 ...
292 372
 
293
-2.5. userblacklist_domain_col (string)
373
+5. userblacklist_domain_col (string)
294 374
 
295 375
    The domain that is used for the blacklist lookup.
296 376
 
... ...
@@ -299,7 +379,7 @@ modparam("userblacklist", "userblacklist_username_col", "username")
299 379
 modparam("userblacklist", "userblacklist_domain_col", "domain")
300 380
 ...
301 381
 
302
-2.6. userblacklist_prefix_col (string)
382
+6. userblacklist_prefix_col (string)
303 383
 
304 384
    The prefix that is matched for the blacklist.
305 385
 
... ...
@@ -308,7 +388,7 @@ modparam("userblacklist", "userblacklist_domain_col", "domain")
308 388
 modparam("userblacklist", "userblacklist_prefix_col", "prefix")
309 389
 ...
310 390
 
311
-2.7. userblacklist_whitelist_col (string)
391
+7. userblacklist_whitelist_col (string)
312 392
 
313 393
    Specify if this a blacklist (0) or a whitelist (1) entry.
314 394
 
... ...
@@ -317,7 +397,7 @@ modparam("userblacklist", "userblacklist_prefix_col", "prefix")
317 397
 modparam("userblacklist", "userblacklist_whitelist_col", "whitelist")
318 398
 ...
319 399
 
320
-2.8. globalblacklist_table (String)
400
+8. globalblacklist_table (String)
321 401
 
322 402
    Name of the globalblacklist table for the userblacklist module.
323 403
 
... ...
@@ -328,7 +408,7 @@ modparam("userblacklist", "userblacklist_whitelist_col", "whitelist")
328 408
 modparam("userblacklist", "globalblacklist_table", "globalblacklist")
329 409
 ...
330 410
 
331
-2.9. globalblacklist_id_col (string)
411
+9. globalblacklist_id_col (string)
332 412
 
333 413
    unique ID
334 414
 
... ...
@@ -337,7 +417,7 @@ modparam("userblacklist", "globalblacklist_table", "globalblacklist")
337 417
 modparam("userblacklist", "globalblacklist_id_col", "id")
338 418
 ...
339 419
 
340
-2.10. globalblacklist_prefix_col (string)
420
+10. globalblacklist_prefix_col (string)
341 421
 
342 422
    The prefix that is matched for the blacklist.
343 423
 
... ...
@@ -346,7 +426,7 @@ modparam("userblacklist", "globalblacklist_id_col", "id")
346 426
 modparam("userblacklist", "globalblacklist_prefix_col", "prefix")
347 427
 ...
348 428
 
349
-2.11. globalblacklist_whitelist_col (string)
429
+11. globalblacklist_whitelist_col (string)
350 430
 
351 431
    Specify if this a blacklist (0) or a whitelist (1) entry.
352 432
 
... ...
@@ -355,12 +435,11 @@ modparam("userblacklist", "globalblacklist_prefix_col", "prefix")
355 435
 modparam("userblacklist", "globalblacklist_whitelist_col", "whitelist")
356 436
 ...
357 437
 
358
-2.12. globalblacklist_description_col (string)
438
+12. globalblacklist_description_col (string)
359 439
 
360 440
    A comment for the entry.
361 441
 
362 442
    Example 2.12. Set globalblacklist_description_col parameter
363 443
 ...
364
-modparam("userblacklist", "globalblacklist_description_col", "descriptio
365
-n")
444
+modparam("userblacklist", "globalblacklist_description_col", "description")
366 445
 ...
... ...
@@ -30,10 +30,10 @@
30 30
 	hotlines.
31 31
 	</para>
32 32
 	<para>
33
-	The module exports two functions, <emphasis>check_blacklist</emphasis>
34
-	and <emphasis>check_user_blacklist</emphasis> for usage in the config
35
-	file. Furthermore its provide a FIFO function to reload the global
36
-	blacklist cache.
33
+	The module exports three functions, <emphasis>check_blacklist</emphasis>
34
+	<emphasis>check_user_blacklist</emphasis> and <emphasis>check_user_whitelist</emphasis>
35
+	for usage in the config file. Furthermore its provide a FIFO function to
36
+	reload the global blacklist cache.
37 37
 	</para>
38 38
 	<para>
39 39
 	Please note that only numerical strings for matching are supported at the
... ...
@@ -119,6 +119,33 @@ if (!check_user_blacklist("$avp(i:80)", "$avp(i:82)"))
119 119
 	sl_send_reply("403", "Forbidden");
120 120
 	exit;
121 121
 }
122
+...
123
+		</programlisting>
124
+	    </example>
125
+	</section>
126
+	<section>
127
+	    <title>
128
+		<function moreinfo="none">check_user_whitelist (string user, string domain, string number, string table)</function>
129
+	    </title>
130
+	    <para>
131
+		Finds the longest prefix that matches the request URI user (or the number
132
+		parameter) for the given user and domain name in the database.
133
+		If a match is found and it is set to whitelist, true is returned.
134
+		Otherwise, false is returned. Pseudo-variables or AVPs can be used for
135
+		the user, domain and number parameters. The number and table variables
136
+		are optional, the defaults are used if they are ommited. The number
137
+		parameter can be used to check for example against the from URI user.
138
+	    </para>
139
+	<example>
140
+		<title><function>check_user_blacklist</function> usage</title>
141
+		<programlisting format="linespecific">
142
+...
143
+$avp(i:80) = $rU;
144
+# rewrite the R-URI
145
+if (!check_user_whitelist("$avp(i:80)", "$avp(i:82)"))
146
+	# process request
147
+	exit;
148
+}
122 149
 ...
123 150
 		</programlisting>
124 151
 	    </example>
... ...
@@ -81,6 +81,7 @@ static int check_user_blacklist_fixup(void** param, int param_no);
81 81
 
82 82
 /* ---- exported commands: */
83 83
 static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4);
84
+static int check_user_whitelist(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4);
84 85
 static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg1);
85 86
 
86 87
 /* ---- module init functions: */
... ...
@@ -95,8 +96,11 @@ struct mi_root * mi_reload_blacklist(struct mi_root* cmd, void* param);  /* usag
95 96
 
96 97
 static cmd_export_t cmds[]={
97 98
 	{ "check_user_blacklist", (cmd_function)check_user_blacklist, 2, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
99
+	{ "check_user_whitelist", (cmd_function)check_user_whitelist, 2, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
98 100
 	{ "check_user_blacklist", (cmd_function)check_user_blacklist, 3, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
101
+	{ "check_user_whitelist", (cmd_function)check_user_whitelist, 3, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
99 102
 	{ "check_user_blacklist", (cmd_function)check_user_blacklist, 4, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
103
+	{ "check_user_whitelist", (cmd_function)check_user_whitelist, 4, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
100 104
 	{ "check_blacklist", (cmd_function)check_blacklist, 1, check_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
101 105
 	{ 0, 0, 0, 0, 0, 0}
102 106
 };
... ...
@@ -200,7 +204,7 @@ static int check_user_blacklist_fixup(void** param, int param_no)
200 204
 }
201 205
 
202 206
 
203
-static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4)
207
+static int check_user_list(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4, int listtype)
204 208
 {
205 209
 	str user = { .len = 0, .s = NULL };
206 210
 	str domain = { .len = 0, .s = NULL};
... ...
@@ -285,15 +289,32 @@ static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, cha
285 289
 			return 1; /* found, but is whitelisted */
286 290
 		}
287 291
 	} else {
288
-		/* LM_ERR("not found"); */
289
-		return 1; /* not found is ok */
292
+		if(!listtype) {
293
+			/* LM_ERR("not found return 1"); */
294
+			return 1; /* not found is ok */
295
+		} else {
296
+			/* LM_ERR("not found return -1"); */
297
+			return -1; /* not found is not ok */
298
+		}
290 299
 	}
291
-
292 300
 	LM_DBG("entry %s is blacklisted\n", req_number);
293 301
 	return -1;
294 302
 }
295 303
 
296 304
 
305
+static int check_user_whitelist(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4)
306
+{
307
+	return check_user_list(msg, str1, str2, str3, str4, 1);
308
+}
309
+
310
+
311
+static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4)
312
+{
313
+	return check_user_list(msg, str1, str2, str3, str4, 0);
314
+}
315
+
316
+
317
+
297 318
 /**
298 319
  * Finds d-tree root for given table.
299 320
  * \return pointer to d-tree root on success, NULL otherwise