[Freeswitch-svn] [commit] r8323 - in freeswitch/trunk/src/mod/languages: mod_lua mod_perl
Freeswitch SVN
anthm at freeswitch.org
Thu May 8 19:58:45 EDT 2008
Author: anthm
Date: Thu May 8 19:58:45 2008
New Revision: 8323
Modified:
freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp
freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h
freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp
freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm
freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp
freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h
freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
Log:
add optional arg to hangup hook in perl/lua
Modified: freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp (original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp Thu May 8 19:58:45 2008
@@ -3,19 +3,19 @@
Session::Session() : CoreSession()
{
- cb_function = cb_arg = hangup_func_str = NULL;
+ cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
hh = mark = 0;
}
Session::Session(char *uuid) : CoreSession(uuid)
{
- cb_function = cb_arg = hangup_func_str = NULL;
+ cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
hh = mark = 0;
}
Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
{
- cb_function = cb_arg = hangup_func_str = NULL;
+ cb_function = cb_arg = hangup_func_str = hangup_func_arg = NULL;
hh = mark = 0;
}
static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup);
@@ -29,6 +29,7 @@
free(hangup_func_str);
}
+ switch_safe_free(hangup_func_arg);
switch_safe_free(cb_function);
switch_safe_free(cb_arg);
}
@@ -89,6 +90,11 @@
lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_str);
lua_pushstring(L, hook_state == CS_HANGUP ? "hangup" : "transfer");
+
+ if (hangup_func_arg) {
+ lua_pushstring(L, hangup_func_arg);
+ }
+
lua_call(L, 1, 1);
err = lua_tostring(L, -1);
@@ -115,14 +121,16 @@
}
-void Session::setHangupHook(char *func) {
+void Session::setHangupHook(char *func, char *arg) {
sanity_check_noreturn;
switch_safe_free(hangup_func_str);
-
+ switch_safe_free(hangup_func_arg);
+
if (func) {
hangup_func_str = strdup(func);
+ hangup_func_arg = strdup(arg);
switch_channel_set_private(channel, "CoreSession", this);
hook_state = switch_channel_get_state(channel);
switch_core_event_hook_add_state_change(session, lua_hanguphook);
Modified: freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h (original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h Thu May 8 19:58:45 2008
@@ -29,12 +29,13 @@
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(char *cbfunc, char *funcargs);
- void setHangupHook(char *func);
+ void setHangupHook(char *func, char *arg = NULL);
bool ready();
char *cb_function;
char *cb_arg;
char *hangup_func_str;
+ char *hangup_func_arg;
void setLUA(lua_State *state);
};
Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp (original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp Thu May 8 19:58:45 2008
@@ -5365,7 +5365,37 @@
}
-static int _wrap_Session_setHangupHook(lua_State* L) {
+static int _wrap_Session_setHangupHook__SWIG_0(lua_State* L) {
+ int SWIG_arg = -1;
+ Session *arg1 = (Session *) 0 ;
+ char *arg2 = (char *) 0 ;
+ char *arg3 = (char *) 0 ;
+
+ SWIG_check_num_args("setHangupHook",3,3)
+ if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("setHangupHook",1,"Session *");
+ if(!lua_isstring(L,2)) SWIG_fail_arg("setHangupHook",2,"char *");
+ if(!lua_isstring(L,3)) SWIG_fail_arg("setHangupHook",3,"char *");
+
+ if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
+ SWIG_fail_ptr("Session_setHangupHook",1,SWIGTYPE_p_Session);
+ }
+
+ arg2 = (char *)lua_tostring(L, 2);
+ arg3 = (char *)lua_tostring(L, 3);
+ (arg1)->setHangupHook(arg2,arg3);
+ SWIG_arg=0;
+
+ return SWIG_arg;
+
+ if(0) SWIG_fail;
+
+fail:
+ lua_error(L);
+ return SWIG_arg;
+}
+
+
+static int _wrap_Session_setHangupHook__SWIG_1(lua_State* L) {
int SWIG_arg = -1;
Session *arg1 = (Session *) 0 ;
char *arg2 = (char *) 0 ;
@@ -5392,6 +5422,62 @@
}
+static int _wrap_Session_setHangupHook(lua_State* L) {
+ int argc;
+ int argv[4]={
+ 1,2,3,4
+ };
+
+ argc = lua_gettop(L);
+ if (argc == 2) {
+ int _v;
+ {
+ void *ptr;
+ if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_Session, 0)) {
+ _v = 0;
+ } else {
+ _v = 1;
+ }
+ }
+ if (_v) {
+ {
+ _v = lua_isstring(L,argv[1]);
+ }
+ if (_v) {
+ return _wrap_Session_setHangupHook__SWIG_1(L);
+ }
+ }
+ }
+ if (argc == 3) {
+ int _v;
+ {
+ void *ptr;
+ if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_Session, 0)) {
+ _v = 0;
+ } else {
+ _v = 1;
+ }
+ }
+ if (_v) {
+ {
+ _v = lua_isstring(L,argv[1]);
+ }
+ if (_v) {
+ {
+ _v = lua_isstring(L,argv[2]);
+ }
+ if (_v) {
+ return _wrap_Session_setHangupHook__SWIG_0(L);
+ }
+ }
+ }
+ }
+
+ lua_pushstring(L,"No matching function for overloaded 'Session_setHangupHook'");
+ lua_error(L);return 0;
+}
+
+
static int _wrap_Session_ready(lua_State* L) {
int SWIG_arg = -1;
Session *arg1 = (Session *) 0 ;
@@ -5597,6 +5683,66 @@
}
+static int _wrap_Session_hangup_func_arg_set(lua_State* L) {
+ int SWIG_arg = -1;
+ Session *arg1 = (Session *) 0 ;
+ char *arg2 = (char *) 0 ;
+
+ SWIG_check_num_args("hangup_func_arg",2,2)
+ if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("hangup_func_arg",1,"Session *");
+ if(!lua_isstring(L,2)) SWIG_fail_arg("hangup_func_arg",2,"char *");
+
+ if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
+ SWIG_fail_ptr("Session_hangup_func_arg_set",1,SWIGTYPE_p_Session);
+ }
+
+ arg2 = (char *)lua_tostring(L, 2);
+ {
+ if (arg1->hangup_func_arg) delete [] arg1->hangup_func_arg;
+ if (arg2) {
+ arg1->hangup_func_arg = (char *) (new char[strlen((const char *)arg2)+1]);
+ strcpy((char *)arg1->hangup_func_arg, (const char *)arg2);
+ } else {
+ arg1->hangup_func_arg = 0;
+ }
+ }
+ SWIG_arg=0;
+
+ return SWIG_arg;
+
+ if(0) SWIG_fail;
+
+fail:
+ lua_error(L);
+ return SWIG_arg;
+}
+
+
+static int _wrap_Session_hangup_func_arg_get(lua_State* L) {
+ int SWIG_arg = -1;
+ Session *arg1 = (Session *) 0 ;
+ char *result = 0 ;
+
+ SWIG_check_num_args("hangup_func_arg",1,1)
+ if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("hangup_func_arg",1,"Session *");
+
+ if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
+ SWIG_fail_ptr("Session_hangup_func_arg_get",1,SWIGTYPE_p_Session);
+ }
+
+ result = (char *) ((arg1)->hangup_func_arg);
+ SWIG_arg=0;
+ lua_pushstring(L,(const char*)result); SWIG_arg++;
+ return SWIG_arg;
+
+ if(0) SWIG_fail;
+
+fail:
+ lua_error(L);
+ return SWIG_arg;
+}
+
+
static int _wrap_Session_setLUA(lua_State* L) {
int SWIG_arg = -1;
Session *arg1 = (Session *) 0 ;
@@ -5642,6 +5788,7 @@
{ "cb_function", _wrap_Session_cb_function_get, _wrap_Session_cb_function_set},
{ "cb_arg", _wrap_Session_cb_arg_get, _wrap_Session_cb_arg_set},
{ "hangup_func_str", _wrap_Session_hangup_func_str_get, _wrap_Session_hangup_func_str_set},
+ { "hangup_func_arg", _wrap_Session_hangup_func_arg_get, _wrap_Session_hangup_func_arg_set},
{0,0,0}
};
static swig_lua_class *swig_Session_bases[] = {0,0};
Modified: freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm (original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm Thu May 8 19:58:45 2008
@@ -382,6 +382,8 @@
*swig_cb_arg_set = *freeswitchc::Session_cb_arg_set;
*swig_hangup_func_str_get = *freeswitchc::Session_hangup_func_str_get;
*swig_hangup_func_str_set = *freeswitchc::Session_hangup_func_str_set;
+*swig_hangup_func_arg_get = *freeswitchc::Session_hangup_func_arg_get;
+*swig_hangup_func_arg_set = *freeswitchc::Session_hangup_func_arg_set;
*setPERL = *freeswitchc::Session_setPERL;
sub DISOWN {
my $self = shift;
Modified: freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp (original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp Thu May 8 19:58:45 2008
@@ -4,7 +4,7 @@
static STRLEN n_a;
-#define init_me() cb_function = hangup_func_str = NULL; hh = mark = 0; my_perl = NULL; cb_arg = NULL
+#define init_me() cb_function = hangup_func_str = NULL; hangup_func_arg = NULL; hh = mark = 0; my_perl = NULL; cb_arg = NULL
Session::Session() : CoreSession()
{
@@ -26,6 +26,7 @@
switch_safe_free(cb_function);
switch_safe_free(cb_arg);
switch_safe_free(hangup_func_str);
+ switch_safe_free(hangup_func_arg);
switch_core_event_hook_remove_state_change(session, perl_hanguphook);
}
@@ -82,7 +83,12 @@
return;
}
- code = switch_mprintf("%s(%s)", hangup_func_str, hook_state == CS_HANGUP ? "hangup" : "transfer");
+ if (hangup_func_arg) {
+ code = switch_mprintf("%s(%s,%s)", hangup_func_str, hook_state == CS_HANGUP ? "hangup" : "transfer", hangup_func_arg);
+ } else {
+ code = switch_mprintf("%s(%s)", hangup_func_str, hook_state == CS_HANGUP ? "hangup" : "transfer");
+ }
+
Perl_eval_pv(my_perl, code, TRUE);
free(code);
}
@@ -105,7 +111,7 @@
}
-void Session::setHangupHook(char *func) {
+void Session::setHangupHook(char *func, char *arg) {
sanity_check_noreturn;
@@ -116,6 +122,9 @@
switch_channel_set_private(channel, "CoreSession", this);
hook_state = switch_channel_get_state(channel);
switch_core_event_hook_add_state_change(session, perl_hanguphook);
+ if (arg) {
+ hangup_func_arg = strdup(func);
+ }
}
}
Modified: freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h (original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h Thu May 8 19:58:45 2008
@@ -36,12 +36,13 @@
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(char *cbfunc, char *funcargs);
- void setHangupHook(char *func);
+ void setHangupHook(char *func, char *arg=NULL);
bool ready();
char *cb_function;
char *cb_arg;
char *hangup_func_str;
+ char *hangup_func_arg;
void setPERL(PerlInterpreter *pi);
};
Modified: freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp (original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp Thu May 8 19:58:45 2008
@@ -6997,7 +6997,56 @@
}
-XS(_wrap_Session_setHangupHook) {
+XS(_wrap_Session_setHangupHook__SWIG_0) {
+ {
+ Session *arg1 = (Session *) 0 ;
+ char *arg2 = (char *) 0 ;
+ char *arg3 = (char *) 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ int res2 ;
+ char *buf2 = 0 ;
+ int alloc2 = 0 ;
+ int res3 ;
+ char *buf3 = 0 ;
+ int alloc3 = 0 ;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 3) || (items > 3)) {
+ SWIG_croak("Usage: Session_setHangupHook(self,func,arg);");
+ }
+ res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Session, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Session_setHangupHook" "', argument " "1"" of type '" "Session *""'");
+ }
+ arg1 = reinterpret_cast< Session * >(argp1);
+ res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Session_setHangupHook" "', argument " "2"" of type '" "char *""'");
+ }
+ arg2 = reinterpret_cast< char * >(buf2);
+ res3 = SWIG_AsCharPtrAndSize(ST(2), &buf3, NULL, &alloc3);
+ if (!SWIG_IsOK(res3)) {
+ SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Session_setHangupHook" "', argument " "3"" of type '" "char *""'");
+ }
+ arg3 = reinterpret_cast< char * >(buf3);
+ (arg1)->setHangupHook(arg2,arg3);
+
+
+ if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
+ XSRETURN(argvi);
+ fail:
+
+ if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ if (alloc3 == SWIG_NEWOBJ) delete[] buf3;
+ SWIG_croak_null();
+ }
+}
+
+
+XS(_wrap_Session_setHangupHook__SWIG_1) {
{
Session *arg1 = (Session *) 0 ;
char *arg2 = (char *) 0 ;
@@ -7035,6 +7084,92 @@
}
+XS(_wrap_Session_setHangupHook) {
+ dXSARGS;
+
+ {
+ unsigned long _index = 0;
+ SWIG_TypeRank _rank = 0;
+ if (items == 2) {
+ SWIG_TypeRank _ranki = 0;
+ SWIG_TypeRank _rankm = 0;
+ SWIG_TypeRank _pi = 1;
+ int _v = 0;
+ {
+ void *vptr = 0;
+ int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_Session, 0);
+ _v = SWIG_CheckState(res);
+ }
+ if (!_v) goto check_1;
+ _ranki += _v*_pi;
+ _rankm += _pi;
+ _pi *= SWIG_MAXCASTRANK;
+ {
+ int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0);
+ _v = SWIG_CheckState(res);
+ }
+ if (!_v) goto check_1;
+ _ranki += _v*_pi;
+ _rankm += _pi;
+ _pi *= SWIG_MAXCASTRANK;
+ if (!_index || (_ranki < _rank)) {
+ _rank = _ranki; _index = 1;
+ if (_rank == _rankm) goto dispatch;
+ }
+ }
+ check_1:
+
+ if (items == 3) {
+ SWIG_TypeRank _ranki = 0;
+ SWIG_TypeRank _rankm = 0;
+ SWIG_TypeRank _pi = 1;
+ int _v = 0;
+ {
+ void *vptr = 0;
+ int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_Session, 0);
+ _v = SWIG_CheckState(res);
+ }
+ if (!_v) goto check_2;
+ _ranki += _v*_pi;
+ _rankm += _pi;
+ _pi *= SWIG_MAXCASTRANK;
+ {
+ int res = SWIG_AsCharPtrAndSize(ST(1), 0, NULL, 0);
+ _v = SWIG_CheckState(res);
+ }
+ if (!_v) goto check_2;
+ _ranki += _v*_pi;
+ _rankm += _pi;
+ _pi *= SWIG_MAXCASTRANK;
+ {
+ int res = SWIG_AsCharPtrAndSize(ST(2), 0, NULL, 0);
+ _v = SWIG_CheckState(res);
+ }
+ if (!_v) goto check_2;
+ _ranki += _v*_pi;
+ _rankm += _pi;
+ _pi *= SWIG_MAXCASTRANK;
+ if (!_index || (_ranki < _rank)) {
+ _rank = _ranki; _index = 2;
+ if (_rank == _rankm) goto dispatch;
+ }
+ }
+ check_2:
+
+ dispatch:
+ switch(_index) {
+ case 1:
+ ++PL_markstack_ptr; SWIG_CALLXS(_wrap_Session_setHangupHook__SWIG_1); return;
+ case 2:
+ ++PL_markstack_ptr; SWIG_CALLXS(_wrap_Session_setHangupHook__SWIG_0); return;
+ }
+ }
+
+ croak("No matching function for overloaded 'Session_setHangupHook'");
+ XSRETURN(0);
+}
+
+
XS(_wrap_Session_ready) {
{
Session *arg1 = (Session *) 0 ;
@@ -7279,6 +7414,78 @@
}
+XS(_wrap_Session_hangup_func_arg_set) {
+ {
+ Session *arg1 = (Session *) 0 ;
+ char *arg2 = (char *) 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ int res2 ;
+ char *buf2 = 0 ;
+ int alloc2 = 0 ;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 2) || (items > 2)) {
+ SWIG_croak("Usage: Session_hangup_func_arg_set(self,hangup_func_arg);");
+ }
+ res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Session, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Session_hangup_func_arg_set" "', argument " "1"" of type '" "Session *""'");
+ }
+ arg1 = reinterpret_cast< Session * >(argp1);
+ res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Session_hangup_func_arg_set" "', argument " "2"" of type '" "char *""'");
+ }
+ arg2 = reinterpret_cast< char * >(buf2);
+ if (arg1->hangup_func_arg) delete[] arg1->hangup_func_arg;
+ if (arg2) {
+ size_t size = strlen(reinterpret_cast< const char * >(arg2)) + 1;
+ arg1->hangup_func_arg = (char *)reinterpret_cast< char* >(memcpy((new char[size]), reinterpret_cast< const char * >(arg2), sizeof(char)*(size)));
+ } else {
+ arg1->hangup_func_arg = 0;
+ }
+
+
+ if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ XSRETURN(argvi);
+ fail:
+
+ if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+ SWIG_croak_null();
+ }
+}
+
+
+XS(_wrap_Session_hangup_func_arg_get) {
+ {
+ Session *arg1 = (Session *) 0 ;
+ char *result = 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 1) || (items > 1)) {
+ SWIG_croak("Usage: Session_hangup_func_arg_get(self);");
+ }
+ res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Session, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Session_hangup_func_arg_get" "', argument " "1"" of type '" "Session *""'");
+ }
+ arg1 = reinterpret_cast< Session * >(argp1);
+ result = (char *) ((arg1)->hangup_func_arg);
+ ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
+
+ XSRETURN(argvi);
+ fail:
+
+ SWIG_croak_null();
+ }
+}
+
+
XS(_wrap_Session_setPERL) {
{
Session *arg1 = (Session *) 0 ;
@@ -7529,6 +7736,8 @@
{"freeswitchc::Session_cb_arg_get", _wrap_Session_cb_arg_get},
{"freeswitchc::Session_hangup_func_str_set", _wrap_Session_hangup_func_str_set},
{"freeswitchc::Session_hangup_func_str_get", _wrap_Session_hangup_func_str_get},
+{"freeswitchc::Session_hangup_func_arg_set", _wrap_Session_hangup_func_arg_set},
+{"freeswitchc::Session_hangup_func_arg_get", _wrap_Session_hangup_func_arg_get},
{"freeswitchc::Session_setPERL", _wrap_Session_setPERL},
{0,0}
};
More information about the Freeswitch-svn
mailing list