Browse Source

modules_k/alias_db: exported alias_db API for use in app_lua

pd 14 năm trước cách đây
mục cha
commit
ac560678f4
3 tập tin đã thay đổi với 32 bổ sung10 xóa
  1. 29 1
      modules_k/alias_db/alias_db.c
  2. 2 8
      modules_k/alias_db/alookup.c
  3. 1 1
      modules_k/alias_db/alookup.h

+ 29 - 1
modules_k/alias_db/alias_db.c

@@ -38,6 +38,7 @@
 #include "../../mod_fix.h"
 
 #include "alookup.h"
+#include "api.h"
 
 MODULE_VERSION
 
@@ -53,6 +54,7 @@ static int child_init(int rank);
 /* Module initialization function prototype */
 static int mod_init(void);
 
+static int w_alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2);
 
 /* Module parameter variables */
 static str db_url       = str_init(DEFAULT_RODB_URL);
@@ -69,8 +71,10 @@ db_func_t adbf;  /* DB functions */
 
 /* Exported functions */
 static cmd_export_t cmds[] = {
-	{"alias_db_lookup", (cmd_function)alias_db_lookup, 1, fixup_spve_null, 0,
+	{"alias_db_lookup", (cmd_function)w_alias_db_lookup, 1, fixup_spve_null, 0,
 		REQUEST_ROUTE|FAILURE_ROUTE},
+	{"bind_alias_db",   (cmd_function)bind_alias_db, 1, 0, 0,
+		0},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -166,3 +170,27 @@ static void destroy(void)
 	}
 }
 
+static int w_alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2)
+{
+        str table_s;
+
+        if(_table==NULL || fixup_get_svalue(_msg, (gparam_p)_table, &table_s)!=0)
+        {
+                LM_ERR("invalid table parameter\n");
+                return -1;
+        }
+
+        return alias_db_lookup(_msg, table_s);
+}
+
+int bind_alias_db(struct alias_db_binds *pxb)
+{
+        if (pxb == NULL)
+        {
+                LM_WARN("bind_alias_db: Cannot load alias_db API into a NULL pointer\n");
+                return -1;
+        }
+
+        pxb->alias_db_lookup = alias_db_lookup;
+        return 0;
+}

+ 2 - 8
modules_k/alias_db/alookup.c

@@ -70,20 +70,14 @@ static inline int rewrite_ruri(struct sip_msg* _m, char* _s)
 /**
  *
  */
-int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2)
+int alias_db_lookup(struct sip_msg* _msg, str table_s)
 {
-	str user_s, table_s;
+	str user_s;
 	db_key_t db_keys[2] = {&alias_user_column, &alias_domain_column};
 	db_val_t db_vals[2];
 	db_key_t db_cols[] = {&user_column, &domain_column};
 	db1_res_t* db_res = NULL;
 	int i;
-	
-	if(_table==NULL || fixup_get_svalue(_msg, (gparam_p)_table, &table_s)!=0)
-	{
-		LM_ERR("invalid table parameter\n");
-		return -1;
-	}
 
 	if (parse_sip_msg_uri(_msg) < 0)
 		return -1;

+ 1 - 1
modules_k/alias_db/alookup.h

@@ -32,6 +32,6 @@
 
 #include "../../parser/msg_parser.h"
 
-int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2);
+int alias_db_lookup(struct sip_msg* _msg, str _table);
 
 #endif /* _ALOOKUP_H_ */