[Freeswitch-svn] [commit] r8214 - in freeswitch/trunk/src: . include mod/languages/mod_lua mod/languages/mod_perl

Freeswitch SVN anthm at freeswitch.org
Tue Apr 29 19:34:27 EDT 2008


Author: anthm
Date: Tue Apr 29 19:34:26 2008
New Revision: 8214

Added:
   freeswitch/trunk/src/mod/languages/mod_lua/hack.diff
   freeswitch/trunk/src/mod/languages/mod_lua/lua-mode.el
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.c
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.h
Modified:
   freeswitch/trunk/src/include/switch_cpp.h
   freeswitch/trunk/src/mod/languages/mod_lua/Makefile
   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.c
   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/mod_perl_wrap.cpp
   freeswitch/trunk/src/switch_cpp.cpp
   freeswitch/trunk/src/switch_event.c

Log:
update

Modified: freeswitch/trunk/src/include/switch_cpp.h
==============================================================================
--- freeswitch/trunk/src/include/switch_cpp.h	(original)
+++ freeswitch/trunk/src/include/switch_cpp.h	Tue Apr 29 19:34:26 2008
@@ -11,6 +11,11 @@
 
 #include <switch.h>
 
+#define sanity_check(x) do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
+#define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
+#define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown";  caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = "";  caller_profile.username = ""; on_hangup = NULL; memset(&cb_state, 0, sizeof(cb_state)); hook_state = CS_NEW; } while(0)
+
+
 //
 // C++ Interface: switch_to_cpp_mempool
 //
@@ -62,19 +67,6 @@
 void api_reply_delete(char *reply);
 
 
-/**
- * \brief - process language specific callback results
- * 
- * First the actual callback is called, (in the case of python, 
- * PythonDTMFCallback), it then calls the language specific callback defined
- * by the user (eg, some python method), and then _this_ function is called
- * with the results of the language specific callback.
- */
-switch_status_t process_callback_result(char *raw_result,
-										struct input_callback_state *cb_state,
-										switch_core_session_t *session);
-
-
 typedef struct input_callback_state {
     void *function;           // pointer to the language specific callback function
                               // eg, PyObject *pyfunc
@@ -105,10 +97,15 @@
 
 class Event {
  protected:
-	switch_event_t *event;
  public:
+	switch_event_t *event;
+	char *serialized_string;
+	int mine;
+
 	Event(const char *type, const char *subclass_name = NULL);
+	Event(switch_event_t *wrap_me, int free_me=0);
 	virtual ~Event();
+	const char *serialize(const char *format=NULL);
 	bool set_priority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
 	char *get_header(char *header_name);
 	char *get_body(void);
@@ -131,8 +128,9 @@
 	char *voice_name;
 	void store_file_handle(switch_file_handle_t *fh);
 	void *on_hangup; // language specific callback function, cast as void * 
-
-
+	switch_file_handle_t local_fh;
+	switch_file_handle_t *fhp;
+	switch_status_t process_callback_result(char *ret);
  public:
 	CoreSession();
 	CoreSession(char *uuid);
@@ -150,8 +148,10 @@
 	int preAnswer();
 	virtual void hangup(char *cause = "normal_clearing");
 	void setVariable(char *var, char *val);
+	void setPrivate(char *var, void *val);
+	void *getPrivate(char *var);
 	const char *getVariable(char *var);
-
+	
 
 	/** \brief Record to a file
 	 * \param filename 
@@ -193,7 +193,6 @@
 	 */
 	void setDTMFCallback(void *cbfunc, char *funcargs);
 
-
 	int speak(char *text);
 	void set_tts_parms(char *tts_name, char *voice_name);
 
@@ -265,6 +264,9 @@
 	bool ready();
 
 	void execute(char *app, char *data);
+
+	void sendEvent(Event *sendME);
+
 	virtual bool begin_allow_threads() = 0;
 	virtual bool end_allow_threads() = 0;
 

Modified: freeswitch/trunk/src/mod/languages/mod_lua/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/Makefile	(original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/Makefile	Tue Apr 29 19:34:26 2008
@@ -3,12 +3,12 @@
 LIBLUA_A=lua/liblua.a
 LOCAL_LIBADD=$(LIBLUA_A)
 LOCAL_LDFLAGS=-lm
-LOCAL_OBJS=freeswitch_lua.o mod_lua_wrap.o #glua.o
+LOCAL_OBJS=freeswitch_lua.o mod_lua_wrap.o
 VERBOSE=1
 
 include $(BASE)/build/modmake.rules
 
-glua.o: mod_lua_wrap.cpp
+local_depend: $(LOCAL_OBJS)
 
 $(LIBLUA_A):
 	cd lua && $(MAKE) CFLAGS="$(ALL_CFLAGS) -DLUA_USE_LINUX -w" liblua.a
@@ -16,14 +16,18 @@
 luaclean:
 	cd lua && $(MAKE) clean
 
+freeswitch_lua.o: freeswitch_lua.h
+
 allclean: clean luaclean
 	rm -f mod_lua_wrap.* freeswitch_lua.$(DYNAMIC_LIB_EXTEN)
 
 swigclean:
 	rm mod_lua_wrap.*
 
-mod_lua_wrap.cpp:
+mod_lua_wrap.cpp: mod_lua_extra.c
 	swig -lua -c++ -I../../../../src/include -oh mod_lua_wrap.h -o mod_lua_wrap.cpp freeswitch.i
+	echo "#include \"mod_lua_extra.c\"" >> mod_lua_wrap.cpp
+	patch -s -p0 -i hack.diff
 
 freeswitch_lua.$(DYNAMIC_LIB_EXTEN): $(LOCAL_OBJS) $(LOCAL_LIBADD)
 	$(LINK) $(SOLINK) -o freeswitch_lua.$(DYNAMIC_LIB_EXTEN)  $(LOCAL_OBJS) $(LOCAL_LIBADD) $(LDFLAGS)

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	Tue Apr 29 19:34:26 2008
@@ -1,23 +1,34 @@
 #include "freeswitch_lua.h"
 
+SWITCH_BEGIN_EXTERN_C
+#include "lua.h"
+#include <lauxlib.h>
+#include <lualib.h>
+#include "mod_lua_extra.h"
+SWITCH_END_EXTERN_C
+
+
 Session::Session() : CoreSession()
 {
-	
+	cb_function = cb_arg = hangup_func_str = NULL;
 }
 
 Session::Session(char *uuid) : CoreSession(uuid)
 {
-	
+	cb_function = cb_arg = hangup_func_str = NULL;
 }
 
 Session::Session(switch_core_session_t *new_session) : CoreSession(new_session)
 {
-
+	cb_function = cb_arg = hangup_func_str = NULL;
 }
-
-Session::~Session() 
+static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup);
+Session::~Session()
 {
-	
+	switch_safe_free(cb_function);
+	switch_safe_free(cb_arg);
+	switch_safe_free(hangup_func_str);
+	switch_core_event_hook_remove_state_change(session, lua_hanguphook);
 }
 
 
@@ -33,11 +44,145 @@
 
 void Session::check_hangup_hook() 
 {
+	if (hangup_func_str && (hook_state == CS_HANGUP || hook_state == CS_RING)) {
+		lua_State *L;
+		L = (lua_State *) getPrivate("__L");
+
+		if (!L) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
+			return;
+		}
+		
+		lua_getfield(L, LUA_GLOBALSINDEX, (char *)hangup_func_str);
+		lua_pushstring(L, hook_state == CS_HANGUP ? "hangup" : "transfer");
+		lua_call(L, 1, 0);
+	}
+}
+
+static switch_status_t lua_hanguphook(switch_core_session_t *session_hungup) 
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
+	CoreSession *coresession = NULL;
+	switch_channel_state_t state = switch_channel_get_state(channel);
+
+	if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
+		if (coresession->hook_state != state) {
+			coresession->hook_state = state;
+			coresession->check_hangup_hook();
+		}
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
+void Session::setHangupHook(char *func) {
+
+	sanity_check_noreturn;
+
+	switch_safe_free(hangup_func_str);
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not Currently Available\n");
+	func = NULL;
+
+	if (func) {
+		hangup_func_str = strdup(func);
+		switch_channel_set_private(channel, "CoreSession", this);
+		hook_state = switch_channel_get_state(channel);
+		switch_core_event_hook_add_state_change(session, lua_hanguphook);
+	}
+}
+
+void Session::setInputCallback(char *cbfunc, char *funcargs) {
+
+	sanity_check_noreturn;
+
+	switch_safe_free(cb_function);
+	if (cbfunc) {
+		cb_function = strdup(cbfunc);
+	}
+
+	switch_safe_free(cb_arg);
+	if (funcargs) {
+		cb_arg = strdup(funcargs);
+	}
+
+	args.buf = this;
+	switch_channel_set_private(channel, "CoreSession", this);
+
+	args.input_callback = dtmf_callback;  
+	ap = &args;
 }
 
 switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t itype) 
 {
-	return SWITCH_STATUS_FALSE;
+	lua_State *L;
+	const char *ret;
+	
+	L = (lua_State *) getPrivate("__L");
+	if (!L) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh!\n");
+		return SWITCH_STATUS_FALSE;
+	}
+
+	switch (itype) {
+    case SWITCH_INPUT_TYPE_DTMF:
+		{
+			switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
+			char str[2] = "";
+			int arg_count = 2;
+
+			lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_function);
+			lua_pushstring(L, "dtmf");			
+			
+			lua_newtable(L);		
+			lua_pushstring(L, "digit");
+			str[0] = dtmf->digit;
+			lua_pushstring(L, str);
+			lua_rawset(L, -3);
+			
+			lua_pushstring(L, "duration");
+			lua_pushnumber(L, dtmf->duration);
+			lua_rawset(L, -3);
+
+			if (cb_arg) {
+				lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_arg);
+				arg_count++;
+			}
+
+			lua_call(L, arg_count, 1);
+			ret = lua_tostring(L, -1);
+			lua_pop(L, 1);
+
+			return process_callback_result((char *)ret);
+		}
+		break;
+    case SWITCH_INPUT_TYPE_EVENT:
+		{
+			switch_event_t *event = (switch_event_t *) input;
+			int arg_count = 2;
+
+			lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_function);
+			lua_pushstring(L, "event");
+			mod_lua_conjure_event(L, event, "__Input_Event__", 1);
+			lua_getfield(L, LUA_GLOBALSINDEX, "__Input_Event__");
+
+			if (cb_arg) {
+				lua_getfield(L, LUA_GLOBALSINDEX, (char *)cb_arg);
+				arg_count++;
+			}
+
+			lua_call(L, 2, 1);
+
+            ret = lua_tostring(L, -1);
+			lua_pop(L, 1);
+			
+            return process_callback_result((char *)ret);			
+		}
+		break;
+	}
+
+	return SWITCH_STATUS_SUCCESS;
 }
 
 

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	Tue Apr 29 19:34:26 2008
@@ -1,5 +1,5 @@
-#ifndef FREESWITCH_PYTHON_H
-#define FREESWITCH_PYTHON_H
+#ifndef FREESWITCH_LUA_H
+#define FREESWITCH_LUA_H
 
 #include <switch_cpp.h>
 
@@ -10,7 +10,6 @@
 
 
 class Session : public CoreSession {
- private:
  public:
     Session();
     Session(char *uuid);
@@ -21,58 +20,12 @@
 	virtual bool end_allow_threads();
 	virtual void check_hangup_hook();
 	virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
+	void setInputCallback(char *cbfunc, char *funcargs);
+	void setHangupHook(char *func);
 
-	switch_core_session_t *session;
-	switch_channel_t *channel;
-	unsigned int flags;
-	int allocated;
-	input_callback_state cb_state; // callback state, always pointed to by the buf
-                                   // field in this->args
-	switch_channel_state_t hook_state; // store hookstate for on_hangup callback
-
-#if 0
-
-	int answer();
-	int preAnswer();
-	virtual void hangup(char *cause);
-	void setVariable(char *var, char *val);
-	const char *getVariable(char *var);
-	int recordFile(char *file_name, int max_len=0, int silence_threshold=0, int silence_secs=0);
-	void setCallerData(char *var, char *val);
-	int originate(CoreSession *a_leg_session, char *dest, int timeout=60);
-	void setDTMFCallback(void *cbfunc, char *funcargs);
-	int speak(char *text);
-	void set_tts_parms(char *tts_name, char *voice_name);
-	int collectDigits(int timeout);
-	int getDigits(char *dtmf_buf, 
-				  switch_size_t buflen, 
-				  switch_size_t maxdigits, 
-				  char *terminators, 
-				  char *terminator, 
-				  int timeout);
-
-	int transfer(char *extensions, char *dialplan, char *context);
-	int playAndGetDigits(int min_digits, 
-						 int max_digits, 
-						 int max_tries, 
-						 int timeout, 
-						 char *terminators,
-						 char *audio_files, 
-						 char *bad_input_audio_files, 
-						 char *dtmf_buf, 
-						 char *digits_regex);
-
-	int streamFile(char *file, int starting_sample_count=0);
-	int flushEvents();
-	int flushDigits();
-	int setAutoHangup(bool val);
-	void setHangupHook(void *hangup_func);
-	bool ready();
-	void execute(char *app, char *data);
-	char* get_uuid();
-	const switch_input_args_t& get_cb_args();
-#endif
-
+	char *cb_function;
+	char *cb_arg;
+	char *hangup_func_str;
 };
 
 #endif

Added: freeswitch/trunk/src/mod/languages/mod_lua/hack.diff
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/languages/mod_lua/hack.diff	Tue Apr 29 19:34:26 2008
@@ -0,0 +1,29 @@
+--- hack.cpp	2008-04-29 13:49:22.000000000 -0400
++++ mod_lua_wrap.cpp	2008-04-29 13:49:10.000000000 -0400
+@@ -4028,7 +4028,7 @@
+   SWIG_check_num_args("Session",0,0)
+   result = (Session *)new Session();
+   SWIG_arg=0;
+-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; 
++  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
+   return SWIG_arg;
+   
+   if(0) SWIG_fail;
+@@ -4049,7 +4049,7 @@
+   arg1 = (char *)lua_tostring(L, 1);
+   result = (Session *)new Session(arg1);
+   SWIG_arg=0;
+-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; 
++  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
+   return SWIG_arg;
+   
+   if(0) SWIG_fail;
+@@ -4074,7 +4074,7 @@
+   
+   result = (Session *)new Session(arg1);
+   SWIG_arg=0;
+-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; 
++  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
+   return SWIG_arg;
+   
+   if(0) SWIG_fail;

Added: freeswitch/trunk/src/mod/languages/mod_lua/lua-mode.el
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/languages/mod_lua/lua-mode.el	Tue Apr 29 19:34:26 2008
@@ -0,0 +1,1338 @@
+;;; lua-mode.el --- a major-mode for editing Lua scripts
+
+;; Copyright (C) 1997, 2001, 2004, 2006, 2007 Free Software Foundation, Inc.
+
+;; Author: 2006 Juergen Hoetzel <juergen at hoetzel.info>
+;;         2004 various (support for Lua 5 and byte compilation)
+;;         2001 Christian Vogler <cvogler at gradient.cis.upenn.edu>
+;;         1997 Bret Mogilefsky <mogul-lua at gelatinous.com> starting from
+;;              tcl-mode by Gregor Schmid <schmid at fb3-s7.math.tu-berlin.de>
+;;              with tons of assistance from
+;;              Paul Du Bois <pld-lua at gelatinous.com> and
+;;              Aaron Smith <aaron-lua at gelatinous.com>.
+;; URL:		http://lua-mode.luaforge.net/
+;; Version:	20070703
+;; This file is NOT part of Emacs.
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License
+;; as published by the Free Software Foundation; either version 2
+;; of the License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+;; MA 02110-1301, USA.
+
+(defconst lua-version "20071122"
+  "Lua Mode version number.")
+
+;; Keywords: languages, processes, tools
+
+
+;;; Commentary:
+
+;; Thanks to Tobias Polzin <polzin<at>gmx.de> for function indenting
+;; patch: Indent "(" like "{"
+
+;; Thanks to  Fabien <fleutot<at>gmail.com> for imenu patches.
+
+;; Special Thanks to Simon Marshall <simonm at mail.esrin.esa.it> for
+;; font-lock patches.
+
+;; Additional font-lock highlighting and indentation tweaks by
+;; Adam D. Moss <adam at gimp.org> <aspirin at icculus.org>
+
+;; This file was written with emacs using Jamie Lokier's folding mode
+;; That's what the funny ;;{{{ ;;}}} marks are there for
+
+;;{{{ INSTALLATION:
+
+;; To install, just drop this file into a directory on your load-path (and
+;; byte-compile it).  To set up Emacs to automatically edit files ending in
+;; ".lua" using lua-mode add the following to your ~/.emacs file (GNU
+;; Emacs) or ~/.xemacs/init.el file (XEmacs):
+;;    (setq auto-mode-alist (cons '("\\.lua$" . lua-mode) auto-mode-alist))
+;;    (autoload 'lua-mode "lua-mode" "Lua editing mode." t)
+
+;;}}}
+;;{{{ Usage
+
+;; Lua-mode supports c-mode style formatting and sending of
+;; lines/regions/files to a Lua interpreter. An interpreter (see
+;; variable `lua-default-application') will be started if you try to
+;; send some code and none is running. You can use the process-buffer
+;; (named after the application you chose) as if it were an
+;; interactive shell. See the documentation for `comint.el' for
+;; details.
+
+;;}}}
+;;{{{ Key-bindings
+
+;; To see all the keybindings for Lua mode, look at `lua-setup-keymap'
+;; or start `lua-mode' and type `\C-h m'.
+;; The keybindings may seem strange, since I prefer to use them with
+;; lua-prefix-key set to nil, but since those keybindings are already used
+;; the default for `lua-prefix-key' is `\C-c', which is the conventional
+;; prefix for major-mode commands.
+
+;; You can customise the keybindings either by setting `lua-prefix-key'
+;; or by putting the following in your .emacs
+;;      (setq lua-mode-map (make-sparse-keymap))
+;; and
+;;      (define-key lua-mode-map <your-key> <function>)
+;; for all the functions you need.
+
+;;}}}
+
+;;; Code:
+(defconst lua-using-xemacs (string-match "XEmacs" emacs-version)
+  "Nil unless using XEmacs).")
+
+;; We need that !
+(require 'comint)
+
+;;{{{ variables
+
+;; Local variables
+(defgroup lua nil
+  "Major mode for editing lua code."
+  :prefix "lua-"
+  :group 'languages)
+
+(defcustom lua-default-application "lua"
+  "Default application to run in lua subprocess."
+  :type 'string
+  :group 'lua)
+
+(defcustom lua-default-command-switches (list "-i")
+  "Command switches for `lua-default-application'.
+Should be a list of strings."
+  :type '(repeat string)
+  :group 'lua)
+
+(defcustom lua-always-show t
+  "*Non-nil means display lua-process-buffer after sending a command."
+  :type 'boolean
+  :group 'lua)
+
+(defcustom lua-search-url-prefix "http://www.lua.org/manual/5.1/manual.html#pdf-"
+  "*URL at which to search for documentation on a word"
+  :type 'string
+  :group 'lua)
+
+(defvar lua-process nil
+  "The active Lua subprocess")
+
+(defvar lua-process-buffer nil
+  "Buffer used for communication with Lua subprocess")
+
+(defvar lua-mode-map nil
+  "Keymap used with lua-mode.")
+
+(defvar lua-electric-flag t
+"If t, electric actions (like automatic reindentation)  will happen when an electric
+ key like `{' is pressed") 
+(make-variable-buffer-local 'lua-electric-flag)
+
+(defcustom lua-prefix-key "\C-c"
+  "Prefix for all lua-mode commands."
+  :type 'string
+  :group 'lua)
+
+(defcustom lua-prompt-regexp "[^\n]*\\(>[\t ]+\\)+$"
+  "Regexp which matches the Lua program's prompt."
+  :group 'lua
+  :type  'regexp
+  )
+
+(defcustom lua-traceback-line-re
+  "^\\(?:[\t ]*\\|.*>[\t ]+\\)\\([^\n\t ]+\\):\\([0-9]+\\):"
+  "Regular expression that describes tracebacks and errors."
+  :group 'lua
+  :type  'regexp
+  )
+
+(defcustom lua-jump-on-traceback t
+  "*Jump to innermost traceback location in *lua* buffer.  When this
+variable is non-nil and a traceback occurs when running Lua code in a
+subprocess, jump immediately to the source code of the innermost
+traceback location."
+  :group 'lua
+  :type 'boolean
+  )
+
+(defvar lua-mode-hook nil
+  "Hooks called when Lua mode fires up.")
+
+(defvar lua-region-start (make-marker)
+  "Start of special region for Lua communication.")
+
+(defvar lua-region-end (make-marker)
+  "End of special region for Lua communication.")
+
+(defvar lua-indent-level 3
+  "Amount by which Lua subexpressions are indented.")
+
+(defvar lua-mode-menu (make-sparse-keymap "Lua")
+  "Keymap for lua-mode's menu.")
+
+(defvar lua-xemacs-menu
+  '(["Restart With Whole File" lua-restart-with-whole-file t]
+    ["Kill Process" lua-kill-process t]
+    ["Hide Process Buffer" lua-hide-process-buffer t]
+    ["Show Process Buffer" lua-show-process-buffer t]
+    ["Beginning Of Proc" lua-beginning-of-proc t]
+    ["End Of Proc" lua-end-of-proc t]
+    ["Set Lua-Region Start" lua-set-lua-region-start t]
+    ["Set Lua-Region End" lua-set-lua-region-end t]
+    ["Send Lua-Region" lua-send-lua-region t]
+    ["Send Current Line" lua-send-current-line t]
+    ["Send Region" lua-send-region t]
+    ["Send Proc" lua-send-proc t]
+    ["Send Buffer" lua-send-buffer t]
+    ["Search Documentation" lua-search-documentation t])
+  "XEmacs menu for Lua mode.")
+
+(defvar lua-font-lock-keywords
+  (eval-when-compile
+    (list
+     ;;
+     ;; Function name declarations.
+     '("^[ \t]*\\<\\(\\(local[ \t]+\\)?function\\)\\>[ \t]+\\(\\(\\sw:\\|\\sw\\.\\|\\sw_\\|\\sw\\)+\\)"
+       (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
+     
+     ;; Handle function names in assignments
+     '("\\(\\(\\sw:\\|\\sw\\.\\|\\sw_\\|\\sw\\)+\\)[ \t]*=[ \t]*\\(function\\)\\>"
+       (1 font-lock-function-name-face nil t) (3 font-lock-keyword-face))
+
+     ; Highlight multi-line comment blocks; since font-lock-mode doesn't
+     ; claim to handle the highlighting of multi-line expressions elegantly
+     ; this works best with lazy-lock-mode if your Emacs supports it, e.g.
+     ; try (setq font-lock-support-mode 'lazy-lock-mode) in your ~/.emacs
+
+     ;; Multi-line comment blocks.
+     `("\\(?:^\\|[^-]\\)\\(--\\[\\(=*\\)\\[\\(?:.\\|\n\\)*?\\]\\2\\]\\)"
+       (1 font-lock-comment-face t))
+
+     ;;
+     ;; Keywords.
+     ;; (concat "\\<"
+     ;;         (regexp-opt '("and" "break" "do" "else" "elseif" "end" "false"
+     ;;                       "for" "function" "if" "in" "local" "nil" "not"
+     ;;                       "or" "repeat" "return" "then" "true" "until"
+     ;;                       "while") t)
+     ;;         "\\>")
+
+     ; Insert expanded regexp-opt here for the benefit of those who
+     ; don't have regexp-opt available.
+
+     "\\<\\(and\\|break\\|do\\|e\\(lse\\(if\\)?\\|nd\\)\\|f\\(alse\\|or\\|unction\\)\\|i[fn]\\|local\\|n\\(il\\|ot\\)\\|or\\|re\\(peat\\|turn\\)\\|t\\(hen\\|rue\\)\\|until\\|while\\)\\>"
+
+     "Default expressions to highlight in Lua mode.")))
+
+(defvar lua-imenu-generic-expression
+  '((nil "^[ \t]*\\(?:local[ \t]+\\)?function[ \t]+\\(\\(\\sw:\\|\\sw_\\|\\sw\\.\\|\\sw\\)+\\)" 1))
+  "Imenu generic expression for lua-mode.  See `imenu-generic-expression'.")
+
+(defvar lua-mode-abbrev-table nil
+  "Abbreviation table used in lua-mode buffers.")
+
+(defvar lua-sexp-alist '(("then" . "end")
+                        ("function" . "end")
+                        ("do" . "end")))
+
+(define-abbrev-table 'lua-mode-abbrev-table
+  '(
+        ("end" "end" lua-indent-line 0)
+        ("else" "else" lua-indent-line 0)
+        ("elseif" "elseif" lua-indent-line 0)
+        ))
+
+(defconst lua-indent-whitespace " \t"
+  "Character set that constitutes whitespace for indentation in lua.")
+
+;;}}}
+;;{{{ lua-make-temp-file
+
+(eval-and-compile
+  (defalias 'lua-make-temp-file
+    (if (fboundp 'make-temp-file)
+	'make-temp-file
+      (lambda (prefix &optional dir-flag) ;; Simple implementation
+	(expand-file-name
+	 (make-temp-name prefix)
+	 (if (fboundp 'temp-directory)
+	     (temp-directory)
+	   temporary-file-directory))))))
+
+;;}}}
+;;{{{ replace-in-string
+
+(eval-and-compile
+  (if (not (fboundp 'replace-in-string)) ;GNU emacs doesn't have it
+      (defun replace-in-string  (string regexp newtext &optional literal)
+	(replace-regexp-in-string regexp newtext string nil literal))))
+
+;;}}}
+;;{{{ lua-mode
+
+;;;###autoload
+(defun lua-mode ()
+  "Major mode for editing Lua code.
+The following keys are bound:
+\\{lua-mode-map}
+"
+  (interactive)
+  (let ((switches nil)
+                  s)
+    (kill-all-local-variables)
+    (setq major-mode 'lua-mode)
+    (setq mode-name "Lua")
+    (setq comint-prompt-regexp lua-prompt-regexp)
+    (make-local-variable 'lua-default-command-switches)
+    (set (make-local-variable 'indent-line-function) 'lua-indent-line)
+    (set (make-local-variable 'comment-start) "--")
+    (set (make-local-variable 'comment-start-skip) "--")
+    (set (make-local-variable 'font-lock-defaults)
+                        '(lua-font-lock-keywords nil nil ((?_ . "w"))))
+    (set (make-local-variable 'imenu-generic-expression)
+                        lua-imenu-generic-expression)
+         (setq local-abbrev-table lua-mode-abbrev-table)
+         (abbrev-mode 1)
+    (make-local-variable 'lua-default-eval)
+    (or lua-mode-map
+                  (lua-setup-keymap))
+    (use-local-map lua-mode-map)
+    (set-syntax-table (copy-syntax-table))
+    (modify-syntax-entry ?+ ".")
+    (modify-syntax-entry ?- ". 12")
+    (modify-syntax-entry ?* ".")
+    (modify-syntax-entry ?/ ".")
+    (modify-syntax-entry ?^ ".")
+    ;; This might be better as punctuation, as for C, but this way you
+    ;; can treat table index as symbol.
+    (modify-syntax-entry ?. "_")	; e.g. `io.string'
+    (modify-syntax-entry ?> ".")
+    (modify-syntax-entry ?< ".")
+    (modify-syntax-entry ?= ".")
+    (modify-syntax-entry ?~ ".")
+    (modify-syntax-entry ?\n ">")
+    (modify-syntax-entry ?\' "\"")
+    (modify-syntax-entry ?\" "\"")
+    ;; _ needs to be part of a word, or the regular expressions will
+    ;; incorrectly regognize end_ to be matched by "\\<end\\>"!
+    (modify-syntax-entry ?_ "w")
+    (if (and lua-using-xemacs
+	     (featurep 'menubar)
+	     current-menubar
+	     (not (assoc "Lua" current-menubar)))
+	(progn
+	  (set-buffer-menubar (copy-sequence current-menubar))
+	  (add-menu nil "Lua" lua-xemacs-menu)))
+    ;; Append Lua menu to popup menu for XEmacs.
+    (if (and lua-using-xemacs (boundp 'mode-popup-menu))
+	(setq mode-popup-menu
+	      (cons (concat mode-name " Mode Commands") lua-xemacs-menu)))
+
+    ;; hideshow setup
+    (unless (assq 'lua-mode hs-special-modes-alist)
+      (add-to-list 'hs-special-modes-alist
+		   `(lua-mode  
+		     ,(regexp-opt (mapcar 'car lua-sexp-alist) 'words);start
+		     ,(regexp-opt (mapcar 'cdr lua-sexp-alist) 'words) ;end
+		     nil lua-forward-sexp)))
+    (run-hooks 'lua-mode-hook)))
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
+
+;;}}}
+;;{{{ lua-setup-keymap
+
+(defun lua-setup-keymap ()
+  "Set up keymap for Lua mode.
+If the variable `lua-prefix-key' is nil, the bindings go directly
+to `lua-mode-map', otherwise they are prefixed with `lua-prefix-key'."
+  (setq lua-mode-map (make-sparse-keymap))
+  (define-key lua-mode-map [menu-bar lua-mode]
+    (cons "Lua" lua-mode-menu))
+  (define-key lua-mode-map "}" 'lua-electric-match)
+  (define-key lua-mode-map "]" 'lua-electric-match)
+  (define-key lua-mode-map ")" 'lua-electric-match)
+  (let ((map (if lua-prefix-key
+                                          (make-sparse-keymap)
+                                        lua-mode-map)))
+
+         ;; communication
+         (define-key map "\M-[" 'lua-beginning-of-proc)
+         (define-key map "\M-]" 'lua-end-of-proc)
+         (define-key map "\C-c" 'comment-region)
+	 (define-key map "\C-l" 'lua-send-buffer)
+	 (define-key map "\C-f" 'lua-search-documentation)
+         (if lua-prefix-key
+                  (define-key lua-mode-map lua-prefix-key map))
+         ))
+
+;;}}}
+;;{{{ lua-electric-match
+
+(defun lua-electric-match (arg)
+  "Insert character and adjust indentation."
+  (interactive "P")
+  (insert-char last-command-char (prefix-numeric-value arg))
+  (if lua-electric-flag 
+      (lua-indent-line))
+  (blink-matching-open))
+
+;;}}}
+
+;;{{{ private functions
+(defun lua-syntax-status ()
+  "Returns the syntactic status of the character after the point."
+  (parse-partial-sexp (save-excursion (beginning-of-line) (point))
+		      (point)))
+
+
+(defun lua-string-p ()
+  "Returns true if the point is in a string."
+  (elt (lua-syntax-status) 3))
+
+(defun lua-comment-p ()
+  "Returns true if the point is in a comment."
+    (elt (lua-syntax-status) 4))
+
+(defun lua-comment-or-string-p ()
+  "Returns true if the point is in a comment or string."
+  (let ((parse-result (lua-syntax-status)))
+    (or (elt parse-result 3) (elt parse-result 4))))
+
+;;}}}
+;;{{{ lua-indent-line
+
+(defun lua-indent-line ()
+  "Indent current line for Lua mode.
+Return the amount the indentation changed by."
+  (let ((indent (max 0 (- (lua-calculate-indentation nil)
+			  (lua-calculate-indentation-left-shift))))
+	beg shift-amt
+	(case-fold-search nil)
+	(pos (- (point-max) (point))))
+    (beginning-of-line)
+    (setq beg (point))
+    (skip-chars-forward lua-indent-whitespace)
+    (setq shift-amt (- indent (current-column)))
+    (when (not (zerop shift-amt))
+      (delete-region beg (point))
+      (indent-to indent))
+    ;; If initial point was within line's indentation,
+    ;; position after the indentation.  Else stay at same point in text.
+    (if (> (- (point-max) pos) (point))
+	(goto-char (- (point-max) pos)))
+    shift-amt
+    indent))
+
+;;}}}
+;;{{{ lua-find-regexp
+
+(defun lua-find-regexp (direction regexp &optional limit ignore-p)
+  "Searches for a regular expression in the direction specified.
+Direction is one of 'forward and 'backward.
+By default, matches in comments and strings are ignored, but what to ignore is
+configurable by specifying ignore-p. If the regexp is found, returns point
+position, nil otherwise.
+ignore-p returns true if the match at the current point position should be
+ignored, nil otherwise."
+  (let ((ignore-func (or ignore-p 'lua-comment-or-string-p))
+	(search-func (if (eq direction 'forward)
+			 're-search-forward 're-search-backward))
+	(case-fold-search nil))
+    (catch 'found
+      (while (funcall search-func regexp limit t)
+	(if (not (funcall ignore-func))
+	    (throw 'found (point)))))))
+
+;;}}}
+;;{{{ lua-backwards-to-block-begin-or-end
+
+(defun lua-backwards-to-block-begin-or-end ()
+  "Move backwards to nearest block begin or end.  Returns nil if not successful."
+  (interactive)
+  (lua-find-regexp 'backward lua-block-regexp))
+
+;;}}}
+;;{{{ var. constants
+
+(defconst lua-block-regexp
+  (eval-when-compile
+    ;; This is the code we used to generate the regexp:
+    (concat
+     "\\(\\<"
+     (regexp-opt '("do" "function" "repeat" "then"
+		   "else" "elseif" "end" "until") t)
+     "\\>\\)\\|"
+     (regexp-opt '("{" "(" "[" "]" ")" "}") t))
+
+	))
+
+(defconst lua-block-token-alist
+  ;; The absence of "else" is deliberate. This construct in a way both
+  ;; opens and closes a block. As a result, it is difficult to handle
+  ;; cleanly. It is also ambiguous - if we are looking for the match
+  ;; of "else", should we look backward for "then/elseif" or forward
+  ;; for "end"?
+  ;; Maybe later we will find a way to handle it.
+  '(("do"       "\\<end\\>"                                   open)
+    ("function" "\\<end\\>"                                   open)
+    ("repeat"   "\\<until\\>"                                 open)
+    ("then"     "\\<\\(e\\(lseif\\|nd\\)\\)\\>"               open)
+    ("{"        "}"                                           open)
+    ("["        "]"                                           open)
+    ("("        ")"                                           open)
+    ("elseif"   "\\<then\\>"                                  close)
+    ("end"      "\\<\\(do\\|function\\|then\\)\\>"            close)
+    ("until"    "\\<repeat\\>"                                close)
+    ("}"        "{"                                           close)
+    ("]"        "\\["                                         close)
+    (")"        "("                                           close)))
+
+
+(defconst lua-indentation-modifier-regexp
+    ;; The absence of else is deliberate, since it does not modify the
+    ;; indentation level per se. It only may cause the line, in which the
+    ;; else is, to be shifted to the left.
+    ;; This is the code we used to generate the regexp:
+    (concat
+     "\\(\\<"
+     ; n.b. "local function" is a bit of a hack, allowing only a single space
+     (regexp-opt '("do" "local function" "function" "repeat" "then") t)
+     "\\>\\|"
+     (regexp-opt '("{" "(" "["))
+     "\\)\\|\\(\\<"
+     (regexp-opt '("elseif" "end" "until") t)
+     "\\>\\|"
+     (regexp-opt '("]" ")" "}"))
+     "\\)")
+
+    )
+
+;;}}}
+;;{{{ lua-find-matching-token-word
+
+(defun lua-find-matching-token-word (token search-start)
+  (let* ((token-info (assoc token lua-block-token-alist))
+	 (match (car (cdr token-info)))
+	 (match-type (car (cdr (cdr token-info))))
+	 (search-direction (if (eq match-type 'open) 'forward 'backward)))
+    ;; if we are searching forward from the token at the current point
+    ;; (i.e. for a closing token), need to step one character forward
+    ;; first, or the regexp will match the opening token.
+    (if (eq match-type 'open) (forward-char 1))
+    (if search-start (goto-char search-start))
+    (catch 'found
+      (while (lua-find-regexp search-direction lua-indentation-modifier-regexp)
+	;; have we found a valid matching token?
+	(let ((found-token (match-string 0))
+	      (found-pos (match-beginning 0)))
+	  (if (string-match match found-token)
+	      (throw 'found found-pos))
+	    ;; no - then there is a nested block. If we were looking for
+	    ;; a block begin token, found-token must be a block end
+	    ;; token; likewise, if we were looking for a block end token,
+	    ;; found-token must be a block begin token, otherwise there
+	    ;; is a grammatical error in the code.
+	    (if (not (and
+		      (eq (car (cdr (cdr (assoc found-token lua-block-token-alist))))
+			  match-type)
+		      (lua-find-matching-token-word found-token nil)))
+	      (throw 'found nil)))))))
+
+;;}}}
+;;{{{ lua-goto-matching-block-token 
+
+(defun lua-goto-matching-block-token (&optional search-start parse-start)
+  "Find block begion/end token matching the one at the point.
+This function moves the point to the token that matches the one
+at the current point. Returns the point position of the first character of
+the matching token if successful, nil otherwise."
+  (if parse-start (goto-char parse-start))
+  (let ((case-fold-search nil))
+    (if (looking-at lua-indentation-modifier-regexp)
+	(let ((position (lua-find-matching-token-word (match-string 0)
+						      search-start)))
+	  (and position
+	       (goto-char position))))))
+
+
+;; The following may be useful to speed up the search in the future.
+;      (let ((token-type (char-syntax (string-to-char token-to-match)))
+;	    matching-pos)
+;	(cond ((eq token-type ?\()
+;	       (setq matching-pos (scan-sexps (point) 1 (current-buffer) t))
+;	       (when matching-pos (goto-char matching-pos)))
+
+;	      ((eq token-type ?\))
+;	       ;; need to move one char forward, because scan-sexps
+;	       ;; expects the point to be one past the closing parenthesis
+;	       (forward-char 1)
+;	       (setq matching-pos (scan-sexps (point) -1 (current-buffer) t))
+;	       (when matching-pos (goto-char matching-pos)))
+
+;	      (t
+;	       (lua-goto-matching-token-word token-to-match search-start)))))))
+
+
+;;}}}
+;;{{{ lua-goto-matching-block
+
+(defun lua-goto-matching-block (&optional noreport)
+  "Go to the keyword balancing the one under the point.
+If the point is on a keyword/brace that starts a block, go to the
+matching keyword that ends the block, and vice versa."
+  (interactive)
+  ;; search backward to the beginning of the keyword if necessary
+  (if (eq (char-syntax (following-char)) ?w)
+      (re-search-backward "\\<" nil t))
+  (let ((position (lua-goto-matching-block-token)))
+    (if (and (not position)
+	     (not noreport))
+	(error "Not on a block control keyword or brace.")
+      position)))
+
+;;}}}
+;;{{{ lua-goto-nonblank-previous-line
+
+(defun lua-goto-nonblank-previous-line ()
+  "Puts the point at the first previous line that is not blank.
+Returns the point, or nil if it reached the beginning of the buffer"
+  (catch 'found
+    (beginning-of-line)
+    (while t
+      (if (bobp) (throw 'found nil))
+      (forward-char -1)
+      (beginning-of-line)
+      (if (not (looking-at "\\s *\\(--.*\\)?$")) (throw 'found (point))))))
+
+;;}}}
+;;{{{ lua-goto-nonblank-next-line
+
+(defun lua-goto-nonblank-next-line ()
+  "Puts the point at the first next line that is not blank.
+Returns the point, or nil if it reached the end of the buffer"
+  (catch 'found
+    (end-of-line)
+    (while t
+      (forward-line)
+      (if (eobp) (throw 'found nil))
+      (beginning-of-line)
+      (if (not (looking-at "\\s *\\(--.*\\)?$")) (throw 'found (point))))))
+
+(eval-when-compile
+  (defconst lua-operator-class
+    "-+*/^.=<>~"))
+
+;;}}}
+;;{{{ var. constans
+
+(defconst lua-cont-eol-regexp
+  (eval-when-compile
+    ;; expression used to generate the regexp
+    (concat
+     "\\(\\<"
+     (regexp-opt '("and" "or" "not" "in" "for" "while"
+		   "local" "function") t)
+     "\\>\\|"
+     "\\(^\\|[^" lua-operator-class "]\\)"
+     (regexp-opt '("+" "-" "*" "/" "^" ".." "==" "=" "<" ">" "<=" ">=" "~=") t)
+     "\\)"
+     "\\s *\\=")
+
+    ))
+
+
+(defconst lua-cont-bol-regexp
+  (eval-when-compile
+    ;; expression used to generate the regexp
+    (concat
+     "\\=\\s *"
+     "\\(\\<"
+     (regexp-opt '("and" "or" "not") t)
+     "\\>\\|"
+     (regexp-opt '("+" "-" "*" "/" "^" ".." "==" "=" "<" ">" "<=" ">=" "~=") t)
+     "\\($\\|[^" lua-operator-class "]\\)"
+     "\\)")
+
+    ))
+
+;;}}}
+;;{{{ lua-last-token-continues-p
+
+(defun lua-last-token-continues-p ()
+  "Returns true if the last token on this line is a continuation token."
+  (let (line-begin
+	line-end)
+    (save-excursion
+      (beginning-of-line)
+      (setq line-begin (point))
+      (end-of-line)
+      (setq line-end (point))
+      ;; we need to check whether the line ends in a comment and
+      ;; skip that one.
+      (while (lua-find-regexp 'backward "-" line-begin 'lua-string-p)
+	(if (looking-at "--")
+	    (setq line-end (point))))
+      (goto-char line-end)
+      (re-search-backward lua-cont-eol-regexp line-begin t))))
+
+;;}}}
+;;{{{ lua-first-token-continues-p
+
+(defun lua-first-token-continues-p ()
+  "Returns true if the first token on this line is a continuation token."
+  (let (line-end)
+    (save-excursion
+      (end-of-line)
+      (setq line-end (point))
+      (beginning-of-line)
+      (re-search-forward lua-cont-bol-regexp line-end t))))
+
+;;}}}
+;;{{{ lua-is-continuing-statement-p
+
+(defun lua-is-continuing-statement-p (&optional parse-start)
+  "Return nonnil if the line continues a statement.
+More specifically, return the point in the line that is continued.
+The criteria for a continuing statement are:
+
+* the last token of the previous line is a continuing op,
+  OR the first token of the current line is a continuing op
+
+"
+  (let ((prev-line nil))
+    (save-excursion
+      (if parse-start (goto-char parse-start))
+      (save-excursion (setq prev-line (lua-goto-nonblank-previous-line)))
+      (and prev-line
+	   (or (lua-first-token-continues-p)
+	       (and (goto-char prev-line)
+		    ;; check last token of previous nonblank line
+		    (lua-last-token-continues-p)))))))
+
+;;}}}
+;;{{{ lua-make-indentation-info-pair
+
+(defun lua-make-indentation-info-pair ()
+  "This is a helper function to lua-calculate-indentation-info. Don't
+use standalone."
+  (cond ((string-equal found-token "function")
+	 ;; this is the location where we need to start searching for the
+	 ;; matching opening token, when we encounter the next closing token.
+	 ;; It is primarily an optimization to save some searchingt ime.
+	 (cons 'absolute (+ (save-excursion (goto-char found-pos)
+					    (current-column))
+			    lua-indent-level)))
+	((or (string-equal found-token "{")
+         (string-equal found-token "("))
+	 (save-excursion 
+	   ;; expression follows -> indent at start of next expression
+	   (if (and (not (search-forward-regexp "[[:space:]]--" (line-end-position) t))
+		    (search-forward-regexp "[^[:space:]]" (line-end-position) t))
+	       	 (cons 'absolute (1- (current-column)))
+	     	 (cons 'relative lua-indent-level))))
+	;; closing tokens follow
+	((string-equal found-token "end")
+	 (save-excursion
+	   (lua-goto-matching-block-token nil found-pos)
+	   (if (looking-at "\\<function\\>")
+	       (cons 'absolute
+		     (+ (current-indentation)
+			(lua-calculate-indentation-block-modifier
+			 nil (point))))
+	     (cons 'relative (- lua-indent-level)))))
+	((or (string-equal found-token ")")
+	     (string-equal found-token "}"))
+	 (save-excursion
+	   (lua-goto-matching-block-token nil found-pos)
+	   (cons 'absolute
+		 (+ (current-indentation)
+		    (lua-calculate-indentation-block-modifier
+		     nil (point))))))
+	(t
+	 (cons 'relative (if (nth 2 (match-data))
+			     ;; beginning of a block matched
+			     lua-indent-level
+			   ;; end of a block matched
+			   (- lua-indent-level))))))
+
+
+;;}}}
+;;{{{ lua-calculate-indentation-info
+
+(defun lua-calculate-indentation-info (&optional parse-start parse-end)
+  "For each block token on the line, computes how it affects the indentation.
+The effect of each token can be either a shift relative to the current
+indentation level, or indentation to some absolute column. This information
+is collected in a list of indentation info pairs, which denote absolute
+and relative each, and the shift/column to indent to."
+  (let* ((line-end (save-excursion (end-of-line) (point)))
+	 (search-stop (if parse-end (min parse-end line-end) line-end))
+	 (indentation-info nil))
+    (if parse-start (goto-char parse-start))
+    (save-excursion
+      (beginning-of-line)
+      (while (lua-find-regexp 'forward lua-indentation-modifier-regexp
+			      search-stop)
+	(let ((found-token (match-string 0))
+	      (found-pos (match-beginning 0))
+	      (found-end (match-end 0))
+	      (data (match-data)))
+	  (setq indentation-info
+		(cons (lua-make-indentation-info-pair) indentation-info)))))
+    indentation-info))
+
+;;}}}
+;;{{{ lua-accumulate-indentation-info
+
+(defun lua-accumulate-indentation-info (info)
+  "Accumulates the indentation information previously calculated by
+lua-calculate-indentation-info. Returns either the relative indentation
+shift, or the absolute column to indent to."
+  (let ((info-list (reverse info))
+	(type 'relative)
+	(accu 0))
+    (mapcar (lambda (x)
+	    (setq accu (if (eq 'absolute (car x))
+			   (progn (setq type 'absolute)
+				  (cdr x))
+			 (+ accu (cdr x)))))
+	  info-list)
+    (cons type accu)))
+
+;;}}}
+;;{{{ lua-calculate-indentation-block-modifier
+
+(defun lua-calculate-indentation-block-modifier (&optional parse-start
+							   parse-end)
+  "Return amount by which this line modifies the indentation.
+Beginnings of blocks add lua-indent-level once each, and endings
+of blocks subtract lua-indent-level once each. This function is used
+to determine how the indentation of the following line relates to this
+one."
+  (if parse-start (goto-char parse-start))
+  (let ((case-fold-search nil)
+	(indentation-info (lua-accumulate-indentation-info
+			   (lua-calculate-indentation-info nil parse-end))))
+    (if (eq (car indentation-info) 'absolute)
+	(- (cdr indentation-info)
+	   (current-indentation)
+	   ;; reduce indentation if this line also starts new continued statement 
+	   ;; or next line cont. this line
+	   ;;This is for aesthetic reasons: the indentation should be
+	   ;;dosomething(d +
+	   ;;   e + f + g)
+	   ;;not
+	   ;;dosomething(d +
+	   ;;      e + f + g)"
+	   (save-excursion
+	     (or (and (lua-last-token-continues-p) lua-indent-level)
+		 (and (lua-goto-nonblank-next-line) (lua-first-token-continues-p) lua-indent-level)
+		 0)))
+      (+ (lua-calculate-indentation-left-shift)
+	 (cdr indentation-info)
+	 (if (lua-is-continuing-statement-p) (- lua-indent-level) 0)))))
+;;}}}
+;;{{{ constants
+
+(defconst lua-left-shift-regexp-1
+  (concat "\\("
+	  "\\(\\<" (regexp-opt '("else" "elseif" "until") t)
+	  "\\>\\)\\($\\|\\s +\\)"
+	  "\\)"))
+
+(defconst lua-left-shift-regexp-2
+  (concat "\\(\\<"
+	  (regexp-opt '("end") t)
+	  "\\>\\)"))
+
+
+(defconst lua-left-shift-regexp
+  ;; This is the code we used to generate the regexp:
+  ;; ("else", "elseif", "until" followed by whitespace, or "end"/closing
+  ;; brackets followed by
+  ;; whitespace, punctuation, or closing parentheses)
+  (concat lua-left-shift-regexp-1
+	  "\\|\\(\\("
+	  lua-left-shift-regexp-2
+	  "\\|\\("
+	  (regexp-opt '("]" "}" ")"))
+	  "\\)\\)\\($\\|\\(\\s \\|\\s.\\)*\\)"
+	  "\\)"))
+
+(defconst lua-left-shift-pos-1
+  2)
+
+(defconst lua-left-shift-pos-2
+  (+ 3 (regexp-opt-depth lua-left-shift-regexp-1)))
+
+(defconst lua-left-shift-pos-3
+  (+ lua-left-shift-pos-2
+     (regexp-opt-depth lua-left-shift-regexp-2)))
+
+;;}}} 
+;;{{{ lua-calculate-indentation-left-shift
+
+(defun lua-calculate-indentation-left-shift (&optional parse-start)
+  "Return amount, by which this line should be shifted left.
+Look for an uninterrupted sequence of block-closing tokens that starts
+at the beginning of the line. For each of these tokens, shift indentation
+to the left by the amount specified in lua-indent-level."
+  (let (line-begin
+	(indentation-modifier 0)
+	(case-fold-search nil)
+	(block-token nil))
+    (save-excursion
+      (if parse-start (goto-char parse-start))
+      (beginning-of-line)
+      (setq line-begin (point))
+      ;; Look for the block-closing token sequence
+      (skip-chars-forward lua-indent-whitespace)
+      (catch 'stop
+	(while (and (looking-at lua-left-shift-regexp)
+		    (not (lua-comment-or-string-p)))
+	  (let ((last-token (or (match-string lua-left-shift-pos-1)
+				(match-string lua-left-shift-pos-2)
+				(match-string lua-left-shift-pos-3))))
+	    (if (not block-token) (setq block-token last-token))
+	    (if (not (string-equal block-token last-token)) (throw 'stop nil))
+	    (setq indentation-modifier (+ indentation-modifier
+					  lua-indent-level))
+		(forward-char (length (match-string 0))))))
+      indentation-modifier)))
+
+;;}}}
+;;{{{ lua-calculate-indentation
+
+(defun lua-calculate-indentation (&optional parse-start)
+  "Return appropriate indentation for current line as Lua code.
+In usual case returns an integer: the column to indent to."
+  (let ((pos (point))
+	shift-amt)
+    (save-excursion
+      (if parse-start (setq pos (goto-char parse-start)))
+      (beginning-of-line)
+      (setq shift-amt (if (lua-is-continuing-statement-p) lua-indent-level 0))
+      (if (bobp)          ; If we're at the beginning of the buffer, no change.
+	  (+ (current-indentation) shift-amt)
+	;; This code here searches backwards for a "block beginning/end"
+	;; It snarfs the indentation of that, plus whatever amount the
+	;; line was shifted left by, because of block end tokens. It
+	;; then adds the indentation modifier of that line to obtain the
+	;; final level of indentation.
+	;; Finally, if this line continues a statement from the
+	;; previous line, add another level of indentation.
+	(if (lua-backwards-to-block-begin-or-end)
+	    ;; now we're at the line with block beginning or end.
+	    (max (+ (current-indentation)
+		    (lua-calculate-indentation-block-modifier)
+		    shift-amt)
+		 0)
+	  ;; Failed to find a block begin/end.
+	  ;; Just use the previous line's indent.
+	  (goto-char pos)
+	  (beginning-of-line)
+	  (forward-line -1)
+	  (+ (current-indentation) shift-amt))))))
+
+;;}}}
+;;{{{ lua-beginning-of-proc
+
+(defun lua-beginning-of-proc (&optional arg)
+  "Move backward to the beginning of a lua proc (or similar).
+With argument, do it that many times.  Negative arg -N
+means move forward to Nth following beginning of proc.
+Returns t unless search stops due to beginning or end of buffer."
+  (interactive "P")
+  (or arg
+      (setq arg 1))
+  (let ((found nil)
+                  (ret t))
+    (if (and (< arg 0)
+                                 (looking-at "^function[ \t]"))
+                  (forward-char 1))
+    (while (< arg 0)
+      (if (re-search-forward "^function[ \t]" nil t)
+                         (setq arg (1+ arg)
+                                         found t)
+                  (setq ret nil
+                                  arg 0)))
+    (if found
+                  (beginning-of-line))
+    (while (> arg 0)
+      (if (re-search-backward "^function[ \t]" nil t)
+                         (setq arg (1- arg))
+                  (setq ret nil
+                                  arg 0)))
+    ret))
+
+;;}}}
+;;{{{ lua-end-of-proc
+
+(defun lua-end-of-proc (&optional arg)
+  "Move forward to next end of lua proc (or similar).
+With argument, do it that many times.  Negative argument -N means move
+back to Nth preceding end of proc.
+
+This function just searches for a `end' at the beginning of a line."
+  (interactive "P")
+  (or arg
+      (setq arg 1))
+  (let ((found nil)
+	(ret t))
+    (if (and (< arg 0)
+	     (not (bolp))
+	     (save-excursion
+	       (beginning-of-line)
+	       (eq (following-char) ?})))
+	(forward-char -1))
+    (while (> arg 0)
+      (if (re-search-forward "^end" nil t)
+	  (setq arg (1- arg)
+		found t)
+	(setq ret nil
+	      arg 0)))
+    (while (< arg 0)
+      (if (re-search-backward "^end" nil t)
+	  (setq arg (1+ arg)
+		found t)
+	(setq ret nil
+	      arg 0)))
+    (if found
+	(end-of-line))
+    ret))
+
+;;}}}
+;;{{{ lua-start-process
+
+(defun lua-start-process (name &optional program startfile &rest switches)
+  "Start a lua process named NAME, running PROGRAM."
+  (or switches
+      (setq switches lua-default-command-switches))
+  (setq program (or program name))
+  (setq lua-process-buffer (apply 'make-comint name program startfile switches))
+  (setq lua-process (get-buffer-process lua-process-buffer))
+  ;; wait for prompt
+  (with-current-buffer lua-process-buffer
+    (while (not (lua-prompt-line))
+      (accept-process-output (get-buffer-process (current-buffer)))
+      (goto-char (point-max)))))
+
+;;}}}
+;;{{{ lua-kill-process
+
+(defun lua-kill-process ()
+  "Kill lua subprocess and its buffer."
+  (interactive)
+  (if lua-process-buffer
+      (kill-buffer lua-process-buffer)))
+
+;;}}}
+;;{{{ lua-set-lua-region-start
+
+(defun lua-set-lua-region-start (&optional arg)
+  "Set start of region for use with `lua-send-lua-region'."
+  (interactive)
+  (set-marker lua-region-start (or arg (point))))
+
+;;}}}
+;;{{{ lua-set-lua-region-end
+
+(defun lua-set-lua-region-end (&optional arg)
+  "Set end of region for use with `lua-send-lua-region'."
+  (interactive)
+  (set-marker lua-region-end (or arg (point))))
+
+;;}}}
+;;{{{ lua-send-current-line
+
+(defun lua-send-current-line ()
+  "Send current line to lua subprocess, found in `lua-process'.
+If `lua-process' is nil or dead, start a new process first."
+  (interactive)
+  (let ((start (save-excursion (beginning-of-line) (point)))
+        (end (save-excursion (end-of-line) (point))))
+    (lua-send-region start end)))
+
+;;}}}
+;;{{{ lua-send-region
+
+(defun lua-send-region (start end)
+  "Send region to lua subprocess."
+  (interactive "r")
+  ;; make temporary lua file
+  (let ((tempfile (lua-make-temp-file "lua-"))
+	(last-prompt nil)
+	(prompt-found nil)
+	(lua-stdin-line-offset (count-lines (point-min) start))
+	(lua-stdin-buffer (current-buffer))
+	current-prompt )
+    (write-region start end tempfile)
+    (or (and lua-process
+	     (comint-check-proc lua-process-buffer))
+	(lua-start-process lua-default-application))
+    ;; kill lua process without query
+    (if (fboundp 'process-kill-without-query) 
+	(process-kill-without-query lua-process)) 
+    ;; send dofile(tempfile)
+    (with-current-buffer lua-process-buffer   
+      (goto-char (point-max))
+      (setq last-prompt (point-max))
+      (comint-simple-send (get-buffer-process (current-buffer)) 
+			  (format "dofile(\"%s\")"  
+				  (replace-in-string tempfile "\\\\" "\\\\\\\\" )))
+      ;; wait for prompt
+      (while (not prompt-found) 
+	(accept-process-output (get-buffer-process (current-buffer)))
+	(goto-char (point-max))
+	(setq prompt-found (and (lua-prompt-line) (< last-prompt (point-max)))))
+    ;; remove temp. lua file
+    (delete-file tempfile)
+    (lua-postprocess-output-buffer lua-process-buffer last-prompt lua-stdin-line-offset)    
+    (if lua-always-show
+	(display-buffer lua-process-buffer)))))
+
+;;}}}
+;;{{{ lua-postprocess-output-buffer
+
+(defun lua-postprocess-output-buffer (buf start &optional lua-stdin-line-offset)
+  "Highlight tracebacks found in buf. If an traceback occurred return
+t, otherwise return nil.  BUF must exist."
+  (let ((lua-stdin-line-offset (or lua-stdin-line-offset 0))
+	line file bol err-p)
+    (save-excursion
+      (set-buffer buf)
+      (goto-char start)
+      (beginning-of-line)
+      (if (re-search-forward lua-traceback-line-re nil t)
+	  (setq file (match-string 1)
+		line (string-to-int (match-string 2)))))
+    (when (and lua-jump-on-traceback line)
+      (beep)
+      ;; TODO: highlight
+      (lua-jump-to-traceback file line lua-stdin-line-offset)
+      (setq err-p t))
+    err-p))
+  
+;;}}}
+;;{{{ lua-jump-to-tracebackw
+
+(defun lua-jump-to-traceback (file line lua-stdin-line-offset)
+  "Jump to the Lua code in FILE at LINE."
+  ;; sanity check: temporary-file-directory
+  (if (string= (substring file 0 3)  "...")
+      (message "Lua traceback output truncated: customize 'temporary-file-directory' or increase 'LUA_IDSIZE' in 'luaconf.h'.")
+    (let ((buffer (cond ((or (string-equal file tempfile) (string-equal file "stdin"))
+		       (setq line (+ line lua-stdin-line-offset))
+		       lua-stdin-buffer)
+			(t (find-file-noselect file)))))
+      (pop-to-buffer buffer)
+      ;; Force Lua mode
+      (if (not (eq major-mode 'lua-mode))
+	  (lua-mode))
+      ;; TODO fix offset when executing region
+      (goto-line line)			
+      (message "Jumping to error in file %s on line %d" file line))))
+
+;;}}}
+;;{{{ lua-prompt-line
+
+(defun lua-prompt-line ()
+  (save-excursion 
+    (save-match-data
+      (forward-line 0)
+      (if (looking-at comint-prompt-regexp)
+	  (match-end 0)))))
+
+;;{{{ lua-send-lua-region
+;;}}}
+
+(defun lua-send-lua-region ()
+  "Send preset lua region to lua subprocess."
+  (interactive)
+  (or (and lua-region-start lua-region-end)
+      (error "lua-region not set"))
+  (or (and lua-process
+           (comint-check-proc lua-process-buffer))
+      (lua-start-process lua-default-application))
+  (comint-simple-send lua-process
+                              (buffer-substring lua-region-start lua-region-end)
+)
+  (if lua-always-show
+      (display-buffer lua-process-buffer)))
+
+;;}}}
+;;{{{ lua-send-proc
+
+(defun lua-send-proc ()
+  "Send proc around point to lua subprocess."
+  (interactive)
+  (let (beg end)
+    (save-excursion
+      (lua-beginning-of-proc)
+      (setq beg (point))
+      (lua-end-of-proc)
+      (setq end (point)))
+    (or (and lua-process
+             (comint-check-proc lua-process-buffer))
+        (lua-start-process lua-default-application))
+    (comint-simple-send lua-process
+                                (buffer-substring beg end))
+    (if lua-always-show
+        (display-buffer lua-process-buffer))))
+
+;;}}}
+;;{{{ lua-send-buffer
+
+; This needs work... -Bret
+(defun lua-send-buffer ()
+  "Send whole buffer to lua subprocess."
+  (interactive)
+  (lua-send-region (point-min) (point-max)))
+
+;;}}}
+;;{{{ lua-restart-with-whole-file
+
+(defun lua-restart-with-whole-file ()
+  "Restart lua subprocess and send whole file as input."
+  (interactive)
+  (lua-kill-process)
+  (lua-start-process lua-default-application)
+  (lua-send-buffer))
+
+;;}}}
+;;{{{ lua-show-process-buffer
+
+(defun lua-show-process-buffer ()
+  "Make sure `lua-process-buffer' is being displayed."
+  (interactive)
+  (display-buffer lua-process-buffer))
+
+;;}}}
+;;{{{ lua-hide-process-buffer
+
+(defun lua-hide-process-buffer ()
+  "Delete all windows that display `lua-process-buffer'."
+  (interactive)
+  (delete-windows-on lua-process-buffer))
+
+;;}}}
+;;{{{ lua-search-documentation
+
+(defun lua-search-documentation ()
+  "Search Lua documentation for the word at the point."
+  (interactive)
+  (browse-url (concat lua-search-url-prefix (current-word t))))
+
+;;}}}
+;;{{{ lua-calculate-state
+
+(defun lua-calculate-state (arg prevstate)
+  ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
+  ;; arg is nil or zero, toggle the state. If arg is negative, turn
+  ;; the state off, and if arg is positive, turn the state on
+  (if (or (not arg)
+	  (zerop (setq arg (prefix-numeric-value arg))))
+      (not prevstate)
+    (> arg 0)))
+
+;;}}}
+;;{{{ lua-toggle-electric-state
+
+(defun lua-toggle-electric-state (&optional arg)
+  "Toggle the electric indentation feature.
+Optional numeric ARG, if supplied, turns on electric indentation when
+positive, turns it off when negative, and just toggles it when zero or
+left out."
+  (interactive "P")
+  (setq lua-electric-flag (lua-calculate-state arg lua-electric-flag)))
+
+;;}}}
+;;{{{ lua-forward-sexp
+
+(defun lua-forward-sexp (&optional count)
+ "Forward to block end"
+ (interactive "p")
+ (save-match-data
+ (let* ((count (or count 1))
+	(stackheight 0)
+	(block-start (mapcar 'car lua-sexp-alist))
+	(block-end (mapcar 'cdr lua-sexp-alist))
+	(block-regex (regexp-opt (append  block-start block-end) 'words))
+	current-exp
+	)
+   (while (> count 0)
+     ;; skip whitespace
+     (skip-chars-forward " \t\n")
+     (if (looking-at (regexp-opt block-start 'words)) 
+	 (let ((keyword (match-string 1)))
+	   (lua-find-matching-token-word keyword nil))
+       ;; If the current keyword is not a "begin" keyword, then just
+       ;; perform the normal forward-sexp.
+       (forward-sexp 1))
+     (setq count (1- count))))))
+
+
+;;}}}
+;;{{{ menu bar
+
+(define-key lua-mode-menu [restart-with-whole-file]
+  '("Restart With Whole File" .  lua-restart-with-whole-file))
+(define-key lua-mode-menu [kill-process]
+  '("Kill Process" . lua-kill-process))
+
+(define-key lua-mode-menu [hide-process-buffer]
+  '("Hide Process Buffer" . lua-hide-process-buffer))
+(define-key lua-mode-menu [show-process-buffer]
+  '("Show Process Buffer" . lua-show-process-buffer))
+
+(define-key lua-mode-menu [end-of-proc]
+  '("End Of Proc" . lua-end-of-proc))
+(define-key lua-mode-menu [beginning-of-proc]
+  '("Beginning Of Proc" . lua-beginning-of-proc))
+
+(define-key lua-mode-menu [send-lua-region]
+  '("Send Lua-Region" . lua-send-lua-region))
+(define-key lua-mode-menu [set-lua-region-end]
+  '("Set Lua-Region End" . lua-set-lua-region-end))
+(define-key lua-mode-menu [set-lua-region-start]
+  '("Set Lua-Region Start" . lua-set-lua-region-start))
+
+(define-key lua-mode-menu [send-current-line]
+  '("Send Current Line" . lua-send-current-line))
+(define-key lua-mode-menu [send-region]
+  '("Send Region" . lua-send-region))
+(define-key lua-mode-menu [send-proc]
+  '("Send Proc" . lua-send-proc))
+(define-key lua-mode-menu [send-buffer]
+  '("Send Buffer" . lua-send-buffer))
+(define-key lua-mode-menu [search-documentation]
+  '("Search Documentation" . lua-search-documentation))
+
+;;}}}
+
+(provide 'lua-mode)
+
+
+;;{{{ Emacs local variables
+
+;; Local Variables:
+;; folded-file: t
+;; End:
+
+;;}}}
+
+;;; lua-mode.el ends here

Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.c	Tue Apr 29 19:34:26 2008
@@ -33,16 +33,27 @@
 #include "lua.h"
 #include <lauxlib.h>
 #include <lualib.h>
+#include "mod_lua_extra.h"
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load);
 SWITCH_MODULE_DEFINITION(mod_lua, mod_lua_load, NULL, NULL);
 
 static struct {
 	switch_memory_pool_t *pool;
+	char *xml_handler;
 } globals;
 
 int luaopen_freeswitch(lua_State* L);
 
+static int panic (lua_State *L) 
+{
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "unprotected error in call to Lua API (%s)\n",
+					  lua_tostring(L, -1));
+
+	return 0;
+}
+
+
 static lua_State *lua_init(void) 
 {
 	lua_State *L = lua_open();
@@ -51,6 +62,7 @@
 		luaL_openlibs(L);
 		luaopen_freeswitch(L);
 		lua_gc(L, LUA_GCRESTART, 0);
+		lua_atpanic(L, panic);
  	}
 	return L;
 }
@@ -144,6 +156,11 @@
 	char *input_code = (char *) obj;
 	lua_State *L = lua_init();	 /* opens Lua */
 
+	//switch_event_t *event;
+	//switch_event_create(&event, SWITCH_EVENT_MESSAGE);
+	//switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "testing", "1234");
+	//mod_lua_conjure_event(L, event, "blah");
+
 	lua_parse_and_execute(L, input_code);
 	
 	if (input_code) {
@@ -155,6 +172,96 @@
 	return NULL;
 }
 
+
+static switch_xml_t lua_fetch(const char *section, 
+							  const char *tag_name, 
+							  const char *key_name, 
+							  const char *key_value, 
+							  switch_event_t *params,
+							  void *user_data)
+{
+
+	switch_xml_t xml = NULL;
+
+	if (!switch_strlen_zero(globals.xml_handler)) {
+		lua_State *L = lua_init();
+		char *mycmd = strdup(globals.xml_handler);
+		const char *str;
+
+		switch_assert(mycmd);
+
+		lua_newtable(L);
+
+		lua_pushstring(L, "section");
+		lua_pushstring(L, switch_str_nil(section));
+		lua_rawset(L, -3);
+		lua_pushstring(L, "tag_name");
+		lua_pushstring(L, switch_str_nil(tag_name));
+		lua_rawset(L, -3);
+		lua_pushstring(L, "key_name");
+		lua_pushstring(L, switch_str_nil(key_name));
+		lua_rawset(L, -3);
+		lua_pushstring(L, "key_value");
+		lua_pushstring(L, switch_str_nil(key_value));
+		lua_rawset(L, -3);
+		lua_setglobal(L, "XML_REQUEST");
+
+		if (params) {
+			mod_lua_conjure_event(L, params, "params", 1);
+		}
+
+		lua_parse_and_execute(L, mycmd);
+
+		lua_getfield(L, LUA_GLOBALSINDEX, "XML_STRING");
+		str = lua_tostring(L, 1);
+
+		if (str) {
+			if (switch_strlen_zero(str)) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Result\n");
+			} else if (!(xml = switch_xml_parse_str((char *)str, strlen(str)))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing XML Result!\n");
+			}
+		}
+		
+		lua_uninit(L);
+		free(mycmd);
+	}
+
+	return xml;
+}
+
+
+static switch_status_t do_config(void)
+{
+	char *cf = "lua.conf";
+	switch_xml_t cfg, xml, settings, param;
+
+	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+		return SWITCH_STATUS_TERM;
+	}
+
+	if ((settings = switch_xml_child(cfg, "settings"))) {
+		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+			char *var = (char *) switch_xml_attr_soft(param, "name");
+			char *val = (char *) switch_xml_attr_soft(param, "value");
+
+			if (!strcmp(var, "xml-handler-script")) {
+				globals.xml_handler = switch_core_strdup(globals.pool, val);
+			} else if (!strcmp(var, "xml-handler-bindings")) {
+				if (!switch_strlen_zero(globals.xml_handler)) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "binding '%s' to '%s'\n", globals.xml_handler, val);
+					switch_xml_bind_search_function(lua_fetch, switch_xml_parse_section_string(val), NULL);
+				}
+			}
+		}
+	}
+
+	switch_xml_free(xml);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
 int lua_thread(const char *text)
 {
 	switch_thread_t *thread;
@@ -172,20 +279,36 @@
 {
 	lua_State *L = lua_init();
 	char code[1024] = "";
-	snprintf(code, sizeof(code), "~session = LUASession:new(\"%s\");", switch_core_session_get_uuid(session));
+	snprintf(code, sizeof(code), "~session = freeswitch.Session(\"%s\");", switch_core_session_get_uuid(session));
 	lua_parse_and_execute(L, code);
 	lua_parse_and_execute(L, (char *) data);
-	snprintf(code, sizeof(code), "~session:delete()");
-	lua_parse_and_execute(L, code);
 	lua_uninit(L);
 }
 
-SWITCH_STANDARD_API(lua_api_function) {
+SWITCH_STANDARD_API(luarun_api_function) {
 	lua_thread(cmd);
 	stream->write_function(stream, "+OK\n");
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
+SWITCH_STANDARD_API(lua_api_function) {
+
+	lua_State *L = lua_init();
+	char *mycmd = strdup(cmd);
+
+	switch_assert(mycmd);
+	mod_lua_conjure_stream(L, stream, "stream", 1);
+	if (stream->event) {
+		mod_lua_conjure_event(L, stream->event, "env", 1);
+	}
+
+	lua_parse_and_execute(L, mycmd);
+	lua_uninit(L);
+	free(mycmd);
+	return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
 {
 	switch_api_interface_t *api_interface;
@@ -194,12 +317,14 @@
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
-	SWITCH_ADD_API(api_interface, "luarun", "run a script", lua_api_function, "<script>");
+	SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function, "<script>");
+	SWITCH_ADD_API(api_interface, "lua", "run a script as an api function", lua_api_function, "<script>");
 	SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
-
+	
 	globals.pool = pool;
+	do_config();
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;

Added: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.c	Tue Apr 29 19:34:26 2008
@@ -0,0 +1,21 @@
+SWITCH_BEGIN_EXTERN_C
+
+
+int mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me)
+{
+	Event *result = new Event(event);
+	SWIG_NewPointerObj(L,result,SWIGTYPE_p_Event, destroy_me);
+	lua_setglobal(L, name);
+}
+
+
+int mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me)
+{
+	Stream *result = new Stream(stream);
+	SWIG_NewPointerObj(L,result,SWIGTYPE_p_Stream, destroy_me);
+	lua_setglobal(L, name);
+}
+
+
+
+SWITCH_END_EXTERN_C

Added: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.h	Tue Apr 29 19:34:26 2008
@@ -0,0 +1,9 @@
+#ifndef MOD_LUA_EXTRA
+#define MOD_LUA_EXTRA
+SWITCH_BEGIN_EXTERN_C
+
+int mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me);
+int mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me);
+
+SWITCH_END_EXTERN_C
+#endif

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	Tue Apr 29 19:34:26 2008
@@ -1493,15 +1493,16 @@
 #define SWIGTYPE_p_switch_channel_state_t swig_types[6]
 #define SWIGTYPE_p_switch_channel_t swig_types[7]
 #define SWIGTYPE_p_switch_core_session_t swig_types[8]
-#define SWIGTYPE_p_switch_input_args_t swig_types[9]
-#define SWIGTYPE_p_switch_input_type_t swig_types[10]
-#define SWIGTYPE_p_switch_priority_t swig_types[11]
-#define SWIGTYPE_p_switch_size_t swig_types[12]
-#define SWIGTYPE_p_switch_status_t swig_types[13]
-#define SWIGTYPE_p_switch_stream_handle_t swig_types[14]
-#define SWIGTYPE_p_void swig_types[15]
-static swig_type_info *swig_types[17];
-static swig_module_info swig_module = {swig_types, 16, 0, 0, 0, 0};
+#define SWIGTYPE_p_switch_event_t swig_types[9]
+#define SWIGTYPE_p_switch_input_args_t swig_types[10]
+#define SWIGTYPE_p_switch_input_type_t swig_types[11]
+#define SWIGTYPE_p_switch_priority_t swig_types[12]
+#define SWIGTYPE_p_switch_size_t swig_types[13]
+#define SWIGTYPE_p_switch_status_t swig_types[14]
+#define SWIGTYPE_p_switch_stream_handle_t swig_types[15]
+#define SWIGTYPE_p_void swig_types[16]
+static swig_type_info *swig_types[18];
+static swig_module_info swig_module = {swig_types, 17, 0, 0, 0, 0};
 #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
 #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
 
@@ -1612,44 +1613,6 @@
 }
 
 
-static int _wrap_process_callback_result(lua_State* L) {
-  int SWIG_arg = -1;
-  char *arg1 = (char *) 0 ;
-  input_callback_state *arg2 = (input_callback_state *) 0 ;
-  switch_core_session_t *arg3 = (switch_core_session_t *) 0 ;
-  switch_status_t result;
-  
-  SWIG_check_num_args("process_callback_result",3,3)
-  if(!lua_isstring(L,1)) SWIG_fail_arg("process_callback_result",1,"char *");
-  if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("process_callback_result",2,"input_callback_state *");
-  if(!SWIG_isptrtype(L,3)) SWIG_fail_arg("process_callback_result",3,"switch_core_session_t *");
-  arg1 = (char *)lua_tostring(L, 1);
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&arg2,SWIGTYPE_p_input_callback_state,0))){
-    SWIG_fail_ptr("process_callback_result",2,SWIGTYPE_p_input_callback_state);
-  }
-  
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,3,(void**)&arg3,SWIGTYPE_p_switch_core_session_t,0))){
-    SWIG_fail_ptr("process_callback_result",3,SWIGTYPE_p_switch_core_session_t);
-  }
-  
-  result = process_callback_result(arg1,arg2,arg3);
-  SWIG_arg=0;
-  {
-    switch_status_t * resultptr = new switch_status_t((switch_status_t &) result);
-    SWIG_NewPointerObj(L,(void *) resultptr,SWIGTYPE_p_switch_status_t,1); SWIG_arg++;
-  }
-  return SWIG_arg;
-  
-  if(0) SWIG_fail;
-  
-fail:
-  lua_error(L);
-  return SWIG_arg;
-}
-
-
 static int _wrap_input_callback_state_t_function_set(lua_State* L) {
   int SWIG_arg = -1;
   input_callback_state_t *arg1 = (input_callback_state_t *) 0 ;
@@ -2096,7 +2059,177 @@
 static const char *swig_Stream_base_names[] = {0};
 static swig_lua_class _wrap_class_Stream = { "Stream", &SWIGTYPE_p_Stream,_wrap_new_Stream, swig_delete_Stream, swig_Stream_methods, swig_Stream_attributes, swig_Stream_bases, swig_Stream_base_names };
 
-static int _wrap_new_Event(lua_State* L) {
+static int _wrap_Event_event_set(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  switch_event_t *arg2 = (switch_event_t *) 0 ;
+  
+  SWIG_check_num_args("event",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("event",1,"Event *");
+  if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("event",2,"switch_event_t *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_event_set",1,SWIGTYPE_p_Event);
+  }
+  
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&arg2,SWIGTYPE_p_switch_event_t,SWIG_POINTER_DISOWN))){
+    SWIG_fail_ptr("Event_event_set",2,SWIGTYPE_p_switch_event_t);
+  }
+  
+  if (arg1) (arg1)->event = arg2;
+  
+  SWIG_arg=0;
+  
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_Event_event_get(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  switch_event_t *result = 0 ;
+  
+  SWIG_check_num_args("event",1,1)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("event",1,"Event *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_event_get",1,SWIGTYPE_p_Event);
+  }
+  
+  result = (switch_event_t *) ((arg1)->event);
+  SWIG_arg=0;
+  SWIG_NewPointerObj(L,result,SWIGTYPE_p_switch_event_t,0); SWIG_arg++; 
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_Event_serialized_string_set(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  char *arg2 = (char *) 0 ;
+  
+  SWIG_check_num_args("serialized_string",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("serialized_string",1,"Event *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("serialized_string",2,"char *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_serialized_string_set",1,SWIGTYPE_p_Event);
+  }
+  
+  arg2 = (char *)lua_tostring(L, 2);
+  {
+    if (arg1->serialized_string) delete [] arg1->serialized_string;
+    if (arg2) {
+      arg1->serialized_string = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->serialized_string, (const char *)arg2);
+    } else {
+      arg1->serialized_string = 0;
+    }
+  }
+  SWIG_arg=0;
+  
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_Event_serialized_string_get(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  char *result = 0 ;
+  
+  SWIG_check_num_args("serialized_string",1,1)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("serialized_string",1,"Event *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_serialized_string_get",1,SWIGTYPE_p_Event);
+  }
+  
+  result = (char *) ((arg1)->serialized_string);
+  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_Event_mine_set(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  int arg2 ;
+  
+  SWIG_check_num_args("mine",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("mine",1,"Event *");
+  if(!lua_isnumber(L,2)) SWIG_fail_arg("mine",2,"int");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_mine_set",1,SWIGTYPE_p_Event);
+  }
+  
+  arg2 = (int)lua_tonumber(L, 2);
+  if (arg1) (arg1)->mine = arg2;
+  
+  SWIG_arg=0;
+  
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_Event_mine_get(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  int result;
+  
+  SWIG_check_num_args("mine",1,1)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("mine",1,"Event *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_mine_get",1,SWIGTYPE_p_Event);
+  }
+  
+  result = (int) ((arg1)->mine);
+  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 int _wrap_new_Event__SWIG_0(lua_State* L) {
   int SWIG_arg = -1;
   char *arg1 = (char *) 0 ;
   char *arg2 = (char *) NULL ;
@@ -2122,6 +2255,88 @@
 }
 
 
+static int _wrap_new_Event__SWIG_1(lua_State* L) {
+  int SWIG_arg = -1;
+  switch_event_t *arg1 = (switch_event_t *) 0 ;
+  int arg2 = (int) 0 ;
+  Event *result = 0 ;
+  
+  SWIG_check_num_args("Event",1,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("Event",1,"switch_event_t *");
+  if(lua_gettop(L)>=2 && !lua_isnumber(L,2)) SWIG_fail_arg("Event",2,"int");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_switch_event_t,0))){
+    SWIG_fail_ptr("new_Event",1,SWIGTYPE_p_switch_event_t);
+  }
+  
+  if(lua_gettop(L)>=2){
+    arg2 = (int)lua_tonumber(L, 2);
+  }
+  result = (Event *)new Event(arg1,arg2);
+  SWIG_arg=0;
+  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Event,1); SWIG_arg++; 
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_new_Event(lua_State* L) {
+  int argc;
+  int argv[3]={
+    1,2,3
+  };
+  
+  argc = lua_gettop(L);
+  if ((argc >= 1) && (argc <= 2)) {
+    int _v;
+    {
+      void *ptr;
+      if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_switch_event_t, 0)) {
+        _v = 0;
+      } else {
+        _v = 1;
+      }
+    }
+    if (_v) {
+      if (argc <= 1) {
+        return _wrap_new_Event__SWIG_1(L);
+      }
+      {
+        _v = lua_isnumber(L,argv[1]);
+      }
+      if (_v) {
+        return _wrap_new_Event__SWIG_1(L);
+      }
+    }
+  }
+  if ((argc >= 1) && (argc <= 2)) {
+    int _v;
+    {
+      _v = lua_isstring(L,argv[0]);
+    }
+    if (_v) {
+      if (argc <= 1) {
+        return _wrap_new_Event__SWIG_0(L);
+      }
+      {
+        _v = lua_isstring(L,argv[1]);
+      }
+      if (_v) {
+        return _wrap_new_Event__SWIG_0(L);
+      }
+    }
+  }
+  
+  lua_pushstring(L,"No matching function for overloaded 'new_Event'");
+  lua_error(L);return 0;
+}
+
+
 static int _wrap_delete_Event(lua_State* L) {
   int SWIG_arg = -1;
   Event *arg1 = (Event *) 0 ;
@@ -2147,6 +2362,36 @@
 }
 
 
+static int _wrap_Event_serialize(lua_State* L) {
+  int SWIG_arg = -1;
+  Event *arg1 = (Event *) 0 ;
+  char *arg2 = (char *) NULL ;
+  char *result = 0 ;
+  
+  SWIG_check_num_args("serialize",1,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("serialize",1,"Event *");
+  if(lua_gettop(L)>=2 && !lua_isstring(L,2)) SWIG_fail_arg("serialize",2,"char const *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("Event_serialize",1,SWIGTYPE_p_Event);
+  }
+  
+  if(lua_gettop(L)>=2){
+    arg2 = (char *)lua_tostring(L, 2);
+  }
+  result = (char *)(arg1)->serialize((char const *)arg2);
+  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_Event_set_priority(lua_State* L) {
   int SWIG_arg = -1;
   Event *arg1 = (Event *) 0 ;
@@ -2351,6 +2596,7 @@
 delete arg1;
 }
 static swig_lua_method swig_Event_methods[] = {
+    {"serialize", _wrap_Event_serialize}, 
     {"set_priority", _wrap_Event_set_priority}, 
     {"get_header", _wrap_Event_get_header}, 
     {"get_body", _wrap_Event_get_body}, 
@@ -2361,6 +2607,9 @@
     {0,0}
 };
 static swig_lua_attribute swig_Event_attributes[] = {
+    { "event", _wrap_Event_event_get, _wrap_Event_event_set},
+    { "serialized_string", _wrap_Event_serialized_string_get, _wrap_Event_serialized_string_set},
+    { "mine", _wrap_Event_mine_get, _wrap_Event_mine_set},
     {0,0,0}
 };
 static swig_lua_class *swig_Event_bases[] = {0};
@@ -2840,6 +3089,64 @@
 }
 
 
+static int _wrap_CoreSession_setPrivate(lua_State* L) {
+  int SWIG_arg = -1;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *arg2 = (char *) 0 ;
+  void *arg3 = (void *) 0 ;
+  
+  SWIG_check_num_args("setPrivate",3,3)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("setPrivate",1,"CoreSession *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("setPrivate",2,"char *");
+  if(!SWIG_isptrtype(L,3)) SWIG_fail_arg("setPrivate",3,"void *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){
+    SWIG_fail_ptr("CoreSession_setPrivate",1,SWIGTYPE_p_CoreSession);
+  }
+  
+  arg2 = (char *)lua_tostring(L, 2);
+  arg3=(void *)SWIG_MustGetPtr(L,3,0,0,3,"CoreSession_setPrivate");
+  (arg1)->setPrivate(arg2,arg3);
+  SWIG_arg=0;
+  
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
+static int _wrap_CoreSession_getPrivate(lua_State* L) {
+  int SWIG_arg = -1;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *arg2 = (char *) 0 ;
+  void *result = 0 ;
+  
+  SWIG_check_num_args("getPrivate",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("getPrivate",1,"CoreSession *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("getPrivate",2,"char *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){
+    SWIG_fail_ptr("CoreSession_getPrivate",1,SWIGTYPE_p_CoreSession);
+  }
+  
+  arg2 = (char *)lua_tostring(L, 2);
+  result = (void *)(arg1)->getPrivate(arg2);
+  SWIG_arg=0;
+  SWIG_NewPointerObj(L,result,SWIGTYPE_p_void,0); SWIG_arg++; 
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
 static int _wrap_CoreSession_getVariable(lua_State* L) {
   int SWIG_arg = -1;
   CoreSession *arg1 = (CoreSession *) 0 ;
@@ -3431,6 +3738,37 @@
 }
 
 
+static int _wrap_CoreSession_sendEvent(lua_State* L) {
+  int SWIG_arg = -1;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  Event *arg2 = (Event *) 0 ;
+  
+  SWIG_check_num_args("sendEvent",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("sendEvent",1,"CoreSession *");
+  if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("sendEvent",2,"Event *");
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){
+    SWIG_fail_ptr("CoreSession_sendEvent",1,SWIGTYPE_p_CoreSession);
+  }
+  
+  
+  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&arg2,SWIGTYPE_p_Event,0))){
+    SWIG_fail_ptr("CoreSession_sendEvent",2,SWIGTYPE_p_Event);
+  }
+  
+  (arg1)->sendEvent(arg2);
+  SWIG_arg=0;
+  
+  return SWIG_arg;
+  
+  if(0) SWIG_fail;
+  
+fail:
+  lua_error(L);
+  return SWIG_arg;
+}
+
+
 static int _wrap_CoreSession_begin_allow_threads(lua_State* L) {
   int SWIG_arg = -1;
   CoreSession *arg1 = (CoreSession *) 0 ;
@@ -3607,6 +3945,8 @@
     {"preAnswer", _wrap_CoreSession_preAnswer}, 
     {"hangup", _wrap_CoreSession_hangup}, 
     {"setVariable", _wrap_CoreSession_setVariable}, 
+    {"setPrivate", _wrap_CoreSession_setPrivate}, 
+    {"getPrivate", _wrap_CoreSession_getPrivate}, 
     {"getVariable", _wrap_CoreSession_getVariable}, 
     {"recordFile", _wrap_CoreSession_recordFile}, 
     {"setCallerData", _wrap_CoreSession_setCallerData}, 
@@ -3625,6 +3965,7 @@
     {"setHangupHook", _wrap_CoreSession_setHangupHook}, 
     {"ready", _wrap_CoreSession_ready}, 
     {"execute", _wrap_CoreSession_execute}, 
+    {"sendEvent", _wrap_CoreSession_sendEvent}, 
     {"begin_allow_threads", _wrap_CoreSession_begin_allow_threads}, 
     {"end_allow_threads", _wrap_CoreSession_end_allow_threads}, 
     {"get_uuid", _wrap_CoreSession_get_uuid}, 
@@ -3758,7 +4099,7 @@
   SWIG_check_num_args("Session",0,0)
   result = (Session *)new Session();
   SWIG_arg=0;
-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; 
+  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
   return SWIG_arg;
   
   if(0) SWIG_fail;
@@ -3779,7 +4120,7 @@
   arg1 = (char *)lua_tostring(L, 1);
   result = (Session *)new Session(arg1);
   SWIG_arg=0;
-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; 
+  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
   return SWIG_arg;
   
   if(0) SWIG_fail;
@@ -3804,7 +4145,7 @@
   
   result = (Session *)new Session(arg1);
   SWIG_arg=0;
-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; 
+  SWIG_NewPointerObj(L,result,SWIGTYPE_p_Session,1); SWIG_arg++; result->setPrivate("__L", L);
   return SWIG_arg;
   
   if(0) SWIG_fail;
@@ -3993,83 +4334,24 @@
 }
 
 
-static int _wrap_Session_session_set(lua_State* L) {
-  int SWIG_arg = -1;
-  Session *arg1 = (Session *) 0 ;
-  switch_core_session_t *arg2 = (switch_core_session_t *) 0 ;
-  
-  SWIG_check_num_args("session",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("session",1,"Session *");
-  if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("session",2,"switch_core_session_t *");
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_session_set",1,SWIGTYPE_p_Session);
-  }
-  
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&arg2,SWIGTYPE_p_switch_core_session_t,SWIG_POINTER_DISOWN))){
-    SWIG_fail_ptr("Session_session_set",2,SWIGTYPE_p_switch_core_session_t);
-  }
-  
-  if (arg1) (arg1)->session = arg2;
-  
-  SWIG_arg=0;
-  
-  return SWIG_arg;
-  
-  if(0) SWIG_fail;
-  
-fail:
-  lua_error(L);
-  return SWIG_arg;
-}
-
-
-static int _wrap_Session_session_get(lua_State* L) {
-  int SWIG_arg = -1;
-  Session *arg1 = (Session *) 0 ;
-  switch_core_session_t *result = 0 ;
-  
-  SWIG_check_num_args("session",1,1)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("session",1,"Session *");
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_session_get",1,SWIGTYPE_p_Session);
-  }
-  
-  result = (switch_core_session_t *) ((arg1)->session);
-  SWIG_arg=0;
-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_switch_core_session_t,0); SWIG_arg++; 
-  return SWIG_arg;
-  
-  if(0) SWIG_fail;
-  
-fail:
-  lua_error(L);
-  return SWIG_arg;
-}
-
-
-static int _wrap_Session_channel_set(lua_State* L) {
+static int _wrap_Session_setInputCallback(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  switch_channel_t *arg2 = (switch_channel_t *) 0 ;
+  char *arg2 = (char *) 0 ;
+  char *arg3 = (char *) 0 ;
   
-  SWIG_check_num_args("channel",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("channel",1,"Session *");
-  if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("channel",2,"switch_channel_t *");
+  SWIG_check_num_args("setInputCallback",3,3)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("setInputCallback",1,"Session *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("setInputCallback",2,"char *");
+  if(!lua_isstring(L,3)) SWIG_fail_arg("setInputCallback",3,"char *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_channel_set",1,SWIGTYPE_p_Session);
-  }
-  
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&arg2,SWIGTYPE_p_switch_channel_t,SWIG_POINTER_DISOWN))){
-    SWIG_fail_ptr("Session_channel_set",2,SWIGTYPE_p_switch_channel_t);
+    SWIG_fail_ptr("Session_setInputCallback",1,SWIGTYPE_p_Session);
   }
   
-  if (arg1) (arg1)->channel = arg2;
-  
+  arg2 = (char *)lua_tostring(L, 2);
+  arg3 = (char *)lua_tostring(L, 3);
+  (arg1)->setInputCallback(arg2,arg3);
   SWIG_arg=0;
   
   return SWIG_arg;
@@ -4082,47 +4364,21 @@
 }
 
 
-static int _wrap_Session_channel_get(lua_State* L) {
-  int SWIG_arg = -1;
-  Session *arg1 = (Session *) 0 ;
-  switch_channel_t *result = 0 ;
-  
-  SWIG_check_num_args("channel",1,1)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("channel",1,"Session *");
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_channel_get",1,SWIGTYPE_p_Session);
-  }
-  
-  result = (switch_channel_t *) ((arg1)->channel);
-  SWIG_arg=0;
-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_switch_channel_t,0); SWIG_arg++; 
-  return SWIG_arg;
-  
-  if(0) SWIG_fail;
-  
-fail:
-  lua_error(L);
-  return SWIG_arg;
-}
-
-
-static int _wrap_Session_flags_set(lua_State* L) {
+static int _wrap_Session_setHangupHook(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  unsigned int arg2 ;
+  char *arg2 = (char *) 0 ;
   
-  SWIG_check_num_args("flags",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("flags",1,"Session *");
-  if(!lua_isnumber(L,2)) SWIG_fail_arg("flags",2,"unsigned int");
+  SWIG_check_num_args("setHangupHook",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("setHangupHook",1,"Session *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("setHangupHook",2,"char *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_flags_set",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_setHangupHook",1,SWIGTYPE_p_Session);
   }
   
-  arg2 = (unsigned int)lua_tonumber(L, 2);
-  if (arg1) (arg1)->flags = arg2;
-  
+  arg2 = (char *)lua_tostring(L, 2);
+  (arg1)->setHangupHook(arg2);
   SWIG_arg=0;
   
   return SWIG_arg;
@@ -4135,47 +4391,29 @@
 }
 
 
-static int _wrap_Session_flags_get(lua_State* L) {
+static int _wrap_Session_cb_function_set(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  unsigned int result;
+  char *arg2 = (char *) 0 ;
   
-  SWIG_check_num_args("flags",1,1)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("flags",1,"Session *");
+  SWIG_check_num_args("cb_function",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("cb_function",1,"Session *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("cb_function",2,"char *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_flags_get",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_cb_function_set",1,SWIGTYPE_p_Session);
   }
   
-  result = (unsigned int) ((arg1)->flags);
-  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 int _wrap_Session_allocated_set(lua_State* L) {
-  int SWIG_arg = -1;
-  Session *arg1 = (Session *) 0 ;
-  int arg2 ;
-  
-  SWIG_check_num_args("allocated",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("allocated",1,"Session *");
-  if(!lua_isnumber(L,2)) SWIG_fail_arg("allocated",2,"int");
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_allocated_set",1,SWIGTYPE_p_Session);
+  arg2 = (char *)lua_tostring(L, 2);
+  {
+    if (arg1->cb_function) delete [] arg1->cb_function;
+    if (arg2) {
+      arg1->cb_function = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->cb_function, (const char *)arg2);
+    } else {
+      arg1->cb_function = 0;
+    }
   }
-  
-  arg2 = (int)lua_tonumber(L, 2);
-  if (arg1) (arg1)->allocated = arg2;
-  
   SWIG_arg=0;
   
   return SWIG_arg;
@@ -4188,21 +4426,21 @@
 }
 
 
-static int _wrap_Session_allocated_get(lua_State* L) {
+static int _wrap_Session_cb_function_get(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  int result;
+  char *result = 0 ;
   
-  SWIG_check_num_args("allocated",1,1)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("allocated",1,"Session *");
+  SWIG_check_num_args("cb_function",1,1)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("cb_function",1,"Session *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_allocated_get",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_cb_function_get",1,SWIGTYPE_p_Session);
   }
   
-  result = (int) ((arg1)->allocated);
+  result = (char *) ((arg1)->cb_function);
   SWIG_arg=0;
-  lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
+  lua_pushstring(L,(const char*)result); SWIG_arg++;
   return SWIG_arg;
   
   if(0) SWIG_fail;
@@ -4213,26 +4451,29 @@
 }
 
 
-static int _wrap_Session_cb_state_set(lua_State* L) {
+static int _wrap_Session_cb_arg_set(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  input_callback_state *arg2 = (input_callback_state *) 0 ;
+  char *arg2 = (char *) 0 ;
   
-  SWIG_check_num_args("cb_state",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("cb_state",1,"Session *");
-  if(!SWIG_isptrtype(L,2)) SWIG_fail_arg("cb_state",2,"input_callback_state *");
+  SWIG_check_num_args("cb_arg",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("cb_arg",1,"Session *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("cb_arg",2,"char *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_cb_state_set",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_cb_arg_set",1,SWIGTYPE_p_Session);
   }
   
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&arg2,SWIGTYPE_p_input_callback_state,0))){
-    SWIG_fail_ptr("Session_cb_state_set",2,SWIGTYPE_p_input_callback_state);
+  arg2 = (char *)lua_tostring(L, 2);
+  {
+    if (arg1->cb_arg) delete [] arg1->cb_arg;
+    if (arg2) {
+      arg1->cb_arg = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->cb_arg, (const char *)arg2);
+    } else {
+      arg1->cb_arg = 0;
+    }
   }
-  
-  if (arg1) (arg1)->cb_state = *arg2;
-  
   SWIG_arg=0;
   
   return SWIG_arg;
@@ -4245,21 +4486,21 @@
 }
 
 
-static int _wrap_Session_cb_state_get(lua_State* L) {
+static int _wrap_Session_cb_arg_get(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  input_callback_state *result = 0 ;
+  char *result = 0 ;
   
-  SWIG_check_num_args("cb_state",1,1)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("cb_state",1,"Session *");
+  SWIG_check_num_args("cb_arg",1,1)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("cb_arg",1,"Session *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_cb_state_get",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_cb_arg_get",1,SWIGTYPE_p_Session);
   }
   
-  result = (input_callback_state *)& ((arg1)->cb_state);
+  result = (char *) ((arg1)->cb_arg);
   SWIG_arg=0;
-  SWIG_NewPointerObj(L,result,SWIGTYPE_p_input_callback_state,0); SWIG_arg++; 
+  lua_pushstring(L,(const char*)result); SWIG_arg++;
   return SWIG_arg;
   
   if(0) SWIG_fail;
@@ -4270,28 +4511,29 @@
 }
 
 
-static int _wrap_Session_hook_state_set(lua_State* L) {
+static int _wrap_Session_hangup_func_str_set(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  switch_channel_state_t arg2 ;
-  switch_channel_state_t *argp2 ;
+  char *arg2 = (char *) 0 ;
   
-  SWIG_check_num_args("hook_state",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("hook_state",1,"Session *");
-  if(!lua_isuserdata(L,2)) SWIG_fail_arg("hook_state",2,"switch_channel_state_t");
+  SWIG_check_num_args("hangup_func_str",2,2)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("hangup_func_str",1,"Session *");
+  if(!lua_isstring(L,2)) SWIG_fail_arg("hangup_func_str",2,"char *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_hook_state_set",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_hangup_func_str_set",1,SWIGTYPE_p_Session);
   }
   
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,2,(void**)&argp2,SWIGTYPE_p_switch_channel_state_t,0))){
-    SWIG_fail_ptr("Session_hook_state_set",2,SWIGTYPE_p_switch_channel_state_t);
+  arg2 = (char *)lua_tostring(L, 2);
+  {
+    if (arg1->hangup_func_str) delete [] arg1->hangup_func_str;
+    if (arg2) {
+      arg1->hangup_func_str = (char *) (new char[strlen((const char *)arg2)+1]);
+      strcpy((char *)arg1->hangup_func_str, (const char *)arg2);
+    } else {
+      arg1->hangup_func_str = 0;
+    }
   }
-  arg2 = *argp2;
-  
-  if (arg1) (arg1)->hook_state = arg2;
-  
   SWIG_arg=0;
   
   return SWIG_arg;
@@ -4304,24 +4546,21 @@
 }
 
 
-static int _wrap_Session_hook_state_get(lua_State* L) {
+static int _wrap_Session_hangup_func_str_get(lua_State* L) {
   int SWIG_arg = -1;
   Session *arg1 = (Session *) 0 ;
-  switch_channel_state_t result;
+  char *result = 0 ;
   
-  SWIG_check_num_args("hook_state",1,1)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("hook_state",1,"Session *");
+  SWIG_check_num_args("hangup_func_str",1,1)
+  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("hangup_func_str",1,"Session *");
   
   if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Session,0))){
-    SWIG_fail_ptr("Session_hook_state_get",1,SWIGTYPE_p_Session);
+    SWIG_fail_ptr("Session_hangup_func_str_get",1,SWIGTYPE_p_Session);
   }
   
-  result =  ((arg1)->hook_state);
+  result = (char *) ((arg1)->hangup_func_str);
   SWIG_arg=0;
-  {
-    switch_channel_state_t * resultptr = new switch_channel_state_t((switch_channel_state_t &) result);
-    SWIG_NewPointerObj(L,(void *) resultptr,SWIGTYPE_p_switch_channel_state_t,1); SWIG_arg++;
-  }
+  lua_pushstring(L,(const char*)result); SWIG_arg++;
   return SWIG_arg;
   
   if(0) SWIG_fail;
@@ -4341,15 +4580,14 @@
     {"end_allow_threads", _wrap_Session_end_allow_threads}, 
     {"check_hangup_hook", _wrap_Session_check_hangup_hook}, 
     {"run_dtmf_callback", _wrap_Session_run_dtmf_callback}, 
+    {"setInputCallback", _wrap_Session_setInputCallback}, 
+    {"setHangupHook", _wrap_Session_setHangupHook}, 
     {0,0}
 };
 static swig_lua_attribute swig_Session_attributes[] = {
-    { "session", _wrap_Session_session_get, _wrap_Session_session_set},
-    { "channel", _wrap_Session_channel_get, _wrap_Session_channel_set},
-    { "flags", _wrap_Session_flags_get, _wrap_Session_flags_set},
-    { "allocated", _wrap_Session_allocated_get, _wrap_Session_allocated_set},
-    { "cb_state", _wrap_Session_cb_state_get, _wrap_Session_cb_state_set},
-    { "hook_state", _wrap_Session_hook_state_get, _wrap_Session_hook_state_set},
+    { "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},
     {0,0,0}
 };
 static swig_lua_class *swig_Session_bases[] = {0,0};
@@ -4365,7 +4603,6 @@
     { "console_clean_log", _wrap_console_clean_log},
     { "api_execute", _wrap_api_execute},
     { "api_reply_delete", _wrap_api_reply_delete},
-    { "process_callback_result", _wrap_process_callback_result},
     { "bridge", _wrap_bridge},
     { "hanguphook", _wrap_hanguphook},
     { "dtmf_callback", _wrap_dtmf_callback},
@@ -4397,6 +4634,7 @@
 static swig_type_info _swigt__p_switch_channel_state_t = {"_p_switch_channel_state_t", "switch_channel_state_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_channel_t = {"_p_switch_channel_t", "switch_channel_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_core_session_t = {"_p_switch_core_session_t", "switch_core_session_t *", 0, 0, (void*)0, 0};
+static swig_type_info _swigt__p_switch_event_t = {"_p_switch_event_t", "switch_event_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_input_args_t = {"_p_switch_input_args_t", "switch_input_args_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_input_type_t = {"_p_switch_input_type_t", "switch_input_type_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_priority_t = {"_p_switch_priority_t", "switch_priority_t *", 0, 0, (void*)0, 0};
@@ -4415,6 +4653,7 @@
   &_swigt__p_switch_channel_state_t,
   &_swigt__p_switch_channel_t,
   &_swigt__p_switch_core_session_t,
+  &_swigt__p_switch_event_t,
   &_swigt__p_switch_input_args_t,
   &_swigt__p_switch_input_type_t,
   &_swigt__p_switch_priority_t,
@@ -4433,6 +4672,7 @@
 static swig_cast_info _swigc__p_switch_channel_state_t[] = {  {&_swigt__p_switch_channel_state_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_channel_t[] = {  {&_swigt__p_switch_channel_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_core_session_t[] = {  {&_swigt__p_switch_core_session_t, 0, 0, 0},{0, 0, 0, 0}};
+static swig_cast_info _swigc__p_switch_event_t[] = {  {&_swigt__p_switch_event_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_input_args_t[] = {  {&_swigt__p_switch_input_args_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_input_type_t[] = {  {&_swigt__p_switch_input_type_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_priority_t[] = {  {&_swigt__p_switch_priority_t, 0, 0, 0},{0, 0, 0, 0}};
@@ -4451,6 +4691,7 @@
   _swigc__p_switch_channel_state_t,
   _swigc__p_switch_channel_t,
   _swigc__p_switch_core_session_t,
+  _swigc__p_switch_event_t,
   _swigc__p_switch_input_args_t,
   _swigc__p_switch_input_type_t,
   _swigc__p_switch_priority_t,
@@ -4769,3 +5010,4 @@
   SWIG_Lua_dostring(L,SWIG_LUACODE);
 }
 
+#include "mod_lua_extra.c"

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	Tue Apr 29 19:34:26 2008
@@ -52,7 +52,6 @@
 *console_clean_log = *freeswitchc::console_clean_log;
 *api_execute = *freeswitchc::api_execute;
 *api_reply_delete = *freeswitchc::api_reply_delete;
-*process_callback_result = *freeswitchc::process_callback_result;
 *bridge = *freeswitchc::bridge;
 *hanguphook = *freeswitchc::hanguphook;
 *dtmf_callback = *freeswitchc::dtmf_callback;
@@ -148,6 +147,12 @@
 @ISA = qw( freeswitch );
 %OWNER = ();
 %ITERATORS = ();
+*swig_event_get = *freeswitchc::Event_event_get;
+*swig_event_set = *freeswitchc::Event_event_set;
+*swig_serialized_string_get = *freeswitchc::Event_serialized_string_get;
+*swig_serialized_string_set = *freeswitchc::Event_serialized_string_set;
+*swig_mine_get = *freeswitchc::Event_mine_get;
+*swig_mine_set = *freeswitchc::Event_mine_set;
 sub new {
     my $pkg = shift;
     my $self = freeswitchc::new_Event(@_);
@@ -165,6 +170,7 @@
     }
 }
 
+*serialize = *freeswitchc::Event_serialize;
 *set_priority = *freeswitchc::Event_set_priority;
 *get_header = *freeswitchc::Event_get_header;
 *get_body = *freeswitchc::Event_get_body;
@@ -219,6 +225,8 @@
 *preAnswer = *freeswitchc::CoreSession_preAnswer;
 *hangup = *freeswitchc::CoreSession_hangup;
 *setVariable = *freeswitchc::CoreSession_setVariable;
+*setPrivate = *freeswitchc::CoreSession_setPrivate;
+*getPrivate = *freeswitchc::CoreSession_getPrivate;
 *getVariable = *freeswitchc::CoreSession_getVariable;
 *recordFile = *freeswitchc::CoreSession_recordFile;
 *setCallerData = *freeswitchc::CoreSession_setCallerData;
@@ -237,6 +245,7 @@
 *setHangupHook = *freeswitchc::CoreSession_setHangupHook;
 *ready = *freeswitchc::CoreSession_ready;
 *execute = *freeswitchc::CoreSession_execute;
+*sendEvent = *freeswitchc::CoreSession_sendEvent;
 *begin_allow_threads = *freeswitchc::CoreSession_begin_allow_threads;
 *end_allow_threads = *freeswitchc::CoreSession_end_allow_threads;
 *get_uuid = *freeswitchc::CoreSession_get_uuid;

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	Tue Apr 29 19:34:26 2008
@@ -1456,15 +1456,16 @@
 #define SWIGTYPE_p_switch_channel_state_t swig_types[7]
 #define SWIGTYPE_p_switch_channel_t swig_types[8]
 #define SWIGTYPE_p_switch_core_session_t swig_types[9]
-#define SWIGTYPE_p_switch_input_args_t swig_types[10]
-#define SWIGTYPE_p_switch_input_type_t swig_types[11]
-#define SWIGTYPE_p_switch_priority_t swig_types[12]
-#define SWIGTYPE_p_switch_size_t swig_types[13]
-#define SWIGTYPE_p_switch_status_t swig_types[14]
-#define SWIGTYPE_p_switch_stream_handle_t swig_types[15]
-#define SWIGTYPE_p_void swig_types[16]
-static swig_type_info *swig_types[18];
-static swig_module_info swig_module = {swig_types, 17, 0, 0, 0, 0};
+#define SWIGTYPE_p_switch_event_t swig_types[10]
+#define SWIGTYPE_p_switch_input_args_t swig_types[11]
+#define SWIGTYPE_p_switch_input_type_t swig_types[12]
+#define SWIGTYPE_p_switch_priority_t swig_types[13]
+#define SWIGTYPE_p_switch_size_t swig_types[14]
+#define SWIGTYPE_p_switch_status_t swig_types[15]
+#define SWIGTYPE_p_switch_stream_handle_t swig_types[16]
+#define SWIGTYPE_p_void swig_types[17]
+static swig_type_info *swig_types[19];
+static swig_module_info swig_module = {swig_types, 18, 0, 0, 0, 0};
 #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
 #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
 
@@ -1591,19 +1592,6 @@
 }
 
 
-SWIGINTERNINLINE SV *
-SWIG_From_bool  SWIG_PERL_DECL_ARGS_1(bool value)
-{    
-  SV *obj = sv_newmortal();
-  if (value) {
-    sv_setsv(obj, &PL_sv_yes);
-  } else {
-    sv_setsv(obj, &PL_sv_no); 
-  }
-  return obj;
-}
-
-
 #include <limits.h>
 #if !defined(SWIG_NO_LLONG_MAX)
 # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
@@ -1680,27 +1668,19 @@
 
 
 SWIGINTERN int
-SWIG_AsVal_unsigned_SS_long SWIG_PERL_DECL_ARGS_2(SV *obj, unsigned long *val) 
+SWIG_AsVal_long SWIG_PERL_DECL_ARGS_2(SV *obj, long* val)
 {
-  if (SvUOK(obj)) {
-    if (val) *val = SvUV(obj);
+  if (SvIOK(obj)) {
+    if (val) *val = SvIV(obj);
     return SWIG_OK;
-  } else  if (SvIOK(obj)) {
-    long v = SvIV(obj);
-    if (v >= 0) {
-      if (val) *val = v;
-      return SWIG_OK;
-    } else {
-      return SWIG_OverflowError;
-    }
   } else {
     int dispatch = 0;
     const char *nptr = SvPV_nolen(obj);
     if (nptr) {
       char *endptr;
-      unsigned long v;
+      long v;
       errno = 0;
-      v = strtoul(nptr, &endptr,0);
+      v = strtol(nptr, &endptr,0);
       if (errno == ERANGE) {
 	errno = 0;
 	return SWIG_OverflowError;
@@ -1714,8 +1694,8 @@
     if (!dispatch) {
       double d;
       int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d));
-      if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
-	if (val) *val = (unsigned long)(d);
+      if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
+	if (val) *val = (long)(d);
 	return res;
       }
     }
@@ -1725,15 +1705,15 @@
 
 
 SWIGINTERN int
-SWIG_AsVal_unsigned_SS_int SWIG_PERL_DECL_ARGS_2(SV * obj, unsigned int *val)
+SWIG_AsVal_int SWIG_PERL_DECL_ARGS_2(SV * obj, int *val)
 {
-  unsigned long v;
-  int res = SWIG_AsVal_unsigned_SS_long SWIG_PERL_CALL_ARGS_2(obj, &v);
+  long v;
+  int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(obj, &v);
   if (SWIG_IsOK(res)) {
-    if ((v > UINT_MAX)) {
+    if ((v < INT_MIN || v > INT_MAX)) {
       return SWIG_OverflowError;
     } else {
-      if (val) *val = static_cast< unsigned int >(v);
+      if (val) *val = static_cast< int >(v);
     }
   }  
   return res;
@@ -1741,35 +1721,40 @@
 
 
 SWIGINTERNINLINE SV *
-SWIG_From_unsigned_SS_long  SWIG_PERL_DECL_ARGS_1(unsigned long value)
+SWIG_From_bool  SWIG_PERL_DECL_ARGS_1(bool value)
 {    
   SV *obj = sv_newmortal();
-  sv_setuv(obj, (UV) value);
+  if (value) {
+    sv_setsv(obj, &PL_sv_yes);
+  } else {
+    sv_setsv(obj, &PL_sv_no); 
+  }
   return obj;
 }
 
 
-SWIGINTERNINLINE SV *
-SWIG_From_unsigned_SS_int  SWIG_PERL_DECL_ARGS_1(unsigned int value)
-{    
-  return SWIG_From_unsigned_SS_long  SWIG_PERL_CALL_ARGS_1(value);
-}
-
-
 SWIGINTERN int
-SWIG_AsVal_long SWIG_PERL_DECL_ARGS_2(SV *obj, long* val)
+SWIG_AsVal_unsigned_SS_long SWIG_PERL_DECL_ARGS_2(SV *obj, unsigned long *val) 
 {
-  if (SvIOK(obj)) {
-    if (val) *val = SvIV(obj);
+  if (SvUOK(obj)) {
+    if (val) *val = SvUV(obj);
     return SWIG_OK;
+  } else  if (SvIOK(obj)) {
+    long v = SvIV(obj);
+    if (v >= 0) {
+      if (val) *val = v;
+      return SWIG_OK;
+    } else {
+      return SWIG_OverflowError;
+    }
   } else {
     int dispatch = 0;
     const char *nptr = SvPV_nolen(obj);
     if (nptr) {
       char *endptr;
-      long v;
+      unsigned long v;
       errno = 0;
-      v = strtol(nptr, &endptr,0);
+      v = strtoul(nptr, &endptr,0);
       if (errno == ERANGE) {
 	errno = 0;
 	return SWIG_OverflowError;
@@ -1783,8 +1768,8 @@
     if (!dispatch) {
       double d;
       int res = SWIG_AddCast(SWIG_AsVal_double SWIG_PERL_CALL_ARGS_2(obj,&d));
-      if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
-	if (val) *val = (long)(d);
+      if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
+	if (val) *val = (unsigned long)(d);
 	return res;
       }
     }
@@ -1794,21 +1779,37 @@
 
 
 SWIGINTERN int
-SWIG_AsVal_int SWIG_PERL_DECL_ARGS_2(SV * obj, int *val)
+SWIG_AsVal_unsigned_SS_int SWIG_PERL_DECL_ARGS_2(SV * obj, unsigned int *val)
 {
-  long v;
-  int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(obj, &v);
+  unsigned long v;
+  int res = SWIG_AsVal_unsigned_SS_long SWIG_PERL_CALL_ARGS_2(obj, &v);
   if (SWIG_IsOK(res)) {
-    if ((v < INT_MIN || v > INT_MAX)) {
+    if ((v > UINT_MAX)) {
       return SWIG_OverflowError;
     } else {
-      if (val) *val = static_cast< int >(v);
+      if (val) *val = static_cast< unsigned int >(v);
     }
   }  
   return res;
 }
 
 
+SWIGINTERNINLINE SV *
+SWIG_From_unsigned_SS_long  SWIG_PERL_DECL_ARGS_1(unsigned long value)
+{    
+  SV *obj = sv_newmortal();
+  sv_setuv(obj, (UV) value);
+  return obj;
+}
+
+
+SWIGINTERNINLINE SV *
+SWIG_From_unsigned_SS_int  SWIG_PERL_DECL_ARGS_1(unsigned int value)
+{    
+  return SWIG_From_unsigned_SS_long  SWIG_PERL_CALL_ARGS_1(value);
+}
+
+
 SWIGINTERN int
 SWIG_AsVal_bool SWIG_PERL_DECL_ARGS_2(SV *obj, bool* val)
 {
@@ -1989,55 +1990,6 @@
 }
 
 
-XS(_wrap_process_callback_result) {
-  {
-    char *arg1 = (char *) 0 ;
-    input_callback_state *arg2 = (input_callback_state *) 0 ;
-    switch_core_session_t *arg3 = (switch_core_session_t *) 0 ;
-    switch_status_t result;
-    int res1 ;
-    char *buf1 = 0 ;
-    int alloc1 = 0 ;
-    void *argp2 = 0 ;
-    int res2 = 0 ;
-    void *argp3 = 0 ;
-    int res3 = 0 ;
-    int argvi = 0;
-    dXSARGS;
-    
-    if ((items < 3) || (items > 3)) {
-      SWIG_croak("Usage: process_callback_result(raw_result,cb_state,session);");
-    }
-    res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1);
-    if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "process_callback_result" "', argument " "1"" of type '" "char *""'");
-    }
-    arg1 = reinterpret_cast< char * >(buf1);
-    res2 = SWIG_ConvertPtr(ST(1), &argp2,SWIGTYPE_p_input_callback_state, 0 |  0 );
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "process_callback_result" "', argument " "2"" of type '" "input_callback_state *""'"); 
-    }
-    arg2 = reinterpret_cast< input_callback_state * >(argp2);
-    res3 = SWIG_ConvertPtr(ST(2), &argp3,SWIGTYPE_p_switch_core_session_t, 0 |  0 );
-    if (!SWIG_IsOK(res3)) {
-      SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "process_callback_result" "', argument " "3"" of type '" "switch_core_session_t *""'"); 
-    }
-    arg3 = reinterpret_cast< switch_core_session_t * >(argp3);
-    result = process_callback_result(arg1,arg2,arg3);
-    ST(argvi) = SWIG_NewPointerObj((new switch_status_t(static_cast< const switch_status_t& >(result))), SWIGTYPE_p_switch_status_t, SWIG_POINTER_OWN | 0); argvi++ ;
-    if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
-    
-    
-    XSRETURN(argvi);
-  fail:
-    if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
-    
-    
-    SWIG_croak_null();
-  }
-}
-
-
 XS(_wrap_input_callback_state_t_function_set) {
   {
     input_callback_state_t *arg1 = (input_callback_state_t *) 0 ;
@@ -2394,34 +2346,497 @@
 }
 
 
-XS(_wrap_new_Stream) {
+XS(_wrap_new_Stream) {
+  dXSARGS;
+  
+  {
+    unsigned long _index = 0;
+    SWIG_TypeRank _rank = 0; 
+    if (items == 0) {
+      SWIG_TypeRank _ranki = 0;
+      SWIG_TypeRank _rankm = 0;
+      if (!_index || (_ranki < _rank)) {
+        _rank = _ranki; _index = 1;
+        if (_rank == _rankm) goto dispatch;
+      }
+    }
+    if (items == 1) {
+      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_switch_stream_handle_t, 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_new_Stream__SWIG_0); return;
+    case 2:
+      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Stream__SWIG_1); return;
+    }
+  }
+  
+  croak("No matching function for overloaded 'new_Stream'");
+  XSRETURN(0);
+}
+
+
+XS(_wrap_delete_Stream) {
+  {
+    Stream *arg1 = (Stream *) 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 1)) {
+      SWIG_croak("Usage: delete_Stream(self);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Stream, SWIG_POINTER_DISOWN |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Stream" "', argument " "1"" of type '" "Stream *""'"); 
+    }
+    arg1 = reinterpret_cast< Stream * >(argp1);
+    delete arg1;
+    
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Stream_write) {
+  {
+    Stream *arg1 = (Stream *) 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: Stream_write(self,data);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Stream, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Stream_write" "', argument " "1"" of type '" "Stream *""'"); 
+    }
+    arg1 = reinterpret_cast< Stream * >(argp1);
+    res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+    if (!SWIG_IsOK(res2)) {
+      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Stream_write" "', argument " "2"" of type '" "char const *""'");
+    }
+    arg2 = reinterpret_cast< char * >(buf2);
+    (arg1)->write((char const *)arg2);
+    
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    XSRETURN(argvi);
+  fail:
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Stream_get_data) {
+  {
+    Stream *arg1 = (Stream *) 0 ;
+    char *result = 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 1)) {
+      SWIG_croak("Usage: Stream_get_data(self);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Stream, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Stream_get_data" "', argument " "1"" of type '" "Stream *""'"); 
+    }
+    arg1 = reinterpret_cast< Stream * >(argp1);
+    result = (char *)(arg1)->get_data();
+    ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
+    
+    XSRETURN(argvi);
+  fail:
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Event_event_set) {
+  {
+    Event *arg1 = (Event *) 0 ;
+    switch_event_t *arg2 = (switch_event_t *) 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    void *argp2 = 0 ;
+    int res2 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 2) || (items > 2)) {
+      SWIG_croak("Usage: Event_event_set(self,event);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_event_set" "', argument " "1"" of type '" "Event *""'"); 
+    }
+    arg1 = reinterpret_cast< Event * >(argp1);
+    res2 = SWIG_ConvertPtr(ST(1), &argp2,SWIGTYPE_p_switch_event_t, SWIG_POINTER_DISOWN |  0 );
+    if (!SWIG_IsOK(res2)) {
+      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_event_set" "', argument " "2"" of type '" "switch_event_t *""'"); 
+    }
+    arg2 = reinterpret_cast< switch_event_t * >(argp2);
+    if (arg1) (arg1)->event = arg2;
+    
+    
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Event_event_get) {
+  {
+    Event *arg1 = (Event *) 0 ;
+    switch_event_t *result = 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 1)) {
+      SWIG_croak("Usage: Event_event_get(self);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_event_get" "', argument " "1"" of type '" "Event *""'"); 
+    }
+    arg1 = reinterpret_cast< Event * >(argp1);
+    result = (switch_event_t *) ((arg1)->event);
+    ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_switch_event_t, 0 | 0); argvi++ ;
+    
+    XSRETURN(argvi);
+  fail:
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Event_serialized_string_set) {
+  {
+    Event *arg1 = (Event *) 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: Event_serialized_string_set(self,serialized_string);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_serialized_string_set" "', argument " "1"" of type '" "Event *""'"); 
+    }
+    arg1 = reinterpret_cast< Event * >(argp1);
+    res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+    if (!SWIG_IsOK(res2)) {
+      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_serialized_string_set" "', argument " "2"" of type '" "char *""'");
+    }
+    arg2 = reinterpret_cast< char * >(buf2);
+    if (arg1->serialized_string) delete[] arg1->serialized_string;
+    if (arg2) {
+      size_t size = strlen(reinterpret_cast< const char * >(arg2)) + 1;
+      arg1->serialized_string = (char *)reinterpret_cast< char* >(memcpy((new char[size]), reinterpret_cast< const char * >(arg2), sizeof(char)*(size)));
+    } else {
+      arg1->serialized_string = 0;
+    }
+    
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    XSRETURN(argvi);
+  fail:
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Event_serialized_string_get) {
+  {
+    Event *arg1 = (Event *) 0 ;
+    char *result = 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 1)) {
+      SWIG_croak("Usage: Event_serialized_string_get(self);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_serialized_string_get" "', argument " "1"" of type '" "Event *""'"); 
+    }
+    arg1 = reinterpret_cast< Event * >(argp1);
+    result = (char *) ((arg1)->serialized_string);
+    ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
+    
+    XSRETURN(argvi);
+  fail:
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Event_mine_set) {
+  {
+    Event *arg1 = (Event *) 0 ;
+    int arg2 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int val2 ;
+    int ecode2 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 2) || (items > 2)) {
+      SWIG_croak("Usage: Event_mine_set(self,mine);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_mine_set" "', argument " "1"" of type '" "Event *""'"); 
+    }
+    arg1 = reinterpret_cast< Event * >(argp1);
+    ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
+    if (!SWIG_IsOK(ecode2)) {
+      SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Event_mine_set" "', argument " "2"" of type '" "int""'");
+    } 
+    arg2 = static_cast< int >(val2);
+    if (arg1) (arg1)->mine = arg2;
+    
+    
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_Event_mine_get) {
+  {
+    Event *arg1 = (Event *) 0 ;
+    int result;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 1)) {
+      SWIG_croak("Usage: Event_mine_get(self);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_mine_get" "', argument " "1"" of type '" "Event *""'"); 
+    }
+    arg1 = reinterpret_cast< Event * >(argp1);
+    result = (int) ((arg1)->mine);
+    ST(argvi) = SWIG_From_int  SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ;
+    
+    XSRETURN(argvi);
+  fail:
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_new_Event__SWIG_0) {
+  {
+    char *arg1 = (char *) 0 ;
+    char *arg2 = (char *) NULL ;
+    Event *result = 0 ;
+    int res1 ;
+    char *buf1 = 0 ;
+    int alloc1 = 0 ;
+    int res2 ;
+    char *buf2 = 0 ;
+    int alloc2 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 2)) {
+      SWIG_croak("Usage: new_Event(type,subclass_name);");
+    }
+    res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1);
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Event" "', argument " "1"" of type '" "char const *""'");
+    }
+    arg1 = reinterpret_cast< char * >(buf1);
+    if (items > 1) {
+      res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+      if (!SWIG_IsOK(res2)) {
+        SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_Event" "', argument " "2"" of type '" "char const *""'");
+      }
+      arg2 = reinterpret_cast< char * >(buf2);
+    }
+    result = (Event *)new Event((char const *)arg1,(char const *)arg2);
+    ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_OWNER | SWIG_SHADOW); argvi++ ;
+    if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    XSRETURN(argvi);
+  fail:
+    if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_new_Event__SWIG_1) {
+  {
+    switch_event_t *arg1 = (switch_event_t *) 0 ;
+    int arg2 = (int) 0 ;
+    Event *result = 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int val2 ;
+    int ecode2 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 1) || (items > 2)) {
+      SWIG_croak("Usage: new_Event(wrap_me,free_me);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_switch_event_t, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Event" "', argument " "1"" of type '" "switch_event_t *""'"); 
+    }
+    arg1 = reinterpret_cast< switch_event_t * >(argp1);
+    if (items > 1) {
+      ecode2 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), &val2);
+      if (!SWIG_IsOK(ecode2)) {
+        SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "new_Event" "', argument " "2"" of type '" "int""'");
+      } 
+      arg2 = static_cast< int >(val2);
+    }
+    result = (Event *)new Event(arg1,arg2);
+    ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_OWNER | SWIG_SHADOW); argvi++ ;
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_new_Event) {
   dXSARGS;
   
   {
     unsigned long _index = 0;
     SWIG_TypeRank _rank = 0; 
-    if (items == 0) {
+    if ((items >= 1) && (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_switch_event_t, 0);
+        _v = SWIG_CheckState(res);
+      }
+      if (!_v) goto check_1;
+      _ranki += _v*_pi;
+      _rankm += _pi;
+      _pi *= SWIG_MAXCASTRANK;
+      if (items > 1) {
+        {
+          {
+            int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(1), NULL);
+            _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;
       }
     }
-    if (items == 1) {
+  check_1:
+    
+    if ((items >= 1) && (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_switch_stream_handle_t, 0);
+        int res = SWIG_AsCharPtrAndSize(ST(0), 0, NULL, 0);
         _v = SWIG_CheckState(res);
       }
       if (!_v) goto check_2;
       _ranki += _v*_pi;
       _rankm += _pi;
       _pi *= SWIG_MAXCASTRANK;
+      if (items > 1) {
+        {
+          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;
+      }
       if (!_index || (_ranki < _rank)) {
         _rank = _ranki; _index = 2;
         if (_rank == _rankm) goto dispatch;
@@ -2432,33 +2847,33 @@
   dispatch:
     switch(_index) {
     case 1:
-      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Stream__SWIG_0); return;
+      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Event__SWIG_1); return;
     case 2:
-      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Stream__SWIG_1); return;
+      ++PL_markstack_ptr; SWIG_CALLXS(_wrap_new_Event__SWIG_0); return;
     }
   }
   
-  croak("No matching function for overloaded 'new_Stream'");
+  croak("No matching function for overloaded 'new_Event'");
   XSRETURN(0);
 }
 
 
-XS(_wrap_delete_Stream) {
+XS(_wrap_delete_Event) {
   {
-    Stream *arg1 = (Stream *) 0 ;
+    Event *arg1 = (Event *) 0 ;
     void *argp1 = 0 ;
     int res1 = 0 ;
     int argvi = 0;
     dXSARGS;
     
     if ((items < 1) || (items > 1)) {
-      SWIG_croak("Usage: delete_Stream(self);");
+      SWIG_croak("Usage: delete_Event(self);");
     }
-    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Stream, SWIG_POINTER_DISOWN |  0 );
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, SWIG_POINTER_DISOWN |  0 );
     if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Stream" "', argument " "1"" of type '" "Stream *""'"); 
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Event" "', argument " "1"" of type '" "Event *""'"); 
     }
-    arg1 = reinterpret_cast< Stream * >(argp1);
+    arg1 = reinterpret_cast< Event * >(argp1);
     delete arg1;
     
     
@@ -2471,80 +2886,13 @@
 }
 
 
-XS(_wrap_Stream_write) {
-  {
-    Stream *arg1 = (Stream *) 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: Stream_write(self,data);");
-    }
-    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Stream, 0 |  0 );
-    if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Stream_write" "', argument " "1"" of type '" "Stream *""'"); 
-    }
-    arg1 = reinterpret_cast< Stream * >(argp1);
-    res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Stream_write" "', argument " "2"" of type '" "char const *""'");
-    }
-    arg2 = reinterpret_cast< char * >(buf2);
-    (arg1)->write((char const *)arg2);
-    
-    
-    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
-    XSRETURN(argvi);
-  fail:
-    
-    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
-    SWIG_croak_null();
-  }
-}
-
-
-XS(_wrap_Stream_get_data) {
+XS(_wrap_Event_serialize) {
   {
-    Stream *arg1 = (Stream *) 0 ;
+    Event *arg1 = (Event *) 0 ;
+    char *arg2 = (char *) NULL ;
     char *result = 0 ;
     void *argp1 = 0 ;
     int res1 = 0 ;
-    int argvi = 0;
-    dXSARGS;
-    
-    if ((items < 1) || (items > 1)) {
-      SWIG_croak("Usage: Stream_get_data(self);");
-    }
-    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Stream, 0 |  0 );
-    if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Stream_get_data" "', argument " "1"" of type '" "Stream *""'"); 
-    }
-    arg1 = reinterpret_cast< Stream * >(argp1);
-    result = (char *)(arg1)->get_data();
-    ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
-    
-    XSRETURN(argvi);
-  fail:
-    
-    SWIG_croak_null();
-  }
-}
-
-
-XS(_wrap_new_Event) {
-  {
-    char *arg1 = (char *) 0 ;
-    char *arg2 = (char *) NULL ;
-    Event *result = 0 ;
-    int res1 ;
-    char *buf1 = 0 ;
-    int alloc1 = 0 ;
     int res2 ;
     char *buf2 = 0 ;
     int alloc2 = 0 ;
@@ -2552,56 +2900,28 @@
     dXSARGS;
     
     if ((items < 1) || (items > 2)) {
-      SWIG_croak("Usage: new_Event(type,subclass_name);");
+      SWIG_croak("Usage: Event_serialize(self,format);");
     }
-    res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1);
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, 0 |  0 );
     if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Event" "', argument " "1"" of type '" "char const *""'");
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Event_serialize" "', argument " "1"" of type '" "Event *""'"); 
     }
-    arg1 = reinterpret_cast< char * >(buf1);
+    arg1 = reinterpret_cast< Event * >(argp1);
     if (items > 1) {
       res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
       if (!SWIG_IsOK(res2)) {
-        SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_Event" "', argument " "2"" of type '" "char const *""'");
+        SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Event_serialize" "', argument " "2"" of type '" "char const *""'");
       }
       arg2 = reinterpret_cast< char * >(buf2);
     }
-    result = (Event *)new Event((char const *)arg1,(char const *)arg2);
-    ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_OWNER | SWIG_SHADOW); argvi++ ;
-    if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
-    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
-    XSRETURN(argvi);
-  fail:
-    if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
-    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
-    SWIG_croak_null();
-  }
-}
-
-
-XS(_wrap_delete_Event) {
-  {
-    Event *arg1 = (Event *) 0 ;
-    void *argp1 = 0 ;
-    int res1 = 0 ;
-    int argvi = 0;
-    dXSARGS;
-    
-    if ((items < 1) || (items > 1)) {
-      SWIG_croak("Usage: delete_Event(self);");
-    }
-    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Event, SWIG_POINTER_DISOWN |  0 );
-    if (!SWIG_IsOK(res1)) {
-      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Event" "', argument " "1"" of type '" "Event *""'"); 
-    }
-    arg1 = reinterpret_cast< Event * >(argp1);
-    delete arg1;
-    
-    
+    result = (char *)(arg1)->serialize((char const *)arg2);
+    ST(argvi) = SWIG_FromCharPtr((const char *)result); argvi++ ;
     
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
     XSRETURN(argvi);
   fail:
     
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
     SWIG_croak_null();
   }
 }
@@ -3447,6 +3767,91 @@
 }
 
 
+XS(_wrap_CoreSession_setPrivate) {
+  {
+    CoreSession *arg1 = (CoreSession *) 0 ;
+    char *arg2 = (char *) 0 ;
+    void *arg3 = (void *) 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    int res2 ;
+    char *buf2 = 0 ;
+    int alloc2 = 0 ;
+    int res3 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 3) || (items > 3)) {
+      SWIG_croak("Usage: CoreSession_setPrivate(self,var,val);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_setPrivate" "', argument " "1"" of type '" "CoreSession *""'"); 
+    }
+    arg1 = reinterpret_cast< CoreSession * >(argp1);
+    res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+    if (!SWIG_IsOK(res2)) {
+      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_setPrivate" "', argument " "2"" of type '" "char *""'");
+    }
+    arg2 = reinterpret_cast< char * >(buf2);
+    res3 = SWIG_ConvertPtr(ST(2),SWIG_as_voidptrptr(&arg3), 0, 0);
+    if (!SWIG_IsOK(res3)) {
+      SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CoreSession_setPrivate" "', argument " "3"" of type '" "void *""'"); 
+    }
+    (arg1)->setPrivate(arg2,arg3);
+    
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    
+    XSRETURN(argvi);
+  fail:
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    
+    SWIG_croak_null();
+  }
+}
+
+
+XS(_wrap_CoreSession_getPrivate) {
+  {
+    CoreSession *arg1 = (CoreSession *) 0 ;
+    char *arg2 = (char *) 0 ;
+    void *result = 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: CoreSession_getPrivate(self,var);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_getPrivate" "', argument " "1"" of type '" "CoreSession *""'"); 
+    }
+    arg1 = reinterpret_cast< CoreSession * >(argp1);
+    res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2);
+    if (!SWIG_IsOK(res2)) {
+      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_getPrivate" "', argument " "2"" of type '" "char *""'");
+    }
+    arg2 = reinterpret_cast< char * >(buf2);
+    result = (void *)(arg1)->getPrivate(arg2);
+    ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_void, 0 | 0); argvi++ ;
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    XSRETURN(argvi);
+  fail:
+    
+    if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+    SWIG_croak_null();
+  }
+}
+
+
 XS(_wrap_CoreSession_getVariable) {
   {
     CoreSession *arg1 = (CoreSession *) 0 ;
@@ -4383,6 +4788,43 @@
 }
 
 
+XS(_wrap_CoreSession_sendEvent) {
+  {
+    CoreSession *arg1 = (CoreSession *) 0 ;
+    Event *arg2 = (Event *) 0 ;
+    void *argp1 = 0 ;
+    int res1 = 0 ;
+    void *argp2 = 0 ;
+    int res2 = 0 ;
+    int argvi = 0;
+    dXSARGS;
+    
+    if ((items < 2) || (items > 2)) {
+      SWIG_croak("Usage: CoreSession_sendEvent(self,sendME);");
+    }
+    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+    if (!SWIG_IsOK(res1)) {
+      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sendEvent" "', argument " "1"" of type '" "CoreSession *""'"); 
+    }
+    arg1 = reinterpret_cast< CoreSession * >(argp1);
+    res2 = SWIG_ConvertPtr(ST(1), &argp2,SWIGTYPE_p_Event, 0 |  0 );
+    if (!SWIG_IsOK(res2)) {
+      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sendEvent" "', argument " "2"" of type '" "Event *""'"); 
+    }
+    arg2 = reinterpret_cast< Event * >(argp2);
+    (arg1)->sendEvent(arg2);
+    
+    
+    
+    XSRETURN(argvi);
+  fail:
+    
+    
+    SWIG_croak_null();
+  }
+}
+
+
 XS(_wrap_CoreSession_begin_allow_threads) {
   {
     CoreSession *arg1 = (CoreSession *) 0 ;
@@ -5437,6 +5879,7 @@
 static swig_type_info _swigt__p_switch_channel_state_t = {"_p_switch_channel_state_t", "switch_channel_state_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_channel_t = {"_p_switch_channel_t", "switch_channel_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_core_session_t = {"_p_switch_core_session_t", "switch_core_session_t *", 0, 0, (void*)0, 0};
+static swig_type_info _swigt__p_switch_event_t = {"_p_switch_event_t", "switch_event_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_input_args_t = {"_p_switch_input_args_t", "switch_input_args_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_input_type_t = {"_p_switch_input_type_t", "switch_input_type_t *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_switch_priority_t = {"_p_switch_priority_t", "switch_priority_t *", 0, 0, (void*)0, 0};
@@ -5456,6 +5899,7 @@
   &_swigt__p_switch_channel_state_t,
   &_swigt__p_switch_channel_t,
   &_swigt__p_switch_core_session_t,
+  &_swigt__p_switch_event_t,
   &_swigt__p_switch_input_args_t,
   &_swigt__p_switch_input_type_t,
   &_swigt__p_switch_priority_t,
@@ -5475,6 +5919,7 @@
 static swig_cast_info _swigc__p_switch_channel_state_t[] = {  {&_swigt__p_switch_channel_state_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_channel_t[] = {  {&_swigt__p_switch_channel_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_core_session_t[] = {  {&_swigt__p_switch_core_session_t, 0, 0, 0},{0, 0, 0, 0}};
+static swig_cast_info _swigc__p_switch_event_t[] = {  {&_swigt__p_switch_event_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_input_args_t[] = {  {&_swigt__p_switch_input_args_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_input_type_t[] = {  {&_swigt__p_switch_input_type_t, 0, 0, 0},{0, 0, 0, 0}};
 static swig_cast_info _swigc__p_switch_priority_t[] = {  {&_swigt__p_switch_priority_t, 0, 0, 0},{0, 0, 0, 0}};
@@ -5494,6 +5939,7 @@
   _swigc__p_switch_channel_state_t,
   _swigc__p_switch_channel_t,
   _swigc__p_switch_core_session_t,
+  _swigc__p_switch_event_t,
   _swigc__p_switch_input_args_t,
   _swigc__p_switch_input_type_t,
   _swigc__p_switch_priority_t,
@@ -5520,7 +5966,6 @@
 {"freeswitchc::console_clean_log", _wrap_console_clean_log},
 {"freeswitchc::api_execute", _wrap_api_execute},
 {"freeswitchc::api_reply_delete", _wrap_api_reply_delete},
-{"freeswitchc::process_callback_result", _wrap_process_callback_result},
 {"freeswitchc::input_callback_state_t_function_set", _wrap_input_callback_state_t_function_set},
 {"freeswitchc::input_callback_state_t_function_get", _wrap_input_callback_state_t_function_get},
 {"freeswitchc::input_callback_state_t_threadState_set", _wrap_input_callback_state_t_threadState_set},
@@ -5535,8 +5980,15 @@
 {"freeswitchc::delete_Stream", _wrap_delete_Stream},
 {"freeswitchc::Stream_write", _wrap_Stream_write},
 {"freeswitchc::Stream_get_data", _wrap_Stream_get_data},
+{"freeswitchc::Event_event_set", _wrap_Event_event_set},
+{"freeswitchc::Event_event_get", _wrap_Event_event_get},
+{"freeswitchc::Event_serialized_string_set", _wrap_Event_serialized_string_set},
+{"freeswitchc::Event_serialized_string_get", _wrap_Event_serialized_string_get},
+{"freeswitchc::Event_mine_set", _wrap_Event_mine_set},
+{"freeswitchc::Event_mine_get", _wrap_Event_mine_get},
 {"freeswitchc::new_Event", _wrap_new_Event},
 {"freeswitchc::delete_Event", _wrap_delete_Event},
+{"freeswitchc::Event_serialize", _wrap_Event_serialize},
 {"freeswitchc::Event_set_priority", _wrap_Event_set_priority},
 {"freeswitchc::Event_get_header", _wrap_Event_get_header},
 {"freeswitchc::Event_get_body", _wrap_Event_get_body},
@@ -5561,6 +6013,8 @@
 {"freeswitchc::CoreSession_preAnswer", _wrap_CoreSession_preAnswer},
 {"freeswitchc::CoreSession_hangup", _wrap_CoreSession_hangup},
 {"freeswitchc::CoreSession_setVariable", _wrap_CoreSession_setVariable},
+{"freeswitchc::CoreSession_setPrivate", _wrap_CoreSession_setPrivate},
+{"freeswitchc::CoreSession_getPrivate", _wrap_CoreSession_getPrivate},
 {"freeswitchc::CoreSession_getVariable", _wrap_CoreSession_getVariable},
 {"freeswitchc::CoreSession_recordFile", _wrap_CoreSession_recordFile},
 {"freeswitchc::CoreSession_setCallerData", _wrap_CoreSession_setCallerData},
@@ -5579,6 +6033,7 @@
 {"freeswitchc::CoreSession_setHangupHook", _wrap_CoreSession_setHangupHook},
 {"freeswitchc::CoreSession_ready", _wrap_CoreSession_ready},
 {"freeswitchc::CoreSession_execute", _wrap_CoreSession_execute},
+{"freeswitchc::CoreSession_sendEvent", _wrap_CoreSession_sendEvent},
 {"freeswitchc::CoreSession_begin_allow_threads", _wrap_CoreSession_begin_allow_threads},
 {"freeswitchc::CoreSession_end_allow_threads", _wrap_CoreSession_end_allow_threads},
 {"freeswitchc::CoreSession_get_uuid", _wrap_CoreSession_get_uuid},

Modified: freeswitch/trunk/src/switch_cpp.cpp
==============================================================================
--- freeswitch/trunk/src/switch_cpp.cpp	(original)
+++ freeswitch/trunk/src/switch_cpp.cpp	Tue Apr 29 19:34:26 2008
@@ -37,30 +37,83 @@
 #pragma warning(disable:4127 4003)
 #endif
 
-#define sanity_check(x) do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
-#define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
-#define init_vars() do { session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown";  caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = "";  caller_profile.username = ""; on_hangup = NULL; cb_state.function = NULL; } while(0)
 
 Event::Event(const char *type, const char *subclass_name)
 {
 	switch_event_types_t event_id;
-
+	
 	if (switch_name_event(type, &event_id) != SWITCH_STATUS_SUCCESS) {
 		event_id = SWITCH_EVENT_MESSAGE;
 	}
 
 	switch_event_create_subclass(&event, event_id, subclass_name);
+	serialized_string = NULL;
+	mine = 1;
+}
+
+Event::Event(switch_event_t *wrap_me, int free_me)
+{
+	event = wrap_me;
+	mine = free_me;
+	serialized_string = NULL;
 }
 
 Event::~Event()
 {
-	if (event) {
+
+	if (serialized_string) {
+		free(serialized_string);
+	}
+
+	if (event && mine) {
 		switch_event_destroy(&event);
 	}
 }
 
+
+const char *Event::serialize(const char *format)
+{
+	int isxml = 0;
+
+	if (serialized_string) {
+		free(serialized_string);
+	}
+
+	if (!event) {
+		return "";
+	}
+
+	if (format && !strcasecmp(format, "xml")) {
+		isxml++;
+	}
+
+	if (isxml) {
+		switch_xml_t xml;
+		char *xmlstr;
+		if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) {
+			serialized_string = switch_xml_toxml(xml, SWITCH_FALSE);
+			switch_xml_free(xml);
+			return serialized_string;
+		} else {
+			return "";
+		}
+	} else {
+		if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
+			return serialized_string;
+		}
+	}
+	
+	return "";
+
+}
+
 bool Event::fire(void)
 {
+	if (!mine) {
+		switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Not My event!\n");
+		return false;
+	}
+
 	if (event) {
 		switch_event_fire(&event);
 		return true;
@@ -184,7 +237,7 @@
 {
 	memset(&caller_profile, 0, sizeof(caller_profile)); 	
 	init_vars();
-	if (session = switch_core_session_locate(nuuid)) {
+	if (!strchr(nuuid, '/') && (session = switch_core_session_locate(nuuid))) {
 		uuid = strdup(nuuid);
 		channel = switch_core_session_get_channel(session);
 		allocated = 1;
@@ -254,6 +307,18 @@
     switch_channel_hangup(channel, switch_channel_str2cause(cause));
 }
 
+void CoreSession::setPrivate(char *var, void *val)
+{
+	sanity_check_noreturn;
+    switch_channel_set_private(channel, var, val);
+}
+
+void *CoreSession::getPrivate(char *var)
+{
+	sanity_check(NULL);
+    return switch_channel_get_private(channel, var);
+}
+
 void CoreSession::setVariable(char *var, char *val)
 {
 	sanity_check_noreturn;
@@ -301,6 +366,15 @@
 
 }
 
+void CoreSession::sendEvent(Event *sendME)
+{
+	if (sendME->mine) {
+		switch_core_session_receive_event(session, &sendME->event);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Not My event!\n");
+	}
+}
+
 int CoreSession::speak(char *text)
 {
     switch_status_t status;
@@ -417,24 +491,30 @@
 int CoreSession::streamFile(char *file, int starting_sample_count) {
 
     switch_status_t status;
-    switch_file_handle_t fh = { 0 };
+    //switch_file_handle_t fh = { 0 };
 	const char *prebuf;
 
     sanity_check(-1);
-    fh.samples = starting_sample_count;
-	store_file_handle(&fh);
+	
+	memset(&local_fh, 0, sizeof(local_fh));
+	fhp = &local_fh;
+    local_fh.samples = starting_sample_count;
 
-    begin_allow_threads();
-    status = switch_ivr_play_file(session, &fh, file, ap);
-    end_allow_threads();
 
 	if ((prebuf = switch_channel_get_variable(this->channel, "stream_prebuffer"))) {
         int maybe = atoi(prebuf);
         if (maybe > 0) {
-            fh.prebuf = maybe;
+            local_fh.prebuf = maybe;
         }
 	}
 
+
+	store_file_handle(&local_fh);
+
+    begin_allow_threads();
+    status = switch_ivr_play_file(session, fhp, file, ap);
+    end_allow_threads();
+
     return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
 
 }
@@ -676,7 +756,7 @@
 	switch_channel_state_t state = switch_channel_get_state(channel);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hangup_hook called\n");
-	fflush(stdout);
+	
 
 	if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
 		if (coresession->hook_state != state) {
@@ -700,9 +780,11 @@
 	switch_status_t result;
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "dtmf_callback called\n");
-	fflush(stdout);
 
+
+	//coresession = (CoreSession *) buf;
 	coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession");
+
 	if (!coresession) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid CoreSession\n");		
 		return SWITCH_STATUS_FALSE;
@@ -717,24 +799,24 @@
 
 }
 
-switch_status_t process_callback_result(char *ret, 
-					struct input_callback_state *cb_state,
-					switch_core_session_t *session) 
+
+
+switch_status_t CoreSession::process_callback_result(char *ret)
 {
 	
     switch_file_handle_t *fh = NULL;	   
 
-    if (!cb_state) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state is null\n");
-		return SWITCH_STATUS_FALSE;	
-    }
-
-    if (!cb_state->extra) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state->extra is null\n");
-		return SWITCH_STATUS_FALSE;	
-    }
+	if (fhp) {
+		fh = fhp;
+	} else {
+		if (!cb_state.extra) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state.extra is null\n");
+			return SWITCH_STATUS_FALSE;	
+		}
+		
+		fh = (switch_file_handle_t *) cb_state.extra;    
+	}
 
-    fh = (switch_file_handle_t *) cb_state->extra;    
 
     if (!fh) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because fh is null\n");
@@ -747,8 +829,7 @@
     }
 
     if (!ret) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because ret is null\n");
-		return SWITCH_STATUS_FALSE;	
+		return SWITCH_STATUS_SUCCESS;	
     }
 
     if (!session) {

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Tue Apr 29 19:34:26 2008
@@ -871,7 +871,7 @@
 		add_xml_header(xml, hp->name, hp->value, off++);
 	}
 
-	if (data) {
+	if (!switch_strlen_zero(data)) {
 		body = data;
 	} else if (event->body) {
 		body = event->body;



More information about the Freeswitch-svn mailing list