-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrayo_fax_components.c
561 lines (498 loc) · 22.2 KB
/
rayo_fax_components.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
* mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2013-2014, Grasshopper
*
* 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 mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is Grasshopper
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Rienzo <[email protected]>
*
* rayo_fax_components.c -- Rayo receivefax and sendfax components implementation
*
*/
#include "rayo_components.h"
#include "rayo_elements.h"
/**
* settings
*/
static struct {
const char *file_prefix;
} globals;
struct fax_component {
/** component base class */
struct rayo_component base;
/** Flag to stop fax */
int stop;
};
#define FAX_COMPONENT(x) ((struct fax_component *)x)
struct receivefax_component {
/** fax component base class */
struct fax_component base;
/** true if HTTP PUT needs to be done after fax is received */
int http_put_after_receive;
/** fax stored on local filesystem */
const char *local_filename;
/** fax final target (may be same as local filename) */
const char *filename;
};
#define RECEIVEFAX_COMPONENT(x) ((struct receivefax_component *)x)
#define FAX_FINISH "finish", RAYO_FAX_COMPLETE_NS
/**
* Start execution of call sendfax component
* @param call the call to send fax to
* @param msg the original request
* @param session_data the call's session
*/
static iks *start_sendfax_component(struct rayo_actor *call, struct rayo_message *msg, void *session_data)
{
iks *iq = msg->payload;
switch_core_session_t *session = (switch_core_session_t *)session_data;
struct fax_component *sendfax_component = NULL;
iks *sendfax = iks_find(iq, "sendfax");
iks *response = NULL;
switch_event_t *execute_event = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_memory_pool_t *pool;
iks *document;
const char *fax_document;
const char *fax_header;
const char *fax_identity;
const char *pages;
/* validate attributes */
if (!VALIDATE_RAYO_SENDFAX(sendfax)) {
return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST);
}
/* fax is only allowed if the call is not currently joined */
if (rayo_call_is_joined(RAYO_CALL(call))) {
return iks_new_error_detailed(iq, STANZA_ERROR_UNEXPECTED_REQUEST, "can't send fax on a joined call");
}
if (rayo_call_is_faxing(RAYO_CALL(call))) {
return iks_new_error_detailed(iq, STANZA_ERROR_UNEXPECTED_REQUEST, "fax already in progress");
}
/* get fax document */
document = iks_find(sendfax, "document");
if (!document) {
return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "missing document");
}
fax_document = iks_find_attrib_soft(document, "url");
if (zstr(fax_document)) {
return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "missing document url");
}
/* is valid URL type? */
if (!strncasecmp(fax_document, "http://", 7) || !strncasecmp(fax_document, "https://", 8)) {
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
/* need to fetch document from server... */
switch_api_execute("http_get", fax_document, session, &stream);
if (!zstr(stream.data) && !strncmp(fax_document, SWITCH_PATH_SEPARATOR, strlen(SWITCH_PATH_SEPARATOR))) {
fax_document = switch_core_session_strdup(session, stream.data);
} else {
switch_safe_free(stream.data);
return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to fetch document");
}
switch_safe_free(stream.data);
} else if (!strncasecmp(fax_document, "file://", 7)) {
fax_document = fax_document + 7;
if (zstr(fax_document)) {
return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "invalid file:// url");
}
} else if (strncasecmp(fax_document, SWITCH_PATH_SEPARATOR, strlen(SWITCH_PATH_SEPARATOR))) {
return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "unsupported url type");
}
/* does document exist? */
if (switch_file_exists(fax_document, NULL) != SWITCH_STATUS_SUCCESS) {
return iks_new_error_detailed_printf(iq, STANZA_ERROR_BAD_REQUEST, "file not found: %s", fax_document);
}
/* get fax identity and header */
fax_identity = iks_find_attrib_soft(document, "identity");
if (!zstr(fax_identity)) {
switch_channel_set_variable(channel, "fax_ident", fax_identity);
} else {
switch_channel_set_variable(channel, "fax_ident", NULL);
}
fax_header = iks_find_attrib_soft(document, "header");
if (!zstr(fax_header)) {
switch_channel_set_variable(channel, "fax_header", fax_header);
} else {
switch_channel_set_variable(channel, "fax_header", NULL);
}
/* get pages to send */
pages = iks_find_attrib_soft(document, "pages");
if (!zstr(pages)) {
if (switch_regex_match(pages, "[1-9][0-9]*(-[1-9][0-9]*)?") == SWITCH_STATUS_FALSE) {
return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "invalid pages value");
} else {
int start = 0;
int end = 0;
char *pages_dup = switch_core_session_strdup(session, pages);
char *sep = strchr(pages_dup, '-');
if (sep) {
*sep = '\0';
sep++;
end = atoi(sep);
}
start = atoi(pages_dup);
if (end && end < start) {
return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "invalid pages value");
}
switch_channel_set_variable(channel, "fax_start_page", pages_dup);
switch_channel_set_variable(channel, "fax_end_page", sep);
}
} else {
switch_channel_set_variable(channel, "fax_start_page", NULL);
switch_channel_set_variable(channel, "fax_end_page", NULL);
}
/* create sendfax component */
switch_core_new_memory_pool(&pool);
sendfax_component = switch_core_alloc(pool, sizeof(*sendfax_component));
sendfax_component = FAX_COMPONENT(rayo_component_init((struct rayo_component *)sendfax_component, pool, RAT_CALL_COMPONENT, "sendfax", NULL, call, iks_find_attrib(iq, "from")));
if (!sendfax_component) {
switch_core_destroy_memory_pool(&pool);
return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "Failed to create sendfax entity");
}
/* add channel variable so that fax component can be located from fax events */
switch_channel_set_variable(channel, "rayo_fax_jid", RAYO_JID(sendfax_component));
/* clear fax result variables */
switch_channel_set_variable(channel, "fax_success", NULL);
switch_channel_set_variable(channel, "fax_result_code", NULL);
switch_channel_set_variable(channel, "fax_result_text", NULL);
switch_channel_set_variable(channel, "fax_document_transferred_pages", NULL);
switch_channel_set_variable(channel, "fax_document_total_pages", NULL);
switch_channel_set_variable(channel, "fax_image_resolution", NULL);
switch_channel_set_variable(channel, "fax_image_size", NULL);
switch_channel_set_variable(channel, "fax_bad_rows", NULL);
switch_channel_set_variable(channel, "fax_transfer_rate", NULL);
switch_channel_set_variable(channel, "fax_ecm_used", NULL);
switch_channel_set_variable(channel, "fax_local_station_id", NULL);
switch_channel_set_variable(channel, "fax_remote_station_id", NULL);
rayo_call_set_faxing(RAYO_CALL(call), 1);
/* execute txfax APP */
if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", "txfax");
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", fax_document);
if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) {
switch_channel_set_flag(channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA);
}
if (switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) {
response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to txfax (queue event failed)");
if (execute_event) {
switch_event_destroy(&execute_event);
}
rayo_call_set_faxing(RAYO_CALL(call), 0);
RAYO_RELEASE(sendfax_component);
} else {
/* component starting... */
rayo_component_send_start(RAYO_COMPONENT(sendfax_component), iq);
}
} else {
response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to create txfax event");
rayo_call_set_faxing(RAYO_CALL(call), 0);
RAYO_RELEASE(sendfax_component);
}
return response;
}
/**
* Start execution of call receivefax component
* @param call the call to receive fax from
* @param msg the original request
* @param session_data the call's session
*/
static iks *start_receivefax_component(struct rayo_actor *call, struct rayo_message *msg, void *session_data)
{
iks *iq = msg->payload;
switch_core_session_t *session = (switch_core_session_t *)session_data;
struct receivefax_component *receivefax_component = NULL;
iks *receivefax = iks_find(iq, "receivefax");
iks *response = NULL;
switch_event_t *execute_event = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_memory_pool_t *pool;
int file_no;
/* validate attributes */
if (!VALIDATE_RAYO_RECEIVEFAX(receivefax)) {
return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST);
}
/* fax is only allowed if the call is not currently joined */
if (rayo_call_is_joined(RAYO_CALL(call))) {
return iks_new_error_detailed(iq, STANZA_ERROR_UNEXPECTED_REQUEST, "can't receive fax on a joined call");
}
if (rayo_call_is_faxing(RAYO_CALL(call))) {
return iks_new_error_detailed(iq, STANZA_ERROR_UNEXPECTED_REQUEST, "fax already in progress");
}
/* create receivefax component */
switch_core_new_memory_pool(&pool);
receivefax_component = switch_core_alloc(pool, sizeof(*receivefax_component));
receivefax_component = RECEIVEFAX_COMPONENT(rayo_component_init((struct rayo_component *)receivefax_component, pool, RAT_CALL_COMPONENT, "receivefax", NULL, call, iks_find_attrib(iq, "from")));
if (!receivefax_component) {
switch_core_destroy_memory_pool(&pool);
return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "Failed to create sendfax entity");
}
file_no = rayo_actor_seq_next(call);
receivefax_component->filename = switch_core_sprintf(pool, "%s%s%s-%d.tif",
globals.file_prefix, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session), file_no);
if (!strncmp(receivefax_component->filename, "http://", 7) || !strncmp(receivefax_component->filename, "https://", 8)) {
/* This is an HTTP URL, need to PUT after fax is received */
receivefax_component->local_filename = switch_core_sprintf(pool, "%s%s%s-%d",
SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session), file_no);
receivefax_component->http_put_after_receive = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s save fax to HTTP URL\n", RAYO_JID(receivefax_component));
} else {
/* assume file.. */
receivefax_component->local_filename = receivefax_component->filename;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s save fax to local file\n", RAYO_JID(receivefax_component));
}
/* add channel variable so that fax component can be located from fax events */
switch_channel_set_variable(channel, "rayo_fax_jid", RAYO_JID(receivefax_component));
/* clear fax result variables */
switch_channel_set_variable(channel, "fax_success", NULL);
switch_channel_set_variable(channel, "fax_result_code", NULL);
switch_channel_set_variable(channel, "fax_result_text", NULL);
switch_channel_set_variable(channel, "fax_document_transferred_pages", NULL);
switch_channel_set_variable(channel, "fax_document_total_pages", NULL);
switch_channel_set_variable(channel, "fax_image_resolution", NULL);
switch_channel_set_variable(channel, "fax_image_size", NULL);
switch_channel_set_variable(channel, "fax_bad_rows", NULL);
switch_channel_set_variable(channel, "fax_transfer_rate", NULL);
switch_channel_set_variable(channel, "fax_ecm_used", NULL);
switch_channel_set_variable(channel, "fax_local_station_id", NULL);
switch_channel_set_variable(channel, "fax_remote_station_id", NULL);
rayo_call_set_faxing(RAYO_CALL(call), 1);
/* execute rxfax APP */
if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", "rxfax");
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", receivefax_component->local_filename);
if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) {
switch_channel_set_flag(channel, CF_BLOCK_BROADCAST_UNTIL_MEDIA);
}
if (switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) {
response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to rxfax (queue event failed)");
if (execute_event) {
switch_event_destroy(&execute_event);
}
rayo_call_set_faxing(RAYO_CALL(call), 0);
RAYO_RELEASE(receivefax_component);
} else {
/* component starting... */
rayo_component_send_start(RAYO_COMPONENT(receivefax_component), iq);
}
} else {
response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to create rxfax event");
rayo_call_set_faxing(RAYO_CALL(call), 0);
RAYO_RELEASE(receivefax_component);
}
return response;
}
/**
* Stop execution of fax component
*/
static iks *stop_fax_component(struct rayo_actor *component, struct rayo_message *msg, void *data)
{
iks *iq = msg->payload;
switch_core_session_t *session = switch_core_session_locate(component->parent->id);
FAX_COMPONENT(component)->stop = 1;
if (session) {
switch_core_session_execute_application_async(session, "stopfax", "");
switch_core_session_rwunlock(session);
}
return iks_new_iq_result(iq);
}
/**
* Add fax metadata to result
* @param event source of metadata
* @param name of metadata
* @param result to add metadata to
*/
static void insert_fax_metadata(switch_event_t *event, const char *name, iks *result)
{
char actual_name[256];
const char *value;
snprintf(actual_name, sizeof(actual_name), "variable_%s", name);
actual_name[sizeof(actual_name) - 1] = '\0';
value = switch_event_get_header(event, actual_name);
if (!zstr(value)) {
iks *metadata = iks_insert(result, "metadata");
iks_insert_attrib(metadata, "xmlns", RAYO_FAX_COMPLETE_NS);
iks_insert_attrib(metadata, "name", name);
iks_insert_attrib(metadata, "value", value);
}
}
/**
* Handle fax completion event from FreeSWITCH core
* @param event received from FreeSWITCH core. It will be destroyed by the core after this function returns.
*/
static void on_execute_complete_event(switch_event_t *event)
{
const char *application = switch_event_get_header(event, "Application");
if (!zstr(application) && (!strcmp(application, "rxfax") || !strcmp(application, "txfax"))) {
int is_rxfax = !strcmp(application, "rxfax");
const char *uuid = switch_event_get_header(event, "Unique-ID");
const char *fax_jid = switch_event_get_header(event, "variable_rayo_fax_jid");
struct rayo_actor *component;
if (!zstr(fax_jid) && (component = RAYO_LOCATE(fax_jid))) {
iks *result;
iks *complete;
iks *fax;
int have_fax_document = 1;
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Got result for %s\n", fax_jid);
/* RX only: transfer HTTP document and delete local copy */
if (is_rxfax && RECEIVEFAX_COMPONENT(component)->http_put_after_receive && switch_file_exists(RECEIVEFAX_COMPONENT(component)->local_filename, RAYO_POOL(component)) == SWITCH_STATUS_SUCCESS) {
char *cmd = switch_core_sprintf(RAYO_POOL(component), "%s %s", RECEIVEFAX_COMPONENT(component)->filename, RECEIVEFAX_COMPONENT(component)->local_filename);
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s PUT fax to %s\n", RAYO_JID(component), RECEIVEFAX_COMPONENT(component)->filename);
switch_api_execute("http_put", cmd, NULL, &stream);
/* check if successful */
if (!zstr(stream.data) && strncmp(stream.data, "+OK", 3)) {
/* PUT failed */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s PUT fax %s to %s failed: %s\n", RAYO_JID(component), RECEIVEFAX_COMPONENT(component)->local_filename, RECEIVEFAX_COMPONENT(component)->filename, (char *)stream.data);
have_fax_document = 0;
}
switch_safe_free(stream.data)
switch_file_remove(RECEIVEFAX_COMPONENT(component)->local_filename, RAYO_POOL(component));
}
/* successful fax? */
if (have_fax_document && switch_true(switch_event_get_header(event, "variable_fax_success"))) {
result = rayo_component_create_complete_event(RAYO_COMPONENT(component), FAX_FINISH);
} else if (have_fax_document && FAX_COMPONENT(component)->stop) {
result = rayo_component_create_complete_event(RAYO_COMPONENT(component), COMPONENT_COMPLETE_STOP);
} else {
result = rayo_component_create_complete_event(RAYO_COMPONENT(component), COMPONENT_COMPLETE_ERROR);
}
complete = iks_find(result, "complete");
/* RX only: add fax document information */
if (is_rxfax && have_fax_document) {
const char *pages = switch_event_get_header(event, "variable_fax_document_transferred_pages");
if (!zstr(pages) && switch_is_number(pages) && atoi(pages) > 0) {
const char *resolution = switch_event_get_header(event, "variable_fax_file_image_resolution");
const char *size = switch_event_get_header(event, "variable_fax_image_size");
fax = iks_insert(complete, "fax");
iks_insert_attrib(fax, "xmlns", RAYO_FAX_COMPLETE_NS);
if (RECEIVEFAX_COMPONENT(component)->http_put_after_receive) {
iks_insert_attrib(fax, "url", RECEIVEFAX_COMPONENT(component)->filename);
} else {
/* convert absolute path to file:// URI */
iks_insert_attrib_printf(fax, "url", "file://%s", RECEIVEFAX_COMPONENT(component)->filename);
}
if (!zstr(resolution)) {
iks_insert_attrib(fax, "resolution", resolution);
}
if (!zstr(size)) {
iks_insert_attrib(fax, "size", size);
}
iks_insert_attrib(fax, "pages", pages);
}
}
/* add metadata from event */
insert_fax_metadata(event, "fax_success", complete);
insert_fax_metadata(event, "fax_result_code", complete);
insert_fax_metadata(event, "fax_result_text", complete);
insert_fax_metadata(event, "fax_document_transferred_pages", complete);
insert_fax_metadata(event, "fax_document_total_pages", complete);
insert_fax_metadata(event, "fax_image_resolution", complete);
insert_fax_metadata(event, "fax_image_size", complete);
insert_fax_metadata(event, "fax_bad_rows", complete);
insert_fax_metadata(event, "fax_transfer_rate", complete);
insert_fax_metadata(event, "fax_ecm_used", complete);
insert_fax_metadata(event, "fax_local_station_id", complete);
insert_fax_metadata(event, "fax_remote_station_id", complete);
/* flag faxing as done */
rayo_call_set_faxing(RAYO_CALL(component->parent), 0);
rayo_component_send_complete_event(RAYO_COMPONENT(component), result);
RAYO_RELEASE(component);
}
}
}
/**
* Process module XML configuration
* @param pool memory pool to allocate from
* @param config_file to use
* @return SWITCH_STATUS_SUCCESS on successful configuration
*/
static switch_status_t do_config(switch_memory_pool_t *pool, const char *config_file)
{
switch_xml_t cfg, xml;
/* set defaults */
globals.file_prefix = switch_core_sprintf(pool, "%s%s", SWITCH_GLOBAL_dirs.recordings_dir, SWITCH_PATH_SEPARATOR);
if (!(xml = switch_xml_open_cfg(config_file, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", config_file);
return SWITCH_STATUS_TERM;
}
/* get params */
{
switch_xml_t settings = switch_xml_child(cfg, "fax");
if (settings) {
switch_xml_t param;
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "param: %s = %s\n", var, val);
if (!strcasecmp(var, "receivefax-file-prefix")) {
if (!zstr(val)) {
globals.file_prefix = switch_core_strdup(pool, val);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unsupported param: %s\n", var);
}
}
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "receivefax-file-prefix = %s\n", globals.file_prefix);
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
}
/**
* Initialize fax components
* @param module_interface
* @param pool memory pool to allocate from
* @param config_file to use
* @return SWITCH_STATUS_SUCCESS if successful
*/
switch_status_t rayo_fax_components_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool, const char *config_file)
{
if (do_config(pool, config_file) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
switch_event_bind("rayo_fax_components", SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE, NULL, on_execute_complete_event, NULL);
rayo_actor_command_handler_add(RAT_CALL, "", "set:"RAYO_FAX_NS":receivefax", start_receivefax_component);
rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "receivefax", "set:"RAYO_EXT_NS":stop", stop_fax_component);
rayo_actor_command_handler_add(RAT_CALL, "", "set:"RAYO_FAX_NS":sendfax", start_sendfax_component);
rayo_actor_command_handler_add(RAT_CALL_COMPONENT, "sendfax", "set:"RAYO_EXT_NS":stop", stop_fax_component);
return SWITCH_STATUS_SUCCESS;
}
/**
* Shutdown fax components
* @return SWITCH_STATUS_SUCCESS if successful
*/
switch_status_t rayo_fax_components_shutdown(void)
{
switch_event_unbind_callback(on_execute_complete_event);
return SWITCH_STATUS_SUCCESS;
}
/* 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
*/