[Freeswitch-svn] [commit] r2527 - freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript
Freeswitch SVN
docelmo at freeswitch.org
Tue Sep 5 22:50:55 EDT 2006
Author: docelmo
Date: Tue Sep 5 22:50:55 2006
New Revision: 2527
Added:
freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/mod_elmoscript.c
Modified:
freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.c
freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.i
Log:
Added: freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/mod_elmoscript.c
==============================================================================
--- (empty file)
+++ freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/mod_elmoscript.c Tue Sep 5 22:50:55 2006
@@ -0,0 +1,132 @@
+/*
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Brian Fertig <brian.fertig at convergencetek.com>
+ *
+ *
+ * mod_elmoscript.c -- php Framework
+ *
+ */
+
+#include "php.h"
+#include "switch.h"
+static char *embedding[] = { "", "-q", "" };
+EXTERN_C void xs_init(pTHX);
+
+static const char modname[] = "mod_php";
+
+static struct {
+ phpInterpreter *my_php;
+} globals;
+
+
+static void destroy_php(phpInterpreter **to_destroy)
+{
+ php_destruct(*to_destroy);
+ php_free(*to_destroy);
+ *to_destroy = NULL;
+}
+
+static phpInterpreter *clone_php(void)
+{
+ return php_clone(globals.my_php, CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+}
+
+
+static void php_function(switch_core_session_t *session, char *data)
+{
+ char *uuid = switch_core_session_get_uuid(session);
+ char code[1024];
+ phpInterpreter *my_php = clone_php();
+ sprintf(code, "package fs_elmoscript;\n"
+ "$SWITCH_ENV{UUID} = \"%s\";\n"
+ "chdir(\"%s/php\");\n",
+ uuid, SWITCH_GLOBAL_dirs.base_dir);
+
+ php_eval_pv(my_php, code, TRUE);
+
+
+ php_eval_pv(my_php, data, TRUE);
+ destroy_php(&my_php);
+}
+
+static const switch_application_interface_t php_application_interface = {
+ /*.interface_name */ "elmoscript",
+ /*.application_function */ php_function
+};
+
+static switch_loadable_module_interface_t php_module_interface = {
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ &php_application_interface,
+ /*.api_interface */ NULL,
+ /*.file_interface */ NULL,
+ /*.speech_interface */ NULL,
+ /*.directory_interface */ NULL
+};
+
+
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
+{
+ if (globals.my_php) {
+ php_destruct(globals.my_php);
+ php_free(globals.my_php);
+ globals.my_php = NULL;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Unallocated php interpreter.\n");
+ }
+ return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
+{
+
+ phpInterpreter *my_php;
+ char code[1024];
+
+ if (!(my_php = php_alloc())) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate php intrepreter\n");
+ switch_core_destroy();
+ return SWITCH_STATUS_MEMERR;
+ }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocated php intrepreter.\n");
+
+ php_SET_CONTEXT(my_php);
+ php_construct(my_php);
+ php_parse(my_php, xs_init, 3, embedding, NULL);
+ php_run(my_php);
+ globals.my_php = my_php;
+ sprintf(code, "use lib '%s/php';use fs_elmoscript;use freeswitch\n", SWITCH_GLOBAL_dirs.base_dir);
+ php_eval_pv(my_php, code, TRUE);
+
+
+ /* connect my internal structure to the blank pointer passed to me */
+ *module_interface = &php_module_interface;
+
+ /* indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
+}
Modified: freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.c
==============================================================================
--- freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.c (original)
+++ freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.c Tue Sep 5 22:50:55 2006
@@ -4,12 +4,12 @@
#endif
-
+/*
#ifdef _MSC_VER
#include <php.h>
#pragma comment(lib, PHP_LIB)
#endif
-
+*/
void fs_core_set_globals(void)
{
switch_core_set_globals();
Modified: freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.i
==============================================================================
--- freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.i (original)
+++ freeswitch/branches/docelmo/trunk/src/mod/languages/mod_elmoscript/switch_swig.i Tue Sep 5 22:50:55 2006
@@ -1,9 +1,9 @@
// gd.i
%module fs_elmoscript
%{
-#include "/usr/local/freeswitch/include/switch.h"
+#include "switch.h"
%}
// Grab the gd.h header file
-%include "/usr/local/freeswitch/include/switch.h"
+%include "switch.h"
More information about the Freeswitch-svn
mailing list