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  * Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
28  * Joseph Sullivan <jossulli@amazon.com>
29  * Emmanuel Schmidbauer <eschmidbauer@gmail.com>
30  * Andrey Volk <andywolk@gmail.com>
31  *
32  * switch_core.h -- Core Library
33  *
34  */
35 /*! \file switch_core.h
36   \brief Core Library
37 
38   This module is the main core library and is the intended location of all fundamental operations.
39 */
40 
41 #ifndef SWITCH_CORE_H
42 #define SWITCH_CORE_H
43 
44 #include <switch.h>
45 
46 SWITCH_BEGIN_EXTERN_C
47 #define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128
48 #define SWITCH_MAX_STREAMS 128
49 	struct switch_core_time_duration {
50 	uint32_t mms;
51 	uint32_t ms;
52 	uint32_t sec;
53 	uint32_t min;
54 	uint32_t hr;
55 	uint32_t day;
56 	uint32_t yr;
57 };
58 
59 struct switch_app_log {
60 	char *app;
61 	char *arg;
62 	switch_time_t stamp;
63 	struct switch_app_log *next;
64 };
65 
66 typedef struct switch_thread_data_s {
67 	switch_thread_start_t func;
68 	void *obj;
69 	int alloc;
70 	switch_memory_pool_t *pool;
71 } switch_thread_data_t;
72 
73 typedef struct switch_hold_record_s {
74 	switch_time_t on;
75 	switch_time_t off;
76 	char *uuid;
77 	struct switch_hold_record_s *next;
78 } switch_hold_record_t;
79 
80 typedef struct device_uuid_node_s {
81 	char *uuid;
82 	switch_xml_t xml_cdr;
83 	switch_event_t *event;
84 	switch_channel_callstate_t callstate;
85 	switch_hold_record_t *hold_record;
86 	switch_caller_profile_t *hup_profile;
87 	switch_call_direction_t direction;
88 	struct switch_device_record_s *parent;
89 	struct device_uuid_node_s *next;
90 } switch_device_node_t;
91 
92 typedef struct switch_device_stats_s {
93 	uint32_t total;
94 	uint32_t total_in;
95 	uint32_t total_out;
96 	uint32_t offhook;
97 	uint32_t offhook_in;
98 	uint32_t offhook_out;
99 	uint32_t active;
100 	uint32_t active_in;
101 	uint32_t active_out;
102 	uint32_t held;
103 	uint32_t held_in;
104 	uint32_t held_out;
105 	uint32_t unheld;
106 	uint32_t unheld_in;
107 	uint32_t unheld_out;
108 	uint32_t hup;
109 	uint32_t hup_in;
110 	uint32_t hup_out;
111 	uint32_t ringing;
112 	uint32_t ringing_in;
113 	uint32_t ringing_out;
114 	uint32_t early;
115 	uint32_t early_in;
116 	uint32_t early_out;
117 	uint32_t ring_wait;
118 } switch_device_stats_t;
119 
120 
121 typedef struct switch_device_record_s {
122 	char *device_id;
123 	char *uuid;
124 	int refs;
125 	switch_device_stats_t stats;
126 	switch_device_stats_t last_stats;
127 	switch_device_state_t state;
128 	switch_device_state_t last_state;
129 	switch_time_t active_start;
130 	switch_time_t active_stop;
131 	switch_time_t last_call_time;
132 	switch_time_t ring_start;
133 	switch_time_t ring_stop;
134 	switch_time_t hold_start;
135 	switch_time_t hold_stop;
136 	switch_time_t call_start;
137 	struct device_uuid_node_s *uuid_list;
138 	struct device_uuid_node_s *uuid_tail;
139 	switch_mutex_t *mutex;
140 	switch_memory_pool_t *pool;
141 	void *user_data;
142 } switch_device_record_t;
143 
144 typedef void(*switch_device_state_function_t)(switch_core_session_t *session, switch_channel_callstate_t callstate, switch_device_record_t *drec);
145 
146 
147 #define DTLS_SRTP_FNAME "dtls-srtp"
148 #define MAX_FPLEN 64
149 #define MAX_FPSTRLEN 192
150 
151 typedef struct dtls_fp_s {
152 	uint32_t len;
153 	uint8_t data[MAX_FPLEN+1];
154 	char *type;
155 	char str[MAX_FPSTRLEN];
156 } dtls_fingerprint_t;
157 
158 typedef enum {
159 	DTLS_TYPE_CLIENT = (1 << 0),
160 	DTLS_TYPE_SERVER = (1 << 1),
161 	DTLS_TYPE_RTP = (1 << 2),
162 	DTLS_TYPE_RTCP = (1 << 3)
163 } dtls_type_t;
164 
165 typedef enum {
166 	DS_OFF,
167 	DS_HANDSHAKE,
168 	DS_SETUP,
169 	DS_READY,
170 	DS_FAIL,
171 	DS_INVALID,
172 } dtls_state_t;
173 
174 #define MESSAGE_STAMP_FFL(_m) _m->_file = __FILE__; _m->_func = __SWITCH_FUNC__; _m->_line = __LINE__
175 
176 #define MESSAGE_STRING_ARG_MAX 10
177 /*! \brief A message object designed to allow unlike technologies to exchange data */
178 struct switch_core_session_message {
179 	/*! uuid of the sender (for replies) */
180 	char *from;
181 	/*! enumeration of the type of message */
182 	switch_core_session_message_types_t message_id;
183 
184 	/*! optional numeric arg */
185 	int numeric_arg;
186 	/*! optional string arg */
187 	const char *string_arg;
188 	/*! optional string arg */
189 	switch_size_t string_arg_size;
190 	/*! optional arbitrary pointer arg */
191 	void *pointer_arg;
192 	/*! optional arbitrary pointer arg's size */
193 	switch_size_t pointer_arg_size;
194 
195 	/*! optional numeric reply */
196 	int numeric_reply;
197 	/*! optional string reply */
198 	char *string_reply;
199 	/*! optional string reply */
200 	switch_size_t string_reply_size;
201 	/*! optional arbitrary pointer reply */
202 	void *pointer_reply;
203 	/*! optional arbitrary pointer reply's size */
204 	switch_size_t pointer_reply_size;
205 	/*! message flags */
206 	switch_core_session_message_flag_t flags;
207 	const char *_file;
208 	const char *_func;
209 	int _line;
210 	const char *string_array_arg[MESSAGE_STRING_ARG_MAX];
211 	time_t delivery_time;
212 };
213 
214 /*! \brief A generic object to pass as a thread's session object to allow mutiple arguements and a pool */
215 struct switch_core_thread_session {
216 	/*! status of the thread */
217 	int running;
218 	/*! mutex */
219 	switch_mutex_t *mutex;
220 	/*! array of void pointers to pass mutiple data objects */
221 	void *objs[SWITCH_MAX_CORE_THREAD_SESSION_OBJS];
222 	/*! a pointer to a memory pool if the thread has it's own pool */
223 	switch_input_callback_function_t input_callback;
224 	switch_memory_pool_t *pool;
225 };
226 
227 struct switch_core_session;
228 struct switch_core_runtime;
229 struct switch_core_port_allocator;
230 
231 
switch_must_malloc(size_t _b)232 static inline void *switch_must_malloc(size_t _b)
233 {
234 	void *m = malloc(_b);
235 	switch_assert(m);
236 	return m;
237 }
238 
switch_must_realloc(void * _b,size_t _z)239 static inline void *switch_must_realloc(void *_b, size_t _z)
240 {
241 	void *m = realloc(_b, _z);
242 	switch_assert(m);
243 	return m;
244 }
245 
switch_must_strdup(const char * _s)246 static inline char *switch_must_strdup(const char *_s)
247 {
248 	char *s = strdup(_s);
249 	switch_assert(s);
250 	return s;
251 }
252 
253 
254 /*!
255   \defgroup core1 Core Library
256   \ingroup FREESWITCH
257   \{
258 */
259 
260 ///\defgroup mb1 Media Bugs
261 ///\ingroup core1
262 ///\{
263 
264 
265 SWITCH_DECLARE(void) switch_core_screen_size(int *x, int *y);
266 SWITCH_DECLARE(void) switch_core_session_sched_heartbeat(switch_core_session_t *session, uint32_t seconds);
267 SWITCH_DECLARE(void) switch_core_session_unsched_heartbeat(switch_core_session_t *session);
268 
269 SWITCH_DECLARE(void) switch_core_session_enable_heartbeat(switch_core_session_t *session, uint32_t seconds);
270 SWITCH_DECLARE(void) switch_core_session_disable_heartbeat(switch_core_session_t *session);
271 
272 #define switch_core_session_get_name(_s) switch_channel_get_name(switch_core_session_get_channel(_s))
273 
274 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_pop(switch_core_session_t *orig_session, const char *function, switch_media_bug_t **pop);
275 
276 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_exec_all(switch_core_session_t *orig_session,
277 															   const char *function, switch_media_bug_exec_cb_t cb, void *user_data);
278 SWITCH_DECLARE(uint32_t) switch_core_media_bug_patch_video(switch_core_session_t *orig_session, switch_frame_t *frame);
279 SWITCH_DECLARE(uint32_t) switch_core_media_bug_count(switch_core_session_t *orig_session, const char *function);
280 SWITCH_DECLARE(void) switch_media_bug_set_spy_fmt(switch_media_bug_t *bug, switch_vid_spy_fmt_t spy_fmt);
281 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_push_spy_frame(switch_media_bug_t *bug, switch_frame_t *frame, switch_rw_t rw);
282 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_patch_spy_frame(switch_media_bug_t *bug, switch_image_t *img, switch_rw_t rw);
283 SWITCH_DECLARE(switch_vid_spy_fmt_t) switch_media_bug_parse_spy_fmt(const char *name);
284 
285 /*!
286   \brief Add a media bug to the session
287   \param session the session to add the bug to
288   \param callback a callback for events
289   \param user_data arbitrary user data
290   \param stop_time absolute time at which the bug is automatically removed (or 0)
291   \param flags flags to choose the stream
292   \param new_bug pointer to assign new bug to
293   \return SWITCH_STATUS_SUCCESS if the operation was a success
294 */
295 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(_In_ switch_core_session_t *session,
296 														  _In_ const char *function,
297 														  _In_ const char *target,
298 														  _In_ switch_media_bug_callback_t callback,
299 														  _In_opt_ void *user_data,
300 														  _In_ time_t stop_time, _In_ switch_media_bug_flag_t flags, _Out_ switch_media_bug_t **new_bug);
301 
302 /*!
303   \brief Pause a media bug on the session
304   \param session the session to pause the bug on sets CF_PAUSE_BUGS flag
305 */
306 SWITCH_DECLARE(void) switch_core_media_bug_pause(switch_core_session_t *session);
307 
308 /*!
309   \brief Resume a media bug on the session
310   \param session the session to resume the bug on, clears CF_PAUSE_BUGS flag
311 */
312 SWITCH_DECLARE(void) switch_core_media_bug_resume(switch_core_session_t *session);
313 
314 SWITCH_DECLARE(void) switch_core_media_bug_inuse(switch_media_bug_t *bug, switch_size_t *readp, switch_size_t *writep);
315 
316 /*!
317   \brief Obtain private data from a media bug
318   \param bug the bug to get the data from
319   \return the private data
320 */
321 SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(_In_ switch_media_bug_t *bug);
322 
323 /*!
324   \brief Obtain a replace frame from a media bug
325   \param bug the bug to get the data from
326 */
327 SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_write_replace_frame(_In_ switch_media_bug_t *bug);
328 
329 
330 SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_native_read_frame(switch_media_bug_t *bug);
331 SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_native_write_frame(switch_media_bug_t *bug);
332 
333 
334 SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_video_ping_frame(switch_media_bug_t *bug);
335 
336 /*!
337   \brief Set a return replace frame
338   \param bug the bug to set the frame on
339   \param frame the frame to set
340 */
341 SWITCH_DECLARE(void) switch_core_media_bug_set_write_replace_frame(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
342 
343 /*!
344   \brief Obtain a replace frame from a media bug
345   \param bug the bug to get the data from
346 */
347 SWITCH_DECLARE(switch_frame_t *) switch_core_media_bug_get_read_replace_frame(_In_ switch_media_bug_t *bug);
348 SWITCH_DECLARE(void) switch_core_media_bug_set_read_demux_frame(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
349 /*!
350   \brief Obtain the session from a media bug
351   \param bug the bug to get the data from
352 */
353 SWITCH_DECLARE(switch_core_session_t *) switch_core_media_bug_get_session(_In_ switch_media_bug_t *bug);
354 
355 SWITCH_DECLARE(void) switch_core_media_bug_set_media_params(switch_media_bug_t *bug, switch_mm_t *mm);
356 SWITCH_DECLARE(void) switch_core_media_bug_get_media_params(switch_media_bug_t *bug, switch_mm_t *mm);
357 
358 SWITCH_DECLARE(const char *) switch_core_media_bug_get_text(switch_media_bug_t *bug);
359 
360 /*!
361   \brief Test for the existance of a flag on an media bug
362   \param bug the object to test
363   \param flag the or'd list of flags to test
364   \return true value if the object has the flags defined
365 */
366 SWITCH_DECLARE(uint32_t) switch_core_media_bug_test_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag);
367 SWITCH_DECLARE(uint32_t) switch_core_media_bug_set_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag);
368 SWITCH_DECLARE(uint32_t) switch_core_media_bug_clear_flag(_In_ switch_media_bug_t *bug, _In_ uint32_t flag);
369 
370 /*!
371   \brief Set a return replace frame
372   \param bug the bug to set the frame on
373   \param frame the frame to set
374 */
375 SWITCH_DECLARE(void) switch_core_media_bug_set_read_replace_frame(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
376 
377 SWITCH_DECLARE(uint32_t) switch_core_cpu_count(void);
378 
379 /*!
380   \brief Remove a media bug from the session
381   \param session the session to remove the bug from
382   \param bug bug to remove
383   \return SWITCH_STATUS_SUCCESS if the operation was a success
384 */
385 
386 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(_In_ switch_core_session_t *session, _Inout_ switch_media_bug_t **bug);
387 SWITCH_DECLARE(uint32_t) switch_core_media_bug_prune(switch_core_session_t *session);
388 
389 /*!
390   \brief Remove media bug callback
391   \param bug bug to remove
392   \param callback callback to remove
393   \return SWITCH_STATUS_SUCCESS if the operation was a success
394 */
395 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_callback(switch_core_session_t *session, switch_media_bug_callback_t callback);
396 
397 /*!
398   \brief Close and destroy a media bug
399   \param bug bug to remove
400   \return SWITCH_STATUS_SUCCESS if the operation was a success
401 */
402 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(_Inout_ switch_media_bug_t **bug, switch_bool_t destroy);
403 /*!
404   \brief Remove all media bugs from the session
405   \param session the session to remove the bugs from
406   \return SWITCH_STATUS_SUCCESS if the operation was a success
407 */
408 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all_function(_In_ switch_core_session_t *session, const char *function);
409 
410 #define switch_core_media_bug_remove_all(_s) switch_core_media_bug_remove_all_function(_s, NULL)
411 
412 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_enumerate(switch_core_session_t *session, switch_stream_handle_t *stream);
413 
414 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_transfer_callback(switch_core_session_t *orig_session, switch_core_session_t *new_session,
415 																		switch_media_bug_callback_t callback, void * (*user_data_dup_func) (switch_core_session_t *, void *));
416 
417 
418 /*!
419   \brief Read a frame from the bug
420   \param bug the bug to read from
421   \param frame the frame to write the data to
422   \return the amount of data
423 */
424 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame, switch_bool_t fill);
425 
426 /*!
427   \brief Flush the read and write buffers for the bug
428   \param bug the bug to flush the read and write buffers on
429 */
430 SWITCH_DECLARE(void) switch_core_media_bug_flush(_In_ switch_media_bug_t *bug);
431 
432 /*!
433   \brief Flush the read/write buffers for all media bugs on the session
434   \param session the session to flush the read/write buffers for all media bugs on the session
435 */
436 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(_In_ switch_core_session_t *session);
437 
438 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_set_pre_buffer_framecount(switch_media_bug_t *bug, uint32_t framecount);
439 
440 ///\}
441 
442 ///\defgroup pa1 Port Allocation
443 ///\ingroup core1
444 ///\{
445 
446 /*!
447   \brief Initilize the port allocator
448   \param start the starting port
449   \param end the ending port
450   \param flags flags to change allocator behaviour (e.g. only even/odd portnumbers)
451   \param new_allocator new pointer for the return value
452   \return SWITCH_STATUS_SUCCESS if the operation was a success
453 */
454 SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(_In_ const char *ip,
455 															   _In_ switch_port_t start,
456 															   _In_ switch_port_t end,
457 															   _In_ switch_port_flag_t flags, _Out_ switch_core_port_allocator_t **new_allocator);
458 
459 /*!
460   \brief Get a port from the port allocator
461   \param alloc the allocator object
462   \param port_ptr a pointer to the port
463   \return SUCCESS
464 */
465 SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_request_port(_In_ switch_core_port_allocator_t *alloc, _Out_ switch_port_t *port_ptr);
466 
467 /*!
468   \brief Return unused port to the port allocator
469   \param alloc the allocator object
470   \param port the port
471   \return SUCCESS
472 */
473 SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(_In_ switch_core_port_allocator_t *alloc, _In_ switch_port_t port);
474 
475 /*!
476   \brief destroythe port allocator
477   \param alloc the allocator object
478 */
479 SWITCH_DECLARE(void) switch_core_port_allocator_destroy(_Inout_ switch_core_port_allocator_t **alloc);
480 ///\}
481 
482 
483 SWITCH_DECLARE(int) switch_core_test_flag(int flag);
484 
485 ///\defgroup ss Startup/Shutdown
486 ///\ingroup core1
487 ///\{
488 /*!
489   \brief Initilize the core
490   \param console optional FILE stream for output
491   \param flags core flags
492   \param err a pointer to set any errors to
493   \note to be called at application startup
494 */
495 SWITCH_DECLARE(switch_status_t) switch_core_init(_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err);
496 
497 /*!
498   \brief Initilize the core and load modules
499   \param console optional FILE stream for output
500   \param flags core flags
501   \param err a pointer to set any errors to
502   \note to be called at application startup instead of switch_core_init.  Includes module loading.
503 */
504 SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(_In_ switch_core_flag_t flags, _In_ switch_bool_t console, _Out_ const char **err);
505 
506 /*!
507   \brief Set/Get Session Limit
508   \param new_limit new value (if > 0)
509   \return the current session limit
510 */
511 SWITCH_DECLARE(uint32_t) switch_core_session_limit(_In_ uint32_t new_limit);
512 
513 /*!
514   \brief Set/Get Session Rate Limit
515   \param new_limit new value (if > 0)
516   \return the current session rate limit
517 */
518 SWITCH_DECLARE(uint32_t) switch_core_sessions_per_second(_In_ uint32_t new_limit);
519 
520 /*!
521   \brief Destroy the core
522   \note to be called at application shutdown
523 */
524 SWITCH_DECLARE(switch_status_t) switch_core_destroy(void);
525 ///\}
526 
527 
528 ///\defgroup rwl Read/Write Locking
529 ///\ingroup core1
530 ///\{
531 
532 
533 SWITCH_DECLARE(switch_status_t) switch_core_session_io_read_lock(switch_core_session_t *session);
534 SWITCH_DECLARE(switch_status_t) switch_core_session_io_write_lock(switch_core_session_t *session);
535 SWITCH_DECLARE(switch_status_t) switch_core_session_io_rwunlock(switch_core_session_t *session);
536 
537 #ifdef SWITCH_DEBUG_RWLOCKS
538 SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
539 #endif
540 
541 /*!
542   \brief Acquire a read lock on the session
543   \param session the session to acquire from
544   \return success if it is safe to read from the session
545 */
546 #ifdef SWITCH_DEBUG_RWLOCKS
547 #define switch_core_session_read_lock(session) switch_core_session_perform_read_lock(session, __FILE__, __SWITCH_FUNC__, __LINE__)
548 #else
549 SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(_In_ switch_core_session_t *session);
550 #endif
551 
552 
553 #ifdef SWITCH_DEBUG_RWLOCKS
554 SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(_In_ switch_core_session_t *session, const char *file, const char *func,
555 																			 int line);
556 #endif
557 
558 /*!
559   \brief Acquire a read lock on the session
560   \param session the session to acquire from
561   \return success if it is safe to read from the session
562 */
563 #ifdef SWITCH_DEBUG_RWLOCKS
564 #define switch_core_session_read_lock_hangup(session) switch_core_session_perform_read_lock_hangup(session, __FILE__, __SWITCH_FUNC__, __LINE__)
565 #else
566 SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(_In_ switch_core_session_t *session);
567 #endif
568 
569 
570 #ifdef SWITCH_DEBUG_RWLOCKS
571 SWITCH_DECLARE(void) switch_core_session_perform_write_lock(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
572 #endif
573 
574 /*!
575   \brief Acquire a write lock on the session
576   \param session the session to acquire from
577 */
578 #ifdef SWITCH_DEBUG_RWLOCKS
579 #define switch_core_session_write_lock(session) switch_core_session_perform_write_lock(session, __FILE__, __SWITCH_FUNC__, __LINE__)
580 #else
581 SWITCH_DECLARE(void) switch_core_session_write_lock(_In_ switch_core_session_t *session);
582 #endif
583 
584 #ifdef SWITCH_DEBUG_RWLOCKS
585 SWITCH_DECLARE(void) switch_core_session_perform_rwunlock(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
586 #endif
587 
588 /*!
589   \brief Unlock a read or write lock on as given session
590   \param session the session
591 */
592 #ifdef SWITCH_DEBUG_RWLOCKS
593 #define switch_core_session_rwunlock(session) switch_core_session_perform_rwunlock(session, __FILE__, __SWITCH_FUNC__, __LINE__)
594 #else
595 SWITCH_DECLARE(void) switch_core_session_rwunlock(_In_ switch_core_session_t *session);
596 #endif
597 
598 ///\}
599 
600 ///\defgroup sh State Handlers
601 ///\ingroup core1
602 ///\{
603 /*!
604   \brief Add a global state handler
605   \param state_handler a state handler to add
606   \return the current index/priority of this handler
607 */
608 SWITCH_DECLARE(int) switch_core_add_state_handler(_In_ const switch_state_handler_table_t *state_handler);
609 
610 /*!
611   \brief Remove a global state handler
612   \param state_handler the state handler to remove
613 */
614 SWITCH_DECLARE(void) switch_core_remove_state_handler(_In_ const switch_state_handler_table_t *state_handler);
615 
616 /*!
617   \brief Access a state handler
618   \param index the desired index to access
619   \return the desired state handler table or NULL when it does not exist.
620 */
621 SWITCH_DECLARE(const switch_state_handler_table_t *) switch_core_get_state_handler(_In_ int index);
622 ///\}
623 
624 SWITCH_DECLARE(void) switch_core_memory_pool_tag(switch_memory_pool_t *pool, const char *tag);
625 
626 SWITCH_DECLARE(void) switch_core_pool_stats(switch_stream_handle_t *stream);
627 
628 SWITCH_DECLARE(switch_status_t) switch_core_perform_new_memory_pool(_Out_ switch_memory_pool_t **pool,
629 																	_In_z_ const char *file, _In_z_ const char *func, _In_ int line);
630 
631 ///\defgroup memp Memory Pooling/Allocation
632 ///\ingroup core1
633 ///\{
634 /*!
635   \brief Create a new sub memory pool from the core's master pool
636   \return SWITCH_STATUS_SUCCESS on success
637 */
638 #define switch_core_new_memory_pool(p) switch_core_perform_new_memory_pool(p, __FILE__, __SWITCH_FUNC__, __LINE__)
639 
640 SWITCH_DECLARE(int) switch_core_session_sync_clock(void);
641 SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(_Inout_ switch_memory_pool_t **pool,
642 																		_In_z_ const char *file, _In_z_ const char *func, _In_ int line);
643 /*!
644   \brief Returns a subpool back to the main pool
645   \return SWITCH_STATUS_SUCCESS on success
646 */
647 #define switch_core_destroy_memory_pool(p) switch_core_perform_destroy_memory_pool(p, __FILE__, __SWITCH_FUNC__, __LINE__)
648 
649 
650 SWITCH_DECLARE(void) switch_core_memory_pool_set_data(switch_memory_pool_t *pool, const char *key, void *data);
651 SWITCH_DECLARE(void *) switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key);
652 
653 
654 /*!
655   \brief Start the session's state machine
656   \param session the session on which to start the state machine
657 */
658 SWITCH_DECLARE(void) switch_core_session_run(_In_ switch_core_session_t *session);
659 
660 /*!
661   \brief determine if the session's state machine is running
662   \param session the session on which to check
663 */
664 SWITCH_DECLARE(unsigned int) switch_core_session_running(_In_ switch_core_session_t *session);
665 SWITCH_DECLARE(unsigned int) switch_core_session_started(_In_ switch_core_session_t *session);
666 
667 SWITCH_DECLARE(void *) switch_core_perform_permanent_alloc(_In_ switch_size_t memory, _In_z_ const char *file, _In_z_ const char *func, _In_ int line);
668 
669 
670 /*!
671   \brief Allocate memory from the main pool with no intention of returning it
672   \param _memory the number of bytes to allocate
673   \return a void pointer to the allocated memory
674   \note this memory never goes out of scope until the core is destroyed
675 */
676 #define switch_core_permanent_alloc(_memory) switch_core_perform_permanent_alloc(_memory, __FILE__, __SWITCH_FUNC__, __LINE__)
677 
678 
679 SWITCH_DECLARE(void *) switch_core_perform_alloc(_In_ switch_memory_pool_t *pool, _In_ switch_size_t memory, _In_z_ const char *file,
680 												 _In_z_ const char *func, _In_ int line);
681 
682 /*!
683   \brief Allocate memory directly from a memory pool
684   \param _pool the memory pool to allocate from
685   \param _mem the number of bytes to allocate
686   \remark the memory returned has been memset to zero
687   \return a void pointer to the allocated memory
688 */
689 #define switch_core_alloc(_pool, _mem) switch_core_perform_alloc(_pool, _mem, __FILE__, __SWITCH_FUNC__, __LINE__)
690 
691 	 _Ret_ SWITCH_DECLARE(void *) switch_core_perform_session_alloc(_In_ switch_core_session_t *session, _In_ switch_size_t memory, const char *file,
692 																	const char *func, int line);
693 
694 /*!
695   \brief Allocate memory from a session's pool
696   \param _session the session to request memory from
697   \param _memory the amount of memory to allocate
698   \return a void pointer to the newly allocated memory
699   \note the memory will be in scope as long as the session exists
700 */
701 #define switch_core_session_alloc(_session, _memory) switch_core_perform_session_alloc(_session, _memory, __FILE__, __SWITCH_FUNC__, __LINE__)
702 
703 
704 
705 SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(_In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line);
706 
707 /*!
708   \brief Copy a string using permanent memory allocation
709   \param _todup the string to duplicate
710   \return a pointer to the newly duplicated string
711 */
712 #define switch_core_permanent_strdup(_todup) switch_core_perform_permanent_strdup(_todup, __FILE__, __SWITCH_FUNC__, __LINE__)
713 
714 
715 SWITCH_DECLARE(char *) switch_core_perform_session_strdup(_In_ switch_core_session_t *session, _In_z_ const char *todup, _In_z_ const char *file,
716 														  _In_z_ const char *func, _In_ int line);
717 
718 /*!
719   \brief Copy a string using memory allocation from a session's pool
720   \param _session a session to use for allocation
721   \param _todup the string to duplicate
722   \return a pointer to the newly duplicated string
723 */
724 #define switch_core_session_strdup(_session, _todup) switch_core_perform_session_strdup(_session, _todup, __FILE__, __SWITCH_FUNC__, __LINE__)
725 
726 
727 SWITCH_DECLARE(char *) switch_core_perform_strdup(_In_ switch_memory_pool_t *pool, _In_z_ const char *todup, _In_z_ const char *file,
728 												  _In_z_ const char *func, _In_ int line);
729 SWITCH_DECLARE(char *) switch_core_perform_strndup(_In_ switch_memory_pool_t *pool, _In_z_ const char *todup, size_t len, _In_z_ const char *file,
730 												  _In_z_ const char *func, _In_ int line);
731 
732 /*!
733   \brief Copy a string using memory allocation from a given pool
734   \param _pool the pool to use for allocation
735   \param _todup the string to duplicate
736   \return a pointer to the newly duplicated string
737 */
738 #define switch_core_strdup(_pool, _todup)  switch_core_perform_strdup(_pool, _todup, __FILE__, __SWITCH_FUNC__, __LINE__)
739 
740 #define switch_core_strndup(_pool, _todup, _len)  switch_core_perform_strndup(_pool, _todup, _len, __FILE__, __SWITCH_FUNC__, __LINE__)
741 
742 /*!
743   \brief printf-style style printing routine.  The data is output to a string allocated from the session
744   \param session a session to use for allocation
745   \param fmt The format of the string
746   \param ... The arguments to use while printing the data
747   \return The new string
748 */
749 SWITCH_DECLARE(char *) switch_core_session_sprintf(_In_ switch_core_session_t *session, _In_z_ _Printf_format_string_ const char *fmt, ...);
750 
751 /*!
752   \brief printf-style style printing routine.  The data is output to a string allocated from the session
753   \param session a session to use for allocation
754   \param fmt The format of the string
755   \param ap The arguments to use while printing the data
756   \return The new string
757 */
758 #ifndef SWIG
759 SWITCH_DECLARE(char *) switch_core_session_vsprintf(switch_core_session_t *session, const char *fmt, va_list ap);
760 #endif
761 
762 /*!
763   \brief printf-style style printing routine.  The data is output to a string allocated from the pool
764   \param pool a pool to use for allocation
765   \param fmt The format of the string
766   \param ... The arguments to use while printing the data
767   \return The new string
768 */
769 SWITCH_DECLARE(char *) switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt, ...);
770 
771 /*!
772   \brief printf-style style printing routine.  The data is output to a string allocated from the pool
773   \param pool a pool to use for allocation
774   \param fmt The format of the string
775   \param ap The arguments to use while printing the data
776   \return The new string
777 */
778 #ifndef SWIG
779 SWITCH_DECLARE(char *) switch_core_vsprintf(switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt, va_list ap);
780 #endif
781 
782 /*!
783   \brief Retrieve the memory pool from a session
784   \param session the session to retrieve the pool from
785   \return the session's pool
786   \note to be used sparingly
787 */
788 SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(_In_ switch_core_session_t *session);
789 ///\}
790 
791 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_xml(switch_endpoint_interface_t *endpoint_interface,
792 																		switch_memory_pool_t **pool, switch_xml_t xml);
793 
794 ///\defgroup sessm Session Creation / Management
795 ///\ingroup core1
796 ///\{
797 /*!
798   \brief Allocate and return a new session from the core
799   \param endpoint_interface the endpoint interface the session is to be based on
800   \param pool the pool to use for the allocation (a new one will be used if NULL)
801   \return the newly created session
802 */
803 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ switch_endpoint_interface_t *endpoint_interface,
804 																		 _In_ switch_call_direction_t direction,
805 																		 switch_originate_flag_t originate_flags,
806 																		 _Inout_opt_ switch_memory_pool_t **pool,
807 																		 _In_opt_z_ const char *use_uuid);
808 #define switch_core_session_request(_ep, _d, _f, _p) switch_core_session_request_uuid(_ep, _d, _f, _p, NULL)
809 
810 SWITCH_DECLARE(switch_status_t) switch_core_session_set_uuid(_In_ switch_core_session_t *session, _In_z_ const char *use_uuid);
811 
812 SWITCH_DECLARE(void) switch_core_session_perform_destroy(_Inout_ switch_core_session_t **session,
813 														 _In_z_ const char *file, _In_z_ const char *func, _In_ int line);
814 
815 /*!
816   \brief Destroy a session and return the memory pool to the core
817   \param session pointer to a pointer of the session to destroy
818   \return
819 */
820 #define switch_core_session_destroy(session) switch_core_session_perform_destroy(session, __FILE__, __SWITCH_FUNC__, __LINE__)
821 
822 SWITCH_DECLARE(void) switch_core_session_destroy_state(switch_core_session_t *session);
823 SWITCH_DECLARE(void) switch_core_session_reporting_state(switch_core_session_t *session);
824 SWITCH_DECLARE(void) switch_core_session_hangup_state(switch_core_session_t *session, switch_bool_t force);
825 
826 /*!
827   \brief Provide the total number of sessions
828   \return the total number of allocated sessions
829 */
830 SWITCH_DECLARE(uint32_t) switch_core_session_count(void);
831 
832 SWITCH_DECLARE(switch_size_t) switch_core_session_get_id(_In_ switch_core_session_t *session);
833 
834 /*!
835   \brief Provide the current session_id
836   \return the total number of allocated sessions since core startup
837 */
838 SWITCH_DECLARE(switch_size_t) switch_core_session_id(void);
839 SWITCH_DECLARE(switch_size_t) switch_core_session_id_dec(void);
840 
841 /*!
842   \brief Allocate and return a new session from the core based on a given endpoint module name
843   \param endpoint_name the name of the endpoint module
844   \param pool the pool to use
845   \return the newly created session
846 */
847 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(_In_z_ const char *endpoint_name,
848 																			_In_ switch_call_direction_t direction, _Inout_ switch_memory_pool_t **pool);
849 
850 /*!
851   \brief Launch the session thread (state machine) on a given session
852   \param session the session to activate the state machine on
853   \return SWITCH_STATUS_SUCCESS if the thread was launched
854 */
855 SWITCH_DECLARE(switch_status_t) switch_core_session_thread_launch(_In_ switch_core_session_t *session);
856 
857 
858 SWITCH_DECLARE(switch_status_t) switch_thread_pool_launch_thread(switch_thread_data_t **tdp);
859 SWITCH_DECLARE(switch_status_t) switch_core_session_thread_pool_launch(switch_core_session_t *session);
860 
861 /*!
862   \brief Retrieve a pointer to the channel object associated with a given session
863   \param session the session to retrieve from
864   \return a pointer to the channel object
865 */
866 	 _Ret_ SWITCH_DECLARE(switch_channel_t *) switch_core_session_get_channel(_In_ switch_core_session_t *session);
867 
868 /*!
869   \brief Signal a session's state machine thread that a state change has occured
870 */
871 SWITCH_DECLARE(switch_mutex_t *) switch_core_session_get_mutex(switch_core_session_t *session);
872 SWITCH_DECLARE(switch_status_t) switch_core_session_wake_session_thread(_In_ switch_core_session_t *session);
873 SWITCH_DECLARE(void) switch_core_session_signal_state_change(_In_ switch_core_session_t *session);
874 
875 /*!
876   \brief Retrieve the unique identifier from a session
877   \param session the session to retrieve the uuid from
878   \return a string representing the uuid
879 */
880 SWITCH_DECLARE(char *) switch_core_session_get_uuid(_In_ switch_core_session_t *session);
881 
882 
883 /*!
884   \brief Sets the log level for a session
885   \param session the session to set the log level on
886   \return SWITCH_STATUS_SUCCESS
887 */
888 SWITCH_DECLARE(switch_status_t) switch_core_session_set_loglevel(switch_core_session_t *session, switch_log_level_t loglevel);
889 
890 
891 /*!
892   \brief Get the log level for a session
893   \param session the session to get the log level from
894   \return the log level
895 */
896 SWITCH_DECLARE(switch_log_level_t) switch_core_session_get_loglevel(switch_core_session_t *session);
897 
898 SWITCH_DECLARE(switch_jb_t *) switch_core_session_get_jb(switch_core_session_t *session, switch_media_type_t type);
899 SWITCH_DECLARE(void) switch_core_session_soft_lock(switch_core_session_t *session, uint32_t sec);
900 SWITCH_DECLARE(void) switch_core_session_soft_unlock(switch_core_session_t *session);
901 SWITCH_DECLARE(void) switch_core_session_set_dmachine(switch_core_session_t *session, switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target);
902 SWITCH_DECLARE(switch_ivr_dmachine_t *) switch_core_session_get_dmachine(switch_core_session_t *session, switch_digit_action_target_t target);
903 SWITCH_DECLARE(switch_digit_action_target_t) switch_ivr_dmachine_get_target(switch_ivr_dmachine_t *dmachine);
904 SWITCH_DECLARE(void) switch_ivr_dmachine_set_target(switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target);
905 SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_terminators(switch_ivr_dmachine_t *dmachine, const char *terminators);
906 SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_session_t *session, switch_slin_data_t *data);
907 SWITCH_DECLARE(void) switch_core_session_raw_read(switch_core_session_t *session);
908 
909 /*!
910   \brief Retrieve the unique identifier from the core
911   \return a string representing the uuid
912 */
913 SWITCH_DECLARE(char *) switch_core_get_uuid(void);
914 
915 
916 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(const char *uuid_str, const char *file, const char *func, int line);
917 SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_force_locate(const char *uuid_str, const char *file, const char *func, int line);
918 
919 
920 /*!
921   \brief Locate a session based on it's uuid
922   \param uuid_str the unique id of the session you want to find
923   \return the session or NULL
924   \note if the session was located it will have a read lock obtained which will need to be released with switch_core_session_rwunlock()
925 */
926 
927 #define switch_core_session_locate(uuid_str) switch_core_session_perform_locate(uuid_str, __FILE__, __SWITCH_FUNC__, __LINE__)
928 
929 /*!
930   \brief Locate a session based on it's uuid even if the channel is not ready
931   \param uuid_str the unique id of the session you want to find
932   \return the session or NULL
933   \note if the session was located it will have a read lock obtained which will need to be released with switch_core_session_rwunlock()
934 */
935 
936 #define switch_core_session_force_locate(uuid_str) switch_core_session_perform_force_locate(uuid_str, __FILE__, __SWITCH_FUNC__, __LINE__)
937 
938 
939 /*!
940   \brief Retrieve a global variable from the core
941   \param varname the name of the variable
942   \return the value of the desired variable
943 */
944 SWITCH_DECLARE(char *) switch_core_get_variable(_In_z_ const char *varname);
945 SWITCH_DECLARE(char *) switch_core_get_variable_dup(_In_z_ const char *varname);
946 SWITCH_DECLARE(char *) switch_core_get_variable_pdup(_In_z_ const char *varname, switch_memory_pool_t *pool);
947 SWITCH_DECLARE(const char *) switch_core_get_hostname(void);
948 SWITCH_DECLARE(const char *) switch_core_get_switchname(void);
949 
950 SWITCH_DECLARE(char *) switch_core_get_domain(switch_bool_t dup);
951 
952 /*!
953   \brief Add a global variable to the core
954   \param varname the name of the variable
955   \param value the value of the variable
956   \     If \p value is NULL, then \p varname is deleted.
957 */
958 SWITCH_DECLARE(void) switch_core_set_variable(_In_z_ const char *varname, _In_opt_z_ const char *value);
959 SWITCH_DECLARE(switch_status_t) switch_core_get_variables(switch_event_t **event);
960 
961 /*!
962   \brief Conditionally add a global variable to the core
963   \param varname the name of the variable
964   \param value the value of the variable
965   \param val2 the value of the variable to verify against
966   \     If the global did not exist and val2=="", add global with value, return true
967   \     If the global exists with the value of val2, replace it, return true
968   \     If the global exists with a value other than val2, return false
969 */
970 SWITCH_DECLARE(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);
971 
972 SWITCH_DECLARE(void) switch_core_dump_variables(_In_ switch_stream_handle_t *stream);
973 
974 /*!
975   \brief Hangup all sessions
976   \param cause the hangup cause to apply to the hungup channels
977 */
978 SWITCH_DECLARE(void) switch_core_session_hupall(_In_ switch_call_cause_t cause);
979 
980 typedef enum {
981 	SHT_NONE = 0,
982 	SHT_UNANSWERED = (1 << 0),
983 	SHT_ANSWERED = (1 << 1)
984 } switch_hup_type_t;
985 
986 /*!
987   \brief Hangup all sessions which match a specific channel variable
988   \param var_name The variable name to look for
989   \param var_val The value to look for
990   \param cause the hangup cause to apply to the hungup channels
991 */
992 SWITCH_DECLARE(uint32_t) switch_core_session_hupall_matching_var_ans(_In_ const char *var_name, _In_ const char *var_val, _In_
993 																	 switch_call_cause_t cause, switch_hup_type_t type);
994 SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_matching_var(const char *var_name, const char *var_val);
995 #define switch_core_session_hupall_matching_var(_vn, _vv, _c) switch_core_session_hupall_matching_var_ans(_vn, _vv, _c, SHT_UNANSWERED | SHT_ANSWERED)
996 SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall(void);
997 /*!
998   \brief Hangup all sessions which match specific channel variable(s)
999   \param var_name The variable name to look for
1000   \param var_val The value to look for
1001   \param cause the hangup cause to apply to the hungup channels
1002 */
1003 SWITCH_DECLARE(uint32_t) switch_core_session_hupall_matching_vars_ans(_In_ switch_event_t *vars, _In_
1004 																	 switch_call_cause_t cause, switch_hup_type_t type);
1005 #define switch_core_session_hupall_matching_vars(_vs, _c) switch_core_session_hupall_matching_vars_ans(_vs, _c, SHT_UNANSWERED | SHT_ANSWERED)
1006 
1007 /*!
1008   \brief Hangup all sessions that belong to an endpoint
1009   \param endpoint_interface The endpoint interface
1010   \param cause the hangup cause to apply to the hungup channels
1011 */
1012 SWITCH_DECLARE(void) switch_core_session_hupall_endpoint(const switch_endpoint_interface_t *endpoint_interface, switch_call_cause_t cause);
1013 
1014 /*!
1015   \brief Get the session's partner (the session its bridged to)
1016   \param session The session we're searching with
1017   \param partner [out] The session's partner, or NULL if it wasnt found
1018   \return SWITCH_STATUS_SUCCESS or SWITCH_STATUS_FALSE if this session isn't bridged
1019 */
1020 SWITCH_DECLARE(switch_status_t) switch_core_session_perform_get_partner(switch_core_session_t *session, switch_core_session_t **partner,
1021 																		const char *file, const char *func, int line);
1022 
1023 #define switch_core_session_get_partner(_session, _partner) switch_core_session_perform_get_partner(_session, _partner, __FILE__, __SWITCH_FUNC__, __LINE__)
1024 
1025 /*!
1026   \brief Send a message to another session using it's uuid
1027   \param uuid_str the unique id of the session you want to send a message to
1028   \param message the switch_core_session_message_t object to send
1029   \return the status returned by the message handler
1030 */
1031 SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(_In_z_ const char *uuid_str, _In_ switch_core_session_message_t *message);
1032 
1033 /*!
1034   \brief Queue a message on a session
1035   \param session the session to queue the message to
1036   \param message the message to queue
1037   \return SWITCH_STATUS_SUCCESS if the message was queued
1038 */
1039 SWITCH_DECLARE(switch_status_t) switch_core_session_queue_message(_In_ switch_core_session_t *session, _In_ switch_core_session_message_t *message);
1040 
1041 SWITCH_DECLARE(void) switch_core_session_free_message(switch_core_session_message_t **message);
1042 
1043 
1044 SWITCH_DECLARE(switch_status_t) switch_core_session_queue_signal_data(switch_core_session_t *session, void *signal_data);
1045 SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_signal_data(switch_core_session_t *session, void **signal_data);
1046 
1047 /*!
1048   \brief pass an indication message on a session
1049   \param session the session to pass the message across
1050   \param indication the indication message to pass
1051   \return SWITCH_STATUS_SUCCESS if the message was passed
1052 */
1053 SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(_In_ switch_core_session_t *session,
1054 																	_In_ switch_core_session_message_types_t indication);
1055 
1056 /*!
1057   \brief Queue an indication message on a session
1058   \param session the session to queue the message to
1059   \param indication the indication message to queue
1060   \return SWITCH_STATUS_SUCCESS if the message was queued
1061 */
1062 SWITCH_DECLARE(switch_status_t) switch_core_session_queue_indication(_In_ switch_core_session_t *session,
1063 																	 _In_ switch_core_session_message_types_t indication);
1064 
1065 /*!
1066   \brief DE-Queue an message on a given session
1067   \param session the session to de-queue the message on
1068   \param message the de-queued message
1069   \return SWITCH_STATUS_SUCCESS if the message was de-queued
1070 */
1071 SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_message(_In_ switch_core_session_t *session, _Out_ switch_core_session_message_t **message);
1072 
1073 /*!
1074   \brief Flush a message queue on a given session
1075   \param session the session to de-queue the message on
1076   \return SWITCH_STATUS_SUCCESS if the message was de-queued
1077 */
1078 SWITCH_DECLARE(switch_status_t) switch_core_session_flush_message(_In_ switch_core_session_t *session);
1079 
1080 /*!
1081   \brief Queue an event on another session using its uuid
1082   \param uuid_str the unique id of the session you want to send a message to
1083   \param event the event to send
1084   \return the status returned by the message handler
1085 */
1086 SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(_In_z_ const char *uuid_str, _Inout_ switch_event_t **event);
1087 
1088 SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(_In_ switch_core_session_t *session);
1089 
1090 /*!
1091   \brief Execute an application on a session
1092   \param session the current session
1093   \param application_interface the interface of the application to execute
1094   \param arg application arguments
1095   \warning Has to be called from the session's thread
1096   \return the application's return value
1097 */
1098 SWITCH_DECLARE(switch_status_t) switch_core_session_exec(_In_ switch_core_session_t *session,
1099 														 _In_ const switch_application_interface_t *application_interface, _In_opt_z_ const char *arg);
1100 
1101 SWITCH_DECLARE(void) switch_core_session_video_reset(switch_core_session_t *session);
1102 /*!
1103   \brief Execute an application on a session
1104   \param session the current session
1105   \param app the application's name
1106   \param arg application arguments
1107   \param flags pointer to a flags variable to set the applications flags to
1108   \return the application's return value
1109 */
1110 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flags(_In_ switch_core_session_t *session,
1111 																				  _In_ const char *app, _In_opt_z_ const char *arg, _Out_opt_ int32_t *flags);
1112 
1113 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_async(switch_core_session_t *session, const char *app, const char *arg);
1114 
1115 SWITCH_DECLARE(switch_status_t) switch_core_session_get_app_flags(const char *app, int32_t *flags);
1116 
1117 /*!
1118   \brief Execute an application on a session
1119   \param session the current session
1120   \param app the application's name
1121   \param arg application arguments
1122   \return the application's return value
1123 */
1124 #define switch_core_session_execute_application(_a, _b, _c) switch_core_session_execute_application_get_flags(_a, _b, _c, NULL)
1125 
1126 SWITCH_DECLARE(uint32_t) switch_core_session_stack_count(switch_core_session_t *session, int x);
1127 
1128 /*!
1129   \brief Run a dialplan and execute an extension
1130   \param session the current session
1131   \param exten the interface of the application to execute
1132   \param arg application arguments
1133   \note It does not change the channel back to CS_ROUTING, it manually calls the dialplan and executes the applications
1134   \warning Has to be called from the session's thread
1135   \return the application's return value
1136 */
1137 SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(_In_ switch_core_session_t *session,
1138 																  _In_z_ const char *exten,
1139 																  _In_opt_z_ const char *dialplan, _In_opt_z_ const char *context);
1140 
1141 /*!
1142   \brief Send an event to a session translating it to it's native message format
1143   \param session the session to receive the event
1144   \param event the event to receive
1145   \return the status returned by the handler
1146 */
1147 SWITCH_DECLARE(switch_status_t) switch_core_session_receive_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event);
1148 
1149 /*!
1150   \brief Retrieve private user data from a session
1151   \param session the session to retrieve from
1152   \return a pointer to the private data
1153 */
1154 SWITCH_DECLARE(void *) switch_core_session_get_private_class(_In_ switch_core_session_t *session, _In_ switch_pvt_class_t index);
1155 #define switch_core_session_get_private(_s) switch_core_session_get_private_class(_s, SWITCH_PVT_PRIMARY)
1156 
1157 /*!
1158   \brief Add private user data to a session
1159   \param session the session to add used data to
1160   \param private_info the used data to add
1161   \return SWITCH_STATUS_SUCCESS if data is added
1162 */
1163 SWITCH_DECLARE(switch_status_t) switch_core_session_set_private_class(_In_ switch_core_session_t *session, _In_ void *private_info, _In_ switch_pvt_class_t index);
1164 #define switch_core_session_set_private(_s, _p) switch_core_session_set_private_class(_s, _p, SWITCH_PVT_PRIMARY)
1165 
1166 /*!
1167   \brief Add a logical stream to a session
1168   \param session the session to add the stream to
1169   \param private_info an optional pointer to private data for the new stream
1170   \return the stream id of the new stream
1171 */
1172 SWITCH_DECLARE(int) switch_core_session_add_stream(_In_ switch_core_session_t *session, _In_opt_ void *private_info);
1173 
1174 /*!
1175   \brief Retreive a logical stream from a session
1176   \param session the session to add the stream to
1177   \param index the index to retrieve
1178   \return the stream
1179 */
1180 SWITCH_DECLARE(void *) switch_core_session_get_stream(_In_ switch_core_session_t *session, _In_ int index);
1181 
1182 /*!
1183   \brief Determine the number of logical streams a session has
1184   \param session the session to query
1185   \return the total number of logical streams
1186 */
1187 SWITCH_DECLARE(int) switch_core_session_get_stream_count(_In_ switch_core_session_t *session);
1188 
1189 SWITCH_DECLARE(const char *) switch_core_session_get_text_buffer(switch_core_session_t *session);
1190 
1191 /*!
1192   \brief Launch a thread designed to exist within the scope of a given session
1193   \param session a session to allocate the thread from
1194   \param func a function to execute in the thread
1195   \param obj an arguement
1196 */
1197 SWITCH_DECLARE(void) switch_core_session_launch_thread(_In_ switch_core_session_t *session,
1198 													   _In_ void *(*func) (switch_thread_t *, void *), _In_opt_ void *obj);
1199 
1200 /*!
1201   \brief Signal a thread using a thread session to terminate
1202   \param session the session to indicate to
1203 */
1204 SWITCH_DECLARE(void) switch_core_thread_session_end(_In_ switch_core_session_t *session);
1205 
1206 /*!
1207   \brief Launch a service thread on a session to drop inbound data
1208   \param session the session the launch thread on
1209 */
1210 SWITCH_DECLARE(void) switch_core_service_session_av(_In_ switch_core_session_t *session, switch_bool_t audio, switch_bool_t video);
1211 #define switch_core_service_session(_s) switch_core_service_session_av(_s, SWITCH_TRUE, SWITCH_FALSE)
1212 
1213 
1214 /*!
1215   \brief Request an outgoing session spawned from an existing session using a desired endpoing module
1216   \param session the originating session
1217   \param var_event switch_event_t containing paramaters
1218   \param endpoint_name the name of the module to use for the new session
1219   \param caller_profile the originator's caller profile
1220   \param new_session a NULL pointer to aim at the newly created session
1221   \param pool optional existing memory pool to donate to the session
1222   \param flags flags to use
1223   \return the cause code of the attempted call
1224 */
1225 SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(_In_opt_ switch_core_session_t *session,
1226 																		 _In_opt_ switch_event_t *var_event,
1227 																		 _In_z_ const char *endpoint_name,
1228 																		 _In_ switch_caller_profile_t *caller_profile,
1229 																		 _Inout_ switch_core_session_t **new_session,
1230 																		 _Inout_ switch_memory_pool_t **pool, _In_ switch_originate_flag_t flags,
1231 																		 switch_call_cause_t *cancel_cause);
1232 
1233 /*!
1234   \brief Receive a message on a given session
1235   \param session the session to receive the message from
1236   \param message the message to recieve
1237   \return the status returned by the message handler
1238 */
1239 SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(_In_ switch_core_session_t *session,
1240 																			_In_ switch_core_session_message_t *message,
1241 																			const char *file, const char *func, int line);
1242 #define switch_core_session_receive_message(_session, _message) switch_core_session_perform_receive_message(_session, _message, \
1243 																											__FILE__, __SWITCH_FUNC__, __LINE__)
1244 
1245 /*!
1246   \brief Queue an event on a given session
1247   \param session the session to queue the message on
1248   \param event the event to queue
1249   \return the status returned by the message handler
1250 */
1251 SWITCH_DECLARE(switch_status_t) switch_core_session_queue_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event);
1252 
1253 
1254 /*!
1255   \brief Indicate the number of waiting events on a session
1256   \param session the session to check
1257   \return the number of events
1258 */
1259 SWITCH_DECLARE(uint32_t) switch_core_session_event_count(_In_ switch_core_session_t *session);
1260 
1261 /*
1262   Number of parsable messages waiting on the session.
1263  */
1264 SWITCH_DECLARE(uint32_t) switch_core_session_messages_waiting(switch_core_session_t *session);
1265 
1266 /*!
1267   \brief DE-Queue an event on a given session
1268   \param session the session to de-queue the message on
1269   \param event the de-queued event
1270   \param force force the dequeue
1271   \return the  SWITCH_STATUS_SUCCESS if the event was de-queued
1272 */
1273 SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_event(_In_ switch_core_session_t *session, _Out_ switch_event_t **event, switch_bool_t force);
1274 
1275 /*!
1276   \brief Queue a private event on a given session
1277   \param session the session to queue the message on
1278   \param event the event to queue
1279   \param priority event has high priority
1280   \return the status returned by the message handler
1281 */
1282 SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event,
1283 																		switch_bool_t priority);
1284 
1285 
1286 /*!
1287   \brief Indicate the number of waiting private events on a session
1288   \param session the session to check
1289   \return the number of events
1290 */
1291 SWITCH_DECLARE(uint32_t) switch_core_session_private_event_count(_In_ switch_core_session_t *session);
1292 
1293 /*!
1294   \brief DE-Queue a private event on a given session
1295   \param session the session to de-queue the message on
1296   \param event the de-queued event
1297   \return the  SWITCH_STATUS_SUCCESS if the event was de-queued
1298 */
1299 SWITCH_DECLARE(switch_status_t) switch_core_session_dequeue_private_event(_In_ switch_core_session_t *session, _Out_ switch_event_t **event);
1300 
1301 
1302 /*!
1303   \brief Flush the private event queue of a session
1304   \param session the session to flush
1305   \return SWITCH_STATUS_SUCCESS if the events have been flushed
1306 */
1307 SWITCH_DECLARE(uint32_t) switch_core_session_flush_private_events(switch_core_session_t *session);
1308 
1309 
1310 /*!
1311   \brief Read a frame from a session
1312   \param session the session to read from
1313   \param frame a NULL pointer to a frame to aim at the newly read frame
1314   \param flags I/O flags to modify behavior (i.e. non blocking)
1315   \param stream_id which logical media channel to use
1316   \return SWITCH_STATUS_SUCCESS a the frame was read
1317 */
1318 SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags,
1319 															   int stream_id);
1320 
1321 SWITCH_DECLARE(switch_bool_t) switch_core_session_transcoding(switch_core_session_t *session_a, switch_core_session_t *session_b, switch_media_type_t type);
1322 SWITCH_DECLARE(void) switch_core_session_passthru(switch_core_session_t *session, switch_media_type_t type, switch_bool_t on);
1323 
1324 /*!
1325   \brief Read a video frame from a session
1326   \param session the session to read from
1327   \param frame a NULL pointer to a frame to aim at the newly read frame
1328   \param flags I/O flags to modify behavior (i.e. non blocking)
1329   \param stream_id which logical media channel to use
1330   \return SWITCH_STATUS_SUCCESS a if the frame was read
1331 */
1332 SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags,
1333 																	 int stream_id);
1334 /*!
1335   \brief Write a video frame to a session
1336   \param session the session to write to
1337   \param frame a pointer to a frame to write
1338   \param flags I/O flags to modify behavior (i.e. non blocking)
1339   \param stream_id which logical media channel to use
1340   \return SWITCH_STATUS_SUCCESS a if the frame was written
1341 */
1342 SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags,
1343 																	  int stream_id);
1344 
1345 SWITCH_DECLARE(switch_status_t) switch_core_session_write_encoded_video_frame(switch_core_session_t *session,
1346 																		switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
1347 
1348 SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp);
1349 SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp);
1350 SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp);
1351 SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp);
1352 
1353 /*!
1354   \brief Reset the buffers and resampler on a session
1355   \param session the session to reset
1356   \param flush_dtmf flush all queued dtmf events too
1357 */
1358 SWITCH_DECLARE(void) switch_core_session_reset(_In_ switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec);
1359 
1360 /*!
1361   \brief Write a frame to a session
1362   \param session the session to write to
1363   \param frame the frame to write
1364   \param flags I/O flags to modify behavior (i.e. non blocking)
1365   \param stream_id which logical media channel to use
1366   \return SWITCH_STATUS_SUCCESS a the frame was written
1367 */
1368 SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags,
1369 																int stream_id);
1370 
1371 
1372 SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(_In_ switch_core_session_t *session,
1373 																		 const char *file, const char *func, int line, switch_signal_t sig);
1374 /*!
1375   \brief Send a signal to a channel
1376   \param session session to send signal to
1377   \param sig signal to send
1378   \return status returned by the session's signal handler
1379 */
1380 #define switch_core_session_kill_channel(session, sig) switch_core_session_perform_kill_channel(session, __FILE__, __SWITCH_FUNC__, __LINE__, sig)
1381 
1382 /*!
1383   \brief Send DTMF to a session
1384   \param session session to send DTMF to
1385   \param dtmf dtmf to send to the session
1386   \return SWITCH_STATUS_SUCCESS if the dtmf was written
1387 */
1388 SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf);
1389 /*!
1390   \brief Send DTMF to a session
1391   \param session session to send DTMF to
1392   \param dtmf_string string to send to the session
1393   \return SWITCH_STATUS_SUCCESS if the dtmf was written
1394 */
1395 SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string);
1396 
1397 /*!
1398   \brief RECV DTMF on a session
1399   \param session session to recv DTMF from
1400   \param dtmf string to recv from the session
1401   \return SWITCH_STATUS_SUCCESS if the dtmf is ok to queue
1402 */
1403 SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf);
1404 
1405 ///\}
1406 
1407 
1408 ///\defgroup hashf Hash Functions
1409 ///\ingroup core1
1410 ///\{
1411 /*!
1412   \brief Initialize a hash table
1413   \param hash a NULL pointer to a hash table to aim at the new hash
1414   \param pool the pool to use for the new hash
1415   \return SWITCH_STATUS_SUCCESS if the hash is created
1416 */
1417 SWITCH_DECLARE(switch_status_t) switch_core_hash_init_case(_Out_ switch_hash_t **hash, switch_bool_t case_sensitive);
1418 #define switch_core_hash_init(_hash) switch_core_hash_init_case(_hash, SWITCH_TRUE)
1419 #define switch_core_hash_init_nocase(_hash) switch_core_hash_init_case(_hash, SWITCH_FALSE)
1420 
1421 
1422 /*!
1423   \brief Destroy an existing hash table
1424   \param hash the hash to destroy
1425   \return SWITCH_STATUS_SUCCESS if the hash is destroyed
1426 */
1427 SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(_Inout_ switch_hash_t **hash);
1428 
1429 /*!
1430   \brief Insert data into a hash and set flags so the value is automatically freed on delete
1431   \param hash the hash to add data to
1432   \param key the name of the key to add the data to
1433   \param data the data to add
1434   \return SWITCH_STATUS_SUCCESS if the data is added
1435   \note the string key must be a constant or a dynamic string
1436 */
1437 SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_auto_free(switch_hash_t *hash, const char *key, const void *data);
1438 
1439 /*!
1440   \brief Insert data into a hash
1441   \param hash the hash to add data to
1442   \param key the name of the key to add the data to
1443   \param data the data to add
1444   \return SWITCH_STATUS_SUCCESS if the data is added
1445   \note the string key must be a constant or a dynamic string
1446 */
1447 SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_destructor(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, hashtable_destructor_t destructor);
1448 #define switch_core_hash_insert(_h, _k, _d) switch_core_hash_insert_destructor(_h, _k, _d, NULL)
1449 
1450 
1451 /*!
1452   \brief Insert data into a hash
1453   \param hash the hash to add data to
1454   \param key the name of the key to add the data to
1455   \param data the data to add
1456   \param mutex optional mutex to lock
1457   \return SWITCH_STATUS_SUCCESS if the data is added
1458   \note the string key must be a constant or a dynamic string
1459 */
1460 SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data,
1461 															   _In_opt_ switch_mutex_t *mutex);
1462 /*!
1463   \brief Retrieve data from a given hash
1464   \param hash the hash to retrieve from
1465   \param key the key to retrieve
1466   \param mutex optional rwlock to wrlock
1467   \return a pointer to the data held in the key
1468 */
1469 SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock);
1470 
1471 /*!
1472   \brief Delete data from a hash based on desired key
1473   \param hash the hash to delete from
1474   \param key the key from which to delete the data
1475   \return The value stored if the data is deleted otherwise NULL
1476 */
1477 SWITCH_DECLARE(void *) switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key);
1478 
1479 /*!
1480   \brief Delete data from a hash based on desired key
1481   \param hash the hash to delete from
1482   \param key the key from which to delete the data
1483   \param mutex optional mutex to lock
1484   \return a pointer to the deleted data
1485 */
1486 SWITCH_DECLARE(void *) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex);
1487 
1488 /*!
1489   \brief Delete data from a hash based on desired key
1490   \param hash the hash to delete from
1491   \param key the key from which to delete the data
1492   \param mutex optional rwlock to wrlock
1493   \return a pointer to the deleted data
1494 */
1495 SWITCH_DECLARE(void *) switch_core_hash_delete_wrlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock);
1496 
1497 /*!
1498   \brief Delete data from a hash based on callback function
1499   \param hash the hash to delete from
1500   \param callback the function to call which returns SWITCH_TRUE to delete, SWITCH_FALSE to preserve
1501   \return SWITCH_STATUS_SUCCESS if any data is deleted
1502 */
1503 SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(_In_ switch_hash_t *hash, _In_ switch_hash_delete_callback_t callback, _In_opt_ void *pData);
1504 
1505 /*!
1506   \brief Retrieve data from a given hash
1507   \param hash the hash to retrieve from
1508   \param key the key to retrieve
1509   \return a pointer to the data held in the key
1510 */
1511 SWITCH_DECLARE(void *) switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key);
1512 
1513 
1514 /*!
1515   \brief Retrieve data from a given hash
1516   \param hash the hash to retrieve from
1517   \param key the key to retrieve
1518   \param mutex optional mutex to lock
1519   \return a pointer to the data held in the key
1520 */
1521 SWITCH_DECLARE(void *) switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
1522 
1523 /*!
1524   \brief Retrieve data from a given hash
1525   \param hash the hash to retrieve from
1526   \param key the key to retrieve
1527   \param mutex optional rwlock to rdlock
1528   \return a pointer to the data held in the key
1529 */
1530 SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_thread_rwlock_t *rwlock);
1531 
1532 /*!
1533  \brief Gets the first element of a hashtable
1534  \param deprecate_me [deprecated] NULL
1535  \param hash the hashtable to use
1536  \return The element, or NULL if it wasn't found
1537 */
1538 SWITCH_DECLARE(switch_hash_index_t *) switch_core_hash_first_iter(_In_ switch_hash_t *hash, switch_hash_index_t *hi);
1539 #define switch_core_hash_first(_h) switch_core_hash_first_iter(_h, NULL)
1540 
1541 /*!
1542  \brief tells if a hash is empty
1543  \param hash the hashtable
1544  \return TRUE or FALSE depending on if the hash is empty
1545 */
1546 SWITCH_DECLARE(switch_bool_t) switch_core_hash_empty(switch_hash_t *hash);
1547 
1548 /*!
1549  \brief Gets the next element of a hashtable
1550  \param hi The current element
1551  \return The next element, or NULL if there are no more
1552 */
1553 SWITCH_DECLARE(switch_hash_index_t *) switch_core_hash_next(_In_ switch_hash_index_t **hi);
1554 
1555 /*!
1556  \brief Gets the key and value of the current hash element
1557  \param hi The current element
1558  \param key [out] the key
1559  \param klen [out] the key's size
1560  \param val [out] the value
1561 */
1562 SWITCH_DECLARE(void) switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen)
1563 									  const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val);
1564 
1565 SWITCH_DECLARE(void) switch_core_hash_this_val(switch_hash_index_t *hi, void *val);
1566 
1567 SWITCH_DECLARE(switch_status_t) switch_core_inthash_init(switch_inthash_t **hash);
1568 SWITCH_DECLARE(switch_status_t) switch_core_inthash_destroy(switch_inthash_t **hash);
1569 SWITCH_DECLARE(switch_status_t) switch_core_inthash_insert(switch_inthash_t *hash, uint32_t key, const void *data);
1570 SWITCH_DECLARE(void *) switch_core_inthash_delete(switch_inthash_t *hash, uint32_t key);
1571 SWITCH_DECLARE(void *) switch_core_inthash_find(switch_inthash_t *hash, uint32_t key);
1572 
1573 ///\}
1574 
1575 ///\defgroup timer Timer Functions
1576 ///\ingroup core1
1577 ///\{
1578 /*!
1579   \brief Request a timer handle using given time module
1580   \param timer a timer object to allocate to
1581   \param timer_name the name of the timer module to use
1582   \param interval desired interval
1583   \param samples the number of samples to increment on each cycle
1584   \param pool the memory pool to use for allocation
1585   \return
1586 */
1587 SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples,
1588 													   switch_memory_pool_t *pool);
1589 
1590 SWITCH_DECLARE(void) switch_time_calibrate_clock(void);
1591 
1592 /*!
1593   \brief Wait for one cycle on an existing timer
1594   \param timer the timer to wait on
1595   \return the newest sample count
1596 */
1597 SWITCH_DECLARE(switch_status_t) switch_core_timer_next(switch_timer_t *timer);
1598 
1599 /*!
1600   \brief Step the timer one step
1601   \param timer the timer to wait on
1602   \return the newest sample count
1603 */
1604 SWITCH_DECLARE(switch_status_t) switch_core_timer_step(switch_timer_t *timer);
1605 
1606 SWITCH_DECLARE(switch_status_t) switch_core_timer_sync(switch_timer_t *timer);
1607 
1608 /*!
1609   \brief Check if the current step has been exceeded
1610   \param timer the timer to wait on
1611   \param step increment timer if a tick was detected
1612   \return the newest sample count
1613 */
1614 SWITCH_DECLARE(switch_status_t) switch_core_timer_check(switch_timer_t *timer, switch_bool_t step);
1615 
1616 /*!
1617   \brief Destroy an allocated timer
1618   \param timer timer to destroy
1619   \return SWITCH_STATUS_SUCCESS after destruction
1620 */
1621 SWITCH_DECLARE(switch_status_t) switch_core_timer_destroy(switch_timer_t *timer);
1622 ///\}
1623 
1624 ///\defgroup codecs Codec Functions
1625 ///\ingroup core1
1626 ///\{
1627 /*!
1628   \brief Initialize a codec handle
1629   \param codec the handle to initilize
1630   \param codec_name the name of the codec module to use
1631   \param fmtp codec parameters to send
1632   \param rate the desired rate (0 for any)
1633   \param ms the desired number of milliseconds (0 for any)
1634   \param channels the desired number of channels (0 for any)
1635   \param flags flags to alter behaviour
1636   \param codec_settings desired codec settings
1637   \param pool the memory pool to use
1638   \return SWITCH_STATUS_SUCCESS if the handle is allocated
1639 */
1640 #define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool) \
1641 	switch_core_codec_init_with_bitrate(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, 0, _flags, _codec_settings, _pool)
1642 SWITCH_DECLARE(switch_status_t) switch_core_codec_init_with_bitrate(switch_codec_t *codec,
1643 																	const char *codec_name,
1644 																	const char *fmtp,
1645 																	const char *modname,
1646 																	uint32_t rate,
1647 																	int ms,
1648 																	int channels,
1649 																	uint32_t bitrate,
1650 																	uint32_t flags,
1651 																	const switch_codec_settings_t *codec_settings,
1652 																	switch_memory_pool_t *pool);
1653 
1654 SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec,
1655 													   const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool);
1656 SWITCH_DECLARE(switch_status_t) switch_core_codec_parse_fmtp(const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp);
1657 SWITCH_DECLARE(switch_status_t) switch_core_codec_reset(switch_codec_t *codec);
1658 
1659 /*!
1660   \brief Encode data using a codec handle
1661   \param codec the codec handle to use
1662   \param other_codec the codec handle of the last codec used
1663   \param decoded_data the raw data
1664   \param decoded_data_len then length of the raw buffer
1665   \param decoded_rate the rate of the decoded data
1666   \param encoded_data the buffer to write the encoded data to
1667   \param encoded_data_len the size of the encoded_data buffer
1668   \param encoded_rate the new rate of the encoded data
1669   \param flag flags to exchange
1670   \return SWITCH_STATUS_SUCCESS if the data was encoded
1671   \note encoded_data_len will be rewritten to the in-use size of encoded_data
1672 */
1673 SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
1674 														 switch_codec_t *other_codec,
1675 														 void *decoded_data,
1676 														 uint32_t decoded_data_len,
1677 														 uint32_t decoded_rate,
1678 														 void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag);
1679 
1680 /*!
1681   \brief Decode data using a codec handle
1682   \param codec the codec handle to use
1683   \param other_codec the codec handle of the last codec used
1684   \param encoded_data the buffer to read the encoded data from
1685   \param encoded_data_len the size of the encoded_data buffer
1686   \param encoded_rate the rate of the encoded data
1687   \param decoded_data the raw data buffer
1688   \param decoded_data_len then length of the raw buffer
1689   \param decoded_rate the new rate of the decoded data
1690   \param flag flags to exchange
1691   \return SWITCH_STATUS_SUCCESS if the data was decoded
1692   \note decoded_data_len will be rewritten to the in-use size of decoded_data
1693 */
1694 SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
1695 														 switch_codec_t *other_codec,
1696 														 void *encoded_data,
1697 														 uint32_t encoded_data_len,
1698 														 uint32_t encoded_rate,
1699 														 void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag);
1700 
1701 /*!
1702   \brief Encode video data using a codec handle
1703   \param codec the codec handle to use
1704   \param frame the frame to encode
1705 */
1706 SWITCH_DECLARE(switch_status_t) switch_core_codec_encode_video(switch_codec_t *codec, switch_frame_t *frame);
1707 
1708 
1709 /*!
1710   \brief send control data using a codec handle
1711   \param codec the codec handle to use
1712   \param cmd the command to send
1713   \param ctype the type of the arguement
1714   \param cmd_data a void pointer to the data matching the passed type
1715   \param atype the type of the extra arguement
1716   \param cmd_arg a void pointer to the data matching the passed type
1717   \param rtype the type of the response if any
1718   \param ret_data a void pointer to a pointer of return data
1719   \return SWITCH_STATUS_SUCCESS if the command was received
1720 */
1721 SWITCH_DECLARE(switch_status_t) switch_core_codec_control(switch_codec_t *codec,
1722 														  switch_codec_control_command_t cmd,
1723 														  switch_codec_control_type_t ctype,
1724 														  void *cmd_data,
1725 														  switch_codec_control_type_t atype,
1726 														  void *cmd_arg,
1727 														  switch_codec_control_type_t *rtype,
1728 														  void **ret_data);
1729 
1730 /*!
1731   \brief Decode video data using a codec handle
1732   \param codec the codec handle to use
1733   \param frame the frame to be decoded
1734   \param img the new image in I420 format, allocated by the codec
1735   \param flag flags to exchange
1736   \return SWITCH_STATUS_SUCCESS if the data was decoded, and a non-NULL img
1737 */
1738 SWITCH_DECLARE(switch_status_t) switch_core_codec_decode_video(switch_codec_t *codec, switch_frame_t *frame);
1739 
1740 /*!
1741   \brief Destroy an initalized codec handle
1742   \param codec the codec handle to destroy
1743   \return SWITCH_STATUS_SUCCESS if the codec was destroyed
1744 */
1745 SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec);
1746 
1747 /*!
1748   \brief Assign the read codec to a given session
1749   \param session session to add the codec to
1750   \param codec the codec to add
1751   \return SWITCH_STATUS_SUCCESS if successful
1752 */
1753 SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(_In_ switch_core_session_t *session, switch_codec_t *codec);
1754 
1755 /*!
1756   \brief Assign the original read codec to a given session.  This is the read codec used by an endpoint.
1757   \param session session to add the codec to
1758   \param codec the codec to add
1759   \return SWITCH_STATUS_SUCCESS if successful
1760 */
1761 SWITCH_DECLARE(switch_status_t) switch_core_session_set_real_read_codec(_In_ switch_core_session_t *session, switch_codec_t *codec);
1762 
1763 SWITCH_DECLARE(void) switch_core_session_unset_read_codec(_In_ switch_core_session_t *session);
1764 SWITCH_DECLARE(void) switch_core_session_unset_write_codec(_In_ switch_core_session_t *session);
1765 
1766 
1767 SWITCH_DECLARE(void) switch_core_session_lock_codec_write(_In_ switch_core_session_t *session);
1768 SWITCH_DECLARE(void) switch_core_session_unlock_codec_write(_In_ switch_core_session_t *session);
1769 SWITCH_DECLARE(void) switch_core_session_lock_codec_read(_In_ switch_core_session_t *session);
1770 SWITCH_DECLARE(void) switch_core_session_unlock_codec_read(_In_ switch_core_session_t *session);
1771 
1772 
1773 SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
1774 SWITCH_DECLARE(switch_status_t) switch_core_session_get_real_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
1775 SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
1776 SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
1777 SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
1778 
1779 
1780 /*!
1781   \brief Retrieve the read codec from a given session
1782   \param session session to retrieve from
1783   \return a pointer to the codec
1784 */
1785 SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(_In_ switch_core_session_t *session);
1786 
1787 /*!
1788   \brief Retrieve the effevtive read codec from a given session
1789   \param session session to retrieve from
1790   \return a pointer to the codec
1791 */
1792 SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_read_codec(_In_ switch_core_session_t *session);
1793 
1794 /*!
1795   \brief Assign the write codec to a given session
1796   \param session session to add the codec to
1797   \param codec the codec to add
1798   \return SWITCH_STATUS_SUCCESS if successful
1799 */
1800 SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(_In_ switch_core_session_t *session, switch_codec_t *codec);
1801 
1802 /*!
1803   \brief Retrieve the write codec from a given session
1804   \param session session to retrieve from
1805   \return a pointer to the codec
1806 */
1807 SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(_In_ switch_core_session_t *session);
1808 
1809 /*!
1810   \brief Retrieve the effevtive write codec from a given session
1811   \param session session to retrieve from
1812   \return a pointer to the codec
1813 */
1814 SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_write_codec(_In_ switch_core_session_t *session);
1815 
1816 /*!
1817   \brief Assign the video_read codec to a given session
1818   \param session session to add the codec to
1819   \param codec the codec to add
1820   \return SWITCH_STATUS_SUCCESS if successful
1821 */
1822 SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_codec(_In_ switch_core_session_t *session, switch_codec_t *codec);
1823 
1824 /*!
1825   \brief Retrieve the video_read codec from a given session
1826   \param session session to retrieve from
1827   \return a pointer to the codec
1828 */
1829 SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_read_codec(_In_ switch_core_session_t *session);
1830 
1831 /*!
1832   \brief Assign the video_write codec to a given session
1833   \param session session to add the codec to
1834   \param codec the codec to add
1835   \return SWITCH_STATUS_SUCCESS if successful
1836 */
1837 SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(_In_ switch_core_session_t *session, switch_codec_t *codec);
1838 
1839 /*!
1840   \brief Retrieve the video_write codec from a given session
1841   \param session session to retrieve from
1842   \return a pointer to the codec
1843 */
1844 SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_write_codec(_In_ switch_core_session_t *session);
1845 
1846 ///\}
1847 ///\defgroup db Database Functions
1848 ///\ingroup core1
1849 ///\{
1850 /*!
1851   \brief Open a core db (SQLite) file
1852   \param filename the path to the db file to open
1853   \return the db handle
1854 */
1855 SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(const char *filename);
1856 
1857 /*!
1858   \brief Open a core db (SQLite) in-memory
1859   \param uri to the db to open
1860   \return the db handle
1861 */
1862 SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_in_memory(const char *uri);
1863 
1864 /*!
1865   \brief Execute a sql stmt until it is accepted
1866   \param db the db handle
1867   \param sql the sql to execute
1868   \param retries the number of retries to use
1869   \return SWITCH_STATUS_SUCCESS if successful
1870 
1871 */
1872 SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute(switch_core_db_t *db, char *sql, uint32_t retries);
1873 SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries);
1874 SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries);
1875 
1876 
1877 
1878 /*!
1879   \brief perform a test query then perform a reactive query if the first one fails
1880   \param db the db handle
1881   \param test_sql the test sql
1882   \param drop_sql the drop sql
1883   \param reactive_sql the reactive sql
1884 */
1885 SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *test_sql, char *drop_sql, char *reactive_sql);
1886 
1887 ///\}
1888 
1889 ///\defgroup Media File Functions
1890 ///\ingroup core1
1891 ///\{
1892 
1893 SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line,
1894 															  _In_ switch_file_handle_t *fh,
1895 															  _In_opt_z_ const char *file_path,
1896 															  _In_ uint32_t channels,
1897 															  _In_ uint32_t rate, _In_ unsigned int flags, _In_opt_ switch_memory_pool_t *pool);
1898 
1899 /*!
1900   \brief Open a media file using file format modules
1901   \param _fh a file handle to use
1902   \param _file_path the path to the file
1903   \param _channels the number of channels
1904   \param _rate the sample rate
1905   \param _flags read/write flags
1906   \param _pool the pool to use (NULL for new pool)
1907   \return SWITCH_STATUS_SUCCESS if the file is opened
1908   \note the loadable module used is chosen based on the file extension
1909 */
1910 #define switch_core_file_open(_fh, _file_path, _channels, _rate, _flags, _pool) \
1911 	switch_core_perform_file_open(__FILE__, __SWITCH_FUNC__, __LINE__, _fh, _file_path, _channels, _rate, _flags, _pool)
1912 
1913 /*!
1914   \brief Read media from a file handle
1915   \param fh the file handle to read from (must be initilized by you memset all 0 for read, fill in channels and rate for write)
1916   \param data the buffer to read the data to
1917   \param len the max size of the buffer
1918   \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes read if successful
1919 */
1920 SWITCH_DECLARE(switch_status_t) switch_core_file_read(_In_ switch_file_handle_t *fh, void *data, switch_size_t *len);
1921 
1922 /*!
1923   \brief Write media to a file handle
1924   \param fh the file handle to write to
1925   \param data the buffer to write
1926   \param len the amount of data to write from the buffer
1927   \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
1928 */
1929 SWITCH_DECLARE(switch_status_t) switch_core_file_write(_In_ switch_file_handle_t *fh, void *data, switch_size_t *len);
1930 
1931 /*!
1932   \brief Write media to a file handle
1933   \param fh the file handle to write to
1934   \param data the buffer to write
1935   \param len the amount of data to write from the buffer
1936   \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
1937 */
1938 SWITCH_DECLARE(switch_status_t) switch_core_file_write_video(_In_ switch_file_handle_t *fh, switch_frame_t *frame);
1939 SWITCH_DECLARE(switch_status_t) switch_core_file_read_video(switch_file_handle_t *fh, switch_frame_t *frame, switch_video_read_flag_t flags);
1940 
1941 /*!
1942   \brief Seek a position in a file
1943   \param fh the file handle to seek
1944   \param cur_pos the current position in the file
1945   \param samples the amount of samples to seek from the beginning of the file
1946   \param whence the indicator (see traditional seek)
1947   \return SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position
1948 */
1949 SWITCH_DECLARE(switch_status_t) switch_core_file_seek(_In_ switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence);
1950 
1951 /*!
1952   \brief Set metadata to the desired string
1953   \param fh the file handle to set data to
1954   \param col the enum of the col name
1955   \param string the string to add
1956   \return SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position
1957 */
1958 SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(_In_ switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
1959 
1960 /*!
1961   \brief get metadata of the desired string
1962   \param fh the file handle to get data from
1963   \param col the enum of the col name
1964   \param string pointer to the string to fetch
1965   \return SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position
1966 */
1967 SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(_In_ switch_file_handle_t *fh, switch_audio_col_t col, const char **string);
1968 
1969 /*!
1970   \brief Pre close an open file handle, then can get file size etc., no more wirte to the file
1971   \param fh the file handle to close
1972   \return SWITCH_STATUS_SUCCESS if the file handle was pre closed
1973 */
1974 SWITCH_DECLARE(switch_status_t) switch_core_file_pre_close(_In_ switch_file_handle_t *fh);
1975 
1976 /*!
1977   \brief Close an open file handle
1978   \param fh the file handle to close
1979   \return SWITCH_STATUS_SUCCESS if the file handle was closed
1980 */
1981 SWITCH_DECLARE(switch_status_t) switch_core_file_close(_In_ switch_file_handle_t *fh);
1982 
1983 SWITCH_DECLARE(switch_status_t) switch_core_file_command(switch_file_handle_t *fh, switch_file_command_t command);
1984 
1985 SWITCH_DECLARE(switch_status_t) switch_core_file_truncate(switch_file_handle_t *fh, int64_t offset);
1986 SWITCH_DECLARE(switch_bool_t) switch_core_file_has_video(switch_file_handle_t *fh, switch_bool_t CHECK_OPEN);
1987 
1988 
1989 ///\}
1990 
1991 ///\defgroup speech ASR/TTS Functions
1992 ///\ingroup core1
1993 ///\{
1994 /*!
1995   \brief Open a speech handle
1996   \param sh a speech handle to use
1997   \param module_name the speech module to use
1998   \param voice_name the desired voice name
1999   \param rate the sampling rate
2000   \param interval the sampling interval
2001   \param flags tts flags
2002   \param pool the pool to use (NULL for new pool)
2003   \return SWITCH_STATUS_SUCCESS if the handle is opened
2004 */
2005 SWITCH_DECLARE(switch_status_t) switch_core_speech_open(_In_ switch_speech_handle_t *sh,
2006 														const char *module_name,
2007 														const char *voice_name,
2008 														_In_ unsigned int rate,
2009 														_In_ unsigned int interval,
2010 														_In_ unsigned int channels,
2011 														switch_speech_flag_t *flags, _In_opt_ switch_memory_pool_t *pool);
2012 /*!
2013   \brief Feed text to the TTS module
2014   \param sh the speech handle to feed
2015   \param text the buffer to write
2016   \param flags flags in/out for fine tuning
2017   \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
2018 */
2019 SWITCH_DECLARE(switch_status_t) switch_core_speech_feed_tts(switch_speech_handle_t *sh, const char *text, switch_speech_flag_t *flags);
2020 
2021 /*!
2022   \brief Flush TTS audio on a given handle
2023   \param sh the speech handle
2024 */
2025 SWITCH_DECLARE(void) switch_core_speech_flush_tts(switch_speech_handle_t *sh);
2026 
2027 /*!
2028   \brief Set a text parameter on a TTS handle
2029   \param sh the speech handle
2030   \param param the parameter
2031   \param val the value
2032 */
2033 SWITCH_DECLARE(void) switch_core_speech_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val);
2034 
2035 /*!
2036   \brief Set a numeric parameter on a TTS handle
2037   \param sh the speech handle
2038   \param param the parameter
2039   \param val the value
2040 */
2041 SWITCH_DECLARE(void) switch_core_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val);
2042 
2043 /*!
2044   \brief Set a float parameter on a TTS handle
2045   \param sh the speech handle
2046   \param param the parameter
2047   \param val the value
2048 */
2049 SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val);
2050 
2051 /*!
2052   \brief Read rendered audio from the TTS module
2053   \param sh the speech handle to read
2054   \param data the buffer to read to
2055   \param datalen the max size / written size of the data
2056   \param rate the rate of the read audio
2057   \param flags flags in/out for fine tuning
2058   \return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
2059 */
2060 SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh, void *data, switch_size_t *datalen, switch_speech_flag_t *flags);
2061 /*!
2062   \brief Close an open speech handle
2063   \param sh the speech handle to close
2064   \param flags flags in/out for fine tuning
2065   \return SWITCH_STATUS_SUCCESS if the file handle was closed
2066 */
2067 SWITCH_DECLARE(switch_status_t) switch_core_speech_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags);
2068 
2069 
2070 /*!
2071   \brief Open an asr handle
2072   \param ah the asr handle to open
2073   \param module_name the name of the asr module
2074   \param codec the preferred codec
2075   \param rate the preferred rate
2076   \param dest the destination address
2077   \param flags flags to influence behaviour
2078   \param pool the pool to use (NULL for new pool)
2079   \return SWITCH_STATUS_SUCCESS if the asr handle was opened
2080 */
2081 SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
2082 													 const char *module_name,
2083 													 const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool);
2084 
2085 /*!
2086   \brief Close an asr handle
2087   \param ah the handle to close
2088   \param flags flags to influence behaviour
2089   \return SWITCH_STATUS_SUCCESS
2090 */
2091 SWITCH_DECLARE(switch_status_t) switch_core_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags);
2092 
2093 /*!
2094   \brief Feed audio data to an asr handle
2095   \param ah the handle to feed data to
2096   \param data a pointer to the data
2097   \param len the size in bytes of the data
2098   \param flags flags to influence behaviour
2099   \return SWITCH_STATUS_SUCCESS
2100 */
2101 SWITCH_DECLARE(switch_status_t) switch_core_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags);
2102 
2103 /*!
2104   \brief Feed DTMF to an asr handle
2105   \param ah the handle to feed data to
2106   \param dtmf a string of DTMF digits
2107   \param flags flags to influence behaviour
2108   \return SWITCH_STATUS_SUCCESS
2109 */
2110 SWITCH_DECLARE(switch_status_t) switch_core_asr_feed_dtmf(switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags);
2111 
2112 /*!
2113   \brief Check an asr handle for results
2114   \param ah the handle to check
2115   \param flags flags to influence behaviour
2116   \return SWITCH_STATUS_SUCCESS
2117 */
2118 SWITCH_DECLARE(switch_status_t) switch_core_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags);
2119 
2120 /*!
2121   \brief Get results from an asr handle
2122   \param ah the handle to get results from
2123   \param xmlstr a pointer to dynamically allocate an xml result string to
2124   \param flags flags to influence behaviour
2125   \return SWITCH_STATUS_SUCCESS
2126 */
2127 SWITCH_DECLARE(switch_status_t) switch_core_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags);
2128 
2129 /*!
2130   \brief Get result headers from an asr handle
2131   \param ah the handle to get results from
2132   \param headers a pointer to dynamically allocate an switch_event_t result to
2133   \param flags flags to influence behaviour
2134   \return SWITCH_STATUS_SUCCESS
2135 */
2136 SWITCH_DECLARE(switch_status_t) switch_core_asr_get_result_headers(switch_asr_handle_t *ah, switch_event_t **headers, switch_asr_flag_t *flags);
2137 
2138 /*!
2139   \brief Load a grammar to an asr handle
2140   \param ah the handle to load to
2141   \param grammar the grammar text, file path, or URI
2142   \param name the grammar name
2143   \return SWITCH_STATUS_SUCCESS
2144 */
2145 SWITCH_DECLARE(switch_status_t) switch_core_asr_load_grammar(switch_asr_handle_t *ah, const char *grammar, const char *name);
2146 
2147 /*!
2148   \brief Unload a grammar from an asr handle
2149   \param ah the handle to unload the grammar from
2150   \param name the name of the grammar to unload
2151   \return SWITCH_STATUS_SUCCESS
2152 */
2153 SWITCH_DECLARE(switch_status_t) switch_core_asr_unload_grammar(switch_asr_handle_t *ah, const char *name);
2154 
2155 /*!
2156   \brief Enable a grammar from an asr handle
2157   \param ah the handle to enable the grammar from
2158   \param name the name of the grammar to enable
2159   \return SWITCH_STATUS_SUCCESS
2160 */
2161 SWITCH_DECLARE(switch_status_t) switch_core_asr_enable_grammar(switch_asr_handle_t *ah, const char *name);
2162 
2163 /*!
2164   \brief Disable a grammar from an asr handle
2165   \param ah the handle to disable the grammar from
2166   \param name the name of the grammar to disable
2167   \return SWITCH_STATUS_SUCCESS
2168 */
2169 SWITCH_DECLARE(switch_status_t) switch_core_asr_disable_grammar(switch_asr_handle_t *ah, const char *name);
2170 
2171 /*!
2172   \brief Disable all grammars from an asr handle
2173   \param ah the handle to disable the grammars from
2174   \return SWITCH_STATUS_SUCCESS
2175 */
2176 SWITCH_DECLARE(switch_status_t) switch_core_asr_disable_all_grammars(switch_asr_handle_t *ah);
2177 
2178 /*!
2179   \brief Pause detection on an asr handle
2180   \param ah the handle to pause
2181   \return SWITCH_STATUS_SUCCESS
2182 */
2183 SWITCH_DECLARE(switch_status_t) switch_core_asr_pause(switch_asr_handle_t *ah);
2184 
2185 /*!
2186   \brief Resume detection on an asr handle
2187   \param ah the handle to resume
2188   \return SWITCH_STATUS_SUCCESS
2189 */
2190 SWITCH_DECLARE(switch_status_t) switch_core_asr_resume(switch_asr_handle_t *ah);
2191 
2192 /*!
2193   \brief Start input timers on an asr handle
2194   \param ah the handle to start timers on
2195   \return SWITCH_STATUS_SUCCESS
2196 */
2197 SWITCH_DECLARE(switch_status_t) switch_core_asr_start_input_timers(switch_asr_handle_t *ah);
2198 
2199 /*!
2200   \brief Set a text parameter on an asr handle
2201   \param sh the asr handle
2202   \param param the parameter
2203   \param val the value
2204 */
2205 SWITCH_DECLARE(void) switch_core_asr_text_param(switch_asr_handle_t *ah, char *param, const char *val);
2206 
2207 /*!
2208   \brief Set a numeric parameter on an asr handle
2209   \param sh the asr handle
2210   \param param the parameter
2211   \param val the value
2212 */
2213 SWITCH_DECLARE(void) switch_core_asr_numeric_param(switch_asr_handle_t *ah, char *param, int val);
2214 
2215 /*!
2216   \brief Set a float parameter on an asr handle
2217   \param sh the asr handle
2218   \param param the parameter
2219   \param val the value
2220 */
2221 SWITCH_DECLARE(void) switch_core_asr_float_param(switch_asr_handle_t *ah, char *param, double val);
2222 
2223 ///\}
2224 
2225 
2226 ///\defgroup dir Directory Service Functions
2227 ///\ingroup core1
2228 ///\{
2229 /*!
2230   \brief Open a directory handle
2231   \param dh a directory handle to use
2232   \param module_name the directory module to use
2233   \param source the source of the db (ip, hostname, path etc)
2234   \param dsn the username or designation of the lookup
2235   \param passwd the password
2236   \param pool the pool to use (NULL for new pool)
2237   \return SWITCH_STATUS_SUCCESS if the handle is opened
2238 */
2239 SWITCH_DECLARE(switch_status_t) switch_core_directory_open(switch_directory_handle_t *dh,
2240 														   char *module_name, char *source, char *dsn, char *passwd, switch_memory_pool_t *pool);
2241 
2242 /*!
2243   \brief Query a directory handle
2244   \param dh a directory handle to use
2245   \param base the base to query against
2246   \param query a string of filters or query data
2247   \return SWITCH_STATUS_SUCCESS if the query is successful
2248 */
2249 SWITCH_DECLARE(switch_status_t) switch_core_directory_query(switch_directory_handle_t *dh, char *base, char *query);
2250 
2251 /*!
2252   \brief Obtain the next record in a lookup
2253   \param dh a directory handle to use
2254   \return SWITCH_STATUS_SUCCESS if another record exists
2255 */
2256 SWITCH_DECLARE(switch_status_t) switch_core_directory_next(switch_directory_handle_t *dh);
2257 
2258 /*!
2259   \brief Obtain the next name/value pair in the current record
2260   \param dh a directory handle to use
2261   \param var a pointer to pointer of the name to fill in
2262   \param val a pointer to pointer of the value to fill in
2263   \return SWITCH_STATUS_SUCCESS if an item exists
2264 */
2265 SWITCH_DECLARE(switch_status_t) switch_core_directory_next_pair(switch_directory_handle_t *dh, char **var, char **val);
2266 
2267 /*!
2268   \brief Close an open directory handle
2269   \param dh a directory handle to close
2270   \return SWITCH_STATUS_SUCCESS if handle was closed
2271 */
2272 SWITCH_DECLARE(switch_status_t) switch_core_directory_close(switch_directory_handle_t *dh);
2273 ///\}
2274 
2275 
2276 ///\defgroup misc Misc
2277 ///\ingroup core1
2278 ///\{
2279 /*!
2280   \brief Retrieve a FILE stream of a given text channel name
2281   \param channel text channel enumeration
2282   \return a FILE stream
2283 */
2284 SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel_t channel);
2285 
2286 /*!
2287   \brief Determines if the core is ready to take calls
2288   \return SWITCH_TRUE or SWITCH_FALSE
2289 */
2290 SWITCH_DECLARE(switch_bool_t) switch_core_ready(void);
2291 
2292 SWITCH_DECLARE(switch_bool_t) switch_core_running(void);
2293 
2294 /*!
2295   \brief Determines if the core is ready to take inbound calls
2296   \return SWITCH_TRUE or SWITCH_FALSE
2297 */
2298 SWITCH_DECLARE(switch_bool_t) switch_core_ready_inbound(void);
2299 
2300 /*!
2301   \brief Determines if the core is ready to place outbound calls
2302   \return SWITCH_TRUE or SWITCH_FALSE
2303 */
2304 SWITCH_DECLARE(switch_bool_t) switch_core_ready_outbound(void);
2305 
2306 /*!
2307   \brief return core flags
2308   \return core flags
2309 */
2310 SWITCH_DECLARE(switch_core_flag_t) switch_core_flags(void);
2311 
2312 /*!
2313   \brief Execute a management operation.
2314   \param relative_oid the relative oid of the operation.
2315   \param action the action to perform.
2316   \param data input/output string.
2317   \param datalen size in bytes of data.
2318   \return SUCCESS on sucess.
2319 */
2320 SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen);
2321 
2322 /*!
2323   \brief Switch on the privilege awareness for the process and request required privileges
2324   \return 0 on success
2325 */
2326 
2327 SWITCH_DECLARE(int32_t) switch_core_set_process_privileges(void);
2328 
2329 /*!
2330   \brief Set the maximum priority the process can obtain
2331   \return 0 on success
2332 */
2333 
2334 SWITCH_DECLARE(int32_t) set_normal_priority(void);
2335 SWITCH_DECLARE(int32_t) set_auto_priority(void);
2336 SWITCH_DECLARE(int32_t) set_realtime_priority(void);
2337 SWITCH_DECLARE(int32_t) set_low_priority(void);
2338 
2339 /*!
2340   \brief Change user and/or group of the running process
2341   \param user name of the user to switch to (or NULL)
2342   \param group name of the group to switch to (or NULL)
2343   \return 0 on success, -1 otherwise
2344 
2345   Several possible combinations:
2346   - user only (group NULL): switch to user and his primary group (and supplementary groups, if supported)
2347   - user and group: switch to user and specified group (only)
2348   - group only (user NULL): switch group only
2349 */
2350 SWITCH_DECLARE(int32_t) change_user_group(const char *user, const char *group);
2351 
2352 /*!
2353   \brief Run endlessly until the system is shutdown
2354   \param bg divert console to the background
2355 */
2356 SWITCH_DECLARE(void) switch_core_runtime_loop(int bg);
2357 
2358 /*!
2359   \brief Set the output console to the desired file
2360   \param console the file path
2361 */
2362 SWITCH_DECLARE(switch_status_t) switch_core_set_console(const char *console);
2363 
2364 /*!
2365   \brief Breakdown a number of milliseconds into various time spec
2366   \param total_ms a number of milliseconds
2367   \param duration an object to store the results
2368 */
2369 SWITCH_DECLARE(void) switch_core_measure_time(switch_time_t total_ms, switch_core_time_duration_t *duration);
2370 
2371 /*!
2372   \brief Number of microseconds the system has been up
2373   \return a number of microseconds
2374 */
2375 SWITCH_DECLARE(switch_time_t) switch_core_uptime(void);
2376 
2377 /*!
2378   \brief send a control message to the core
2379   \param cmd the command
2380   \param val the command arguement (if needed)
2381   \return 0 on success nonzero on error
2382 */
2383 SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *val);
2384 
2385 /*!
2386   \brief Get the output console
2387   \return the FILE stream
2388 */
2389 SWITCH_DECLARE(FILE *) switch_core_get_console(void);
2390 
2391 #ifndef SWIG
2392 /*!
2393   \brief Launch a thread
2394 */
2395 SWITCH_DECLARE(switch_thread_t *) switch_core_launch_thread(void *(SWITCH_THREAD_FUNC * func) (switch_thread_t *, void *),
2396 															void *obj, switch_memory_pool_t *pool);
2397 #endif
2398 
2399 /*!
2400   \brief Initiate Globals
2401 */
2402 SWITCH_DECLARE(void) switch_core_set_globals(void);
2403 
2404 /*!
2405   \brief Checks if 2 sessions are using the same endpoint module
2406   \param a the first session
2407   \param b the second session
2408   \return TRUE or FALSE
2409 */
2410 SWITCH_DECLARE(uint8_t) switch_core_session_compare(switch_core_session_t *a, switch_core_session_t *b);
2411 /*!
2412   \brief Checks if a session is using a specific endpoint
2413   \param session the session
2414   \param endpoint_interface interface of the endpoint to check
2415   \return TRUE or FALSE
2416 */
2417 SWITCH_DECLARE(uint8_t) switch_core_session_check_interface(switch_core_session_t *session, const switch_endpoint_interface_t *endpoint_interface);
2418 
2419 SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_callback(switch_core_session_t *session,
2420 																			switch_core_video_thread_callback_func_t func, void *user_data);
2421 
2422 SWITCH_DECLARE(switch_status_t) switch_core_session_video_read_callback(switch_core_session_t *session, switch_frame_t *frame);
2423 
2424 SWITCH_DECLARE(switch_hash_index_t *) switch_core_mime_index(void);
2425 SWITCH_DECLARE(const char *) switch_core_mime_ext2type(const char *ext);
2426 SWITCH_DECLARE(const char *) switch_core_mime_type2ext(const char *type);
2427 SWITCH_DECLARE(switch_status_t) switch_core_mime_add_type(const char *type, const char *ext);
2428 
2429 SWITCH_DECLARE(switch_loadable_module_interface_t *) switch_loadable_module_create_module_interface(switch_memory_pool_t *pool, const char *name);
2430 SWITCH_DECLARE(void *) switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname);
2431 /*!
2432  \brief Get the current epoch time in microseconds
2433  \return the current epoch time in microseconds
2434 */
2435 SWITCH_DECLARE(switch_time_t) switch_micro_time_now(void);
2436 SWITCH_DECLARE(switch_time_t) switch_mono_micro_time_now(void);
2437 SWITCH_DECLARE(void) switch_core_memory_reclaim(void);
2438 SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void);
2439 SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void);
2440 SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void);
2441 SWITCH_DECLARE(void) switch_core_setrlimits(void);
2442 SWITCH_DECLARE(switch_time_t) switch_time_ref(void);
2443 SWITCH_DECLARE(void) switch_time_sync(void);
2444 /*!
2445  \brief Get the current epoch time
2446  \param [out] (optional) The current epoch time
2447  \return The current epoch time
2448 */
2449 SWITCH_DECLARE(time_t) switch_epoch_time_now(time_t *t);
2450 SWITCH_DECLARE(const char *) switch_lookup_timezone(const char *tz_name);
2451 SWITCH_DECLARE(switch_status_t) switch_strftime_tz(const char *tz, const char *format, char *date, size_t len, switch_time_t thetime);
2452 SWITCH_DECLARE(switch_status_t) switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime);
2453 SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload);
2454 SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip_port_token(const char *ip_str, int port, const char *list_name, const char **token);
2455 SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip_token(const char *ip_str, const char *list_name, const char **token);
2456 #define switch_check_network_list_ip(_ip_str, _list_name) switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
2457 SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable);
2458 SWITCH_DECLARE(void) switch_time_set_timerfd(int enable);
2459 SWITCH_DECLARE(void) switch_time_set_nanosleep(switch_bool_t enable);
2460 SWITCH_DECLARE(void) switch_time_set_matrix(switch_bool_t enable);
2461 SWITCH_DECLARE(void) switch_time_set_cond_yield(switch_bool_t enable);
2462 SWITCH_DECLARE(void) switch_time_set_use_system_time(switch_bool_t enable);
2463 SWITCH_DECLARE(uint32_t) switch_core_min_dtmf_duration(uint32_t duration);
2464 SWITCH_DECLARE(uint32_t) switch_core_max_dtmf_duration(uint32_t duration);
2465 SWITCH_DECLARE(double) switch_core_min_idle_cpu(double new_limit);
2466 SWITCH_DECLARE(double) switch_core_idle_cpu(void);
2467 SWITCH_DECLARE(uint32_t) switch_core_default_dtmf_duration(uint32_t duration);
2468 SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string);
2469 SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string);
2470 SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait);
2471 SWITCH_DECLARE(int) switch_stream_system(const char *cmd, switch_stream_handle_t *stream);
2472 SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t);
2473 SWITCH_DECLARE(void) switch_cond_next(void);
2474 SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_proto, const char *proto, const char *from, const char *to,
2475 														   const char *subject, const char *body, const char *type, const char *hint, switch_bool_t blocking);
2476 SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *dest_proto, switch_event_t *message_event);
2477 SWITCH_DECLARE(switch_status_t) switch_core_chat_deliver(const char *dest_proto, switch_event_t **message_event);
2478 
2479 SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_session_t *session, const char *cmds);
2480 SWITCH_DECLARE(void) switch_core_sqldb_pause(void);
2481 SWITCH_DECLARE(void) switch_core_sqldb_resume(void);
2482 
2483 
2484 ///\}
2485 
2486 /*!
2487   \}
2488 */
2489 
2490 typedef int (*switch_core_db_event_callback_func_t) (void *pArg, switch_event_t *event);
2491 
2492 #define CACHE_DB_LEN 256
2493 typedef enum {
2494 	CDF_INUSE = (1 << 0),
2495 	CDF_PRUNE = (1 << 1),
2496 	CDF_NONEXPIRING = (1 << 2)
2497 } cache_db_flag_t;
2498 
2499 typedef enum {
2500 	SCDB_TYPE_CORE_DB,
2501 	SCDB_TYPE_ODBC,
2502 	SCDB_TYPE_DATABASE_INTERFACE
2503 } switch_cache_db_handle_type_t;
2504 
2505 typedef union {
2506 	switch_coredb_handle_t *core_db_dbh;
2507 	switch_odbc_handle_t *odbc_dbh;
2508 	switch_database_interface_handle_t *database_interface_dbh;
2509 } switch_cache_db_native_handle_t;
2510 
2511 typedef struct {
2512 	char *db_path;
2513 	switch_bool_t in_memory;
2514 } switch_cache_db_core_db_options_t;
2515 
2516 typedef struct {
2517 	char *dsn;
2518 	char *user;
2519 	char *pass;
2520 } switch_cache_db_odbc_options_t;
2521 
2522 typedef struct {
2523 	const char *original_dsn;
2524 	char *connection_string;
2525 	char prefix[16];
2526 	switch_database_interface_t *database_interface;
2527 	switch_bool_t make_module_no_unloadable;
2528 } switch_cache_db_database_interface_options_t;
2529 
2530 typedef union {
2531 	switch_cache_db_core_db_options_t core_db_options;
2532 	switch_cache_db_odbc_options_t odbc_options;
2533 	switch_cache_db_database_interface_options_t database_interface_options;
2534 } switch_cache_db_connection_options_t;
2535 
2536 struct switch_cache_db_handle;
2537 typedef struct switch_cache_db_handle switch_cache_db_handle_t;
2538 
switch_cache_db_type_name(switch_cache_db_handle_type_t type)2539 static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
2540 {
2541 	const char *type_str = "INVALID";
2542 
2543 	switch (type) {
2544 	case SCDB_TYPE_DATABASE_INTERFACE:
2545 		{
2546 			type_str = "DATABASE_INTERFACE";
2547 		}
2548 		break;
2549 	case SCDB_TYPE_ODBC:
2550 		{
2551 			type_str = "ODBC";
2552 		}
2553 		break;
2554 	case SCDB_TYPE_CORE_DB:
2555 		{
2556 			type_str = "CORE_DB";
2557 		}
2558 		break;
2559 	}
2560 
2561 	return type_str;
2562 }
2563 
2564 SWITCH_DECLARE(switch_cache_db_handle_type_t) switch_cache_db_get_type(switch_cache_db_handle_t *dbh);
2565 
2566 /*!
2567  \brief Returns the handle to the pool, immediately available for other
2568  		threads to use.
2569  \param [in] The handle
2570 */
2571 SWITCH_DECLARE(void) switch_cache_db_dismiss_db_handle(switch_cache_db_handle_t ** dbh);
2572 /*!
2573  \brief Returns the handle to the pool, handle is NOT available to
2574  		other threads until the allocating thread actually terminates.
2575  \param [in] The handle
2576 */
2577 SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t ** dbh);
2578 /*!
2579  \brief Gets a new cached handle from the pool, potentially creating a new connection.
2580  		The connection is bound to the thread until it (the thread) terminates unless
2581  		you dismiss rather than release.
2582  \param [out] dbh The handle
2583  \param [in] type - ODBC or SQLLITE
2584  \param [in] connection_options (userid, password, etc)
2585 */
2586 SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t ** dbh,
2587 															   switch_cache_db_handle_type_t type,
2588 															   switch_cache_db_connection_options_t *connection_options,
2589 															   const char *file, const char *func, int line);
2590 #define switch_cache_db_get_db_handle(_a, _b, _c) _switch_cache_db_get_db_handle(_a, _b, _c, __FILE__, __SWITCH_FUNC__, __LINE__)
2591 
2592 SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn_ex(switch_cache_db_handle_t **dbh, const char *dsn, switch_bool_t make_module_no_unloadable,
2593 																	  const char *file, const char *func, int line);
2594 SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn(switch_cache_db_handle_t **dbh, const char *dsn,
2595 																   const char *file, const char *func, int line);
2596 #define switch_cache_db_get_db_handle_dsn(_a, _b) _switch_cache_db_get_db_handle_dsn(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)
2597 
2598 /*!
2599  \brief Executes the create schema sql
2600  \param [in] dbh The handle
2601  \param [in] sql - sql to run
2602  \param [out] err - Error if it exists
2603 */
2604 SWITCH_DECLARE(switch_status_t) switch_cache_db_create_schema(switch_cache_db_handle_t *dbh, char *sql, char **err);
2605 /*!
2606  \brief Executes the sql and returns the result as a string
2607  \param [in] dbh The handle
2608  \param [in] sql - sql to run
2609  \param [out] str - buffer for result
2610  \param [in] len - length of str buffer
2611  \param [out] err - Error if it exists
2612 */
2613 SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err);
2614 /*!
2615  \brief Executes the sql
2616  \param [in] dbh The handle
2617  \param [in] sql - sql to run
2618  \param [out] err - Error if it exists
2619 */
2620 SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err);
2621 /*!
2622  \brief Executes the sql and uses callback for row-by-row processing
2623  \param [in] dbh The handle
2624  \param [in] sql - sql to run
2625  \param [in] callback - function pointer to callback
2626  \param [in] pdata - data to pass to callback
2627  \param [out] err - Error if it exists
2628 */
2629 SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql,
2630 																	 switch_core_db_callback_func_t callback, void *pdata, char **err);
2631 
2632 /*!
2633  \brief Executes the sql and uses callback for row-by-row processing
2634  \param [in] dbh The handle
2635  \param [in] sql - sql to run
2636  \param [in] callback - function pointer to callback
2637  \param [in] err_callback - function pointer to callback when error occurs
2638  \param [in] pdata - data to pass to callback
2639  \param [out] err - Error if it exists
2640 */
2641 SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback_err(switch_cache_db_handle_t *dbh, const char *sql,
2642 																	 switch_core_db_callback_func_t callback,
2643 																	 switch_core_db_err_callback_func_t err_callback,
2644 																	 void *pdata, char **err);
2645 
2646 /*!
2647  \brief Get the affected rows of the last performed query
2648  \param [in] dbh The handle
2649  \param [out] the number of affected rows
2650 */
2651 SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh);
2652 
2653 /*!
2654  \brief load an external extension to db
2655  \param [in] dbh The handle
2656  \param [out] the path to the extension
2657 */
2658 SWITCH_DECLARE(int) switch_cache_db_load_extension(switch_cache_db_handle_t *dbh, const char *extension);
2659 
2660 /*!
2661  \brief Provides some feedback as to the status of the db connection pool
2662  \param [in] stream stream for status
2663 */
2664 SWITCH_DECLARE(void) switch_cache_db_status(switch_stream_handle_t *stream);
2665 SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t ** dbh, const char *file, const char *func, int line);
2666 #define switch_core_db_handle(_a) _switch_core_db_handle(_a, __FILE__, __SWITCH_FUNC__, __LINE__)
2667 
2668 SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *db,
2669 															const char *test_sql, const char *drop_sql, const char *reactive_sql);
2670 SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive_ex(switch_cache_db_handle_t *db,
2671 															const char *test_sql, const char *drop_sql, const char *reactive_sql, const char *row_size_limited_reactive_sql);
2672 SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries);
2673 SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries,
2674 																			  const char *pre_trans_execute,
2675 																			  const char *post_trans_execute,
2676 																			  const char *inner_pre_trans_execute,
2677 																			  const char *inner_post_trans_execute);
2678 #define switch_cache_db_persistant_execute_trans(_d, _s, _r) switch_cache_db_persistant_execute_trans_full(_d, _s, _r, NULL, NULL, NULL, NULL)
2679 
2680 SWITCH_DECLARE(void) switch_cache_db_database_interface_flush_handles(switch_database_interface_t *database_interface);
2681 
2682 /*!
2683 \brief Returns error if no suitable database interface found to serve core db dsn.
2684 */
2685 SWITCH_DECLARE(switch_status_t) switch_core_check_core_db_dsn(void);
2686 
2687 /*!
2688 \brief Returns error if no suitable database interface found for a dsn.
2689 */
2690 SWITCH_DECLARE(switch_status_t) switch_database_available(char* dsn);
2691 
2692 SWITCH_DECLARE(void) switch_core_set_signal_handlers(void);
2693 SWITCH_DECLARE(uint32_t) switch_core_debug_level(void);
2694 SWITCH_DECLARE(int32_t) switch_core_sps(void);
2695 SWITCH_DECLARE(int32_t) switch_core_sps_last(void);
2696 SWITCH_DECLARE(int32_t) switch_core_sps_peak(void);
2697 SWITCH_DECLARE(int32_t) switch_core_sps_peak_fivemin(void);
2698 SWITCH_DECLARE(int32_t) switch_core_sessions_peak(void);
2699 SWITCH_DECLARE(int32_t) switch_core_sessions_peak_fivemin(void);
2700 SWITCH_DECLARE(void) switch_cache_db_flush_handles(void);
2701 SWITCH_DECLARE(const char *) switch_core_banner(void);
2702 SWITCH_DECLARE(switch_bool_t) switch_core_session_in_thread(switch_core_session_t *session);
2703 SWITCH_DECLARE(uint32_t) switch_default_ptime(const char *name, uint32_t number);
2704 SWITCH_DECLARE(uint32_t) switch_default_rate(const char *name, uint32_t number);
2705 SWITCH_DECLARE(uint32_t) switch_core_max_audio_channels(uint32_t limit);
2706 
2707 /*!
2708  \brief Add user registration
2709  \param [in] user
2710  \param [in] realm
2711  \param [in] token
2712  \param [in] url - a freeswitch dial string
2713  \param [in] expires
2714  \param [in] network_ip
2715  \param [in] network_port
2716  \param [in] network_proto - one of tls, tcp, udp
2717  \param [in] metadata - generic metadata supplied by module
2718  \param [out] err - Error if it exists
2719 */
2720 SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires,
2721 															 const char *network_ip, const char *network_port, const char *network_proto,
2722 															 const char *metadata);
2723 /*!
2724  \brief Delete user registration
2725  \param [in] user
2726  \param [in] realm
2727  \param [in] token
2728  \param [out] err - Error if it exists
2729 */
2730 SWITCH_DECLARE(switch_status_t) switch_core_del_registration(const char *user, const char *realm, const char *token);
2731 /*!
2732  \brief Expire user registrations
2733  \param [in] force delete all registrations
2734  \param [out] err - Error if it exists
2735 */
2736 SWITCH_DECLARE(switch_status_t) switch_core_expire_registration(int force);
2737 
2738 /*!
2739  \brief Get RTP port range start value
2740  \param[in] void
2741  \param[out] RTP port range start value
2742 */
2743 SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_start_port(void);
2744 
2745 /*!
2746  \brief Get RTP port range end value
2747  \param[in] void
2748  \param[out] RTP port range end value
2749 */
2750 SWITCH_DECLARE(uint16_t) switch_core_get_rtp_port_range_end_port(void);
2751 
2752 SWITCH_DECLARE(char *) switch_say_file_handle_get_variable(switch_say_file_handle_t *sh, const char *var);
2753 SWITCH_DECLARE(char *) switch_say_file_handle_get_path(switch_say_file_handle_t *sh);
2754 SWITCH_DECLARE(char *) switch_say_file_handle_detach_path(switch_say_file_handle_t *sh);
2755 SWITCH_DECLARE(void) switch_say_file_handle_destroy(switch_say_file_handle_t **sh);
2756 SWITCH_DECLARE(switch_status_t) switch_say_file_handle_create(switch_say_file_handle_t **sh, const char *ext, switch_event_t **var_event);
2757 SWITCH_DECLARE(void) switch_say_file(switch_say_file_handle_t *sh, const char *fmt, ...);
2758 SWITCH_DECLARE(int) switch_max_file_desc(void);
2759 SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl);
2760 SWITCH_DECLARE(switch_status_t) switch_core_thread_set_cpu_affinity(int cpu);
2761 SWITCH_DECLARE(void) switch_os_yield(void);
2762 SWITCH_DECLARE(switch_status_t) switch_core_get_stacksizes(switch_size_t *cur, switch_size_t *max);
2763 SWITCH_DECLARE(void) switch_core_gen_encoded_silence(unsigned char *data, const switch_codec_implementation_t *read_impl, switch_size_t len);
2764 
2765 SWITCH_DECLARE(switch_cache_db_handle_type_t) switch_core_dbtype(void);
2766 SWITCH_DECLARE(void) switch_core_sql_exec(const char *sql);
2767 SWITCH_DECLARE(int) switch_core_recovery_recover(const char *technology, const char *profile_name);
2768 SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session, switch_bool_t force);
2769 SWITCH_DECLARE(void) switch_core_recovery_track(switch_core_session_t *session);
2770 SWITCH_DECLARE(void) switch_core_recovery_flush(const char *technology, const char *profile_name);
2771 
2772 SWITCH_DECLARE(void) switch_sql_queue_manager_pause(switch_sql_queue_manager_t *qm, switch_bool_t flush);
2773 SWITCH_DECLARE(void) switch_sql_queue_manager_resume(switch_sql_queue_manager_t *qm);
2774 
2775 SWITCH_DECLARE(int) switch_sql_queue_manager_size(switch_sql_queue_manager_t *qm, uint32_t index);
2776 SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push_confirm(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup);
2777 SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup);
2778 SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_destroy(switch_sql_queue_manager_t **qmp);
2779 SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_init_name(const char *name,
2780 																   switch_sql_queue_manager_t **qmp,
2781 																   uint32_t numq, const char *dsn, uint32_t max_trans,
2782 																   const char *pre_trans_execute,
2783 																   const char *post_trans_execute,
2784 																   const char *inner_pre_trans_execute,
2785 																   const char *inner_post_trans_execute);
2786 
2787 #define switch_sql_queue_manager_init(_q, _n, _d, _m, _p1, _p2, _ip1, _ip2) switch_sql_queue_manager_init_name(__FILE__, _q, _n, _d, _m, _p1, _p2, _ip1, _ip2)
2788 
2789 SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_start(switch_sql_queue_manager_t *qm);
2790 SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_stop(switch_sql_queue_manager_t *qm);
2791 SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_event_callback(switch_cache_db_handle_t *dbh,
2792 																		   const char *sql, switch_core_db_event_callback_func_t callback, void *pdata, char **err);
2793 
2794 SWITCH_DECLARE(void) switch_sql_queue_manager_execute_sql_callback(switch_sql_queue_manager_t *qm, const char *sql,
2795 																   switch_core_db_callback_func_t callback,
2796 																   void *pdata);
2797 SWITCH_DECLARE(void) switch_sql_queue_manager_execute_sql_callback_err(switch_sql_queue_manager_t *qm, const char *sql,
2798 																	   switch_core_db_callback_func_t callback,
2799 																	   switch_core_db_err_callback_func_t err_callback,
2800 																	   void *pdata);
2801 
2802 SWITCH_DECLARE(void) switch_sql_queue_manager_execute_sql_event_callback(switch_sql_queue_manager_t *qm, const char *sql,
2803 																		 switch_core_db_event_callback_func_t callback,
2804 																		 void *pdata);
2805 SWITCH_DECLARE(void) switch_sql_queue_manager_execute_sql_event_callback_err(switch_sql_queue_manager_t *qm, const char *sql,
2806 																			 switch_core_db_event_callback_func_t callback,
2807 																			 switch_core_db_err_callback_func_t err_callback,
2808 																			 void *pdata);
2809 
2810 SWITCH_DECLARE(pid_t) switch_fork(void);
2811 
2812 SWITCH_DECLARE(int) switch_core_gen_certs(const char *prefix);
2813 SWITCH_DECLARE(int) switch_core_cert_gen_fingerprint(const char *prefix, dtls_fingerprint_t *fp);
2814 SWITCH_DECLARE(int) switch_core_cert_expand_fingerprint(dtls_fingerprint_t *fp, const char *str);
2815 SWITCH_DECLARE(int) switch_core_cert_verify(dtls_fingerprint_t *fp);
2816 SWITCH_DECLARE(switch_status_t) _switch_core_session_request_video_refresh(switch_core_session_t *session, int force, const char *file, const char *func, int line);
2817 #define switch_core_session_request_video_refresh(_s) _switch_core_session_request_video_refresh(_s, 0, __FILE__, __SWITCH_FUNC__, __LINE__)
2818 #define switch_core_session_force_request_video_refresh(_s) _switch_core_session_request_video_refresh(_s, 1, __FILE__, __SWITCH_FUNC__, __LINE__)
2819 SWITCH_DECLARE(switch_status_t) switch_core_session_send_and_request_video_refresh(switch_core_session_t *session);
2820 SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait);
2821 SWITCH_DECLARE(int) switch_stream_system_fork(const char *cmd, switch_stream_handle_t *stream);
2822 SWITCH_DECLARE(int) switch_stream_system(const char *cmd, switch_stream_handle_t *stream);
2823 
2824 
2825 SWITCH_DECLARE(void) switch_core_session_debug_pool(switch_stream_handle_t *stream);
2826 
2827 SWITCH_DECLARE(switch_status_t) switch_core_session_override_io_routines(switch_core_session_t *session, switch_io_routines_t *ior);
2828 
2829 SWITCH_DECLARE(const char *)switch_version_major(void);
2830 SWITCH_DECLARE(const char *)switch_version_minor(void);
2831 SWITCH_DECLARE(const char *)switch_version_micro(void);
2832 
2833 SWITCH_DECLARE(const char *)switch_version_revision(void);
2834 SWITCH_DECLARE(const char *)switch_version_revision_human(void);
2835 SWITCH_DECLARE(const char *)switch_version_full(void);
2836 SWITCH_DECLARE(const char *)switch_version_full_human(void);
2837 
2838 SWITCH_DECLARE(void) switch_core_autobind_cpu(void);
2839 
2840 SWITCH_DECLARE(switch_status_t) switch_core_session_start_text_thread(switch_core_session_t *session);
2841 
2842 SWITCH_DECLARE(const char *) switch_core_get_event_channel_key_separator(void);
2843 
2844 SWITCH_END_EXTERN_C
2845 #endif
2846 /* For Emacs:
2847  * Local Variables:
2848  * mode:c
2849  * indent-tabs-mode:t
2850  * tab-width:4
2851  * c-basic-offset:4
2852  * End:
2853  * For VIM:
2854  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
2855  */
2856