Browse code

- support for dynamic table name

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

Elena-Ramona Modroiu authored on 24/03/2008 19:58:50
Showing 4 changed files
... ...
@@ -173,11 +173,12 @@ modparam("alias_db", "domain_prefix", "sip.")
173 173
 
174 174
    Meaning of the parameters is as follows:
175 175
      * table_name - the name of the table where to search for
176
-       alias.
176
+       alias. It can include pseudo-variables.
177 177
 
178 178
    This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
179 179
 
180 180
    Example 1.8. alias_db_lookup() usage
181 181
 ...
182 182
 alias_db_lookup("dbaliases");
183
+alias_db_lookup("dba_$(rU{s.substr,0,1})");
183 184
 ...
... ...
@@ -35,6 +35,7 @@
35 35
 #include "../../error.h"
36 36
 #include "../../mem/mem.h"
37 37
 #include "../../ut.h"
38
+#include "../../mod_fix.h"
38 39
 
39 40
 #include "alookup.h"
40 41
 
... ...
@@ -67,7 +68,7 @@ db_func_t adbf;  /* DB functions */
67 68
 
68 69
 /* Exported functions */
69 70
 static cmd_export_t cmds[] = {
70
-	{"alias_db_lookup", (cmd_function)alias_db_lookup, 1, 0, 0,
71
+	{"alias_db_lookup", (cmd_function)alias_db_lookup, 1, fixup_spve_null, 0,
71 72
 		REQUEST_ROUTE|FAILURE_ROUTE},
72 73
 	{0, 0, 0, 0, 0, 0}
73 74
 };
... ...
@@ -75,13 +76,13 @@ static cmd_export_t cmds[] = {
75 76
 
76 77
 /* Exported parameters */
77 78
 static param_export_t params[] = {
78
-	{"db_url",           STR_PARAM, &db_url.s        },
79
-	{"user_column",      STR_PARAM, &user_column.s   },
80
-	{"domain_column",    STR_PARAM, &domain_column.s },
81
-	{"alias_user_column",      STR_PARAM, &alias_user_column.s   },
82
-	{"alias_domain_column",    STR_PARAM, &alias_domain_column.s },
83
-	{"use_domain",       INT_PARAM, &use_domain      },
84
-	{"domain_prefix",    STR_PARAM, &domain_prefix.s },
79
+	{"db_url",              STR_PARAM, &db_url.s        },
80
+	{"user_column",         STR_PARAM, &user_column.s   },
81
+	{"domain_column",       STR_PARAM, &domain_column.s },
82
+	{"alias_user_column",   STR_PARAM, &alias_user_column.s   },
83
+	{"alias_domain_column", STR_PARAM, &alias_domain_column.s },
84
+	{"use_domain",          INT_PARAM, &use_domain      },
85
+	{"domain_prefix",       STR_PARAM, &domain_prefix.s },
85 86
 	{0, 0, 0}
86 87
 };
87 88
 
... ...
@@ -34,6 +34,7 @@
34 34
 #include "../../ut.h"
35 35
 #include "../../parser/parse_uri.h"
36 36
 #include "../../db/db.h"
37
+#include "../../mod_fix.h"
37 38
 
38 39
 #include "alias_db.h"
39 40
 #include "alookup.h"
... ...
@@ -75,12 +76,11 @@ int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2)
75 76
 	db_key_t db_cols[] = {&user_column, &domain_column};
76 77
 	db_res_t* db_res = NULL;
77 78
 	
78
-	if(!_table) {
79
-		LM_ERR("invalid parameter");
79
+	if(_table==NULL || fixup_get_svalue(_msg, (gparam_p)_table, &table_s)!=0)
80
+	{
81
+		LM_ERR("invalid table parameter\n");
80 82
 		return -1;
81 83
 	}
82
-	table_s.s = _table;
83
-	table_s.len = strlen(_table);	
84 84
 
85 85
 	if (parse_sip_msg_uri(_msg) < 0)
86 86
 		return -1;
... ...
@@ -99,7 +99,8 @@ int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2)
99 99
 	
100 100
 		if (domain_prefix.s && domain_prefix.len>0
101 101
 			&& domain_prefix.len<_msg->parsed_uri.host.len
102
-			&& strncasecmp(_msg->parsed_uri.host.s,domain_prefix.s,domain_prefix.len)==0)
102
+			&& strncasecmp(_msg->parsed_uri.host.s,domain_prefix.s,
103
+				domain_prefix.len)==0)
103 104
 		{
104 105
 			db_vals[1].val.str_val.s   += domain_prefix.len;
105 106
 			db_vals[1].val.str_val.len -= domain_prefix.len;
... ...
@@ -214,7 +214,7 @@ modparam("alias_db", "domain_prefix", "sip.")
214 214
 		<itemizedlist>
215 215
 		<listitem>
216 216
 			<para><emphasis>table_name</emphasis> - the name of the table
217
-			where to search for alias.
217
+				where to search for alias. It can include pseudo-variables.
218 218
 			</para>
219 219
 		</listitem>
220 220
 		</itemizedlist>
... ...
@@ -226,6 +226,7 @@ modparam("alias_db", "domain_prefix", "sip.")
226 226
 		<programlisting format="linespecific">
227 227
 ...
228 228
 alias_db_lookup("dbaliases");
229
+alias_db_lookup("dba_$(rU{s.substr,0,1})");
229 230
 ...
230 231
 </programlisting>
231 232
 		</example>