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