git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4406 d0543943-73ff-0310-b7d9-9358b9ac24b2

This commit is contained in:
Brian West 2007-02-27 19:57:20 +00:00
parent 58f7f5da9b
commit 4575a9ea5f
11 changed files with 0 additions and 3618 deletions

View File

@ -1,19 +0,0 @@
MOD_PHP (c)2006 Tony M, Brian Fertig & Contributors
***8SEPT06***
Added all of the IVR features for the core.
Added Channel Variable Functions
***TODO***
Add Logging
Add other thing
Build PHP Class Framework for PHP & Freeswitch

View File

@ -1,55 +0,0 @@
#Usage: /usr/local/freeswitch/bin/php-config [--prefix|--includes|--ldflags|--libs|--extension-dir|--include-dir|--php-binary|--version]
PCFG=$(PREFIX)/bin/php-config
LCFLAGS=-fPIC -DZTS -DPTHREADS
# we should NOT use -fno-strict-aliasing. we need to fix this issue, but it is an issue in the php header files. we need to be careful of the optimization level on this module becuase of this setting.
CFLAGS += `$(PCFG) --includes` -g3 -fno-strict-aliasing
MDIR += `$(PCFG) --extension-dir`
PHPMOD=freeswitch
PHPLDFLAGS = `$(PCFG) --ldflags` -lm -ldl -lxml2 -lz -lphp5
MOD_CFLAGS += -fPIC
SWIGCFILE=../../../switch_swig.c
SWIGIFILE=../../../switch_swig.i
all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PHPMOD).$(DYNAMIC_LIB_EXTEN)
depends:
MOD_CFLAGS="$(MOD_CFLAGS)" MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install zlib-1.2.3.tar.gz --prefix=$(PREFIX)
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl --prefix=$(PREFIX)
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-5.1.6.tar.gz --prefix=$(PREFIX) --enable-embed=shared --enable-shared --with-pic --with-zlib=$(PREFIX) --with-curl --enable-maintainer-zts --with-tsrm-pthreads --enable-debug
%.o: %.c
$(CC) $(LCFLAGS) $(CFLAGS) -c $< -o $@
reswig:
rm -f switch_swig_wrap.c config.m4 CREDITS *$(PHPMOD)*
swig -o switch_swig_wrap.c -l$(SWIGIFILE) -ignoremissing -DMULTIPLICITY -php -module $(PHPMOD) $(SWIGCFILE)
patch -p0 -i fix.diff
switch_swig_wrap.o: switch_swig_wrap.c Makefile
$(CC) -w $(CFLAGS) -c $< -o $@
switch_swig.o: $(SWIGCFILE) Makefile
$(CC) -w $(CFLAGS) -c $< -o $@
$(PHPMOD).$(DYNAMIC_LIB_EXTEN): $(MODNAME).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o Makefile
$(CC) $(SOLINK) -o php_$(PHPMOD).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o $(LDFLAGS)
$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).o $(OBJS) Makefile
$(CC) $(LCFLAGS) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(MODNAME).o $(OBJS) $(LDFLAGS) $(PHPLDFLAGS)
clean:
rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~
install:
#mkdir -p $(MDIR)
#cp -f php_$(PHPMOD).$(DYNAMIC_LIB_EXTEN) $(MDIR)
cp -f php_$(PHPMOD).$(DYNAMIC_LIB_EXTEN) $(PREFIX)/lib/php/extensions
cp -f $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PREFIX)/mod
cp -f $(PHPMOD).php $(PREFIX)/lib/php
cp -f classFreeswitch.php $(PREFIX)/lib/php
cp -f freeswitch.php $(PREFIX)/lib/php
cp -f apptest.php $(PREFIX)/scripts
cp -f test.php $(PREFIX)/scripts
cp -f php.ini $(PREFIX)/lib

View File

@ -1,17 +0,0 @@
<?
/*
This application does not fall under the MPL. Its 100% freeware
no code needs to be submitted back to us for this.
(c)2006 Brian Fertig
*/
require("classFreeswitch.php");
$fs = new fs_class_api($uuid); // $uuid MUST be there for the class to work.
$fs->fs_answer();
//$fs->fs_play_file("/ram/sr8k.wav");
?>

View File

@ -1,154 +0,0 @@
<?
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@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@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Brian Fertig <brian.fertig@convergencetek.com>
* IRC: docelmo
*
* php_freeswitch.c -- PHP Module Framework
*
*/
require("freeswitch.php"); // Required for freeswitch driver to be loaded
class fs_class_api {
Private $uuid;
function fs_class_api($uuid) {
$this->uuid = $uuid;
}
function fs_start() {
// only use this function if you plan to start freeswitch in your script.
fs_core_set_globals();
fs_core_init("");
fs_loadable_module_init();
fs_console_loop();
fs_core_destroy();
}
function fs_log($level_str, $msg) {
fs_console_log($level_str, $msg);
}
function fs_log_clean($msg) {
fs_console_clean($msg);
}
function fs_answer(){
fs_channel_answer($this->uuid);
}
function fs_early_media(){
fs_channel_pre_answer($this->uuid);
}
function fs_hangup($cause){
fs_channel_hangup($this->uuid, $cause);
}
function fs_set_variable($var, $val){
fs_channel_set_variable($this->uuid, $var, $val);
}
function fs_get_variable($var){
return fs_channel_get_var($this->uuid, $var);
}
function fs_set_channel_state($state){
fs_channel_set_state($this->uuid, $state);
}
function fs_play_file($file){
return fs_ivr_play_file($this->uuid, $file, NULL, NULL, NULL, 0);
}
function record_file($file){
return fs_switch_ivr_record_file($this->uuid, NULL, $file, NULL, NULL, 0);
}
function fs_wait($ms){
return fs_switch_ivr_sleep($this->uuid, $ms);
}
function fs_get_dtmf_callback($len){
return fs_switch_ivr_collect_digits_callback($this->uuid, NULL, NULL, $len);
}
function fs_get_digit_count ($maxdigits, $terminator, $timeout){
return fs_switch_ivr_collect_digits_count($this->uuid, NULL, NULL, $maxdigits, NULL, $terminator, $timeout);
}
function fs_dial($data, $timelimit){
return fs_switch_ivr_originate($this->uuid, NULL, $data, $timelimit, NULL, NULL, NULL, NULL);
}
function fs_transfer($exten, $dialplan, $context){
return fs_switch_ivr_sessn_transfer($this->uuid, $exten, $dialplan, $context);
}
function fs_speak($ttsName, $voice, $text, $dtmf=NULL){
return fs_switch_ivr_speak_text($this->uuid, $ttsName, NULL, NULL, $dtmf, $text, NULL, 0);
}
}
?>

View File

@ -1,10 +0,0 @@
--- switch_swig_wrap.c 2006-09-07 14:16:42.000000000 -0400
+++ fix.c 2006-09-07 14:16:29.000000000 -0400
@@ -284,6 +284,7 @@
#include <string.h>
+#include "switch.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,24 +0,0 @@
<?php
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.21
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */
global $FREESWITCH_LOADED__;
if ($FREESWITCH_LOADED__) return;
$FREESWITCH_LOADED__ = true;
/* if our extension has not been loaded, do what we can */
if (!extension_loaded("php_freeswitch")) {
if (!dl("php_freeswitch.so")) return;
}
?>

View File

@ -1,323 +0,0 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@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@yahoo.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthmct@yahoo.com>
* Brian Fertig <brian.fertig@convergencetek.com>
* Steph Fox <steph@zend.com>
*
*
* mod_php.c -- PHP Module
*
*/
#ifndef _REENTRANT
#define _REENTRANT
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifdef _MSC_VER
//disable warnings for malformed header files
#pragma warning(push)
#pragma warning(disable:4127 4311 4133 4244 4201)
#define _USE_32BIT_TIME_T 1
#endif
#include <sapi/embed/php_embed.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef ZTS
zend_compiler_globals *compiler_globals;
zend_executor_globals *executor_globals;
php_core_globals *core_globals;
sapi_globals_struct *sapi_globals;
#endif
#include <switch.h>
const char modname[] = "mod_php";
static int sapi_mod_php_ub_write(const char *str, unsigned int str_length TSRMLS_DC)
{
char buffer[4096];
unsigned int i;
int j = 0;
FILE *fp = fopen("mod_php.log", "a");
fwrite(str, str_length, sizeof(char), fp);
fclose(fp);
for(i = 0; i < str_length; i++) {
buffer[j++] = str[i];
if(str[i] == 10) { /* new line */
buffer[j] = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s", buffer);
j = 0;
}
else if(str[i] == 0) { /* null character */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s", buffer);
j = 0;
}
if(j == 4095) { /* don't overfill buffer */
buffer[j] = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s", buffer);
j = 0;
}
}
if(j) { /* stuff left over */
buffer[j] = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s", buffer);
}
return str_length;
}
void mod_php_error_handler(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
{
char *buffer;
int buffer_len;
TSRMLS_FETCH();
buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
if((EG(error_reporting) & type || (type & E_CORE)) && (PG(log_errors) || PG(display_errors))) {
char *error_type_str;
switch (type) {
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
error_type_str = "Fatal error";
break;
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_WARNING:
error_type_str = "Warning";
break;
case E_PARSE:
error_type_str = "Parse error";
break;
case E_NOTICE:
case E_USER_NOTICE:
error_type_str = "Notice";
break;
default:
error_type_str = "Unknown error";
break;
}
if(PG(log_errors)) {
char *log_buffer;
spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
php_log_err(log_buffer TSRMLS_CC);
efree(log_buffer);
}
if(PG(display_errors)) {
char *prepend_string = INI_STR("error_prepend_string");
char *append_string = INI_STR("error_append_string");
char *error_format = "%s\n%s: %s in %s on line %d\n%s";
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
}
}
// Bail out if we can't recover
switch(type) {
case E_CORE_ERROR:
case E_ERROR:
//case E_PARSE: the parser would return 1 (failure), we can bail out nicely
case E_COMPILE_ERROR:
case E_USER_ERROR:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "\nPHP: %s exiting\n", error_filename);
EG(exit_status) = 255;
#if MEMORY_LIMIT
// restore memory limit
AG(memory_limit) = PG(memory_limit);
#endif
efree(buffer);
zend_bailout();
return;
}
// Log if necessary
if(PG(track_errors) && EG(active_symbol_table)) {
pval *tmp;
ALLOC_ZVAL(tmp);
INIT_PZVAL(tmp);
Z_STRVAL_P(tmp) = (char *) estrndup(buffer, buffer_len);
Z_STRLEN_P(tmp) = buffer_len;
Z_TYPE_P(tmp) = IS_STRING;
zend_hash_update(EG(active_symbol_table), "php_errormsg", sizeof("php_errormsg"), (void **) & tmp, sizeof(pval *), NULL);
}
efree(buffer);
}
static void mod_php_log_message(char *message)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s\n", message);
}
typedef void (*sapi_error_function_t)(int type, const char *error_msg, ...);
static void php_function(switch_core_session_t *session, char *data)
{
char *uuid = switch_core_session_get_uuid(session);
size_t ulen = strlen(uuid);
size_t len = strlen((char *) data) + ulen + 2;
char *mydata = switch_core_session_alloc(session, len);
int argc, retval;
char *argv[5];
char php_code[1024];
void*** tsrm_ls = NULL;
zend_file_handle script;
zval *php_uuid;
snprintf(mydata, len, "%s %s", uuid, data);
argc = switch_separate_string(mydata, ' ',argv,(sizeof(argv) / sizeof(argv[0])));
sprintf(php_code, "uuid=\"%s\"; include(\"%s\");\n", argv[0], argv[1]);
sprintf(php_code, "%s %s", data, uuid);
script.type = ZEND_HANDLE_FP;
script.filename = data;
script.opened_path = NULL;
script.free_filename = 0;
script.handle.fp = fopen(script.filename, "rb");
// Initialize PHPs CORE
php_embed_init(argc, argv, &tsrm_ls);
// Return All of the DEBUG crap to the console and/or a log file
php_embed_module.ub_write = sapi_mod_php_ub_write;
php_embed_module.log_message = mod_php_log_message;
php_embed_module.sapi_error = (sapi_error_function_t)mod_php_error_handler;
// Let the nice people know we are about to start their script
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting Script %s\n",data);
// Force $uuid and $session to exist in PHPs memory space
MAKE_STD_ZVAL(php_uuid);
#ifdef _MSC_VER
//disable warnings for malformed macros from header files
#pragma warning(push)
#pragma warning(disable:4127 4267)
#endif
ZVAL_STRING(php_uuid, uuid , 1);
ZEND_SET_SYMBOL(&EG(symbol_table), "uuid", php_uuid);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// Execute the bloody script
retval = php_execute_script(&script TSRMLS_CC);
// Clean up after PHP and such
php_embed_shutdown(tsrm_ls);
// Return back to the Dialplan
// Buh bye now!
}
static const switch_application_interface_t php_application_interface = {
/*.interface_name */ "php",
/*.application_function */ php_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE, /* should we support no media mode here? If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
/*.next*/ NULL
};
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_load(const switch_loadable_module_interface_t **module_interface, char *filename)
{
void*** tsrm_ls = NULL;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &php_module_interface;
#ifdef ZTS
tsrm_startup(1, 1, 0, NULL);
compiler_globals = ts_resource(compiler_globals_id);
executor_globals = ts_resource(executor_globals_id);
core_globals = ts_resource(core_globals_id);
sapi_globals = ts_resource(sapi_globals_id);
tsrm_ls = ts_resource(0);
#endif
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
/*
//Called when the system shuts down
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
return SWITCH_STATUS_SUCCESS;
}
//If it exists, this is called in it's own thread when the module-load completes
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
return SWITCH_STATUS_SUCCESS;
}
*/
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:nil
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +0,0 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.21
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */
/*
+----------------------------------------------------------------------+
| PHP version 4.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
#ifndef PHP_FREESWITCH_H
#define PHP_FREESWITCH_H
extern zend_module_entry freeswitch_module_entry;
#define phpext_freeswitch_ptr &freeswitch_module_entry
#ifdef PHP_WIN32
# define PHP_FREESWITCH_API __declspec(dllexport)
#else
# define PHP_FREESWITCH_API
#endif
PHP_MINIT_FUNCTION(freeswitch);
PHP_MSHUTDOWN_FUNCTION(freeswitch);
PHP_RINIT_FUNCTION(freeswitch);
PHP_RSHUTDOWN_FUNCTION(freeswitch);
PHP_MINFO_FUNCTION(freeswitch);
ZEND_NAMED_FUNCTION(_wrap_fs_core_set_globals);
ZEND_NAMED_FUNCTION(_wrap_fs_core_init);
ZEND_NAMED_FUNCTION(_wrap_fs_core_destroy);
ZEND_NAMED_FUNCTION(_wrap_fs_loadable_module_init);
ZEND_NAMED_FUNCTION(_wrap_fs_loadable_module_shutdown);
ZEND_NAMED_FUNCTION(_wrap_fs_console_loop);
ZEND_NAMED_FUNCTION(_wrap_fs_consol_log);
ZEND_NAMED_FUNCTION(_wrap_fs_consol_clean);
ZEND_NAMED_FUNCTION(_wrap_fs_core_session_locate);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_answer);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_pre_answer);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_hangup);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_set_variable);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_get_variable);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_set_state);
ZEND_NAMED_FUNCTION(_wrap_fs_ivr_play_file);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_record_file);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_sleep);
ZEND_NAMED_FUNCTION(_wrap_fs_ivr_play_file2);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_collect_digits_callback);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_collect_digits_count);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_originate);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_session_transfer);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_speak_text);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_channel_get_variable);
ZEND_NAMED_FUNCTION(_wrap_fs_switch_channel_set_variable);
/*If you declare any globals in php_freeswitch.h uncomment this:
ZEND_BEGIN_MODULE_GLOBALS(freeswitch)
ZEND_END_MODULE_GLOBALS(freeswitch)
*/
#ifdef ZTS
#define FREESWITCH_D zend_freeswitch_globals *freeswitch_globals
#define FREESWITCH_DC , FREESWITCH_D
#define FREESWITCH_C freeswitch_globals
#define FREESWITCH_CC , FREESWITCH_C
#define FREESWITCH_SG(v) (freeswitch_globals->v)
#define FREESWITCH_FETCH() zend_freeswitch_globals *freeswitch_globals = ts_resource(freeswitch_globals_id)
#else
#define FREESWITCH_D
#define FREESWITCH_DC
#define FREESWITCH_C
#define FREESWITCH_CC
#define FREESWITCH_SG(v) (freeswitch_globals.v)
#define FREESWITCH_FETCH()
#endif
#endif /* PHP_FREESWITCH_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
<?
include("classFreeswitch.php");
$fs = new fs_class_api;
$fs->fs_start();
?>