2006-09-10 19:19:15 -04:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2009-02-04 16:20:54 -05:00
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthm@freeswitch.org>
|
2006-09-10 19:19:15 -04:00
|
|
|
*
|
|
|
|
* 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
|
2009-02-04 16:20:54 -05:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-09-10 19:19:15 -04:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 16:20:54 -05:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-09-10 19:19:15 -04:00
|
|
|
* Brian Fertig <brian.fertig@convergencetek.com>
|
|
|
|
*
|
|
|
|
* php_freeswitch.c -- PHP Module Framework
|
|
|
|
*
|
|
|
|
*/
|
2006-09-07 16:00:23 -04:00
|
|
|
#include <switch.h>
|
|
|
|
#ifdef __ICC
|
|
|
|
#pragma warning (disable:1418)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <php.h>
|
|
|
|
#pragma comment(lib, PHP_LIB)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void fs_core_set_globals(void)
|
|
|
|
{
|
|
|
|
switch_core_set_globals();
|
|
|
|
}
|
|
|
|
|
|
|
|
int fs_core_init(char *path)
|
|
|
|
{
|
|
|
|
switch_status_t status;
|
|
|
|
const char *err = NULL;
|
|
|
|
|
|
|
|
if (switch_strlen_zero(path)) {
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-30 16:19:24 -04:00
|
|
|
status = switch_core_init(path, SCF_NONE, &err);
|
2006-09-07 16:00:23 -04:00
|
|
|
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fs_core_destroy(void)
|
|
|
|
{
|
|
|
|
switch_status_t status;
|
|
|
|
|
2007-03-05 09:37:15 -05:00
|
|
|
status = switch_core_destroy();
|
2006-09-07 16:00:23 -04:00
|
|
|
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fs_loadable_module_init(void)
|
|
|
|
{
|
|
|
|
return switch_loadable_module_init() == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fs_loadable_module_shutdown(void)
|
|
|
|
{
|
|
|
|
switch_loadable_module_shutdown();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
int fs_console_loop(void)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_console_loop();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-10 19:19:15 -04:00
|
|
|
void fs_consol_log(char *level_str, char *msg)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_log_level_t level = SWITCH_LOG_DEBUG;
|
|
|
|
if (level_str) {
|
|
|
|
level = switch_log_str2level(level_str);
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
|
2006-09-07 16:00:23 -04:00
|
|
|
}
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2006-09-10 19:19:15 -04:00
|
|
|
void fs_consol_clean(char *msg)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, msg);
|
2006-09-07 16:00:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_core_session_t *fs_core_session_locate(char *uuid)
|
|
|
|
{
|
2006-09-07 23:09:26 -04:00
|
|
|
switch_core_session_t *session;
|
|
|
|
|
|
|
|
if ((session = switch_core_session_locate(uuid))) {
|
|
|
|
switch_core_session_rwunlock(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
return session;
|
2006-09-07 16:00:23 -04:00
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
void fs_channel_answer(switch_core_session_t *session)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
2006-09-11 21:23:53 -04:00
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
2006-09-07 16:00:23 -04:00
|
|
|
switch_channel_answer(channel);
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
void fs_channel_pre_answer(switch_core_session_t *session)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_pre_answer(channel);
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
void fs_channel_hangup(switch_core_session_t *session, char *cause)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_hangup(channel, switch_channel_str2cause(cause));
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
void fs_channel_set_variable(switch_core_session_t *session, char *var, char *val)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_set_variable(channel, var, val);
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
void fs_channel_get_variable(switch_core_session_t *session, char *var)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_get_variable(channel, var);
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
void fs_channel_set_state(switch_core_session_t *session, char *state)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
|
|
|
switch_channel_state_t fs_state = switch_channel_get_state(channel);
|
|
|
|
|
|
|
|
if ((fs_state = switch_channel_name_state(state)) < CS_HANGUP) {
|
|
|
|
switch_channel_set_state(channel, fs_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-10 19:19:15 -04:00
|
|
|
/*
|
2006-11-28 16:46:29 -05:00
|
|
|
IVR Routines! You can do IVR in PHP NOW!
|
2006-09-10 19:19:15 -04:00
|
|
|
*/
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
int fs_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args)
|
2006-09-07 16:00:23 -04:00
|
|
|
{
|
|
|
|
switch_status_t status;
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2006-12-26 13:13:43 -05:00
|
|
|
status = switch_ivr_play_file(session, fh, file, args);
|
2006-09-07 16:00:23 -04:00
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2007-03-29 20:13:31 -04:00
|
|
|
int fs_switch_ivr_record_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args, unsigned int limit)
|
2007-03-29 18:31:56 -04:00
|
|
|
{
|
2006-09-10 19:19:15 -04:00
|
|
|
switch_status_t status;
|
2007-03-29 18:31:56 -04:00
|
|
|
|
|
|
|
status = switch_ivr_record_file(session, fh, file, args, limit);
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
int fs_switch_ivr_sleep(switch_core_session_t *session, uint32_t ms)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
|
|
|
switch_status_t status;
|
|
|
|
status = switch_ivr_sleep(session, ms);
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
2006-09-07 23:09:26 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
int fs_ivr_play_file2(switch_core_session_t *session, char *file)
|
2006-09-07 23:09:26 -04:00
|
|
|
{
|
|
|
|
switch_status_t status;
|
2007-03-29 18:31:56 -04:00
|
|
|
|
2006-12-26 13:13:43 -05:00
|
|
|
status = switch_ivr_play_file(session, NULL, file, NULL);
|
2006-09-07 23:09:26 -04:00
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-03-29 20:13:31 -04:00
|
|
|
int fs_switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, unsigned int timeout)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status;
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
status = switch_ivr_collect_digits_callback(session, args, timeout);
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
int fs_switch_ivr_collect_digits_count(switch_core_session_t *session,
|
2007-03-29 20:15:25 -04:00
|
|
|
char *buf, unsigned int buflen, unsigned int maxdigits, const char *terminators, char *terminator,
|
|
|
|
unsigned int timeout)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status;
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
status = switch_ivr_collect_digits_count(session, buf, buflen, maxdigits, terminators, terminator, timeout);
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*int fs_switch_ivr_multi_threaded_bridge (switch_core_session_t *session,
|
2006-11-28 16:46:29 -05:00
|
|
|
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;
|
|
|
|
}
|
2006-09-10 19:19:15 -04:00
|
|
|
*/
|
|
|
|
|
2007-03-29 20:13:31 -04:00
|
|
|
int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, char *bridgeto, uint32_t timelimit_sec)
|
2006-11-28 16:46:29 -05:00
|
|
|
/*const switch_state_handler_table_t *table,
|
|
|
|
char * cid_name_override,
|
|
|
|
char * cid_num_override,
|
|
|
|
switch_caller_profile_t *caller_profile_override) */
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_channel_t *caller_channel;
|
|
|
|
switch_core_session_t *peer_session;
|
|
|
|
unsigned int timelimit = 60;
|
|
|
|
char *var;
|
|
|
|
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
|
|
|
|
|
|
|
|
caller_channel = switch_core_session_get_channel(session);
|
|
|
|
assert(caller_channel != NULL);
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) {
|
|
|
|
timelimit = atoi(var);
|
|
|
|
}
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-12-20 16:42:00 -05:00
|
|
|
if (switch_ivr_originate(session, &peer_session, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
|
2007-03-29 18:31:56 -04:00
|
|
|
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);
|
2008-05-27 00:30:03 -04:00
|
|
|
switch_core_session_rwunlock(peer_session);
|
2007-03-29 18:31:56 -04:00
|
|
|
}
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
int fs_switch_ivr_session_transfer(switch_core_session_t *session, char *extension, char *dialplan, char *context)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status;
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
status = switch_ivr_session_transfer(session, extension, dialplan, context);
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
|
|
|
|
2007-08-28 13:06:20 -04:00
|
|
|
int fs_switch_ivr_speak_text(switch_core_session_t *session, char *tts_name, char *voice_name, char *text)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status;
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2007-08-28 13:06:20 -04:00
|
|
|
status = switch_ivr_speak_text(session, tts_name, voice_name, text, NULL);
|
2007-03-29 18:31:56 -04:00
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
2006-09-10 19:19:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
******* CHANNEL STUFF *******
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
char *fs_switch_channel_get_variable(switch_channel_t *channel, char *varname)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
|
|
|
return switch_channel_get_variable(channel, varname);
|
|
|
|
}
|
|
|
|
|
2006-09-11 21:23:53 -04:00
|
|
|
int fs_switch_channel_set_variable(switch_channel_t *channel, char *varname, char *value)
|
2006-09-10 19:19:15 -04:00
|
|
|
{
|
2007-03-29 18:31:56 -04:00
|
|
|
switch_status_t status;
|
2006-09-11 21:23:53 -04:00
|
|
|
|
2007-03-29 18:31:56 -04:00
|
|
|
status = switch_channel_set_variable(channel, varname, value);
|
|
|
|
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
|
|
|
|
}
|
2006-09-10 19:19:15 -04:00
|
|
|
|
2006-11-27 17:30:48 -05:00
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 17:14:57 -05:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 17:30:48 -05:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|