提交 ca74ae80 authored 作者: Brian Fertig's avatar Brian Fertig

Major Updates Still buggy

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2629 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 89649d47
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
...@@ -10,7 +10,7 @@ PHPLDFLAGS = `$(PCFG) --ldflags` -lcrypt -lresolv -lm -ldl -lnsl -lxml2 -lz -lph ...@@ -10,7 +10,7 @@ PHPLDFLAGS = `$(PCFG) --ldflags` -lcrypt -lresolv -lm -ldl -lnsl -lxml2 -lz -lph
all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PHPMOD).$(DYNAMIC_LIB_EXTEN) all: depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PHPMOD).$(DYNAMIC_LIB_EXTEN)
depends: depends:
MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-5.1.6.tar.gz --prefix=$(PREFIX) --enable-embed=static --enable-static --with-pic MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install php-5.1.6.tar.gz --prefix=$(PREFIX) --enable-embed=static --enable-static --with-pic --with-mysql --with-curl
%.o: %.c %.o: %.c
$(CC) $(LCFLAGS) $(CFLAGS) -c $< -o $@ $(CC) $(LCFLAGS) $(CFLAGS) -c $< -o $@
......
<? <?
include("freeswitch.php"); /*
$session = fs_core_session_locate($uuid);
fs_channel_answer($session); This application does not fall under the MPL. Its 100% freeware
fs_ivr_play_file2($session, "/ram/sr8k.wav"); no code needs to be submitted back to us for this.
(c)2006 Brian Fertig
*/
require("classFreeswitch.php");
$fs = new fs_class_api;
$fs->fs_answer($session);
$fs->fs_play_file($session, "/ram/sr8k.wav");
?> ?>
<?
/*
* 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
global $sessn;
class fs_class_api {
function fs_class_api() {
if($sessn = $this->fs_getsessn($uuid)){}
else{
echo "Couldnt get sessn!\n";
}
}
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_getsessn($uuid){
return fs_core_sessn_locate($uuid);
}
function fs_answer(){
fs_channel_answer($sessn);
}
function fs_early_media($sessn){
fs_channel_pre_answer($sessn);
}
function fs_hangup($cause){
fs_channel_hangup($sessn, $cause);
}
function fs_set_variable($var, $val){
fs_channel_set_variable($sessn, $var, $val);
}
function fs_get_variable($var){
return fs_channel_get_var($sessn, $var);
}
function fs_set_channel_state($state){
fs_channel_set_state($sessn, $state);
}
function fs_play_file($file){
return fs_ivr_play_file($sessn, $file, NULL, NULL, NULL, 0);
}
function record_file($file){
return fs_switch_ivr_record_file($sessn, NULL, $file, NULL, NULL, 0);
}
function fs_wait($ms){
return fs_switch_ivr_sleep($sessn, $ms);
}
function fs_get_dtmf_callback($len){
return fs_switch_ivr_collect_digits_callback($sessn, NULL, NULL, $len);
}
function fs_get_digit_count ($maxdigits, $terminator, $timeout){
return fs_switch_ivr_collect_digits_count($sessn, NULL, NULL, $maxdigits, NULL, $terminator, $timeout);
}
function fs_x_way($peer_sessn, $dtmf, $sessn_data, $peer_data){
return fs_switch_ivr_multi_threaded_bridge ($sessn, $peer_sessn, $dtmf, $sessn_data, $peer_data);
}
function fs_dial($data, $timelimit){
return fs_switch_ivr_originate(sessn, NULL, $data, $timelimit, NULL, NULL, NULL, NULL);
}
function fs_transfer($exten, $dialplan, $context){
return fs_switch_ivr_sessn_transfer($sessn, $exten, $dialplan, $context);
}
function fs_speak($ttsName, $voice, $text, $dtmf=NULL){
return fs_switch_ivr_speak_text($sessn, $ttsName, NULL, NULL, $dtmf, $text, NULL, 0);
}
}
?>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org). * This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.21 * Version 1.3.29
* *
* This file is not intended to be easily readable and contains a number of * 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 * coding conventions designed to improve portability and efficiency. Do not make
...@@ -16,7 +16,7 @@ $FREESWITCH_LOADED__ = true; ...@@ -16,7 +16,7 @@ $FREESWITCH_LOADED__ = true;
/* if our extension has not been loaded, do what we can */ /* if our extension has not been loaded, do what we can */
if (!extension_loaded("php_freeswitch")) { if (!extension_loaded("php_freeswitch")) {
if (!dl("php_freeswitch.so")) return; if (!dl("php_freeswitch.so")) return;
} }
......
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org). * This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.21 * Version 1.3.29
* *
* This file is not intended to be easily readable and contains a number of * 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 * coding conventions designed to improve portability and efficiency. Do not make
...@@ -40,6 +40,10 @@ extern zend_module_entry freeswitch_module_entry; ...@@ -40,6 +40,10 @@ extern zend_module_entry freeswitch_module_entry;
# define PHP_FREESWITCH_API # define PHP_FREESWITCH_API
#endif #endif
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(freeswitch); PHP_MINIT_FUNCTION(freeswitch);
PHP_MSHUTDOWN_FUNCTION(freeswitch); PHP_MSHUTDOWN_FUNCTION(freeswitch);
PHP_RINIT_FUNCTION(freeswitch); PHP_RINIT_FUNCTION(freeswitch);
...@@ -52,8 +56,8 @@ ZEND_NAMED_FUNCTION(_wrap_fs_core_destroy); ...@@ -52,8 +56,8 @@ ZEND_NAMED_FUNCTION(_wrap_fs_core_destroy);
ZEND_NAMED_FUNCTION(_wrap_fs_loadable_module_init); ZEND_NAMED_FUNCTION(_wrap_fs_loadable_module_init);
ZEND_NAMED_FUNCTION(_wrap_fs_loadable_module_shutdown); ZEND_NAMED_FUNCTION(_wrap_fs_loadable_module_shutdown);
ZEND_NAMED_FUNCTION(_wrap_fs_console_loop); ZEND_NAMED_FUNCTION(_wrap_fs_console_loop);
ZEND_NAMED_FUNCTION(_wrap_fs_console_log); ZEND_NAMED_FUNCTION(_wrap_fs_consol_log);
ZEND_NAMED_FUNCTION(_wrap_fs_console_clean); ZEND_NAMED_FUNCTION(_wrap_fs_consol_clean);
ZEND_NAMED_FUNCTION(_wrap_fs_core_session_locate); ZEND_NAMED_FUNCTION(_wrap_fs_core_session_locate);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_answer); ZEND_NAMED_FUNCTION(_wrap_fs_channel_answer);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_pre_answer); ZEND_NAMED_FUNCTION(_wrap_fs_channel_pre_answer);
...@@ -62,25 +66,14 @@ ZEND_NAMED_FUNCTION(_wrap_fs_channel_set_variable); ...@@ -62,25 +66,14 @@ ZEND_NAMED_FUNCTION(_wrap_fs_channel_set_variable);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_get_variable); ZEND_NAMED_FUNCTION(_wrap_fs_channel_get_variable);
ZEND_NAMED_FUNCTION(_wrap_fs_channel_set_state); ZEND_NAMED_FUNCTION(_wrap_fs_channel_set_state);
ZEND_NAMED_FUNCTION(_wrap_fs_ivr_play_file); 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_ivr_play_file2);
/*If you declare any globals in php_freeswitch.h uncomment this: ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_collect_digits_callback);
ZEND_BEGIN_MODULE_GLOBALS(freeswitch) ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_collect_digits_count);
ZEND_END_MODULE_GLOBALS(freeswitch) ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_originate);
*/ ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_session_transfer);
#ifdef ZTS ZEND_NAMED_FUNCTION(_wrap_fs_switch_ivr_speak_text);
#define FREESWITCH_D zend_freeswitch_globals *freeswitch_globals ZEND_NAMED_FUNCTION(_wrap_fs_switch_channel_get_variable);
#define FREESWITCH_DC , FREESWITCH_D ZEND_NAMED_FUNCTION(_wrap_fs_switch_channel_set_variable);
#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 */ #endif /* PHP_FREESWITCH_H */
/*
* 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>
*
* php_freeswitch.c -- PHP Module Framework
*
*/
#include <switch.h> #include <switch.h>
#ifdef __ICC #ifdef __ICC
#pragma warning (disable:1418) #pragma warning (disable:1418)
...@@ -55,14 +86,19 @@ int fs_console_loop(void) ...@@ -55,14 +86,19 @@ int fs_console_loop(void)
return 0; return 0;
} }
void fs_console_log(char *msg) void fs_consol_log(char *level_str, char *msg)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, msg); switch_log_level_t level = SWITCH_LOG_DEBUG;
if (level_str) {
level = switch_log_str2level(level_str);
}
switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
} }
void fs_console_clean(char *msg) void fs_consol_clean(char *msg)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, msg); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, msg);
} }
switch_core_session_t *fs_core_session_locate(char *uuid) switch_core_session_t *fs_core_session_locate(char *uuid)
...@@ -116,6 +152,11 @@ void fs_channel_set_state(switch_core_session_t *session, char *state) ...@@ -116,6 +152,11 @@ void fs_channel_set_state(switch_core_session_t *session, char *state)
} }
} }
/*
IVR Routines! You can do IVR in PHP NOW!
*/
int fs_ivr_play_file(switch_core_session_t *session, int fs_ivr_play_file(switch_core_session_t *session,
char *file, char *file,
char *timer_name, char *timer_name,
...@@ -132,6 +173,26 @@ int fs_ivr_play_file(switch_core_session_t *session, ...@@ -132,6 +173,26 @@ int fs_ivr_play_file(switch_core_session_t *session,
return status == SWITCH_STATUS_SUCCESS ? 1 : 0; return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
} }
int fs_switch_ivr_record_file(switch_core_session_t *session,
switch_file_handle_t *fh,
char *file,
switch_input_callback_function_t dtmf_callback,
void *buf,
unsigned int buflen)
{
switch_status_t status;
status = switch_ivr_record_file(session, fh, file, dtmf_callback, buf, buflen);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
int fs_switch_ivr_sleep(switch_core_session_t *session,
uint32_t ms)
{
switch_status_t status;
status = switch_ivr_sleep(session, ms);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
int fs_ivr_play_file2(switch_core_session_t *session, int fs_ivr_play_file2(switch_core_session_t *session,
char *file) char *file)
...@@ -143,3 +204,123 @@ int fs_ivr_play_file2(switch_core_session_t *session, ...@@ -143,3 +204,123 @@ int fs_ivr_play_file2(switch_core_session_t *session,
return status == SWITCH_STATUS_SUCCESS ? 1 : 0; return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
} }
int fs_switch_ivr_collect_digits_callback (switch_core_session_t *session,
switch_input_callback_function_t dtmf_callback,
void *buf,
unsigned int buflen)
{
switch_status_t status;
status = switch_ivr_collect_digits_callback(session, dtmf_callback, buf, buflen);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
int fs_switch_ivr_collect_digits_count (switch_core_session_t *session,
char *buf,
unsigned int buflen,
unsigned int maxdigits,
const char *terminators,
char *terminator,
unsigned int timeout)
{
switch_status_t status;
status = switch_ivr_collect_digits_count(session, buf, buflen, maxdigits, terminators, terminator, timeout);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
/*int fs_switch_ivr_multi_threaded_bridge (switch_core_session_t *session,
switch_core_session_t *peer_session,
switch_input_callback_function_t dtmf_callback,
void *session_data,
void *peer_session_data)
{
switch_status_t status;
status = switch_ivr_multi_threaded_bridge(session, peer_session, dtmf_callback, session_data, peer_session_data);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
*/
int fs_switch_ivr_originate (switch_core_session_t *session,
switch_core_session_t **bleg,
char * bridgeto,
uint32_t timelimit_sec)
/*const switch_state_handler_table_t *table,
char * cid_name_override,
char * cid_num_override,
switch_caller_profile_t *caller_profile_override) */
{
switch_channel_t *caller_channel;
switch_core_session_t *peer_session;
unsigned int timelimit = 60;
char *var;
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) {
timelimit = atoi(var);
}
if (switch_ivr_originate(session, &peer_session, bridgeto, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
return;
} else {
switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
}
}
int fs_switch_ivr_session_transfer(switch_core_session_t *session,
char *extension,
char *dialplan,
char *context)
{
switch_status_t status;
status = switch_ivr_session_transfer(session,extension,dialplan,context);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
int fs_switch_ivr_speak_text (switch_core_session_t *session,
char *tts_name,
char *voice_name,
char *timer_name,
uint32_t rate,
switch_input_callback_function_t dtmf_callback,
char *text,
void *buf,
unsigned int buflen)
{
switch_status_t status;
status = switch_ivr_speak_text(session,tts_name,voice_name,timer_name,rate,dtmf_callback,text,buf,buflen);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
/*
******* CHANNEL STUFF *******
*/
char* fs_switch_channel_get_variable(switch_channel_t *channel, char *varname)
{
return switch_channel_get_variable(channel, varname);
}
int fs_switch_channel_set_variable(switch_channel_t *channel, char *varname, char *value)
{
switch_status_t status;
status = switch_channel_set_variable(channel, varname, value);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
<? <?
include("classFreeswitch.php");
include("freeswitch.php"); $fs = new fs_class_api;
fs_core_set_globals(); $fs->fs_start();
fs_core_init("");
fs_loadable_module_init(); ?>
fs_console_loop();
fs_core_destroy();
?>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论