mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-24 03:47:39 +00:00
MODLANG-174
This commit is contained in:
parent
68d1c32ad1
commit
26f2e095ef
@ -18,6 +18,10 @@
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* Lua function typemap */
|
||||||
|
%typemap(in,checkfn="lua_isfunction") SWIGLUA_FN
|
||||||
|
%{ $1.L=L; $1.idx=$input; %}
|
||||||
|
|
||||||
|
|
||||||
%ignore SwitchToMempool;
|
%ignore SwitchToMempool;
|
||||||
%newobject EventConsumer::pop;
|
%newobject EventConsumer::pop;
|
||||||
@ -25,6 +29,7 @@
|
|||||||
%newobject CoreSession;
|
%newobject CoreSession;
|
||||||
%newobject Event;
|
%newobject Event;
|
||||||
%newobject Stream;
|
%newobject Stream;
|
||||||
|
%newobject Dbh;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tell swig to grok everything defined in these header files and
|
* tell swig to grok everything defined in these header files and
|
||||||
@ -66,9 +71,18 @@ class Session : public CoreSession {
|
|||||||
void setLUA(lua_State *state);
|
void setLUA(lua_State *state);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Dbh {
|
||||||
|
private:
|
||||||
|
switch_cache_db_handle_t *dbh;
|
||||||
|
bool connected;
|
||||||
|
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
||||||
|
public:
|
||||||
|
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
||||||
|
~Dbh();
|
||||||
|
bool release();
|
||||||
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,3 +308,69 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
|
|||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dbh::Dbh(char *dsn, char *user, char *pass)
|
||||||
|
{
|
||||||
|
switch_cache_db_connection_options_t options = { {0} };
|
||||||
|
|
||||||
|
options.odbc_options.dsn = dsn;
|
||||||
|
options.odbc_options.user = user;
|
||||||
|
options.odbc_options.pass = pass;
|
||||||
|
|
||||||
|
if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
connected = true;
|
||||||
|
} else {
|
||||||
|
connected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dbh::~Dbh()
|
||||||
|
{
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Dbh::release()
|
||||||
|
{
|
||||||
|
if (connected) {
|
||||||
|
switch_cache_db_release_db_handle(&dbh);
|
||||||
|
connected = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv)
|
||||||
|
{
|
||||||
|
SWIGLUA_FN *lua_fun = (SWIGLUA_FN *)pArg;
|
||||||
|
|
||||||
|
lua_pushvalue(lua_fun->L, lua_fun->idx); /* get the lua callback function onto the stack */
|
||||||
|
|
||||||
|
lua_newtable(lua_fun->L); /* push a row (table) */
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++) {
|
||||||
|
lua_pushstring(lua_fun->L, switch_str_nil(cargv[i]));
|
||||||
|
lua_pushstring(lua_fun->L, switch_str_nil(argv[i]));
|
||||||
|
lua_settable(lua_fun->L, -3);
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_call(lua_fun->L, 1, 1); /* 1 in, 1 out */
|
||||||
|
|
||||||
|
if (lua_isnumber(lua_fun->L, -1)) {
|
||||||
|
if (lua_tonumber(lua_fun->L, -1) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; /* 0 to continue with next row */
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Dbh::query(char *sql, SWIGLUA_FN lua_fun)
|
||||||
|
{
|
||||||
|
if (connected) {
|
||||||
|
if (switch_cache_db_execute_sql_callback(dbh, sql, query_callback, &lua_fun, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no workie workie :(\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -8,6 +8,16 @@ extern "C" {
|
|||||||
#include "mod_lua_extra.h"
|
#include "mod_lua_extra.h"
|
||||||
}
|
}
|
||||||
#include <switch_cpp.h>
|
#include <switch_cpp.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
lua_State* L;
|
||||||
|
int idx;
|
||||||
|
}SWIGLUA_FN;
|
||||||
|
|
||||||
|
#define SWIGLUA_FN_GET(fn) {lua_pushvalue(fn.L,fn.idx);}
|
||||||
|
|
||||||
|
|
||||||
namespace LUA {
|
namespace LUA {
|
||||||
class Session:public CoreSession {
|
class Session:public CoreSession {
|
||||||
private:
|
private:
|
||||||
@ -41,5 +51,17 @@ namespace LUA {
|
|||||||
void setLUA(lua_State * state);
|
void setLUA(lua_State * state);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Dbh {
|
||||||
|
protected:
|
||||||
|
switch_cache_db_handle_t *dbh;
|
||||||
|
bool connected;
|
||||||
|
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
||||||
|
public:
|
||||||
|
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
||||||
|
~Dbh();
|
||||||
|
bool release();
|
||||||
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,38 +1,38 @@
|
|||||||
--- mod_lua_wrap.cpp 2008-07-16 16:58:58.000000000 -0400
|
--- mod_lua_wrap.cpp.orig 2010-09-05 16:39:26.000000000 +0200
|
||||||
+++ old.cpp 2008-07-16 16:58:42.000000000 -0400
|
+++ mod_lua_wrap.cpp 2010-09-05 16:39:44.000000000 +0200
|
||||||
@@ -6731,7 +6731,7 @@
|
@@ -4913,7 +4913,7 @@
|
||||||
SWIG_check_num_args("LUA::Session",0,0)
|
|
||||||
result = (LUA::Session *)new LUA::Session();
|
result = (LUA::Session *)new LUA::Session();
|
||||||
SWIG_arg=0;
|
SWIG_arg=0;
|
||||||
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
||||||
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
||||||
return SWIG_arg;
|
return SWIG_arg;
|
||||||
|
|
||||||
if(0) SWIG_fail;
|
fail:
|
||||||
@@ -6759,7 +6759,7 @@
|
@@ -4934,7 +4934,7 @@
|
||||||
|
arg2=(CoreSession *)SWIG_MustGetPtr(L,2,SWIGTYPE_p_CoreSession,0,2,"new_Session");
|
||||||
result = (LUA::Session *)new LUA::Session(arg1,arg2);
|
result = (LUA::Session *)new LUA::Session(arg1,arg2);
|
||||||
SWIG_arg=0;
|
SWIG_arg=0;
|
||||||
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
||||||
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
||||||
return SWIG_arg;
|
return SWIG_arg;
|
||||||
|
|
||||||
if(0) SWIG_fail;
|
fail:
|
||||||
@@ -6780,7 +6780,7 @@
|
@@ -4952,7 +4952,7 @@
|
||||||
arg1 = (char *)lua_tostring(L, 1);
|
arg1 = (char*)lua_tostring(L, 1);
|
||||||
result = (LUA::Session *)new LUA::Session(arg1);
|
result = (LUA::Session *)new LUA::Session(arg1);
|
||||||
SWIG_arg=0;
|
SWIG_arg=0;
|
||||||
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
||||||
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
||||||
return SWIG_arg;
|
return SWIG_arg;
|
||||||
|
|
||||||
if(0) SWIG_fail;
|
fail:
|
||||||
@@ -6805,7 +6805,7 @@
|
@@ -4970,7 +4970,7 @@
|
||||||
|
arg1=(switch_core_session_t *)SWIG_MustGetPtr(L,1,SWIGTYPE_p_switch_core_session_t,0,1,"new_Session");
|
||||||
result = (LUA::Session *)new LUA::Session(arg1);
|
result = (LUA::Session *)new LUA::Session(arg1);
|
||||||
SWIG_arg=0;
|
SWIG_arg=0;
|
||||||
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
- SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++;
|
||||||
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
+ SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; result->setLUA(L);
|
||||||
return SWIG_arg;
|
return SWIG_arg;
|
||||||
|
|
||||||
if(0) SWIG_fail;
|
fail:
|
||||||
|
@ -49,6 +49,19 @@ class Event {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Dbh {
|
||||||
|
protected:
|
||||||
|
switch_cache_db_handle_t *dbh;
|
||||||
|
bool connected;
|
||||||
|
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
||||||
|
public:
|
||||||
|
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
||||||
|
~Dbh();
|
||||||
|
bool release();
|
||||||
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CoreSession {
|
class CoreSession {
|
||||||
protected:
|
protected:
|
||||||
switch_input_args_t args;
|
switch_input_args_t args;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user