-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathswitch_swig.c
294 lines (238 loc) · 8.01 KB
/
switch_swig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
*
* 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 <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthm@freeswitch.org>
* Brian Fertig <brian.fertig@convergencetek.com>
*
* php_freeswitch.c -- PHP Module Framework
*
*/
#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 (zstr(path)) {
path = NULL;
}
status = switch_core_init(path, SCF_NONE, &err);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
int fs_core_destroy(void)
{
switch_status_t status;
status = switch_core_destroy();
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;
}
int fs_console_loop(void)
{
switch_console_loop();
return 0;
}
void fs_consol_log(char *level_str, char *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_consol_clean(char *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 *session;
if ((session = switch_core_session_locate(uuid))) {
switch_core_session_rwunlock(session);
}
return session;
}
void fs_channel_answer(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_answer(channel);
}
void fs_channel_pre_answer(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_pre_answer(channel);
}
void fs_channel_hangup(switch_core_session_t *session, char *cause)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_hangup(channel, switch_channel_str2cause(cause));
}
void fs_channel_set_variable(switch_core_session_t *session, char *var, char *val)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_variable(channel, var, val);
}
void fs_channel_get_variable(switch_core_session_t *session, char *var)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_get_variable(channel, var);
}
void fs_channel_set_state(switch_core_session_t *session, char *state)
{
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);
}
}
/*
IVR Routines! You can do IVR in PHP NOW!
*/
int fs_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args)
{
switch_status_t status;
status = switch_ivr_play_file(session, fh, file, args);
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_args_t *args, unsigned int limit)
{
switch_status_t status;
status = switch_ivr_record_file(session, fh, file, args, limit);
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, char *file)
{
switch_status_t status;
status = switch_ivr_play_file(session, NULL, file, NULL);
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
int fs_switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, unsigned int timeout)
{
switch_status_t status;
status = switch_ivr_collect_digits_callback(session, args, timeout);
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 = SWITCH_DEFAULT_TIMEOUT;
char *var;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
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, &cause, bridgeto, timelimit, NULL, NULL, NULL, NULL, SOF_NONE, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "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);
switch_core_session_rwunlock(peer_session);
}
}
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 *text)
{
switch_status_t status;
status = switch_ivr_speak_text(session, tts_name, voice_name, text, NULL);
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;
}
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/