]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-4883 --resolve I can add this but if it leads to issues in the loaded code we...
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 29 Nov 2012 14:58:44 +0000 (08:58 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 29 Nov 2012 14:58:44 +0000 (08:58 -0600)
src/include/switch_core.h
src/include/switch_core_db.h
src/mod/languages/mod_lua/freeswitch.i
src/mod/languages/mod_lua/freeswitch_lua.cpp
src/mod/languages/mod_lua/freeswitch_lua.h
src/mod/languages/mod_lua/mod_lua_wrap.cpp
src/mod/languages/mod_managed/freeswitch_wrap.cxx
src/mod/languages/mod_managed/managed/swig.cs
src/switch_core_db.c
src/switch_core_sqldb.c

index 7b164af20a2829f6e8edbe0ebc6f2972140ad8be..68e592b9dfe65cfd7a826434321d71fcc0c28d46 100644 (file)
@@ -2360,6 +2360,13 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cach
 */
 SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh);
 
+/*!
+ \brief load an external extension to db
+ \param [in] dbh The handle
+ \param [out] the path to the extension
+*/
+SWITCH_DECLARE(int) switch_cache_db_load_extension(switch_cache_db_handle_t *dbh, const char *extension);
+
 /*! 
  \brief Provides some feedback as to the status of the db connection pool
  \param [in] stream stream for status
index e5fbf76a951220a0f8dac13ea546eba482a76933..002a6ec7b6ebc48dc181b7c39f4a07daf761a1b5 100644 (file)
@@ -462,6 +462,11 @@ SWITCH_DECLARE(void) switch_core_db_free(char *z);
  */
 SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db);
 
+/**
+ * Call this routine to load an external extension
+ */
+SWITCH_DECLARE(int) switch_core_db_load_extension(switch_core_db_t *db, const char *extension);
+
 /** Return values for switch_core_db_exec() and switch_core_db_step()*/
 #define SWITCH_CORE_DB_OK           0  /* Successful result */
 /* beginning-of-error-codes */
index a615fcd7420d3005cc459563eb1e47b2b8bb2ae1..6fca2260016ac6ac4a6bde70c03fd6e1d9abd61a 100644 (file)
@@ -93,6 +93,7 @@ class Dbh {
     bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
     bool query(char *sql, SWIGLUA_FN lua_fun);
     int affected_rows();
+    int load_extension(const char *extension);
 };
 
 }
index 811a8a7bd6beea406c2a29bf05274be8cc3b3977..c8918aee972c691cc6f6044f01ca901d0518a2b0 100644 (file)
@@ -438,3 +438,11 @@ int Dbh::affected_rows()
   }
   return 0;
 }
+
+int Dbh::load_extension(const char *extension)
+{
+  if (m_connected) {
+    return switch_cache_db_load_extension(dbh, extension);
+  }
+  return 0;
+}
index 36c0afae5c08cd39e389376078b0e368ed471e43..a1a289a70bcfb12e3cbd39bc7498a2f2fa700b4a 100644 (file)
@@ -65,6 +65,7 @@ namespace LUA {
       bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
       bool query(char *sql, SWIGLUA_FN lua_fun);
       int affected_rows();
+      int load_extension(const char *extension);
   };
 }
 #endif
index 3f9ad57fb50dbede634219b5e4455d330b1258be..98c50f081d6300213a93b8ba791d1557499ed52e 100644 (file)
@@ -7764,6 +7764,34 @@ fail:
 }
 
 
+static int _wrap_Dbh_load_extension(lua_State* L) {
+  int SWIG_arg = -1;
+  LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int result;
+  
+  SWIG_check_num_args("load_extension",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("load_extension",1,"LUA::Dbh *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("load_extension",2,"char const *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Dbh,0))){
+    SWIG_fail_ptr("Dbh_load_extension",1,SWIGTYPE_p_LUA__Dbh);
+  }
+  
+  arg2 = (char *)lua_tostring(L, 2);
+  result = (int)(arg1)->load_extension((char const *)arg2);
+  SWIG_arg=0;
+  lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
 static void swig_delete_Dbh(void *obj) {
 LUA::Dbh *arg1 = (LUA::Dbh *) obj;
 delete arg1;
@@ -7774,6 +7802,7 @@ static swig_lua_method swig_LUA_Dbh_methods[] = {
     {"test_reactive", _wrap_Dbh_test_reactive}, 
     {"query", _wrap_Dbh_query}, 
     {"affected_rows", _wrap_Dbh_affected_rows}, 
+    {"load_extension", _wrap_Dbh_load_extension}, 
     {0,0}
 };
 static swig_lua_attribute swig_LUA_Dbh_attributes[] = {
index 4f885e481b0615acd16e577794f0e9935ac6778b..64f38107f78e158c7d3020cbbd68f24d4e58e7af 100644 (file)
@@ -5444,6 +5444,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_db_changes(void * jarg1) {
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_db_load_extension(void * jarg1, char * jarg2) {
+  int jresult ;
+  switch_core_db_t *arg1 = (switch_core_db_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int result;
+  
+  arg1 = (switch_core_db_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (int)switch_core_db_load_extension(arg1,(char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT int SWIGSTDCALL CSharp_SWITCH_CORE_DB_OK_get() {
   int jresult ;
   int result;
@@ -12035,6 +12049,20 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_affected_rows(void * jarg1) {
 }
 
 
+SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_load_extension(void * jarg1, char * jarg2) {
+  int jresult ;
+  switch_cache_db_handle_t *arg1 = (switch_cache_db_handle_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  int result;
+  
+  arg1 = (switch_cache_db_handle_t *)jarg1; 
+  arg2 = (char *)jarg2; 
+  result = (int)switch_cache_db_load_extension(arg1,(char const *)arg2);
+  jresult = result; 
+  return jresult;
+}
+
+
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_cache_db_status(void * jarg1) {
   switch_stream_handle_t *arg1 = (switch_stream_handle_t *) 0 ;
   
index e560b2046c9d473fc0e8a661bb93eba6fe4c36c0..7364cce845f7fc76ebbfb1119eba0c38272c3f85 100644 (file)
@@ -986,6 +986,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static int switch_core_db_load_extension(SWIGTYPE_p_sqlite3 db, string extension) {
+    int ret = freeswitchPINVOKE.switch_core_db_load_extension(SWIGTYPE_p_sqlite3.getCPtr(db), extension);
+    return ret;
+  }
+
   public static string switch_sql_concat() {
     string ret = freeswitchPINVOKE.switch_sql_concat();
     return ret;
@@ -2698,6 +2703,11 @@ public class freeswitch {
     return ret;
   }
 
+  public static int switch_cache_db_load_extension(SWIGTYPE_p_switch_cache_db_handle dbh, string extension) {
+    int ret = freeswitchPINVOKE.switch_cache_db_load_extension(SWIGTYPE_p_switch_cache_db_handle.getCPtr(dbh), extension);
+    return ret;
+  }
+
   public static void switch_cache_db_status(switch_stream_handle stream) {
     freeswitchPINVOKE.switch_cache_db_status(switch_stream_handle.getCPtr(stream));
   }
@@ -7968,6 +7978,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_db_changes")]
   public static extern int switch_core_db_changes(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_core_db_load_extension")]
+  public static extern int switch_core_db_load_extension(HandleRef jarg1, string jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_CORE_DB_OK_get")]
   public static extern int SWITCH_CORE_DB_OK_get();
 
@@ -9489,6 +9502,9 @@ class freeswitchPINVOKE {
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_affected_rows")]
   public static extern int switch_cache_db_affected_rows(HandleRef jarg1);
 
+  [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_load_extension")]
+  public static extern int switch_cache_db_load_extension(HandleRef jarg1, string jarg2);
+
   [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_status")]
   public static extern void switch_cache_db_status(HandleRef jarg1);
 
index 7cc151dc5ba3817141fd0937605ced0d4be05a02..6cc8896fab291b4d76e127ad031b8150bbd3985f 100644 (file)
@@ -178,6 +178,23 @@ SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db)
        return sqlite3_changes(db);
 }
 
+SWITCH_DECLARE(int) switch_core_db_load_extension(switch_core_db_t *db, const char *extension)
+{
+       int ret = 0;
+       char *err = NULL;
+
+       sqlite3_enable_load_extension(db, 1);
+       ret = sqlite3_load_extension(db, extension, 0, &err);
+       sqlite3_enable_load_extension(db, 0);
+
+       if (err) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "LOAD EXTENSION ERR [%s]\n", err);
+               switch_core_db_free(err);
+               err = NULL;
+       }
+       return ret;
+}
+
 SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(const char *filename)
 {
        switch_core_db_t *db;
index c1381bd351fb6f6328194e93d4b2cb4d27be1988..3860af15d4ebc61fe049ed49c5bf87cc21a2c7cb 100644 (file)
@@ -703,6 +703,29 @@ SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh)
        return 0;
 }
 
+SWITCH_DECLARE(int) switch_cache_db_load_extension(switch_cache_db_handle_t *dbh, const char *extension)
+{
+       switch (dbh->type) {
+       case SCDB_TYPE_CORE_DB:
+               {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "try to load extension [%s]!\n", extension);
+                       return switch_core_db_load_extension(dbh->native_handle.core_db_dbh, extension);
+               }
+               break;
+       case SCDB_TYPE_ODBC:
+               {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type ODBC!\n");
+               }
+               break;
+       case SCDB_TYPE_PGSQL:
+               {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "load extension not supported by type PGSQL!\n");
+               }
+               break;
+       }
+       return 0;
+}
+
 
 SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err)
 {