FreeSWITCH API Documentation  1.7.0
switch_swig.c
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Brian Fertig <brian.fertig@convergencetek.com>
28  *
29  * php_freeswitch.c -- PHP Module Framework
30  *
31  */
32 #include <switch.h>
33 #ifdef __ICC
34 #pragma warning (disable:1418)
35 #endif
36 
37 #ifdef _MSC_VER
38 #include <php.h>
39 #pragma comment(lib, PHP_LIB)
40 #endif
41 
43 {
45 }
46 
47 int fs_core_init(char *path)
48 {
49  switch_status_t status;
50  const char *err = NULL;
51 
52  if (zstr(path)) {
53  path = NULL;
54  }
55 
56  status = switch_core_init(path, SCF_NONE, &err);
57 
58  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
59 }
60 
61 int fs_core_destroy(void)
62 {
63  switch_status_t status;
64 
65  status = switch_core_destroy();
66 
67  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
68 }
69 
71 {
73 }
74 
76 {
78  return 1;
79 }
80 
81 int fs_console_loop(void)
82 {
84  return 0;
85 }
86 
87 void fs_consol_log(char *level_str, char *msg)
88 {
90  if (level_str) {
91  level = switch_log_str2level(level_str);
92  }
93 
95 }
96 
97 void fs_consol_clean(char *msg)
98 {
100 }
101 
103 {
104  switch_core_session_t *session;
105 
106  if ((session = switch_core_session_locate(uuid))) {
108  }
109 
110  return session;
111 }
112 
114 {
116  switch_channel_answer(channel);
117 }
118 
120 {
122  switch_channel_pre_answer(channel);
123 }
124 
125 void fs_channel_hangup(switch_core_session_t *session, char *cause)
126 {
129 }
130 
131 void fs_channel_set_variable(switch_core_session_t *session, char *var, char *val)
132 {
134  switch_channel_set_variable(channel, var, val);
135 }
136 
138 {
140  switch_channel_get_variable(channel, var);
141 }
142 
144 {
147 
148  if ((fs_state = switch_channel_name_state(state)) < CS_HANGUP) {
149  switch_channel_set_state(channel, fs_state);
150  }
151 }
152 
153 /*
154  IVR Routines! You can do IVR in PHP NOW!
155 */
156 
158 {
159  switch_status_t status;
160 
161  status = switch_ivr_play_file(session, fh, file, args);
162  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
163 }
164 
165 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)
166 {
167  switch_status_t status;
168 
169  status = switch_ivr_record_file(session, fh, file, args, limit);
170  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
171 }
172 
173 int fs_switch_ivr_sleep(switch_core_session_t *session, uint32_t ms)
174 {
175  switch_status_t status;
176  status = switch_ivr_sleep(session, ms);
177  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
178 }
179 
180 int fs_ivr_play_file2(switch_core_session_t *session, char *file)
181 {
182  switch_status_t status;
183 
184  status = switch_ivr_play_file(session, NULL, file, NULL);
185  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
186 }
187 
188 
190 {
191  switch_status_t status;
192 
193  status = switch_ivr_collect_digits_callback(session, args, timeout);
194  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
195 }
196 
198  char *buf, unsigned int buflen, unsigned int maxdigits, const char *terminators, char *terminator,
199  unsigned int timeout)
200 {
201  switch_status_t status;
202 
203  status = switch_ivr_collect_digits_count(session, buf, buflen, maxdigits, terminators, terminator, timeout);
204  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
205 }
206 
207 /*int fs_switch_ivr_multi_threaded_bridge (switch_core_session_t *session,
208  switch_core_session_t *peer_session,
209  switch_input_callback_function_t dtmf_callback,
210  void *session_data,
211  void *peer_session_data)
212  {
213  switch_status_t status;
214 
215  status = switch_ivr_multi_threaded_bridge(session, peer_session, dtmf_callback, session_data, peer_session_data);
216  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
217  }
218 */
219 
220 int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, char *bridgeto, uint32_t timelimit_sec)
221 /*const switch_state_handler_table_t *table,
222  char * cid_name_override,
223  char * cid_num_override,
224  switch_caller_profile_t *caller_profile_override) */
225 {
226 
227  switch_channel_t *caller_channel;
228  switch_core_session_t *peer_session;
229  unsigned int timelimit = 60;
230  char *var;
232 
233  caller_channel = switch_core_session_get_channel(session);
234  assert(caller_channel != NULL);
235 
236  if ((var = switch_channel_get_variable(caller_channel, "call_timeout"))) {
237  timelimit = atoi(var);
238  }
239 
240  if (switch_ivr_originate(session, &peer_session, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
241  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Cannot Create Outgoing Channel!\n");
243  return;
244  } else {
245  switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
246  switch_core_session_rwunlock(peer_session);
247  }
248 }
249 
250 int fs_switch_ivr_session_transfer(switch_core_session_t *session, char *extension, char *dialplan, char *context)
251 {
252  switch_status_t status;
253 
254  status = switch_ivr_session_transfer(session, extension, dialplan, context);
255  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
256 }
257 
258 int fs_switch_ivr_speak_text(switch_core_session_t *session, char *tts_name, char *voice_name, char *text)
259 {
260  switch_status_t status;
261 
262  status = switch_ivr_speak_text(session, tts_name, voice_name, text, NULL);
263  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
264 }
265 
266 /*
267 
268 ******* CHANNEL STUFF *******
269 
270 */
271 
272 char *fs_switch_channel_get_variable(switch_channel_t *channel, char *varname)
273 {
274  return switch_channel_get_variable(channel, varname);
275 }
276 
277 int fs_switch_channel_set_variable(switch_channel_t *channel, char *varname, char *value)
278 {
279  switch_status_t status;
280 
281  status = switch_channel_set_variable(channel, varname, value);
282  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
283 }
284 
285 /* For Emacs:
286  * Local Variables:
287  * mode:c
288  * indent-tabs-mode:t
289  * tab-width:4
290  * c-basic-offset:4
291  * End:
292  * For VIM:
293  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
294  */
switch_core_session_t * fs_core_session_locate(char *uuid)
Definition: switch_swig.c:102
void fs_channel_set_variable(switch_core_session_t *session, char *var, char *val)
Definition: switch_swig.c:131
switch_channel_state_t switch_channel_get_state(switch_channel_t *channel)
Get the current state of a channel in the state engine.
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
#define switch_channel_answer(channel)
Answer a channel (initiate/acknowledge a successful connection)
int fs_ivr_play_file2(switch_core_session_t *session, char *file)
Definition: switch_swig.c:180
#define SWITCH_CHANNEL_SESSION_LOG(x)
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)
Definition: switch_swig.c:165
#define SWITCH_CHANNEL_LOG
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
switch_status_t switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_bool_t sync, switch_input_args_t *args)
Wait for time to pass for a specified number of milliseconds.
Definition: switch_ivr.c:127
switch_status_t switch_core_init(_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err)
Initilize the core.
switch_status_t switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout)
Wait for DTMF digits calling a pluggable callback function when digits are collected.
Definition: switch_ivr.c:1173
int fs_loadable_module_shutdown(void)
Definition: switch_swig.c:75
switch_channel_state_t switch_channel_name_state(_In_ const char *name)
Render the enum of the provided state name.
char * fs_switch_channel_get_variable(switch_channel_t *channel, char *varname)
Definition: switch_swig.c:272
void switch_core_set_globals(void)
Initiate Globals.
Definition: switch_core.c:620
int fs_loadable_module_init(void)
Definition: switch_swig.c:70
switch_status_t switch_core_destroy(void)
Destroy the core.
Definition: switch_core.c:2877
switch_status_t switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, const char *file, switch_input_args_t *args)
play a file from the disk to the session
switch_status_t switch_ivr_speak_text(switch_core_session_t *session, const char *tts_name, const char *voice_name, char *text, switch_input_args_t *args)
Speak given text with given tts engine.
void fs_channel_pre_answer(switch_core_session_t *session)
Definition: switch_swig.c:119
int fs_core_init(char *path)
Definition: switch_swig.c:47
void switch_loadable_module_shutdown(void)
Shutdown the module backend and call the shutdown routine in all loaded modules.
void fs_core_set_globals(void)
Definition: switch_swig.c:42
#define zstr(x)
Definition: switch_utils.h:281
int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, char *bridgeto, uint32_t timelimit_sec)
Definition: switch_swig.c:220
switch_status_t switch_ivr_session_transfer(_In_ switch_core_session_t *session, const char *extension, const char *dialplan, const char *context)
Transfer an existing session to another location.
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_status_t switch_ivr_collect_digits_count(switch_core_session_t *session, char *buf, switch_size_t buflen, switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout)
Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up...
Definition: switch_ivr.c:1287
void fs_consol_log(char *level_str, char *msg)
Definition: switch_swig.c:87
switch_byte_t switch_byte_t * buf
int fs_switch_ivr_session_transfer(switch_core_session_t *session, char *extension, char *dialplan, char *context)
Definition: switch_swig.c:250
switch_status_t switch_ivr_multi_threaded_bridge(_In_ switch_core_session_t *session, _In_ switch_core_session_t *peer_session, switch_input_callback_function_t dtmf_callback, void *session_data, void *peer_session_data)
Bridge Audio from one session to another.
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)
Definition: switch_swig.c:197
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
void fs_channel_get_variable(switch_core_session_t *session, char *var)
Definition: switch_swig.c:137
#define switch_channel_get_variable(_c, _v)
void fs_channel_hangup(switch_core_session_t *session, char *cause)
Definition: switch_swig.c:125
switch_call_cause_t switch_channel_str2cause(_In_ const char *str)
return a cause code for a given string
#define SWITCH_CHANNEL_LOG_CLEAN
switch_byte_t switch_byte_t uint32_t buflen
int fs_switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, unsigned int timeout)
Definition: switch_swig.c:189
switch_call_cause_t
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
switch_status_t switch_ivr_record_file(_In_ switch_core_session_t *session, _In_ switch_file_handle_t *fh, _In_z_ const char *file, _In_opt_ switch_input_args_t *args, _In_ uint32_t limit)
record a file from the session to a file
void fs_channel_set_state(switch_core_session_t *session, char *state)
Definition: switch_swig.c:143
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
switch_status_t
Common return values.
void fs_channel_answer(switch_core_session_t *session)
Definition: switch_swig.c:113
#define switch_core_session_locate(uuid_str)
Locate a session based on it's uuid.
Definition: switch_core.h:916
Main Library Header.
int fs_switch_channel_set_variable(switch_channel_t *channel, char *varname, char *value)
Definition: switch_swig.c:277
switch_status_t switch_loadable_module_init(switch_bool_t autoload)
Initilize the module backend and load all the modules.
int fs_switch_ivr_sleep(switch_core_session_t *session, uint32_t ms)
Definition: switch_swig.c:173
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
int fs_console_loop(void)
Definition: switch_swig.c:81
void fs_consol_clean(char *msg)
Definition: switch_swig.c:97
int fs_switch_ivr_speak_text(switch_core_session_t *session, char *tts_name, char *voice_name, char *text)
Definition: switch_swig.c:258
#define switch_channel_set_variable(_channel, _var, _val)
int fs_core_destroy(void)
Definition: switch_swig.c:61
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
void switch_console_loop(void)
A simple comand loop that reads input from the terminal.
switch_status_t switch_ivr_originate(switch_core_session_t *session, switch_core_session_t **bleg, switch_call_cause_t *cause, const char *bridgeto, uint32_t timelimit_sec, const switch_state_handler_table_t *table, const char *cid_name_override, const char *cid_num_override, switch_caller_profile_t *caller_profile_override, switch_event_t *ovars, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
Make an outgoing call.
switch_log_level_t
Log Level Enumeration.
int fs_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args)
Definition: switch_swig.c:157