FreeSWITCH API Documentation  1.7.0
switch_cpp.cpp
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  *
28  *
29  * switch_cpp.cpp -- C++ wrapper
30  *
31  */
32 
33 #include <switch.h>
34 #include <switch_cpp.h>
35 
36 #ifdef _MSC_VER
37 #pragma warning(disable:4127 4003)
38 #endif
39 
40 static void event_handler(switch_event_t *event)
41 {
43  switch_event_t *dup;
44 
45  switch_event_dup(&dup, event);
46 
48  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot queue any more events.....\n");
50  }
51 
52 }
53 
54 SWITCH_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(const char *event_name, const char *subclass_name, int len)
55 {
56 
59  node_index = 0;
60  ready = 1;
61 
62  if (!zstr(event_name)) {
63  bind(event_name, subclass_name);
64  }
65 }
66 
67 SWITCH_DECLARE(int) EventConsumer::bind(const char *event_name, const char *subclass_name)
68 {
70 
71  if (!ready) {
72  return 0;
73  }
74 
75  if (switch_name_event(event_name, &event_id) != SWITCH_STATUS_SUCCESS) {
76  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't bind to %s, event not found\n", event_name);
77  return 0;
78  }
79 
80  if (zstr(subclass_name)) {
81  subclass_name = NULL;
82  }
83 
84  if (node_index <= SWITCH_EVENT_ALL &&
85  switch_event_bind_removable(__FILE__, event_id, subclass_name, event_handler, this, &enodes[node_index]) == SWITCH_STATUS_SUCCESS) {
86  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "bound to %s %s\n", event_name, switch_str_nil(subclass_name));
87  node_index++;
88  return 1;
89  }
90 
91  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot bind to %s %s\n", event_name, switch_str_nil(subclass_name));
92  return 0;
93 }
94 
95 
96 SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout)
97 {
98  void *pop = NULL;
99  Event *ret = NULL;
100  switch_event_t *event;
101 
102  if (!ready) {
103  return NULL;
104  }
105 
106  if (block) {
107  if (timeout > 0) {
108  switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec
109  } else {
110  switch_queue_pop(events, &pop);
111  }
112  } else {
113  switch_queue_trypop(events, &pop);
114  }
115 
116  if ((event = (switch_event_t *) pop)) {
117  ret = new Event(event, 1);
118  }
119 
120  return ret;
121 }
122 
124 {
125 
126  uint32_t i;
127  void *pop;
128 
129  if (!ready) {
130  return;
131  }
132 
133  ready = 0;
134 
135  for (i = 0; i < node_index; i++) {
136  switch_event_unbind(&enodes[i]);
137  }
138 
139  node_index = 0;
140 
141  if (events) {
143  }
144 
145  while(switch_queue_trypop(events, &pop) == SWITCH_STATUS_SUCCESS) {
146  switch_event_t *event = (switch_event_t *) pop;
147  switch_event_destroy(&event);
148  }
149 
150 
152 
153 }
154 
155 
157 {
158  cleanup();
159 }
160 
162  const char *name,
163  const char *greeting_sound,
164  const char *short_greeting_sound,
165  const char *invalid_sound,
166  const char *exit_sound,
167  const char *transfer_sound,
168  const char *confirm_macro,
169  const char *confirm_key,
170  const char *tts_engine,
171  const char *tts_voice,
172  int confirm_attempts,
173  int inter_timeout,
174  int digit_len,
175  int timeout,
176  int max_failures,
177  int max_timeouts)
178 {
179  menu = NULL;
182  if (zstr(name)) {
183  name = "no name";
184  }
185 
186  switch_ivr_menu_init(&menu, main ? main->menu : NULL, name, greeting_sound, short_greeting_sound, invalid_sound,
187  exit_sound, transfer_sound, confirm_macro, confirm_key, tts_engine, tts_voice, confirm_attempts, inter_timeout,
188  digit_len, timeout, max_failures, max_timeouts, pool);
189 
190 
191 }
192 
194 {
195  if (menu) {
197  }
199 }
200 
201 SWITCH_DECLARE(void) IVRMenu::bindAction(char *action, const char *arg, const char *bind)
202 {
204 
205  this_check_void();
206 
207  if (switch_ivr_menu_str2action(action, &ivr_action) == SWITCH_STATUS_SUCCESS) {
208  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "bind %s to %s(%s)\n", bind, action, arg);
209  switch_ivr_menu_bind_action(menu, ivr_action, arg, bind);
210  } else {
211  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid action %s\n", action);
212  }
213 }
214 
215 SWITCH_DECLARE(void) IVRMenu::execute(CoreSession *session, const char *name)
216 {
217  this_check_void();
218  switch_ivr_menu_execute(session->session, menu, (char *)name, NULL);
219 }
220 
222 {
223  if (s) {
224  session = s->session;
225  } else {
226  session = NULL;
227  }
228 }
229 
231 {
232  return;
233 }
234 
235 
236 SWITCH_DECLARE(const char *) API::execute(const char *cmd, const char *arg)
237 {
238  switch_stream_handle_t stream = { 0 };
239  this_check("");
240 
241  SWITCH_STANDARD_STREAM(stream);
242 
243  if (zstr(cmd)) {
244  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No application specified\n");
245  stream.write_function(&stream, "-ERR No application specified");
246  } else {
247  switch_api_execute(cmd, arg, session, &stream);
248  }
249 
250  return (char *) stream.data;
251 }
252 
253 
254 /* we have to do this as a string because swig and languages can't find an embedded way to pass a big int */
255 SWITCH_DECLARE(char *) API::getTime(void)
256 {
257  switch_time_t now = switch_micro_time_now() / 1000;
258  snprintf(time_buf, sizeof(time_buf), "%" SWITCH_TIME_T_FMT, now);
259  return time_buf;
260 }
261 
262 
263 
264 SWITCH_DECLARE(const char *) API::executeString(const char *cmd)
265 {
266  char *arg;
267  switch_stream_handle_t stream = { 0 };
268  char *mycmd = NULL;
269 
270  this_check("");
271 
272  SWITCH_STANDARD_STREAM(stream);
273 
274  if (zstr(cmd)) {
275  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No application specified\n");
276  stream.write_function(&stream, "-ERR No application specified");
277  } else {
278  mycmd = strdup(cmd);
279 
280  switch_assert(mycmd);
281 
282  if ((arg = strchr(mycmd, ' '))) {
283  *arg++ = '\0';
284  }
285 
286  switch_api_execute(mycmd, arg, session, &stream);
287  switch_safe_free(mycmd);
288  }
289 
290  return (char *) stream.data;
291 }
292 
293 SWITCH_DECLARE_CONSTRUCTOR Event::Event(const char *type, const char *subclass_name)
294 {
295  switch_event_types_t event_id;
296 
297  if (!strcasecmp(type, "json") && !zstr(subclass_name)) {
298  if (switch_event_create_json(&event, subclass_name) != SWITCH_STATUS_SUCCESS) {
299  return;
300  }
301 
302  event_id = event->event_id;
303 
304  } else {
305  if (switch_name_event(type, &event_id) != SWITCH_STATUS_SUCCESS) {
306  event_id = SWITCH_EVENT_MESSAGE;
307  }
308 
309  if (!zstr(subclass_name) && event_id != SWITCH_EVENT_CUSTOM) {
310  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_WARNING, "Changing event type to custom because you specified a subclass name!\n");
311  event_id = SWITCH_EVENT_CUSTOM;
312  }
313 
314  if (switch_event_create_subclass(&event, event_id, subclass_name) != SWITCH_STATUS_SUCCESS) {
315  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to create event!\n");
316  event = NULL;
317  }
318  }
319 
320  serialized_string = NULL;
321  mine = 1;
322 }
323 
325 {
326  event = wrap_me;
327  mine = free_me;
328  serialized_string = NULL;
329 }
330 
332 {
333 
334  if (serialized_string) {
335  free(serialized_string);
336  }
337 
338  if (event && mine) {
340  }
341 }
342 
343 SWITCH_DECLARE(int)Event::chat_execute(const char *app, const char *data)
344 {
345  return (int) switch_core_execute_chat_app(event, app, data);
346 }
347 
348 SWITCH_DECLARE(int)Event::chat_send(const char *dest_proto)
349 {
350  if (zstr(dest_proto)) {
351  dest_proto = switch_event_get_header(event, "dest_proto");
352  }
353 
354  return (int) switch_core_chat_send(dest_proto, event);
355 }
356 
357 SWITCH_DECLARE(const char *)Event::serialize(const char *format)
358 {
359  this_check("");
360 
361 
362  switch_safe_free(serialized_string);
363 
364  if (!event) {
365  return "";
366  }
367 
368  if (format && !strcasecmp(format, "xml")) {
369  switch_xml_t xml;
370  if ((xml = switch_event_xmlize(event, SWITCH_VA_NONE))) {
371  serialized_string = switch_xml_toxml(xml, SWITCH_FALSE);
372  switch_xml_free(xml);
373  return serialized_string;
374  } else {
375  return "";
376  }
377  } else if (format && !strcasecmp(format, "json")) {
378  switch_event_serialize_json(event, &serialized_string);
379  return serialized_string;
380  } else {
381  if (switch_event_serialize(event, &serialized_string, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
382  char *new_serialized_string = switch_mprintf("'%s'", serialized_string);
383  free(serialized_string);
384  serialized_string = new_serialized_string;
385  return serialized_string;
386  }
387  }
388 
389  return "";
390 
391 }
392 
393 SWITCH_DECLARE(bool) Event::fire(void)
394 {
395 
396  this_check(false);
397 
398  if (!mine) {
400  return false;
401  }
402 
403  if (event) {
404  switch_event_t *new_event;
405  if (switch_event_dup(&new_event, event) == SWITCH_STATUS_SUCCESS) {
406  if (switch_event_fire(&new_event) != SWITCH_STATUS_SUCCESS) {
407  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to fire the event!\n");
408  switch_event_destroy(&new_event);
409  return false;
410  }
411  return true;
412  } else {
413  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Failed to dup the event!\n");
414  }
415  } else {
416  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to fire an event that does not exist!\n");
417  }
418  return false;
419 }
420 
421 SWITCH_DECLARE(bool) Event::setPriority(switch_priority_t priority)
422 {
423  this_check(false);
424 
425  if (event) {
426  switch_event_set_priority(event, priority);
427  return true;
428  } else {
429  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to setPriority an event that does not exist!\n");
430  }
431  return false;
432 }
433 
434 SWITCH_DECLARE(const char *)Event::getHeader(const char *header_name)
435 {
436  this_check("");
437 
438  if (zstr(header_name)) {
439  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Trying to getHeader an invalid header!\n");
440  return NULL;
441  }
442 
443  if (event) {
444  return switch_event_get_header(event, header_name);
445  } else {
446  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getHeader an event that does not exist!\n");
447  }
448  return NULL;
449 }
450 
451 SWITCH_DECLARE(bool) Event::addHeader(const char *header_name, const char *value)
452 {
453  this_check(false);
454 
455  if (event) {
456  return switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, value) == SWITCH_STATUS_SUCCESS ? true : false;
457  } else {
458  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to addHeader an event that does not exist!\n");
459  }
460 
461  return false;
462 }
463 
464 SWITCH_DECLARE(bool) Event::delHeader(const char *header_name)
465 {
466  this_check(false);
467 
468  if (zstr(header_name)) {
469  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Trying to delHeader an invalid header!\n");
470  return false;
471  }
472 
473  if (event) {
474  return switch_event_del_header(event, header_name) == SWITCH_STATUS_SUCCESS ? true : false;
475  } else {
476  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to delHeader an event that does not exist!\n");
477  }
478 
479  return false;
480 }
481 
482 
483 SWITCH_DECLARE(bool) Event::addBody(const char *value)
484 {
485  this_check(false);
486 
487  if (event) {
488  return switch_event_add_body(event, "%s", value) == SWITCH_STATUS_SUCCESS ? true : false;
489  } else {
490  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to addBody an event that does not exist!\n");
491  }
492 
493  return false;
494 }
495 
496 SWITCH_DECLARE(char *)Event::getBody(void)
497 {
498 
499  this_check((char *)"");
500 
501  if (event) {
502  return switch_event_get_body(event);
503  } else {
504  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getBody an event that does not exist!\n");
505  }
506 
507  return NULL;
508 }
509 
510 SWITCH_DECLARE(const char *)Event::getType(void)
511 {
512  this_check("");
513 
514  if (event) {
515  return switch_event_name(event->event_id);
516  } else {
517  switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "Trying to getType an event that does not exist!\n");
518  }
519 
520  return (char *) "invalid";
521 }
522 
523 
524 SWITCH_DECLARE_CONSTRUCTOR DTMF::DTMF(char idigit, uint32_t iduration)
525 {
526  digit = idigit;
527 
528  if (iduration == 0) {
529  iduration = SWITCH_DEFAULT_DTMF_DURATION;
530  }
531 
532  duration = iduration;
533 }
534 
536 {
537 
538 }
539 
540 
542 {
544  stream_p = &mystream;
545  mine = 1;
546 }
547 
549 {
550  stream_p = sp;
551  mine = 0;
552 }
553 
554 
556 {
557  if (mine) {
559  }
560 }
561 
562 /* WARNING!! you are not encouraged to use this unless you understand the risk!!! */
563 SWITCH_DECLARE(const char *) Stream::read(int *len)
564 {
565  uint8_t *buff;
566 
567  this_check(NULL);
568 
569  if (!stream_p->read_function) return NULL;
570 
571  buff = stream_p->read_function(stream_p, len);
572 
573  if (!buff || *len <= 0) {
574  *len = 0;
575  return NULL;
576  }
577 
578  return (const char *)buff;
579 }
580 
581 SWITCH_DECLARE(void) Stream::write(const char *data)
582 {
583  this_check_void();
584  stream_p->write_function(stream_p, "%s", data);
585 }
586 
587 SWITCH_DECLARE(void) Stream::raw_write(const char *data, int len)
588 {
589  this_check_void();
590  stream_p->raw_write_function(stream_p, (uint8_t *)data, len);
591 }
592 
593 SWITCH_DECLARE(const char *)Stream::get_data()
594 {
595  this_check("");
596 
597  return stream_p ? (const char *)stream_p->data : NULL;
598 }
599 
600 
602 {
603  init_vars();
604 }
605 
607 {
608  switch_channel_t *other_channel = NULL;
609 
610  init_vars();
611 
612  if (a_leg && a_leg->session) {
613  other_channel = switch_core_session_get_channel(a_leg->session);
614  }
615 
616  if (!strchr(nuuid, '/') && (session = switch_core_session_force_locate(nuuid))) {
617  uuid = strdup(nuuid);
619  allocated = 1;
620  } else {
622  if (switch_ivr_originate(a_leg ? a_leg->session : NULL, &session, &cause, nuuid, 60, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL)
625  allocated = 1;
626  switch_set_flag(this, S_HUP);
630  }
631  }
632 }
633 
635 {
636  init_vars();
637 
638  if (new_session) {
639  session = new_session;
641  allocated = 1;
644  }
645 }
646 
648 {
649  this_check_void();
650  if (allocated) destroy();
651 }
652 
653 SWITCH_DECLARE(char *) CoreSession::getXMLCDR()
654 {
655 
656  switch_xml_t cdr = NULL;
657 
658  this_check((char *)"");
659  sanity_check((char *)"");
660 
661  switch_safe_free(xml_cdr_text);
662 
663  if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
664  xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE);
665  switch_xml_free(cdr);
666  }
667 
668  return (char *) (xml_cdr_text ? xml_cdr_text : "");
669 }
670 
671 SWITCH_DECLARE(void) CoreSession::setEventData(Event *e)
672 {
673  this_check_void();
675 
676  if (channel && e->event) {
677  switch_channel_event_set_data(channel, e->event);
678  }
679 }
680 
682 {
683  switch_status_t status;
684  this_check(-1);
685  sanity_check(-1);
686  status = switch_channel_answer(channel);
687  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
688 }
689 
690 SWITCH_DECLARE(int) CoreSession::insertFile(const char *file, const char *insert_file, int sample_point)
691 {
692  switch_status_t status;
693  this_check(-1);
694  sanity_check(-1);
695  status = switch_ivr_insert_file(session, file, insert_file, (switch_size_t)sample_point);
696  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
697 }
698 
699 SWITCH_DECLARE(int) CoreSession::preAnswer()
700 {
701  switch_status_t status;
702  this_check(-1);
703  sanity_check(-1);
704  status = switch_channel_pre_answer(channel);
705  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
706 }
707 
708 SWITCH_DECLARE(void) CoreSession::hangupState(void)
709 {
711  this->begin_allow_threads();
712  if (switch_channel_down(channel)) {
714  }
715  this->end_allow_threads();
716 }
717 
718 SWITCH_DECLARE(void) CoreSession::hangup(const char *cause)
719 {
720  this_check_void();
722  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "CoreSession::hangup\n");
723  this->begin_allow_threads();
725  this->end_allow_threads();
726 }
727 
728 SWITCH_DECLARE(void) CoreSession::setPrivate(char *var, void *val)
729 {
730  this_check_void();
732  switch_channel_set_private(channel, var, val);
733 }
734 
735 SWITCH_DECLARE(void *)CoreSession::getPrivate(char *var)
736 {
737  this_check(NULL);
738  sanity_check(NULL);
739  return switch_channel_get_private(channel, var);
740 }
741 
742 SWITCH_DECLARE(void) CoreSession::setVariable(char *var, char *val)
743 {
744  this_check_void();
746  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "CoreSession::setVariable('%s', '%s')\n", var, val);
748 }
749 
750 SWITCH_DECLARE(const char *)CoreSession::getVariable(char *var)
751 {
752  this_check("");
753  sanity_check("");
754  return switch_channel_get_variable(channel, var);
755 }
756 
757 SWITCH_DECLARE(void) CoreSession::execute(const char *app, const char *data)
758 {
759  this_check_void();
761 
762  if (zstr(app)) {
763  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No application specified\n");
764  return;
765  }
766 
767  begin_allow_threads();
768  switch_core_session_execute_application(session, app, data);
769  end_allow_threads();
770 }
771 
772 SWITCH_DECLARE(void) CoreSession::setDTMFCallback(void *cbfunc, char *funcargs) {
773 
774  this_check_void();
776 
777  cb_state.funcargs = funcargs;
778  cb_state.function = cbfunc;
779 
780  args.buf = &cb_state;
781  args.buflen = sizeof(cb_state); // not sure what this is used for, copy mod_spidermonkey
782 
783  switch_channel_set_private(channel, "CoreSession", this);
784 
785  // we cannot set the actual callback to a python function, because
786  // the callback is a function pointer with a specific signature.
787  // so, set it to the following c function which will act as a proxy,
788  // finding the python callback in the args callback args structure
789  args.input_callback = dtmf_callback;
790  ap = &args;
791 
792 
793 }
794 
795 SWITCH_DECLARE(void) CoreSession::sendEvent(Event *sendME)
796 {
797  this_check_void();
799 
800  if (sendME->event) {
801  switch_event_t *new_event;
802  if (switch_event_dup(&new_event, sendME->event) == SWITCH_STATUS_SUCCESS) {
803  switch_core_session_receive_event(session, &new_event);
804  }
805  }
806 }
807 
808 SWITCH_DECLARE(int) CoreSession::speak(char *text)
809 {
810  switch_status_t status;
811 
812  this_check(-1);
813  sanity_check(-1);
814 
815  if (!tts_name) {
816  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No TTS engine specified\n");
817  return SWITCH_STATUS_FALSE;
818  }
819 
820  if (!voice_name) {
821  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No TTS voice specified\n");
822  return SWITCH_STATUS_FALSE;
823  }
824 
825 
826  begin_allow_threads();
827  status = switch_ivr_speak_text(session, tts_name, voice_name, text, ap);
828  end_allow_threads();
829  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
830 }
831 
832 SWITCH_DECLARE(void) CoreSession::set_tts_parms(char *tts_name_p, char *voice_name_p)
833 {
834  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "set_tts_parms is deprecated. Use set_tts_params.\n");
835  this_check_void();
837  switch_safe_free(tts_name);
838  switch_safe_free(voice_name);
839  tts_name = strdup(tts_name_p);
840  voice_name = strdup(voice_name_p);
841 }
842 
843 SWITCH_DECLARE(void) CoreSession::set_tts_params(char *tts_name_p, char *voice_name_p)
844 {
845  this_check_void();
847  switch_safe_free(tts_name);
848  switch_safe_free(voice_name);
849  tts_name = strdup(tts_name_p);
850  voice_name = strdup(voice_name_p);
851 }
852 
853 SWITCH_DECLARE(int) CoreSession::collectDigits(int abs_timeout) {
854  return collectDigits(0, abs_timeout);
855 }
856 
857 SWITCH_DECLARE(int) CoreSession::collectDigits(int digit_timeout, int abs_timeout) {
858  this_check(-1);
859  sanity_check(-1);
860  begin_allow_threads();
861  switch_ivr_collect_digits_callback(session, ap, digit_timeout, abs_timeout);
862  end_allow_threads();
863  return SWITCH_STATUS_SUCCESS;
864 }
865 
866 SWITCH_DECLARE(char *) CoreSession::getDigits(int maxdigits, char *terminators, int timeout)
867 {
868  return getDigits(maxdigits, terminators, timeout, 0);
869 }
870 
871 SWITCH_DECLARE(char *) CoreSession::getDigits(int maxdigits,
872  char *terminators,
873  int timeout,
874  int interdigit)
875 {
876  this_check((char *)"");
877  sanity_check((char *)"");
878  begin_allow_threads();
879  char terminator;
880 
881  memset(dtmf_buf, 0, sizeof(dtmf_buf));
883  dtmf_buf,
884  sizeof(dtmf_buf),
885  maxdigits,
886  terminators,
887  &terminator,
888  (uint32_t) timeout, (uint32_t)interdigit, 0);
889 
890  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "getDigits dtmf_buf: %s\n", dtmf_buf);
891  end_allow_threads();
892  return dtmf_buf;
893 }
894 
895 SWITCH_DECLARE(int) CoreSession::transfer(char *extension, char *dialplan, char *context)
896 {
897  switch_status_t status;
898  this_check(-1);
899  sanity_check(-1);
900  begin_allow_threads();
901  status = switch_ivr_session_transfer(session, extension, dialplan, context);
902  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "transfer result: %d\n", status);
903  end_allow_threads();
904  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
905 }
906 
907 
908 SWITCH_DECLARE(char *) CoreSession::read(int min_digits,
909  int max_digits,
910  const char *prompt_audio_file,
911  int timeout,
912  const char *valid_terminators,
913  int digit_timeout)
914 {
915  this_check((char *)"");
916  sanity_check((char *)"");
917  if (min_digits < 1) {
918  min_digits = 1;
919  }
920 
921  if (max_digits < 1) {
922  max_digits = 1;
923  }
924 
925  if (timeout < 1) {
926  timeout = 1;
927  }
928 
929  begin_allow_threads();
930  switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, NULL, dtmf_buf,
931  sizeof(dtmf_buf), timeout, valid_terminators, (uint32_t)digit_timeout);
932  end_allow_threads();
933 
934  return dtmf_buf;
935 }
936 
937 SWITCH_DECLARE(char *) CoreSession::playAndGetDigits(int min_digits,
938  int max_digits,
939  int max_tries,
940  int timeout,
941  char *terminators,
942  char *audio_files,
943  char *bad_input_audio_files,
944  char *digits_regex,
945  const char *var_name,
946  int digit_timeout,
947  const char *transfer_on_failure)
948 {
949  sanity_check((char *)"");
950  this_check((char *)"");
951  begin_allow_threads();
952  memset(dtmf_buf, 0, sizeof(dtmf_buf));
953  switch_play_and_get_digits( session,
954  (uint32_t) min_digits,
955  (uint32_t) max_digits,
956  (uint32_t) max_tries,
957  (uint32_t) timeout,
958  terminators,
959  audio_files,
960  bad_input_audio_files,
961  var_name,
962  dtmf_buf,
963  sizeof(dtmf_buf),
964  digits_regex,
965  (uint32_t) digit_timeout,
966  transfer_on_failure);
967 
968  end_allow_threads();
969  return dtmf_buf;
970 }
971 
972 SWITCH_DECLARE(void) CoreSession::say(const char *tosay, const char *module_name, const char *say_type, const char *say_method, const char *say_gender)
973 {
974  this_check_void();
976  if (!(tosay && module_name && say_type && say_method)) {
977  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error! invalid args.\n");
978  return;
979  }
980  begin_allow_threads();
981  switch_ivr_say(session, tosay, module_name, say_type, say_method, say_gender, ap);
982  end_allow_threads();
983 }
984 
985 SWITCH_DECLARE(void) CoreSession::sayPhrase(const char *phrase_name, const char *phrase_data, const char *phrase_lang)
986 {
987  this_check_void();
989 
990  if (!(phrase_name)) {
991  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error! invalid args.\n");
992  return;
993  }
994 
995  begin_allow_threads();
996  switch_ivr_phrase_macro(session, phrase_name, phrase_data, phrase_lang, ap);
997  end_allow_threads();
998 }
999 
1000 SWITCH_DECLARE(int) CoreSession::streamFile(char *file, int starting_sample_count) {
1001 
1002  switch_status_t status;
1003  //switch_file_handle_t fh = { 0 };
1004  const char *prebuf;
1005  switch_file_handle_t local_fh;
1006 
1007  this_check(-1);
1008  sanity_check(-1);
1009 
1010  memset(&local_fh, 0, sizeof(local_fh));
1011  fhp = &local_fh;
1012  local_fh.samples = starting_sample_count;
1013 
1014 
1015  if ((prebuf = switch_channel_get_variable(this->channel, "stream_prebuffer"))) {
1016  int maybe = atoi(prebuf);
1017  if (maybe > 0) {
1018  local_fh.prebuf = maybe;
1019  }
1020  }
1021 
1022  begin_allow_threads();
1023  status = switch_ivr_play_file(session, fhp, file, ap);
1024  end_allow_threads();
1025 
1026  fhp = NULL;
1027 
1028  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
1029 
1030 }
1031 
1032 SWITCH_DECLARE(int) CoreSession::sleep(int ms, int sync) {
1033 
1034  switch_status_t status;
1035 
1036  this_check(-1);
1037  sanity_check(-1);
1038 
1039  begin_allow_threads();
1040  status = switch_ivr_sleep(session, ms, (switch_bool_t) sync, ap);
1041  end_allow_threads();
1042 
1043  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
1044 
1045 }
1046 
1047 SWITCH_DECLARE(bool) CoreSession::ready() {
1048 
1049  this_check(false);
1050 
1051  if (!session) {
1052  return false;
1053  }
1054  sanity_check(false);
1055 
1056  return switch_channel_ready(channel) != 0;
1057 }
1058 
1059 
1060 SWITCH_DECLARE(bool) CoreSession::bridged() {
1061 
1062  this_check(false);
1063 
1064  if (!session) {
1065  return false;
1066  }
1067  sanity_check(false);
1068 
1069  return (switch_channel_up(channel) && switch_channel_test_flag(channel, CF_BRIDGED));
1070 }
1071 
1072 SWITCH_DECLARE(bool) CoreSession::mediaReady() {
1073 
1074  this_check(false);
1075  sanity_check(false);
1076  return switch_channel_media_ready(channel) != 0;
1077 }
1078 
1079 SWITCH_DECLARE(bool) CoreSession::answered() {
1080 
1081  this_check(false);
1082  sanity_check(false);
1083  return switch_channel_test_flag(channel, CF_ANSWERED) != 0;
1084 }
1085 
1086 SWITCH_DECLARE(void) CoreSession::destroy(void)
1087 {
1088  this_check_void();
1089 
1090  if (!allocated) {
1091  return;
1092  }
1093 
1094  allocated = 0;
1095 
1096  switch_safe_free(xml_cdr_text);
1097  switch_safe_free(uuid);
1098  switch_safe_free(tts_name);
1099  switch_safe_free(voice_name);
1100 
1101  if (session) {
1102  if (!channel) {
1103  channel = switch_core_session_get_channel(session);
1104  }
1105 
1106  if (channel) {
1108  "%s destroy/unlink session from object\n", switch_channel_get_name(channel));
1109  switch_channel_set_private(channel, "CoreSession", NULL);
1110  if (switch_channel_up(channel) && switch_test_flag(this, S_HUP) && !switch_channel_test_flag(channel, CF_TRANSFER)) {
1112  }
1113  }
1114 
1116  session = NULL;
1117  channel = NULL;
1118  }
1119 
1120  init_vars();
1121 
1122 }
1123 
1124 SWITCH_DECLARE(const char *) CoreSession::hangupCause()
1125 {
1126  this_check(NULL);
1127  return switch_channel_cause2str(cause);
1128 }
1129 
1130 SWITCH_DECLARE(const char *) CoreSession::getState()
1131 {
1132  this_check(NULL);
1133 
1134  if (channel) {
1136  }
1137 
1138  return "ERROR";
1139 
1140 }
1141 
1142 SWITCH_DECLARE(int) CoreSession::originate(CoreSession *a_leg_session, char *dest, int timeout, switch_state_handler_table_t *handlers)
1143 {
1144 
1145  switch_core_session_t *aleg_core_session = NULL;
1146 
1147  this_check(0);
1148 
1150 
1151  if (a_leg_session != NULL) {
1152  aleg_core_session = a_leg_session->session;
1153  }
1154 
1155  // this session has no valid switch_core_session_t at this point, and therefore
1156  // no valid channel. since the threadstate is stored in the channel, and there
1157  // is none, if we try to call begin_alllow_threads it will fail miserably.
1158  // use the 'a leg session' to do the thread swapping stuff.
1159  if (a_leg_session) a_leg_session->begin_allow_threads();
1160 
1161  if (switch_ivr_originate(aleg_core_session,
1162  &session,
1163  &cause,
1164  dest,
1165  timeout,
1166  handlers,
1167  NULL,
1168  NULL,
1169  NULL,
1170  NULL,
1171  SOF_NONE,
1172  NULL) != SWITCH_STATUS_SUCCESS) {
1173  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error Creating Outgoing Channel! [%s]\n", dest);
1174  goto failed;
1175 
1176  }
1177 
1178  if (a_leg_session) a_leg_session->end_allow_threads();
1179  channel = switch_core_session_get_channel(session);
1180  allocated = 1;
1181  switch_safe_free(uuid);
1182  uuid = strdup(switch_core_session_get_uuid(session));
1184 
1185  return SWITCH_STATUS_SUCCESS;
1186 
1187  failed:
1188  if (a_leg_session) a_leg_session->end_allow_threads();
1189  return SWITCH_STATUS_FALSE;
1190 }
1191 
1192 SWITCH_DECLARE(int) CoreSession::recordFile(char *file_name, int time_limit, int silence_threshold, int silence_hits)
1193 {
1194  switch_status_t status;
1195  switch_file_handle_t local_fh;
1196 
1197  this_check(-1);
1198  sanity_check(-1);
1199 
1200  memset(&local_fh, 0, sizeof(local_fh));
1201  fhp = &local_fh;
1202  local_fh.thresh = silence_threshold;
1203  local_fh.silence_hits = silence_hits;
1204 
1205  begin_allow_threads();
1206  status = switch_ivr_record_file(session, &local_fh, file_name, ap, time_limit);
1207  end_allow_threads();
1208 
1209  fhp = NULL;
1210 
1211  return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
1212 
1213 }
1214 
1215 SWITCH_DECLARE(int) CoreSession::flushEvents()
1216 {
1217  switch_event_t *event;
1218 
1219  this_check(-1);
1220  sanity_check(-1);
1221 
1222  if (!session) {
1223  return SWITCH_STATUS_FALSE;
1224  }
1225 
1227  switch_event_destroy(&event);
1228  }
1229  return SWITCH_STATUS_SUCCESS;
1230 }
1231 
1232 SWITCH_DECLARE(int) CoreSession::flushDigits()
1233 {
1234  this_check(-1);
1235  sanity_check(-1);
1237  return SWITCH_STATUS_SUCCESS;
1238 }
1239 
1240 SWITCH_DECLARE(int) CoreSession::setAutoHangup(bool val)
1241 {
1242  this_check(-1);
1243  sanity_check(-1);
1244 
1245  if (!session) {
1246  return SWITCH_STATUS_FALSE;
1247  }
1248  if (val) {
1249  switch_set_flag(this, S_HUP);
1250  } else {
1251  switch_clear_flag(this, S_HUP);
1252  }
1253  return SWITCH_STATUS_SUCCESS;
1254 }
1255 
1256 SWITCH_DECLARE(void) CoreSession::waitForAnswer(CoreSession *calling_session)
1257 {
1258  this_check_void();
1260 
1261  switch_ivr_wait_for_answer(calling_session ? calling_session->session : NULL, session);
1262 
1263 }
1264 
1265 SWITCH_DECLARE(void) CoreSession::setHangupHook(void *hangup_func) {
1266 
1267  this_check_void();
1269 
1270  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "CoreSession::seHangupHook, hangup_func: %p\n", hangup_func);
1271  on_hangup = hangup_func;
1273 
1274  hook_state = switch_channel_get_state(channel);
1275  switch_channel_set_private(channel, "CoreSession", this);
1276  switch_core_event_hook_add_state_change(session, hanguphook);
1277 }
1278 
1279 SWITCH_DECLARE(void) CoreSession::consoleLog(char *level_str, char *msg)
1280 {
1282  if (level_str) {
1283  level = switch_log_str2level(level_str);
1284  if (level == SWITCH_LOG_INVALID) {
1285  level = SWITCH_LOG_DEBUG;
1286  }
1287  }
1288  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), level, "%s", switch_str_nil(msg));
1289 }
1290 
1291 SWITCH_DECLARE(void) CoreSession::consoleLog2(char *level_str, char *file, char *func, int line, char *msg)
1292 {
1294  if (level_str) {
1295  level = switch_log_str2level(level_str);
1296  if (level == SWITCH_LOG_INVALID) {
1297  level = SWITCH_LOG_DEBUG;
1298  }
1299  }
1300  switch_log_printf(SWITCH_CHANNEL_ID_SESSION, file, func, line, (const char*)session,
1301  level, "%s", switch_str_nil(msg));
1302 }
1303 
1304 /* ---- methods not bound to CoreSession instance ---- */
1305 
1306 
1307 SWITCH_DECLARE(int) globalSetVariable(const char *var, const char *val, const char *val2)
1308 {
1309  if (zstr(val)) val = NULL;
1310  if (zstr(val2)) val2 = NULL;
1311 
1312  if (val2) {
1313  return switch_core_set_var_conditional(var, val, val2);
1314  } else {
1315  switch_core_set_variable(var, val);
1316  return SWITCH_STATUS_SUCCESS;
1317  }
1318 }
1319 
1320 SWITCH_DECLARE(void) setGlobalVariable(char *var_name, char *var_val)
1321 {
1322  switch_core_set_variable(var_name, var_val);
1323 }
1324 
1325 SWITCH_DECLARE(char *) getGlobalVariable(char *var_name)
1326 {
1327  return switch_core_get_variable_dup(var_name);
1328 }
1329 
1330 
1332 {
1333  return switch_core_running() ? true : false;
1334 }
1335 
1336 SWITCH_DECLARE(void) consoleLog(char *level_str, char *msg)
1337 {
1338  return console_log(level_str, msg);
1339 }
1340 
1341 SWITCH_DECLARE(void) consoleLog2(char *level_str, char *file, char *func, int line, char *msg)
1342 {
1343  return console_log2(level_str, file, func, line, msg);
1344 }
1345 
1347 {
1348  return console_clean_log(msg);
1349 }
1350 
1351 SWITCH_DECLARE(void) console_log(char *level_str, char *msg)
1352 {
1354  if (level_str) {
1355  level = switch_log_str2level(level_str);
1356  if (level == SWITCH_LOG_INVALID) {
1357  level = SWITCH_LOG_DEBUG;
1358  }
1359  }
1361 }
1362 
1363 SWITCH_DECLARE(void) console_log2(char *level_str, char *file, char *func, int line, char *msg)
1364 {
1366  if (level_str) {
1367  level = switch_log_str2level(level_str);
1368  if (level == SWITCH_LOG_INVALID) {
1369  level = SWITCH_LOG_DEBUG;
1370  }
1371  }
1372  switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level, "%s", switch_str_nil(msg));
1373 }
1374 
1376 {
1378 }
1379 
1380 SWITCH_DECLARE(bool) email(char *to, char *from, char *headers, char *body, char *file, char *convert_cmd, char *convert_ext)
1381 {
1382  if (switch_simple_email(to, from, headers, body, file, convert_cmd, convert_ext) == SWITCH_TRUE) {
1383  return true;
1384  }
1385  return false;
1386 }
1387 
1388 SWITCH_DECLARE(void) switch_msleep(unsigned ms)
1389 {
1390  switch_sleep(ms * 1000);
1391  return;
1392 }
1393 
1394 SWITCH_DECLARE(void) bridge(CoreSession &session_a, CoreSession &session_b)
1395 {
1396  switch_input_callback_function_t dtmf_func = NULL;
1397  switch_input_args_t args;
1398  switch_channel_t *channel_a = NULL, *channel_b = NULL;
1399  const char *err = "Channels not ready\n";
1400 
1401  if (session_a.allocated && session_a.session && session_b.allocated && session_b.session) {
1402  channel_a = switch_core_session_get_channel(session_a.session);
1403  channel_b = switch_core_session_get_channel(session_b.session);
1404 
1405  if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) {
1406  session_a.begin_allow_threads();
1408  switch_channel_pre_answer(channel_a);
1409  }
1410 
1411  if (switch_channel_ready(channel_a) && switch_channel_ready(channel_b)) {
1412  args = session_a.get_cb_args(); // get the cb_args data structure for session a
1413  dtmf_func = args.input_callback; // get the call back function
1414  err = NULL;
1415  switch_ivr_multi_threaded_bridge(session_a.session, session_b.session, dtmf_func, args.buf, args.buf);
1416  }
1417  session_a.end_allow_threads();
1418  }
1419  }
1420 
1421  if (err) {
1422  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a.session), SWITCH_LOG_ERROR, "%s", err);
1423  }
1424 
1425 
1426 }
1427 
1429 {
1430  if (session_hungup) {
1431  switch_channel_t *channel = switch_core_session_get_channel(session_hungup);
1432  CoreSession *coresession = NULL;
1434 
1435  if ((coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession"))) {
1436  if (coresession->hook_state != state) {
1437  coresession->cause = switch_channel_get_cause(channel);
1438  coresession->hook_state = state;
1439  coresession->check_hangup_hook();
1440  }
1441  }
1442 
1443  return SWITCH_STATUS_SUCCESS;
1444  } else {
1445  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "hangup hook called with null session, something is horribly wrong\n");
1446  return SWITCH_STATUS_FALSE;
1447  }
1448 }
1449 
1450 
1452  void *input,
1453  switch_input_type_t itype,
1454  void *buf,
1455  unsigned int buflen) {
1456 
1457  switch_channel_t *channel = switch_core_session_get_channel(session_cb);
1458  CoreSession *coresession = NULL;
1459 
1460  coresession = (CoreSession *) switch_channel_get_private(channel, "CoreSession");
1461 
1462  if (!coresession) {
1463  return SWITCH_STATUS_FALSE;
1464  }
1465 
1466  return coresession->run_dtmf_callback(input, itype);
1467 }
1468 
1469 
1470 SWITCH_DECLARE(switch_status_t) CoreSession::process_callback_result(char *result)
1471 {
1472 
1475 
1476  return switch_ivr_process_fh(session, result, fhp);
1477 }
1478 
1479 /* For Emacs:
1480  * Local Variables:
1481  * mode:c
1482  * indent-tabs-mode:t
1483  * tab-width:4
1484  * c-basic-offset:4
1485  * End:
1486  * For VIM:
1487  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
1488  */
switch_channel_t * channel
Definition: switch_cpp.h:224
switch_status_t switch_event_serialize_json(switch_event_t *event, char **str)
virtual ~Event()
Definition: switch_cpp.cpp:331
void console_clean_log(char *msg)
void consoleCleanLog(char *msg)
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
void switch_core_session_hangup_state(switch_core_session_t *session, switch_bool_t force)
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_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#define switch_channel_hangup(channel, hangup_cause)
Hangup a channel flagging it's state machine to end.
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
#define switch_channel_answer(channel)
Answer a channel (initiate/acknowledge a successful connection)
switch_status_t hanguphook(switch_core_session_t *session_hungup)
the actual hangup hook called back by freeswitch core which in turn gets the session and calls the ap...
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
switch_status_t switch_ivr_process_fh(switch_core_session_t *session, const char *cmd, switch_file_handle_t *fhp)
Definition: switch_ivr.c:3888
#define SWITCH_CHANNEL_SESSION_LOG(x)
#define switch_core_session_force_locate(uuid_str)
Locate a session based on it's uuid even if the channel is not ready.
Definition: switch_core.h:925
char * switch_xml_toxml(_In_ switch_xml_t xml, _In_ switch_bool_t prn_header)
Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ mus...
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
int mine
Definition: switch_cpp.h:163
switch_status_t switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data, switch_event_node_t **node)
Bind an event callback to a specific event.
DTMF(char idigit, uint32_t iduration=SWITCH_DEFAULT_DTMF_DURATION)
Definition: switch_cpp.cpp:524
#define SWITCH_CHANNEL_LOG
switch_status_t switch_ivr_read(switch_core_session_t *session, uint32_t min_digits, uint32_t max_digits, const char *prompt_audio_file, const char *var_name, char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators, uint32_t digit_timeout)
void setGlobalVariable(char *var_name, char *var_val)
#define switch_event_del_header(_e, _h)
Definition: switch_event.h:211
switch_status_t switch_play_and_get_digits(switch_core_session_t *session, uint32_t min_digits, uint32_t max_digits, uint32_t max_tries, uint32_t timeout, const char *valid_terminators, const char *audio_file, const char *bad_input_audio_file, const char *var_name, char *digit_buffer, uint32_t digit_buffer_length, const char *digits_regex, uint32_t digit_timeout, const char *transfer_on_failure)
Play a sound and gather digits with the number of retries specified if the user doesn't give digits i...
#define switch_channel_set_state(channel, state)
Set the current state of a channel.
switch_status_t switch_channel_set_private(switch_channel_t *channel, const char *key, const void *private_info)
Set private data on channel.
const char * switch_channel_cause2str(_In_ switch_call_cause_t cause)
return a cause string for a given cause
Stream(void)
Definition: switch_cpp.cpp:541
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
void switch_channel_flush_dtmf(_In_ switch_channel_t *channel)
EventConsumer(const char *event_name=NULL, const char *subclass_name="", int len=5000)
Definition: switch_cpp.cpp:54
switch_event_types_t
Built-in Events.
switch_status_t switch_ivr_wait_for_answer(switch_core_session_t *session, switch_core_session_t *peer_session)
void switch_sleep(switch_interval_time_t t)
Definition: switch_time.c:620
switch_status_t switch_queue_pop_timeout(switch_queue_t *queue, void **data, switch_interval_time_t timeout)
Definition: switch_apr.c:1124
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
#define switch_channel_up(_channel)
switch_bool_t switch_core_running(void)
Definition: switch_core.c:2857
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_bool_t
Definition: switch_types.h:405
switch_status_t switch_name_event(const char *name, switch_event_types_t *type)
return the event id that matches a given event name
Definition: switch_event.c:430
switch_priority_t
Priority Indication.
Definition: switch_types.h:991
switch_bool_t switch_core_set_var_conditional(_In_z_ const char *varname, _In_opt_z_ const char *value, _In_opt_z_ const char *val2)
Conditionally add a global variable to the core.
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
switch_event_t * event
Definition: switch_cpp.h:161
switch_ivr_menu_t * menu
Definition: switch_cpp.h:85
switch_status_t switch_ivr_menu_bind_action(switch_ivr_menu_t *menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind)
switch_ivr_menu_bind_action: Bind a keystroke to an action.
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
void console_log2(char *level_str, char *file, char *func, int line, char *msg)
Representation of an event.
Definition: switch_event.h:80
#define switch_channel_ready(_channel)
void switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value)
Add a global variable to the core.
switch_status_t switch_event_add_body(switch_event_t *event, const char *fmt,...) PRINTF_FUNCTION(2
Add a body to an event.
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
switch_status_t switch_event_set_priority(switch_event_t *event, switch_priority_t priority)
Set the priority of an event.
Definition: switch_event.c:760
#define this_check(x)
Definition: switch_cpp.h:12
#define switch_channel_media_ready(_channel)
virtual ~DTMF()
Definition: switch_cpp.cpp:535
switch_status_t switch_ivr_insert_file(switch_core_session_t *session, const char *file, const char *insert_file, switch_size_t sample_point)
Definition: switch_ivr.c:4009
switch_stream_handle_t mystream
Definition: switch_cpp.h:145
switch_core_session_t * session
Definition: switch_cpp.h:223
void consoleLog2(char *level_str, char *file, char *func, int line, char *msg)
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
A representation of an XML tree.
Definition: switch_xml.h:76
#define SWITCH_DEFAULT_DTMF_DURATION
Definition: switch_types.h:115
const char * switch_channel_state_name(_In_ switch_channel_state_t state)
Render the name of the provided state enum.
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.
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1119
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
#define switch_event_create_subclass(_e, _eid, _sn)
Definition: switch_event.h:153
switch_status_t switch_ivr_menu_execute(switch_core_session_t *session, switch_ivr_menu_t *stack, char *name, void *obj)
Execute a menu.
uint32_t switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
Test for presence of given flag on a given channel.
switch_input_type_t
int mine
Definition: switch_cpp.h:147
#define zstr(x)
Definition: switch_utils.h:281
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.
switch_stream_handle_t * stream_p
Definition: switch_cpp.h:146
#define switch_core_session_execute_application(_a, _b, _c)
Execute an application on a session.
Definition: switch_core.h:1103
_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_core_chat_send(const char *dest_proto, switch_event_t *message_event)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:655
int main(int argc, char *argv[])
Definition: fs_encode.c:56
void switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state)
switch_memory_pool_t * pool
Definition: switch_cpp.h:184
switch_queue_t * events
Definition: switch_cpp.h:187
#define sanity_check(x)
Definition: switch_cpp.h:14
int64_t switch_time_t
Definition: switch_apr.h:188
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
switch_byte_t switch_byte_t * buf
void bridge(CoreSession &session_a, CoreSession &session_b)
bridge the audio of session_b into session_a
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.
switch_status_t(* switch_input_callback_function_t)(switch_core_session_t *session, void *input, switch_input_type_t input_type, void *buf, unsigned int buflen)
switch_log_level_t switch_log_str2level(_In_z_ const char *str)
Return the level number of the specified log level name.
char * switch_event_get_body(switch_event_t *event)
Retrieve the body value from an event.
Definition: switch_event.c:838
#define switch_channel_get_variable(_c, _v)
switch_core_session_t * session
Definition: switch_cpp.h:110
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
int globalSetVariable(const char *var, const char *val, const char *val2)
const char * switch_event_name(switch_event_types_t event)
Render the name of an event id enumeration.
Definition: switch_event.c:422
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_status_t dtmf_callback(switch_core_session_t *session_cb, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
switch_input_callback_function_t input_callback
#define SWITCH_DECLARE_CONSTRUCTOR
#define SWITCH_TIME_T_FMT
IVRMenu(IVRMenu *main, const char *name, const char *greeting_sound, const char *short_greeting_sound, const char *invalid_sound, const char *exit_sound, const char *transfer_sound, const char *confirm_macro, const char *confirm_key, const char *tts_engine, const char *tts_voice, int confirm_attempts, int inter_timeout, int digit_len, int timeout, int max_failures, int max_timeouts)
Definition: switch_cpp.cpp:161
switch_call_cause_t switch_channel_str2cause(_In_ const char *str)
return a cause code for a given string
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype)=0
#define SWITCH_CHANNEL_LOG_CLEAN
uintptr_t switch_size_t
char digit
Definition: switch_cpp.h:137
switch_status_t switch_event_create_json(switch_event_t **event, const char *json)
virtual void destroy(void)
switch_memory_pool_t * pool
Definition: switch_cpp.h:86
switch_byte_t switch_byte_t uint32_t buflen
int64_t switch_interval_time_t
Definition: switch_apr.h:191
#define SWITCH_STANDARD_STREAM(s)
switch_call_cause_t cause
Definition: switch_cpp.h:230
switch_channel_state_t hook_state
Definition: switch_cpp.h:229
uint32_t node_index
Definition: switch_cpp.h:193
#define this_check_void()
Definition: switch_cpp.h:13
void switch_core_session_rwunlock(_In_ switch_core_session_t *session)
Unlock a read or write lock on as given session.
char * switch_core_session_get_uuid(_In_ switch_core_session_t *session)
Retrieve the unique identifier from a session.
switch_status_t switch_channel_set_variable_var_check(switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check)
#define sanity_check_noreturn
Definition: switch_cpp.h:15
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
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:903
void switch_msleep(unsigned ms)
#define SWITCH_DECLARE_NONSTD(type)
Event(const char *type, const char *subclass_name=NULL)
Definition: switch_cpp.cpp:293
switch_channel_state_t
Channel States (these are the defaults, CS_SOFT_EXECUTE, CS_EXCHANGE_MEDIA, and CS_CONSUME_MEDIA are ...
bool email(char *to, char *from, char *headers, char *body, char *file, char *convert_cmd, char *convert_ext)
uint32_t duration
Definition: switch_cpp.h:138
switch_status_t switch_ivr_menu_init(switch_ivr_menu_t **new_menu, switch_ivr_menu_t *main, const char *name, const char *greeting_sound, const char *short_greeting_sound, const char *invalid_sound, const char *exit_sound, const char *transfer_sound, const char *confirm_macro, const char *confirm_key, const char *tts_engine, const char *tts_voice, int confirm_attempts, int inter_timeout, int digit_len, int timeout, int max_failures, int max_timeouts, switch_memory_pool_t *pool)
Create a new menu object.
switch_stream_handle_write_function_t write_function
#define switch_channel_down(_channel)
switch_status_t
Common return values.
void * switch_channel_get_private(switch_channel_t *channel, const char *key)
Retrieve private from a given channel.
switch_status_t switch_core_session_read_lock_hangup(_In_ switch_core_session_t *session)
Acquire a read lock on the session.
switch_status_t switch_core_session_dequeue_event(_In_ switch_core_session_t *session, _Out_ switch_event_t **event, switch_bool_t force)
DE-Queue an event on a given session.
virtual ~IVRMenu()
Definition: switch_cpp.cpp:193
char * getGlobalVariable(char *var_name)
switch_status_t switch_core_session_receive_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event)
Send an event to a session translating it to it's native message format.
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
Definition: switch_apr.c:1145
static void event_handler(switch_event_t *event)
Definition: switch_cpp.cpp:40
Main Library Header.
switch_ivr_action_t
Definition: switch_ivr.h:773
#define SWITCH_DECLARE(type)
switch_bool_t switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file, const char *convert_cmd, const char *convert_ext)
Definition: switch_utils.c:981
#define switch_event_get_header(_e, _h)
Definition: switch_event.h:172
bool running(void)
switch_call_direction_t switch_channel_direction(switch_channel_t *channel)
virtual ~CoreSession()
Definition: switch_cpp.cpp:647
switch_status_t switch_ivr_menu_str2action(const char *action_name, switch_ivr_action_t *action)
switch_status_t switch_core_execute_chat_app(switch_event_t *message, const char *app, const char *data)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
#define init_vars()
Definition: switch_cpp.h:16
virtual void check_hangup_hook()=0
Callback to the language specific hangup callback.
char * serialized_string
Definition: switch_cpp.h:162
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
virtual ~Stream()
Definition: switch_cpp.cpp:555
char * uuid
Definition: switch_cpp.h:232
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.
#define SWITCH_VA_NONE
#define switch_ivr_phrase_macro(session, macro_name, data, lang, args)
Definition: switch_ivr.h:903
API(CoreSession *s=NULL)
Definition: switch_cpp.cpp:221
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1109
void switch_event_destroy(switch_event_t **event)
Destroy an event.
void * bind_user_data
Definition: switch_event.h:96
#define switch_assert(expr)
switch_status_t switch_ivr_say(switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type, const char *say_method, const char *say_gender, switch_input_args_t *args)
Definition: switch_ivr.c:3507
switch_status_t switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
Generate an XML CDR report.
Definition: switch_ivr.c:2713
#define switch_channel_pre_answer(channel)
Indicate progress on a channel to attempt early media.
switch_status_t switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode)
virtual ~API()
Definition: switch_cpp.cpp:230
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
SWITCH_BEGIN_EXTERN_C char * switch_mprintf(const char *zFormat,...)
void console_log(char *level_str, char *msg)
memset(buf, 0, buflen)
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.
char * switch_core_get_variable_dup(_In_z_ const char *varname)
void consoleLog(char *level_str, char *msg)
switch_call_cause_t switch_channel_get_cause(_In_ switch_channel_t *channel)
return the cause code for a given channel
switch_status_t switch_ivr_menu_stack_free(switch_ivr_menu_t *stack)
free a stack of menu objects.
switch_xml_t switch_event_xmlize(switch_event_t *event, const char *fmt,...) PRINTF_FUNCTION(2
Render a XML representation of an event suitable for printing or network transport.
switch_status_t switch_event_unbind(switch_event_node_t **node)
Unbind a bound event consumer.
int bind(const char *event_name, const char *subclass_name="")
Definition: switch_cpp.cpp:67