Browse Source

- refactor uri_db module somewhat
- combine uri and subscriber colums parameter, its not possible to use both of
them the same time because of the use_uri_table parameter
- remove subscriber and uri table, use db_table like almost any other module


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3883 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 years ago
parent
commit
867be7a851

+ 41 - 81
modules_k/uri_db/README

@@ -27,15 +27,12 @@ Bogdan-Andrei Iancu
         1.3. Exported Parameters
 
               1.3.1. db_url (string)
-              1.3.2. uri_table (string)
-              1.3.3. uri_user_column (string)
-              1.3.4. uri_domain_column (string)
-              1.3.5. uri_uriuser_column (string)
-              1.3.6. subscriber_table (string)
-              1.3.7. subscriber_user_column (string)
-              1.3.8. subscriber_domain_column (string)
-              1.3.9. use_uri_table (integer)
-              1.3.10. use_domain (integer)
+              1.3.2. db_table (string)
+              1.3.3. user_column (string)
+              1.3.4. domain_column (string)
+              1.3.5. uriuser_column (string)
+              1.3.6. use_uri_table (integer)
+              1.3.7. use_domain (integer)
 
         1.4. Exported Functions
 
@@ -45,18 +42,15 @@ Bogdan-Andrei Iancu
 
    List of Examples
    1-1. Set db_url parameter
-   1-2. Set uri_table parameter
-   1-3. Set uri_user_column parameter
-   1-4. Set uri_domain_column parameter
-   1-5. Set uri_uriuser_column parameter
-   1-6. Set subscriber_table parameter
-   1-7. Set subscriber_user_column parameter
-   1-8. Set subscriber_domain_column parameter
-   1-9. Set use_uri_table parameter
-   1-10. Set use_domain parameter
-   1-11. check_to usage
-   1-12. check_from usage
-   1-13. does_uri_exist usage
+   1-2. Set db_table parameter
+   1-3. Set user_column parameter
+   1-4. Set domain_column parameter
+   1-5. Set uriuser_column parameter
+   1-6. Set use_uri_table parameter
+   1-7. Set use_domain parameter
+   1-8. check_to usage
+   1-9. check_from usage
+   1-10. does_uri_exist usage
      __________________________________________________________
 
 Chapter 1. User's Guide
@@ -101,104 +95,70 @@ r")
 ...
      __________________________________________________________
 
-1.3.2. uri_table (string)
+1.3.2. db_table (string)
 
-   Table containing list of allowed URIs for each user.
+   The dbtable that should be used. Its possible to use the
+   "subscriber" and "uri" table.
 
-   Default value is "uri".
+   Default value is "subscriber".
 
-   Example 1-2. Set uri_table parameter
+   Example 1-2. Set db_table parameter
 ...
-modparam("uri_db", "uri_table", "uri")
+modparam("uri_db", "db_table", "susbscriber")
 ...
      __________________________________________________________
 
-1.3.3. uri_user_column (string)
+1.3.3. user_column (string)
 
-   Column holding usernames in the URI table.
+   Column holding usernames in the table.
 
    Default value is "username".
 
-   Example 1-3. Set uri_user_column parameter
+   Example 1-3. Set user_column parameter
 ...
-modparam("uri_db", "uri_user_column", "username")
+modparam("uri_db", "user_column", "username")
 ...
      __________________________________________________________
 
-1.3.4. uri_domain_column (string)
+1.3.4. domain_column (string)
 
-   Column holding domain in the URI table.
+   Column holding domain in the table.
 
    Default value is "domain".
 
-   Example 1-4. Set uri_domain_column parameter
+   Example 1-4. Set domain_column parameter
 ...
-modparam("uri_db", "uri_domain_column", "domain")
+modparam("uri_db", "domain_column", "domain")
 ...
      __________________________________________________________
 
-1.3.5. uri_uriuser_column (string)
+1.3.5. uriuser_column (string)
 
-   Column holding URI username in the URI table.
+   Column holding URI username in the table. This colum is only
+   available in the uri table.
 
    Default value is "uri_user".
 
-   Example 1-5. Set uri_uriuser_column parameter
-...
-modparam("uri_db", "uri_uriuser_column", "uri_user")
-...
-     __________________________________________________________
-
-1.3.6. subscriber_table (string)
-
-   Name of the subscriber table.
-
-   Default value is "subscriber".
-
-   Example 1-6. Set subscriber_table parameter
-...
-modparam("uri_db", "subscriber_table", "subscriber")
-...
-     __________________________________________________________
-
-1.3.7. subscriber_user_column (string)
-
-   Column holding username in subscriber table.
-
-   Default value is "username".
-
-   Example 1-7. Set subscriber_user_column parameter
-...
-modparam("uri_db", "subscriber_user_column", "username")
-...
-     __________________________________________________________
-
-1.3.8. subscriber_domain_column (string)
-
-   Column holding domains in the subscriber table.
-
-   Default value is "domain".
-
-   Example 1-8. Set subscriber_domain_column parameter
+   Example 1-5. Set uriuser_column parameter
 ...
-modparam("uri_db", "subscriber_domain_column", "domain")
+modparam("uri_db", "uriuser_column", "uri_user")
 ...
      __________________________________________________________
 
-1.3.9. use_uri_table (integer)
+1.3.6. use_uri_table (integer)
 
    Specify if the "uri" table should be used for checkings instead
    of "subscriber" table. A non-zero value means true.
 
    Default value is "0 (false)".
 
-   Example 1-9. Set use_uri_table parameter
+   Example 1-6. Set use_uri_table parameter
 ...
 modparam("uri_db", "use_uri_table", 1)
 ...
      __________________________________________________________
 
-1.3.10. use_domain (integer)
+1.3.7. use_domain (integer)
 
    Specify if the domain part of the URI should be used to
    identify the users (along with username). This is useful in
@@ -210,7 +170,7 @@ modparam("uri_db", "use_uri_table", 1)
 
    Default value is "0 (false)".
 
-   Example 1-10. Set use_domain parameter
+   Example 1-7. Set use_domain parameter
 ...
 modparam("uri_db", "use_domain", 1)
 ...
@@ -225,7 +185,7 @@ modparam("uri_db", "use_domain", 1)
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1-11. check_to usage
+   Example 1-8. check_to usage
 ...
 if (check_to()) {
         ...
@@ -240,7 +200,7 @@ if (check_to()) {
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1-12. check_from usage
+   Example 1-9. check_from usage
 ...
 if (check_from()) {
         ...
@@ -258,7 +218,7 @@ if (check_from()) {
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1-13. does_uri_exist usage
+   Example 1-10. does_uri_exist usage
 ...
 if (does_uri_exist()) {
         ...

+ 13 - 13
modules_k/uri_db/checks.c

@@ -88,15 +88,15 @@ static inline int check_username(struct sip_msg* _m, struct sip_uri *_uri)
 	 * (which are different from digest username and it will still match)
 	 */
 	if (use_uri_table) {
-		if (uridb_dbf.use_table(db_handle, &uri_table) < 0) {
+		if (uridb_dbf.use_table(db_handle, &db_table) < 0) {
 			LM_ERR("Error while trying to use uri table\n");
 			return -7;
 		}
 
-		keys[0] = &uri_user_col;
-		keys[1] = &uri_domain_col;
-		keys[2] = &uri_uriuser_col;
-		cols[0] = &uri_user_col;
+		keys[0] = &uridb_user_col;
+		keys[1] = &uridb_domain_col;
+		keys[2] = &uridb_uriuser_col;
+		cols[0] = &uridb_user_col;
 
 		VAL_TYPE(vals) = VAL_TYPE(vals + 1) = VAL_TYPE(vals + 2) = DB_STR;
 		VAL_NULL(vals) = VAL_NULL(vals + 1) = VAL_NULL(vals + 2) = 0;
@@ -196,21 +196,21 @@ int does_uri_exist(struct sip_msg* _msg, char* _s1, char* _s2)
 	}
 
 	if (use_uri_table) {
-		if (uridb_dbf.use_table(db_handle, &uri_table) < 0) {
+		if (uridb_dbf.use_table(db_handle, &db_table) < 0) {
 			LM_ERR("Error while trying to use uri table\n");
 			return -2;
 		}
-		keys[0] = &uri_uriuser_col;
-		keys[1] = &uri_domain_col;
-		cols[0] = &uri_uriuser_col;
+		keys[0] = &uridb_uriuser_col;
+		keys[1] = &uridb_domain_col;
+		cols[0] = &uridb_uriuser_col;
 	} else {
-		if (uridb_dbf.use_table(db_handle, &subscriber_table) < 0) {
+		if (uridb_dbf.use_table(db_handle, &db_table) < 0) {
 			LM_ERR("Error while trying to use subscriber table\n");
 			return -3;
 		}
-		keys[0] = &subscriber_user_col;
-		keys[1] = &subscriber_domain_col;
-		cols[0] = &subscriber_user_col;
+		keys[0] = &uridb_user_col;
+		keys[1] = &uridb_domain_col;
+		cols[0] = &uridb_user_col;
 	}
 
 	VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;

+ 20 - 78
modules_k/uri_db/doc/uri_db_user.sgml

@@ -66,29 +66,30 @@ modparam("uri_db", "db_url", "mysql://username:password@localhost/openser")
 	</section>
 
 	<section>
-		<title><varname>uri_table</varname> (string)</title>
+		<title><varname>db_table</varname> (string)</title>
 		<para>
-		Table containing list of allowed &uri;s for each user.
+		The dbtable that should be used. Its possible to use the
+		<quote>subscriber</quote> and <quote>uri</quote> table.
 		</para>
 		<para>
 		<emphasis>
-			Default value is <quote>uri</quote>.
+			Default value is <quote>subscriber</quote>.
 		</emphasis>
 		</para>
 		<example>
-		<title>Set <varname>uri_table</varname> parameter</title>
+		<title>Set <varname>db_table</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("uri_db", "uri_table", "uri")
+modparam("uri_db", "db_table", "susbscriber")
 ...
 </programlisting>
 		</example>
 	</section>
 
 	<section>
-		<title><varname>uri_user_column</varname> (string)</title>
+		<title><varname>user_column</varname> (string)</title>
 		<para>
-		Column holding usernames in the &uri; table.
+		Column holding usernames in the table.
 		</para>
 		<para>
 		<emphasis>
@@ -96,19 +97,19 @@ modparam("uri_db", "uri_table", "uri")
 		</emphasis>
 		</para>
 		<example>
-		<title>Set <varname>uri_user_column</varname> parameter</title>
+		<title>Set <varname>user_column</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("uri_db", "uri_user_column", "username")
+modparam("uri_db", "user_column", "username")
 ...
 </programlisting>
 		</example>
 	</section>
 
 	<section>
-		<title><varname>uri_domain_column</varname> (string)</title>
+		<title><varname>domain_column</varname> (string)</title>
 		<para>
-		Column holding domain in the &uri; table.
+		Column holding domain in the table.
 		</para>
 		<para>
 		<emphasis>
@@ -116,19 +117,20 @@ modparam("uri_db", "uri_user_column", "username")
 		</emphasis>
 		</para>
 		<example>
-		<title>Set <varname>uri_domain_column</varname> parameter</title>
+		<title>Set <varname>domain_column</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("uri_db", "uri_domain_column", "domain")
+modparam("uri_db", "domain_column", "domain")
 ...
 </programlisting>
 		</example>
 	</section>
 
 	<section>
-		<title><varname>uri_uriuser_column</varname> (string)</title>
+		<title><varname>uriuser_column</varname> (string)</title>
 		<para>
-		Column holding &uri; username in the &uri; table.
+		Column holding &uri; username in the table. This colum is only
+		available in the uri table.
 		</para>
 		<para>
 		<emphasis>
@@ -136,75 +138,15 @@ modparam("uri_db", "uri_domain_column", "domain")
 		</emphasis>
 		</para>
 		<example>
-		<title>Set <varname>uri_uriuser_column</varname> parameter</title>
-		<programlisting format="linespecific">
-...
-modparam("uri_db", "uri_uriuser_column", "uri_user")
-...
-</programlisting>
-		</example>
-	</section>
-
-	<section>
-		<title><varname>subscriber_table</varname> (string)</title>
-		<para>
-		Name of the subscriber table.
-		</para>
-		<para>
-		<emphasis>
-			Default value is <quote>subscriber</quote>.
-		</emphasis>
-		</para>
-		<example>
-		<title>Set <varname>subscriber_table</varname> parameter</title>
+		<title>Set <varname>uriuser_column</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
-modparam("uri_db", "subscriber_table", "subscriber")
+modparam("uri_db", "uriuser_column", "uri_user")
 ...
 </programlisting>
 		</example>
 	</section>
-
-	<section>
-		<title><varname>subscriber_user_column</varname> (string)</title>
-		<para>
-		Column holding username in subscriber table.
-		</para>
-		<para>
-		<emphasis>
-			Default value is <quote>username</quote>.
-		</emphasis>
-		</para>
-		<example>
-		<title>Set <varname>subscriber_user_column</varname> parameter</title>
-		<programlisting format="linespecific">
-...
-modparam("uri_db", "subscriber_user_column", "username")
-...
-</programlisting>
-		</example>
-	</section>
-
-	<section>
-		<title><varname>subscriber_domain_column</varname> (string)</title>
-		<para>
-		Column holding domains in the subscriber table.
-		</para>
-		<para>
-		<emphasis>
-			Default value is <quote>domain</quote>.
-		</emphasis>
-		</para>
-		<example>
-		<title>Set <varname>subscriber_domain_column</varname> parameter</title>
-		<programlisting format="linespecific">
-...
-modparam("uri_db", "subscriber_domain_column", "domain")
-...
-</programlisting>
-		</example>
-	</section>
-
+	
 	<section>
 		<title><varname>use_uri_table</varname> (integer)</title>
 		<para>

+ 24 - 38
modules_k/uri_db/uridb_mod.c

@@ -78,32 +78,24 @@ static int mod_init(void);       /* Module initialization function */
  * Module parameter variables
  */
 static str db_url         = {DEFAULT_RODB_URL, DEFAULT_RODB_URL_LEN};
-/* Name of URI table */
-str uri_table             = {URI_TABLE, URI_TABLE_LEN};
-/* Name of username column in URI table */
-str uri_user_col          = {USER_COL, USER_COL_LEN};
-/* Name of domain column in URI table */
-str uri_domain_col        = {DOMAIN_COL, DOMAIN_COL_LEN};
-/* Name of uri_user column in URI table */
-str uri_uriuser_col       = {URI_USER_COL, URI_USER_COL_LEN};
-/* Name of subscriber table */
+str db_table              = {SUBSCRIBER_TABLE, SUBSCRIBER_TABLE_LEN};
+str uridb_user_col        = {USER_COL, USER_COL_LEN};
+str uridb_domain_col      = {DOMAIN_COL, DOMAIN_COL_LEN};
+str uridb_uriuser_col     = {URI_USER_COL, URI_USER_COL_LEN};
 str subscriber_table      = {SUBSCRIBER_TABLE, SUBSCRIBER_TABLE_LEN};
-/* Name of user column in subscriber table */
-str subscriber_user_col   = {USER_COL, USER_COL_LEN};
-/* Name of domain column in subscriber table */
-str subscriber_domain_col = {DOMAIN_COL, DOMAIN_COL_LEN};
 
 int use_uri_table = 0;     /* Should uri table be used */
 int use_domain = 0;        /* Should does_uri_exist honor the domain part ? */
 
 static int fixup_exist(void** param, int param_no);
+
 /*
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"check_to",       (cmd_function)check_to,       0, 0, 0,           REQUEST_ROUTE},
-	{"check_from",     (cmd_function)check_from,     0, 0, 0,           REQUEST_ROUTE},
-	{"does_uri_exist", (cmd_function)does_uri_exist, 0, fixup_exist, 0, REQUEST_ROUTE},
+	{"check_to",       (cmd_function)check_to,       0, 0, 0, REQUEST_ROUTE},
+	{"check_from",     (cmd_function)check_from,     0, 0, 0, REQUEST_ROUTE},
+	{"does_uri_exist", (cmd_function)does_uri_exist, 0, 0, fixup_exist, REQUEST_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -113,13 +105,10 @@ static cmd_export_t cmds[] = {
  */
 static param_export_t params[] = {
 	{"db_url",                   STR_PARAM, &db_url.s               },
-	{"uri_table",                STR_PARAM, &uri_table.s            },
-	{"uri_user_column",          STR_PARAM, &uri_user_col.s         },
-	{"uri_domain_column",        STR_PARAM, &uri_domain_col.s       },
-	{"uri_uriuser_column",       STR_PARAM, &uri_uriuser_col.s      },
-	{"subscriber_table",         STR_PARAM, &subscriber_table.s     },
-	{"subscriber_user_column",   STR_PARAM, &subscriber_user_col.s  },
-	{"subscriber_domain_column", STR_PARAM, &subscriber_domain_col.s},
+	{"db_table",                 STR_PARAM, &db_table.s             },
+	{"user_column",              STR_PARAM, &uridb_user_col.s       },
+	{"domain_column",            STR_PARAM, &uridb_domain_col.s     },
+	{"uriuser_column",           STR_PARAM, &uridb_uriuser_col.s    },
 	{"use_uri_table",            INT_PARAM, &use_uri_table          },
 	{"use_domain",               INT_PARAM, &use_domain             },
 	{0, 0, 0}
@@ -145,7 +134,7 @@ struct module_exports exports = {
 };
 
 
-/*
+/**
  * Module initialization function callee in each child separately
  */
 static int child_init(int rank)
@@ -157,7 +146,7 @@ static int child_init(int rank)
 }
 
 
-/*
+/**
  * Module initialization function that is called before the main process forks
  */
 static int mod_init(void)
@@ -167,22 +156,19 @@ static int mod_init(void)
 	LM_DBG("uri_db - initializing\n");
 
 	db_url.len = strlen(db_url.s);
-	if (db_url.len == 0 ) {
+	if (db_url.len == 0) {
 		if (use_uri_table) {
-            LM_ERR("configuration error - no database URL, "
-                   "but use_uri_table is set!\n");
+			LM_ERR("configuration error - no database URL, "
+				"but use_uri_table is set!\n");
 			goto error;
 		}
 		return 0;
 	}
 
-	uri_table.len = strlen(uri_table.s);
-	uri_user_col.len = strlen(uri_user_col.s);
-	uri_domain_col.len = strlen(uri_domain_col.s);
-	uri_uriuser_col.len = strlen(uri_uriuser_col.s);
-	subscriber_table.len = strlen(subscriber_table.s);
-	subscriber_user_col.len = strlen(subscriber_user_col.s);
-	subscriber_domain_col.len = strlen(subscriber_domain_col.s);
+	db_table.len = strlen(db_table.s);
+	uridb_user_col.len = strlen(uridb_user_col.s);
+	uridb_domain_col.len = strlen(uridb_domain_col.s);
+	uridb_uriuser_col.len = strlen(uridb_uriuser_col.s);
 
 	if (uridb_db_bind(&db_url)) {
 		LM_ERR("No database module found\n");
@@ -191,7 +177,7 @@ static int mod_init(void)
 
 	if (use_uri_table) {
 		/* Check table version */
-		ver = uridb_db_ver(&db_url, &uri_table);
+		ver = uridb_db_ver(&db_url, &db_table);
 		if (ver < 0) {
 			LM_ERR("Error while querying table version\n");
 			goto error;
@@ -201,7 +187,7 @@ static int mod_init(void)
 		}
 	} else {
 		/* Check table version */
-		ver = uridb_db_ver(&db_url, &subscriber_table);
+		ver = uridb_db_ver(&db_url, &db_table);
 		if (ver < 0) {
 			LM_ERR("Error while querying table version\n");
 			goto error;
@@ -226,7 +212,7 @@ static void destroy(void)
 static int fixup_exist(void** param, int param_no)
 {
 	if (db_url.len == 0) {
-        LM_ERR("configuration error - does_uri_exist() called with no database URL!\n");
+		LM_ERR("configuration error - does_uri_exist() called with no database URL!\n");
 		return E_CFG;
 	}
 	return 0;

+ 6 - 9
modules_k/uri_db/uridb_mod.h

@@ -36,14 +36,11 @@
 /*
  * Module parameters variables
  */
-extern str uri_table;                 /* Name of URI table */
-extern str uri_user_col;              /* Name of username column in URI table */
-extern str uri_domain_col;            /* Name of domain column in URI table */
-extern str uri_uriuser_col;           /* Name of uri_user column in URI table */
-extern str subscriber_table;          /* Name of subscriber table */
-extern str subscriber_user_col;       /* Name of user column in subscriber table */
-extern str subscriber_domain_col;     /* Name of domain column in subscriber table */
-extern int use_uri_table;             /* Whether or not should be uri table used */
-extern int use_domain;                /* Should does_uri_exist honor the domain part ? */
+extern str db_table;                  /**< Name of URI table */
+extern str uridb_user_col;            /**< Name of username column in URI table */
+extern str uridb_domain_col;          /**< Name of domain column in URI table */
+extern str uridb_uriuser_col;         /**< Name of uri_user column in URI table */
+extern int use_uri_table;             /**< Whether or not should be uri table used */
+extern int use_domain;                /**< Should does_uri_exist honor the domain part ? */
 
 #endif /* URI_MOD_H */