[sr-dev] git:master: modules_k/userblacklist : check_blacklist function uses globalblacklist_table as data source if no parameter is given .

Marius Zbihlei marius.zbihlei at 1and1.ro
Fri Mar 5 15:35:26 CET 2010


Module: sip-router
Branch: master
Commit: 9858546ec00532afa6aea36a5a770cb6a9255bf7
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9858546ec00532afa6aea36a5a770cb6a9255bf7

Author: Marius Zbihlei <marius.zbihlei at 1and1.ro>
Committer: Marius Zbihlei <marius.zbihlei at 1and1.ro>
Date:   Fri Mar  5 16:32:49 2010 +0200

modules_k/userblacklist : check_blacklist function uses globalblacklist_table as data source if no parameter is given.

Globalblacklist_table parameter was not used at all in the userblacklist module, the check_blacklist funtion always needing
one parameters and the db table. This is not mandatory anymore, as the check_blacklist function with no parameters will use
the globalblacklist_table

---

 modules_k/userblacklist/README                     |   35 +++++++------
 .../userblacklist/doc/userblacklist_admin.xml      |    5 +-
 modules_k/userblacklist/doc/userblacklist_db.xml   |    3 +-
 modules_k/userblacklist/userblacklist.c            |   52 ++++++++++++++++++--
 4 files changed, 69 insertions(+), 26 deletions(-)

diff --git a/modules_k/userblacklist/README b/modules_k/userblacklist/README
index 5e0c242..3627c5c 100644
--- a/modules_k/userblacklist/README
+++ b/modules_k/userblacklist/README
@@ -11,7 +11,7 @@ Henning Westerholt
    1&1 Internet AG
    <henning.westerholt at 1und1.de>
 
-   Copyright © 2008 1&1 Internet AG
+   Copyright © 2008 1&1 Internet AG
    Revision History
    Revision $Revision$ $Date$
      __________________________________________________________________
@@ -38,7 +38,7 @@ Henning Westerholt
               4.2. check_user_whitelist (string user, string domain,
                       string number, string table)
 
-              4.3. check_blacklist (string table)
+              4.3. check_blacklist ([string table])
 
         5. MI Commands
 
@@ -107,7 +107,7 @@ Chapter 1. Admin Guide
         4.2. check_user_whitelist (string user, string domain, string
                 number, string table)
 
-        4.3. check_blacklist (string table)
+        4.3. check_blacklist ([string table])
 
    5. MI Commands
 
@@ -170,7 +170,7 @@ Chapter 1. Admin Guide
    If set to non-zero value, the domain column in the userblacklist is
    used.
 
-   Default value is "0".
+   Default value is “0”.
 
    Example 1.1. Set use_domain parameter
 ...
@@ -185,7 +185,7 @@ modparam("userblacklist", "use_domain", 0)
    4.2. check_user_whitelist (string user, string domain, string number,
           string table)
 
-   4.3. check_blacklist (string table)
+   4.3. check_blacklist ([string table])
 
 4.1.  check_user_blacklist (string user, string domain, string number, string
 table)
@@ -229,11 +229,12 @@ if (!check_user_whitelist("$avp(i:80)", "$avp(i:82)"))
 }
 ...
 
-4.3.  check_blacklist (string table)
+4.3.  check_blacklist ([string table])
 
    Finds the longest prefix that matches the request URI for the given
    table. If a match is found and it is not set to whitelist, false is
-   returned. Otherwise, true is returned.
+   returned. Otherwise, true is returned. If no table is given, then
+   globalblacklist_table is used.
 
    Example 1.4. check_blacklist usage
 ...
@@ -287,8 +288,8 @@ kamctl fifo reload_blacklist
 ...
 
    This table will setup a global blacklist for all numbers, only allowing
-   calls starting with "1". Numbers that starting with "123456" and
-   "123455787" are also blacklisted, because the longest prefix will be
+   calls starting with “1”. Numbers that starting with “123456” and
+   “123455787” are also blacklisted, because the longest prefix will be
    matched.
 
    Example 1.7. Example database content - userblacklist table
@@ -307,10 +308,10 @@ kamctl fifo reload_blacklist
 ...
 
    This table will setup user specific blacklists for certain usernames.
-   For example for user "49721123456788" the prefix "1234" will be not
-   allowed, but the number "123456788" is allowed. Additionally a domain
+   For example for user “49721123456788” the prefix “1234” will be not
+   allowed, but the number “123456788” is allowed. Additionally a domain
    could be specified that is used for username matching if the
-   "use_domain" parameter is set.
+   “use_domain” parameter is set.
 
 Chapter 2. Module parameter for database access.
 
@@ -333,7 +334,7 @@ Chapter 2. Module parameter for database access.
 
    URL to the database containing the data.
 
-   Default value is "mysql://openserro:openserro@localhost/openser".
+   Default value is “mysql://openserro:openserro@localhost/openser”.
 
    Example 2.1. Set db_url parameter
 ...
@@ -345,7 +346,7 @@ modparam("userblacklist", "db_url", "dbdriver://username:password@dbhost/dbname"
 
    Name of the userblacklist table for the userblacklist module.
 
-   Default value is "userblacklist".
+   Default value is “userblacklist”.
 
    Example 2.2. Set userblacklist_table parameter
 ...
@@ -400,10 +401,10 @@ modparam("userblacklist", "userblacklist_whitelist_col", "whitelist")
 8. globalblacklist_table (String)
 
    Name of the globalblacklist table for the userblacklist module. Please
-   not that this table is currently ignored, the table needs to be given
-   as a parameter for the check_blacklist function.
+   note that this table is used when the check_blacklist function is
+   called with no parameters.
 
-   Default value is "globalblacklist".
+   Default value is “globalblacklist”.
 
    Example 2.8. Set globalblacklist_table parameter
 ...
diff --git a/modules_k/userblacklist/doc/userblacklist_admin.xml b/modules_k/userblacklist/doc/userblacklist_admin.xml
index a438741..367d298 100644
--- a/modules_k/userblacklist/doc/userblacklist_admin.xml
+++ b/modules_k/userblacklist/doc/userblacklist_admin.xml
@@ -152,12 +152,13 @@ if (!check_user_whitelist("$avp(i:80)", "$avp(i:82)"))
 	</section>
 	<section>
 	    <title>
-		<function moreinfo="none">check_blacklist (string table)</function>
+		<function moreinfo="none">check_blacklist ([string table])</function>
 	    </title>
 	    <para>
 		Finds the longest prefix that matches the request URI for the
 		given table. If a match is found and it is not set to whitelist,
-		false is returned. Otherwise, true is returned.
+		false is returned. Otherwise, true is returned. If no table is given, 
+		then globalblacklist_table is used.
 	    </para>
 	<example>
 		<title><function>check_blacklist</function> usage</title>
diff --git a/modules_k/userblacklist/doc/userblacklist_db.xml b/modules_k/userblacklist/doc/userblacklist_db.xml
index 5e8df9c..8739cbb 100644
--- a/modules_k/userblacklist/doc/userblacklist_db.xml
+++ b/modules_k/userblacklist/doc/userblacklist_db.xml
@@ -112,8 +112,7 @@ modparam("userblacklist", "userblacklist_whitelist_col", "whitelist")
   <section>
     <title><varname>globalblacklist_table</varname> (String)</title>
     <para>Name of the globalblacklist table for the userblacklist module.
-    Please not that this table is currently ignored, the table needs to be
-    given as a parameter for the check_blacklist function.</para>
+    Please note that this table is used when the check_blacklist function is called with no parameters.</para>
     <para>
       <emphasis>Default value is <quote>globalblacklist</quote>.</emphasis>
     </para>
diff --git a/modules_k/userblacklist/userblacklist.c b/modules_k/userblacklist/userblacklist.c
index 57b2b84..51cb4db 100644
--- a/modules_k/userblacklist/userblacklist.c
+++ b/modules_k/userblacklist/userblacklist.c
@@ -74,10 +74,12 @@ struct check_blacklist_fs_t {
 
 str userblacklist_db_url = str_init(DEFAULT_RODB_URL);
 static int use_domain   = 0;
+static struct dtrie_node_t *gnode = NULL;
 
 /* ---- fixup functions: */
 static int check_blacklist_fixup(void** param, int param_no);
 static int check_user_blacklist_fixup(void** param, int param_no);
+static int check_globalblacklist_fixup(void** param, int param_no);
 
 /* ---- exported commands: */
 static int check_user_blacklist(struct sip_msg *msg, char* str1, char* str2, char* str3, char* str4);
@@ -87,6 +89,8 @@ static int check_user_whitelist2(struct sip_msg *msg, char* str1, char* str2);
 static int check_user_blacklist3(struct sip_msg *msg, char* str1, char* str2, char* str3);
 static int check_user_whitelist3(struct sip_msg *msg, char* str1, char* str2, char* str3);
 static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg1);
+static int check_globalblacklist(struct sip_msg *msg);
+
 
 /* ---- module init functions: */
 static int mod_init(void);
@@ -106,6 +110,7 @@ static cmd_export_t cmds[]={
 	{ "check_user_blacklist", (cmd_function)check_user_blacklist, 4, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
 	{ "check_user_whitelist", (cmd_function)check_user_whitelist, 4, check_user_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
 	{ "check_blacklist", (cmd_function)check_blacklist, 1, check_blacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
+	{ "check_blacklist", (cmd_function)check_globalblacklist, 0, check_globalblacklist_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
 	{ 0, 0, 0, 0, 0, 0}
 };
 
@@ -401,6 +406,48 @@ static int add_source(const char *table)
 }
 
 
+static int check_globalblacklist_fixup(void** param, int param_no)
+{
+	char * table = globalblacklist_table.s;
+	if(param_no > 0){
+		LM_ERR("Wrong number of parameters\n");
+		return -1;
+	}
+
+	if (!table) {
+		LM_ERR("no table name\n");
+		return -1;
+	}
+	/* try to add the table */
+	if (add_source(table) != 0) {
+		LM_ERR("could not add table");
+		return -1;
+	}
+
+	gnode = table2dt(table);
+	if (!gnode) {
+		LM_ERR("invalid table '%s'\n", table);
+		return -1;
+	}
+
+	return 0;
+}
+
+static int check_globalblacklist(struct sip_msg* msg)
+{
+	static struct check_blacklist_fs_t* arg = NULL;
+	if(!arg){
+		arg = pkg_malloc(sizeof(struct check_blacklist_fs_t));
+		if (!arg) {
+			PKG_MEM_ERROR;
+			return -1;
+		}
+		memset(arg, 0, sizeof(struct check_blacklist_fs_t));
+		arg->dtrie_root = gnode;
+	}
+	return check_blacklist(msg, arg);
+}
+
 static int check_blacklist_fixup(void **arg, int arg_no)
 {
 	char *table = (char *)(*arg);
@@ -454,11 +501,6 @@ static int check_blacklist(struct sip_msg *msg, struct check_blacklist_fs_t *arg
 		return -1;
 	}
 
-	if (parse_sip_msg_uri(msg) < 0) {
-		LM_ERR("cannot parse msg URI\n");
-		return -1;
-	}
-
 	if ((parse_sip_msg_uri(msg) < 0) || (!msg->parsed_uri.user.s) || (msg->parsed_uri.user.len > MAXNUMBERLEN)) {
 		LM_ERR("cannot parse msg URI\n");
 		return -1;




More information about the sr-dev mailing list