indent pass 1

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8686 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-05-27 04:30:03 +00:00
parent 49ff246b7c
commit 3c349c274e
66 changed files with 3258 additions and 3498 deletions

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l155 -cs -T size_t " > ./.indent.pro echo -n "-brs -npsl -di0 -br -ce -d0 -cli0 -npcs -nfc1 -ut -i4 -ts4 -l155 -cs -T size_t " > ./.indent.pro
grep typedef ./src/include/*.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 `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 "} switch_" ./src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> ./.indent.pro grep "} switch_" ./src/include/*.h | perl -ne '@l = split; $l[1] =~ s/;//g ; print " -T $l[1] "' >> ./.indent.pro

File diff suppressed because it is too large Load Diff

View File

@ -50,137 +50,108 @@ extern "C" {
#ifndef __inline__ #ifndef __inline__
#define __inline__ __inline #define __inline__ __inline
#endif #endif
typedef unsigned __int8 uint8_t; typedef unsigned __int8 uint8_t;
typedef __int16 int16_t; typedef __int16 int16_t;
typedef __int32 int32_t; typedef __int32 int32_t;
typedef unsigned __int16 uint16_t; typedef unsigned __int16 uint16_t;
#endif #endif
#if defined(__i386__) #if defined(__i386__)
/*! \brief Find the bit position of the highest set bit in a word /*! \brief Find the bit position of the highest set bit in a word
\param bits The word to be searched \param bits The word to be searched
\return The bit number of the highest set bit, or -1 if the word is zero. */ \return The bit number of the highest set bit, or -1 if the word is zero. */
static __inline__ int top_bit(unsigned int bits) static __inline__ int top_bit(unsigned int bits) {
{ int res;
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n" __asm__ __volatile__(" movl $-1,%%edx;\n" " bsrl %%eax,%%edx;\n":"=d"(res)
" bsrl %%eax,%%edx;\n" :"a" (bits));
: "=d" (res) return res;
: "a" (bits)); }
return res; /*- End of function --------------------------------------------------------*//*! \brief Find the bit position of the lowest set bit in a word
} \param bits The word to be searched
/*- End of function --------------------------------------------------------*/ \return The bit number of the lowest set bit, or -1 if the word is zero. */ static __inline__ int bottom_bit(unsigned int bits) {
int res;
/*! \brief Find the bit position of the lowest set bit in a word __asm__ __volatile__(" movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n":"=d"(res)
\param bits The word to be searched :"a" (bits));
\return The bit number of the lowest set bit, or -1 if the word is zero. */ return res;
static __inline__ int bottom_bit(unsigned int bits) }
{
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsfl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
#elif defined(__x86_64__) #elif defined(__x86_64__)
static __inline__ int top_bit(unsigned int bits) static __inline__ int top_bit(unsigned int bits) {
{ int res;
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n" __asm__ __volatile__(" movq $-1,%%rdx;\n" " bsrq %%rax,%%rdx;\n":"=d"(res)
" bsrq %%rax,%%rdx;\n" :"a" (bits));
: "=d" (res) return res;
: "a" (bits)); }
return res; /*- End of function --------------------------------------------------------*/ static __inline__ int bottom_bit(unsigned int bits) {
} int res;
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits) __asm__ __volatile__(" movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n":"=d"(res)
{ :"a" (bits));
int res; return res;
}
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsfq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
#else #else
static __inline__ int top_bit(unsigned int bits) static __inline__ int top_bit(unsigned int bits) {
{ int i;
int i;
if (bits == 0)
if (bits == 0) return -1;
return -1; i = 0;
i = 0; if (bits & 0xFFFF0000) {
if (bits & 0xFFFF0000) bits &= 0xFFFF0000;
{ i += 16;
bits &= 0xFFFF0000; }
i += 16; if (bits & 0xFF00FF00) {
} bits &= 0xFF00FF00;
if (bits & 0xFF00FF00) i += 8;
{ }
bits &= 0xFF00FF00; if (bits & 0xF0F0F0F0) {
i += 8; bits &= 0xF0F0F0F0;
} i += 4;
if (bits & 0xF0F0F0F0) }
{ if (bits & 0xCCCCCCCC) {
bits &= 0xF0F0F0F0; bits &= 0xCCCCCCCC;
i += 4; i += 2;
} }
if (bits & 0xCCCCCCCC) if (bits & 0xAAAAAAAA) {
{ bits &= 0xAAAAAAAA;
bits &= 0xCCCCCCCC; i += 1;
i += 2; }
} return i;
if (bits & 0xAAAAAAAA) }
{
bits &= 0xAAAAAAAA;
i += 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits) static __inline__ int bottom_bit(unsigned int bits) {
{ int i;
int i;
if (bits == 0)
if (bits == 0) return -1;
return -1; i = 32;
i = 32; if (bits & 0x0000FFFF) {
if (bits & 0x0000FFFF) bits &= 0x0000FFFF;
{ i -= 16;
bits &= 0x0000FFFF; }
i -= 16; if (bits & 0x00FF00FF) {
} bits &= 0x00FF00FF;
if (bits & 0x00FF00FF) i -= 8;
{ }
bits &= 0x00FF00FF; if (bits & 0x0F0F0F0F) {
i -= 8; bits &= 0x0F0F0F0F;
} i -= 4;
if (bits & 0x0F0F0F0F) }
{ if (bits & 0x33333333) {
bits &= 0x0F0F0F0F; bits &= 0x33333333;
i -= 4; i -= 2;
} }
if (bits & 0x33333333) if (bits & 0x55555555) {
{ bits &= 0x55555555;
bits &= 0x33333333; i -= 1;
i -= 2; }
} return i;
if (bits & 0x55555555) }
{
bits &= 0x55555555;
i -= 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
#endif #endif
@ -194,7 +165,7 @@ static __inline__ int bottom_bit(unsigned int bits)
* segment, but a little inline assembly can fix that on an i386, x86_64 and * segment, but a little inline assembly can fix that on an i386, x86_64 and
* many other modern processors. * many other modern processors.
*/ */
/* /*
* Mu-law is basically as follows: * Mu-law is basically as follows:
* *
@ -222,66 +193,61 @@ static __inline__ int bottom_bit(unsigned int bits)
*/ */
//#define ULAW_ZEROTRAP /* turn on the trap as per the MIL-STD */ //#define ULAW_ZEROTRAP /* turn on the trap as per the MIL-STD */
#define ULAW_BIAS 0x84 /* Bias for linear code. */ #define ULAW_BIAS 0x84 /* Bias for linear code. */
/*! \brief Encode a linear sample to u-law /*! \brief Encode a linear sample to u-law
\param linear The sample to encode. \param linear The sample to encode.
\return The u-law value. \return The u-law value.
*/ */
static __inline__ uint8_t linear_to_ulaw(int linear) static __inline__ uint8_t linear_to_ulaw(int linear) {
{ uint8_t u_val;
uint8_t u_val; int mask;
int mask; int seg;
int seg;
/* Get the sign and the magnitude of the value. */ /* Get the sign and the magnitude of the value. */
if (linear < 0) if (linear < 0) {
{ linear = ULAW_BIAS - linear;
linear = ULAW_BIAS - linear; mask = 0x7F;
mask = 0x7F; } else {
} linear = ULAW_BIAS + linear;
else mask = 0xFF;
{ }
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
seg = top_bit(linear | 0xFF) - 7; seg = top_bit(linear | 0xFF) - 7;
/* /*
* Combine the sign, segment, quantization bits, * Combine the sign, segment, quantization bits,
* and complement the code word. * and complement the code word.
*/ */
if (seg >= 8) if (seg >= 8)
u_val = (uint8_t) (0x7F ^ mask); u_val = (uint8_t) (0x7F ^ mask);
else else
u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
#ifdef ULAW_ZEROTRAP #ifdef ULAW_ZEROTRAP
/* Optional ITU trap */ /* Optional ITU trap */
if (u_val == 0) if (u_val == 0)
u_val = 0x02; u_val = 0x02;
#endif #endif
return u_val; return u_val;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/*! \brief Decode an u-law sample to a linear value. /*! \brief Decode an u-law sample to a linear value.
\param ulaw The u-law sample to decode. \param ulaw The u-law sample to decode.
\return The linear value. \return The linear value.
*/ */
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) {
{ int t;
int t;
/* Complement to obtain normal u-law value. */
/* Complement to obtain normal u-law value. */ ulaw = ~ulaw;
ulaw = ~ulaw; /*
/* * Extract and bias the quantization bits. Then
* Extract and bias the quantization bits. Then * shift up by the segment number and subtract out the bias.
* shift up by the segment number and subtract out the bias. */
*/ t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); }
}
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/* /*
@ -308,71 +274,64 @@ static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
\param linear The sample to encode. \param linear The sample to encode.
\return The A-law value. \return The A-law value.
*/ */
static __inline__ uint8_t linear_to_alaw(int linear) static __inline__ uint8_t linear_to_alaw(int linear) {
{ int mask;
int mask; int seg;
int seg;
if (linear >= 0)
{
/* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
}
else
{
/* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK;
linear = -linear - 8;
}
/* Convert the scaled magnitude to segment number. */ if (linear >= 0) {
seg = top_bit(linear | 0xFF) - 7; /* Sign (bit 7) bit = 1 */
if (seg >= 8) mask = ALAW_AMI_MASK | 0x80;
{ } else {
if (linear >= 0) /* Sign (bit 7) bit = 0 */
{ mask = ALAW_AMI_MASK;
/* Out of range. Return maximum value. */ linear = -linear - 8;
return (uint8_t) (0x7F ^ mask); }
}
/* We must be just a tiny step below zero */ /* Convert the scaled magnitude to segment number. */
return (uint8_t) (0x00 ^ mask); seg = top_bit(linear | 0xFF) - 7;
} if (seg >= 8) {
/* Combine the sign, segment, and quantization bits. */ if (linear >= 0) {
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); /* Out of range. Return maximum value. */
} return (uint8_t) (0x7F ^ mask);
}
/* We must be just a tiny step below zero */
return (uint8_t) (0x00 ^ mask);
}
/* Combine the sign, segment, and quantization bits. */
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
}
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/*! \brief Decode an A-law sample to a linear value. /*! \brief Decode an A-law sample to a linear value.
\param alaw The A-law sample to decode. \param alaw The A-law sample to decode.
\return The linear value. \return The linear value.
*/ */
static __inline__ int16_t alaw_to_linear(uint8_t alaw) static __inline__ int16_t alaw_to_linear(uint8_t alaw) {
{ int i;
int i; int seg;
int seg;
alaw ^= ALAW_AMI_MASK; alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4); i = ((alaw & 0x0F) << 4);
seg = (((int) alaw & 0x70) >> 4); seg = (((int) alaw & 0x70) >> 4);
if (seg) if (seg)
i = (i + 0x108) << (seg - 1); i = (i + 0x108) << (seg - 1);
else else
i += 8; i += 8;
return (int16_t) ((alaw & 0x80) ? i : -i); return (int16_t) ((alaw & 0x80) ? i : -i);
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. /*! \brief Transcode from A-law to u-law, using the procedure defined in G.711.
\param alaw The A-law sample to transcode. \param alaw The A-law sample to transcode.
\return The best matching u-law value. \return The best matching u-law value.
*/ */
uint8_t alaw_to_ulaw(uint8_t alaw); uint8_t alaw_to_ulaw(uint8_t alaw);
/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. /*! \brief Transcode from u-law to A-law, using the procedure defined in G.711.
\param ulaw The u-law sample to transcode. \param ulaw The u-law sample to transcode.
\return The best matching A-law value. \return The best matching A-law value.
*/ */
uint8_t ulaw_to_alaw(uint8_t ulaw); uint8_t ulaw_to_alaw(uint8_t ulaw);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -56,8 +56,6 @@ SWITCH_BEGIN_EXTERN_C
*/ */
/** The fundamental pool type */ /** The fundamental pool type */
/* see switch types.h typedef struct apr_pool_t switch_memory_pool_t;*/ /* see switch types.h typedef struct apr_pool_t switch_memory_pool_t;*/
/** /**
* Clear all memory in the pool and run all the cleanups. This also destroys all * Clear all memory in the pool and run all the cleanups. This also destroys all
* subpools. * subpools.
@ -93,13 +91,13 @@ SWITCH_DECLARE(void) switch_pool_clear(switch_memory_pool_t *p);
* @bug We aught to provide an alternative to RTLD_GLOBAL, which * @bug We aught to provide an alternative to RTLD_GLOBAL, which
* is the only supported method of loading DSOs today. * 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. * Close a DSO library.
* @param handle handle to close. * @param handle handle to close.
*/ */
SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t * handle); SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t *handle);
/** /**
* Load a symbol from a DSO handle. * Load a symbol from a DSO handle.
@ -107,7 +105,7 @@ SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t * handle);
* @param handle handle to load the symbol from. * @param handle handle to load the symbol from.
* @param symname Name of the symbol to load. * @param symname Name of the symbol to load.
*/ */
SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t * ressym, switch_dso_handle_t * handle, const char *symname); SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t *ressym, switch_dso_handle_t *handle, const char *symname);
/** /**
* Report more information when a DSO function fails. * Report more information when a DSO function fails.
@ -115,7 +113,7 @@ SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t * ressym,
* @param buf Location to store the dso error * @param buf Location to store the dso error
* @param bufsize The size of the provided buffer * @param bufsize The size of the provided buffer
*/ */
SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t * dso, char *buf, size_t bufsize); SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *buf, size_t bufsize);
/** @} */ /** @} */
@ -125,11 +123,13 @@ SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t * dso, char *b
* @{ * @{
*/ */
SWITCH_DECLARE(int) switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format, ...); SWITCH_DECLARE(int) switch_snprintf(_Out_z_cap_(len)
char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format, ...);
SWITCH_DECLARE(int) switch_vasprintf(_Out_opt_ char **buf, _In_z_ _Printf_format_string_ const char *format, _In_ va_list ap); SWITCH_DECLARE(int) switch_vasprintf(_Out_opt_ char **buf, _In_z_ _Printf_format_string_ const char *format, _In_ va_list ap);
SWITCH_DECLARE(char *) switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size); SWITCH_DECLARE(char *) switch_copy_string(_Out_z_cap_(dst_size)
char *dst, _In_z_ const char *src, _In_ switch_size_t dst_size);
/** @} */ /** @} */
@ -164,7 +164,7 @@ SWITCH_DECLARE(char *) switch_copy_string(_Out_z_cap_(dst_size) char *dst, _In_z
* progress at the same time. * progress at the same time.
*/ */
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t * ht); SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p, switch_hash_t *ht);
/** /**
* Continue iterating over the entries in a hash table. * Continue iterating over the entries in a hash table.
@ -172,7 +172,7 @@ SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(switch_memory_pool_t *p,
* @return a pointer to the updated iteration state. NULL if there are no more * @return a pointer to the updated iteration state. NULL if there are no more
* entries. * entries.
*/ */
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t * ht); SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t *ht);
/** /**
* Get the current entry's details from the iteration state. * Get the current entry's details from the iteration state.
@ -183,11 +183,11 @@ SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(switch_hash_index_t * ht)
* @remark The return pointers should point to a variable that will be set to the * @remark The return pointers should point to a variable that will be set to the
* corresponding data, or they may be NULL if the data isn't interesting. * corresponding data, or they may be NULL if the data isn't interesting.
*/ */
SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t * hi, const void **key, switch_ssize_t *klen, void **val); SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t *hi, const void **key, switch_ssize_t *klen, void **val);
SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t * ht); SWITCH_DECLARE(switch_memory_pool_t *) switch_hash_pool_get(switch_hash_t *ht);
/** @} */ /** @} */
@ -258,7 +258,7 @@ SWITCH_DECLARE(switch_time_t) switch_time_now(void);
* @param result the resulting imploded time * @param result the resulting imploded time
* @param input the input exploded time * @param input the input exploded time
*/ */
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t * result, switch_time_exp_t * input); SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input);
/** /**
* formats the exploded time according to the format specified * formats the exploded time according to the format specified
@ -268,7 +268,7 @@ SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t * result,
* @param format The format for the time string * @param format The format for the time string
* @param tm The time to convert * @param tm The time to convert
*/ */
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); 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);
/** /**
* switch_rfc822_date formats dates in the RFC822 * switch_rfc822_date formats dates in the RFC822
@ -285,7 +285,7 @@ SWITCH_DECLARE(switch_status_t) switch_rfc822_date(char *date_str, switch_time_t
* @param result the exploded time * @param result the exploded time
* @param input the time to explode * @param input the time to explode
*/ */
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t * result, switch_time_t input); SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input);
/** /**
* Convert time value from human readable format to a numeric apr_time_t * Convert time value from human readable format to a numeric apr_time_t
@ -293,14 +293,14 @@ SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t * result,
* @param result the resulting imploded time * @param result the resulting imploded time
* @param input the input exploded time * @param input the input exploded time
*/ */
SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t * result, switch_time_exp_t * input); SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input);
/** /**
* convert a time to its human readable components in local timezone * convert a time to its human readable components in local timezone
* @param result the exploded time * @param result the exploded time
* @param input the time to explode * @param input the time to explode
*/ */
SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t * result, switch_time_t input); SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input);
/** /**
* Sleep for the specified number of micro-seconds. * Sleep for the specified number of micro-seconds.
@ -341,27 +341,27 @@ SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t);
* it will behave as either a nested or an unnested lock. * 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);
/** /**
* Destroy the mutex and free the memory associated with the lock. * Destroy the mutex and free the memory associated with the lock.
* @param lock the mutex to destroy. * @param lock the mutex to destroy.
*/ */
SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t * lock); SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t *lock);
/** /**
* Acquire the lock for the given mutex. If the mutex is already locked, * Acquire the lock for the given mutex. If the mutex is already locked,
* the current thread will be put to sleep until the lock becomes available. * the current thread will be put to sleep until the lock becomes available.
* @param lock the mutex on which to acquire the lock. * @param lock the mutex on which to acquire the lock.
*/ */
SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t * lock); SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t *lock);
/** /**
* Release the lock for the given mutex. * Release the lock for the given mutex.
* @param lock the mutex from which to release the lock. * @param lock the mutex from which to release the lock.
*/ */
SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t * lock); SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t *lock);
/** /**
* Attempt to acquire the lock for the given mutex. If the mutex has already * Attempt to acquire the lock for the given mutex. If the mutex has already
@ -370,7 +370,7 @@ SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t * lock);
* if the return value was APR_EBUSY, for portability reasons. * if the return value was APR_EBUSY, for portability reasons.
* @param lock the mutex on which to attempt the lock acquiring. * @param lock the mutex on which to attempt the lock acquiring.
*/ */
SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t * lock); SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t *lock);
/** @} */ /** @} */
@ -383,14 +383,14 @@ SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t * lock);
/** Opaque structure used for the rwlock */ /** Opaque structure used for the rwlock */
typedef struct apr_thread_rwlock_t switch_thread_rwlock_t; 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_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_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); SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock);
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t * rwlock); SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock);
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t * rwlock); SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock);
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t * rwlock); SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock);
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t * rwlock); SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock);
/** @} */ /** @} */
@ -416,7 +416,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock
* will be stored. * will be stored.
* @param pool the pool from which to allocate the mutex. * @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 * Put the active calling thread to sleep until signaled to wake up. Each
@ -430,7 +430,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_cond_create(switch_thread_cond_t *
* is released while the thread is asleep, and is again acquired before * is released while the thread is asleep, and is again acquired before
* returning from this function. * returning from this function.
*/ */
SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t * cond, switch_mutex_t * mutex); SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex);
/** /**
* Put the active calling thread to sleep until signaled to wake up or * Put the active calling thread to sleep until signaled to wake up or
@ -448,7 +448,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t * c
* will wake up before this time, otherwise the error APR_TIMEUP * will wake up before this time, otherwise the error APR_TIMEUP
* is returned. * is returned.
*/ */
SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t * cond, switch_mutex_t * mutex, switch_interval_time_t timeout); SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout);
/** /**
* Signals a single thread, if one exists, that is blocking on the given * Signals a single thread, if one exists, that is blocking on the given
@ -457,7 +457,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_
* is desired, that mutex must be locked while calling this function. * is desired, that mutex must be locked while calling this function.
* @param cond the condition variable on which to produce the signal. * @param cond the condition variable on which to produce the signal.
*/ */
SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t * cond); SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t *cond);
/** /**
* Signals all threads blocking on the given condition variable. * Signals all threads blocking on the given condition variable.
@ -465,13 +465,13 @@ SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t *
* the associated mutex. This will happen in a serialized manner. * the associated mutex. This will happen in a serialized manner.
* @param cond the condition variable on which to produce the broadcast. * @param cond the condition variable on which to produce the broadcast.
*/ */
SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t * cond); SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t *cond);
/** /**
* Destroy the condition variable and free the associated memory. * Destroy the condition variable and free the associated memory.
* @param cond the condition variable to destroy. * @param cond the condition variable to destroy.
*/ */
SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t * cond); SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t *cond);
/** @} */ /** @} */
@ -498,20 +498,20 @@ SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t
* the formatted UUID and a null terminator * the formatted UUID and a null terminator
* @param uuid The UUID to format * @param uuid The UUID to format
*/ */
SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t * uuid); SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid);
/** /**
* Generate and return a (new) UUID * Generate and return a (new) UUID
* @param uuid The resulting UUID * @param uuid The resulting UUID
*/ */
SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t * uuid); SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid);
/** /**
* Parse a standard-format string into a UUID * Parse a standard-format string into a UUID
* @param uuid The resulting UUID * @param uuid The resulting UUID
* @param uuid_str The formatted UUID * @param uuid_str The formatted UUID
*/ */
SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t * uuid, const char *uuid_str); SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str);
/** @} */ /** @} */
@ -530,7 +530,7 @@ SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t * uuid, const ch
* @param queue_capacity maximum size of the queue * @param queue_capacity maximum size of the queue
* @param pool a pool to allocate queue from * @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 * pop/get an object from the queue, blocking if the queue is already empty
@ -541,7 +541,7 @@ SWITCH_DECLARE(switch_status_t) switch_queue_create(switch_queue_t ** queue, uns
* @returns APR_EOF if the queue has been terminated * @returns APR_EOF if the queue has been terminated
* @returns APR_SUCCESS on a successfull pop * @returns APR_SUCCESS on a successfull pop
*/ */
SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t * queue, void **data); SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t *queue, void **data);
/** /**
* push/add a object to the queue, blocking if the queue is already full * push/add a object to the queue, blocking if the queue is already full
@ -552,7 +552,7 @@ SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t * queue, void **
* @returns APR_EOF the queue has been terminated * @returns APR_EOF the queue has been terminated
* @returns APR_SUCCESS on a successfull push * @returns APR_SUCCESS on a successfull push
*/ */
SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t * queue, void *data); SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t *queue, void *data);
/** /**
* returns the size of the queue. * returns the size of the queue.
@ -562,7 +562,7 @@ SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t * queue, void *
* @param queue the queue * @param queue the queue
* @returns the size of the queue * @returns the size of the queue
*/ */
SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t * queue); SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t *queue);
/** /**
* pop/get an object to the queue, returning immediatly if the queue is empty * pop/get an object to the queue, returning immediatly if the queue is empty
@ -574,7 +574,7 @@ SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t * queue);
* @returns APR_EOF the queue has been terminated * @returns APR_EOF the queue has been terminated
* @returns APR_SUCCESS on a successfull push * @returns APR_SUCCESS on a successfull push
*/ */
SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t * queue, void **data); SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data);
/** /**
* push/add a object to the queue, returning immediatly if the queue is full * push/add a object to the queue, returning immediatly if the queue is full
@ -586,7 +586,7 @@ SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t * queue, void
* @returns APR_EOF the queue has been terminated * @returns APR_EOF the queue has been terminated
* @returns APR_SUCCESS on a successfull push * @returns APR_SUCCESS on a successfull push
*/ */
SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t * queue, void *data); SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void *data);
/** @} */ /** @} */
@ -650,13 +650,13 @@ SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t * queue, voi
* @{ * @{
*/ */
#define SWITCH_FLOCK_SHARED 1 /**< Shared lock. More than one process #define SWITCH_FLOCK_SHARED 1 /**< Shared lock. More than one process
or thread can hold a shared lock or thread can hold a shared lock
at any given time. Essentially, at any given time. Essentially,
this is a "read lock", preventing this is a "read lock", preventing
writers from establishing an writers from establishing an
exclusive lock. */ exclusive lock. */
#define SWITCH_FLOCK_EXCLUSIVE 2 /**< Exclusive lock. Only one process #define SWITCH_FLOCK_EXCLUSIVE 2 /**< Exclusive lock. Only one process
may hold an exclusive lock at any may hold an exclusive lock at any
given time. This is analogous to given time. This is analogous to
a "write lock". */ a "write lock". */
@ -722,19 +722,19 @@ SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t * queue, voi
* @remark If perm is SWITCH_FPROT_OS_DEFAULT and the file is being created, * @remark If perm is SWITCH_FPROT_OS_DEFAULT and the file is being created,
* appropriate default permissions will be used. * 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_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_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset);
/** /**
* Close the specified file. * Close the specified file.
* @param thefile The file descriptor to close. * @param thefile The file descriptor to close.
*/ */
SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t * thefile); SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t *thefile);
SWITCH_DECLARE(switch_status_t) switch_file_lock(switch_file_t * thefile, int type); SWITCH_DECLARE(switch_status_t) switch_file_lock(switch_file_t *thefile, int type);
/** /**
* Delete the specified file. * Delete the specified file.
@ -764,7 +764,7 @@ SWITCH_DECLARE(switch_status_t) switch_file_rename(const char *from_path, const
* @remark It is not possible for both bytes to be read and an APR_EOF * @remark It is not possible for both bytes to be read and an APR_EOF
* or other error to be returned. APR_EINTR is never returned. * or other error to be returned. APR_EINTR is never returned.
*/ */
SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void *buf, switch_size_t *nbytes); SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t *thefile, void *buf, switch_size_t *nbytes);
/** /**
* Write data to the specified file. * Write data to the specified file.
@ -781,7 +781,7 @@ SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void *
* @remark It is possible for both bytes to be written and an error to * @remark It is possible for both bytes to be written and an error to
* be returned. APR_EINTR is never returned. * be returned. APR_EINTR is never returned.
*/ */
SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes); 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(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);
@ -798,8 +798,7 @@ SWITCH_DECLARE(switch_status_t) switch_directory_exists(const char *dirname, swi
* @param perm Permissions for the new direcoty. * @param perm Permissions for the new direcoty.
* @param pool the pool to use. * @param pool the pool to use.
*/ */
SWITCH_DECLARE(switch_status_t) switch_dir_make(const char *path, switch_fileperms_t perm, SWITCH_DECLARE(switch_status_t) switch_dir_make(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool);
switch_memory_pool_t *pool);
/** Creates a new directory on the file system, but behaves like /** Creates a new directory on the file system, but behaves like
* 'mkdir -p'. Creates intermediate directories as required. No error * 'mkdir -p'. Creates intermediate directories as required. No error
@ -808,24 +807,23 @@ SWITCH_DECLARE(switch_status_t) switch_dir_make(const char *path, switch_fileper
* @param perm Permissions for the new direcoty. * @param perm Permissions for the new direcoty.
* @param pool the pool to use. * @param pool the pool to use.
*/ */
SWITCH_DECLARE(switch_status_t) switch_dir_make_recursive(const char *path, switch_fileperms_t perm, SWITCH_DECLARE(switch_status_t) switch_dir_make_recursive(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool);
switch_memory_pool_t *pool);
typedef struct switch_dir switch_dir_t; typedef struct switch_dir switch_dir_t;
struct switch_array_header_t { struct switch_array_header_t {
/** The pool the array is allocated out of */ /** The pool the array is allocated out of */
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
/** The amount of memory allocated for each element of the array */ /** The amount of memory allocated for each element of the array */
int elt_size; int elt_size;
/** The number of active elements in the array */ /** The number of active elements in the array */
int nelts; int nelts;
/** The number of elements allocated in the array */ /** The number of elements allocated in the array */
int nalloc; int nalloc;
/** The elements in the array */ /** The elements in the array */
char *elts; char *elts;
}; };
typedef struct switch_array_header_t switch_array_header_t; 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(switch_status_t) switch_dir_close(switch_dir_t *thedir);
@ -852,7 +850,7 @@ SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *bu
typedef void *(SWITCH_THREAD_FUNC * switch_thread_start_t) (switch_thread_t *, void *); typedef void *(SWITCH_THREAD_FUNC * switch_thread_start_t) (switch_thread_t *, void *);
//APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr, switch_size_t stacksize) //APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr, switch_size_t stacksize)
SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t * attr, switch_size_t stacksize); SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize);
SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threadattr_t *attr); SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threadattr_t *attr);
@ -862,14 +860,14 @@ SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threa
* @param new_attr The newly created threadattr. * @param new_attr The newly created threadattr.
* @param pool The pool to use * @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. * Set if newly created threads should be created in detached state.
* @param attr The threadattr to affect * @param attr The threadattr to affect
* @param on Non-zero if detached threads should be created. * @param on Non-zero if detached threads should be created.
*/ */
SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t * attr, int32_t on); SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on);
/** /**
* Create a new thread of execution * Create a new thread of execution
@ -879,7 +877,7 @@ SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t
* @param data Any data to be passed to the starting function * @param data Any data to be passed to the starting function
* @param cont The pool to use * @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); switch_thread_start_t func, void *data, switch_memory_pool_t *cont);
/** @} */ /** @} */
@ -946,7 +944,7 @@ SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thre
* @param protocol The protocol of the socket (e.g., SWITCH_PROTO_TCP). * @param protocol The protocol of the socket (e.g., SWITCH_PROTO_TCP).
* @param pool The pool to use * @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. * Shutdown either reading, writing, or both sides of a socket.
@ -961,13 +959,13 @@ SWITCH_DECLARE(switch_status_t) switch_socket_create(switch_socket_t ** new_sock
* @remark This does not actually close the socket descriptor, it just * @remark This does not actually close the socket descriptor, it just
* controls which calls are still valid on the socket. * controls which calls are still valid on the socket.
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t * sock, switch_shutdown_how_e how); SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how);
/** /**
* Close a socket. * Close a socket.
* @param sock The socket to close * @param sock The socket to close
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t * sock); SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t *sock);
/** /**
* Bind the socket to its associated port * Bind the socket to its associated port
@ -976,7 +974,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t * sock);
* @remark This may be where we will find out if there is any other process * @remark This may be where we will find out if there is any other process
* using the selected port. * using the selected port.
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t * sock, switch_sockaddr_t * sa); SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa);
/** /**
* Listen to a bound socket for connections. * Listen to a bound socket for connections.
@ -985,7 +983,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t * sock, switc
* listen queue. If this value is less than zero, the listen * listen queue. If this value is less than zero, the listen
* queue size is set to zero. * queue size is set to zero.
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t * sock, int32_t backlog); SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t *sock, int32_t backlog);
/** /**
* Accept a new connection request * Accept a new connection request
@ -995,7 +993,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t * sock, int
* @param sock The socket we are listening on. * @param sock The socket we are listening on.
* @param pool The pool for the new socket. * @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 * Issue a connection request to a socket either on the same machine
@ -1003,12 +1001,12 @@ SWITCH_DECLARE(switch_status_t) switch_socket_accept(switch_socket_t ** new_sock
* @param sock The socket we wish to use for our side of the connection * @param sock The socket we wish to use for our side of the connection
* @param sa The address of the machine we wish to connect to. * @param sa The address of the machine we wish to connect to.
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t * sock, switch_sockaddr_t * sa); SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa);
SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t * sa); SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa);
SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in); SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in);
SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t * sa); SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t *sa);
SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t * sa); SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa);
/** /**
@ -1034,7 +1032,7 @@ SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_socka
* </PRE> * </PRE>
* @param pool The pool for the apr_sockaddr_t and associated storage. * @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); int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool);
/** /**
@ -1054,7 +1052,7 @@ SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa
* APR_EINTR is never returned. * APR_EINTR is never returned.
* </PRE> * </PRE>
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t * sock, const char *buf, switch_size_t *len); SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len);
/** /**
* @param sock The socket to send from * @param sock The socket to send from
@ -1063,8 +1061,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t * sock, const
* @param buf The data to send * @param buf The data to send
* @param len The length of 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_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_size_t *len);
/** /**
* @param from The apr_sockaddr_t to fill in the recipient info * @param from The apr_sockaddr_t to fill in the recipient info
@ -1074,7 +1071,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t * sock, swi
* @param len The length of the available buffer * @param len The length of the available buffer
* *
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t * from, switch_socket_t * sock, int32_t flags, char *buf, size_t *len); SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len);
/** /**
@ -1096,7 +1093,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t * from,
* APR_EINTR is never returned. * APR_EINTR is never returned.
* </PRE> * </PRE>
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t * sock, char *buf, switch_size_t *len); SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len);
/** /**
* Setup socket options for the specified socket * Setup socket options for the specified socket
@ -1120,7 +1117,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t * sock, char
* </PRE> * </PRE>
* @param on Value for the option. * @param on Value for the option.
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t * sock, int32_t opt, int32_t on); SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on);
/** /**
* Setup socket timeout for the specified socket * Setup socket timeout for the specified socket
@ -1133,7 +1130,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t * sock, in
* t < 0 -- read and write calls block * t < 0 -- read and write calls block
* </PRE> * </PRE>
*/ */
SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t * sock, switch_interval_time_t t); SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t);
/** /**
* Join a Multicast Group * Join a Multicast Group
@ -1144,7 +1141,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t * sock
* @param source Source Address to accept transmissions from (non-NULL * @param source Source Address to accept transmissions from (non-NULL
* implies Source-Specific Multicast) * implies Source-Specific Multicast)
*/ */
SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch_sockaddr_t * join, switch_sockaddr_t * iface, switch_sockaddr_t * source); SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source);
@ -1185,7 +1182,7 @@ SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch
* platforms; the apr_pollset_create() call will fail with * platforms; the apr_pollset_create() call will fail with
* APR_ENOTIMPL on platforms where it is not supported. * 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 * Add a socket or file descriptor to a pollset
@ -1204,7 +1201,7 @@ SWITCH_DECLARE(switch_status_t) switch_pollset_create(switch_pollset_t ** pollse
* allowed for implementations where option (1) is impossible * allowed for implementations where option (1) is impossible
* or impractical. * or impractical.
*/ */
SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t * pollset, const switch_pollfd_t * descriptor); SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t *pollset, const switch_pollfd_t *descriptor);
/** /**
* Poll the sockets in the poll structure * Poll the sockets in the poll structure
@ -1219,7 +1216,7 @@ SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t * pollset, c
* This is a blocking call, and it will not return until either a * This is a blocking call, and it will not return until either a
* socket has been signalled, or the timeout has expired. * socket has been signalled, or the timeout has expired.
*/ */
SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout); SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout);
/*! /*!
\brief Create a set of file descriptors to poll \brief Create a set of file descriptors to poll
@ -1229,7 +1226,7 @@ SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t nu
\param pool the memory pool to use \param pool the memory pool to use
\return SWITCH_STATUS_SUCCESS when successful \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_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_socket_addr_get(switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock);

View File

@ -106,7 +106,7 @@ static inline void pack_check_over(switch_bitpack_t *pack)
pack->cur++; pack->cur++;
} else { } else {
switch_byte_t mask = SWITCH_BITS_PER_BYTE - pack->over; switch_byte_t mask = SWITCH_BITS_PER_BYTE - pack->over;
switch_assert(mask < 8); /* if pack->over this will allways be true */ switch_assert(mask < 8); /* if pack->over this will allways be true */
this_byte &= SWITCH_REVERSE_BITPACKED_MASKS[mask]; this_byte &= SWITCH_REVERSE_BITPACKED_MASKS[mask];
this_byte >>= mask; this_byte >>= mask;

View File

@ -122,7 +122,8 @@ SWITCH_DECLARE(void) switch_buffer_set_loops(_In_ switch_buffer_t *buffer, _In_
* \param datalen amount of data to be written * \param datalen amount of data to be written
* \return int amount of buffer used after the write, or 0 if no space available * \return int amount of buffer used after the write, or 0 if no space available
*/ */
SWITCH_DECLARE(switch_size_t) switch_buffer_write(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen) const void *data, _In_ switch_size_t datalen); SWITCH_DECLARE(switch_size_t) switch_buffer_write(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen)
const void *data, _In_ switch_size_t datalen);
/*! \brief Remove data from the buffer /*! \brief Remove data from the buffer
* \param buffer any buffer of type switch_buffer_t * \param buffer any buffer of type switch_buffer_t
@ -142,7 +143,8 @@ SWITCH_DECLARE(void) switch_buffer_zero(_In_ switch_buffer_t *buffer);
*/ */
SWITCH_DECLARE(void) switch_buffer_destroy(switch_buffer_t **buffer); SWITCH_DECLARE(void) switch_buffer_destroy(switch_buffer_t **buffer);
SWITCH_DECLARE(switch_size_t) switch_buffer_zwrite(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen) const void *data, _In_ switch_size_t datalen); SWITCH_DECLARE(switch_size_t) switch_buffer_zwrite(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen)
const void *data, _In_ switch_size_t datalen);
/** @} */ /** @} */

View File

@ -140,8 +140,7 @@ struct switch_caller_extension {
\return a new extension object allocated from the session's memory pool \return a new extension object allocated from the session's memory pool
*/ */
SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(_In_ switch_core_session_t *session, 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_name, _In_z_ const char *extension_number);
_In_z_ const char *extension_number);
/*! /*!
\brief Add an application (instruction) to the given extension \brief Add an application (instruction) to the given extension
@ -152,8 +151,7 @@ SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(_In_ swi
*/ */
SWITCH_DECLARE(void) switch_caller_extension_add_application(_In_ switch_core_session_t *session, SWITCH_DECLARE(void) switch_caller_extension_add_application(_In_ switch_core_session_t *session,
_In_ switch_caller_extension_t *caller_extension, _In_ switch_caller_extension_t *caller_extension,
_In_z_ const char *application_name, _In_z_ const char *application_name, _In_z_ const char *extra_data);
_In_z_ const char *extra_data);
/*! /*!
@ -162,8 +160,8 @@ SWITCH_DECLARE(void) switch_caller_extension_add_application(_In_ switch_core_se
\param name the name \param name the name
\note this function is meant for situations where the name paramater is the contents of the variable \note this function is meant for situations where the name paramater is the contents of the variable
*/ */
_Check_return_ _Ret_opt_z_ SWITCH_DECLARE(const char *) switch_caller_get_field_by_name(_In_ switch_caller_profile_t *caller_profile, _Check_return_ _Ret_opt_z_ SWITCH_DECLARE(const char *) switch_caller_get_field_by_name(_In_ switch_caller_profile_t *caller_profile,
_In_z_ const char *name); _In_z_ const char *name);
/*! /*!
\brief Create a new caller profile object \brief Create a new caller profile object
@ -191,8 +189,7 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(_In_ switch_
_In_opt_z_ const char *aniii, _In_opt_z_ const char *aniii,
_In_opt_z_ const char *rdnis, _In_opt_z_ const char *rdnis,
_In_opt_z_ const char *source, _In_opt_z_ const char *source,
_In_opt_z_ const char *context, _In_opt_z_ const char *context, _In_opt_z_ const char *destination_number);
_In_opt_z_ const char *destination_number);
/*! /*!
\brief Clone an existing caller profile object \brief Clone an existing caller profile object
@ -216,8 +213,7 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_dup(_In_ switch_
*/ */
SWITCH_DECLARE(void) switch_caller_profile_event_set_data(_In_ switch_caller_profile_t *caller_profile, SWITCH_DECLARE(void) switch_caller_profile_event_set_data(_In_ switch_caller_profile_t *caller_profile,
_In_opt_z_ const char *prefix, _In_opt_z_ const char *prefix, _In_ switch_event_t *event);
_In_ switch_event_t *event);
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
/** @} */ /** @} */

View File

@ -438,7 +438,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(_In_ switch_cha
*/ */
SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(_In_ switch_channel_t *channel, _In_ switch_dtmf_t *dtmf); SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(_In_ switch_channel_t *channel, _In_ switch_dtmf_t *dtmf);
SWITCH_DECLARE(void) switch_channel_flush_dtmf(_In_ switch_channel_t *channel); SWITCH_DECLARE(void) switch_channel_flush_dtmf(_In_ switch_channel_t *channel);
SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf_string(_In_ switch_channel_t *channel, _Out_opt_bytecapcount_(len) char *dtmf_str, _In_ switch_size_t len); SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf_string(_In_ switch_channel_t *channel, _Out_opt_bytecapcount_(len)
char *dtmf_str, _In_ switch_size_t len);
/*! /*!
\brief Render the name of the provided state enum \brief Render the name of the provided state enum
@ -469,7 +470,8 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(_In_ switch_channel_t *channe
\note it's necessary to test if the return val is the same as the input and free the string if it is not. \note it's necessary to test if the return val is the same as the input and free the string if it is not.
*/ */
SWITCH_DECLARE(char *) switch_channel_expand_variables(_In_ switch_channel_t *channel, _In_ const char *in); SWITCH_DECLARE(char *) switch_channel_expand_variables(_In_ switch_channel_t *channel, _In_ const char *in);
SWITCH_DECLARE(char *) switch_channel_build_param_string(_In_ switch_channel_t *channel, _In_opt_ switch_caller_profile_t *caller_profile, _In_opt_ const char *prefix); SWITCH_DECLARE(char *) switch_channel_build_param_string(_In_ switch_channel_t *channel, _In_opt_ switch_caller_profile_t *caller_profile,
_In_opt_ const char *prefix);
SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(_In_ switch_channel_t *channel); SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(_In_ switch_channel_t *channel);
#define switch_channel_stop_broadcast(_channel) if (switch_channel_test_flag(_channel, CF_BROADCAST)) switch_channel_set_flag(_channel, CF_BREAK | CF_STOP_BROADCAST) #define switch_channel_stop_broadcast(_channel) if (switch_channel_test_flag(_channel, CF_BROADCAST)) switch_channel_set_flag(_channel, CF_BREAK | CF_STOP_BROADCAST)

View File

@ -88,13 +88,13 @@ struct switch_config {
\param file_path path to the file \param file_path path to the file
\return 1 (true) on success 0 (false) on failure \return 1 (true) on success 0 (false) on failure
*/ */
SWITCH_DECLARE(int) switch_config_open_file(switch_config_t * cfg, char *file_path); SWITCH_DECLARE(int) switch_config_open_file(switch_config_t *cfg, char *file_path);
/*! /*!
\brief Close a previously opened configuration file \brief Close a previously opened configuration file
\param cfg (switch_config_t *) config handle to use \param cfg (switch_config_t *) config handle to use
*/ */
SWITCH_DECLARE(void) switch_config_close_file(switch_config_t * cfg); SWITCH_DECLARE(void) switch_config_close_file(switch_config_t *cfg);
/*! /*!
\brief Retrieve next name/value pair from configuration file \brief Retrieve next name/value pair from configuration file
@ -102,7 +102,7 @@ SWITCH_DECLARE(void) switch_config_close_file(switch_config_t * cfg);
\param var pointer to aim at the new variable name \param var pointer to aim at the new variable name
\param val pointer to aim at the new value \param val pointer to aim at the new value
*/ */
SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t * cfg, char **var, char **val); SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t *cfg, char **var, char **val);
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
/** @} */ /** @} */

View File

@ -52,7 +52,6 @@ SWITCH_BEGIN_EXTERN_C
s.raw_write_function = switch_console_stream_raw_write; \ s.raw_write_function = switch_console_stream_raw_write; \
s.alloc_len = SWITCH_CMD_CHUNK_LEN; \ s.alloc_len = SWITCH_CMD_CHUNK_LEN; \
s.alloc_chunk = SWITCH_CMD_CHUNK_LEN s.alloc_chunk = SWITCH_CMD_CHUNK_LEN
/*! /*!
\brief A simple comand loop that reads input from the terminal \brief A simple comand loop that reads input from the terminal
*/ */

View File

@ -43,7 +43,7 @@
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C
#define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128 #define SWITCH_MAX_CORE_THREAD_SESSION_OBJS 128
#define SWITCH_MAX_STREAMS 128 #define SWITCH_MAX_STREAMS 128
struct switch_core_time_duration { struct switch_core_time_duration {
uint32_t mms; uint32_t mms;
uint32_t ms; uint32_t ms;
uint32_t sec; uint32_t sec;
@ -132,9 +132,7 @@ struct switch_core_port_allocator;
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(_In_ switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(_In_ switch_core_session_t *session,
_In_ switch_media_bug_callback_t callback, _In_ switch_media_bug_callback_t callback,
_In_opt_ void *user_data, _In_opt_ void *user_data,
_In_ time_t stop_time, _In_ time_t stop_time, _In_ switch_media_bug_flag_t flags, _Out_ switch_media_bug_t **new_bug);
_In_ switch_media_bug_flag_t flags,
_Out_ switch_media_bug_t **new_bug);
/*! /*!
\brief Obtain private data from a media bug \brief Obtain private data from a media bug
\param bug the bug to get the data from \param bug the bug to get the data from
@ -220,9 +218,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug
\return SWITCH_STATUS_SUCCESS if the operation was a success \return SWITCH_STATUS_SUCCESS if the operation was a success
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(_In_ switch_port_t start, SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(_In_ switch_port_t start,
_In_ switch_port_t end, _In_ switch_port_t end,
_In_ switch_port_flag_t flags, _In_ switch_port_flag_t flags, _Out_ switch_core_port_allocator_t **new_allocator);
_Out_ switch_core_port_allocator_t **new_allocator);
/*! /*!
\brief Get a port from the port allocator \brief Get a port from the port allocator
@ -406,7 +403,8 @@ SWITCH_DECLARE(void *) switch_core_perform_permanent_alloc(_In_ switch_size_t me
#define switch_core_permanent_alloc(_memory) switch_core_perform_permanent_alloc(_memory, __FILE__, __SWITCH_FUNC__, __LINE__) #define switch_core_permanent_alloc(_memory) switch_core_perform_permanent_alloc(_memory, __FILE__, __SWITCH_FUNC__, __LINE__)
SWITCH_DECLARE(void *) switch_core_perform_alloc(_In_ switch_memory_pool_t *pool, _In_ switch_size_t memory, _In_z_ const char *file, _In_z_ const char *func, _In_ int line); SWITCH_DECLARE(void *) switch_core_perform_alloc(_In_ switch_memory_pool_t *pool, _In_ switch_size_t memory, _In_z_ const char *file,
_In_z_ const char *func, _In_ int line);
/*! /*!
\brief Allocate memory directly from a memory pool \brief Allocate memory directly from a memory pool
@ -416,7 +414,8 @@ SWITCH_DECLARE(void *) switch_core_perform_alloc(_In_ switch_memory_pool_t *pool
*/ */
#define switch_core_alloc(_pool, _mem) switch_core_perform_alloc(_pool, _mem, __FILE__, __SWITCH_FUNC__, __LINE__) #define switch_core_alloc(_pool, _mem) switch_core_perform_alloc(_pool, _mem, __FILE__, __SWITCH_FUNC__, __LINE__)
_Ret_ SWITCH_DECLARE(void *) switch_core_perform_session_alloc(_In_ switch_core_session_t *session, _In_ switch_size_t memory, const char *file, const char *func, int line); _Ret_ SWITCH_DECLARE(void *) switch_core_perform_session_alloc(_In_ switch_core_session_t *session, _In_ switch_size_t memory, const char *file,
const char *func, int line);
/*! /*!
\brief Allocate memory from a session's pool \brief Allocate memory from a session's pool
@ -429,7 +428,7 @@ _Ret_ SWITCH_DECLARE(void *) switch_core_perform_session_alloc(_In_ switch_core_
SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(_In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line); SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(_In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line);
/*! /*!
\brief Copy a string using permanent memory allocation \brief Copy a string using permanent memory allocation
@ -439,7 +438,8 @@ SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(_In_z_ const char *t
#define switch_core_permanent_strdup(_todup) switch_core_perform_permanent_strdup(_todup, __FILE__, __SWITCH_FUNC__, __LINE__) #define switch_core_permanent_strdup(_todup) switch_core_perform_permanent_strdup(_todup, __FILE__, __SWITCH_FUNC__, __LINE__)
SWITCH_DECLARE(char *) switch_core_perform_session_strdup(_In_ switch_core_session_t *session, _In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line); SWITCH_DECLARE(char *) switch_core_perform_session_strdup(_In_ switch_core_session_t *session, _In_z_ const char *todup, _In_z_ const char *file,
_In_z_ const char *func, _In_ int line);
/*! /*!
\brief Copy a string using memory allocation from a session's pool \brief Copy a string using memory allocation from a session's pool
@ -450,7 +450,8 @@ SWITCH_DECLARE(char *) switch_core_perform_session_strdup(_In_ switch_core_sessi
#define switch_core_session_strdup(_session, _todup) switch_core_perform_session_strdup(_session, _todup, __FILE__, __SWITCH_FUNC__, __LINE__) #define switch_core_session_strdup(_session, _todup) switch_core_perform_session_strdup(_session, _todup, __FILE__, __SWITCH_FUNC__, __LINE__)
SWITCH_DECLARE(char *) switch_core_perform_strdup(_In_ switch_memory_pool_t *pool, _In_z_ const char *todup, _In_z_ const char *file, _In_z_ const char *func, _In_ int line); SWITCH_DECLARE(char *) switch_core_perform_strdup(_In_ switch_memory_pool_t *pool, _In_z_ const char *todup, _In_z_ const char *file,
_In_z_ const char *func, _In_ int line);
/*! /*!
\brief Copy a string using memory allocation from a given pool \brief Copy a string using memory allocation from a given pool
@ -542,7 +543,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_thread_launch(_In_ switch_co
\param session the session to retrieve from \param session the session to retrieve from
\return a pointer to the channel object \return a pointer to the channel object
*/ */
_Ret_ SWITCH_DECLARE(switch_channel_t *) switch_core_session_get_channel(_In_ switch_core_session_t *session); _Ret_ SWITCH_DECLARE(switch_channel_t *) switch_core_session_get_channel(_In_ switch_core_session_t *session);
/*! /*!
\brief Signal a session's state machine thread that a state change has occured \brief Signal a session's state machine thread that a state change has occured
@ -620,7 +621,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_queue_message(_In_ switch_co
\param indication the indication message to pass \param indication the indication message to pass
\return SWITCH_STATUS_SUCCESS if the message was passed \return SWITCH_STATUS_SUCCESS if the message was passed
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(_In_ switch_core_session_t *session, _In_ switch_core_session_message_types_t indication); SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(_In_ switch_core_session_t *session,
_In_ switch_core_session_message_types_t indication);
/*! /*!
\brief Queue an indication message on a session \brief Queue an indication message on a session
@ -628,7 +630,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(_In_ switch_
\param indication the indication message to queue \param indication the indication message to queue
\return SWITCH_STATUS_SUCCESS if the message was queued \return SWITCH_STATUS_SUCCESS if the message was queued
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_queue_indication(_In_ switch_core_session_t *session, _In_ switch_core_session_message_types_t indication); SWITCH_DECLARE(switch_status_t) switch_core_session_queue_indication(_In_ switch_core_session_t *session,
_In_ switch_core_session_message_types_t indication);
/*! /*!
\brief DE-Queue an message on a given session \brief DE-Queue an message on a given session
@ -656,17 +659,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_event_send(_In_z_ const char
SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(_In_ switch_core_session_t *session); SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(_In_ switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_core_session_exec(_In_ switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_core_session_exec(_In_ switch_core_session_t *session,
_In_ const switch_application_interface_t *application_interface, _In_ const switch_application_interface_t *application_interface, _In_opt_z_ const char *arg);
_In_opt_z_ const char *arg);
SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(_In_ switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(_In_ switch_core_session_t *session,
_In_ const char *app, _In_ const char *app, _In_opt_z_ const char *arg);
_In_opt_z_ const char *arg);
SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(_In_ switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(_In_ switch_core_session_t *session,
_In_z_ const char *exten, _In_z_ const char *exten,
_In_opt_z_ const char *dialplan, _In_opt_z_ const char *dialplan, _In_opt_z_ const char *context);
_In_opt_z_ const char *context);
/*! /*!
\brief Send an event to a session translating it to it's native message format \brief Send an event to a session translating it to it's native message format
@ -721,8 +721,7 @@ SWITCH_DECLARE(int) switch_core_session_get_stream_count(_In_ switch_core_sessio
\param obj an arguement \param obj an arguement
*/ */
SWITCH_DECLARE(void) switch_core_session_launch_thread(_In_ switch_core_session_t *session, SWITCH_DECLARE(void) switch_core_session_launch_thread(_In_ switch_core_session_t *session,
_In_ void *(*func) (switch_thread_t *, void *), _In_ void *(*func) (switch_thread_t *, void *), _In_opt_ void *obj);
_In_opt_ void *obj);
/*! /*!
\brief Signal a thread using a thread session to terminate \brief Signal a thread using a thread session to terminate
@ -737,8 +736,7 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(_In_ switch_core_thread_sess
\param thread_session the thread_session to use \param thread_session the thread_session to use
*/ */
SWITCH_DECLARE(void) switch_core_service_session(_In_ switch_core_session_t *session, SWITCH_DECLARE(void) switch_core_service_session(_In_ switch_core_session_t *session,
_In_ switch_core_thread_session_t *thread_session, _In_ switch_core_thread_session_t *thread_session, _In_ int stream_id);
_In_ int stream_id);
/*! /*!
\brief Request an outgoing session spawned from an existing session using a desired endpoing module \brief Request an outgoing session spawned from an existing session using a desired endpoing module
@ -756,13 +754,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(_In_opt
_In_z_ const char *endpoint_name, _In_z_ const char *endpoint_name,
_In_ switch_caller_profile_t *caller_profile, _In_ switch_caller_profile_t *caller_profile,
_Inout_ switch_core_session_t **new_session, _Inout_ switch_core_session_t **new_session,
_Inout_ switch_memory_pool_t **pool, _Inout_ switch_memory_pool_t **pool, _In_ switch_originate_flag_t flags);
_In_ switch_originate_flag_t flags);
SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(_In_z_ const char *endpoint_name, SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(_In_z_ const char *endpoint_name,
_Inout_ switch_core_session_t **new_session, _Inout_ switch_core_session_t **new_session,
_Inout_ switch_memory_pool_t **pool, _Inout_ switch_memory_pool_t **pool, _In_ void *data);
_In_ void *data);
/*! /*!
\brief Receive a message on a given session \brief Receive a message on a given session
@ -837,7 +833,8 @@ SWITCH_DECLARE(uint32_t) switch_core_session_flush_private_events(switch_core_se
\param stream_id which logical media channel to use \param stream_id which logical media channel to use
\return SWITCH_STATUS_SUCCESS a the frame was read \return SWITCH_STATUS_SUCCESS a the frame was read
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags,
int stream_id);
/*! /*!
\brief Read a video frame from a session \brief Read a video frame from a session
@ -847,7 +844,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(_In_ switch_core_
\param stream_id which logical media channel to use \param stream_id which logical media channel to use
\return SWITCH_STATUS_SUCCESS a if the frame was read \return SWITCH_STATUS_SUCCESS a if the frame was read
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(_In_ switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags,
int stream_id);
/*! /*!
\brief Write a video frame to a session \brief Write a video frame to a session
@ -857,7 +855,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(_In_ switch
\param stream_id which logical media channel to use \param stream_id which logical media channel to use
\return SWITCH_STATUS_SUCCESS a if the frame was written \return SWITCH_STATUS_SUCCESS a if the frame was written
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags,
int stream_id);
/*! /*!
\brief Reset the buffers and resampler on a session \brief Reset the buffers and resampler on a session
@ -874,7 +873,8 @@ SWITCH_DECLARE(void) switch_core_session_reset(_In_ switch_core_session_t *sessi
\param stream_id which logical media channel to use \param stream_id which logical media channel to use
\return SWITCH_STATUS_SUCCESS a the frame was written \return SWITCH_STATUS_SUCCESS a the frame was written
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(_In_ switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags,
int stream_id);
SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(_In_ switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(_In_ switch_core_session_t *session,
@ -916,7 +916,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(_In_ switch_core_s
\param pool the pool to use for the new hash \param pool the pool to use for the new hash
\return SWITCH_STATUS_SUCCESS if the hash is created \return SWITCH_STATUS_SUCCESS if the hash is created
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_hash_init(_Out_ switch_hash_t ** hash, _In_ switch_memory_pool_t *pool); SWITCH_DECLARE(switch_status_t) switch_core_hash_init(_Out_ switch_hash_t **hash, _In_ switch_memory_pool_t *pool);
/*! /*!
\brief Destroy an existing hash table \brief Destroy an existing hash table
@ -933,7 +933,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(_Inout_ switch_hash_t *
\return SWITCH_STATUS_SUCCESS if the data is added \return SWITCH_STATUS_SUCCESS if the data is added
\note the string key must be a constant or a dynamic string \note the string key must be a constant or a dynamic string
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(_In_ switch_hash_t * hash, _In_z_ const char *key, _In_opt_ const void *data); SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data);
/*! /*!
\brief Insert data into a hash \brief Insert data into a hash
@ -944,7 +944,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(_In_ switch_hash_t * has
\return SWITCH_STATUS_SUCCESS if the data is added \return SWITCH_STATUS_SUCCESS if the data is added
\note the string key must be a constant or a dynamic string \note the string key must be a constant or a dynamic string
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_t * hash, _In_z_ const char *key, _In_opt_ const void *data, _In_ switch_mutex_t *mutex); SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data,
_In_ switch_mutex_t *mutex);
/*! /*!
\brief Delete data from a hash based on desired key \brief Delete data from a hash based on desired key
@ -952,7 +953,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_
\param key the key from which to delete the data \param key the key from which to delete the data
\return SWITCH_STATUS_SUCCESS if the data is deleted \return SWITCH_STATUS_SUCCESS if the data is deleted
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(_In_ switch_hash_t * hash, _In_z_ const char *key); SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key);
/*! /*!
\brief Delete data from a hash based on desired key \brief Delete data from a hash based on desired key
@ -961,7 +962,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(_In_ switch_hash_t * has
\param mutex optional mutex to lock \param mutex optional mutex to lock
\return SWITCH_STATUS_SUCCESS if the data is deleted \return SWITCH_STATUS_SUCCESS if the data is deleted
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t * hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex); SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
/*! /*!
\brief Retrieve data from a given hash \brief Retrieve data from a given hash
@ -969,7 +970,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_
\param key the key to retrieve \param key the key to retrieve
\return a pointer to the data held in the key \return a pointer to the data held in the key
*/ */
SWITCH_DECLARE(void *) switch_core_hash_find(_In_ switch_hash_t * hash, _In_z_ const char *key); SWITCH_DECLARE(void *) switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key);
/*! /*!
@ -979,11 +980,12 @@ SWITCH_DECLARE(void *) switch_core_hash_find(_In_ switch_hash_t * hash, _In_z_ c
\param mutex optional mutex to lock \param mutex optional mutex to lock
\return a pointer to the data held in the key \return a pointer to the data held in the key
*/ */
SWITCH_DECLARE(void *) switch_core_hash_find_locked(_In_ switch_hash_t * hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex); SWITCH_DECLARE(void *) switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(char *depricate_me, _In_ switch_hash_t *hash); SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(char *depricate_me, _In_ switch_hash_t *hash);
SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(_In_ switch_hash_index_t *hi); SWITCH_DECLARE(switch_hash_index_t *) switch_hash_next(_In_ switch_hash_index_t *hi);
SWITCH_DECLARE(void) switch_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val); SWITCH_DECLARE(void) switch_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen)
const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val);
///\} ///\}
@ -999,7 +1001,8 @@ SWITCH_DECLARE(void) switch_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptr
\param pool the memory pool to use for allocation \param pool the memory pool to use for allocation
\return \return
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples, switch_memory_pool_t *pool); SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples,
switch_memory_pool_t *pool);
/*! /*!
\brief Wait for one cycle on an existing timer \brief Wait for one cycle on an existing timer
@ -1078,7 +1081,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, uint32_t decoded_rate,
void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag); void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag);
/*! /*!
\brief Decode data using a codec handle \brief Decode data using a codec handle
@ -1099,7 +1102,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, uint32_t encoded_rate,
void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag); void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag);
/*! /*!
\brief Destroy an initalized codec handle \brief Destroy an initalized codec handle
@ -1214,9 +1217,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
_In_ switch_file_handle_t *fh, _In_ switch_file_handle_t *fh,
_In_z_ const char *file_path, _In_z_ const char *file_path,
_In_ uint8_t channels, _In_ uint8_t channels,
_In_ uint32_t rate, _In_ uint32_t rate, _In_ unsigned int flags, _In_opt_ switch_memory_pool_t *pool);
_In_ unsigned int flags,
_In_opt_ switch_memory_pool_t *pool);
/*! /*!
\brief Open a media file using file format modules \brief Open a media file using file format modules
@ -1303,10 +1304,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_close(_In_ switch_file_handle_t
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_speech_open(_In_ switch_speech_handle_t *sh, SWITCH_DECLARE(switch_status_t) switch_core_speech_open(_In_ switch_speech_handle_t *sh,
const char *module_name, const char *module_name,
const char *voice_name, const char *voice_name,
_In_ unsigned int rate, _In_ unsigned int rate,
_In_ unsigned int interval, _In_ unsigned int interval, switch_speech_flag_t *flags, _In_ switch_memory_pool_t *pool);
switch_speech_flag_t *flags, _In_ switch_memory_pool_t *pool);
/*! /*!
\brief Feed text to the TTS module \brief Feed text to the TTS module
\param sh the speech handle to feed \param sh the speech handle to feed
@ -1356,7 +1356,7 @@ SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *
\return SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful \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, SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh,
void *data, switch_size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags); void *data, switch_size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags);
/*! /*!
\brief Close an open speech handle \brief Close an open speech handle
\param sh the speech handle to close \param sh the speech handle to close
@ -1379,11 +1379,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_speech_close(switch_speech_handle_t
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah, SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
const char *module_name, const char *module_name,
const char *codec, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool);
int rate,
const char *dest,
switch_asr_flag_t *flags,
switch_memory_pool_t *pool);
/*! /*!
\brief Close an asr handle \brief Close an asr handle
@ -1587,7 +1583,7 @@ SWITCH_DECLARE(switch_time_t) switch_core_uptime(void);
\param val the command arguement (if needed) \param val the command arguement (if needed)
\return 0 on success nonzero on error \return 0 on success nonzero on error
*/ */
SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t * val); SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t *val);
/*! /*!
\brief Get the output console \brief Get the output console

View File

@ -32,8 +32,7 @@
#define SWITCH_EVENT_HOOKS_H #define SWITCH_EVENT_HOOKS_H
#include <switch.h> #include <switch.h>
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C typedef struct switch_io_event_hooks switch_io_event_hooks_t;
typedef struct switch_io_event_hooks switch_io_event_hooks_t;
typedef struct switch_io_event_hook_outgoing_channel switch_io_event_hook_outgoing_channel_t; typedef struct switch_io_event_hook_outgoing_channel switch_io_event_hook_outgoing_channel_t;
typedef struct switch_io_event_hook_receive_message switch_io_event_hook_receive_message_t; typedef struct switch_io_event_hook_receive_message switch_io_event_hook_receive_message_t;
@ -48,7 +47,7 @@ typedef struct switch_io_event_hook_recv_dtmf switch_io_event_hook_recv_dtmf_t;
typedef struct switch_io_event_hook_state_change switch_io_event_hook_state_change_t; 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 struct switch_io_event_hook_resurrect_session switch_io_event_hook_resurrect_session_t;
typedef switch_status_t (*switch_outgoing_channel_hook_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_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_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); typedef switch_status_t (*switch_read_frame_hook_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
@ -59,7 +58,7 @@ typedef switch_status_t (*switch_kill_channel_hook_t) (switch_core_session_t *,
typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction); typedef switch_status_t (*switch_send_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction);
typedef switch_status_t (*switch_recv_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction); typedef switch_status_t (*switch_recv_dtmf_hook_t) (switch_core_session_t *, const switch_dtmf_t *, switch_dtmf_direction_t direction);
typedef switch_status_t (*switch_state_change_hook_t) (switch_core_session_t *); typedef switch_status_t (*switch_state_change_hook_t) (switch_core_session_t *);
typedef switch_call_cause_t (*switch_resurrect_session_hook_t)(switch_core_session_t **, switch_memory_pool_t **, void *); typedef switch_call_cause_t (*switch_resurrect_session_hook_t) (switch_core_session_t **, switch_memory_pool_t **, void *);
/*! \brief Node in which to store custom receive message callback hooks */ /*! \brief Node in which to store custom receive message callback hooks */
struct switch_io_event_hook_outgoing_channel { struct switch_io_event_hook_outgoing_channel {
@ -210,7 +209,7 @@ extern switch_io_event_hooks_t switch_core_session_get_event_hooks(switch_core_s
last = ptr; \ last = ptr; \
} \ } \
return SWITCH_STATUS_FALSE; \ return SWITCH_STATUS_FALSE; \
} }
NEW_HOOK_DECL_ADD_P(outgoing_channel); NEW_HOOK_DECL_ADD_P(outgoing_channel);

View File

@ -8,41 +8,28 @@ extern "C" {
#ifdef DOH #ifdef DOH
} }
#endif #endif
#include <switch.h> #include <switch.h>
#define this_check(x) do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n"); return x;}} while(0) #define this_check(x) do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n"); return x;}} while(0)
#define this_check_void() do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n");}} while(0) #define this_check_void() do { if (!this) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "object is not initalized\n");}} while(0)
#define sanity_check(x) do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0) #define sanity_check(x) do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
#define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0) #define sanity_check_noreturn do { if (!(session && allocated)) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return;}} while(0)
#define init_vars() do { allocated = 0; session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; xml_cdr_text = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown"; caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = ""; caller_profile.username = ""; on_hangup = NULL; memset(&cb_state, 0, sizeof(cb_state)); hook_state = CS_NEW; } while(0) #define init_vars() do { allocated = 0; session = NULL; channel = NULL; uuid = NULL; tts_name = NULL; voice_name = NULL; xml_cdr_text = NULL; memset(&args, 0, sizeof(args)); ap = NULL; caller_profile.source = "mod_unknown"; caller_profile.dialplan = ""; caller_profile.context = ""; caller_profile.caller_id_name = ""; caller_profile.caller_id_number = ""; caller_profile.network_addr = ""; caller_profile.ani = ""; caller_profile.aniii = ""; caller_profile.rdnis = ""; caller_profile.username = ""; on_hangup = NULL; memset(&cb_state, 0, sizeof(cb_state)); hook_state = CS_NEW; } while(0)
//// C++ Interface: switch_to_cpp_mempool//// Description: This class allows for overloading the new operator to allocate from a switch_memory_pool_t//// Author: Yossi Neiman <freeswitch@cartissolutions.com>, (C) 2007//// Copyright: See COPYING file that comes with this distribution//
//
// C++ Interface: switch_to_cpp_mempool
//
// Description: This class allows for overloading the new operator to allocate from a switch_memory_pool_t
//
// Author: Yossi Neiman <freeswitch@cartissolutions.com>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
#if 0 #if 0
#ifndef SWITCHTOMEMPOOL #ifndef SWITCHTOMEMPOOL
#define SWITCHTOMEMPOOL #define SWITCHTOMEMPOOL
class SwitchToMempool { class SwitchToMempool {
public: public:
SwitchToMempool() { } SwitchToMempool() {
SwitchToMempool(switch_memory_pool_t *mem) { memorypool = mem; } } SwitchToMempool(switch_memory_pool_t *mem) {
void *operator new(switch_size_t num_bytes, switch_memory_pool_t *mem) memorypool = mem;
{ }
void *ptr = switch_core_alloc(mem, (switch_size_t) num_bytes); void *operator new(switch_size_t num_bytes, switch_memory_pool_t *mem) {
return ptr; void *ptr = switch_core_alloc(mem, (switch_size_t) num_bytes);
} return ptr;
protected: }
switch_memory_pool_t *memorypool; protected:
switch_memory_pool_t *memorypool;
}; };
#endif #endif
#endif #endif
@ -66,135 +53,130 @@ Note that the first parameter to the new operator is implicitly handled by c++..
SWITCH_DECLARE(void) consoleLog(char *level_str, char *msg); SWITCH_DECLARE(void) consoleLog(char *level_str, char *msg);
SWITCH_DECLARE(void) consoleCleanLog(char *msg); SWITCH_DECLARE(void) consoleCleanLog(char *msg);
class CoreSession; class CoreSession;
class IVRMenu { class IVRMenu {
protected: protected:
switch_ivr_menu_t *menu; switch_ivr_menu_t *menu;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
public: public:
SWITCH_DECLARE_CONSTRUCTOR IVRMenu(IVRMenu *main, SWITCH_DECLARE_CONSTRUCTOR IVRMenu(IVRMenu * main,
const char *name, const char *name,
const char *greeting_sound, const char *greeting_sound,
const char *short_greeting_sound, const char *short_greeting_sound,
const char *invalid_sound, const char *invalid_sound,
const char *exit_sound, const char *exit_sound,
const char *confirm_macro, const char *confirm_macro,
const char *confirm_key, const char *confirm_key,
int confirm_attempts, int confirm_attempts, int inter_timeout, int digit_len, int timeout, int max_failures);
int inter_timeout, virtual SWITCH_DECLARE_CONSTRUCTOR ~ IVRMenu();
int digit_len, SWITCH_DECLARE(void) bindAction(char *action, const char *arg, const char *bind);
int timeout, SWITCH_DECLARE(void) execute(CoreSession * session, const char *name);
int max_failures };
);
virtual SWITCH_DECLARE_CONSTRUCTOR ~IVRMenu();
SWITCH_DECLARE(void) bindAction(char *action, const char *arg, const char *bind);
SWITCH_DECLARE(void) execute(CoreSession *session, const char *name);
};
class API { class API {
protected: protected:
char *last_data; char *last_data;
public: public:
SWITCH_DECLARE_CONSTRUCTOR API(void); SWITCH_DECLARE_CONSTRUCTOR API(void);
virtual SWITCH_DECLARE_CONSTRUCTOR ~API(); virtual SWITCH_DECLARE_CONSTRUCTOR ~ API();
SWITCH_DECLARE(const char *) execute(const char *command, const char *data); SWITCH_DECLARE(const char *) execute(const char *command, const char *data);
SWITCH_DECLARE(const char *) executeString(const char *command); SWITCH_DECLARE(const char *) executeString(const char *command);
}; };
typedef struct input_callback_state { typedef struct input_callback_state {
void *function; // pointer to the language specific callback function void *function; // pointer to the language specific callback function
// eg, PyObject *pyfunc // eg, PyObject *pyfunc
void *threadState; // pointer to the language specific thread state void *threadState; // pointer to the language specific thread state
// eg, PyThreadState *threadState // eg, PyThreadState *threadState
void *extra; // currently used to store a switch_file_handle_t void *extra; // currently used to store a switch_file_handle_t
char *funcargs; // extra string that will be passed to callback function char *funcargs; // extra string that will be passed to callback function
} input_callback_state_t; } input_callback_state_t;
typedef enum { typedef enum {
S_HUP = (1 << 0), S_HUP = (1 << 0),
S_FREE = (1 << 1), S_FREE = (1 << 1),
S_RDLOCK = (1 << 2) S_RDLOCK = (1 << 2)
} session_flag_t; } session_flag_t;
class Stream { class Stream {
protected: protected:
switch_stream_handle_t mystream; switch_stream_handle_t mystream;
switch_stream_handle_t *stream_p; switch_stream_handle_t *stream_p;
int mine; int mine;
public: public:
SWITCH_DECLARE_CONSTRUCTOR Stream(void); SWITCH_DECLARE_CONSTRUCTOR Stream(void);
SWITCH_DECLARE_CONSTRUCTOR Stream(switch_stream_handle_t *); SWITCH_DECLARE_CONSTRUCTOR Stream(switch_stream_handle_t *);
virtual SWITCH_DECLARE_CONSTRUCTOR ~Stream(); virtual SWITCH_DECLARE_CONSTRUCTOR ~ Stream();
SWITCH_DECLARE(void) write(const char *data); SWITCH_DECLARE(void) write(const char *data);
SWITCH_DECLARE(const char *)get_data(void); SWITCH_DECLARE(const char *) get_data(void);
}; };
class Event { class Event {
protected: protected:
public: public:
switch_event_t *event; switch_event_t *event;
char *serialized_string; char *serialized_string;
int mine; int mine;
SWITCH_DECLARE_CONSTRUCTOR Event(const char *type, const char *subclass_name = NULL); SWITCH_DECLARE_CONSTRUCTOR Event(const char *type, const char *subclass_name = NULL);
SWITCH_DECLARE_CONSTRUCTOR Event(switch_event_t *wrap_me, int free_me=0); SWITCH_DECLARE_CONSTRUCTOR Event(switch_event_t *wrap_me, int free_me = 0);
virtual SWITCH_DECLARE_CONSTRUCTOR ~Event(); virtual SWITCH_DECLARE_CONSTRUCTOR ~ Event();
SWITCH_DECLARE(const char *)serialize(const char *format=NULL); SWITCH_DECLARE(const char *) serialize(const char *format = NULL);
SWITCH_DECLARE(bool) setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL); SWITCH_DECLARE(bool) setPriority(switch_priority_t priority = SWITCH_PRIORITY_NORMAL);
SWITCH_DECLARE(const char *)getHeader(char *header_name); SWITCH_DECLARE(const char *) getHeader(char *header_name);
SWITCH_DECLARE(char *)getBody(void); SWITCH_DECLARE(char *) getBody(void);
SWITCH_DECLARE(const char *)getType(void); SWITCH_DECLARE(const char *) getType(void);
SWITCH_DECLARE(bool) addBody(const char *value); SWITCH_DECLARE(bool) addBody(const char *value);
SWITCH_DECLARE(bool) addHeader(const char *header_name, const char *value); SWITCH_DECLARE(bool) addHeader(const char *header_name, const char *value);
SWITCH_DECLARE(bool) delHeader(const char *header_name); SWITCH_DECLARE(bool) delHeader(const char *header_name);
SWITCH_DECLARE(bool) fire(void); SWITCH_DECLARE(bool) fire(void);
}; };
class CoreSession { class CoreSession {
protected: protected:
switch_input_args_t args; // holds ptr to cb function and input_callback_state struct switch_input_args_t args; // holds ptr to cb function and input_callback_state struct
// which has a language specific callback function // which has a language specific callback function
switch_input_args_t *ap; // ptr to args .. (is this really needed?) switch_input_args_t *ap; // ptr to args .. (is this really needed?)
switch_caller_profile_t caller_profile; // avoid passing so many args to originate, switch_caller_profile_t caller_profile; // avoid passing so many args to originate,
// instead set them here first // instead set them here first
char *xml_cdr_text; char *xml_cdr_text;
char *uuid; char *uuid;
char *tts_name; char *tts_name;
char *voice_name; char *voice_name;
void store_file_handle(switch_file_handle_t *fh); void store_file_handle(switch_file_handle_t *fh);
void *on_hangup; // language specific callback function, cast as void * void *on_hangup; // language specific callback function, cast as void *
switch_file_handle_t local_fh; switch_file_handle_t local_fh;
switch_file_handle_t *fhp; switch_file_handle_t *fhp;
char dtmf_buf[512]; char dtmf_buf[512];
public: public:
SWITCH_DECLARE_CONSTRUCTOR CoreSession(); SWITCH_DECLARE_CONSTRUCTOR CoreSession();
SWITCH_DECLARE_CONSTRUCTOR CoreSession(char *uuid); SWITCH_DECLARE_CONSTRUCTOR CoreSession(char *uuid);
SWITCH_DECLARE_CONSTRUCTOR CoreSession(switch_core_session_t *new_session); SWITCH_DECLARE_CONSTRUCTOR CoreSession(switch_core_session_t *new_session);
SWITCH_DECLARE_CONSTRUCTOR ~CoreSession(); SWITCH_DECLARE_CONSTRUCTOR ~ CoreSession();
switch_core_session_t *session; switch_core_session_t *session;
switch_channel_t *channel; switch_channel_t *channel;
unsigned int flags; unsigned int flags;
int allocated; int allocated;
input_callback_state cb_state; // callback state, always pointed to by the buf input_callback_state cb_state; // callback state, always pointed to by the buf
// field in this->args // field in this->args
switch_channel_state_t hook_state; // store hookstate for on_hangup callback switch_channel_state_t hook_state; // store hookstate for on_hangup callback
SWITCH_DECLARE(int) answer(); SWITCH_DECLARE(int) answer();
SWITCH_DECLARE(int) preAnswer(); SWITCH_DECLARE(int) preAnswer();
SWITCH_DECLARE(void) hangup(char *cause = "normal_clearing"); SWITCH_DECLARE(void) hangup(char *cause = "normal_clearing");
SWITCH_DECLARE(void) setVariable(char *var, char *val); SWITCH_DECLARE(void) setVariable(char *var, char *val);
SWITCH_DECLARE(void) setPrivate(char *var, void *val); SWITCH_DECLARE(void) setPrivate(char *var, void *val);
SWITCH_DECLARE(void *)getPrivate(char *var); SWITCH_DECLARE(void *) getPrivate(char *var);
SWITCH_DECLARE(const char *)getVariable(char *var); SWITCH_DECLARE(const char *) getVariable(char *var);
SWITCH_DECLARE(switch_status_t) process_callback_result(char *result); SWITCH_DECLARE(switch_status_t) process_callback_result(char *result);
SWITCH_DECLARE(void) say(const char *tosay, const char *module_name, const char *say_type, const char *say_method); SWITCH_DECLARE(void) say(const char *tosay, const char *module_name, const char *say_type, const char *say_method);
SWITCH_DECLARE(void) sayPhrase(const char *phrase_name, const char *phrase_data = "", const char *phrase_lang = NULL); SWITCH_DECLARE(void) sayPhrase(const char *phrase_name, const char *phrase_data = "", const char *phrase_lang = NULL);
/** \brief Record to a file /** \brief Record to a file
* \param file_name * \param file_name
@ -203,14 +185,14 @@ class CoreSession {
* to be considered silence (500 is a good starting point). * to be considered silence (500 is a good starting point).
* \param <[silence_secs]> seconds of silence to interrupt the record. * \param <[silence_secs]> seconds of silence to interrupt the record.
*/ */
SWITCH_DECLARE(int) recordFile(char *file_name, int max_len=0, int silence_threshold=0, int silence_secs=0); SWITCH_DECLARE(int) recordFile(char *file_name, int max_len = 0, int silence_threshold = 0, int silence_secs = 0);
/** \brief Set attributes of caller data for purposes of outgoing calls /** \brief Set attributes of caller data for purposes of outgoing calls
* \param var - the variable name, eg, "caller_id_name" * \param var - the variable name, eg, "caller_id_name"
* \param val - the data to set, eg, "bob" * \param val - the data to set, eg, "bob"
*/ */
SWITCH_DECLARE(void) setCallerData(char *var, char *val); SWITCH_DECLARE(void) setCallerData(char *var, char *val);
/** \brief Originate a call to a destination /** \brief Originate a call to a destination
* *
@ -222,9 +204,7 @@ class CoreSession {
* \return an int status code indicating success or failure * \return an int status code indicating success or failure
* *
*/ */
SWITCH_DECLARE(int) originate(CoreSession *a_leg_session, SWITCH_DECLARE(int) originate(CoreSession * a_leg_session, char *dest, int timeout = 60);
char *dest,
int timeout=60);
/** \brief set a DTMF callback function /** \brief set a DTMF callback function
@ -235,16 +215,16 @@ class CoreSession {
* certain other methods are executing. * certain other methods are executing.
* *
*/ */
SWITCH_DECLARE(void) setDTMFCallback(void *cbfunc, char *funcargs); SWITCH_DECLARE(void) setDTMFCallback(void *cbfunc, char *funcargs);
SWITCH_DECLARE(int) speak(char *text); SWITCH_DECLARE(int) speak(char *text);
SWITCH_DECLARE(void) set_tts_parms(char *tts_name, char *voice_name); SWITCH_DECLARE(void) set_tts_parms(char *tts_name, char *voice_name);
/** /**
* For timeout milliseconds, call the dtmf function set previously * For timeout milliseconds, call the dtmf function set previously
* by setDTMFCallback whenever a dtmf or event is received * by setDTMFCallback whenever a dtmf or event is received
*/ */
SWITCH_DECLARE(int) collectDigits(int timeout); SWITCH_DECLARE(int) collectDigits(int timeout);
/** /**
* Collect up to maxdigits digits worth of digits * Collect up to maxdigits digits worth of digits
@ -253,20 +233,13 @@ class CoreSession {
* (see mod_python.i). This does NOT call any callbacks upon * (see mod_python.i). This does NOT call any callbacks upon
* receiving dtmf digits. For that, use collectDigits. * receiving dtmf digits. For that, use collectDigits.
*/ */
SWITCH_DECLARE(char *) getDigits( SWITCH_DECLARE(char *) getDigits(int maxdigits, char *terminators, int timeout);
int maxdigits,
char *terminators, SWITCH_DECLARE(int) transfer(char *extensions, char *dialplan, char *context);
int timeout);
SWITCH_DECLARE(int) transfer(char *extensions, char *dialplan, char *context);
SWITCH_DECLARE(char *) read(int min_digits, SWITCH_DECLARE(char *) read(int min_digits, int max_digits, const char *prompt_audio_file, int timeout, const char *valid_terminators);
int max_digits,
const char *prompt_audio_file,
int timeout,
const char *valid_terminators);
/** \brief Play a file into channel and collect dtmfs /** \brief Play a file into channel and collect dtmfs
* *
* See API docs in switch_ivr.h: switch_play_and_get_digits(..) * See API docs in switch_ivr.h: switch_play_and_get_digits(..)
@ -275,14 +248,10 @@ class CoreSession {
* setDTMFCallback(..) as it uses its own internal callback * setDTMFCallback(..) as it uses its own internal callback
* handler. * handler.
*/ */
SWITCH_DECLARE(char *) playAndGetDigits(int min_digits, SWITCH_DECLARE(char *) playAndGetDigits(int min_digits,
int max_digits, int max_digits,
int max_tries, int max_tries,
int timeout, int timeout, char *terminators, char *audio_files, char *bad_input_audio_files, char *digits_regex);
char *terminators,
char *audio_files,
char *bad_input_audio_files,
char *digits_regex);
/** \brief Play a file that resides on disk into the channel /** \brief Play a file that resides on disk into the channel
* *
@ -292,53 +261,56 @@ class CoreSession {
* \return an int status code indicating success or failure * \return an int status code indicating success or failure
* *
*/ */
SWITCH_DECLARE(int) streamFile(char *file, int starting_sample_count=0); SWITCH_DECLARE(int) streamFile(char *file, int starting_sample_count = 0);
/** \brief flush any pending events /** \brief flush any pending events
*/ */
SWITCH_DECLARE(int) flushEvents(); SWITCH_DECLARE(int) flushEvents();
/** \brief flush any pending digits /** \brief flush any pending digits
*/ */
SWITCH_DECLARE(int) flushDigits(); SWITCH_DECLARE(int) flushDigits();
SWITCH_DECLARE(int) setAutoHangup(bool val); SWITCH_DECLARE(int) setAutoHangup(bool val);
/** \brief Set the hangup callback function /** \brief Set the hangup callback function
* \param hangup_func - language specific function ptr cast into void * * \param hangup_func - language specific function ptr cast into void *
*/ */
SWITCH_DECLARE(void) setHangupHook(void *hangup_func); SWITCH_DECLARE(void) setHangupHook(void *hangup_func);
SWITCH_DECLARE(bool) ready(); SWITCH_DECLARE(bool) ready();
SWITCH_DECLARE(void) execute(char *app, char *data=NULL); SWITCH_DECLARE(void) execute(char *app, char *data = NULL);
SWITCH_DECLARE(void) sendEvent(Event *sendME); SWITCH_DECLARE(void) sendEvent(Event * sendME);
SWITCH_DECLARE(void) setEventData(Event *e); SWITCH_DECLARE(void) setEventData(Event * e);
SWITCH_DECLARE(char *) getXMLCDR(); SWITCH_DECLARE(char *) getXMLCDR();
virtual bool begin_allow_threads() = 0; virtual bool begin_allow_threads() = 0;
virtual bool end_allow_threads() = 0; virtual bool end_allow_threads() = 0;
/** \brief Get the uuid of this session /** \brief Get the uuid of this session
* \return the uuid of this session * \return the uuid of this session
*/ */
char* get_uuid() const { return uuid; }; char *get_uuid() const {
return uuid;
};
/** \brief Get the callback function arguments associated with this session /** \brief Get the callback function arguments associated with this session
* \return a const reference to the callback function arguments * \return a const reference to the callback function arguments
*/ */
const switch_input_args_t& get_cb_args() const { return args; }; const switch_input_args_t &get_cb_args() const {
return args;
};
/** \brief Callback to the language specific hangup callback /** \brief Callback to the language specific hangup callback
*/ */
virtual void check_hangup_hook() = 0; virtual void check_hangup_hook() = 0;
virtual switch_status_t run_dtmf_callback(void *input, virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype) = 0;
switch_input_type_t itype) = 0;
}; };
/* ---- functions not bound to CoreSession instance ----- */ /* ---- functions not bound to CoreSession instance ----- */
@ -351,7 +323,7 @@ SWITCH_DECLARE(void) console_clean_log(char *msg);
* NOTE: the stuff regarding the dtmf callback might be completely * NOTE: the stuff regarding the dtmf callback might be completely
* wrong and has not been reviewed or tested * wrong and has not been reviewed or tested
*/ */
SWITCH_DECLARE(void) bridge(CoreSession &session_a, CoreSession &session_b); SWITCH_DECLARE(void) bridge(CoreSession & session_a, CoreSession & session_b);
/** \brief the actual hangup hook called back by freeswitch core /** \brief the actual hangup hook called back by freeswitch core
@ -360,11 +332,8 @@ SWITCH_DECLARE(void) bridge(CoreSession &session_a, CoreSession &session_b);
*/ */
SWITCH_DECLARE_NONSTD(switch_status_t) hanguphook(switch_core_session_t *session); SWITCH_DECLARE_NONSTD(switch_status_t) hanguphook(switch_core_session_t *session);
SWITCH_DECLARE_NONSTD(switch_status_t) dtmf_callback(switch_core_session_t *session, SWITCH_DECLARE_NONSTD(switch_status_t) dtmf_callback(switch_core_session_t *session,
void *input, void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
switch_input_type_t itype,
void *buf,
unsigned int buflen);
#ifdef __cplusplus #ifdef __cplusplus
@ -382,4 +351,3 @@ SWITCH_DECLARE_NONSTD(switch_status_t) dtmf_callback(switch_core_session_t *sess
* For VIM: * For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
*/ */

View File

@ -156,7 +156,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_priority(switch_event_t *event,
\param header_name the name of the header to read \param header_name the name of the header to read
\return the value of the requested header \return the value of the requested header
*/ */
_Ret_opt_z_ SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, char *header_name); _Ret_opt_z_ SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, char *header_name);
#define switch_event_get_header_nil(e, h) switch_str_nil(switch_event_get_header(e,h)) #define switch_event_get_header_nil(e, h) switch_str_nil(switch_event_get_header(e,h))
@ -292,7 +292,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_add_body(switch_event_t *event, con
#endif #endif
SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const char *in); SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const char *in);
SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(_In_z_ char *file, _In_z_ char *func, _In_ int line, SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(_In_z_ char *file, _In_z_ char *func, _In_ int line,
_In_z_ const char *proto, _In_z_ const char *login, _In_z_ const char *proto, _In_z_ const char *login,
_In_z_ const char *from, _In_z_ const char *from_domain, _In_z_ const char *from, _In_z_ const char *from_domain,
_In_z_ const char *status, _In_z_ const char *event_type, _In_z_ const char *status, _In_z_ const char *event_type,
@ -344,7 +344,7 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event);
*/ */
#define switch_event_fire_data(event, data) switch_event_fire_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, event, data) #define switch_event_fire_data(event, data) switch_event_fire_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, event, data)
SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix,switch_hash_t* vars_map); SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t *vars_map);
///\} ///\}

View File

@ -40,7 +40,7 @@
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C
/*! \brief An abstraction of a data frame */ /*! \brief An abstraction of a data frame */
struct switch_frame { struct switch_frame {
/*! a pointer to the codec information */ /*! a pointer to the codec information */
switch_codec_t *codec; switch_codec_t *codec;
/*! the originating source of the frame */ /*! the originating source of the frame */

View File

@ -41,9 +41,7 @@
#include <switch.h> #include <switch.h>
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C struct switch_unicast_conninfo {
struct switch_unicast_conninfo {
switch_core_session_t *session; switch_core_session_t *session;
switch_codec_t read_codec; switch_codec_t read_codec;
switch_frame_t write_frame; switch_frame_t write_frame;
@ -73,13 +71,10 @@ typedef struct switch_unicast_conninfo switch_unicast_conninfo_t;
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session,
char *local_ip, char *local_ip,
switch_port_t local_port, switch_port_t local_port,
char *remote_ip, char *remote_ip, switch_port_t remote_port, char *transport, char *flags);
switch_port_t remote_port,
char *transport,
char *flags);
/*! /*!
\brief Generate an XML CDR report. \brief Generate an XML CDR report.
@ -88,7 +83,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_
\return SWITCH_STATUS_SUCCESS if successful \return SWITCH_STATUS_SUCCESS if successful
\note on success the xml object must be freed \note on success the xml object must be freed
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr); SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr);
SWITCH_DECLARE(int) switch_ivr_set_xml_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_profile, int off); SWITCH_DECLARE(int) switch_ivr_set_xml_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_profile, int off);
SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channel_t *channel, int off); SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channel_t *channel, int off);
@ -143,11 +138,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
char *buf, char *buf,
switch_size_t buflen, switch_size_t buflen,
switch_size_t maxdigits, switch_size_t maxdigits,
const char *terminators, char *terminator, const char *terminators, char *terminator,
uint32_t first_timeout, uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout);
uint32_t digit_timeout,
uint32_t abs_timeout);
/*! /*!
\brief Engage background Speech detection on a session \brief Engage background Speech detection on a session
@ -161,9 +154,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session,
const char *mod_name, const char *mod_name,
const char *grammar, const char *grammar, const char *path, const char *dest, switch_asr_handle_t *ah);
const char *path,
const char *dest, switch_asr_handle_t *ah);
/*! /*!
\brief Stop background Speech detection on a session \brief Stop background Speech detection on a session
@ -221,10 +212,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
\param flags tweak read-mux, write-mux and dtmf \param flags tweak read-mux, write-mux and dtmf
\return SWITCH_STATUS_SUCESS if all is well \return SWITCH_STATUS_SUCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session_t *session,
const char *uuid, const char *uuid, const char *require_group, switch_eavesdrop_flag_t flags);
const char *require_group,
switch_eavesdrop_flag_t flags);
/*! /*!
\brief displace the media for a session with the audio from a file \brief displace the media for a session with the audio from a file
@ -307,10 +296,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_
\param data optional data for appliaction \param data optional data for appliaction
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
const char *key, const char *tone_spec, const char *key, const char *tone_spec,
const char *flags, time_t timeout, const char *flags, time_t timeout, const char *app, const char *data);
const char *app, const char *data);
@ -322,7 +310,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
\param args arguements to pass for callbacks etc \param args arguements to pass for callbacks etc
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
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_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_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args); SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args);
@ -337,9 +326,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(_In_ switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(_In_ switch_core_session_t *session,
_In_ switch_file_handle_t *fh, _In_ switch_file_handle_t *fh,
_In_z_ const char *file, _In_z_ const char *file, _In_opt_ switch_input_args_t *args, _In_ uint32_t limit);
_In_opt_ switch_input_args_t *args,
_In_ uint32_t limit);
/*! /*!
@ -407,8 +394,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
const switch_state_handler_table_t *table, const switch_state_handler_table_t *table,
const char *cid_name_override, const char *cid_name_override,
const char *cid_num_override, const char *cid_num_override,
switch_caller_profile_t *caller_profile_override, switch_caller_profile_t *caller_profile_override, switch_originate_flag_t flags);
switch_originate_flag_t flags);
/*! /*!
\brief Bridge Audio from one session to another \brief Bridge Audio from one session to another
@ -439,7 +425,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
\param dialplan the new dialplan (OPTIONAL, may be NULL) \param dialplan the new dialplan (OPTIONAL, may be NULL)
\param context the new context (OPTIONAL, may be NULL) \param context the new context (OPTIONAL, may be NULL)
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(_In_ switch_core_session_t *session, const char *extension, const char *dialplan, const char *context); SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(_In_ switch_core_session_t *session, const char *extension, const char *dialplan,
const char *context);
/*! /*!
\brief Transfer an existing session to another location in the future \brief Transfer an existing session to another location in the future
@ -560,14 +547,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_transfer_variable(switch_core_session
\param parser a pointer to the object pointer \param parser a pointer to the object pointer
\return SWITCH_STATUS_SUCCESS if all is well \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 \brief Destroy a digit stream parser object
\param parser a pointer to the parser object \param parser a pointer to the parser object
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t * parser); SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t *parser);
/*! /*!
\brief Create a new digit stream object \brief Create a new digit stream object
@ -575,14 +562,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_iv
\param stream a pointer to the stream object pointer \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 \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 \brief Destroys a digit stream object
\param stream a pointer to the 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 \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 \brief Set a digit string to action mapping
@ -591,7 +578,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit
\param data consumer data attached to this digit string \param data consumer data attached to this digit string
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t * parser, char *digits, void *data); SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, void *data);
/*! /*!
\brief Delete a string to action mapping \brief Delete a string to action mapping
@ -599,7 +586,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_
\param digits the digit string to be removed from the map \param digits the digit string to be removed from the map
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t * parser, char *digits); SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits);
/*! /*!
\brief Feed digits collected into the stream for event match testing \brief Feed digits collected into the stream for event match testing
@ -608,14 +595,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_
\param digit a digit to collect and test against the map of digit strings \param digit a digit to collect and test against the map of digit strings
\return NULL if no match found or consumer data that was associated with a given digit string when matched \return NULL if no match found or consumer data that was associated with a given digit string when matched
*/ */
SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t * parser, switch_ivr_digit_stream_t * stream, char digit); SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t *stream, char digit);
/*! /*!
\brief Reset the collected digit stream to nothing \brief Reset the collected digit stream to nothing
\param stream a pointer to the parser stream object created by switch_ivr_digit_stream_new \param stream a pointer to the parser stream object created by switch_ivr_digit_stream_new
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t * stream); SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t *stream);
/*! /*!
\brief Set a digit string terminator \brief Set a digit string terminator
@ -623,7 +610,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_s
\param digit the terminator digit \param digit the terminator digit
\return SWITCH_STATUS_SUCCESS if all is well \return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t * parser, char digit); SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t *parser, char digit);
/******************************************************************************************************/ /******************************************************************************************************/
@ -655,7 +642,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(sw
SWITCH_IVR_ACTION_NOOP /* No operation */ SWITCH_IVR_ACTION_NOOP /* No operation */
} switch_ivr_action_t; } switch_ivr_action_t;
struct switch_ivr_menu; 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 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 switch_ivr_menu_t;
typedef struct switch_ivr_menu_action switch_ivr_menu_action_t; typedef struct switch_ivr_menu_action switch_ivr_menu_action_t;
/******************************************************************************************************/ /******************************************************************************************************/
@ -680,20 +667,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(sw
*\return SWITCH_STATUS_SUCCESS if the menu was created. *\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, switch_ivr_menu_t *main,
const char *name, const char *name,
const char *greeting_sound, const char *greeting_sound,
const char *short_greeting_sound, const char *short_greeting_sound,
const char *invalid_sound, const char *invalid_sound,
const char *exit_sound, const char *exit_sound,
const char *confirm_macro, const char *confirm_macro,
const char *confirm_key, const char *confirm_key,
int confirm_attempts, int confirm_attempts,
int inter_timeout, int inter_timeout, int digit_len, int timeout, int max_failures, switch_memory_pool_t *pool);
int digit_len,
int timeout, int max_failures,
switch_memory_pool_t *pool);
/*! /*!
*\brief switch_ivr_menu_bind_action: Bind a keystroke to an action. *\brief switch_ivr_menu_bind_action: Bind a keystroke to an action.
@ -703,7 +687,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t ** new_me
*\param bind KeyStrokes to bind the action to. *\param bind KeyStrokes to bind the action to.
*\return SWUTCH_STATUS_SUCCESS if the action was binded *\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);
/*! /*!
@ -717,8 +702,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_action(switch_ivr_menu_t *
*\note The function returns an switch_ivr_action_t enum of what you want to do. and looks to your buffer for args. *\note The function returns an switch_ivr_action_t enum of what you want to do. and looks to your buffer for args.
*\return SWUTCH_STATUS_SUCCESS if the function was binded *\return SWUTCH_STATUS_SUCCESS if the function was binded
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t * menu, 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_function_t *function, const char *arg, const char *bind);
/*! /*!
@ -729,14 +714,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_bind_function(switch_ivr_menu_t
*\param obj A void pointer to an object you want to make avaliable to your callback functions that you may have binded with switch_ivr_menu_bind_function. *\param obj A void pointer to an object you want to make avaliable to your callback functions that you may have binded with switch_ivr_menu_bind_function.
*\return SWITCH_STATUS_SUCCESS if all is well *\return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *session, switch_ivr_menu_t * stack, char *name, void *obj); SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *session, switch_ivr_menu_t *stack, char *name, void *obj);
/*! /*!
*\brief free a stack of menu objects. *\brief free a stack of menu objects.
*\param stack The top level menu you wish to destroy. *\param stack The top level menu you wish to destroy.
*\return SWITCH_STATUS_SUCCESS if the object was a top level menu and it was freed *\return SWITCH_STATUS_SUCCESS if the object was a top level menu and it was freed
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t * stack); SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t *stack);
struct switch_ivr_menu_xml_ctx; struct switch_ivr_menu_xml_ctx;
typedef struct switch_ivr_menu_xml_ctx switch_ivr_menu_xml_ctx_t; typedef struct switch_ivr_menu_xml_ctx switch_ivr_menu_xml_ctx_t;
@ -748,10 +733,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_free(switch_ivr_menu_t * s
*\param xml_menu The xml Menu source of the menu to be created *\param xml_menu The xml Menu source of the menu to be created
*\return SWITCH_STATUS_SUCCESS if all is well *\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_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); SWITCH_DECLARE(switch_status_t) switch_ivr_menu_str2action(const char *action_name, switch_ivr_action_t *action);
/*! /*!
*\param xml_menu_ctx The XML menu parser context previously created by switch_ivr_menu_stack_xml_init *\param xml_menu_ctx The XML menu parser context previously created by switch_ivr_menu_stack_xml_init
@ -759,46 +744,45 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_str2action(const char *action_na
*\param function The menu function callback that will be executed when menu digits are bound to this name *\param function The menu function callback that will be executed when menu digits are bound to this name
*\return SWITCH_STATUS_SUCCESS if all is well *\return SWITCH_STATUS_SUCCESS if all is well
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t * xml_menu_ctx, 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); const char *name, switch_ivr_menu_action_function_t *function);
/*! /*!
*\param xml_menu_ctx A pointer of a XML menu parser context to be created *\param xml_menu_ctx A pointer of a XML menu parser context to be created
*\param pool memory pool (NULL to create one) *\param pool memory pool (NULL to create one)
*\return SWITCH_STATUS_SUCCESS if all is well *\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_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); switch_input_args_t *args);
SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms); SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms);
SWITCH_DECLARE(switch_status_t) switch_ivr_find_bridged_uuid(const char *uuid, char *b_uuid, switch_size_t blen); SWITCH_DECLARE(switch_status_t) switch_ivr_find_bridged_uuid(const char *uuid, char *b_uuid, switch_size_t blen);
SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session, const char *uuid, switch_bool_t bleg); SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session, const char *uuid, switch_bool_t bleg);
SWITCH_DECLARE(void) switch_ivr_park_session(switch_core_session_t *session); SWITCH_DECLARE(void) switch_ivr_park_session(switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t *session, switch_core_session_t *peer_session); SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t *session, switch_core_session_t *peer_session);
SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
uint32_t min_digits, uint32_t min_digits,
uint32_t max_digits, uint32_t max_digits,
const char *prompt_audio_file, const char *prompt_audio_file,
const char *var_name, const char *var_name,
char *digit_buffer, char *digit_buffer,
switch_size_t digit_buffer_length, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators);
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_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); switch_bind_flag_t bind_flags, const char *app);
SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session); SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *session, const char *unhold_key, const char *moh_a, const char *moh_b); SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *session, const char *unhold_key, const char *moh_a, const char *moh_b);
SWITCH_DECLARE(switch_status_t) switch_ivr_say(switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type, const char *say_method, switch_input_args_t *args); SWITCH_DECLARE(switch_status_t) switch_ivr_say(switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type,
const char *say_method, switch_input_args_t *args);
SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char *name); SWITCH_DECLARE(switch_say_method_t) switch_ivr_get_say_method_by_name(const char *name);
SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name); SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *name);
/** @} */ /** @} */
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
#endif #endif
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:

View File

@ -128,9 +128,8 @@ SWITCH_DECLARE(switch_dialplan_interface_t *) switch_loadable_module_get_dialpla
SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filename, SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filename,
switch_module_load_t switch_module_load, switch_module_load_t switch_module_load,
switch_module_runtime_t switch_module_runtime, switch_module_runtime_t switch_module_runtime,
switch_module_shutdown_t switch_module_shutdown, switch_module_shutdown_t switch_module_shutdown, switch_bool_t runtime);
switch_bool_t runtime);
/*! /*!
\brief Retrieve the timer interface by it's registered name \brief Retrieve the timer interface by it's registered name
@ -259,7 +258,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir,
\param filename the path to the module's dll or so file \param filename the path to the module's dll or so file
\return SWITCH_STATUS_SUCCESS on a successful load \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); SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void);
/*! /*!
@ -317,44 +316,43 @@ SWITCH_DECLARE(uint32_t) switch_core_codec_next_id(void);
} }
static inline void switch_core_codec_add_implementation(switch_memory_pool_t *pool, static inline void switch_core_codec_add_implementation(switch_memory_pool_t *pool, switch_codec_interface_t *codec_interface,
switch_codec_interface_t *codec_interface, /*! enumeration defining the type of the codec */
/*! enumeration defining the type of the codec */ const switch_codec_type_t codec_type,
const switch_codec_type_t codec_type, /*! the IANA code number */
/*! the IANA code number */ switch_payload_t ianacode,
switch_payload_t ianacode, /*! the IANA code name */
/*! the IANA code name */ const char *iananame,
const char *iananame, /*! default fmtp to send (can be overridden by the init function) */
/*! default fmtp to send (can be overridden by the init function) */ char *fmtp,
char *fmtp, /*! samples transferred per second */
/*! samples transferred per second */ uint32_t samples_per_second,
uint32_t samples_per_second, /*! actual samples transferred per second for those who are not moron g722 RFC writers */
/*! actual samples transferred per second for those who are not moron g722 RFC writers*/ uint32_t actual_samples_per_second,
uint32_t actual_samples_per_second, /*! bits transferred per second */
/*! bits transferred per second */ int bits_per_second,
int bits_per_second, /*! number of microseconds that denote one frame */
/*! number of microseconds that denote one frame */ int microseconds_per_frame,
int microseconds_per_frame, /*! number of samples that denote one frame */
/*! number of samples that denote one frame */ uint32_t samples_per_frame,
uint32_t samples_per_frame, /*! number of bytes that denote one frame decompressed */
/*! number of bytes that denote one frame decompressed */ uint32_t bytes_per_frame,
uint32_t bytes_per_frame, /*! number of bytes that denote one frame compressed */
/*! number of bytes that denote one frame compressed */ uint32_t encoded_bytes_per_frame,
uint32_t encoded_bytes_per_frame, /*! number of channels represented */
/*! number of channels represented */ uint8_t number_of_channels,
uint8_t number_of_channels, /*! number of frames to send in one netowrk packet */
/*! number of frames to send in one netowrk packet */ int pref_frames_per_packet,
int pref_frames_per_packet, /*! max number of frames to send in one network packet */
/*! max number of frames to send in one network packet */ int max_frames_per_packet,
int max_frames_per_packet, /*! function to initialize a codec handle using this implementation */
/*! function to initialize a codec handle using this implementation */ switch_core_codec_init_func_t init,
switch_core_codec_init_func_t init, /*! function to encode raw data into encoded data */
/*! function to encode raw data into encoded data */ switch_core_codec_encode_func_t encode,
switch_core_codec_encode_func_t encode, /*! function to decode encoded data into raw data */
/*! function to decode encoded data into raw data */ switch_core_codec_decode_func_t decode,
switch_core_codec_decode_func_t decode, /*! deinitalize a codec handle using this implementation */
/*! deinitalize a codec handle using this implementation */ switch_core_codec_destroy_func_t destroy)
switch_core_codec_destroy_func_t destroy)
{ {
if (codec_type == SWITCH_CODEC_TYPE_VIDEO || SWITCH_ACCEPTABLE_INTERVAL(microseconds_per_frame / 1000)) { if (codec_type == SWITCH_CODEC_TYPE_VIDEO || SWITCH_ACCEPTABLE_INTERVAL(microseconds_per_frame / 1000)) {
switch_codec_implementation_t *impl = (switch_codec_implementation_t *) switch_core_alloc(pool, sizeof(*impl)); switch_codec_implementation_t *impl = (switch_codec_implementation_t *) switch_core_alloc(pool, sizeof(*impl));

View File

@ -111,7 +111,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(_In_ switch_log_function_
\param level the level \param level the level
\return the name of the log level \return the name of the log level
*/ */
_Ret_z_ SWITCH_DECLARE(const char *) switch_log_level2str(_In_ switch_log_level_t level); _Ret_z_ SWITCH_DECLARE(const char *) switch_log_level2str(_In_ switch_log_level_t level);
/*! /*!
\brief Return the level number of the specified log level name \brief Return the level number of the specified log level name

View File

@ -45,8 +45,7 @@
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C
/*! \brief A table of functions to execute at various states /*! \brief A table of functions to execute at various states
*/ */
typedef enum {
typedef enum {
SWITCH_SHN_ON_INIT, SWITCH_SHN_ON_INIT,
SWITCH_SHN_ON_ROUTING, SWITCH_SHN_ON_ROUTING,
SWITCH_SHN_ON_EXECUTE, SWITCH_SHN_ON_EXECUTE,
@ -100,7 +99,31 @@ struct switch_io_event_hooks;
typedef switch_call_cause_t (*switch_io_outgoing_channel_t) 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_core_session_t *, switch_event_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **, switch_originate_flag_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_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_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); typedef switch_status_t (*switch_io_kill_channel_t) (switch_core_session_t *, int);
@ -108,9 +131,9 @@ typedef switch_status_t (*switch_io_send_dtmf_t) (switch_core_session_t *, const
typedef switch_status_t (*switch_io_receive_message_t) (switch_core_session_t *, switch_core_session_message_t *); typedef switch_status_t (*switch_io_receive_message_t) (switch_core_session_t *, switch_core_session_message_t *);
typedef switch_status_t (*switch_io_receive_event_t) (switch_core_session_t *, switch_event_t *); typedef switch_status_t (*switch_io_receive_event_t) (switch_core_session_t *, switch_event_t *);
typedef switch_status_t (*switch_io_state_change_t) (switch_core_session_t *); typedef switch_status_t (*switch_io_state_change_t) (switch_core_session_t *);
typedef switch_status_t (*switch_io_read_video_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int); typedef switch_status_t (*switch_io_read_video_frame_t) (switch_core_session_t *, switch_frame_t **, switch_io_flag_t, int);
typedef switch_status_t (*switch_io_write_video_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int); typedef switch_status_t (*switch_io_write_video_frame_t) (switch_core_session_t *, switch_frame_t *, switch_io_flag_t, int);
typedef switch_call_cause_t (*switch_io_resurrect_session_t)(switch_core_session_t **, switch_memory_pool_t **, void *); typedef switch_call_cause_t (*switch_io_resurrect_session_t) (switch_core_session_t **, switch_memory_pool_t **, void *);
typedef enum { typedef enum {
SWITCH_IO_OUTGOING_CHANNEL, SWITCH_IO_OUTGOING_CHANNEL,
@ -192,7 +215,7 @@ struct switch_timer {
switch_memory_pool_t *memory_pool; switch_memory_pool_t *memory_pool;
/*! private data for loadable modules to store information */ /*! private data for loadable modules to store information */
void *private_info; void *private_info;
/*! remaining time from last call to _check()*/ /*! remaining time from last call to _check() */
switch_size_t diff; switch_size_t diff;
switch_size_t tick; switch_size_t tick;
}; };
@ -346,7 +369,7 @@ struct switch_asr_handle {
/*! The Rate */ /*! The Rate */
uint32_t rate; uint32_t rate;
char *grammar; char *grammar;
/*! module specific param*/ /*! module specific param */
char *param; char *param;
/*! the handle's memory pool */ /*! the handle's memory pool */
switch_memory_pool_t *memory_pool; switch_memory_pool_t *memory_pool;
@ -365,7 +388,7 @@ struct switch_speech_interface {
/*! function to feed audio to the ASR */ /*! function to feed audio to the ASR */
switch_status_t (*speech_feed_tts) (switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags); switch_status_t (*speech_feed_tts) (switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags);
/*! function to read audio from the TTS */ /*! function to read audio from the TTS */
switch_status_t (*speech_read_tts) (switch_speech_handle_t *sh, void *data, switch_size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags); switch_status_t (*speech_read_tts) (switch_speech_handle_t *sh, void *data, switch_size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags);
void (*speech_flush_tts) (switch_speech_handle_t *sh); void (*speech_flush_tts) (switch_speech_handle_t *sh);
void (*speech_text_param_tts) (switch_speech_handle_t *sh, char *param, const char *val); void (*speech_text_param_tts) (switch_speech_handle_t *sh, char *param, const char *val);
void (*speech_numeric_param_tts) (switch_speech_handle_t *sh, char *param, int val); void (*speech_numeric_param_tts) (switch_speech_handle_t *sh, char *param, int val);
@ -389,7 +412,7 @@ struct switch_speech_handle {
uint32_t samples; uint32_t samples;
char voice[80]; char voice[80];
char *engine; char *engine;
/*! module specific param*/ /*! module specific param */
char *param; char *param;
/*! the handle's memory pool */ /*! the handle's memory pool */
switch_memory_pool_t *memory_pool; switch_memory_pool_t *memory_pool;
@ -526,7 +549,7 @@ struct switch_codec_implementation {
char *fmtp; char *fmtp;
/*! samples transferred per second */ /*! samples transferred per second */
uint32_t samples_per_second; uint32_t samples_per_second;
/*! actual samples transferred per second for those who are not moron g722 RFC writers*/ /*! actual samples transferred per second for those who are not moron g722 RFC writers */
uint32_t actual_samples_per_second; uint32_t actual_samples_per_second;
/*! bits transferred per second */ /*! bits transferred per second */
int bits_per_second; int bits_per_second;
@ -545,13 +568,13 @@ struct switch_codec_implementation {
/*! max number of frames to send in one network packet */ /*! max number of frames to send in one network packet */
int max_frames_per_packet; int max_frames_per_packet;
/*! function to initialize a codec handle using this implementation */ /*! function to initialize a codec handle using this implementation */
switch_core_codec_init_func_t init; switch_core_codec_init_func_t init;
/*! function to encode raw data into encoded data */ /*! function to encode raw data into encoded data */
switch_core_codec_encode_func_t encode; switch_core_codec_encode_func_t encode;
/*! function to decode encoded data into raw data */ /*! function to decode encoded data into raw data */
switch_core_codec_decode_func_t decode; switch_core_codec_decode_func_t decode;
/*! deinitalize a codec handle using this implementation */ /*! deinitalize a codec handle using this implementation */
switch_core_codec_destroy_func_t destroy; switch_core_codec_destroy_func_t destroy;
uint32_t codec_id; uint32_t codec_id;
struct switch_codec_implementation *next; struct switch_codec_implementation *next;
}; };

View File

@ -44,9 +44,7 @@
#endif #endif
#include <sqltypes.h> #include <sqltypes.h>
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C struct switch_odbc_handle;
struct switch_odbc_handle;
typedef enum { typedef enum {
SWITCH_ODBC_STATE_INIT, SWITCH_ODBC_STATE_INIT,
@ -70,7 +68,6 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
char *sql, switch_core_db_callback_func_t callback, void *pdata); char *sql, switch_core_db_callback_func_t callback, void *pdata);
SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt); SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt);
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
#endif #endif
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:

View File

@ -59,21 +59,16 @@ SWITCH_BEGIN_EXTERN_C
* C4610: struct can never be instantiated - user defined constructor required * C4610: struct can never be instantiated - user defined constructor required
*/ */
#pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610 4996) #pragma warning(disable:4100 4200 4204 4706 4819 4132 4510 4512 4610 4996)
#define SWITCH_HAVE_ODBC 1 #define SWITCH_HAVE_ODBC 1
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma comment(lib, "odbc32.lib") # pragma comment(lib, "odbc32.lib")
#endif #endif
#pragma include_alias(<libteletone.h>, <../../libs/libteletone/src/libteletone.h>) #pragma include_alias(<libteletone.h>, <../../libs/libteletone/src/libteletone.h>)
#pragma include_alias(<libteletone_generate.h>, <../../libs/libteletone/src/libteletone_generate.h>) #pragma include_alias(<libteletone_generate.h>, <../../libs/libteletone/src/libteletone_generate.h>)
#pragma include_alias(<libteletone_detect.h>, <../../libs/libteletone/src/libteletone_detect.h>) #pragma include_alias(<libteletone_detect.h>, <../../libs/libteletone/src/libteletone_detect.h>)
#if (_MSC_VER >= 1400) // VC8+ #if (_MSC_VER >= 1400) // VC8+
#define switch_assert(expr) assert(expr);__analysis_assume( expr ) #define switch_assert(expr) assert(expr);__analysis_assume( expr )
#endif #endif
#if (_MSC_VER >= 1400) // VC8+ #if (_MSC_VER >= 1400) // VC8+
#ifndef _CRT_SECURE_NO_DEPRECATE #ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE
@ -90,7 +85,7 @@ SWITCH_BEGIN_EXTERN_C
#undef inline #undef inline
#define inline __inline #define inline __inline
#ifndef uint32_t #ifndef uint32_t
typedef unsigned __int8 uint8_t; typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t; typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t; typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
@ -187,9 +182,9 @@ typedef int gid_t;
#define PRINTF_FUNCTION(fmtstr,vars) #define PRINTF_FUNCTION(fmtstr,vars)
#endif #endif
#ifdef SWITCH_INT32 #ifdef SWITCH_INT32
typedef SWITCH_INT32 switch_int32_t; typedef SWITCH_INT32 switch_int32_t;
#else #else
typedef int32_t switch_int32_t; typedef int32_t switch_int32_t;
#endif #endif
#ifdef SWITCH_SIZE_T #ifdef SWITCH_SIZE_T
@ -298,10 +293,9 @@ SWITCH_END_EXTERN_C
#ifndef switch_assert #ifndef switch_assert
#define switch_assert(expr) assert(expr) #define switch_assert(expr) assert(expr)
#endif #endif
#ifndef __ATTR_SAL #ifndef __ATTR_SAL
/* used for msvc code analysis */ /* used for msvc code analysis */
/* http://msdn2.microsoft.com/en-us/library/ms235402.aspx */ /* http://msdn2.microsoft.com/en-us/library/ms235402.aspx */
#define _In_ #define _In_
#define _In_z_ #define _In_z_
#define _In_opt_z_ #define _In_opt_z_
@ -324,8 +318,6 @@ SWITCH_END_EXTERN_C
#define _Out_ptrdiff_cap_(x) #define _Out_ptrdiff_cap_(x)
#define _Out_opt_ptrdiff_cap_(x) #define _Out_opt_ptrdiff_cap_(x)
#endif #endif
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c

View File

@ -45,9 +45,7 @@ SWITCH_BEGIN_EXTERN_C
#define SWITCH_RTP_KEY_LEN 30 #define SWITCH_RTP_KEY_LEN 30
#define SWITCH_RTP_CRYPTO_KEY_32 "AES_CM_128_HMAC_SHA1_32" #define SWITCH_RTP_CRYPTO_KEY_32 "AES_CM_128_HMAC_SHA1_32"
#define SWITCH_RTP_CRYPTO_KEY_80 "AES_CM_128_HMAC_SHA1_80" #define SWITCH_RTP_CRYPTO_KEY_80 "AES_CM_128_HMAC_SHA1_80"
typedef enum {
typedef enum {
SWITCH_RTP_CRYPTO_SEND, SWITCH_RTP_CRYPTO_SEND,
SWITCH_RTP_CRYPTO_RECV, SWITCH_RTP_CRYPTO_RECV,
SWITCH_RTP_CRYPTO_MAX SWITCH_RTP_CRYPTO_MAX
@ -72,16 +70,13 @@ typedef struct switch_rtp_crypto_key switch_rtp_crypto_key_t;
SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_session, SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_session,
switch_rtp_crypto_direction_t direction, switch_rtp_crypto_direction_t direction,
uint32_t index, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen);
switch_rtp_crypto_key_type_t type,
unsigned char *key,
switch_size_t keylen);
///\defgroup rtp RTP (RealTime Transport Protocol) ///\defgroup rtp RTP (RealTime Transport Protocol)
///\ingroup core1 ///\ingroup core1
///\{ ///\{
typedef void (*switch_rtp_invalid_handler_t) (switch_rtp_t *rtp_session, typedef void (*switch_rtp_invalid_handler_t) (switch_rtp_t *rtp_session,
switch_socket_t * sock, void *data, switch_size_t datalen, switch_sockaddr_t * from_addr); switch_socket_t *sock, void *data, switch_size_t datalen, switch_sockaddr_t *from_addr);
SWITCH_DECLARE(void) switch_rtp_get_random(void *buf, uint32_t len); SWITCH_DECLARE(void) switch_rtp_get_random(void *buf, uint32_t len);
@ -130,10 +125,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
switch_payload_t payload, switch_payload_t payload,
uint32_t samples_per_interval, uint32_t samples_per_interval,
uint32_t ms_per_packet, uint32_t ms_per_packet,
switch_rtp_flag_t flags, switch_rtp_flag_t flags, char *timer_name, const char **err, switch_memory_pool_t *pool);
char *timer_name,
const char **err,
switch_memory_pool_t *pool);
/*! /*!
@ -158,10 +150,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host,
switch_payload_t payload, switch_payload_t payload,
uint32_t samples_per_interval, uint32_t samples_per_interval,
uint32_t ms_per_packet, uint32_t ms_per_packet,
switch_rtp_flag_t flags, switch_rtp_flag_t flags, char *timer_name, const char **err, switch_memory_pool_t *pool);
char *timer_name,
const char **err,
switch_memory_pool_t *pool);
/*! /*!
@ -296,7 +285,7 @@ SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp_t *rtp_session, sw
\param io_flags i/o flags \param io_flags i/o flags
\return the number of bytes read \return the number of bytes read
*/ */
SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t * datalen, SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen,
switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags); switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags);
/*! /*!
@ -341,7 +330,8 @@ SWITCH_DECLARE(switch_size_t) switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session,
\return the number of bytes read \return the number of bytes read
*/ */
SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session, SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session,
void **data, uint32_t * datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags); void **data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags,
switch_io_flag_t io_flags);
/*! /*!
\brief Read data from a given RTP session without copying \brief Read data from a given RTP session without copying
@ -390,9 +380,7 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra
\return the number of bytes written \return the number of bytes written
*/ */
SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session, SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session,
void *data, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags);
uint32_t datalen,
uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags);
/*! /*!
\brief Retrieve the SSRC from a given RTP session \brief Retrieve the SSRC from a given RTP session

View File

@ -137,7 +137,7 @@ SWITCH_DECLARE(void) switch_stun_random_string(char *buf, uint16_t len, char *se
\param len the length of the data \param len the length of the data
\return a stun packet pointer to buf to use as an access point \return a stun packet pointer to buf to use as an access point
*/ */
SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, uint32_t len); SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, uint32_t len);
/*! /*!
\brief Obtain a printable string form of a given value \brief Obtain a printable string form of a given value
@ -155,7 +155,7 @@ SWITCH_DECLARE(const char *) switch_stun_value_to_name(int32_t type, uint32_t va
\param port the port \param port the port
\return true or false \return true or false
*/ */
SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t * port); SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t *port);
/*! /*!
\brief Extract a username from a packet attribute \brief Extract a username from a packet attribute
@ -174,7 +174,7 @@ SWITCH_DECLARE(char *) switch_stun_packet_attribute_get_username(switch_stun_pac
\param buf a pointer to data to use for the packet \param buf a pointer to data to use for the packet
\return a pointer to a ready-to-use stun packet \return a pointer to a ready-to-use stun packet
*/ */
SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t * buf); SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t *buf);
/*! /*!
\brief Add a username packet attribute \brief Add a username packet attribute

View File

@ -91,11 +91,9 @@ SWITCH_BEGIN_EXTERN_C
#define SWITCH_SEQ_CLEARLINE SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINE_CHAR_STR #define SWITCH_SEQ_CLEARLINE SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINE_CHAR_STR
#define SWITCH_SEQ_CLEARLINEEND SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINEEND_CHAR #define SWITCH_SEQ_CLEARLINEEND SWITCH_SEQ_ESC SWITCH_SEQ_CLEARLINEEND_CHAR
#define SWITCH_SEQ_CLEARSCR SWITCH_SEQ_ESC SWITCH_SEQ_CLEARSCR_CHAR SWITCH_SEQ_HOME #define SWITCH_SEQ_CLEARSCR SWITCH_SEQ_ESC SWITCH_SEQ_CLEARSCR_CHAR SWITCH_SEQ_HOME
#define SWITCH_DEFAULT_DTMF_DURATION 2000 #define SWITCH_DEFAULT_DTMF_DURATION 2000
#define SWITCH_MAX_DTMF_DURATION 192000 #define SWITCH_MAX_DTMF_DURATION 192000
#define SWITCH_DEFAULT_DIR_PERMS SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE | SWITCH_FPROT_UEXECUTE | SWITCH_FPROT_GREAD | SWITCH_FPROT_GEXECUTE #define SWITCH_DEFAULT_DIR_PERMS SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE | SWITCH_FPROT_UEXECUTE | SWITCH_FPROT_GREAD | SWITCH_FPROT_GEXECUTE
#ifdef WIN32 #ifdef WIN32
#define SWITCH_PATH_SEPARATOR "\\" #define SWITCH_PATH_SEPARATOR "\\"
#else #else
@ -144,7 +142,7 @@ SWITCH_BEGIN_EXTERN_C
#define SWITCH_SPEECH_KEY "speech" #define SWITCH_SPEECH_KEY "speech"
#define SWITCH_UUID_BRIDGE "uuid_bridge" #define SWITCH_UUID_BRIDGE "uuid_bridge"
#define SWITCH_BITS_PER_BYTE 8 #define SWITCH_BITS_PER_BYTE 8
typedef uint8_t switch_byte_t; typedef uint8_t switch_byte_t;
typedef struct { typedef struct {
char digit; char digit;
@ -168,7 +166,7 @@ typedef enum {
typedef enum { typedef enum {
SOF_NONE = 0, SOF_NONE = 0,
SOF_NOBLOCK = (1 << 0), SOF_NOBLOCK = (1 << 0),
SOF_FORKED_DIAL = (1 << 1) SOF_FORKED_DIAL = (1 << 1)
} switch_originate_flag_t; } switch_originate_flag_t;
typedef enum { typedef enum {
@ -185,7 +183,7 @@ typedef enum {
typedef enum { typedef enum {
SCF_NONE = 0, SCF_NONE = 0,
SCF_USE_SQL = ( 1 << 0), SCF_USE_SQL = (1 << 0),
SCF_NO_NEW_SESSIONS = (1 << 1), SCF_NO_NEW_SESSIONS = (1 << 1),
SCF_SHUTTING_DOWN = (1 << 2), SCF_SHUTTING_DOWN = (1 << 2),
SCF_CRASH_PROT = (1 << 3) SCF_CRASH_PROT = (1 << 3)
@ -320,10 +318,10 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
#define SWITCH_MAX_STACKS 32 #define SWITCH_MAX_STACKS 32
#define SWITCH_THREAD_STACKSIZE 240 * 1024 #define SWITCH_THREAD_STACKSIZE 240 * 1024
#define SWITCH_MAX_INTERVAL 120 /* we only do up to 120ms */ #define SWITCH_MAX_INTERVAL 120 /* we only do up to 120ms */
#define SWITCH_INTERVAL_PAD 10 /* A little extra buffer space to be safe */ #define SWITCH_INTERVAL_PAD 10 /* A little extra buffer space to be safe */
#define SWITCH_MAX_SAMPLE_LEN 32 #define SWITCH_MAX_SAMPLE_LEN 32
#define SWITCH_BYTES_PER_SAMPLE 2 /* slin is 2 bytes per sample */ #define SWITCH_BYTES_PER_SAMPLE 2 /* slin is 2 bytes per sample */
#define SWITCH_RECOMMENDED_BUFFER_SIZE (SWITCH_BYTES_PER_SAMPLE * SWITCH_MAX_SAMPLE_LEN * (SWITCH_MAX_INTERVAL + SWITCH_INTERVAL_PAD)) #define SWITCH_RECOMMENDED_BUFFER_SIZE (SWITCH_BYTES_PER_SAMPLE * SWITCH_MAX_SAMPLE_LEN * (SWITCH_MAX_INTERVAL + SWITCH_INTERVAL_PAD))
#define SWITCH_MAX_CODECS 30 #define SWITCH_MAX_CODECS 30
#define SWITCH_MAX_STATE_HANDLERS 30 #define SWITCH_MAX_STATE_HANDLERS 30
@ -425,29 +423,29 @@ typedef enum {
#if __BYTE_ORDER == __BIG_ENDIAN #if __BYTE_ORDER == __BIG_ENDIAN
typedef struct { typedef struct {
unsigned version:2; /* protocol version */ unsigned version:2; /* protocol version */
unsigned p:1; /* padding flag */ unsigned p:1; /* padding flag */
unsigned x:1; /* header extension flag */ unsigned x:1; /* header extension flag */
unsigned cc:4; /* CSRC count */ unsigned cc:4; /* CSRC count */
unsigned m:1; /* marker bit */ unsigned m:1; /* marker bit */
unsigned pt:7; /* payload type */ unsigned pt:7; /* payload type */
unsigned seq:16; /* sequence number */ unsigned seq:16; /* sequence number */
unsigned ts:32; /* timestamp */ unsigned ts:32; /* timestamp */
unsigned ssrc:32; /* synchronization source */ unsigned ssrc:32; /* synchronization source */
} switch_rtp_hdr_t; } switch_rtp_hdr_t;
#else /* BIG_ENDIAN */ #else /* BIG_ENDIAN */
typedef struct { typedef struct {
unsigned cc:4; /* CSRC count */ unsigned cc:4; /* CSRC count */
unsigned x:1; /* header extension flag */ unsigned x:1; /* header extension flag */
unsigned p:1; /* padding flag */ unsigned p:1; /* padding flag */
unsigned version:2; /* protocol version */ unsigned version:2; /* protocol version */
unsigned pt:7; /* payload type */ unsigned pt:7; /* payload type */
unsigned m:1; /* marker bit */ unsigned m:1; /* marker bit */
unsigned seq:16; /* sequence number */ unsigned seq:16; /* sequence number */
unsigned ts:32; /* timestamp */ unsigned ts:32; /* timestamp */
unsigned ssrc:32; /* synchronization source */ unsigned ssrc:32; /* synchronization source */
} switch_rtp_hdr_t; } switch_rtp_hdr_t;
#endif #endif
@ -1210,25 +1208,19 @@ typedef switch_bool_t (*switch_media_bug_callback_t) (switch_media_bug_t *, void
typedef switch_status_t (*switch_core_codec_encode_func_t) (switch_codec_t *codec, typedef switch_status_t (*switch_core_codec_encode_func_t) (switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, uint32_t decoded_rate,
void *encoded_data, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag);
uint32_t * encoded_data_len,
uint32_t * encoded_rate,
unsigned int *flag);
typedef switch_status_t (*switch_core_codec_decode_func_t) (switch_codec_t *codec, typedef switch_status_t (*switch_core_codec_decode_func_t) (switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, uint32_t encoded_rate,
void *decoded_data, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag);
uint32_t * decoded_data_len,
uint32_t * decoded_rate,
unsigned int *flag);
typedef switch_status_t (*switch_core_codec_init_func_t) (switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings); typedef switch_status_t (*switch_core_codec_init_func_t) (switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings);
typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *); typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *);
@ -1255,7 +1247,8 @@ typedef struct switch_stream_handle switch_stream_handle_t;
typedef switch_status_t (*switch_stream_handle_write_function_t) (switch_stream_handle_t *handle, const char *fmt, ...); typedef switch_status_t (*switch_stream_handle_write_function_t) (switch_stream_handle_t *handle, const char *fmt, ...);
typedef switch_status_t (*switch_stream_handle_raw_write_function_t) (switch_stream_handle_t *handle, uint8_t *data, switch_size_t datalen); typedef switch_status_t (*switch_stream_handle_raw_write_function_t) (switch_stream_handle_t *handle, uint8_t *data, switch_size_t datalen);
typedef switch_status_t (*switch_api_function_t) (_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream); typedef switch_status_t (*switch_api_function_t) (_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session,
_In_ switch_stream_handle_t *stream);
#define SWITCH_STANDARD_API(name) static switch_status_t name (_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream) #define SWITCH_STANDARD_API(name) static switch_status_t name (_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream)
@ -1274,9 +1267,9 @@ typedef switch_status_t (*switch_say_callback_t) (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);
typedef struct switch_xml *switch_xml_t; typedef struct switch_xml *switch_xml_t;
typedef struct switch_core_time_duration switch_core_time_duration_t; typedef struct switch_core_time_duration switch_core_time_duration_t;
typedef switch_xml_t(*switch_xml_search_function_t) (const char *section, 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, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
void *user_data); void *user_data);
typedef struct switch_hash switch_hash_t; typedef struct switch_hash switch_hash_t;
struct HashElem; struct HashElem;
@ -1290,9 +1283,9 @@ typedef struct switch_network_list switch_network_list_t;
#define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) #define SWITCH_MODULE_LOAD_ARGS (switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)
#define SWITCH_MODULE_RUNTIME_ARGS (void) #define SWITCH_MODULE_RUNTIME_ARGS (void)
#define SWITCH_MODULE_SHUTDOWN_ARGS (void) #define SWITCH_MODULE_SHUTDOWN_ARGS (void)
typedef switch_status_t (*switch_module_load_t) SWITCH_MODULE_LOAD_ARGS ; typedef switch_status_t (*switch_module_load_t) SWITCH_MODULE_LOAD_ARGS;
typedef switch_status_t (*switch_module_runtime_t) SWITCH_MODULE_RUNTIME_ARGS ; typedef switch_status_t (*switch_module_runtime_t) SWITCH_MODULE_RUNTIME_ARGS;
typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS ; typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS;
#define SWITCH_MODULE_LOAD_FUNCTION(name) switch_status_t name SWITCH_MODULE_LOAD_ARGS #define SWITCH_MODULE_LOAD_FUNCTION(name) switch_status_t name SWITCH_MODULE_LOAD_ARGS
#define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS #define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
#define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS #define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS

View File

@ -54,15 +54,12 @@ SWITCH_BEGIN_EXTERN_C
#else #else
#define switch_is_file_path(file) (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))) #define switch_is_file_path(file) (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)))
#endif #endif
/*! /*!
\brief Test for NULL or zero length string \brief Test for NULL or zero length string
\param s the string to test \param s the string to test
\return true value if the string is NULL or zero length \return true value if the string is NULL or zero length
*/ */
#define switch_strlen_zero(s) (!s || *s == '\0') #define switch_strlen_zero(s) (!s || *s == '\0')
static inline switch_bool_t switch_is_moh(const char *s) static inline switch_bool_t switch_is_moh(const char *s)
{ {
if (switch_strlen_zero(s) || !strcasecmp(s, "silence") || !strcasecmp(s, "indicate_hold")) { if (switch_strlen_zero(s) || !strcasecmp(s, "silence") || !strcasecmp(s, "indicate_hold")) {
@ -78,9 +75,10 @@ SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size
SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size_t olen); SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size_t olen);
SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len); SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len);
static inline switch_bool_t switch_is_digit_string(const char *s) { static inline switch_bool_t switch_is_digit_string(const char *s)
{
while(s && *s) { while (s && *s) {
if (*s < 48 || *s > 57) { if (*s < 48 || *s > 57) {
return SWITCH_FALSE; return SWITCH_FALSE;
} }
@ -113,7 +111,8 @@ atoi(expr))) ? SWITCH_TRUE : SWITCH_FALSE
\param family the address family to return (AF_INET or AF_INET6) \param family the address family to return (AF_INET or AF_INET6)
\return SWITCH_STATUS_SUCCESSS for success, otherwise failure \return SWITCH_STATUS_SUCCESSS for success, otherwise failure
*/ */
SWITCH_DECLARE(switch_status_t) switch_find_local_ip(_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_ int family); SWITCH_DECLARE(switch_status_t) switch_find_local_ip(_Out_opt_bytecapcount_(len)
char *buf, _In_ int len, _In_ int family);
/*! /*!
\brief find the char representation of an ip adress \brief find the char representation of an ip adress
@ -205,7 +204,7 @@ switch_mutex_unlock(obj->flag_mutex);
#define switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst)) #define switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst))
static inline char *switch_clean_string(char *s) static inline char *switch_clean_string(char *s)
{ {
char *p; char *p;
for (p = s; p && *p; p++) { for (p = s; p && *p; p++) {
@ -247,11 +246,11 @@ static inline switch_bool_t switch_strstr(char *s, char *q)
} }
S = strdup(s); S = strdup(s);
assert(S != NULL); assert(S != NULL);
for (p = S; p && *p; p++) { for (p = S; p && *p; p++) {
*p = (char)toupper(*p); *p = (char) toupper(*p);
} }
if (strstr(S, q)) { if (strstr(S, q)) {
@ -263,9 +262,9 @@ static inline switch_bool_t switch_strstr(char *s, char *q)
assert(Q != NULL); assert(Q != NULL);
for (p = Q; p && *p; p++) { for (p = Q; p && *p; p++) {
*p = (char)toupper(*p); *p = (char) toupper(*p);
} }
if (strstr(s, Q)) { if (strstr(s, Q)) {
tf = SWITCH_TRUE; tf = SWITCH_TRUE;
goto done; goto done;
@ -275,8 +274,8 @@ static inline switch_bool_t switch_strstr(char *s, char *q)
tf = SWITCH_TRUE; tf = SWITCH_TRUE;
goto done; goto done;
} }
done: done:
switch_safe_free(S); switch_safe_free(S);
switch_safe_free(Q); switch_safe_free(Q);
@ -345,7 +344,7 @@ SWITCH_DECLARE(char *) switch_escape_char(switch_memory_pool_t *pool, char *in,
\param ms the number of milliseconds to wait \param ms the number of milliseconds to wait
\return the requested condition \return the requested condition
*/ */
SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t * poll, int ms); SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms);
/*! /*!
\brief Create a pointer to the file name in a given file path eliminating the directory name \brief Create a pointer to the file name in a given file path eliminating the directory name
@ -369,7 +368,7 @@ SWITCH_DECLARE(switch_status_t) switch_network_list_add_host_mask(switch_network
SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip(switch_network_list_t *list, uint32_t ip); SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip(switch_network_list_t *list, uint32_t ip);
#define switch_test_subnet(_ip, _net, _mask) (_mask ? ((_net & _mask) == (_ip & _mask)) : _net ? _net == _ip : 1) #define switch_test_subnet(_ip, _net, _mask) (_mask ? ((_net & _mask) == (_ip & _mask)) : _net ? _net == _ip : 1)
int switch_inet_pton(int af, const char *src, void *dst); int switch_inet_pton(int af, const char *src, void *dst);
/* malloc or DIE macros */ /* malloc or DIE macros */
#ifdef NDEBUG #ifdef NDEBUG

View File

@ -184,7 +184,7 @@ SWITCH_DECLARE(const char *) switch_xml_attr_soft(switch_xml_t xml, const char *
///\ Returns NULL if not found. ///\ Returns NULL if not found.
///\param xml the xml node ///\param xml the xml node
///\return an xml node or NULL ///\return an xml node or NULL
SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml,...); SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml, ...);
///\brief Converts an switch_xml structure back to xml. Returns a string of xml data that ///\brief Converts an switch_xml structure back to xml. Returns a string of xml data that
///\ must be freed. ///\ must be freed.
@ -234,7 +234,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_new(const char *name);
///\param name the name of the tag ///\param name the name of the tag
///\param off the offset ///\param off the offset
///\return an xml node or NULL ///\return an xml node or NULL
SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off); SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off);
///\brief wrapper for switch_xml_add_child() that strdup()s name ///\brief wrapper for switch_xml_add_child() that strdup()s name
///\param xml the xml node ///\param xml the xml node
@ -247,7 +247,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_new(const char *name);
///\param xml the xml node ///\param xml the xml node
///\param txt the text ///\param txt the text
///\return an xml node or NULL ///\return an xml node or NULL
SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *txt); SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *txt);
///\brief wrapper for switch_xml_set_txt() that strdup()s txt ///\brief wrapper for switch_xml_set_txt() that strdup()s txt
///\ sets the character content for the given tag and returns the tag ///\ sets the character content for the given tag and returns the tag
@ -324,25 +324,22 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_root(void);
///\return SWITCH_STATUS_SUCCESS if successful root and node will be assigned ///\return SWITCH_STATUS_SUCCESS if successful root and node will be assigned
SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section, SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
const char *tag_name, const char *tag_name,
const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node, const char *key_name, const char *key_value, switch_xml_t *root, switch_xml_t *node,
switch_event_t *params); switch_event_t *params);
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_DECLARE(switch_status_t) switch_xml_locate_user(const char *key, SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key,
const char *user_name, const char *user_name,
const char *domain_name, const char *domain_name,
const char *ip, const char *ip,
switch_xml_t *root, switch_xml_t *root, switch_xml_t *domain, switch_xml_t *user, switch_event_t *params);
switch_xml_t *domain,
switch_xml_t *user,
switch_event_t *params);
///\brief open a config in the core registry ///\brief open a config in the core registry
///\param file_path the name of the config section e.g. modules.conf ///\param file_path the name of the config section e.g. modules.conf
///\param node a pointer to point to the node if it is found ///\param node a pointer to point to the node if it is found
///\param params optional URL formatted params to pass to external gateways ///\param params optional URL formatted params to pass to external gateways
///\return the root xml node associated with the current request or NULL ///\return the root xml node associated with the current request or NULL
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t * node, switch_event_t *params); SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t *node, switch_event_t *params);
///\brief bind a search function to an external gateway ///\brief bind a search function to an external gateway
///\param function the search function to bind ///\param function the search function to bind

View File

@ -80,29 +80,29 @@ SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssi
/* DSO functions */ /* 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); return apr_dso_load(res_handle, path, ctx);
} }
SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t * handle) SWITCH_DECLARE(switch_status_t) switch_dso_unload(switch_dso_handle_t *handle)
{ {
return apr_dso_unload(handle); return apr_dso_unload(handle);
} }
SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t * ressym, switch_dso_handle_t * handle, const char *symname) SWITCH_DECLARE(switch_status_t) switch_dso_sym(switch_dso_handle_sym_t *ressym, switch_dso_handle_t *handle, const char *symname)
{ {
return apr_dso_sym(ressym, handle, symname); return apr_dso_sym(ressym, handle, symname);
} }
SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t * dso, char *buf, size_t bufsize) SWITCH_DECLARE(const char *) switch_dso_error(switch_dso_handle_t *dso, char *buf, size_t bufsize)
{ {
return apr_dso_error(dso, buf, bufsize); return apr_dso_error(dso, buf, bufsize);
} }
/* string functions */ /* string functions */
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) 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)
{ {
return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm); return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
} }
@ -124,7 +124,8 @@ SWITCH_DECLARE(int) switch_vsnprintf(char *buf, switch_size_t len, const char *f
SWITCH_DECLARE(char *) switch_copy_string(char *dst, const char *src, switch_size_t dst_size) SWITCH_DECLARE(char *) switch_copy_string(char *dst, const char *src, switch_size_t dst_size)
{ {
if (!dst) return NULL; if (!dst)
return NULL;
if (!src) { if (!src) {
*dst = '\0'; *dst = '\0';
return dst; return dst;
@ -134,69 +135,69 @@ SWITCH_DECLARE(char *) switch_copy_string(char *dst, const char *src, switch_siz
/* thread read write lock functions */ /* 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); return apr_thread_rwlock_create(rwlock, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_destroy(rwlock); return apr_thread_rwlock_destroy(rwlock);
} }
SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_memory_pool_t *) switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_pool_get(rwlock); return apr_thread_rwlock_pool_get(rwlock);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_rdlock(rwlock); return apr_thread_rwlock_rdlock(rwlock);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_tryrdlock(rwlock); return apr_thread_rwlock_tryrdlock(rwlock);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_wrlock(rwlock); return apr_thread_rwlock_wrlock(rwlock);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_trywrlock(rwlock); return apr_thread_rwlock_trywrlock(rwlock);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t * rwlock) SWITCH_DECLARE(switch_status_t) switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
{ {
return apr_thread_rwlock_unlock(rwlock); return apr_thread_rwlock_unlock(rwlock);
} }
/* thread mutex functions */ /* 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); return apr_thread_mutex_create(lock, flags, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t * lock) SWITCH_DECLARE(switch_status_t) switch_mutex_destroy(switch_mutex_t *lock)
{ {
return apr_thread_mutex_destroy(lock); return apr_thread_mutex_destroy(lock);
} }
SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t * lock) SWITCH_DECLARE(switch_status_t) switch_mutex_lock(switch_mutex_t *lock)
{ {
return apr_thread_mutex_lock(lock); return apr_thread_mutex_lock(lock);
} }
SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t * lock) SWITCH_DECLARE(switch_status_t) switch_mutex_unlock(switch_mutex_t *lock)
{ {
return apr_thread_mutex_unlock(lock); return apr_thread_mutex_unlock(lock);
} }
SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t * lock) SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t *lock)
{ {
return apr_thread_mutex_trylock(lock); return apr_thread_mutex_trylock(lock);
} }
@ -207,29 +208,29 @@ SWITCH_DECLARE(switch_time_t) switch_time_now(void)
{ {
#if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS) #if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS)
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_REALTIME,&ts); clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000); return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000);
#else #else
return (switch_time_t) apr_time_now(); return (switch_time_t) apr_time_now();
#endif #endif
} }
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt_get(switch_time_t * result, switch_time_exp_t * input) 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(result, (apr_time_exp_t *) input); return apr_time_exp_gmt_get(result, (apr_time_exp_t *) input);
} }
SWITCH_DECLARE(switch_status_t) switch_time_exp_get(switch_time_t * result, switch_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(result, (apr_time_exp_t *) input); return apr_time_exp_get(result, (apr_time_exp_t *) input);
} }
SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t * result, switch_time_t input) SWITCH_DECLARE(switch_status_t) switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
{ {
return apr_time_exp_lt((apr_time_exp_t *) result, input); return apr_time_exp_lt((apr_time_exp_t *) result, input);
} }
SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t * result, switch_time_t input) SWITCH_DECLARE(switch_status_t) switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
{ {
return apr_time_exp_gmt((apr_time_exp_t *) result, input); return apr_time_exp_gmt((apr_time_exp_t *) result, input);
} }
@ -246,45 +247,45 @@ SWITCH_DECLARE(switch_time_t) switch_time_make(switch_time_t sec, int32_t usec)
/* Thread condition locks */ /* 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); return apr_thread_cond_create(cond, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t * cond, switch_mutex_t * mutex) SWITCH_DECLARE(switch_status_t) switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
{ {
return apr_thread_cond_wait(cond, mutex); return apr_thread_cond_wait(cond, mutex);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t * cond, switch_mutex_t * mutex, switch_interval_time_t timeout) SWITCH_DECLARE(switch_status_t) switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout)
{ {
return apr_thread_cond_timedwait(cond, mutex, timeout); return apr_thread_cond_timedwait(cond, mutex, timeout);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t * cond) SWITCH_DECLARE(switch_status_t) switch_thread_cond_signal(switch_thread_cond_t *cond)
{ {
return apr_thread_cond_signal(cond); return apr_thread_cond_signal(cond);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t * cond) SWITCH_DECLARE(switch_status_t) switch_thread_cond_broadcast(switch_thread_cond_t *cond)
{ {
return apr_thread_cond_broadcast(cond); return apr_thread_cond_broadcast(cond);
} }
SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t * cond) SWITCH_DECLARE(switch_status_t) switch_thread_cond_destroy(switch_thread_cond_t *cond)
{ {
return apr_thread_cond_destroy(cond); return apr_thread_cond_destroy(cond);
} }
/* file i/o stubs */ /* 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) switch_memory_pool_t *pool)
{ {
return apr_file_open(newf, fname, flag, perm, pool); return apr_file_open(newf, fname, flag, perm, 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_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset)
{ {
apr_status_t rv; apr_status_t rv;
apr_off_t off = (apr_off_t) (*offset); apr_off_t off = (apr_off_t) (*offset);
@ -293,12 +294,12 @@ SWITCH_DECLARE(switch_status_t) switch_file_seek(switch_file_t * thefile, switch
return rv; return rv;
} }
SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t * thefile) SWITCH_DECLARE(switch_status_t) switch_file_close(switch_file_t *thefile)
{ {
return apr_file_close(thefile); return apr_file_close(thefile);
} }
SWITCH_DECLARE(switch_status_t) switch_file_lock(switch_file_t * thefile, int type) SWITCH_DECLARE(switch_status_t) switch_file_lock(switch_file_t *thefile, int type)
{ {
return apr_file_lock(thefile, type); return apr_file_lock(thefile, type);
} }
@ -313,12 +314,12 @@ SWITCH_DECLARE(switch_status_t) switch_file_remove(const char *path, switch_memo
return apr_file_remove(path, pool); return apr_file_remove(path, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t * thefile, void *buf, switch_size_t *nbytes) SWITCH_DECLARE(switch_status_t) switch_file_read(switch_file_t *thefile, void *buf, switch_size_t *nbytes)
{ {
return apr_file_read(thefile, buf, nbytes); return apr_file_read(thefile, buf, nbytes);
} }
SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes) SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t *thefile, const void *buf, switch_size_t *nbytes)
{ {
return apr_file_write(thefile, buf, nbytes); return apr_file_write(thefile, buf, nbytes);
} }
@ -341,7 +342,7 @@ SWITCH_DECLARE(switch_status_t) switch_file_mktemp(switch_file_t **thefile, char
SWITCH_DECLARE(switch_size_t) switch_file_get_size(switch_file_t *thefile) SWITCH_DECLARE(switch_size_t) switch_file_get_size(switch_file_t *thefile)
{ {
struct apr_finfo_t finfo; struct apr_finfo_t finfo;
return apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile) == SWITCH_STATUS_SUCCESS ? (switch_size_t)finfo.size : 0; return apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile) == SWITCH_STATUS_SUCCESS ? (switch_size_t) finfo.size : 0;
} }
SWITCH_DECLARE(switch_status_t) switch_directory_exists(const char *dirname, switch_memory_pool_t *pool) SWITCH_DECLARE(switch_status_t) switch_directory_exists(const char *dirname, switch_memory_pool_t *pool)
@ -380,7 +381,7 @@ SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_
if (filename) { if (filename) {
apr_stat(&info, filename, wanted, pool ? pool : our_pool); apr_stat(&info, filename, wanted, pool ? pool : our_pool);
if (info.filetype != APR_NOFILE) { if (info.filetype != APR_NOFILE) {
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
} }
@ -391,15 +392,12 @@ SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_dir_make(const char *path, switch_fileperms_t perm, SWITCH_DECLARE(switch_status_t) switch_dir_make(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
switch_memory_pool_t *pool)
{ {
return apr_dir_make(path, perm, pool); return apr_dir_make(path, perm, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_dir_make_recursive(const char *path, SWITCH_DECLARE(switch_status_t) switch_dir_make_recursive(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
switch_fileperms_t perm,
switch_memory_pool_t *pool)
{ {
return apr_dir_make_recursive(path, perm, pool); return apr_dir_make_recursive(path, perm, pool);
} }
@ -427,7 +425,7 @@ SWITCH_DECLARE(switch_status_t) switch_dir_open(switch_dir_t **new_dir, const ch
*new_dir = NULL; *new_dir = NULL;
} }
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_dir_close(switch_dir_t *thedir) SWITCH_DECLARE(switch_status_t) switch_dir_close(switch_dir_t *thedir)
@ -438,7 +436,7 @@ SWITCH_DECLARE(switch_status_t) switch_dir_close(switch_dir_t *thedir)
return status; return status;
} }
SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len) SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len)
{ {
const char *fname = NULL; const char *fname = NULL;
apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME; apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
@ -471,25 +469,25 @@ SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *bu
/* thread stubs */ /* 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); return apr_threadattr_create(new_attr, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t * attr, int32_t on) SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
{ {
return apr_threadattr_detach_set(attr, on); return apr_threadattr_detach_set(attr, on);
} }
SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t * attr, switch_size_t stacksize) SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
{ {
return apr_threadattr_stacksize_set(attr, stacksize); return apr_threadattr_stacksize_set(attr, stacksize);
} }
#ifndef WIN32 #ifndef WIN32
struct apr_threadattr_t { struct apr_threadattr_t {
apr_pool_t *pool; apr_pool_t *pool;
pthread_attr_t attr; pthread_attr_t attr;
}; };
#endif #endif
@ -497,23 +495,22 @@ SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threa
{ {
int stat = 0; int stat = 0;
#ifndef WIN32 #ifndef WIN32
struct sched_param param; struct sched_param param;
struct apr_threadattr_t *myattr = attr; struct apr_threadattr_t *myattr = attr;
pthread_attr_getschedparam(&myattr->attr, &param); pthread_attr_getschedparam(&myattr->attr, &param);
param.sched_priority = 50; param.sched_priority = 50;
stat = pthread_attr_setschedparam(&myattr->attr, &param); stat = pthread_attr_setschedparam(&myattr->attr, &param);
if (stat == 0) { if (stat == 0) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#endif #endif
return stat; return stat;
} }
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_thread_start_t func, void *data, switch_memory_pool_t *cont)
{ {
return apr_thread_create(new_thread, attr, func, data, cont); return apr_thread_create(new_thread, attr, func, data, cont);
@ -526,42 +523,42 @@ SWITCH_DECLARE(switch_status_t) switch_socket_addr_get(switch_sockaddr_t **sa, s
return apr_socket_addr_get(sa, remote, 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); return apr_socket_create(new_sock, family, type, protocol, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t * sock, switch_shutdown_how_e how) SWITCH_DECLARE(switch_status_t) switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
{ {
return apr_socket_shutdown(sock, (apr_shutdown_how_e)how); return apr_socket_shutdown(sock, (apr_shutdown_how_e) how);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t * sock) SWITCH_DECLARE(switch_status_t) switch_socket_close(switch_socket_t *sock)
{ {
return apr_socket_close(sock); return apr_socket_close(sock);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t * sock, switch_sockaddr_t * sa) SWITCH_DECLARE(switch_status_t) switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
{ {
return apr_socket_bind(sock, sa); return apr_socket_bind(sock, sa);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t * sock, int32_t backlog) SWITCH_DECLARE(switch_status_t) switch_socket_listen(switch_socket_t *sock, int32_t backlog)
{ {
return apr_socket_listen(sock, backlog); 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); return apr_socket_accept(new_sock, sock, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t * sock, switch_sockaddr_t * sa) SWITCH_DECLARE(switch_status_t) switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa)
{ {
return apr_socket_connect(sock, sa); return apr_socket_connect(sock, sa);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t * sock, const char *buf, switch_size_t *len) SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len)
{ {
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_size_t req = *len, wrote = 0, need = *len; switch_size_t req = *len, wrote = 0, need = *len;
@ -585,7 +582,7 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t * sock, const
return status; 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) { if (!where || !buf || !len || !*len) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
@ -593,33 +590,33 @@ SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t * sock, swi
return apr_socket_sendto(sock, where, flags, buf, len); return apr_socket_sendto(sock, where, flags, buf, len);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t * sock, char *buf, switch_size_t *len) SWITCH_DECLARE(switch_status_t) switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
{ {
return apr_socket_recv(sock, buf, len); 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) switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
{ {
return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool); return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t * sock, int32_t opt, int32_t on) SWITCH_DECLARE(switch_status_t) switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
{ {
return apr_socket_opt_set(sock, opt, on); return apr_socket_opt_set(sock, opt, on);
} }
SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t * sock, switch_interval_time_t t) SWITCH_DECLARE(switch_status_t) switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t)
{ {
return apr_socket_timeout_set(sock, t); return apr_socket_timeout_set(sock, t);
} }
SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t * sa) SWITCH_DECLARE(switch_status_t) switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa)
{ {
return apr_sockaddr_ip_get(addr, sa); return apr_sockaddr_ip_get(addr, sa);
} }
SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch_sockaddr_t * join, switch_sockaddr_t * iface, switch_sockaddr_t * source) SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
{ {
return apr_mcast_join(sock, join, iface, source); return apr_mcast_join(sock, join, iface, source);
} }
@ -627,7 +624,7 @@ SWITCH_DECLARE(switch_status_t) switch_mcast_join(switch_socket_t * sock, switch
/* socket functions */ /* socket functions */
SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t * in) SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
{ {
if (!in) { if (!in) {
return ""; return "";
@ -635,52 +632,52 @@ SWITCH_DECLARE(const char *) switch_get_addr(char *buf, switch_size_t len, switc
return get_addr(buf, len, &in->sa.sin.sin_addr); return get_addr(buf, len, &in->sa.sin.sin_addr);
} }
SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t * sa) SWITCH_DECLARE(uint16_t) switch_sockaddr_get_port(switch_sockaddr_t *sa)
{ {
return sa->port; return sa->port;
} }
SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t * sa) SWITCH_DECLARE(int32_t) switch_sockaddr_get_family(switch_sockaddr_t *sa)
{ {
return sa->family; return sa->family;
} }
SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t * from, switch_socket_t * sock, int32_t flags, char *buf, size_t *len) SWITCH_DECLARE(switch_status_t) switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
{ {
apr_status_t r; apr_status_t r;
if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) { if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
from->port = ntohs(from->sa.sin.sin_port); from->port = ntohs(from->sa.sin.sin_port);
/* from->ipaddr_ptr = &(from->sa.sin.sin_addr); /* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
* from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr); * from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
*/ */
}
if (r == 35) {
r = SWITCH_STATUS_BREAK;
} }
if (r == 35 ) {
r = SWITCH_STATUS_BREAK;
}
return r; return r;
} }
/* poll stubs */ /* 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); return apr_pollset_create(pollset, size, p, flags);
} }
SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t * pollset, const switch_pollfd_t * descriptor) SWITCH_DECLARE(switch_status_t) switch_pollset_add(switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
{ {
return apr_pollset_add(pollset, descriptor); return apr_pollset_add(pollset, descriptor);
} }
SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t * aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout) SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
{ {
return apr_poll(aprset, numsock, nsds, timeout); return apr_poll(aprset, numsock, nsds, timeout);
} }
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; switch_pollset_t *pollset;
@ -713,39 +710,39 @@ SWITCH_DECLARE(switch_status_t) switch_socket_create_pollfd(switch_pollfd_t ** p
/* UUID Handling (apr-util) */ /* UUID Handling (apr-util) */
SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t * uuid) SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
{ {
apr_uuid_format(buffer, (const apr_uuid_t *) uuid); apr_uuid_format(buffer, (const apr_uuid_t *) uuid);
} }
SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t * uuid) SWITCH_DECLARE(void) switch_uuid_get(switch_uuid_t *uuid)
{ {
apr_uuid_get((apr_uuid_t *) uuid); apr_uuid_get((apr_uuid_t *) uuid);
} }
SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t * uuid, const char *uuid_str) SWITCH_DECLARE(switch_status_t) switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str)
{ {
return apr_uuid_parse((apr_uuid_t *) uuid, uuid_str); return apr_uuid_parse((apr_uuid_t *) uuid, uuid_str);
} }
/* FIFO queues (apr-util) */ /* 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); return apr_queue_create(queue, queue_capacity, pool);
} }
SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t * queue) SWITCH_DECLARE(unsigned int) switch_queue_size(switch_queue_t *queue)
{ {
return apr_queue_size(queue); return apr_queue_size(queue);
} }
SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t * queue, void **data) SWITCH_DECLARE(switch_status_t) switch_queue_pop(switch_queue_t *queue, void **data)
{ {
return apr_queue_pop(queue, data); return apr_queue_pop(queue, data);
} }
SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t * queue, void *data) SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t *queue, void *data)
{ {
apr_status_t s; apr_status_t s;
@ -756,12 +753,12 @@ SWITCH_DECLARE(switch_status_t) switch_queue_push(switch_queue_t * queue, void *
return s; return s;
} }
SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t * queue, void **data) SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data)
{ {
return apr_queue_trypop(queue, data); return apr_queue_trypop(queue, data);
} }
SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t * queue, void *data) SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void *data)
{ {
apr_status_t s; apr_status_t s;
@ -810,9 +807,9 @@ SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap)
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); return apr_match_glob(pattern, (apr_array_header_t **) result, p);
} }
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c

View File

@ -280,7 +280,7 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_zwrite(switch_buffer_t *buffer, cons
SWITCH_DECLARE(void) switch_buffer_destroy(switch_buffer_t **buffer) SWITCH_DECLARE(void) switch_buffer_destroy(switch_buffer_t **buffer)
{ {
if (buffer && *buffer) { if (buffer && *buffer) {
if ((switch_test_flag((*buffer), SWITCH_BUFFER_FLAG_DYNAMIC))) { if ((switch_test_flag((*buffer), SWITCH_BUFFER_FLAG_DYNAMIC))) {
switch_safe_free((*buffer)->data); switch_safe_free((*buffer)->data);
free(*buffer); free(*buffer);

View File

@ -44,16 +44,14 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memor
const char *network_addr, const char *network_addr,
const char *ani, const char *ani,
const char *aniii, const char *aniii,
const char *rdnis, const char *rdnis,
const char *source, const char *source, const char *context, const char *destination_number)
const char *context,
const char *destination_number)
{ {
switch_caller_profile_t *profile = NULL; switch_caller_profile_t *profile = NULL;
profile = switch_core_alloc(pool, sizeof(*profile)); profile = switch_core_alloc(pool, sizeof(*profile));
switch_assert(profile != NULL); switch_assert(profile != NULL);
if (!context) { if (!context) {
context = "default"; context = "default";
} }
@ -276,7 +274,8 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_
switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "yes" : "no"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "yes" : "no");
} }
SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session, const char *extension_name, const char *extension_number) SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_core_session_t *session, const char *extension_name,
const char *extension_number)
{ {
switch_caller_extension_t *caller_extension = NULL; switch_caller_extension_t *caller_extension = NULL;
@ -290,7 +289,8 @@ SWITCH_DECLARE(switch_caller_extension_t *) switch_caller_extension_new(switch_c
} }
SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session_t *session, SWITCH_DECLARE(void) switch_caller_extension_add_application(switch_core_session_t *session,
switch_caller_extension_t *caller_extension, const char *application_name, const char *application_data) switch_caller_extension_t *caller_extension, const char *application_name,
const char *application_data)
{ {
switch_caller_application_t *caller_application = NULL; switch_caller_application_t *caller_application = NULL;

View File

@ -130,7 +130,7 @@ SWITCH_DECLARE(const char *) switch_channel_cause2str(switch_call_cause_t cause)
uint8_t x; uint8_t x;
const char *str = "UNKNOWN"; const char *str = "UNKNOWN";
for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) -1 ; x++) { for (x = 0; x < (sizeof(CAUSE_CHART) / sizeof(struct switch_cause_table)) - 1; x++) {
if (CAUSE_CHART[x].cause == cause) { if (CAUSE_CHART[x].cause == cause) {
str = CAUSE_CHART[x].name; str = CAUSE_CHART[x].name;
break; break;
@ -214,12 +214,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
switch_status_t status; switch_status_t status;
void *pop; void *pop;
switch_dtmf_t new_dtmf; switch_dtmf_t new_dtmf;
switch_assert(dtmf); switch_assert(dtmf);
switch_mutex_lock(channel->dtmf_mutex); switch_mutex_lock(channel->dtmf_mutex);
new_dtmf = *dtmf; new_dtmf = *dtmf;
if ((status = switch_core_session_recv_dtmf(channel->session, dtmf) != SWITCH_STATUS_SUCCESS)) { if ((status = switch_core_session_recv_dtmf(channel->session, dtmf) != SWITCH_STATUS_SUCCESS)) {
goto done; goto done;
} }
@ -229,13 +229,13 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
int x = 0; int x = 0;
if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n",
switch_channel_get_name(channel), new_dtmf.digit, new_dtmf.duration); switch_channel_get_name(channel), new_dtmf.digit, new_dtmf.duration);
new_dtmf.duration = switch_core_max_dtmf_duration(0); new_dtmf.duration = switch_core_max_dtmf_duration(0);
} else if (!new_dtmf.duration) { } else if (!new_dtmf.duration) {
new_dtmf.duration = switch_core_default_dtmf_duration(0); new_dtmf.duration = switch_core_default_dtmf_duration(0);
} }
switch_zmalloc(dt, sizeof(*dt)); switch_zmalloc(dt, sizeof(*dt));
*dt = new_dtmf; *dt = new_dtmf;
@ -251,7 +251,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
done: done:
switch_mutex_unlock(channel->dtmf_mutex); switch_mutex_unlock(channel->dtmf_mutex);
@ -261,7 +261,7 @@ done:
SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string) SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string)
{ {
char *p; char *p;
switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)}; switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
int sent = 0, dur; int sent = 0, dur;
char *string; char *string;
int i, argc; int i, argc;
@ -274,7 +274,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_
string = switch_core_session_strdup(channel->session, dtmf_string); string = switch_core_session_strdup(channel->session, dtmf_string);
argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
for(i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
dtmf.duration = switch_core_default_dtmf_duration(0); dtmf.duration = switch_core_default_dtmf_duration(0);
dur = switch_core_default_dtmf_duration(0) / 8; dur = switch_core_default_dtmf_duration(0) / 8;
if ((p = strchr(argv[i], '@'))) { if ((p = strchr(argv[i], '@'))) {
@ -297,7 +297,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_
dtmf.digit = *p; dtmf.digit = *p;
if (switch_channel_queue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) { if (switch_channel_queue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Queue dtmf\ndigit=%c ms=%u samples=%u\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Queue dtmf\ndigit=%c ms=%u samples=%u\n",
switch_channel_get_name(channel), dtmf.digit, dur, dtmf.duration); switch_channel_get_name(channel), dtmf.digit, dur, dtmf.duration);
sent++; sent++;
} }
} }
@ -323,7 +323,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *ch
free(dt); free(dt);
if (dtmf->duration > switch_core_max_dtmf_duration(0)) { if (dtmf->duration > switch_core_max_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n",
switch_channel_get_name(channel), dtmf->digit, dtmf->duration); switch_channel_get_name(channel), dtmf->digit, dtmf->duration);
dtmf->duration = switch_core_max_dtmf_duration(0); dtmf->duration = switch_core_max_dtmf_duration(0);
} else if (!dtmf->duration) { } else if (!dtmf->duration) {
@ -347,11 +347,11 @@ SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *ch
SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf_string(switch_channel_t *channel, char *dtmf_str, switch_size_t len) SWITCH_DECLARE(switch_size_t) switch_channel_dequeue_dtmf_string(switch_channel_t *channel, char *dtmf_str, switch_size_t len)
{ {
switch_size_t x = 0; switch_size_t x = 0;
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
memset(dtmf_str, 0, len); memset(dtmf_str, 0, len);
while(x < len - 1 && switch_channel_dequeue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) { while (x < len - 1 && switch_channel_dequeue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
dtmf_str[x++] = dtmf.digit; dtmf_str[x++] = dtmf.digit;
} }
@ -363,7 +363,7 @@ SWITCH_DECLARE(void) switch_channel_flush_dtmf(switch_channel_t *channel)
{ {
void *pop; void *pop;
switch_mutex_lock(channel->dtmf_mutex); switch_mutex_lock(channel->dtmf_mutex);
while(switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_safe_free(pop); switch_safe_free(pop);
} }
switch_mutex_unlock(channel->dtmf_mutex); switch_mutex_unlock(channel->dtmf_mutex);
@ -426,7 +426,7 @@ SWITCH_DECLARE(const char *) switch_channel_get_variable(switch_channel_t *chann
switch_assert(channel != NULL); switch_assert(channel != NULL);
switch_mutex_lock(channel->profile_mutex); switch_mutex_lock(channel->profile_mutex);
if (!channel->variables || !(v = switch_event_get_header(channel->variables, (char*)varname))) { if (!channel->variables || !(v = switch_event_get_header(channel->variables, (char *) varname))) {
switch_caller_profile_t *cp = channel->caller_profile; switch_caller_profile_t *cp = channel->caller_profile;
if (cp) { if (cp) {
@ -551,7 +551,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *ch
switch_event_del_header(channel->variables, varname); switch_event_del_header(channel->variables, varname);
if (!switch_strlen_zero(value)) { if (!switch_strlen_zero(value)) {
switch_event_add_header(channel->variables, SWITCH_STACK_BOTTOM, varname, "%s", value); switch_event_add_header(channel->variables, SWITCH_STACK_BOTTOM, varname, "%s", value);
} }
switch_mutex_unlock(channel->profile_mutex); switch_mutex_unlock(channel->profile_mutex);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -634,7 +634,7 @@ SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, sw
switch_channel_state_t state, mystate, ostate; switch_channel_state_t state, mystate, ostate;
ostate = switch_channel_get_state(channel); ostate = switch_channel_get_state(channel);
for(;;) { for (;;) {
state = switch_channel_get_running_state(other_channel); state = switch_channel_get_running_state(other_channel);
mystate = switch_channel_get_running_state(channel); mystate = switch_channel_get_running_state(channel);
@ -652,7 +652,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *c
to++; to++;
} }
for(;;) { for (;;) {
if (pres) { if (pres) {
if (switch_test_flag(channel, want_flag)) { if (switch_test_flag(channel, want_flag)) {
break; break;
@ -723,9 +723,9 @@ SWITCH_DECLARE(uint8_t) switch_channel_ready(switch_channel_t *channel)
switch_assert(channel != NULL); switch_assert(channel != NULL);
if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET && if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET &&
!switch_test_flag(channel, CF_TRANSFER)) { !switch_test_flag(channel, CF_TRANSFER)) {
ret++; ret++;
} }
return ret; return ret;
@ -769,8 +769,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(
const char *file, const char *func, int line) const char *file, const char *func, int line)
{ {
switch_mutex_lock(channel->flag_mutex); switch_mutex_lock(channel->flag_mutex);
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s Running State Change %s\n", switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s Running State Change %s\n", channel->name, state_names[state]);
channel->name, state_names[state]);
channel->running_state = state; channel->running_state = state;
if (channel->state_flags) { if (channel->state_flags) {
@ -797,7 +796,8 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", "%s", (char *) state_num); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", "%s", (char *) state_num);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", "%s", channel->name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", "%s", channel->name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", "%s", switch_core_session_get_uuid(channel->session)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", "%s", switch_core_session_get_uuid(channel->session));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Call-Direction", "%s", switch_channel_test_flag(channel, CF_OUTBOUND) ? "outbound" : "inbound"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Call-Direction", "%s",
switch_channel_test_flag(channel, CF_OUTBOUND) ? "outbound" : "inbound");
if (switch_channel_test_flag(channel, CF_ANSWERED)) { if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");
} else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) { } else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
@ -837,172 +837,172 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
} }
/* STUB for more dev /* STUB for more dev
case CS_INIT: case CS_INIT:
switch(state) { switch(state) {
case CS_NEW: case CS_NEW:
case CS_INIT: case CS_INIT:
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_HANGUP: case CS_HANGUP:
case CS_DONE: case CS_DONE:
default: default:
break; break;
} }
break; break;
*/ */
switch (last_state) { switch (last_state) {
case CS_NEW: case CS_NEW:
case CS_RESET: case CS_RESET:
switch (state) { switch (state) {
default: default:
ok++; ok++;
break; break;
} }
break; break;
case CS_INIT: case CS_INIT:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_PARK: case CS_PARK:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
switch (state) { switch (state) {
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_PARK: case CS_PARK:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_PARK: case CS_PARK:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_PARK: case CS_PARK:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
case CS_PARK: case CS_PARK:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_HIBERNATE: case CS_HIBERNATE:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_INIT: case CS_INIT:
case CS_ROUTING: case CS_ROUTING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_PARK: case CS_PARK:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
case CS_RESET: case CS_RESET:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_ROUTING: case CS_ROUTING:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_EXECUTE: case CS_EXECUTE:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_PARK: case CS_PARK:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_EXECUTE: case CS_EXECUTE:
switch (state) { switch (state) {
case CS_EXCHANGE_MEDIA: case CS_EXCHANGE_MEDIA:
case CS_SOFT_EXECUTE: case CS_SOFT_EXECUTE:
case CS_ROUTING: case CS_ROUTING:
case CS_PARK: case CS_PARK:
case CS_CONSUME_MEDIA: case CS_CONSUME_MEDIA:
case CS_HIBERNATE: case CS_HIBERNATE:
case CS_RESET: case CS_RESET:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_HANGUP: case CS_HANGUP:
switch (state) { switch (state) {
case CS_DONE: case CS_DONE:
ok++; ok++;
default: default:
break; break;
} }
break; break;
default: default:
break; break;
} }
if (ok) { if (ok) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s State Change %s -> %s\n", switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG, "%s State Change %s -> %s\n",
channel->name, state_names[last_state], state_names[state]); channel->name, state_names[last_state], state_names[state]);
switch_mutex_lock(channel->flag_mutex); switch_mutex_lock(channel->flag_mutex);
channel->state = state; channel->state = state;
switch_mutex_unlock(channel->flag_mutex); switch_mutex_unlock(channel->flag_mutex);
@ -1016,12 +1016,12 @@ default:
} }
} else { } else {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING, switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_WARNING,
"%s Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]); "%s Invalid State Change %s -> %s\n", channel->name, state_names[last_state], state_names[state]);
/* we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee! */ /* we won't tolerate an invalid state change so we can make sure we are as robust as a nice cup of dark coffee! */
/* not cool lets crash this bad boy and figure out wtf is going on */ /* not cool lets crash this bad boy and figure out wtf is going on */
switch_assert(channel->state >= CS_HANGUP); switch_assert(channel->state >= CS_HANGUP);
} }
done: done:
switch_mutex_unlock(channel->flag_mutex); switch_mutex_unlock(channel->flag_mutex);
return channel->state; return channel->state;
@ -1081,7 +1081,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel_t *channel, sw
/* Index Originator's Profile */ /* Index Originator's Profile */
if (originator_caller_profile) { if (originator_caller_profile) {
switch_caller_profile_event_set_data(originator_caller_profile, "Other-Leg", event); switch_caller_profile_event_set_data(originator_caller_profile, "Other-Leg", event);
} else if (originatee_caller_profile) { /* Index Originatee's Profile */ } else if (originatee_caller_profile) { /* Index Originatee's Profile */
switch_caller_profile_event_set_data(originatee_caller_profile, "Other-Leg", event); switch_caller_profile_event_set_data(originatee_caller_profile, "Other-Leg", event);
} }
} }
@ -1152,7 +1152,7 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel
caller_profile->next = channel->caller_profile; caller_profile->next = channel->caller_profile;
channel->caller_profile = caller_profile; channel->caller_profile = caller_profile;
caller_profile->profile_index = switch_core_sprintf(caller_profile->pool, "%d", ++channel->profile_index); caller_profile->profile_index = switch_core_sprintf(caller_profile->pool, "%d", ++channel->profile_index);
switch_mutex_unlock(channel->profile_mutex); switch_mutex_unlock(channel->profile_mutex);
} }
@ -1190,7 +1190,7 @@ SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel
channel->caller_profile->originatee_caller_profile = caller_profile; channel->caller_profile->originatee_caller_profile = caller_profile;
} }
switch_assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile); switch_assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile);
switch_mutex_unlock(channel->profile_mutex); switch_mutex_unlock(channel->profile_mutex);
} }
SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originator_caller_profile(switch_channel_t *channel) SWITCH_DECLARE(switch_caller_profile_t *) switch_channel_get_originator_caller_profile(switch_channel_t *channel)
@ -1249,7 +1249,7 @@ SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel,
channel->state_handlers[index] = state_handler; channel->state_handlers[index] = state_handler;
end: end:
switch_mutex_unlock(channel->flag_mutex); switch_mutex_unlock(channel->flag_mutex);
return index; return index;
} }
@ -1347,7 +1347,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan
channel->state = CS_HANGUP; channel->state = CS_HANGUP;
channel->hangup_cause = hangup_cause; channel->hangup_cause = hangup_cause;
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n", switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n",
channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause)); channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_HANGUP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", "%s", switch_channel_cause2str(channel->hangup_cause)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Hangup-Cause", "%s", switch_channel_cause2str(channel->hangup_cause));
switch_channel_event_set_data(channel, event); switch_channel_event_set_data(channel, event);
@ -1408,12 +1408,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_pre_answered(switch_
} }
/* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send /* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send
a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
*/ */
if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE)) if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) { && (other_session = switch_core_session_locate(uuid))) {
switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK); switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
switch_core_session_rwunlock(other_session); switch_core_session_rwunlock(other_session);
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1443,7 +1443,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_pre_answer(switch_channel
msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS; msg.message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
msg.from = channel->name; msg.from = channel->name;
status = switch_core_session_receive_message(channel->session, &msg); status = switch_core_session_receive_message(channel->session, &msg);
if (status == SWITCH_STATUS_SUCCESS) { if (status == SWITCH_STATUS_SUCCESS) {
switch_channel_perform_mark_pre_answered(channel, file, func, line); switch_channel_perform_mark_pre_answered(channel, file, func, line);
} else { } else {
@ -1515,12 +1515,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_chan
} }
/* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send /* if we're the child of another channel and the other channel is in a blocking read they will never realize we have answered so send
a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel a SWITCH_SIG_BREAK to interrupt any blocking reads on that channel
*/ */
if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE)) if ((uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_VARIABLE))
&& (other_session = switch_core_session_locate(uuid))) { && (other_session = switch_core_session_locate(uuid))) {
switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK); switch_core_session_kill_channel(other_session, SWITCH_SIG_BREAK);
switch_core_session_rwunlock(other_session); switch_core_session_rwunlock(other_session);
} }
switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER"); switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
@ -1588,16 +1588,16 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
int nv = 0; int nv = 0;
if (switch_strlen_zero(in)) { if (switch_strlen_zero(in)) {
return (char *)in; return (char *) in;
} }
q = in; q = in;
while(q && *q) { while (q && *q) {
if (!(p = strchr(q, '$'))) { if (!(p = strchr(q, '$'))) {
break; break;
} }
if (*(p+1) != '{') { if (*(p + 1) != '{') {
q = p + 1; q = p + 1;
continue; continue;
} }
@ -1607,10 +1607,10 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
} }
if (!nv) { if (!nv) {
return (char *)in; return (char *) in;
} }
nv = 0; nv = 0;
olen = strlen(in) + 1; olen = strlen(in) + 1;
indup = strdup(in); indup = strdup(in);
@ -1633,8 +1633,8 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
} }
if (*p == '$' && !nv) { if (*p == '$' && !nv) {
if (*(p+1)) { if (*(p + 1)) {
if (*(p+1) == '{') { if (*(p + 1) == '{') {
vtype = 1; vtype = 1;
} else { } else {
nv = 1; nv = 1;
@ -1686,12 +1686,12 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
if ((vval = strchr(vname, '('))) { if ((vval = strchr(vname, '('))) {
e = vval - 1; e = vval - 1;
*vval++ = '\0'; *vval++ = '\0';
while(*e == ' ') { while (*e == ' ') {
*e-- = '\0'; *e-- = '\0';
} }
e = vval; e = vval;
br = 1; br = 1;
while(e && *e) { while (e && *e) {
if (*e == '(') { if (*e == '(') {
br++; br++;
} else if (br > 1 && *e == ')') { } else if (br > 1 && *e == ')') {
@ -1712,7 +1712,7 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
int ooffset = 0; int ooffset = 0;
char *ptr; char *ptr;
if ((expanded = switch_channel_expand_variables(channel, (char *)vname)) == vname) { if ((expanded = switch_channel_expand_variables(channel, (char *) vname)) == vname) {
expanded = NULL; expanded = NULL;
} else { } else {
vname = expanded; vname = expanded;
@ -1735,12 +1735,12 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
if (offset >= 0) { if (offset >= 0) {
sub_val += offset; sub_val += offset;
} else if ((size_t)abs(offset) <= strlen(sub_val)) { } else if ((size_t) abs(offset) <= strlen(sub_val)) {
sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset); sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset);
} }
if (ooffset > 0 && (size_t)ooffset < strlen(sub_val)) { if (ooffset > 0 && (size_t) ooffset < strlen(sub_val)) {
if ((ptr = (char *)sub_val + ooffset)) { if ((ptr = (char *) sub_val + ooffset)) {
*ptr = '\0'; *ptr = '\0';
} }
} }
@ -1756,7 +1756,7 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
if (stream.data) { if (stream.data) {
char *expanded_vname = NULL; char *expanded_vname = NULL;
if ((expanded_vname = switch_channel_expand_variables(channel, (char *)vname)) == vname) { if ((expanded_vname = switch_channel_expand_variables(channel, (char *) vname)) == vname) {
expanded_vname = NULL; expanded_vname = NULL;
} else { } else {
vname = expanded_vname; vname = expanded_vname;
@ -1782,7 +1782,7 @@ SWITCH_DECLARE(char *) switch_channel_expand_variables(switch_channel_t *channel
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
free(data); free(data);
free(indup); free(indup);
return (char *)in; return (char *) in;
} }
} }
if ((nlen = sub_val ? strlen(sub_val) : 0)) { if ((nlen = sub_val ? strlen(sub_val) : 0)) {
@ -1830,7 +1830,8 @@ SWITCH_DECLARE(char *) switch_channel_build_param_string(switch_channel_t *chann
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
switch_size_t encode_len = 1024, new_len = 0; switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL; char *encode_buf = NULL;
const char *prof[12] = { 0 }, *prof_names[12] = {0}; const char *prof[12] = { 0 }, *prof_names[12] = {
0};
char *e = NULL; char *e = NULL;
switch_event_header_t *hi; switch_event_header_t *hi;
uint32_t x = 0; uint32_t x = 0;
@ -1938,7 +1939,8 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
char start[80] = "", answer[80] = "", progress[80] = "", progress_media[80] = "", end[80] = "", tmp[80] = "", profile_start[80] = ""; char start[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 duration = 0, legbillsec = 0, billsec = 0, mduration = 0, billmsec = 0, legbillmsec = 0, progressmsec = 0, progress_mediamsec = 0;
switch_time_t uduration = 0, legbillusec = 0, billusec = 0, progresssec = 0, progressusec = 0, progress_mediasec = 0, progress_mediausec = 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_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;
if (!(caller_profile = switch_channel_get_caller_profile(channel)) || !channel->variables) { if (!(caller_profile = switch_channel_get_caller_profile(channel)) || !channel->variables) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -1949,13 +1951,13 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
last_app = ap->app; last_app = ap->app;
last_arg = ap->arg; last_arg = ap->arg;
} }
if (!(ocp = switch_channel_get_originatee_caller_profile(channel))) { if (!(ocp = switch_channel_get_originatee_caller_profile(channel))) {
ocp = switch_channel_get_originator_caller_profile(channel); ocp = switch_channel_get_originator_caller_profile(channel);
} }
if (!switch_strlen_zero(caller_profile->caller_id_name)) { if (!switch_strlen_zero(caller_profile->caller_id_name)) {
cid_buf = switch_core_session_sprintf(channel->session, "\"%s\" <%s>", caller_profile->caller_id_name, cid_buf = switch_core_session_sprintf(channel->session, "\"%s\" <%s>", caller_profile->caller_id_name,
switch_str_nil(caller_profile->caller_id_number)); switch_str_nil(caller_profile->caller_id_number));
} else { } else {
cid_buf = caller_profile->caller_id_number; cid_buf = caller_profile->caller_id_number;
@ -2016,21 +2018,21 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_answered); switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_answered);
switch_channel_set_variable(channel, "answer_epoch", tmp); switch_channel_set_variable(channel, "answer_epoch", tmp);
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered); switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
switch_channel_set_variable(channel, "answer_uepoch", tmp); switch_channel_set_variable(channel, "answer_uepoch", tmp);
tt_progress = (time_t) (caller_profile->times->progress / 1000000); tt_progress = (time_t) (caller_profile->times->progress / 1000000);
mtt_progress = (time_t) (caller_profile->times->progress / 1000); mtt_progress = (time_t) (caller_profile->times->progress / 1000);
switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress); switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress);
switch_channel_set_variable(channel, "answer_epoch", tmp); switch_channel_set_variable(channel, "answer_epoch", tmp);
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress); switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
switch_channel_set_variable(channel, "answer_uepoch", tmp); switch_channel_set_variable(channel, "answer_uepoch", tmp);
tt_progress_media = (time_t) (caller_profile->times->progress_media / 1000000); tt_progress_media = (time_t) (caller_profile->times->progress_media / 1000000);
mtt_progress_media = (time_t) (caller_profile->times->progress_media / 1000); mtt_progress_media = (time_t) (caller_profile->times->progress_media / 1000);
switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress_media); switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress_media);
switch_channel_set_variable(channel, "answer_epoch", tmp); switch_channel_set_variable(channel, "answer_epoch", tmp);
switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media); switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
switch_channel_set_variable(channel, "answer_uepoch", tmp); switch_channel_set_variable(channel, "answer_uepoch", tmp);
tt_hungup = (time_t) (caller_profile->times->hungup / 1000000); tt_hungup = (time_t) (caller_profile->times->hungup / 1000000);
@ -2041,28 +2043,28 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_timestamps(switch_channel_t *
switch_channel_set_variable(channel, "end_uepoch", tmp); switch_channel_set_variable(channel, "end_uepoch", tmp);
uduration = caller_profile->times->hungup - caller_profile->times->created; uduration = caller_profile->times->hungup - caller_profile->times->created;
duration = (int32_t)(tt_hungup - tt_created); duration = (int32_t) (tt_hungup - tt_created);
mduration = (int32_t)(mtt_hungup - mtt_created); mduration = (int32_t) (mtt_hungup - mtt_created);
if (caller_profile->times->answered) { if (caller_profile->times->answered) {
billsec = (int32_t)(tt_hungup - tt_answered); billsec = (int32_t) (tt_hungup - tt_answered);
billmsec = (int32_t)(mtt_hungup - mtt_answered); billmsec = (int32_t) (mtt_hungup - mtt_answered);
billusec = caller_profile->times->hungup - caller_profile->times->answered; billusec = caller_profile->times->hungup - caller_profile->times->answered;
legbillsec = (int32_t)(tt_hungup - tt_prof_created); legbillsec = (int32_t) (tt_hungup - tt_prof_created);
legbillmsec = (int32_t)(mtt_hungup - mtt_prof_created); legbillmsec = (int32_t) (mtt_hungup - mtt_prof_created);
legbillusec = caller_profile->times->hungup - caller_profile->times->profile_created; legbillusec = caller_profile->times->hungup - caller_profile->times->profile_created;
} }
if (caller_profile->times->progress) { if (caller_profile->times->progress) {
progresssec = (int32_t)(tt_progress - tt_created); progresssec = (int32_t) (tt_progress - tt_created);
progressmsec = (int32_t)(mtt_progress - mtt_created); progressmsec = (int32_t) (mtt_progress - mtt_created);
progressusec = caller_profile->times->progress - caller_profile->times->created; progressusec = caller_profile->times->progress - caller_profile->times->created;
} }
if (caller_profile->times->progress_media) { if (caller_profile->times->progress_media) {
progress_mediasec = (int32_t)(tt_progress - tt_created); progress_mediasec = (int32_t) (tt_progress - tt_created);
progress_mediamsec = (int32_t)(mtt_progress - mtt_created); progress_mediamsec = (int32_t) (mtt_progress - mtt_created);
progress_mediausec = caller_profile->times->progress - caller_profile->times->created; progress_mediausec = caller_profile->times->progress - caller_profile->times->created;
} }

View File

@ -33,7 +33,7 @@
#include <switch.h> #include <switch.h>
#include <switch_config.h> #include <switch_config.h>
SWITCH_DECLARE(int) switch_config_open_file(switch_config_t * cfg, char *file_path) SWITCH_DECLARE(int) switch_config_open_file(switch_config_t *cfg, char *file_path)
{ {
FILE *f; FILE *f;
char *path = NULL; char *path = NULL;
@ -88,7 +88,7 @@ SWITCH_DECLARE(int) switch_config_open_file(switch_config_t * cfg, char *file_pa
} }
} }
SWITCH_DECLARE(void) switch_config_close_file(switch_config_t * cfg) SWITCH_DECLARE(void) switch_config_close_file(switch_config_t *cfg)
{ {
if (cfg->file) { if (cfg->file) {
@ -98,7 +98,7 @@ SWITCH_DECLARE(void) switch_config_close_file(switch_config_t * cfg)
memset(cfg, 0, sizeof(*cfg)); memset(cfg, 0, sizeof(*cfg));
} }
SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t * cfg, char **var, char **val) SWITCH_DECLARE(int) switch_config_next_pair(switch_config_t *cfg, char **var, char **val)
{ {
int ret = 0; int ret = 0;
char *p, *end; char *p, *end;

View File

@ -53,12 +53,12 @@ static switch_status_t console_xml_config(void)
char *cf = "switch.conf"; char *cf = "switch.conf";
switch_xml_t cfg, xml, settings, param; switch_xml_t cfg, xml, settings, param;
/* clear the keybind array */ /* clear the keybind array */
int i; int i;
for (i = 0; i < 12; i++) { for (i = 0; i < 12; i++) {
console_fnkeys[i] = NULL; console_fnkeys[i] = NULL;
} }
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@ -69,13 +69,13 @@ static switch_status_t console_xml_config(void)
for (param = switch_xml_child(settings, "key"); param; param = param->next) { for (param = switch_xml_child(settings, "key"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name"); char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value"); char *val = (char *) switch_xml_attr_soft(param, "value");
int i = atoi(var); int i = atoi(var);
if ((i < 1) || (i > 12)) { if ((i < 1) || (i > 12)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "keybind %s is invalid, range is from 1 to 12\n", var); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "keybind %s is invalid, range is from 1 to 12\n", var);
} else { } else {
// Add the command to the fnkey array // Add the command to the fnkey array
console_fnkeys[i - 1] = switch_core_permanent_strdup(val); console_fnkeys[i - 1] = switch_core_permanent_strdup(val);
} }
} }
} }
@ -169,7 +169,7 @@ char *expand_alias(char *cmd, char *arg)
char *exp = NULL; char *exp = NULL;
switch_core_db_t *db = switch_core_db_handle(); switch_core_db_t *db = switch_core_db_handle();
int full = 0; int full = 0;
sql = switch_mprintf("select command from aliases where alias='%q'", cmd); sql = switch_mprintf("select command from aliases where alias='%q'", cmd);
switch_core_db_exec(db, sql, alias_callback, &r, &errmsg); switch_core_db_exec(db, sql, alias_callback, &r, &errmsg);
@ -181,9 +181,9 @@ char *expand_alias(char *cmd, char *arg)
if (!r) { if (!r) {
sql = switch_mprintf("select command from aliases where alias='%q %q'", cmd, arg); sql = switch_mprintf("select command from aliases where alias='%q %q'", cmd, arg);
switch_core_db_exec(db, sql, alias_callback, &r, &errmsg); switch_core_db_exec(db, sql, alias_callback, &r, &errmsg);
if (errmsg) { if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg);
free(errmsg); free(errmsg);
@ -270,7 +270,7 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const
if (ret == -1) { if (ret == -1) {
fprintf(stderr, "Memory Error\n"); fprintf(stderr, "Memory Error\n");
goto done; goto done;
} }
if (channel == SWITCH_CHANNEL_ID_LOG_CLEAN) { if (channel == SWITCH_CHANNEL_ID_LOG_CLEAN) {
fprintf(handle, "%s", data); fprintf(handle, "%s", data);
@ -283,11 +283,10 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const
if (channel == SWITCH_CHANNEL_ID_LOG) { if (channel == SWITCH_CHANNEL_ID_LOG) {
fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data); fprintf(handle, "[%d] %s %s:%d %s() %s", (int) getpid(), date, filep, line, func, data);
goto done; goto done;
} }
if (channel == SWITCH_CHANNEL_ID_EVENT && if (channel == SWITCH_CHANNEL_ID_EVENT &&
switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
@ -296,7 +295,7 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const
switch_event_fire(&event); switch_event_fire(&event);
} }
done: done:
if (data) { if (data) {
free(data); free(data);
} }
@ -313,71 +312,85 @@ static char prompt_str[512] = "";
/* /*
* If a fnkey is configured then process the command * If a fnkey is configured then process the command
*/ */
static unsigned char console_fnkey_pressed(int i) { static unsigned char console_fnkey_pressed(int i)
{
char *c, *cmd; char *c, *cmd;
assert((i > 0) && (i <= 12)); assert((i > 0) && (i <= 12));
c = console_fnkeys[i-1]; c = console_fnkeys[i - 1];
// This new line is necessary to avoid output to begin after the ">" of the CLI's prompt // This new line is necessary to avoid output to begin after the ">" of the CLI's prompt
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE,"\n"); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_CONSOLE, "\n");
if (c == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "FUNCTION KEY F%d IS NOT BOUND, please edit switch.conf XML file\n", i);
return CC_REDISPLAY;
}
if (c == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "FUNCTION KEY F%d IS NOT BOUND, please edit switch.conf XML file\n", i);
return CC_REDISPLAY;
}
cmd = strdup(c); cmd = strdup(c);
switch_console_process(cmd, 0); switch_console_process(cmd, 0);
free(cmd); free(cmd);
return CC_REDISPLAY; return CC_REDISPLAY;
} }
static unsigned char console_f1key(EditLine *el, int ch) { static unsigned char console_f1key(EditLine * el, int ch)
return console_fnkey_pressed(1); {
return console_fnkey_pressed(1);
} }
static unsigned char console_f2key(EditLine *el, int ch) { static unsigned char console_f2key(EditLine * el, int ch)
return console_fnkey_pressed(2); {
return console_fnkey_pressed(2);
} }
static unsigned char console_f3key(EditLine *el, int ch) { static unsigned char console_f3key(EditLine * el, int ch)
return console_fnkey_pressed(3); {
return console_fnkey_pressed(3);
} }
static unsigned char console_f4key(EditLine *el, int ch) { static unsigned char console_f4key(EditLine * el, int ch)
return console_fnkey_pressed(4); {
return console_fnkey_pressed(4);
} }
static unsigned char console_f5key(EditLine *el, int ch) { static unsigned char console_f5key(EditLine * el, int ch)
return console_fnkey_pressed(5); {
return console_fnkey_pressed(5);
} }
static unsigned char console_f6key(EditLine *el, int ch) { static unsigned char console_f6key(EditLine * el, int ch)
return console_fnkey_pressed(6); {
return console_fnkey_pressed(6);
} }
static unsigned char console_f7key(EditLine *el, int ch) { static unsigned char console_f7key(EditLine * el, int ch)
return console_fnkey_pressed(7); {
return console_fnkey_pressed(7);
} }
static unsigned char console_f8key(EditLine *el, int ch) { static unsigned char console_f8key(EditLine * el, int ch)
return console_fnkey_pressed(8); {
return console_fnkey_pressed(8);
} }
static unsigned char console_f9key(EditLine *el, int ch) { static unsigned char console_f9key(EditLine * el, int ch)
return console_fnkey_pressed(9); {
return console_fnkey_pressed(9);
} }
static unsigned char console_f10key(EditLine *el, int ch) { static unsigned char console_f10key(EditLine * el, int ch)
return console_fnkey_pressed(10); {
return console_fnkey_pressed(10);
} }
static unsigned char console_f11key(EditLine *el, int ch) { static unsigned char console_f11key(EditLine * el, int ch)
return console_fnkey_pressed(11); {
return console_fnkey_pressed(11);
} }
static unsigned char console_f12key(EditLine *el, int ch) { static unsigned char console_f12key(EditLine * el, int ch)
return console_fnkey_pressed(12); {
return console_fnkey_pressed(12);
} }
char * prompt(EditLine *e) { char *prompt(EditLine * e)
{
if (*prompt_str == '\0') { if (*prompt_str == '\0') {
gethostname(hostname, sizeof(hostname)); gethostname(hostname, sizeof(hostname));
switch_snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", hostname); switch_snprintf(prompt_str, sizeof(prompt_str), "freeswitch@%s> ", hostname);
} }
return prompt_str; return prompt_str;
} }
@ -408,22 +421,22 @@ static void *SWITCH_THREAD_FUNC console_thread(switch_thread_t *thread, void *ob
char *cmd = strdup(line); char *cmd = strdup(line);
char *p; char *p;
const LineInfo *lf = el_line(el); const LineInfo *lf = el_line(el);
char *foo = (char *)lf->buffer; char *foo = (char *) lf->buffer;
if ((p = strrchr(cmd, '\r')) || (p = strrchr(cmd, '\n'))) { if ((p = strrchr(cmd, '\r')) || (p = strrchr(cmd, '\n'))) {
*p = '\0'; *p = '\0';
} }
assert(cmd != NULL); assert(cmd != NULL);
history(myhistory, &ev, H_ENTER, line); history(myhistory, &ev, H_ENTER, line);
running = switch_console_process(cmd, 0); running = switch_console_process(cmd, 0);
el_deletestr(el, strlen(foo)+1); el_deletestr(el, strlen(foo) + 1);
memset(foo, 0, strlen(foo)); memset(foo, 0, strlen(foo));
free(cmd); free(cmd);
} }
} }
switch_yield(1000); switch_yield(1000);
} }
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
return NULL; return NULL;
} }
@ -441,7 +454,7 @@ static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
{ {
struct helper *h = (struct helper *) pArg; struct helper *h = (struct helper *) pArg;
char *target = NULL; char *target = NULL;
target = argv[0]; target = argv[0];
if (!target) { if (!target) {
@ -449,17 +462,17 @@ static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
} }
fprintf(h->out, "%20s\t", target); fprintf(h->out, "%20s\t", target);
switch_copy_string(h->last, target, sizeof(h->last)); switch_copy_string(h->last, target, sizeof(h->last));
if ((++h->hits % 4) == 0) { if ((++h->hits % 4) == 0) {
fprintf(h->out, "\n"); fprintf(h->out, "\n");
} }
return 0; return 0;
} }
static unsigned char complete(EditLine *el, int ch) static unsigned char complete(EditLine * el, int ch)
{ {
switch_core_db_t *db = switch_core_db_handle(); switch_core_db_t *db = switch_core_db_handle();
char *sql; char *sql;
@ -475,13 +488,13 @@ static unsigned char complete(EditLine *el, int ch)
if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) { if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
*p = '\0'; *p = '\0';
} }
while(*buf == ' ') { while (*buf == ' ') {
buf++; buf++;
} }
for(p = buf; p && *p; p++) { for (p = buf; p && *p; p++) {
if (*p == ' ') { if (*p == ' ') {
lp = p; lp = p;
h.words++; h.words++;
@ -491,9 +504,9 @@ static unsigned char complete(EditLine *el, int ch)
if (lp) { if (lp) {
buf = lp + 1; buf = lp + 1;
} }
h.len = strlen(buf); h.len = strlen(buf);
fprintf(h.out, "\n\n"); fprintf(h.out, "\n\n");
if (h.words == 0) { if (h.words == 0) {
@ -503,7 +516,7 @@ static unsigned char complete(EditLine *el, int ch)
} }
switch_core_db_exec(db, sql, comp_callback, &h, &errmsg); switch_core_db_exec(db, sql, comp_callback, &h, &errmsg);
if (errmsg) { if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg);
free(errmsg); free(errmsg);
@ -515,28 +528,25 @@ static unsigned char complete(EditLine *el, int ch)
char *dupdup = strdup(dup); char *dupdup = strdup(dup);
switch_assert(dupdup); switch_assert(dupdup);
int x, argc = 0; int x, argc = 0;
char *argv[10] = {0}; char *argv[10] = { 0 };
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
argc = switch_separate_string(dupdup, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(dupdup, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (h.words == 0) { if (h.words == 0) {
stream.write_function(&stream, stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces) %s ", argc ? "and" : "");
"select distinct a1 from complete where "
"a1 not in (select name from interfaces) %s ", argc ? "and" : "");
} else { } else {
stream.write_function(&stream, stream.write_function(&stream, "select distinct a%d from complete where ", h.words + 1);
"select distinct a%d from complete where ", h.words + 1);
} }
for(x = 0; x < argc; x++) { for (x = 0; x < argc; x++) {
stream.write_function(&stream, "(a%d = '' or a%d like '%s%%')%s", x+1, x+1, switch_str_nil(argv[x]), x == argc -1 ? "" : " and "); stream.write_function(&stream, "(a%d = '' or a%d like '%s%%')%s", x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
} }
switch_core_db_exec(db, stream.data, comp_callback, &h, &errmsg); switch_core_db_exec(db, stream.data, comp_callback, &h, &errmsg);
if (errmsg) { if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", (char *) stream.data, errmsg); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", (char *) stream.data, errmsg);
@ -546,20 +556,20 @@ static unsigned char complete(EditLine *el, int ch)
switch_safe_free(dupdup); switch_safe_free(dupdup);
switch_safe_free(stream.data); switch_safe_free(stream.data);
if (ret == CC_ERROR) { if (ret == CC_ERROR) {
goto end; goto end;
} }
} }
fprintf(h.out, "\n\n"); fprintf(h.out, "\n\n");
if (h.hits == 1) { if (h.hits == 1) {
el_deletestr(el, h.len); el_deletestr(el, h.len);
el_insertstr(el, h.last); el_insertstr(el, h.last);
} }
end: end:
fflush(h.out); fflush(h.out);
@ -567,14 +577,14 @@ static unsigned char complete(EditLine *el, int ch)
switch_safe_free(dup); switch_safe_free(dup);
switch_core_db_close(db); switch_core_db_close(db);
return (ret); return (ret);
} }
SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string) SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
{ {
char *mydata = NULL, *argv[11] = {0}; char *mydata = NULL, *argv[11] = { 0 };
int argc, x; int argc, x;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -587,26 +597,26 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
if (!strcasecmp(argv[0], "stickyadd")) { if (!strcasecmp(argv[0], "stickyadd")) {
mystream.write_function(&mystream, "insert into complete values (1,"); mystream.write_function(&mystream, "insert into complete values (1,");
for(x = 0; x < 10; x++) { for (x = 0; x < 10; x++) {
mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x+1]), x == 9 ? ")" : ", "); mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x + 1]), x == 9 ? ")" : ", ");
} }
switch_core_db_persistant_execute(db, mystream.data, 5); switch_core_db_persistant_execute(db, mystream.data, 5);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "add")) { } else if (!strcasecmp(argv[0], "add")) {
mystream.write_function(&mystream, "insert into complete values (0,"); mystream.write_function(&mystream, "insert into complete values (0,");
for(x = 0; x < 10; x++) { for (x = 0; x < 10; x++) {
mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x+1]), x == 9 ? ")" : ", "); mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x + 1]), x == 9 ? ")" : ", ");
} }
switch_core_db_persistant_execute(db, mystream.data, 5); switch_core_db_persistant_execute(db, mystream.data, 5);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "del")) { } else if (!strcasecmp(argv[0], "del")) {
char *what = argv[1]; char *what = argv[1];
if (!strcasecmp(what, "*")) { if (!strcasecmp(what, "*")) {
switch_core_db_persistant_execute(db, "delete from complete", 1); switch_core_db_persistant_execute(db, "delete from complete", 1);
} else { } else {
mystream.write_function(&mystream, "delete from complete where "); mystream.write_function(&mystream, "delete from complete where ");
for(x = 0; x < argc - 1; x++) { for (x = 0; x < argc - 1; x++) {
mystream.write_function(&mystream, "a%d = '%s'%s", x+1, switch_str_nil(argv[x+1]), x == argc - 2 ? "" : " and "); mystream.write_function(&mystream, "a%d = '%s'%s", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
} }
switch_core_db_persistant_execute(db, mystream.data, 1); switch_core_db_persistant_execute(db, mystream.data, 1);
} }
@ -626,10 +636,10 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string) SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
{ {
char *mydata = NULL, *argv[3] = {0}; char *mydata = NULL, *argv[3] = { 0 };
int argc; int argc;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
if (string && (mydata = strdup(string))) { if (string && (mydata = strdup(string))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) { if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
switch_core_db_t *db = switch_core_db_handle(); switch_core_db_t *db = switch_core_db_handle();
@ -652,7 +662,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} else if (!strcasecmp(argv[0], "del") && argc == 2) { } else if (!strcasecmp(argv[0], "del") && argc == 2) {
char *what = argv[1]; char *what = argv[1];
if (!strcasecmp(what, "*")) { if (!strcasecmp(what, "*")) {
switch_core_db_persistant_execute(db, "delete from aliases", 1); switch_core_db_persistant_execute(db, "delete from aliases", 1);
} else { } else {
sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]); sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]);
@ -664,7 +674,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
switch_core_db_close(db); switch_core_db_close(db);
} }
} }
switch_safe_free(mydata); switch_safe_free(mydata);
return status; return status;
@ -686,44 +696,44 @@ SWITCH_DECLARE(void) switch_console_loop(void)
el = el_init(__FILE__, switch_core_get_console(), switch_core_get_console(), switch_core_get_console()); el = el_init(__FILE__, switch_core_get_console(), switch_core_get_console(), switch_core_get_console());
el_set(el, EL_PROMPT, &prompt); el_set(el, EL_PROMPT, &prompt);
el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_EDITOR, "emacs");
/* AGX: Bind Keyboard function keys. This has been tested with: /* AGX: Bind Keyboard function keys. This has been tested with:
* - linux console keyabord * - linux console keyabord
* - putty.exe connected via ssh to linux * - putty.exe connected via ssh to linux
*/ */
/* Load/Init the config first */ /* Load/Init the config first */
console_xml_config(); console_xml_config();
/* Bind the functions to the key */ /* Bind the functions to the key */
el_set(el, EL_ADDFN, "f1-key", "F1 KEY PRESS", console_f1key ); el_set(el, EL_ADDFN, "f1-key", "F1 KEY PRESS", console_f1key);
el_set(el, EL_ADDFN, "f2-key", "F2 KEY PRESS", console_f2key ); el_set(el, EL_ADDFN, "f2-key", "F2 KEY PRESS", console_f2key);
el_set(el, EL_ADDFN, "f3-key", "F3 KEY PRESS", console_f3key ); el_set(el, EL_ADDFN, "f3-key", "F3 KEY PRESS", console_f3key);
el_set(el, EL_ADDFN, "f4-key", "F4 KEY PRESS", console_f4key ); el_set(el, EL_ADDFN, "f4-key", "F4 KEY PRESS", console_f4key);
el_set(el, EL_ADDFN, "f5-key", "F5 KEY PRESS", console_f5key ); el_set(el, EL_ADDFN, "f5-key", "F5 KEY PRESS", console_f5key);
el_set(el, EL_ADDFN, "f6-key", "F6 KEY PRESS", console_f6key ); el_set(el, EL_ADDFN, "f6-key", "F6 KEY PRESS", console_f6key);
el_set(el, EL_ADDFN, "f7-key", "F7 KEY PRESS", console_f7key ); el_set(el, EL_ADDFN, "f7-key", "F7 KEY PRESS", console_f7key);
el_set(el, EL_ADDFN, "f8-key", "F8 KEY PRESS", console_f8key ); el_set(el, EL_ADDFN, "f8-key", "F8 KEY PRESS", console_f8key);
el_set(el, EL_ADDFN, "f9-key", "F9 KEY PRESS", console_f9key ); el_set(el, EL_ADDFN, "f9-key", "F9 KEY PRESS", console_f9key);
el_set(el, EL_ADDFN, "f10-key", "F10 KEY PRESS", console_f10key ); el_set(el, EL_ADDFN, "f10-key", "F10 KEY PRESS", console_f10key);
el_set(el, EL_ADDFN, "f11-key", "F11 KEY PRESS", console_f11key ); el_set(el, EL_ADDFN, "f11-key", "F11 KEY PRESS", console_f11key);
el_set(el, EL_ADDFN, "f12-key", "F12 KEY PRESS", console_f12key ); el_set(el, EL_ADDFN, "f12-key", "F12 KEY PRESS", console_f12key);
el_set(el, EL_BIND, "\033OP", "f1-key", NULL); el_set(el, EL_BIND, "\033OP", "f1-key", NULL);
el_set(el, EL_BIND, "\033OQ", "f2-key", NULL); el_set(el, EL_BIND, "\033OQ", "f2-key", NULL);
el_set(el, EL_BIND, "\033OR", "f3-key", NULL); el_set(el, EL_BIND, "\033OR", "f3-key", NULL);
el_set(el, EL_BIND, "\033OS", "f4-key", NULL); el_set(el, EL_BIND, "\033OS", "f4-key", NULL);
el_set(el, EL_BIND, "\033[11~", "f1-key", NULL); el_set(el, EL_BIND, "\033[11~", "f1-key", NULL);
el_set(el, EL_BIND, "\033[12~", "f2-key", NULL); el_set(el, EL_BIND, "\033[12~", "f2-key", NULL);
el_set(el, EL_BIND, "\033[13~", "f3-key", NULL); el_set(el, EL_BIND, "\033[13~", "f3-key", NULL);
el_set(el, EL_BIND, "\033[14~", "f4-key", NULL); el_set(el, EL_BIND, "\033[14~", "f4-key", NULL);
el_set(el, EL_BIND, "\033[15~", "f5-key", NULL); el_set(el, EL_BIND, "\033[15~", "f5-key", NULL);
el_set(el, EL_BIND, "\033[17~", "f6-key", NULL); el_set(el, EL_BIND, "\033[17~", "f6-key", NULL);
el_set(el, EL_BIND, "\033[18~", "f7-key", NULL); el_set(el, EL_BIND, "\033[18~", "f7-key", NULL);
el_set(el, EL_BIND, "\033[19~", "f8-key", NULL); el_set(el, EL_BIND, "\033[19~", "f8-key", NULL);
el_set(el, EL_BIND, "\033[20~", "f9-key", NULL); el_set(el, EL_BIND, "\033[20~", "f9-key", NULL);
el_set(el, EL_BIND, "\033[21~", "f10-key", NULL); el_set(el, EL_BIND, "\033[21~", "f10-key", NULL);
el_set(el, EL_BIND, "\033[23~", "f11-key", NULL); el_set(el, EL_BIND, "\033[23~", "f11-key", NULL);
el_set(el, EL_BIND, "\033[24~", "f12-key", NULL); el_set(el, EL_BIND, "\033[24~", "f12-key", NULL);
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete); el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
@ -746,7 +756,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, console_thread, pool, pool); switch_thread_create(&thread, thd_attr, console_thread, pool, pool);
while (running) { while (running) {
int32_t arg = 0; int32_t arg = 0;
switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg); switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
@ -758,7 +768,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
history(myhistory, &ev, H_SAVE, hfile); history(myhistory, &ev, H_SAVE, hfile);
free(hfile); free(hfile);
/* Clean up our memory */ /* Clean up our memory */
history_end(myhistory); history_end(myhistory);
el_end(el); el_end(el);

View File

@ -172,7 +172,7 @@ SWITCH_DECLARE(char *) switch_core_get_uuid(void)
} }
static void *switch_core_service_thread(switch_thread_t * thread, void *obj) static void *switch_core_service_thread(switch_thread_t *thread, void *obj)
{ {
switch_core_thread_session_t *data = obj; switch_core_thread_session_t *data = obj;
switch_core_session_t *session = data->objs[0]; switch_core_session_t *session = data->objs[0];
@ -362,7 +362,7 @@ SWITCH_DECLARE(void) switch_core_set_globals(void)
#endif #endif
#endif #endif
} }
dir_path = switch_mprintf("%s%ssounds", SWITCH_GLOBAL_dirs.base_dir, SWITCH_PATH_SEPARATOR); dir_path = switch_mprintf("%s%ssounds", SWITCH_GLOBAL_dirs.base_dir, SWITCH_PATH_SEPARATOR);
switch_dir_make_recursive(dir_path, switch_dir_make_recursive(dir_path,
SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE | SWITCH_FPROT_UEXECUTE | SWITCH_FPROT_GREAD | SWITCH_FPROT_GEXECUTE, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE | SWITCH_FPROT_UEXECUTE | SWITCH_FPROT_GREAD | SWITCH_FPROT_GEXECUTE,
@ -436,8 +436,7 @@ SWITCH_DECLARE(int32_t) set_high_priority(void)
* So let's try to remove the mlock limit here... * So let's try to remove the mlock limit here...
*/ */
if (setrlimit(RLIMIT_MEMLOCK, &lim) < 0) { if (setrlimit(RLIMIT_MEMLOCK, &lim) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to disable memlock limit, application may crash if run as non-root user!\n");
"Failed to disable memlock limit, application may crash if run as non-root user!\n");
} }
#endif #endif
@ -463,7 +462,7 @@ SWITCH_DECLARE(int32_t) change_user_group(const char *user, const char *group)
/* /*
* Lookup user information in the system's db * Lookup user information in the system's db
*/ */
runas_pw = getpwnam( user ); runas_pw = getpwnam(user);
if (!runas_pw) { if (!runas_pw) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown user \"%s\"\n", user); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown user \"%s\"\n", user);
return -1; return -1;
@ -477,7 +476,7 @@ SWITCH_DECLARE(int32_t) change_user_group(const char *user, const char *group)
/* /*
* Lookup group information in the system's db * Lookup group information in the system's db
*/ */
gr = getgrnam( group ); gr = getgrnam(group);
if (!gr) { if (!gr) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown group \"%s\"\n", group); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unknown group \"%s\"\n", group);
return -1; return -1;
@ -514,7 +513,6 @@ SWITCH_DECLARE(int32_t) change_user_group(const char *user, const char *group)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to change gid!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to change gid!\n");
return -1; return -1;
} }
#ifdef HAVE_INITGROUPS #ifdef HAVE_INITGROUPS
/* /*
* Set all the other groups the user is a member of * Set all the other groups the user is a member of
@ -573,7 +571,7 @@ SWITCH_DECLARE(const char *) switch_core_mime_ext2type(const char *ext)
return (const char *) switch_core_hash_find(runtime.mime_types, ext); return (const char *) switch_core_hash_find(runtime.mime_types, ext);
} }
SWITCH_DECLARE(switch_hash_index_t *) switch_core_mime_index(void) SWITCH_DECLARE(switch_hash_index_t *) switch_core_mime_index(void)
{ {
return switch_hash_first(NULL, runtime.mime_types); return switch_hash_first(NULL, runtime.mime_types);
@ -605,17 +603,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_mime_add_type(const char *type, cons
switch_core_hash_insert(runtime.mime_types, argv[x], ptype); switch_core_hash_insert(runtime.mime_types, argv[x], ptype);
} }
} }
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
free(ext_list); free(ext_list);
} }
return status; return status;
} }
static void load_mime_types(void) static void load_mime_types(void)
{ {
char *cf = "mime.types"; char *cf = "mime.types";
int fd = -1; int fd = -1;
@ -630,7 +628,7 @@ static void load_mime_types(void)
return; return;
} }
while((switch_fd_read_line(fd, line_buf, sizeof(line_buf)))) { while ((switch_fd_read_line(fd, line_buf, sizeof(line_buf)))) {
char *p; char *p;
char *type = line_buf; char *type = line_buf;
@ -645,20 +643,20 @@ static void load_mime_types(void)
if ((p = strchr(type, '\t')) || (p = strchr(type, ' '))) { if ((p = strchr(type, '\t')) || (p = strchr(type, ' '))) {
*p++ = '\0'; *p++ = '\0';
while(*p == ' ' || *p == '\t') { while (*p == ' ' || *p == '\t') {
p++; p++;
} }
switch_core_mime_add_type(type, p); switch_core_mime_add_type(type, p);
} }
} }
if (fd > -1) { if (fd > -1) {
close(fd); close(fd);
fd = -1; fd = -1;
} }
} }
SWITCH_DECLARE(void) switch_core_setrlimits(void) SWITCH_DECLARE(void) switch_core_setrlimits(void)
{ {
@ -667,10 +665,10 @@ SWITCH_DECLARE(void) switch_core_setrlimits(void)
/* /*
Setting the stack size on FreeBSD results in an instant crash. Setting the stack size on FreeBSD results in an instant crash.
If anyone knows how to fix this, If anyone knows how to fix this,
feel free to submit a patch to http://jira.freeswitch.org feel free to submit a patch to http://jira.freeswitch.org
*/ */
#ifndef __FreeBSD__ #ifndef __FreeBSD__
memset(&rlp, 0, sizeof(rlp)); memset(&rlp, 0, sizeof(rlp));
@ -710,10 +708,10 @@ SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip(const char *ip_str, c
switch_network_list_t *list; switch_network_list_t *list;
uint32_t ip, net, mask, bits; uint32_t ip, net, mask, bits;
switch_bool_t ok = SWITCH_FALSE; switch_bool_t ok = SWITCH_FALSE;
switch_mutex_lock(runtime.global_mutex); switch_mutex_lock(runtime.global_mutex);
switch_inet_pton(AF_INET, ip_str, &ip); switch_inet_pton(AF_INET, ip_str, &ip);
if ((list = switch_core_hash_find(IP_LIST.hash, list_name))) { if ((list = switch_core_hash_find(IP_LIST.hash, list_name))) {
ok = switch_network_list_validate_ip(list, ip); ok = switch_network_list_validate_ip(list, ip);
} else if (strchr(list_name, '/')) { } else if (strchr(list_name, '/')) {
@ -721,7 +719,7 @@ SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip(const char *ip_str, c
ok = switch_test_subnet(ip, net, mask); ok = switch_test_subnet(ip, net, mask);
} }
switch_mutex_unlock(runtime.global_mutex); switch_mutex_unlock(runtime.global_mutex);
return ok; return ok;
} }
@ -741,11 +739,11 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload)
if (IP_LIST.pool) { if (IP_LIST.pool) {
switch_core_destroy_memory_pool(&IP_LIST.pool); switch_core_destroy_memory_pool(&IP_LIST.pool);
} }
memset(&IP_LIST, 0, sizeof(IP_LIST)); memset(&IP_LIST, 0, sizeof(IP_LIST));
switch_core_new_memory_pool(&IP_LIST.pool); switch_core_new_memory_pool(&IP_LIST.pool);
switch_core_hash_init(&IP_LIST.hash, IP_LIST.pool); switch_core_hash_init(&IP_LIST.hash, IP_LIST.pool);
if ((xml = switch_xml_open_cfg("acl.conf", &cfg, NULL))) { if ((xml = switch_xml_open_cfg("acl.conf", &cfg, NULL))) {
if ((x_lists = switch_xml_child(cfg, "network-lists"))) { 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) { for (x_list = switch_xml_child(x_lists, "list"); x_list; x_list = x_list->next) {
@ -760,7 +758,7 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload)
if (dft) { if (dft) {
default_type = switch_true(dft); default_type = switch_true(dft);
} }
if (switch_network_list_create(&list, default_type, IP_LIST.pool) != SWITCH_STATUS_SUCCESS) { if (switch_network_list_create(&list, default_type, IP_LIST.pool) != SWITCH_STATUS_SUCCESS) {
abort(); abort();
} }
@ -779,35 +777,36 @@ SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload)
if (type) { if (type) {
ok = switch_true(type); ok = switch_true(type);
} }
cidr = switch_xml_attr(x_node, "cidr"); cidr = switch_xml_attr(x_node, "cidr");
host = switch_xml_attr(x_node, "host"); host = switch_xml_attr(x_node, "host");
mask = switch_xml_attr(x_node, "mask"); mask = switch_xml_attr(x_node, "mask");
if (cidr) { if (cidr) {
if (switch_network_list_add_cidr(list, cidr, ok) == SWITCH_STATUS_SUCCESS) { if (switch_network_list_add_cidr(list, cidr, ok) == SWITCH_STATUS_SUCCESS) {
if (reload) { if (reload) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny",
name);
} }
} else { } else {
if (reload) { if (reload) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Error Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name); "Error Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"Error Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name); "Error Adding %s (%s) to list %s\n", cidr, ok ? "allow" : "deny", name);
} }
} }
} else if (host && mask) { } else if (host && mask) {
if (switch_network_list_add_host_mask(list, host, mask, ok) == SWITCH_STATUS_SUCCESS) { if (switch_network_list_add_host_mask(list, host, mask, ok) == SWITCH_STATUS_SUCCESS) {
if (reload) { if (reload) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
"Adding %s/%s (%s) to list %s\n", host, mask, ok ? "allow" : "deny", name); "Adding %s/%s (%s) to list %s\n", host, mask, ok ? "allow" : "deny", name);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"Adding %s/%s (%s) to list %s\n", host, mask, ok ? "allow" : "deny", name); "Adding %s/%s (%s) to list %s\n", host, mask, ok ? "allow" : "deny", name);
} }
} }
@ -855,8 +854,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
memset(&runtime, 0, sizeof(runtime)); memset(&runtime, 0, sizeof(runtime));
runtime.dummy_cng_frame.data = runtime.dummy_data; runtime.dummy_cng_frame.data = runtime.dummy_data;
runtime.dummy_cng_frame.datalen= sizeof(runtime.dummy_data); runtime.dummy_cng_frame.datalen = sizeof(runtime.dummy_data);
runtime.dummy_cng_frame.buflen= sizeof(runtime.dummy_data); runtime.dummy_cng_frame.buflen = sizeof(runtime.dummy_data);
runtime.dummy_cng_frame.flags = SFF_CNG; runtime.dummy_cng_frame.flags = SFF_CNG;
switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS); switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
@ -914,17 +913,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
switch_set_flag((&runtime), SCF_CRASH_PROT); switch_set_flag((&runtime), SCF_CRASH_PROT);
} }
} else if (!strcasecmp(var, "loglevel")) { } else if (!strcasecmp(var, "loglevel")) {
int level; int level;
if (*val > 47 && *val < 58) { if (*val > 47 && *val < 58) {
level = atoi(val); level = atoi(val);
} else { } else {
level = switch_log_str2level(val); level = switch_log_str2level(val);
} }
if (level != SWITCH_LOG_INVALID) { if (level != SWITCH_LOG_INVALID) {
switch_core_session_ctl(SCSC_LOGLEVEL, &level); switch_core_session_ctl(SCSC_LOGLEVEL, &level);
} }
#ifdef HAVE_SETRLIMIT #ifdef HAVE_SETRLIMIT
} else if (!strcasecmp(var, "dump-cores")) { } else if (!strcasecmp(var, "dump-cores")) {
struct rlimit rlp; struct rlimit rlp;
@ -942,23 +940,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
} else if (!strcasecmp(var, "max_dtmf_duration")) { } else if (!strcasecmp(var, "max_dtmf_duration")) {
int tmp = atoi(val); int tmp = atoi(val);
if (tmp > 0) { if (tmp > 0) {
switch_core_max_dtmf_duration((uint32_t)tmp); switch_core_max_dtmf_duration((uint32_t) tmp);
} }
} else if (!strcasecmp(var, "default_dtmf_duration")) { } else if (!strcasecmp(var, "default_dtmf_duration")) {
int tmp = atoi(val); int tmp = atoi(val);
if (tmp > 0) { if (tmp > 0) {
switch_core_default_dtmf_duration((uint32_t)tmp); switch_core_default_dtmf_duration((uint32_t) tmp);
} }
} else if (!strcasecmp(var, "disable-monotonic-timing")) { } else if (!strcasecmp(var, "disable-monotonic-timing")) {
switch_time_set_monotonic(SWITCH_FALSE); switch_time_set_monotonic(SWITCH_FALSE);
} else if (!strcasecmp(var, "max-sessions")) { } else if (!strcasecmp(var, "max-sessions")) {
switch_core_session_limit(atoi(val)); switch_core_session_limit(atoi(val));
} } else if (!strcasecmp(var, "rtp-start-port")) {
else if (!strcasecmp(var, "rtp-start-port")) { switch_rtp_set_start_port((switch_port_t) atoi(val));
switch_rtp_set_start_port((switch_port_t)atoi(val)); } else if (!strcasecmp(var, "rtp-end-port")) {
} switch_rtp_set_end_port((switch_port_t) atoi(val));
else if (!strcasecmp(var, "rtp-end-port")) {
switch_rtp_set_end_port((switch_port_t)atoi(val));
} }
} }
} }
@ -1059,7 +1055,7 @@ static void handle_SIGHUP(int sig)
{ {
if (sig) { if (sig) {
switch_event_t *event; switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Trapped-Signal", "HUP"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Trapped-Signal", "HUP");
switch_event_fire(&event); switch_event_fire(&event);
@ -1094,7 +1090,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t
#endif #endif
signal(SIGHUP, handle_SIGHUP); signal(SIGHUP, handle_SIGHUP);
switch_load_network_lists(SWITCH_FALSE); switch_load_network_lists(SWITCH_FALSE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Bringing up environment.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Loading Modules.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Loading Modules.\n");
@ -1110,12 +1106,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"\nFreeSWITCH Version %s Started.\nCrash Protection [%s]\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n", SWITCH_VERSION_FULL, "\nFreeSWITCH Version %s Started.\nCrash Protection [%s]\nMax Sessions[%u]\nSession Rate[%d]\nSQL [%s]\n", SWITCH_VERSION_FULL,
switch_test_flag((&runtime), SCF_CRASH_PROT) ? "Enabled" : "Disabled", switch_test_flag((&runtime), SCF_CRASH_PROT) ? "Enabled" : "Disabled",
switch_core_session_limit(0), switch_core_session_limit(0),
switch_core_sessions_per_second(0), switch_core_sessions_per_second(0), switch_test_flag((&runtime), SCF_USE_SQL) ? "Enabled" : "Disabled");
switch_test_flag((&runtime), SCF_USE_SQL) ? "Enabled" : "Disabled"
);
switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS); switch_clear_flag((&runtime), SCF_NO_NEW_SESSIONS);
@ -1145,7 +1139,7 @@ SWITCH_DECLARE(switch_time_t) switch_core_uptime(void)
return switch_timestamp_now() - runtime.initiated; return switch_timestamp_now() - runtime.initiated;
} }
SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t * val) SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t *val)
{ {
if (switch_test_flag((&runtime), SCF_SHUTTING_DOWN)) { if (switch_test_flag((&runtime), SCF_SHUTTING_DOWN)) {
return -1; return -1;
@ -1292,7 +1286,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_management_exec(char *relative_oid,
SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void) SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void)
{ {
switch_core_memory_reclaim_logger(); switch_core_memory_reclaim_logger();
switch_core_memory_reclaim_events(); switch_core_memory_reclaim_events();
switch_core_memory_reclaim(); switch_core_memory_reclaim();
} }

View File

@ -37,11 +37,7 @@
SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah, SWITCH_DECLARE(switch_status_t) switch_core_asr_open(switch_asr_handle_t *ah,
const char *module_name, const char *module_name,
const char *codec, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool)
int rate,
const char *dest,
switch_asr_flag_t *flags,
switch_memory_pool_t *pool)
{ {
switch_status_t status; switch_status_t status;
char buf[256] = ""; char buf[256] = "";

View File

@ -50,7 +50,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
char tmp[30]; char tmp[30];
switch_assert(codec->implementation); switch_assert(codec->implementation);
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_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", "%s", codec->implementation->iananame); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", "%s", codec->implementation->iananame);
@ -92,7 +92,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-name", "%s", codec->implementation->iananame); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-name", "%s", codec->implementation->iananame);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-rate", "%d", codec->implementation->actual_samples_per_second); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-rate", "%d", codec->implementation->actual_samples_per_second);
if (codec->implementation->actual_samples_per_second != codec->implementation->samples_per_second) { if (codec->implementation->actual_samples_per_second != codec->implementation->samples_per_second) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-write-codec-rate", "%d", codec->implementation->actual_samples_per_second); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-write-codec-rate", "%d",
codec->implementation->actual_samples_per_second);
} }
switch_event_fire(&event); switch_event_fire(&event);
} }
@ -185,14 +186,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, sw
new_codec->codec_interface = codec->codec_interface; new_codec->codec_interface = codec->codec_interface;
new_codec->implementation = codec->implementation; new_codec->implementation = codec->implementation;
new_codec->flags = codec->flags; new_codec->flags = codec->flags;
if (codec->fmtp_in) { if (codec->fmtp_in) {
new_codec->fmtp_in = switch_core_strdup(new_codec->memory_pool, codec->fmtp_in); new_codec->fmtp_in = switch_core_strdup(new_codec->memory_pool, codec->fmtp_in);
} }
new_codec->implementation->init(new_codec, new_codec->flags, NULL); new_codec->implementation->init(new_codec, new_codec->flags, NULL);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, char *codec_name, char *fmtp, SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, char *codec_name, char *fmtp,
@ -286,7 +287,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, uint32_t decoded_rate,
void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag) void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
{ {
switch_assert(codec != NULL); switch_assert(codec != NULL);
switch_assert(encoded_data != NULL); switch_assert(encoded_data != NULL);
@ -311,7 +312,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, uint32_t encoded_rate,
void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag) void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
{ {
switch_assert(codec != NULL); switch_assert(codec != NULL);
switch_assert(encoded_data != NULL); switch_assert(encoded_data != NULL);

View File

@ -81,7 +81,7 @@ SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, s
int sane = 100; int sane = 100;
char *err = NULL; char *err = NULL;
while(--sane > 0) { while (--sane > 0) {
ret = sqlite3_exec(db, sql, callback, data, &err); ret = sqlite3_exec(db, sql, callback, data, &err);
if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) { if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
if (sane > 1) { if (sane > 1) {
@ -165,8 +165,9 @@ SWITCH_DECLARE(void) switch_core_db_free(char *z)
sqlite3_free(z); sqlite3_free(z);
} }
SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db) { SWITCH_DECLARE(int) switch_core_db_changes(switch_core_db_t *db)
return sqlite3_changes(db); {
return sqlite3_changes(db);
} }
SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...) SWITCH_DECLARE(char *) switch_mprintf(const char *zFormat, ...)
@ -212,7 +213,7 @@ SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *te
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
switch_core_db_free(errmsg); switch_core_db_free(errmsg);
errmsg = NULL; errmsg = NULL;
} }
switch_core_db_exec(db, reactive_sql, NULL, NULL, &errmsg); switch_core_db_exec(db, reactive_sql, NULL, NULL, &errmsg);
if (errmsg) { if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);

View File

@ -32,17 +32,17 @@
#include "private/switch_core_pvt.h" #include "private/switch_core_pvt.h"
NEW_HOOK_DECL(outgoing_channel) NEW_HOOK_DECL(outgoing_channel)
NEW_HOOK_DECL(receive_message) NEW_HOOK_DECL(receive_message)
NEW_HOOK_DECL(receive_event) NEW_HOOK_DECL(receive_event)
NEW_HOOK_DECL(state_change) NEW_HOOK_DECL(state_change)
NEW_HOOK_DECL(read_frame) NEW_HOOK_DECL(read_frame)
NEW_HOOK_DECL(write_frame) NEW_HOOK_DECL(write_frame)
NEW_HOOK_DECL(video_read_frame) NEW_HOOK_DECL(video_read_frame)
NEW_HOOK_DECL(video_write_frame) NEW_HOOK_DECL(video_write_frame)
NEW_HOOK_DECL(kill_channel) NEW_HOOK_DECL(kill_channel)
NEW_HOOK_DECL(send_dtmf) NEW_HOOK_DECL(send_dtmf)
NEW_HOOK_DECL(recv_dtmf) NEW_HOOK_DECL(recv_dtmf)
NEW_HOOK_DECL(resurrect_session) NEW_HOOK_DECL(resurrect_session)
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:

View File

@ -37,11 +37,8 @@
SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line, SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, const char *func, int line,
switch_file_handle_t *fh, switch_file_handle_t *fh,
const char *file_path, const char *file_path,
uint8_t channels, uint8_t channels, uint32_t rate, unsigned int flags, switch_memory_pool_t *pool)
uint32_t rate,
unsigned int flags,
switch_memory_pool_t *pool)
{ {
char *ext; char *ext;
switch_status_t status; switch_status_t status;
@ -69,7 +66,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid file format [%s] for [%s]!\n", ext, file_path); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid file format [%s] for [%s]!\n", ext, file_path);
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
fh->file = file; fh->file = file;
fh->func = func; fh->func = func;
fh->line = line; fh->line = line;
@ -109,8 +106,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
} else { } else {
fh->native_rate = rate; fh->native_rate = rate;
} }
if (fh->samplerate && rate && fh->samplerate != rate) { if (fh->samplerate && rate && fh->samplerate != rate) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Sample rate doesn't match\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Sample rate doesn't match\n");
if ((flags & SWITCH_FILE_FLAG_READ)) { if ((flags & SWITCH_FILE_FLAG_READ)) {
fh->samplerate = rate; fh->samplerate = rate;
@ -126,7 +123,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
{ {
switch_status_t status; switch_status_t status;
switch_size_t orig_len = *len; switch_size_t orig_len = *len;
switch_assert(fh != NULL); switch_assert(fh != NULL);
switch_assert(fh->file_interface != NULL); switch_assert(fh->file_interface != NULL);
@ -142,20 +139,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) { if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
if (!fh->resampler) { if (!fh->resampler) {
if (switch_resample_create(&fh->resampler, if (switch_resample_create(&fh->resampler,
fh->native_rate, fh->native_rate, orig_len, fh->samplerate, (uint32_t) orig_len, fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
orig_len,
fh->samplerate,
(uint32_t)orig_len,
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
} }
fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len); fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len);
fh->resampler->to_len = fh->resampler->to_len =
switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0); switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0);
if (fh->resampler->to_len > orig_len) { if (fh->resampler->to_len > orig_len) {
if (!fh->buffer) { if (!fh->buffer) {
switch_buffer_create_dynamic(&fh->buffer, fh->resampler->to_len * 2, fh->resampler->to_len * 4, fh->resampler->to_len * 8); switch_buffer_create_dynamic(&fh->buffer, fh->resampler->to_len * 2, fh->resampler->to_len * 4, fh->resampler->to_len * 8);
@ -166,7 +159,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
fh->dbuf = switch_core_alloc(fh->memory_pool, fh->dbuflen); fh->dbuf = switch_core_alloc(fh->memory_pool, fh->dbuflen);
} }
switch_assert(fh->resampler->to_len <= fh->dbuflen); switch_assert(fh->resampler->to_len <= fh->dbuflen);
switch_float_to_short(fh->resampler->to, (int16_t *) fh->dbuf, fh->resampler->to_len); switch_float_to_short(fh->resampler->to, (int16_t *) fh->dbuf, fh->resampler->to_len);
switch_buffer_write(fh->buffer, fh->dbuf, fh->resampler->to_len * 2); switch_buffer_write(fh->buffer, fh->dbuf, fh->resampler->to_len * 2);
*len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2; *len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
@ -174,10 +167,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
switch_float_to_short(fh->resampler->to, data, fh->resampler->to_len); switch_float_to_short(fh->resampler->to, data, fh->resampler->to_len);
*len = fh->resampler->to_len; *len = fh->resampler->to_len;
} }
} }
done: done:
return status; return status;
} }
@ -192,22 +185,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
if (!fh->file_interface->file_write) { if (!fh->file_interface->file_write) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) { if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
if (!fh->resampler) { if (!fh->resampler) {
if (switch_resample_create(&fh->resampler, if (switch_resample_create(&fh->resampler,
fh->native_rate, fh->native_rate, orig_len, fh->samplerate, (uint32_t) orig_len, fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
orig_len,
fh->samplerate,
(uint32_t)orig_len,
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
} }
fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len); fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len);
fh->resampler->to_len = fh->resampler->to_len =
switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0); switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0);
if (fh->resampler->to_len > orig_len) { if (fh->resampler->to_len > orig_len) {
if (!fh->dbuf) { if (!fh->dbuf) {
@ -222,7 +211,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
} }
*len = fh->resampler->to_len; *len = fh->resampler->to_len;
} }
if (!*len) { if (!*len) {

View File

@ -41,16 +41,16 @@ struct switch_hash {
Hash table; Hash table;
}; };
SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t ** hash, switch_memory_pool_t *pool) SWITCH_DECLARE(switch_status_t) switch_core_hash_init(switch_hash_t **hash, switch_memory_pool_t *pool)
{ {
switch_hash_t *newhash; switch_hash_t *newhash;
newhash = switch_core_alloc(pool, sizeof(*newhash)); newhash = switch_core_alloc(pool, sizeof(*newhash));
switch_assert(newhash); switch_assert(newhash);
sqlite3HashInit(&newhash->table, SQLITE_HASH_STRING, 1); sqlite3HashInit(&newhash->table, SQLITE_HASH_STRING, 1);
*hash = newhash; *hash = newhash;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -62,54 +62,54 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_destroy(switch_hash_t **hash)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t * hash, const char *key, const void *data) SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(switch_hash_t *hash, const char *key, const void *data)
{ {
sqlite3HashInsert(&hash->table, key, (int)strlen(key)+1, (void *)data); sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, (void *) data);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t * hash, const char *key, const void *data, switch_mutex_t *mutex) SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t *hash, const char *key, const void *data, switch_mutex_t *mutex)
{ {
if (mutex) { if (mutex) {
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
sqlite3HashInsert(&hash->table, key, (int)strlen(key)+1, (void *)data); sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, (void *) data);
if (mutex) { if (mutex) {
switch_mutex_unlock(mutex); switch_mutex_unlock(mutex);
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t * hash, const char *key) SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t *hash, const char *key)
{ {
sqlite3HashInsert(&hash->table, key, (int)strlen(key)+1, NULL); sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t * hash, const char *key, switch_mutex_t *mutex) SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t *hash, const char *key, switch_mutex_t *mutex)
{ {
if (mutex) { if (mutex) {
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
sqlite3HashInsert(&hash->table, key, (int)strlen(key)+1, NULL); sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL);
if (mutex) { if (mutex) {
switch_mutex_unlock(mutex); switch_mutex_unlock(mutex);
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t * hash, const char *key) SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t *hash, const char *key)
{ {
return sqlite3HashFind(&hash->table, key, (int)strlen(key)+1); return sqlite3HashFind(&hash->table, key, (int) strlen(key) + 1);
} }
SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t * hash, const char *key, switch_mutex_t *mutex) SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t *hash, const char *key, switch_mutex_t *mutex)
{ {
void *val; void *val;
@ -117,8 +117,8 @@ SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t * hash, const
switch_mutex_lock(mutex); switch_mutex_lock(mutex);
} }
val = sqlite3HashFind(&hash->table, key, (int)strlen(key)+1); val = sqlite3HashFind(&hash->table, key, (int) strlen(key) + 1);
if (mutex) { if (mutex) {
switch_mutex_unlock(mutex); switch_mutex_unlock(mutex);
} }

View File

@ -35,7 +35,8 @@
#include <switch.h> #include <switch.h>
#include "private/switch_core_pvt.h" #include "private/switch_core_pvt.h"
SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id) SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags,
int stream_id)
{ {
switch_io_event_hook_video_write_frame_t *ptr; switch_io_event_hook_video_write_frame_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -56,7 +57,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id) SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags,
int stream_id)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_io_event_hook_video_read_frame_t *ptr; switch_io_event_hook_video_read_frame_t *ptr;
@ -68,8 +70,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
} }
if (session->endpoint_interface->io_routines->read_video_frame) { if (session->endpoint_interface->io_routines->read_video_frame) {
if ((status = if ((status = session->endpoint_interface->io_routines->read_video_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
session->endpoint_interface->io_routines->read_video_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.video_read_frame; ptr; ptr = ptr->next) { for (ptr = session->event_hooks.video_read_frame; ptr; ptr = ptr->next) {
if ((status = ptr->video_read_frame(session, frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) { if ((status = ptr->video_read_frame(session, frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
break; break;
@ -93,12 +94,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
goto done; goto done;
} }
done: done:
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id) SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags,
int stream_id)
{ {
switch_io_event_hook_read_frame_t *ptr; switch_io_event_hook_read_frame_t *ptr;
switch_status_t status; switch_status_t status;
@ -107,7 +109,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_assert(session != NULL); switch_assert(session != NULL);
top: top:
if (switch_channel_get_state(session->channel) >= CS_HANGUP) { if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
*frame = NULL; *frame = NULL;
@ -126,8 +128,7 @@ top:
} }
if (session->endpoint_interface->io_routines->read_frame) { if (session->endpoint_interface->io_routines->read_frame) {
if ((status = if ((status = session->endpoint_interface->io_routines->read_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
session->endpoint_interface->io_routines->read_frame(session, frame, flags, stream_id)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) { for (ptr = session->event_hooks.read_frame; ptr; ptr = ptr->next) {
if ((status = ptr->read_frame(session, frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) { if ((status = ptr->read_frame(session, frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
break; break;
@ -150,7 +151,7 @@ top:
/* Fast PASS! */ /* Fast PASS! */
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
goto done; goto done;
} }
if (switch_test_flag(*frame, SFF_CNG)) { if (switch_test_flag(*frame, SFF_CNG)) {
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
@ -158,7 +159,7 @@ top:
goto done; goto done;
} }
is_cng = 1; is_cng = 1;
} }
switch_assert((*frame)->codec != NULL); switch_assert((*frame)->codec != NULL);
@ -195,15 +196,15 @@ top:
if (!switch_test_flag(session, SSF_WARN_TRANSCODE)) { 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; msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY;
switch_core_session_receive_message(session, &msg); switch_core_session_receive_message(session, &msg);
switch_set_flag(session, SSF_WARN_TRANSCODE); switch_set_flag(session, SSF_WARN_TRANSCODE);
} }
if (read_frame->codec || is_cng) { if (read_frame->codec || is_cng) {
session->raw_read_frame.datalen = session->raw_read_frame.buflen; session->raw_read_frame.datalen = session->raw_read_frame.buflen;
if (is_cng) { if (is_cng) {
memset(session->raw_read_frame.data, 255, read_frame->codec->implementation->bytes_per_frame); memset(session->raw_read_frame.data, 255, read_frame->codec->implementation->bytes_per_frame);
session->raw_read_frame.datalen = read_frame->codec->implementation->bytes_per_frame; session->raw_read_frame.datalen = read_frame->codec->implementation->bytes_per_frame;
@ -241,7 +242,7 @@ top:
session->read_codec->implementation->actual_samples_per_second, session->read_codec->implementation->actual_samples_per_second,
session->read_codec->implementation->bytes_per_frame, session->pool); session->read_codec->implementation->bytes_per_frame, session->pool);
switch_mutex_unlock(session->resample_mutex); switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate resampler\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate resampler\n");
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
@ -263,7 +264,7 @@ top:
switch_mutex_lock(session->resample_mutex); switch_mutex_lock(session->resample_mutex);
switch_resample_destroy(&session->read_resampler); switch_resample_destroy(&session->read_resampler);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n");
switch_mutex_unlock(session->resample_mutex); switch_mutex_unlock(session->resample_mutex);
} }
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
@ -296,12 +297,13 @@ top:
switch_mutex_lock(bp->read_mutex); switch_mutex_lock(bp->read_mutex);
switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen);
if (bp->callback) { if (bp->callback) {
if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= switch_timestamp(NULL))) { if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE
|| (bp->stop_time && bp->stop_time <= switch_timestamp(NULL))) {
ok = SWITCH_FALSE; ok = SWITCH_FALSE;
} }
} }
switch_mutex_unlock(bp->read_mutex); switch_mutex_unlock(bp->read_mutex);
} }
if (switch_test_flag(bp, SMBF_READ_REPLACE)) { if (switch_test_flag(bp, SMBF_READ_REPLACE)) {
do_bugs = 0; do_bugs = 0;
@ -339,21 +341,21 @@ top:
} }
if (session->read_codec) { if (session->read_codec) {
if (session->read_resampler) { if (session->read_resampler) {
short *data = read_frame->data; short *data = read_frame->data;
switch_mutex_lock(session->resample_mutex); switch_mutex_lock(session->resample_mutex);
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2); session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
session->read_resampler->to_len = session->read_resampler->to_len =
switch_resample_process(session->read_resampler, session->read_resampler->from, switch_resample_process(session->read_resampler, session->read_resampler->from,
session->read_resampler->from_len, session->read_resampler->to, session->read_resampler->to_size, 0); session->read_resampler->from_len, session->read_resampler->to, session->read_resampler->to_size, 0);
switch_float_to_short(session->read_resampler->to, data, read_frame->datalen); switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
read_frame->samples = session->read_resampler->to_len; read_frame->samples = session->read_resampler->to_len;
read_frame->datalen = session->read_resampler->to_len * 2; read_frame->datalen = session->read_resampler->to_len * 2;
read_frame->rate = session->read_resampler->to_rate; read_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex); switch_mutex_unlock(session->resample_mutex);
} }
if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) { if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) {
perfect = TRUE; perfect = TRUE;
@ -368,7 +370,7 @@ top:
goto done; goto done;
} }
} }
if (perfect || switch_buffer_inuse(session->raw_read_buffer) >= session->read_codec->implementation->bytes_per_frame) { if (perfect || switch_buffer_inuse(session->raw_read_buffer) >= session->read_codec->implementation->bytes_per_frame) {
if (perfect) { if (perfect) {
@ -448,7 +450,8 @@ top:
if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) { if (bp->ready && switch_test_flag(bp, SMBF_READ_PING)) {
switch_mutex_lock(bp->read_mutex); switch_mutex_lock(bp->read_mutex);
if (bp->callback) { if (bp->callback) {
if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_PING) == SWITCH_FALSE || (bp->stop_time && bp->stop_time <= switch_timestamp(NULL))) { if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ_PING) == SWITCH_FALSE
|| (bp->stop_time && bp->stop_time <= switch_timestamp(NULL))) {
ok = SWITCH_FALSE; ok = SWITCH_FALSE;
} }
} }
@ -476,7 +479,7 @@ top:
} }
} }
even_more_done: even_more_done:
if (!*frame) { if (!*frame) {
*frame = &runtime.dummy_cng_frame; *frame = &runtime.dummy_cng_frame;
@ -504,7 +507,8 @@ static switch_status_t perform_write(switch_core_session_t *session, switch_fram
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id) SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags,
int stream_id)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -569,7 +573,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
if (need_codec) { if (need_codec) {
if (!switch_test_flag(session, SSF_WARN_TRANSCODE)) { 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; msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY;
switch_core_session_receive_message(session, &msg); switch_core_session_receive_message(session, &msg);
switch_set_flag(session, SSF_WARN_TRANSCODE); switch_set_flag(session, SSF_WARN_TRANSCODE);
@ -637,7 +641,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
if (session->write_resampler) { if (session->write_resampler) {
short *data = write_frame->data; short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex); switch_mutex_lock(session->resample_mutex);
session->write_resampler->from_len = write_frame->datalen / 2; session->write_resampler->from_len = write_frame->datalen / 2;
@ -665,14 +669,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
continue; continue;
} }
if (switch_test_flag(bp, SMBF_WRITE_STREAM)) { if (switch_test_flag(bp, SMBF_WRITE_STREAM)) {
switch_mutex_lock(bp->write_mutex); switch_mutex_lock(bp->write_mutex);
switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen); switch_buffer_write(bp->raw_write_buffer, write_frame->data, write_frame->datalen);
switch_mutex_unlock(bp->write_mutex); switch_mutex_unlock(bp->write_mutex);
if (bp->callback) { if (bp->callback) {
ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_WRITE); ok = bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_WRITE);
} }
} }
if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) { if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) {
do_bugs = 0; do_bugs = 0;
@ -807,8 +811,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
rate = frame->codec->implementation->actual_samples_per_second; rate = frame->codec->implementation->actual_samples_per_second;
} else { } else {
rate = session->write_codec->implementation->actual_samples_per_second; rate = session->write_codec->implementation->actual_samples_per_second;
} }
status = switch_core_codec_encode(session->write_codec, status = switch_core_codec_encode(session->write_codec,
frame->codec, frame->codec,
enc_frame->data, enc_frame->data,
@ -832,7 +836,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
session->write_codec->implementation->actual_samples_per_second, session->write_codec->implementation->actual_samples_per_second,
session->write_codec->implementation->bytes_per_frame, session->pool); session->write_codec->implementation->bytes_per_frame, session->pool);
switch_mutex_unlock(session->resample_mutex); switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
goto done; goto done;
} }
@ -871,7 +875,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
if (session->read_resampler) { if (session->read_resampler) {
short *data = write_frame->data; short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex); switch_mutex_lock(session->resample_mutex);
session->read_resampler->from_len = session->read_resampler->from_len =
switch_short_to_float(data, session->read_resampler->from, (int) write_frame->datalen / 2); switch_short_to_float(data, session->read_resampler->from, (int) write_frame->datalen / 2);
session->read_resampler->to_len = (uint32_t) session->read_resampler->to_len = (uint32_t)
@ -883,7 +887,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
write_frame->datalen = session->read_resampler->to_len * 2; write_frame->datalen = session->read_resampler->to_len * 2;
write_frame->rate = session->read_resampler->to_rate; write_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex); switch_mutex_unlock(session->resample_mutex);
} }
if (flag & SFF_CNG) { if (flag & SFF_CNG) {
switch_set_flag(write_frame, SFF_CNG); switch_set_flag(write_frame, SFF_CNG);
@ -941,10 +945,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_kill_channel(switch_
SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
{ {
switch_io_event_hook_recv_dtmf_t *ptr; switch_io_event_hook_recv_dtmf_t *ptr;
switch_status_t status; switch_status_t status;
switch_dtmf_t new_dtmf; switch_dtmf_t new_dtmf;
if (switch_channel_get_state(session->channel) >= CS_HANGUP) { if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -954,7 +958,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_sessio
new_dtmf = *dtmf; new_dtmf = *dtmf;
if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n",
switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration); switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
new_dtmf.duration = switch_core_max_dtmf_duration(0); new_dtmf.duration = switch_core_max_dtmf_duration(0);
} else if (!new_dtmf.duration) { } else if (!new_dtmf.duration) {
@ -974,7 +978,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
switch_io_event_hook_send_dtmf_t *ptr; switch_io_event_hook_send_dtmf_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_dtmf_t new_dtmf; switch_dtmf_t new_dtmf;
if (switch_channel_get_state(session->channel) >= CS_HANGUP) { if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -984,7 +988,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
new_dtmf = *dtmf; new_dtmf = *dtmf;
if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n",
switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration); switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration);
new_dtmf.duration = switch_core_max_dtmf_duration(0); new_dtmf.duration = switch_core_max_dtmf_duration(0);
} else if (!new_dtmf.duration) { } else if (!new_dtmf.duration) {
@ -997,7 +1001,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
} }
if (session->endpoint_interface->io_routines->send_dtmf) { if (session->endpoint_interface->io_routines->send_dtmf) {
if (dtmf->digit == 'w') { if (dtmf->digit == 'w') {
switch_yield(500000); switch_yield(500000);
@ -1013,19 +1017,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string) SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string)
{ {
char *p; char *p;
switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)}; switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
int sent = 0, dur; int sent = 0, dur;
char *string; char *string;
int i, argc; int i, argc;
char *argv[256]; char *argv[256];
switch_assert(session != NULL); switch_assert(session != NULL);
if (switch_channel_get_state(session->channel) >= CS_HANGUP) { if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (switch_strlen_zero(dtmf_string)) { if (switch_strlen_zero(dtmf_string)) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -1037,12 +1041,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
string = switch_core_session_strdup(session, dtmf_string); string = switch_core_session_strdup(session, dtmf_string);
argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
if (argc) { if (argc) {
switch_channel_pre_answer(session->channel); switch_channel_pre_answer(session->channel);
} }
for(i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
dtmf.duration = switch_core_default_dtmf_duration(0); dtmf.duration = switch_core_default_dtmf_duration(0);
dur = switch_core_default_dtmf_duration(0) / 8; dur = switch_core_default_dtmf_duration(0) / 8;
if ((p = strchr(argv[i], '@'))) { if ((p = strchr(argv[i], '@'))) {
@ -1054,7 +1058,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
if (dtmf.duration > switch_core_max_dtmf_duration(0)) { if (dtmf.duration > switch_core_max_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s EXECSSIVE DTMF DIGIT [%c] LEN [%d]\n",
switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration); switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration);
dtmf.duration = switch_core_max_dtmf_duration(0); dtmf.duration = switch_core_max_dtmf_duration(0);
} else if (!dtmf.duration) { } else if (!dtmf.duration) {
@ -1071,7 +1075,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
} }
} }
} }
} }
return sent ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE; return sent ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
} }

View File

@ -100,7 +100,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
if ((bug->raw_read_buffer && bug->raw_write_buffer) && (!rlen && !wlen)) { if ((bug->raw_read_buffer && bug->raw_write_buffer) && (!rlen && !wlen)) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
maxlen = SWITCH_RECOMMENDED_BUFFER_SIZE > frame->buflen ? frame->buflen : SWITCH_RECOMMENDED_BUFFER_SIZE; maxlen = SWITCH_RECOMMENDED_BUFFER_SIZE > frame->buflen ? frame->buflen : SWITCH_RECOMMENDED_BUFFER_SIZE;
if ((rdlen = rlen > wlen ? wlen : rlen) > maxlen) { if ((rdlen = rlen > wlen ? wlen : rlen) > maxlen) {
@ -128,11 +128,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
bytes = (datalen > frame->datalen) ? datalen : frame->datalen; bytes = (datalen > frame->datalen) ? datalen : frame->datalen;
switch_assert( bytes <= maxlen ); switch_assert(bytes <= maxlen);
if (bytes) { if (bytes) {
int16_t *tp = bug->tmp; int16_t *tp = bug->tmp;
dp = (int16_t *) bug->data; dp = (int16_t *) bug->data;
fp = (int16_t *) frame->data; fp = (int16_t *) frame->data;
rlen = frame->datalen / 2; rlen = frame->datalen / 2;
@ -171,10 +171,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b
frame->datalen = bytes; frame->datalen = bytes;
frame->samples = bytes / sizeof(int16_t); frame->samples = bytes / sizeof(int16_t);
frame->rate = read_codec->implementation->actual_samples_per_second; frame->rate = read_codec->implementation->actual_samples_per_second;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -183,7 +183,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
switch_media_bug_callback_t callback, switch_media_bug_callback_t callback,
void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug) void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
{ {
switch_media_bug_t *bug;//, *bp; switch_media_bug_t *bug; //, *bp;
switch_size_t bytes; switch_size_t bytes;
if (flags & SMBF_WRITE_REPLACE) { if (flags & SMBF_WRITE_REPLACE) {
@ -287,7 +287,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
switch_thread_rwlock_unlock(session->bug_rwlock); switch_thread_rwlock_unlock(session->bug_rwlock);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if (session->bug_codec.implementation) { if (session->bug_codec.implementation) {
switch_core_codec_destroy(&session->bug_codec); switch_core_codec_destroy(&session->bug_codec);
} }
@ -313,7 +313,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t *
*bug = NULL; *bug = NULL;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -350,7 +350,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
if (!session->bugs && session->bug_codec.implementation) { if (!session->bugs && session->bug_codec.implementation) {
switch_core_codec_destroy(&session->bug_codec); switch_core_codec_destroy(&session->bug_codec);
} }
return status; return status;
} }

View File

@ -43,7 +43,7 @@
static struct { static struct {
switch_mutex_t *mem_lock; switch_mutex_t *mem_lock;
switch_queue_t *pool_queue; /* 8 ball break */ switch_queue_t *pool_queue; /* 8 ball break */
switch_queue_t *pool_recycle_queue; switch_queue_t *pool_recycle_queue;
switch_memory_pool_t *memory_pool; switch_memory_pool_t *memory_pool;
int pool_thread_running; int pool_thread_running;
@ -58,7 +58,8 @@ SWITCH_DECLARE(switch_memory_pool_t *) switch_core_session_get_pool(switch_core_
/* **ONLY** alloc things with this function that **WILL NOT** outlive /* **ONLY** alloc things with this function that **WILL NOT** outlive
the session itself or expect an earth shattering KABOOM!*/ the session itself or expect an earth shattering KABOOM!*/
SWITCH_DECLARE(void *) switch_core_perform_session_alloc(switch_core_session_t *session, switch_size_t memory, const char *file, const char *func, int line) SWITCH_DECLARE(void *) switch_core_perform_session_alloc(switch_core_session_t *session, switch_size_t memory, const char *file, const char *func,
int line)
{ {
void *ptr = NULL; void *ptr = NULL;
switch_assert(session != NULL); switch_assert(session != NULL);
@ -70,14 +71,14 @@ SWITCH_DECLARE(void *) switch_core_perform_session_alloc(switch_core_session_t *
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
if (memory > 500) if (memory > 500)
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Session Allocate %d\n", (int)memory); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Session Allocate %d\n", (int) memory);
#endif #endif
ptr = apr_palloc(session->pool, memory); ptr = apr_palloc(session->pool, memory);
switch_assert(ptr != NULL); switch_assert(ptr != NULL);
memset(ptr, 0, memory); memset(ptr, 0, memory);
#ifdef LOCK_MORE #ifdef LOCK_MORE
switch_mutex_unlock(memory_manager.mem_lock); switch_mutex_unlock(memory_manager.mem_lock);
#endif #endif
@ -98,7 +99,7 @@ SWITCH_DECLARE(void *) switch_core_perform_permanent_alloc(switch_size_t memory,
#endif #endif
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %d\n", (int)memory); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %d\n", (int) memory);
#endif #endif
ptr = apr_palloc(memory_manager.memory_pool, memory); ptr = apr_palloc(memory_manager.memory_pool, memory);
@ -131,7 +132,7 @@ SWITCH_DECLARE(char *) switch_core_perform_permanent_strdup(const char *todup, c
switch_assert(duped != NULL); switch_assert(duped != NULL);
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %d\n", (int)len); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Perm Allocate %d\n", (int) len);
#endif #endif
#ifdef LOCK_MORE #ifdef LOCK_MORE
@ -153,7 +154,7 @@ SWITCH_DECLARE(char *) switch_core_session_sprintf(switch_core_session_t *sessio
switch_assert(session != NULL); switch_assert(session != NULL);
switch_assert(session->pool != NULL); switch_assert(session->pool != NULL);
va_start(ap, fmt); va_start(ap, fmt);
result = apr_pvsprintf(session->pool, fmt, ap); result = apr_pvsprintf(session->pool, fmt, ap);
switch_assert(result != NULL); switch_assert(result != NULL);
va_end(ap); va_end(ap);
@ -199,7 +200,6 @@ SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t
if (!todup) { if (!todup) {
return NULL; return NULL;
} }
#ifdef LOCK_MORE #ifdef LOCK_MORE
switch_mutex_lock(memory_manager.mem_lock); switch_mutex_lock(memory_manager.mem_lock);
#endif #endif
@ -208,7 +208,7 @@ SWITCH_DECLARE(char *) switch_core_perform_session_strdup(switch_core_session_t
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
if (len > 500) if (len > 500)
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Sess Strdup Allocate %d\n", (int)len); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Sess Strdup Allocate %d\n", (int) len);
#endif #endif
duped = apr_pstrmemdup(session->pool, todup, len); duped = apr_pstrmemdup(session->pool, todup, len);
@ -231,7 +231,6 @@ SWITCH_DECLARE(char *) switch_core_perform_strdup(switch_memory_pool_t *pool, co
if (!todup) { if (!todup) {
return NULL; return NULL;
} }
#ifdef LOCK_MORE #ifdef LOCK_MORE
switch_mutex_lock(memory_manager.mem_lock); switch_mutex_lock(memory_manager.mem_lock);
#endif #endif
@ -240,7 +239,7 @@ SWITCH_DECLARE(char *) switch_core_perform_strdup(switch_memory_pool_t *pool, co
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
if (len > 500) if (len > 500)
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "core strdup Allocate %d\n", (int)len); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "core strdup Allocate %d\n", (int) len);
#endif #endif
duped = apr_pstrmemdup(pool, todup, len); duped = apr_pstrmemdup(pool, todup, len);
@ -262,10 +261,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_new_memory_pool(switch_memor
{ {
char *tmp; char *tmp;
#ifdef PER_POOL_LOCK #ifdef PER_POOL_LOCK
apr_allocator_t *my_allocator = NULL; apr_allocator_t *my_allocator = NULL;
apr_thread_mutex_t *my_mutex; apr_thread_mutex_t *my_mutex;
#else #else
void *pop = NULL; void *pop = NULL;
#endif #endif
switch_mutex_lock(memory_manager.mem_lock); switch_mutex_lock(memory_manager.mem_lock);
@ -322,7 +321,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(switch_m
apr_pool_destroy(*pool); apr_pool_destroy(*pool);
} }
*pool = NULL; *pool = NULL;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -338,8 +337,8 @@ SWITCH_DECLARE(void *) switch_core_perform_alloc(switch_memory_pool_t *pool, swi
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
if (memory > 500) if (memory > 500)
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Core Allocate %d\n", (int)memory); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "Core Allocate %d\n", (int) memory);
/*switch_assert(memory < 20000);*/ /*switch_assert(memory < 20000); */
#endif #endif
ptr = apr_palloc(pool, memory); ptr = apr_palloc(pool, memory);
@ -357,9 +356,9 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim(void)
{ {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
void *pop = NULL; void *pop = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled memory pool(s)\n",
switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue)); switch_queue_size(memory_manager.pool_recycle_queue) + switch_queue_size(memory_manager.pool_queue));
while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop(memory_manager.pool_recycle_queue, &pop) == SWITCH_STATUS_SUCCESS) {
pool = (switch_memory_pool_t *) pop; pool = (switch_memory_pool_t *) pop;
if (!pool) { if (!pool) {
@ -369,7 +368,7 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim(void)
} }
} }
static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t *thread, void *obj)
{ {
memory_manager.pool_thread_running = 1; memory_manager.pool_thread_running = 1;
@ -388,7 +387,6 @@ static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t * thread, void *obj)
break; break;
} }
#if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS) #if defined(PER_POOL_LOCK) || defined(DESTROY_POOLS)
apr_pool_destroy(pop); apr_pool_destroy(pop);
#else #else
@ -408,7 +406,7 @@ static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t * thread, void *obj)
} }
} }
done: done:
switch_core_memory_reclaim(); switch_core_memory_reclaim();
{ {
@ -428,7 +426,7 @@ void switch_core_memory_stop(void)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
memory_manager.pool_thread_running = -1; memory_manager.pool_thread_running = -1;
while(memory_manager.pool_thread_running) { while (memory_manager.pool_thread_running) {
switch_yield(1000); switch_yield(1000);
} }
} }
@ -436,7 +434,7 @@ void switch_core_memory_stop(void)
switch_memory_pool_t *switch_core_memory_init(void) switch_memory_pool_t *switch_core_memory_init(void)
{ {
switch_thread_t *thread; switch_thread_t *thread;
switch_threadattr_t *thd_attr; switch_threadattr_t *thd_attr;
#ifdef PER_POOL_LOCK #ifdef PER_POOL_LOCK
apr_allocator_t *my_allocator = NULL; apr_allocator_t *my_allocator = NULL;
apr_thread_mutex_t *my_mutex; apr_thread_mutex_t *my_mutex;
@ -445,22 +443,22 @@ switch_memory_pool_t *switch_core_memory_init(void)
memset(&memory_manager, 0, sizeof(memory_manager)); memset(&memory_manager, 0, sizeof(memory_manager));
#ifdef PER_POOL_LOCK #ifdef PER_POOL_LOCK
if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) { if ((apr_allocator_create(&my_allocator)) != APR_SUCCESS) {
abort(); abort();
} }
if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) { if ((apr_pool_create_ex(&memory_manager.memory_pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
apr_allocator_destroy(my_allocator); apr_allocator_destroy(my_allocator);
my_allocator = NULL; my_allocator = NULL;
abort(); abort();
} }
if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_DEFAULT, memory_manager.memory_pool)) != APR_SUCCESS) { if ((apr_thread_mutex_create(&my_mutex, APR_THREAD_MUTEX_DEFAULT, memory_manager.memory_pool)) != APR_SUCCESS) {
abort(); abort();
} }
apr_allocator_mutex_set(my_allocator, my_mutex); apr_allocator_mutex_set(my_allocator, my_mutex);
apr_allocator_owner_set(my_allocator, memory_manager.memory_pool); apr_allocator_owner_set(my_allocator, memory_manager.memory_pool);
#else #else
apr_pool_create(&memory_manager.memory_pool, NULL); apr_pool_create(&memory_manager.memory_pool, NULL);
switch_assert(memory_manager.memory_pool != NULL); switch_assert(memory_manager.memory_pool != NULL);
@ -475,7 +473,7 @@ switch_memory_pool_t *switch_core_memory_init(void)
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool); switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
while (!memory_manager.pool_thread_running) { while (!memory_manager.pool_thread_running) {
switch_yield(1000); switch_yield(1000);
} }

View File

@ -54,7 +54,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t sta
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_core_port_allocator_t *alloc; switch_core_port_allocator_t *alloc;
int even, odd; int even, odd;
if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_new_memory_pool(&pool)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
@ -63,7 +63,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t sta
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
alloc->flags = flags; alloc->flags = flags;
even = switch_test_flag(alloc, SPF_EVEN); even = switch_test_flag(alloc, SPF_EVEN);
odd = switch_test_flag(alloc, SPF_ODD); odd = switch_test_flag(alloc, SPF_ODD);
@ -90,14 +90,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_new(switch_port_t sta
} }
} }
alloc->track_len = (end - start) + 2; alloc->track_len = (end - start) + 2;
if (!(even && odd)) { if (!(even && odd)) {
alloc->track_len /= 2; alloc->track_len /= 2;
} }
alloc->track = switch_core_alloc(pool, (alloc->track_len + 2) * sizeof(switch_byte_t)); alloc->track = switch_core_alloc(pool, (alloc->track_len + 2) * sizeof(switch_byte_t));
alloc->start = start; alloc->start = start;
alloc->next = start; alloc->next = start;
alloc->end = end; alloc->end = end;
@ -118,20 +118,20 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_request_port(switch_c
int odd = switch_test_flag(alloc, SPF_ODD); int odd = switch_test_flag(alloc, SPF_ODD);
switch_mutex_lock(alloc->mutex); switch_mutex_lock(alloc->mutex);
srand(getpid() + (unsigned)switch_timestamp(NULL)); srand(getpid() + (unsigned) switch_timestamp(NULL));
while(alloc->track_used < alloc->track_len) { while (alloc->track_used < alloc->track_len) {
double r; double r;
uint32_t index; uint32_t index;
int tries = 0; int tries = 0;
do { do {
r = ((double)rand() / ((double)(RAND_MAX)+(double)(1))); r = ((double) rand() / ((double) (RAND_MAX) + (double) (1)));
index = (int) (r * alloc->track_len); index = (int) (r * alloc->track_len);
tries++; tries++;
} while((alloc->track[index] || index >= alloc->track_len) && tries < 10000); } while ((alloc->track[index] || index >= alloc->track_len) && tries < 10000);
while(alloc->track[index]) { while (alloc->track[index]) {
if (++index >= alloc->track_len) { if (++index >= alloc->track_len) {
index = 0; index = 0;
} }
@ -143,29 +143,29 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_request_port(switch_c
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
if ((even && odd)) { if ((even && odd)) {
port = (switch_port_t)(index + alloc->start); port = (switch_port_t) (index + alloc->start);
} else { } else {
port = (switch_port_t)(index + (alloc->start / 2)); port = (switch_port_t) (index + (alloc->start / 2));
port *= 2; port *= 2;
} }
goto end; goto end;
} }
} }
end: end:
switch_mutex_unlock(alloc->mutex); switch_mutex_unlock(alloc->mutex);
if (status == SWITCH_STATUS_SUCCESS) { if (status == SWITCH_STATUS_SUCCESS) {
*port_ptr = port; *port_ptr = port;
} else { } else {
*port_ptr = 0; *port_ptr = 0;
} }
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(switch_core_port_allocator_t *alloc, switch_port_t port) SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(switch_core_port_allocator_t *alloc, switch_port_t port)
@ -174,7 +174,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_port_allocator_free_port(switch_core
int even = switch_test_flag(alloc, SPF_EVEN); int even = switch_test_flag(alloc, SPF_EVEN);
int odd = switch_test_flag(alloc, SPF_ODD); int odd = switch_test_flag(alloc, SPF_ODD);
int index = port - alloc->start; int index = port - alloc->start;
if (!(even && odd)) { if (!(even && odd)) {
index /= 2; index /= 2;
} }

View File

@ -57,7 +57,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_sessio
if (switch_test_flag(session, SSF_DESTROYED)) { if (switch_test_flag(session, SSF_DESTROYED)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
#ifdef SWITCH_DEBUG_RWLOCKS #ifdef SWITCH_DEBUG_RWLOCKS
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n",
switch_channel_get_name(session->channel));
#endif #endif
} else { } else {
status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock); status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
@ -75,7 +76,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_sessio
SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session, const char *file, const char *func, int line) SWITCH_DECLARE(void) switch_core_session_perform_write_lock(switch_core_session_t *session, const char *file, const char *func, int line)
{ {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Write lock AQUIRED\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Write lock AQUIRED\n",
switch_channel_get_name(session->channel));
#else #else
SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *session) SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *session)
{ {

View File

@ -174,9 +174,7 @@ SWITCH_DECLARE(int) switch_core_session_get_stream_count(switch_core_session_t *
} }
SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const char *endpoint_name, SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const char *endpoint_name,
switch_core_session_t **new_session, switch_core_session_t **new_session, switch_memory_pool_t **pool, void *data)
switch_memory_pool_t **pool,
void *data)
{ {
const switch_endpoint_interface_t *endpoint_interface; const switch_endpoint_interface_t *endpoint_interface;
@ -188,12 +186,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const
return endpoint_interface->io_routines->resurrect_session(new_session, pool, data); return endpoint_interface->io_routines->resurrect_session(new_session, pool, data);
} }
SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event, SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
const char *endpoint_name, const char *endpoint_name,
switch_caller_profile_t *caller_profile, switch_caller_profile_t *caller_profile,
switch_core_session_t **new_session, switch_core_session_t **new_session,
switch_memory_pool_t **pool, switch_memory_pool_t **pool, switch_originate_flag_t flags)
switch_originate_flag_t flags)
{ {
switch_io_event_hook_outgoing_channel_t *ptr; switch_io_event_hook_outgoing_channel_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -218,10 +215,10 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL); switch_assert(channel != NULL);
forwardvar = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE); forwardvar = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE);
if (!switch_strlen_zero(forwardvar)) { if (!switch_strlen_zero(forwardvar)) {
forwardval = atoi(forwardvar) - 1; forwardval = atoi(forwardvar) - 1;
} }
if (forwardval <= 0) { if (forwardval <= 0) {
return SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR; return SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR;
@ -249,7 +246,8 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const
} }
} }
if ((cause = endpoint_interface->io_routines->outgoing_channel(session, var_event, outgoing_profile, new_session, pool, flags)) != SWITCH_CAUSE_SUCCESS) { if ((cause =
endpoint_interface->io_routines->outgoing_channel(session, var_event, outgoing_profile, new_session, pool, flags)) != SWITCH_CAUSE_SUCCESS) {
return cause; return cause;
} }
@ -262,16 +260,16 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const
} }
if (!*new_session) { if (!*new_session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "outgoing method for endpoint: [%s] returned: [%s] but there is no new session!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "outgoing method for endpoint: [%s] returned: [%s] but there is no new session!\n",
endpoint_name, switch_channel_cause2str(cause)); endpoint_name, switch_channel_cause2str(cause));
return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} else { } else {
switch_caller_profile_t *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL; switch_caller_profile_t *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL;
switch_event_t *event; switch_event_t *event;
switch_channel_t *peer_channel = switch_core_session_get_channel(*new_session); switch_channel_t *peer_channel = switch_core_session_get_channel(*new_session);
switch_assert(peer_channel); switch_assert(peer_channel);
peer_profile = switch_channel_get_caller_profile(peer_channel); peer_profile = switch_channel_get_caller_profile(peer_channel);
if (channel) { if (channel) {
@ -339,7 +337,7 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_resurrect_channel(const
switch_channel_set_originator_caller_profile(peer_channel, cloned_profile); switch_channel_set_originator_caller_profile(peer_channel, cloned_profile);
} }
} }
if (peer_profile) { if (peer_profile) {
if ((cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) { if ((cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) {
switch_channel_set_originatee_caller_profile(channel, cloned_profile); switch_channel_set_originatee_caller_profile(channel, cloned_profile);
@ -370,9 +368,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_
if ((status = switch_core_session_read_lock(session)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_session_read_lock(session)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
switch_core_session_signal_lock(session); switch_core_session_signal_lock(session);
if (session->endpoint_interface->io_routines->receive_message) { if (session->endpoint_interface->io_routines->receive_message) {
status = session->endpoint_interface->io_routines->receive_message(session, message); status = session->endpoint_interface->io_routines->receive_message(session, message);
} }
@ -396,7 +394,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_
SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(switch_core_session_t *session, switch_core_session_message_types_t indication) SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(switch_core_session_t *session, switch_core_session_message_types_t indication)
{ {
switch_core_session_message_t msg = {0}; switch_core_session_message_t msg = { 0 };
switch_core_session_t *other_session; switch_core_session_t *other_session;
const char *uuid; const char *uuid;
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
@ -410,7 +408,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_pass_indication(switch_core_
} else { } else {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} }
return status; return status;
} }
@ -426,7 +424,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_queue_indication(switch_core
switch_core_session_queue_message(session, msg); switch_core_session_queue_message(session, msg);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -441,7 +439,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_queue_message(switch_core_se
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
} }
return status; return status;
} }
@ -581,7 +579,7 @@ SWITCH_DECLARE(uint32_t) switch_core_session_private_event_count(switch_core_ses
if (!switch_channel_test_flag(channel, CF_EVENT_LOCK) && session->private_event_queue) { if (!switch_channel_test_flag(channel, CF_EVENT_LOCK) && session->private_event_queue) {
return switch_queue_size(session->private_event_queue); return switch_queue_size(session->private_event_queue);
} }
return 0; return 0;
} }
@ -615,7 +613,7 @@ SWITCH_DECLARE(uint32_t) switch_core_session_flush_private_events(switch_core_se
x++; x++;
} }
} }
return x; return x;
} }
@ -624,7 +622,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_size_t has; switch_size_t has;
/* clear resamplers*/ /* clear resamplers */
switch_resample_destroy(&session->read_resampler); switch_resample_destroy(&session->read_resampler);
switch_resample_destroy(&session->write_resampler); switch_resample_destroy(&session->write_resampler);
@ -634,7 +632,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
/* wipe theese, they will be recreated if need be */ /* wipe theese, they will be recreated if need be */
switch_buffer_destroy(&session->raw_read_buffer); switch_buffer_destroy(&session->raw_read_buffer);
switch_buffer_destroy(&session->raw_write_buffer); switch_buffer_destroy(&session->raw_write_buffer);
if (flush_dtmf) { if (flush_dtmf) {
while ((has = switch_channel_has_dtmf(channel))) { while ((has = switch_channel_has_dtmf(channel))) {
switch_channel_flush_dtmf(channel); switch_channel_flush_dtmf(channel);
@ -657,7 +655,7 @@ SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session
{ {
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_io_event_hook_state_change_t *ptr; switch_io_event_hook_state_change_t *ptr;
/* If trylock fails the signal is already awake so we needn't bother */ /* If trylock fails the signal is already awake so we needn't bother */
if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) { if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_signal(session->cond); switch_thread_cond_signal(session->cond);
@ -689,13 +687,12 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t *
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_event_t *event; switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Close Channel %s [%s]\n", switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE, "Close Channel %s [%s]\n",
switch_channel_get_name((*session)->channel), switch_channel_get_name((*session)->channel), switch_channel_state_name(switch_channel_get_state((*session)->channel)));
switch_channel_state_name(switch_channel_get_state((*session)->channel)));
switch_core_media_bug_remove_all(*session); switch_core_media_bug_remove_all(*session);
switch_ivr_deactivate_unicast(*session); switch_ivr_deactivate_unicast(*session);
switch_scheduler_del_task_group((*session)->uuid_str); switch_scheduler_del_task_group((*session)->uuid_str);
switch_mutex_lock(runtime.throttle_mutex); switch_mutex_lock(runtime.throttle_mutex);
@ -722,10 +719,10 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t *
//#endif //#endif
*session = NULL; *session = NULL;
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
} }
static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t *thread, void *obj)
{ {
switch_core_session_t *session = obj; switch_core_session_t *session = obj;
switch_event_t *event; switch_event_t *event;
@ -735,7 +732,7 @@ static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t * thr
session->thread = thread; session->thread = thread;
switch_core_session_run(session); switch_core_session_run(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session %"SWITCH_SIZE_T_FMT" (%s) Locked, Waiting on external entities\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session %" SWITCH_SIZE_T_FMT " (%s) Locked, Waiting on external entities\n",
session->id, switch_channel_get_name(session->channel)); session->id, switch_channel_get_name(session->channel));
switch_core_session_write_lock(session); switch_core_session_write_lock(session);
switch_set_flag(session, SSF_DESTROYED); switch_set_flag(session, SSF_DESTROYED);
@ -753,7 +750,7 @@ static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t * thr
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Session %"SWITCH_SIZE_T_FMT" (%s) Ended\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Session %" SWITCH_SIZE_T_FMT " (%s) Ended\n",
session->id, switch_channel_get_name(session->channel)); session->id, switch_channel_get_name(session->channel));
switch_core_session_destroy(&session); switch_core_session_destroy(&session);
return NULL; return NULL;
@ -769,7 +766,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_thread_launch(switch_core_se
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
switch_mutex_lock(session->mutex); switch_mutex_lock(session->mutex);
if (!session->thread_running) { if (!session->thread_running) {
session->thread_running = 1; session->thread_running = 1;
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@ -818,7 +815,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
count = session_manager.session_count; count = session_manager.session_count;
sps = --runtime.sps; sps = --runtime.sps;
switch_mutex_unlock(runtime.throttle_mutex); switch_mutex_unlock(runtime.throttle_mutex);
if (sps <= 0) { if (sps <= 0) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Throttle Error!\n"); //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Throttle Error!\n");
return NULL; return NULL;
@ -838,7 +835,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
session = switch_core_alloc(usepool, sizeof(*session)); session = switch_core_alloc(usepool, sizeof(*session));
session->pool = usepool; session->pool = usepool;
if (switch_channel_alloc(&session->channel, session->pool) != SWITCH_STATUS_SUCCESS) { if (switch_channel_alloc(&session->channel, session->pool) != SWITCH_STATUS_SUCCESS) {
abort(); abort();
} }
@ -968,13 +965,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_c
switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (!application_interface->application_function) { if (!application_interface->application_function) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n", app); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Function for %s\n", app);
switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(session->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) && !switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA)) { if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) && !switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA)) {
switch_ivr_media(session->uuid_str, SMF_NONE); switch_ivr_media(session->uuid_str, SMF_NONE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Application %s Requires media on channel %s!\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Application %s Requires media on channel %s!\n",
@ -1004,7 +1001,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_c
} }
switch_core_session_exec(session, application_interface, expanded); switch_core_session_exec(session, application_interface, expanded);
if (expanded != arg) { if (expanded != arg) {
switch_safe_free(expanded); switch_safe_free(expanded);
} }
@ -1013,7 +1010,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application(switch_c
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *session,
const switch_application_interface_t *application_interface, const char *arg) { const switch_application_interface_t *application_interface, const char *arg)
{
switch_app_log_t *log, *lp; switch_app_log_t *log, *lp;
switch_event_t *event; switch_event_t *event;
const char *var; const char *var;
@ -1028,7 +1026,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
log->app = switch_core_session_strdup(session, application_interface->interface_name); log->app = switch_core_session_strdup(session, application_interface->interface_name);
log->arg = switch_core_session_strdup(session, arg); log->arg = switch_core_session_strdup(session, arg);
for(lp = session->app_log; lp && lp->next; lp = lp->next); for (lp = session->app_log; lp && lp->next; lp = lp->next);
if (lp) { if (lp) {
lp->next = log; lp->next = log;
@ -1036,7 +1034,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
session->app_log = log; session->app_log = log;
} }
} }
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event); switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", application_interface->interface_name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", application_interface->interface_name);
@ -1049,7 +1047,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
switch_assert(application_interface->application_function); switch_assert(application_interface->application_function);
application_interface->application_function(session, arg); application_interface->application_function(session, arg);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event); switch_channel_event_set_data(session->channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", application_interface->interface_name); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Application", "%s", application_interface->interface_name);
@ -1060,7 +1058,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t *
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_session_t *session, const char *exten, const char *dialplan, const char *context) SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_session_t *session, const char *exten, const char *dialplan,
const char *context)
{ {
char *dp[25]; char *dp[25];
char *dpstr; char *dpstr;
@ -1074,21 +1073,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
if (!(profile = switch_channel_get_caller_profile(channel))) { if (!(profile = switch_channel_get_caller_profile(channel))) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (session->stack_count > SWITCH_MAX_STACKS) { if (session->stack_count > SWITCH_MAX_STACKS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s too many stacked extensions\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s too many stacked extensions\n", switch_channel_get_name(session->channel));
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
session->stack_count++; session->stack_count++;
new_profile = switch_caller_profile_clone(session, profile); new_profile = switch_caller_profile_clone(session, profile);
new_profile->destination_number = switch_core_session_strdup(session, exten); new_profile->destination_number = switch_core_session_strdup(session, exten);
if (!switch_strlen_zero(dialplan)) { if (!switch_strlen_zero(dialplan)) {
new_profile->dialplan = switch_core_session_strdup(session, dialplan); new_profile->dialplan = switch_core_session_strdup(session, dialplan);
} }
if (!switch_strlen_zero(context)) { if (!switch_strlen_zero(context)) {
new_profile->context = switch_core_session_strdup(session, context); new_profile->context = switch_core_session_strdup(session, context);
} }
@ -1101,7 +1100,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
for (x = 0; x < argc; x++) { for (x = 0; x < argc; x++) {
char *dpname = dp[x]; char *dpname = dp[x];
char *dparg = NULL; char *dparg = NULL;
if (dpname) { if (dpname) {
if ((dparg = strchr(dpname, ':'))) { if ((dparg = strchr(dpname, ':'))) {
*dparg++ = '\0'; *dparg++ = '\0';
@ -1113,14 +1112,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) { if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) {
continue; continue;
} }
count++; count++;
if ((extension = dialplan_interface->hunt_function(session, dparg, new_profile)) != 0) { if ((extension = dialplan_interface->hunt_function(session, dparg, new_profile)) != 0) {
break; break;
} }
} }
if (!extension) { if (!extension) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
goto done; goto done;
@ -1129,8 +1128,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
new_profile->caller_extension = extension; new_profile->caller_extension = extension;
if (profile->caller_extension) { if (profile->caller_extension) {
for(pp = profile->caller_extension->children; pp && pp->next; pp = pp->next); for (pp = profile->caller_extension->children; pp && pp->next; pp = pp->next);
if (pp) { if (pp) {
pp->next = new_profile; pp->next = new_profile;
} else { } else {
@ -1141,19 +1140,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_exten(switch_core_se
while (switch_channel_ready(channel) && extension->current_application) { while (switch_channel_ready(channel) && extension->current_application) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Execute %s(%s)\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Execute %s(%s)\n",
extension->current_application->application_name, switch_str_nil(extension->current_application->application_data)); extension->current_application->application_name, switch_str_nil(extension->current_application->application_data));
if (switch_core_session_execute_application(session, if (switch_core_session_execute_application(session,
extension->current_application->application_name, extension->current_application->application_name,
extension->current_application->application_data) != SWITCH_STATUS_SUCCESS) { extension->current_application->application_data) != SWITCH_STATUS_SUCCESS) {
goto done; goto done;
} }
extension->current_application = extension->current_application->next; extension->current_application = extension->current_application->next;
} }
done: done:
session->stack_count--; session->stack_count--;
return status; return status;
} }
/* For Emacs: /* For Emacs:

View File

@ -37,11 +37,8 @@
SWITCH_DECLARE(switch_status_t) switch_core_speech_open(switch_speech_handle_t *sh, SWITCH_DECLARE(switch_status_t) switch_core_speech_open(switch_speech_handle_t *sh,
const char *module_name, const char *module_name,
const char *voice_name, const char *voice_name,
unsigned int rate, unsigned int rate, unsigned int interval, switch_speech_flag_t *flags, switch_memory_pool_t *pool)
unsigned int interval,
switch_speech_flag_t *flags,
switch_memory_pool_t *pool)
{ {
switch_status_t status; switch_status_t status;
char buf[256] = ""; char buf[256] = "";
@ -130,7 +127,7 @@ SWITCH_DECLARE(void) switch_core_speech_float_param_tts(switch_speech_handle_t *
} }
SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh, SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle_t *sh,
void *data, switch_size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags) void *data, switch_size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
{ {
switch_assert(sh != NULL); switch_assert(sh != NULL);

View File

@ -50,8 +50,7 @@ static void switch_core_standard_on_hangup(switch_core_session_t *session)
static void switch_core_standard_on_reset(switch_core_session_t *session) static void switch_core_standard_on_reset(switch_core_session_t *session)
{ {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard RESET %s\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard RESET %s\n", switch_channel_get_name(session->channel));
switch_channel_get_name(session->channel));
} }
static void switch_core_standard_on_routing(switch_core_session_t *session) static void switch_core_standard_on_routing(switch_core_session_t *session)
@ -71,7 +70,7 @@ static void switch_core_standard_on_routing(switch_core_session_t *session)
} else { } else {
char *dp[25]; char *dp[25];
int argc, x, count = 0; int argc, x, count = 0;
if (!switch_strlen_zero(caller_profile->dialplan)) { if (!switch_strlen_zero(caller_profile->dialplan)) {
if ((dpstr = switch_core_session_strdup(session, caller_profile->dialplan))) { if ((dpstr = switch_core_session_strdup(session, caller_profile->dialplan))) {
expanded = switch_channel_expand_variables(session->channel, dpstr); expanded = switch_channel_expand_variables(session->channel, dpstr);
@ -79,7 +78,7 @@ static void switch_core_standard_on_routing(switch_core_session_t *session)
for (x = 0; x < argc; x++) { for (x = 0; x < argc; x++) {
char *dpname = dp[x]; char *dpname = dp[x];
char *dparg = NULL; char *dparg = NULL;
if (dpname) { if (dpname) {
if ((dparg = strchr(dpname, ':'))) { if ((dparg = strchr(dpname, ':'))) {
*dparg++ = '\0'; *dparg++ = '\0';
@ -90,7 +89,7 @@ static void switch_core_standard_on_routing(switch_core_session_t *session)
if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) { if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) {
continue; continue;
} }
count++; count++;
if ((extension = dialplan_interface->hunt_function(session, dparg, NULL)) != 0) { if ((extension = dialplan_interface->hunt_function(session, dparg, NULL)) != 0) {
@ -115,8 +114,8 @@ static void switch_core_standard_on_routing(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No Route, Aborting\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No Route, Aborting\n");
switch_channel_hangup(session->channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION); switch_channel_hangup(session->channel, SWITCH_CAUSE_NO_ROUTE_DESTINATION);
} }
end: end:
if (expanded && dpstr && expanded != dpstr) { if (expanded && dpstr && expanded != dpstr) {
free(expanded); free(expanded);
@ -129,7 +128,7 @@ static void switch_core_standard_on_execute(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard EXECUTE\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Standard EXECUTE\n");
top: top:
switch_channel_clear_flag(session->channel, CF_RESET); switch_channel_clear_flag(session->channel, CF_RESET);
if ((extension = switch_channel_get_caller_extension(session->channel)) == 0) { if ((extension = switch_channel_get_caller_extension(session->channel)) == 0) {
@ -141,12 +140,12 @@ static void switch_core_standard_on_execute(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Execute %s(%s)\n", switch_channel_get_name(session->channel), switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Execute %s(%s)\n", switch_channel_get_name(session->channel),
extension->current_application->application_name, switch_str_nil(extension->current_application->application_data)); extension->current_application->application_name, switch_str_nil(extension->current_application->application_data));
if (switch_core_session_execute_application(session, if (switch_core_session_execute_application(session,
extension->current_application->application_name, extension->current_application->application_name,
extension->current_application->application_data) != SWITCH_STATUS_SUCCESS) { extension->current_application->application_data) != SWITCH_STATUS_SUCCESS) {
return; return;
} }
if (switch_channel_test_flag(session->channel, CF_RESET)) { if (switch_channel_test_flag(session->channel, CF_RESET)) {
goto top; goto top;
} }
@ -249,7 +248,7 @@ static void handle_fatality(int sig)
void switch_core_state_machine_init(switch_memory_pool_t *pool) void switch_core_state_machine_init(switch_memory_pool_t *pool)
{ {
if (switch_test_flag((&runtime), SCF_CRASH_PROT)) { if (switch_test_flag((&runtime), SCF_CRASH_PROT)) {
sqlite3HashInit(&stack_table, SQLITE_HASH_BINARY, 0); sqlite3HashInit(&stack_table, SQLITE_HASH_BINARY, 0);
} }
@ -320,7 +319,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Thread has crashed for channel %s\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Thread has crashed for channel %s\n", switch_channel_get_name(session->channel));
switch_channel_hangup(session->channel, SWITCH_CAUSE_CRASH); switch_channel_hangup(session->channel, SWITCH_CAUSE_CRASH);
} else { } else {
sqlite3HashInsert(&stack_table, &thread_id, sizeof(thread_id), (void *)&env); sqlite3HashInsert(&stack_table, &thread_id, sizeof(thread_id), (void *) &env);
//apr_hash_set(stack_table, &thread_id, sizeof(thread_id), &env); //apr_hash_set(stack_table, &thread_id, sizeof(thread_id), &env);
} }
} }
@ -361,7 +360,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP || exception) { if (state != switch_channel_get_running_state(session->channel) || state == CS_HANGUP || exception) {
int index = 0; int index = 0;
int proceed = 1; int proceed = 1;
int do_extra_handlers = 1; int do_extra_handlers = 1;
switch_channel_set_running_state(session->channel, state); switch_channel_set_running_state(session->channel, state);
@ -372,7 +371,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
case CS_DONE: case CS_DONE:
goto done; goto done;
/* HANGUP INIT ROUTING and RESET are all short term so we signal lock during their callbacks */ /* HANGUP INIT ROUTING and RESET are all short term so we signal lock during their callbacks */
case CS_HANGUP: /* Deactivate and end the thread */ case CS_HANGUP: /* Deactivate and end the thread */
{ {
const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE); const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE);
const char *hook_var; const char *hook_var;
@ -387,7 +386,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
do_extra_handlers = 0; do_extra_handlers = 0;
} }
} else if (!switch_true(var)) { } else if (!switch_true(var)) {
do_extra_handlers = 0; do_extra_handlers = 0;
} }
} }
switch_core_session_signal_lock(session); switch_core_session_signal_lock(session);
@ -405,50 +404,51 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
} }
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
switch_api_execute(cmd, arg, NULL, &stream); switch_api_execute(cmd, arg, NULL, &stream);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hangup Command %s(%s):\n%s\n", cmd, arg, switch_str_nil((char *) stream.data)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hangup Command %s(%s):\n%s\n", cmd, arg,
switch_str_nil((char *) stream.data));
switch_safe_free(stream.data); switch_safe_free(stream.data);
} }
} }
goto done; goto done;
case CS_INIT: /* Basic setup tasks */ case CS_INIT: /* Basic setup tasks */
switch_core_session_signal_lock(session); switch_core_session_signal_lock(session);
STATE_MACRO(init, "INIT"); STATE_MACRO(init, "INIT");
switch_core_session_signal_unlock(session); switch_core_session_signal_unlock(session);
break; break;
case CS_ROUTING: /* Look for a dialplan and find something to do */ case CS_ROUTING: /* Look for a dialplan and find something to do */
switch_core_session_signal_lock(session); switch_core_session_signal_lock(session);
STATE_MACRO(routing, "ROUTING"); STATE_MACRO(routing, "ROUTING");
switch_core_session_signal_unlock(session); switch_core_session_signal_unlock(session);
break; break;
case CS_RESET: /* Reset */ case CS_RESET: /* Reset */
switch_core_session_signal_lock(session); switch_core_session_signal_lock(session);
STATE_MACRO(reset, "RESET"); STATE_MACRO(reset, "RESET");
switch_core_session_signal_unlock(session); switch_core_session_signal_unlock(session);
break; break;
/* These other states are intended for prolonged durations so we do not signal lock for them */ /* These other states are intended for prolonged durations so we do not signal lock for them */
case CS_EXECUTE: /* Execute an Operation */ case CS_EXECUTE: /* Execute an Operation */
STATE_MACRO(execute, "EXECUTE"); STATE_MACRO(execute, "EXECUTE");
break; break;
case CS_EXCHANGE_MEDIA: /* loop all data back to source */ case CS_EXCHANGE_MEDIA: /* loop all data back to source */
STATE_MACRO(exchange_media, "EXCHANGE_MEDIA"); STATE_MACRO(exchange_media, "EXCHANGE_MEDIA");
break; break;
case CS_SOFT_EXECUTE: /* send/recieve data to/from another channel */ case CS_SOFT_EXECUTE: /* send/recieve data to/from another channel */
STATE_MACRO(soft_execute, "SOFT_EXECUTE"); STATE_MACRO(soft_execute, "SOFT_EXECUTE");
break; break;
case CS_PARK: /* wait in limbo */ case CS_PARK: /* wait in limbo */
STATE_MACRO(park, "PARK"); STATE_MACRO(park, "PARK");
break; break;
case CS_CONSUME_MEDIA: /* wait in limbo */ case CS_CONSUME_MEDIA: /* wait in limbo */
STATE_MACRO(consume_media, "CONSUME_MEDIA"); STATE_MACRO(consume_media, "CONSUME_MEDIA");
break; break;
case CS_HIBERNATE: /* sleep */ case CS_HIBERNATE: /* sleep */
STATE_MACRO(hibernate, "HIBERNATE"); STATE_MACRO(hibernate, "HIBERNATE");
break; break;
case CS_NONE: case CS_NONE:
abort(); abort();
break; break;
} }
if (midstate == CS_DONE) { if (midstate == CS_DONE) {
break; break;
} }
@ -456,7 +456,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
} }
endstate = switch_channel_get_state(session->channel); endstate = switch_channel_get_state(session->channel);
if (endstate == switch_channel_get_running_state(session->channel)) { if (endstate == switch_channel_get_running_state(session->channel)) {
if (endstate == CS_NEW) { if (endstate == CS_NEW) {
switch_yield(1000); switch_yield(1000);

View File

@ -35,7 +35,8 @@
#include <switch.h> #include <switch.h>
#include "private/switch_core_pvt.h" #include "private/switch_core_pvt.h"
SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples, switch_memory_pool_t *pool) SWITCH_DECLARE(switch_status_t) switch_core_timer_init(switch_timer_t *timer, const char *timer_name, int interval, int samples,
switch_memory_pool_t *pool)
{ {
switch_timer_interface_t *timer_interface; switch_timer_interface_t *timer_interface;
switch_status_t status; switch_status_t status;

View File

@ -59,13 +59,13 @@ static switch_queue_t *EVENT_RECYCLE_QUEUE = NULL;
static switch_queue_t *EVENT_HEADER_RECYCLE_QUEUE = NULL; static switch_queue_t *EVENT_HEADER_RECYCLE_QUEUE = NULL;
static void launch_dispatch_threads(int max, int len, switch_memory_pool_t *pool); static void launch_dispatch_threads(int max, int len, switch_memory_pool_t *pool);
static char *my_dup (const char *s) static char *my_dup(const char *s)
{ {
size_t len = strlen (s) + 1; size_t len = strlen(s) + 1;
void *new = malloc (len); void *new = malloc(len);
switch_assert(new); switch_assert(new);
return (char *) memcpy (new, s, len); return (char *) memcpy(new, s, len);
} }
#ifndef ALLOC #ifndef ALLOC
@ -172,7 +172,7 @@ static int switch_events_match(switch_event_t *event, switch_event_node_t *node)
return match; return match;
} }
static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *thread, void *obj)
{ {
switch_queue_t *queue = (switch_queue_t *) obj; switch_queue_t *queue = (switch_queue_t *) obj;
int my_id = 0; int my_id = 0;
@ -186,7 +186,7 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t * t
} }
} }
for(;;) { for (;;) {
void *pop = NULL; void *pop = NULL;
switch_event_t *event = NULL; switch_event_t *event = NULL;
@ -197,7 +197,7 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t * t
if (!pop) { if (!pop) {
break; break;
} }
event = (switch_event_t *) pop; event = (switch_event_t *) pop;
switch_event_deliver(&event); switch_event_deliver(&event);
} }
@ -206,14 +206,14 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t * t
switch_mutex_lock(EVENT_QUEUE_MUTEX); switch_mutex_lock(EVENT_QUEUE_MUTEX);
THREAD_COUNT--; THREAD_COUNT--;
switch_mutex_unlock(EVENT_QUEUE_MUTEX); switch_mutex_unlock(EVENT_QUEUE_MUTEX);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Dispatch Thread %d Ended.\n", my_id); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Dispatch Thread %d Ended.\n", my_id);
return NULL; return NULL;
} }
static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t *thread, void *obj)
{ {
switch_queue_t *queue = (switch_queue_t *) obj; switch_queue_t *queue = (switch_queue_t *) obj;
int index = 0; int index = 0;
@ -228,11 +228,11 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t * thread, vo
break; break;
} }
} }
for(;;) { for (;;) {
void *pop = NULL; void *pop = NULL;
switch_event_t *event = NULL; switch_event_t *event = NULL;
if (switch_queue_pop(queue, &pop) != SWITCH_STATUS_SUCCESS) { if (switch_queue_pop(queue, &pop) != SWITCH_STATUS_SUCCESS) {
break; break;
} }
@ -243,18 +243,18 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t * thread, vo
event = (switch_event_t *) pop; event = (switch_event_t *) pop;
while(event) { while (event) {
for (index = 0; index < SOFT_MAX_DISPATCH; index++) { for (index = 0; index < SOFT_MAX_DISPATCH; index++) {
if (switch_queue_trypush(EVENT_DISPATCH_QUEUE[index], event) == SWITCH_STATUS_SUCCESS) { if (switch_queue_trypush(EVENT_DISPATCH_QUEUE[index], event) == SWITCH_STATUS_SUCCESS) {
event = NULL; event = NULL;
break; break;
} }
} }
if (event) { if (event) {
if (SOFT_MAX_DISPATCH+1 < MAX_DISPATCH) { if (SOFT_MAX_DISPATCH + 1 < MAX_DISPATCH) {
switch_mutex_lock(EVENT_QUEUE_MUTEX); switch_mutex_lock(EVENT_QUEUE_MUTEX);
launch_dispatch_threads(SOFT_MAX_DISPATCH+1, DISPATCH_QUEUE_LEN, RUNTIME_POOL); launch_dispatch_threads(SOFT_MAX_DISPATCH + 1, DISPATCH_QUEUE_LEN, RUNTIME_POOL);
switch_mutex_unlock(EVENT_QUEUE_MUTEX); switch_mutex_unlock(EVENT_QUEUE_MUTEX);
} }
} }
@ -264,10 +264,10 @@ static void *SWITCH_THREAD_FUNC switch_event_thread(switch_thread_t * thread, vo
switch_mutex_lock(EVENT_QUEUE_MUTEX); switch_mutex_lock(EVENT_QUEUE_MUTEX);
THREAD_COUNT--; THREAD_COUNT--;
switch_mutex_unlock(EVENT_QUEUE_MUTEX); switch_mutex_unlock(EVENT_QUEUE_MUTEX);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread %d Ended.\n", my_id); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread %d Ended.\n", my_id);
return NULL; return NULL;
} }
@ -352,7 +352,7 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event(s) %d bytes\n", size, (int) sizeof(switch_event_t) * size); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event(s) %d bytes\n", size, (int) sizeof(switch_event_t) * size);
size = switch_queue_size(EVENT_HEADER_RECYCLE_QUEUE); size = switch_queue_size(EVENT_HEADER_RECYCLE_QUEUE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event header(s) %d bytes\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled event header(s) %d bytes\n",
size, (int) sizeof(switch_event_header_t) * size); size, (int) sizeof(switch_event_header_t) * size);
while (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
@ -371,16 +371,16 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
SYSTEM_RUNNING = 0; SYSTEM_RUNNING = 0;
switch_mutex_unlock(EVENT_QUEUE_MUTEX); switch_mutex_unlock(EVENT_QUEUE_MUTEX);
for(x = 0; x < 3; x++) { for (x = 0; x < 3; x++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping event queue %d\n", x); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping event queue %d\n", x);
switch_queue_push(EVENT_QUEUE[x], NULL); switch_queue_push(EVENT_QUEUE[x], NULL);
} }
for(x = 0; x < SOFT_MAX_DISPATCH; x++) { for (x = 0; x < SOFT_MAX_DISPATCH; x++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch queue %d\n", x); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch queue %d\n", x);
switch_queue_push(EVENT_DISPATCH_QUEUE[x], NULL); switch_queue_push(EVENT_DISPATCH_QUEUE[x], NULL);
} }
while (x < 10000 && THREAD_COUNT) { while (x < 10000 && THREAD_COUNT) {
switch_yield(1000); switch_yield(1000);
if (THREAD_COUNT == last) { if (THREAD_COUNT == last) {
@ -388,7 +388,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
} }
last = THREAD_COUNT; last = THREAD_COUNT;
} }
switch_core_hash_destroy(&CUSTOM_HASH); switch_core_hash_destroy(&CUSTOM_HASH);
switch_core_memory_reclaim_events(); switch_core_memory_reclaim_events();
@ -399,17 +399,17 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
static void launch_dispatch_threads(int max, int len, switch_memory_pool_t *pool) static void launch_dispatch_threads(int max, int len, switch_memory_pool_t *pool)
{ {
switch_thread_t *thread; switch_thread_t *thread;
switch_threadattr_t *thd_attr; switch_threadattr_t *thd_attr;
int index = 0; int index = 0;
if (max > MAX_DISPATCH) { if (max > MAX_DISPATCH) {
return; return;
} }
if (max < SOFT_MAX_DISPATCH) { if (max < SOFT_MAX_DISPATCH) {
return; return;
} }
for (index = SOFT_MAX_DISPATCH; index < max && index < MAX_DISPATCH; index++) { for (index = SOFT_MAX_DISPATCH; index < max && index < MAX_DISPATCH; index++) {
if (EVENT_DISPATCH_QUEUE[index]) { if (EVENT_DISPATCH_QUEUE[index]) {
continue; continue;
@ -445,7 +445,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
switch_queue_create(&EVENT_QUEUE[2], POOL_COUNT_MAX + 10, THRUNTIME_POOL); switch_queue_create(&EVENT_QUEUE[2], POOL_COUNT_MAX + 10, THRUNTIME_POOL);
switch_queue_create(&EVENT_RECYCLE_QUEUE, 250000, THRUNTIME_POOL); switch_queue_create(&EVENT_RECYCLE_QUEUE, 250000, THRUNTIME_POOL);
switch_queue_create(&EVENT_HEADER_RECYCLE_QUEUE, 250000, THRUNTIME_POOL); switch_queue_create(&EVENT_HEADER_RECYCLE_QUEUE, 250000, THRUNTIME_POOL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Activate Eventing Engine.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Activate Eventing Engine.\n");
switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL); switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
@ -459,7 +459,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[0], RUNTIME_POOL); switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[0], RUNTIME_POOL);
switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[1], RUNTIME_POOL); switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[1], RUNTIME_POOL);
switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[2], RUNTIME_POOL); switch_thread_create(&thread, thd_attr, switch_event_thread, EVENT_QUEUE[2], RUNTIME_POOL);
while (!THREAD_COUNT) { while (!THREAD_COUNT) {
switch_yield(1000); switch_yield(1000);
} }
@ -475,11 +475,11 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
SWITCH_DECLARE(switch_status_t) switch_event_create_subclass(switch_event_t **event, switch_event_types_t event_id, const char *subclass_name) SWITCH_DECLARE(switch_status_t) switch_event_create_subclass(switch_event_t **event, switch_event_types_t event_id, const char *subclass_name)
{ {
void *pop; void *pop;
if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) { if (event_id != SWITCH_EVENT_CUSTOM && subclass_name) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
if (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) { if (switch_queue_trypop(EVENT_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
*event = (switch_event_t *) pop; *event = (switch_event_t *) pop;
} else { } else {
@ -493,7 +493,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_subclass(switch_event_t **ev
if (subclass_name) { if (subclass_name) {
if (!((*event)->subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) { if (!((*event)->subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
switch_event_reserve_subclass((char *)subclass_name); switch_event_reserve_subclass((char *) subclass_name);
(*event)->subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name); (*event)->subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name);
} }
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", subclass_name); switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", subclass_name);
@ -513,7 +513,8 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, char *head
{ {
switch_event_header_t *hp; switch_event_header_t *hp;
switch_assert(event); switch_assert(event);
if (!header_name) return NULL; if (!header_name)
return NULL;
for (hp = event->headers; hp; hp = hp->next) { for (hp = event->headers; hp; hp = hp->next) {
if (!strcasecmp(hp->name, header_name)) { if (!strcasecmp(hp->name, header_name)) {
@ -556,7 +557,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_del_header(switch_event_t *event, c
} }
lp = hp; lp = hp;
} }
return status; return status;
} }
@ -685,7 +686,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_
for (hp = todup->headers; hp; hp = hp->next) { for (hp = todup->headers; hp; hp = hp->next) {
void *pop; void *pop;
if (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) { if (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
header = (switch_event_header_t *) pop; header = (switch_event_header_t *) pop;
} else { } else {
@ -844,7 +845,7 @@ static switch_xml_t add_xml_header(switch_xml_t xml, char *name, char *value, in
return header; 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; switch_event_header_t *hp;
char *data = NULL, *body = NULL; char *data = NULL, *body = NULL;
@ -863,7 +864,8 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
ret = vasprintf(&data, fmt, ap); ret = vasprintf(&data, fmt, ap);
#else #else
data = (char *) malloc(2048); data = (char *) malloc(2048);
if (!data) return NULL; if (!data)
return NULL;
ret = vsnprintf(data, 2048, fmt, ap); ret = vsnprintf(data, 2048, fmt, ap);
#endif #endif
va_end(ap); va_end(ap);
@ -935,7 +937,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(const char *file, con
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", date); switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-Local", date);
switch_rfc822_date(date, ts); switch_rfc822_date(date, ts);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", date); switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Date-GMT", date);
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-timestamp", "%"SWITCH_UINT64_T_FMT, (uint64_t)ts); switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Date-timestamp", "%" SWITCH_UINT64_T_FMT, (uint64_t) ts);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Calling-File", switch_cut_path(file)); switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Calling-File", switch_cut_path(file));
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", func); switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Function", func);
switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line); switch_event_add_header(*event, SWITCH_STACK_BOTTOM, "Event-Calling-Line-Number", "%d", line);
@ -948,7 +950,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(const char *file, con
if (user_data) { if (user_data) {
(*event)->event_user_data = user_data; (*event)->event_user_data = user_data;
} }
switch_queue_push(EVENT_QUEUE[(*event)->priority], *event); switch_queue_push(EVENT_QUEUE[(*event)->priority], *event);
*event = NULL; *event = NULL;
@ -998,15 +1000,15 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind(const char *id, switch_event_t
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(char *file, char *func, int line, SWITCH_DECLARE(switch_status_t) switch_event_create_pres_in_detailed(char *file, char *func, int line,
const char *proto, const char *login, const char *proto, const char *login,
const char *from, const char *from_domain, const char *from, const char *from_domain,
const char *status, const char *event_type, const char *status, const char *event_type,
const char *alt_event_type, int event_count, const char *alt_event_type, int event_count,
const char *unique_id, const char *channel_state, const char *unique_id, const char *channel_state,
const char *answer_state, const char *call_direction) const char *answer_state, const char *call_direction)
{ {
switch_event_t *pres_event; switch_event_t *pres_event;
if (switch_event_create_subclass(&pres_event, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY) == SWITCH_STATUS_SUCCESS) { if (switch_event_create_subclass(&pres_event, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(pres_event, SWITCH_STACK_TOP, "proto", proto); switch_event_add_header_string(pres_event, SWITCH_STACK_TOP, "proto", proto);
@ -1047,22 +1049,22 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
int nv = 0; int nv = 0;
q = in; q = in;
while(q && *q) { while (q && *q) {
if (!(p = strchr(q, '$'))) { if (!(p = strchr(q, '$'))) {
break; break;
} }
if (*(p+1) != '{') { if (*(p + 1) != '{') {
q = p + 1; q = p + 1;
continue; continue;
} }
nv = 1; nv = 1;
break; break;
} }
if (!nv) { if (!nv) {
return (char *)in; return (char *) in;
} }
nv = 0; nv = 0;
@ -1074,7 +1076,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
c = data; c = data;
for (p = indup; p && *p; p++) { for (p = indup; p && *p; p++) {
vtype = 0; vtype = 0;
if (*p == '\\') { if (*p == '\\') {
if (*(p + 1) == '$') { if (*(p + 1) == '$') {
nv = 1; nv = 1;
@ -1087,8 +1089,8 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
} }
if (*p == '$' && !nv) { if (*p == '$' && !nv) {
if (*(p+1)) { if (*(p + 1)) {
if (*(p+1) == '{') { if (*(p + 1) == '{') {
vtype = 1; vtype = 1;
} else { } else {
nv = 1; nv = 1;
@ -1132,20 +1134,20 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
br--; br--;
} }
} }
e++; e++;
} }
p = e; p = e;
if ((vval = strchr(vname, '('))) { if ((vval = strchr(vname, '('))) {
e = vval - 1; e = vval - 1;
*vval++ = '\0'; *vval++ = '\0';
while(*e == ' ') { while (*e == ' ') {
*e-- = '\0'; *e-- = '\0';
} }
e = vval; e = vval;
br = 1; br = 1;
while(e && *e) { while (e && *e) {
if (*e == '(') { if (*e == '(') {
br++; br++;
} else if (br > 1 && *e == ')') { } else if (br > 1 && *e == ')') {
@ -1166,7 +1168,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
int ooffset = 0; int ooffset = 0;
char *ptr; char *ptr;
if ((expanded = switch_event_expand_headers(event, (char *)vname)) == vname) { if ((expanded = switch_event_expand_headers(event, (char *) vname)) == vname) {
expanded = NULL; expanded = NULL;
} else { } else {
vname = expanded; vname = expanded;
@ -1179,25 +1181,25 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
ooffset = atoi(ptr); ooffset = atoi(ptr);
} }
} }
if (!(sub_val = switch_event_get_header(event, vname))) { if (!(sub_val = switch_event_get_header(event, vname))) {
sub_val = switch_core_get_variable(vname); sub_val = switch_core_get_variable(vname);
} }
if (offset || ooffset) { if (offset || ooffset) {
cloned_sub_val = strdup(sub_val); cloned_sub_val = strdup(sub_val);
switch_assert(cloned_sub_val); switch_assert(cloned_sub_val);
sub_val = cloned_sub_val; sub_val = cloned_sub_val;
} }
if (offset >= 0) { if (offset >= 0) {
sub_val += offset; sub_val += offset;
} else if ((size_t)abs(offset) <= strlen(sub_val)) { } else if ((size_t) abs(offset) <= strlen(sub_val)) {
sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset); sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset);
} }
if (ooffset > 0 && (size_t)ooffset < strlen(sub_val)) { if (ooffset > 0 && (size_t) ooffset < strlen(sub_val)) {
if ((ptr = (char *)sub_val + ooffset)) { if ((ptr = (char *) sub_val + ooffset)) {
*ptr = '\0'; *ptr = '\0';
} }
} }
@ -1212,7 +1214,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
if (stream.data) { if (stream.data) {
char *expanded_vname = NULL; char *expanded_vname = NULL;
if ((expanded_vname = switch_event_expand_headers(event, (char *)vname)) == vname) { if ((expanded_vname = switch_event_expand_headers(event, (char *) vname)) == vname) {
expanded_vname = NULL; expanded_vname = NULL;
} else { } else {
vname = expanded_vname; vname = expanded_vname;
@ -1230,15 +1232,15 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
} else { } else {
free(stream.data); free(stream.data);
} }
switch_safe_free(expanded); switch_safe_free(expanded);
switch_safe_free(expanded_vname); switch_safe_free(expanded_vname);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
free(data); free(data);
free(indup); free(indup);
return (char *)in; return (char *) in;
} }
} }
if ((nlen = sub_val ? strlen(sub_val) : 0)) { if ((nlen = sub_val ? strlen(sub_val) : 0)) {
@ -1277,20 +1279,21 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const
} }
} }
free(indup); free(indup);
return data; return data;
} }
SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t* vars_map) SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t *vars_map)
{ {
switch_stream_handle_t stream = { 0 }; switch_stream_handle_t stream = { 0 };
switch_size_t encode_len = 1024, new_len = 0; switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL; char *encode_buf = NULL;
const char *prof[12] = { 0 }, *prof_names[12] = {0}; const char *prof[12] = { 0 }, *prof_names[12] = {
0};
char *e = NULL; char *e = NULL;
switch_event_header_t *hi; switch_event_header_t *hi;
uint32_t x = 0; uint32_t x = 0;
void* data = NULL; void *data = NULL;
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
@ -1325,24 +1328,23 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co
if (event) { if (event) {
if ((hi = event->headers)) { if ((hi = event->headers)) {
for (; hi; hi = hi->next) { for (; hi; hi = hi->next) {
char *var = hi->name; char *var = hi->name;
char *val = hi->value; char *val = hi->value;
if (vars_map != NULL) if (vars_map != NULL) {
{ if ((data = switch_core_hash_find(vars_map, var)) == NULL || strcasecmp(((char *) data), "enabled"))
if ((data = switch_core_hash_find(vars_map,var)) == NULL || strcasecmp(((char*)data),"enabled")) continue;
continue;
} }
new_len = (strlen((char *) var) * 3) + 1; new_len = (strlen((char *) var) * 3) + 1;
if (encode_len < new_len) { if (encode_len < new_len) {
char *tmp; char *tmp;
encode_len = new_len; encode_len = new_len;
tmp = realloc(encode_buf, encode_len); tmp = realloc(encode_buf, encode_len);
switch_assert(tmp); switch_assert(tmp);
encode_buf = tmp; encode_buf = tmp;
@ -1354,7 +1356,7 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co
} }
} }
} }
e = (char *) stream.data + (strlen((char *) stream.data) - 1); e = (char *) stream.data + (strlen((char *) stream.data) - 1);
if (e && *e == '&') { if (e && *e == '&') {

View File

@ -90,17 +90,17 @@ static void *SWITCH_THREAD_FUNC unicast_thread_run(switch_thread_t *thread, void
} }
channel = switch_core_session_get_channel(conninfo->session); channel = switch_core_session_get_channel(conninfo->session);
while(switch_test_flag(conninfo, SUF_READY) && switch_test_flag(conninfo, SUF_THREAD_RUNNING)) { while (switch_test_flag(conninfo, SUF_READY) && switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
len = conninfo->write_frame.buflen; len = conninfo->write_frame.buflen;
if (switch_socket_recv(conninfo->socket, conninfo->write_frame.data, &len) != SWITCH_STATUS_SUCCESS || len == 0) { if (switch_socket_recv(conninfo->socket, conninfo->write_frame.data, &len) != SWITCH_STATUS_SUCCESS || len == 0) {
break; break;
} }
conninfo->write_frame.datalen = (uint32_t)len; conninfo->write_frame.datalen = (uint32_t) len;
conninfo->write_frame.samples = conninfo->write_frame.datalen / 2; conninfo->write_frame.samples = conninfo->write_frame.datalen / 2;
switch_core_session_write_frame(conninfo->session, &conninfo->write_frame, SWITCH_IO_FLAG_NONE, conninfo->stream_id); switch_core_session_write_frame(conninfo->session, &conninfo->write_frame, SWITCH_IO_FLAG_NONE, conninfo->stream_id);
} }
switch_clear_flag_locked(conninfo, SUF_READY); switch_clear_flag_locked(conninfo, SUF_READY);
switch_clear_flag_locked(conninfo, SUF_THREAD_RUNNING); switch_clear_flag_locked(conninfo, SUF_THREAD_RUNNING);
@ -126,14 +126,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_sessio
int sanity = 0; int sanity = 0;
if (!switch_channel_test_flag(channel, CF_UNICAST)) { if (!switch_channel_test_flag(channel, CF_UNICAST)) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if ((conninfo = switch_channel_get_private(channel, "unicast"))) { if ((conninfo = switch_channel_get_private(channel, "unicast"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutting down unicast connection\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutting down unicast connection\n");
switch_clear_flag_locked(conninfo, SUF_READY); switch_clear_flag_locked(conninfo, SUF_READY);
switch_socket_shutdown(conninfo->socket, SWITCH_SHUTDOWN_READWRITE); switch_socket_shutdown(conninfo->socket, SWITCH_SHUTDOWN_READWRITE);
while(switch_test_flag(conninfo, SUF_THREAD_RUNNING)) { while (switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
switch_yield(10000); switch_yield(10000);
if (++sanity >= 10000) { if (++sanity >= 10000) {
break; break;
@ -148,13 +148,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_sessio
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session,
char *local_ip, char *local_ip,
switch_port_t local_port, switch_port_t local_port,
char *remote_ip, char *remote_ip, switch_port_t remote_port, char *transport, char *flags)
switch_port_t remote_port,
char *transport,
char *flags)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_unicast_conninfo_t *conninfo = switch_core_session_alloc(session, sizeof(*conninfo)); switch_unicast_conninfo_t *conninfo = switch_core_session_alloc(session, sizeof(*conninfo));
@ -168,7 +165,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_
conninfo->remote_ip = switch_core_session_strdup(session, remote_ip); conninfo->remote_ip = switch_core_session_strdup(session, remote_ip);
conninfo->remote_port = remote_port; conninfo->remote_port = remote_port;
conninfo->session = session; conninfo->session = session;
if (!strcasecmp(transport, "udp")) { if (!strcasecmp(transport, "udp")) {
conninfo->type = AF_INET; conninfo->type = AF_INET;
conninfo->transport = SOCK_DGRAM; conninfo->transport = SOCK_DGRAM;
@ -187,9 +184,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_
} }
switch_mutex_init(&conninfo->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&conninfo->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
read_codec = switch_core_session_get_read_codec(session); read_codec = switch_core_session_get_read_codec(session);
if (!switch_test_flag(conninfo, SUF_NATIVE)) { if (!switch_test_flag(conninfo, SUF_NATIVE)) {
if (switch_core_codec_init(&conninfo->read_codec, if (switch_core_codec_init(&conninfo->read_codec,
"L16", "L16",
@ -216,17 +213,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_
conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port); conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
if (switch_sockaddr_info_get(&conninfo->local_addr, if (switch_sockaddr_info_get(&conninfo->local_addr,
conninfo->local_ip, SWITCH_UNSPEC, conninfo->local_port, 0, conninfo->local_ip, SWITCH_UNSPEC, conninfo->local_port, 0,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
goto fail; goto fail;
} }
if (switch_sockaddr_info_get(&conninfo->remote_addr, if (switch_sockaddr_info_get(&conninfo->remote_addr,
conninfo->remote_ip, SWITCH_UNSPEC, conninfo->remote_port, 0, conninfo->remote_ip, SWITCH_UNSPEC, conninfo->remote_port, 0,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
goto fail; goto fail;
} }
if (switch_socket_create(&conninfo->socket, AF_INET, SOCK_DGRAM, 0, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { if (switch_socket_create(&conninfo->socket, AF_INET, SOCK_DGRAM, 0, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
if (switch_socket_bind(conninfo->socket, conninfo->local_addr) != SWITCH_STATUS_SUCCESS) { if (switch_socket_bind(conninfo->socket, conninfo->local_addr) != SWITCH_STATUS_SUCCESS) {
goto fail; goto fail;
@ -242,11 +239,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_
switch_set_flag_locked(conninfo, SUF_READY); switch_set_flag_locked(conninfo, SUF_READY);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
fail: fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating unicast connection %s:%d->%s:%d\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating unicast connection %s:%d->%s:%d\n",
conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port); conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event) SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event)
@ -280,8 +277,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
switch_frame_t *read_frame; switch_frame_t *read_frame;
int frame_count = atoi(lead_frames); int frame_count = atoi(lead_frames);
int max_frames = frame_count * 2; int max_frames = frame_count * 2;
while(frame_count > 0 && --max_frames > 0) { while (frame_count > 0 && --max_frames > 0) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
goto done; goto done;
@ -310,7 +307,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
int x; int x;
const char *b_uuid = NULL; const char *b_uuid = NULL;
switch_core_session_t *b_session = NULL; switch_core_session_t *b_session = NULL;
switch_channel_clear_flag(channel, CF_STOP_BROADCAST); switch_channel_clear_flag(channel, CF_STOP_BROADCAST);
switch_channel_set_flag(channel, CF_BROADCAST); switch_channel_set_flag(channel, CF_BROADCAST);
if (hold_bleg && switch_true(hold_bleg)) { if (hold_bleg && switch_true(hold_bleg)) {
@ -336,8 +333,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
} }
for (x = 0; x < loops || loops < 0; x++) { for (x = 0; x < loops || loops < 0; x++) {
switch_time_t b4, aftr; switch_time_t b4, aftr;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Command Execute %s(%s)\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Command Execute %s(%s)\n",
switch_channel_get_name(channel), app_name, app_arg); switch_channel_get_name(channel), app_name, app_arg);
b4 = switch_timestamp_now(); b4 = switch_timestamp_now();
switch_core_session_exec(session, application_interface, app_arg); switch_core_session_exec(session, application_interface, app_arg);
@ -356,7 +353,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
} }
} }
switch_channel_clear_flag(channel, CF_BROADCAST); switch_channel_clear_flag(channel, CF_BROADCAST);
} }
} }
} }
@ -384,7 +381,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
transport = "udp"; transport = "udp";
} }
switch_ivr_activate_unicast(session, local_ip, (switch_port_t)atoi(local_port), remote_ip, (switch_port_t)atoi(remote_port), transport, flags); switch_ivr_activate_unicast(session, local_ip, (switch_port_t) atoi(local_port), remote_ip, (switch_port_t) atoi(remote_port), transport, flags);
} else if (cmd_hash == CMD_HANGUP) { } else if (cmd_hash == CMD_HANGUP) {
char *cause_name = switch_event_get_header(event, "hangup-cause"); char *cause_name = switch_event_get_header(event, "hangup-cause");
@ -402,7 +399,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *se
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
done: done:
switch_channel_clear_flag(channel, CF_EVENT_PARSE); switch_channel_clear_flag(channel, CF_EVENT_PARSE);
switch_channel_clear_flag(channel, CF_EVENT_LOCK); switch_channel_clear_flag(channel, CF_EVENT_LOCK);
@ -473,18 +470,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
} }
if (switch_channel_test_flag(channel, CF_UNICAST)) { if (switch_channel_test_flag(channel, CF_UNICAST)) {
if (!conninfo) { if (!conninfo) {
if (!(conninfo = switch_channel_get_private(channel, "unicast"))) { if (!(conninfo = switch_channel_get_private(channel, "unicast"))) {
switch_channel_clear_flag(channel, CF_UNICAST); switch_channel_clear_flag(channel, CF_UNICAST);
} }
if (conninfo) { if (conninfo) {
unicast_thread_launch(conninfo); unicast_thread_launch(conninfo);
} }
} }
if (conninfo) { if (conninfo) {
switch_size_t len = 0; switch_size_t len = 0;
uint32_t flags = 0; uint32_t flags = 0;
@ -504,13 +501,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
if (switch_test_flag(conninfo, SUF_NATIVE)) { if (switch_test_flag(conninfo, SUF_NATIVE)) {
tstatus = SWITCH_STATUS_NOOP; tstatus = SWITCH_STATUS_NOOP;
} else { } else {
tstatus = switch_core_codec_decode( tstatus = switch_core_codec_decode(read_codec,
read_codec, &conninfo->read_codec,
&conninfo->read_codec, read_frame->data,
read_frame->data, read_frame->datalen,
read_frame->datalen, read_codec->implementation->actual_samples_per_second, decoded, &dlen, &rate, &flags);
read_codec->implementation->actual_samples_per_second,
decoded, &dlen, &rate, &flags);
} }
switch (tstatus) { switch (tstatus) {
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
@ -533,19 +528,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
if (tstatus == SWITCH_STATUS_SUCCESS) { if (tstatus == SWITCH_STATUS_SUCCESS) {
len = sendlen; len = sendlen;
if (switch_socket_sendto(conninfo->socket, conninfo->remote_addr, 0, (void *)sendbuf, &len) != SWITCH_STATUS_SUCCESS) { if (switch_socket_sendto(conninfo->socket, conninfo->remote_addr, 0, (void *) sendbuf, &len) != SWITCH_STATUS_SUCCESS) {
switch_ivr_deactivate_unicast(session); switch_ivr_deactivate_unicast(session);
} }
} }
} }
} }
if (switch_core_session_private_event_count(session)) { if (switch_core_session_private_event_count(session)) {
switch_ivr_parse_all_events(session); switch_ivr_parse_all_events(session);
} }
if (switch_channel_has_dtmf(channel)) { if (switch_channel_has_dtmf(channel)) {
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
if (args && args->input_callback) { if (args && args->input_callback) {
if ((status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) { if ((status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen)) != SWITCH_STATUS_SUCCESS) {
@ -600,7 +595,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
while (switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
switch_frame_t *read_frame = NULL; switch_frame_t *read_frame = NULL;
switch_event_t *event; switch_event_t *event;
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
if (switch_channel_test_flag(channel, CF_BREAK)) { if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK); switch_channel_clear_flag(channel, CF_BREAK);
@ -616,12 +611,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
} }
if (switch_core_session_private_event_count(session)) { if (switch_core_session_private_event_count(session)) {
switch_ivr_parse_all_events(session); switch_ivr_parse_all_events(session);
} }
if (switch_channel_has_dtmf(channel)) { if (switch_channel_has_dtmf(channel)) {
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
status = args->input_callback(session, (void *)&dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
} }
if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) { if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) {
@ -656,11 +651,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
char *buf, char *buf,
switch_size_t buflen, switch_size_t buflen,
switch_size_t maxdigits, switch_size_t maxdigits,
const char *terminators, char *terminator, const char *terminators, char *terminator,
uint32_t first_timeout, uint32_t first_timeout, uint32_t digit_timeout, uint32_t abs_timeout)
uint32_t digit_timeout,
uint32_t abs_timeout)
{ {
switch_size_t i = 0, x = strlen(buf); switch_size_t i = 0, x = strlen(buf);
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
@ -693,7 +686,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
} else if (first_timeout) { } else if (first_timeout) {
digit_timeout = eff_timeout = first_timeout; digit_timeout = eff_timeout = first_timeout;
} }
if (eff_timeout) { if (eff_timeout) {
digit_started = switch_timestamp_now(); digit_started = switch_timestamp_now();
@ -701,7 +694,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
while (switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
switch_frame_t *read_frame; switch_frame_t *read_frame;
if (abs_timeout) { if (abs_timeout) {
abs_elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000); abs_elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000);
if (abs_elapsed >= abs_timeout) { if (abs_elapsed >= abs_timeout) {
@ -709,9 +702,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
} }
} }
if (switch_core_session_private_event_count(session)) { if (switch_core_session_private_event_count(session)) {
switch_ivr_parse_all_events(session); switch_ivr_parse_all_events(session);
} }
if (eff_timeout) { if (eff_timeout) {
@ -722,9 +715,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
} }
if (switch_channel_has_dtmf(channel)) { if (switch_channel_has_dtmf(channel)) {
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
switch_size_t y; switch_size_t y;
if (eff_timeout) { if (eff_timeout) {
eff_timeout = digit_timeout; eff_timeout = digit_timeout;
digit_started = switch_timestamp_now(); digit_started = switch_timestamp_now();
@ -739,8 +732,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
*terminator = dtmf.digit; *terminator = dtmf.digit;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
buf[x++] = dtmf.digit; buf[x++] = dtmf.digit;
buf[x] = '\0'; buf[x] = '\0';
if (x >= buflen || x >= maxdigits) { if (x >= buflen || x >= maxdigits) {
@ -777,13 +770,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session,
switch_channel_set_flag(channel, CF_SUSPEND); switch_channel_set_flag(channel, CF_SUSPEND);
switch_core_session_receive_message(session, &msg); switch_core_session_receive_message(session, &msg);
if (moh && (stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) { if (moh && (stream = switch_channel_get_variable(channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
if ((other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) { if ((other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
switch_ivr_broadcast(other_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP); switch_ivr_broadcast(other_uuid, stream, SMF_ECHO_ALEG | SMF_LOOP);
} }
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -848,7 +841,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_
switch_status_t status = SWITCH_STATUS_GENERR; switch_status_t status = SWITCH_STATUS_GENERR;
uint8_t swap = 0; uint8_t swap = 0;
switch_frame_t *read_frame = NULL; switch_frame_t *read_frame = NULL;
msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA; msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA;
msg.from = __FILE__; msg.from = __FILE__;
@ -865,7 +858,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_
switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000); switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000);
switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if ((flags & SMF_REBRIDGE) if ((flags & SMF_REBRIDGE)
&& (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE)) && (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE))
&& (other_session = switch_core_session_locate(other_uuid))) { && (other_session = switch_core_session_locate(other_uuid))) {
@ -881,7 +874,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_
switch_channel_clear_state_handler(channel, NULL); switch_channel_clear_state_handler(channel, NULL);
} }
} }
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
if (other_channel) { if (other_channel) {
@ -906,7 +899,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi
switch_core_session_message_t msg = { 0 }; switch_core_session_message_t msg = { 0 };
switch_status_t status = SWITCH_STATUS_GENERR; switch_status_t status = SWITCH_STATUS_GENERR;
uint8_t swap = 0; uint8_t swap = 0;
msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA; msg.message_id = SWITCH_MESSAGE_INDICATE_NOMEDIA;
msg.from = __FILE__; msg.from = __FILE__;
@ -920,7 +913,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi
if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_PROXY_MODE)) { if ((flags & SMF_FORCE) || !switch_channel_test_flag(channel, CF_PROXY_MODE)) {
switch_core_session_receive_message(session, &msg); switch_core_session_receive_message(session, &msg);
if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && if ((flags & SMF_REBRIDGE) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) &&
(other_session = switch_core_session_locate(other_uuid))) { (other_session = switch_core_session_locate(other_uuid))) {
other_channel = switch_core_session_get_channel(other_session); other_channel = switch_core_session_get_channel(other_session);
@ -947,7 +940,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_nomedia(const char *uuid, switch_medi
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, const char *extension, const char *dialplan, const char *context) SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_t *session, const char *extension, const char *dialplan,
const char *context)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_caller_profile_t *profile, *new_profile; switch_caller_profile_t *profile, *new_profile;
@ -960,7 +954,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
int forwardval = 70; int forwardval = 70;
if (!switch_strlen_zero(forwardvar)) { if (!switch_strlen_zero(forwardvar)) {
forwardval = atoi(forwardvar) - 1; forwardval = atoi(forwardvar) - 1;
} }
if (forwardval <= 0) { if (forwardval <= 0) {
switch_channel_hangup(channel, SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR); switch_channel_hangup(channel, SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR);
@ -981,7 +975,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
if (switch_strlen_zero(dialplan)) { if (switch_strlen_zero(dialplan)) {
dialplan = profile->dialplan; dialplan = profile->dialplan;
} }
if (switch_strlen_zero(context)) { if (switch_strlen_zero(context)) {
context = profile->context; context = profile->context;
} }
@ -989,7 +983,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
if (switch_strlen_zero(dialplan)) { if (switch_strlen_zero(dialplan)) {
dialplan = "XML"; dialplan = "XML";
} }
if (switch_strlen_zero(context)) { if (switch_strlen_zero(context)) {
context = "default"; context = "default";
} }
@ -997,7 +991,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
if (switch_strlen_zero(extension)) { if (switch_strlen_zero(extension)) {
extension = "service"; extension = "service";
} }
new_profile = switch_caller_profile_clone(session, profile); new_profile = switch_caller_profile_clone(session, profile);
new_profile->dialplan = switch_core_strdup(new_profile->pool, dialplan); new_profile->dialplan = switch_core_strdup(new_profile->pool, dialplan);
@ -1015,7 +1009,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
if (!uuid) { if (!uuid) {
uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE); uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE);
} }
if (uuid && (other_session = switch_core_session_locate(uuid))) { if (uuid && (other_session = switch_core_session_locate(uuid))) {
other_channel = switch_core_session_get_channel(other_session); other_channel = switch_core_session_get_channel(other_session);
switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL); switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BOND_VARIABLE, NULL);
@ -1028,7 +1022,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(other_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, NULL);
switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(channel, SWITCH_BRIDGE_VARIABLE, NULL);
switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL); switch_channel_set_variable(other_channel, SWITCH_BRIDGE_VARIABLE, NULL);
@ -1045,7 +1039,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_transfer(switch_core_session_
switch_channel_set_flag(channel, CF_TRANSFER); switch_channel_set_flag(channel, CF_TRANSFER);
switch_channel_set_state(channel, CS_ROUTING); switch_channel_set_state(channel, CS_ROUTING);
msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSFER; msg.message_id = SWITCH_MESSAGE_INDICATE_TRANSFER;
msg.from = __FILE__; msg.from = __FILE__;
switch_core_session_receive_message(session, &msg); switch_core_session_receive_message(session, &msg);
@ -1108,7 +1102,7 @@ struct switch_ivr_digit_stream {
switch_time_t last_digit_time; 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; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1148,7 +1142,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_new(switch_memory
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t * parser) SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_ivr_digit_stream_parser_t *parser)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1166,7 +1160,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_destroy(switch_iv
return status; 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; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1182,7 +1176,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_new(switch_ivr_digit_str
return status; 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; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1195,7 +1189,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_destroy(switch_ivr_digit
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t * parser, char *digits, void *data) SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_ivr_digit_stream_parser_t *parser, char *digits, void *data)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1231,7 +1225,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_event(switch_
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t * parser, char *digits) SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_ivr_digit_stream_parser_t *parser, char *digits)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1246,7 +1240,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_del_event(switch_
return status; return status;
} }
SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t * parser, switch_ivr_digit_stream_t * stream, char digit) SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stream_parser_t *parser, switch_ivr_digit_stream_t *stream, char digit)
{ {
void *result = NULL; void *result = NULL;
@ -1297,7 +1291,7 @@ SWITCH_DECLARE(void *) switch_ivr_digit_stream_parser_feed(switch_ivr_digit_stre
return result; return result;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t * stream) SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_stream_t *stream)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1311,7 +1305,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_reset(switch_ivr_digit_s
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t * parser, char digit) SWITCH_DECLARE(switch_status_t) switch_ivr_digit_stream_parser_set_terminator(switch_ivr_digit_stream_parser_t *parser, char digit)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -1403,13 +1397,14 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channe
switch_xml_t variable; switch_xml_t variable;
switch_event_header_t *hi = switch_channel_variable_first(channel); switch_event_header_t *hi = switch_channel_variable_first(channel);
if (!hi) return off; if (!hi)
return off;
for (; hi; hi = hi->next) { for (; hi; hi = hi->next) {
if (!switch_strlen_zero(hi->name) && !switch_strlen_zero(hi->value) && ((variable = switch_xml_add_child_d(xml, hi->name, off++)))) { if (!switch_strlen_zero(hi->name) && !switch_strlen_zero(hi->value) && ((variable = switch_xml_add_child_d(xml, hi->name, off++)))) {
char *data; char *data;
switch_size_t dlen = strlen(hi->value) * 3; switch_size_t dlen = strlen(hi->value) * 3;
if ((data = malloc(dlen))) { if ((data = malloc(dlen))) {
memset(data, 0, dlen); memset(data, 0, dlen);
switch_url_encode(hi->value, data, dlen); switch_url_encode(hi->value, data, dlen);
@ -1423,11 +1418,11 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_chan_vars(switch_xml_t xml, switch_channe
return off; return off;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr) SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t *xml_cdr)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_caller_profile_t *caller_profile; switch_caller_profile_t *caller_profile;
switch_xml_t variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag, 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;
switch_app_log_t *app_log; switch_app_log_t *app_log;
char tmp[512]; char tmp[512];
@ -1444,23 +1439,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
if ((app_log = switch_core_session_get_app_log(session))) { if ((app_log = switch_core_session_get_app_log(session))) {
int app_off = 0; int app_off = 0;
switch_app_log_t *ap; switch_app_log_t *ap;
if (!(x_apps = switch_xml_add_child_d(cdr, "app_log", cdr_off++))) { if (!(x_apps = switch_xml_add_child_d(cdr, "app_log", cdr_off++))) {
goto error; goto error;
} }
for(ap = app_log; ap; ap = ap->next) { for (ap = app_log; ap; ap = ap->next) {
if (!(x_application = switch_xml_add_child_d(x_apps, "application", app_off++))) { if (!(x_application = switch_xml_add_child_d(x_apps, "application", app_off++))) {
goto error; goto error;
} }
switch_xml_set_attr_d(x_application, "app_name", ap->app); switch_xml_set_attr_d(x_application, "app_name", ap->app);
switch_xml_set_attr_d(x_application, "app_data", ap->arg); switch_xml_set_attr_d(x_application, "app_data", ap->arg);
} }
} }
switch_ivr_set_xml_chan_vars(variables, channel, v_off); switch_ivr_set_xml_chan_vars(variables, channel, v_off);
caller_profile = switch_channel_get_caller_profile(channel); caller_profile = switch_channel_get_caller_profile(channel);
while (caller_profile) { while (caller_profile) {
@ -1486,7 +1481,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) { if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) {
goto error; goto error;
} }
switch_xml_set_attr_d(x_caller_extension, "name", caller_profile->caller_extension->extension_name); switch_xml_set_attr_d(x_caller_extension, "name", caller_profile->caller_extension->extension_name);
switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number); switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number);
if (caller_profile->caller_extension->current_application) { if (caller_profile->caller_extension->current_application) {
@ -1509,13 +1504,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
int i_off = 0; int i_off = 0;
for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) { for (cp = caller_profile->caller_extension->children; cp; cp = cp->next) {
app_off = 0; app_off = 0;
if (!cp->caller_extension) { if (!cp->caller_extension) {
continue; 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", i_off++))) {
goto error; 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", cf_off++))) {
goto error; goto error;
@ -1526,7 +1521,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
if (cp->caller_extension->current_application) { if (cp->caller_extension->current_application) {
switch_xml_set_attr_d(x_caller_extension, "current_app", cp->caller_extension->current_application->application_name); switch_xml_set_attr_d(x_caller_extension, "current_app", cp->caller_extension->current_application->application_name);
} }
for (ap = cp->caller_extension->applications; ap; ap = ap->next) { 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", app_off++))) {
goto error; goto error;
@ -1675,7 +1670,7 @@ SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint3
write_frame.codec = read_codec; write_frame.codec = read_codec;
while(switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
@ -1686,7 +1681,7 @@ SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint3
if ((jb_frame = stfu_n_read_a_frame(jb))) { if ((jb_frame = stfu_n_read_a_frame(jb))) {
write_frame.data = jb_frame->data; write_frame.data = jb_frame->data;
write_frame.datalen = (uint32_t)jb_frame->dlen; write_frame.datalen = (uint32_t) jb_frame->dlen;
status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
@ -1697,14 +1692,15 @@ SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint3
stfu_n_destroy(&jb); stfu_n_destroy(&jb);
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_say(switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type, const char *say_method, switch_input_args_t *args) SWITCH_DECLARE(switch_status_t) switch_ivr_say(switch_core_session_t *session, const char *tosay, const char *module_name, const char *say_type,
const char *say_method, switch_input_args_t *args)
{ {
switch_say_interface_t *si; switch_say_interface_t *si;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
if ((si = switch_loadable_module_get_say_interface(module_name))) { if ((si = switch_loadable_module_get_say_interface(module_name))) {
// should go back and proto all the say mods to const.... // should go back and proto all the say mods to const....
status = si->say_function(session, (char *)tosay, switch_ivr_get_say_type_by_name(say_type), switch_ivr_get_say_method_by_name(say_method), args); status = si->say_function(session, (char *) tosay, switch_ivr_get_say_type_by_name(say_type), switch_ivr_get_say_method_by_name(say_method), args);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;

View File

@ -47,20 +47,20 @@ static void *SWITCH_THREAD_FUNC echo_video_thread(switch_thread_t *thread, void
switch_status_t status; switch_status_t status;
switch_frame_t *read_frame; switch_frame_t *read_frame;
eh->up = 1; eh->up = 1;
while(switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
} }
if (switch_test_flag(read_frame, SFF_CNG)) { if (switch_test_flag(read_frame, SFF_CNG)) {
continue; continue;
} }
switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0); switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0);
} }
eh->up = 0; eh->up = 0;
return NULL; return NULL;
@ -73,13 +73,13 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session)
switch_frame_t *read_frame; switch_frame_t *read_frame;
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
struct echo_helper eh = {0}; struct echo_helper eh = { 0 };
switch_thread_t *thread; switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL; switch_threadattr_t *thd_attr = NULL;
#endif #endif
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
if (switch_channel_test_flag(channel, CF_VIDEO)) { if (switch_channel_test_flag(channel, CF_VIDEO)) {
eh.session = session; eh.session = session;
@ -90,7 +90,7 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session)
} }
#endif #endif
while(switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
@ -99,11 +99,11 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session)
#ifndef SWITCH_VIDEO_IN_THREADS #ifndef SWITCH_VIDEO_IN_THREADS
status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
} }
if (switch_test_flag(read_frame, SFF_CNG)) { if (switch_test_flag(read_frame, SFF_CNG)) {
continue; continue;
} }
@ -115,7 +115,7 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session)
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
if (eh.up) { if (eh.up) {
while(eh.up) { while (eh.up) {
switch_yield(1000); switch_yield(1000);
} }
} }
@ -165,8 +165,8 @@ static switch_bool_t write_displace_callback(switch_media_bug_t *bug, void *user
uint32_t x; uint32_t x;
st = switch_core_file_read(&dh->fh, buf, &len); st = switch_core_file_read(&dh->fh, buf, &len);
for(x = 0; x < (uint32_t) len; x++) { for (x = 0; x < (uint32_t) len; x++) {
int32_t mixed = fp[x] + buf[x]; int32_t mixed = fp[x] + buf[x];
switch_normalize_to_16bit(mixed); switch_normalize_to_16bit(mixed);
fp[x] = (int16_t) mixed; fp[x] = (int16_t) mixed;
@ -232,8 +232,8 @@ static switch_bool_t read_displace_callback(switch_media_bug_t *bug, void *user_
uint32_t x; uint32_t x;
st = switch_core_file_read(&dh->fh, buf, &len); st = switch_core_file_read(&dh->fh, buf, &len);
for(x = 0; x < (uint32_t) len; x++) { for (x = 0; x < (uint32_t) len; x++) {
int32_t mixed = fp[x] + buf[x]; int32_t mixed = fp[x] + buf[x];
switch_normalize_to_16bit(mixed); switch_normalize_to_16bit(mixed);
fp[x] = (int16_t) mixed; fp[x] = (int16_t) mixed;
@ -296,19 +296,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
read_codec = switch_core_session_get_read_codec(session); read_codec = switch_core_session_get_read_codec(session);
switch_assert(read_codec != NULL); switch_assert(read_codec != NULL);
dh->fh.channels = read_codec->implementation->number_of_channels; dh->fh.channels = read_codec->implementation->number_of_channels;
dh->fh.samplerate = read_codec->implementation->actual_samples_per_second; dh->fh.samplerate = read_codec->implementation->actual_samples_per_second;
if (switch_core_file_open(&dh->fh, if (switch_core_file_open(&dh->fh,
file, file,
read_codec->implementation->number_of_channels, read_codec->implementation->number_of_channels,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
NULL) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
@ -327,13 +326,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
if (flags && strchr(flags, 'l')) { if (flags && strchr(flags, 'l')) {
dh->loop++; dh->loop++;
} }
if (flags && strchr(flags, 'r')) { if (flags && strchr(flags, 'r')) {
status = switch_core_media_bug_add(session, read_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug); status = switch_core_media_bug_add(session, read_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
} else { } else {
status = switch_core_media_bug_add(session, write_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug); status = switch_core_media_bug_add(session, write_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
} }
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
switch_core_file_close(&dh->fh); switch_core_file_close(&dh->fh);
return status; return status;
@ -416,7 +415,7 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
struct eavesdrop_pvt *ep = (struct eavesdrop_pvt *) user_data; struct eavesdrop_pvt *ep = (struct eavesdrop_pvt *) user_data;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = { 0 }; switch_frame_t frame = { 0 };
frame.data = data; frame.data = data;
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
@ -430,13 +429,13 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
case SWITCH_ABC_TYPE_READ_PING: case SWITCH_ABC_TYPE_READ_PING:
if (ep->buffer) { if (ep->buffer) {
if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) { if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
switch_buffer_lock(ep->buffer); switch_buffer_lock(ep->buffer);
switch_buffer_zwrite(ep->buffer, frame.data, frame.datalen); switch_buffer_zwrite(ep->buffer, frame.data, frame.datalen);
switch_buffer_unlock(ep->buffer); switch_buffer_unlock(ep->buffer);
} }
} else { } else {
return SWITCH_FALSE; return SWITCH_FALSE;
} }
break; break;
case SWITCH_ABC_TYPE_READ: case SWITCH_ABC_TYPE_READ:
break; break;
@ -446,15 +445,15 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
if (switch_test_flag(ep, ED_MUX_READ)) { if (switch_test_flag(ep, ED_MUX_READ)) {
switch_frame_t *rframe = switch_core_media_bug_get_read_replace_frame(bug); switch_frame_t *rframe = switch_core_media_bug_get_read_replace_frame(bug);
if (switch_buffer_inuse(ep->r_buffer) >= rframe->datalen) { if (switch_buffer_inuse(ep->r_buffer) >= rframe->datalen) {
uint32_t bytes; uint32_t bytes;
switch_buffer_lock(ep->r_buffer); switch_buffer_lock(ep->r_buffer);
bytes = (uint32_t) switch_buffer_read(ep->r_buffer, data, rframe->datalen); bytes = (uint32_t) switch_buffer_read(ep->r_buffer, data, rframe->datalen);
rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *)data, bytes / 2) * 2; rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *) data, bytes / 2) * 2;
rframe->samples = rframe->datalen / 2; rframe->samples = rframe->datalen / 2;
switch_buffer_unlock(ep->r_buffer); switch_buffer_unlock(ep->r_buffer);
switch_core_media_bug_set_read_replace_frame(bug, rframe); switch_core_media_bug_set_read_replace_frame(bug, rframe);
} }
@ -466,15 +465,15 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
{ {
if (switch_test_flag(ep, ED_MUX_WRITE)) { if (switch_test_flag(ep, ED_MUX_WRITE)) {
switch_frame_t *rframe = switch_core_media_bug_get_write_replace_frame(bug); switch_frame_t *rframe = switch_core_media_bug_get_write_replace_frame(bug);
if (switch_buffer_inuse(ep->w_buffer) >= rframe->datalen) { if (switch_buffer_inuse(ep->w_buffer) >= rframe->datalen) {
uint32_t bytes; uint32_t bytes;
switch_buffer_lock(ep->w_buffer); switch_buffer_lock(ep->w_buffer);
bytes = (uint32_t) switch_buffer_read(ep->w_buffer, data, rframe->datalen); bytes = (uint32_t) switch_buffer_read(ep->w_buffer, data, rframe->datalen);
rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *)data, bytes / 2) * 2; rframe->datalen = switch_merge_sln(rframe->data, rframe->samples, (int16_t *) data, bytes / 2) * 2;
rframe->samples = rframe->datalen / 2; rframe->samples = rframe->datalen / 2;
switch_buffer_unlock(ep->w_buffer); switch_buffer_unlock(ep->w_buffer);
switch_core_media_bug_set_write_replace_frame(bug, rframe); switch_core_media_bug_set_write_replace_frame(bug, rframe);
} }
@ -489,10 +488,8 @@ static switch_bool_t eavesdrop_callback(switch_media_bug_t *bug, void *user_data
return SWITCH_TRUE; return SWITCH_TRUE;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session_t *session,
const char *uuid, const char *uuid, const char *require_group, switch_eavesdrop_flag_t flags)
const char *require_group,
switch_eavesdrop_flag_t flags)
{ {
switch_core_session_t *tsession; switch_core_session_t *tsession;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
@ -504,8 +501,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
switch_media_bug_t *bug = NULL; switch_media_bug_t *bug = NULL;
switch_channel_t *tchannel = switch_core_session_get_channel(tsession); switch_channel_t *tchannel = switch_core_session_get_channel(tsession);
switch_frame_t *read_frame, write_frame = { 0 }; switch_frame_t *read_frame, write_frame = { 0 };
switch_codec_t codec = {0}; switch_codec_t codec = { 0 };
int16_t buf[SWITCH_RECOMMENDED_BUFFER_SIZE/2]; int16_t buf[SWITCH_RECOMMENDED_BUFFER_SIZE / 2];
switch_codec_t *tread_codec = switch_core_session_get_read_codec(tsession); switch_codec_t *tread_codec = switch_core_session_get_read_codec(tsession);
uint32_t tlen; uint32_t tlen;
const char *macro_name = "eavesdrop_announce"; const char *macro_name = "eavesdrop_announce";
@ -530,39 +527,39 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
if (!switch_strlen_zero(require_group)) { if (!switch_strlen_zero(require_group)) {
const char *group_name = switch_channel_get_variable(tchannel, "eavesdrop_group"); const char *group_name = switch_channel_get_variable(tchannel, "eavesdrop_group");
if (!group_name || strcmp(group_name, require_group)) { if (!group_name || strcmp(group_name, require_group)) {
status = SWITCH_STATUS_BREAK; status = SWITCH_STATUS_BREAK;
goto end; goto end;
} }
} }
ep = switch_core_session_alloc(session, sizeof(*ep)); ep = switch_core_session_alloc(session, sizeof(*ep));
tlen = tread_codec->implementation->bytes_per_frame; tlen = tread_codec->implementation->bytes_per_frame;
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
if (switch_core_codec_init(&codec, if (switch_core_codec_init(&codec,
"L16", "L16",
NULL, NULL,
tread_codec->implementation->actual_samples_per_second, tread_codec->implementation->actual_samples_per_second,
tread_codec->implementation->microseconds_per_frame / 1000, tread_codec->implementation->microseconds_per_frame / 1000,
tread_codec->implementation->number_of_channels, tread_codec->implementation->number_of_channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot init codec\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot init codec\n");
switch_core_session_rwunlock(tsession); switch_core_session_rwunlock(tsession);
goto end; goto end;
} }
switch_core_session_set_read_codec(session, &codec); switch_core_session_set_read_codec(session, &codec);
write_frame.codec = &codec; write_frame.codec = &codec;
write_frame.data = buf; write_frame.data = buf;
write_frame.buflen = sizeof(buf); write_frame.buflen = sizeof(buf);
write_frame.rate = read_codec->implementation->actual_samples_per_second; write_frame.rate = read_codec->implementation->actual_samples_per_second;
ep->flags = flags; ep->flags = flags;
switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession)); switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
switch_buffer_create_dynamic(&ep->buffer, 2048, 2048, 8192); switch_buffer_create_dynamic(&ep->buffer, 2048, 2048, 8192);
@ -576,22 +573,22 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
switch_buffer_create_dynamic(&ep->r_buffer, 2048, 2048, 8192); switch_buffer_create_dynamic(&ep->r_buffer, 2048, 2048, 8192);
switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex); switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex);
if (switch_core_media_bug_add(tsession, eavesdrop_callback, ep, 0, if (switch_core_media_bug_add(tsession, eavesdrop_callback, ep, 0,
SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_REPLACE | SMBF_WRITE_REPLACE | SMBF_READ_PING | SMBF_THREAD_LOCK, SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_REPLACE | SMBF_WRITE_REPLACE | SMBF_READ_PING | SMBF_THREAD_LOCK,
&bug) != SWITCH_STATUS_SUCCESS) { &bug) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot attach bug\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot attach bug\n");
goto end; goto end;
} }
while(switch_channel_ready(tchannel) && switch_channel_ready(channel)) { while (switch_channel_ready(tchannel) && switch_channel_ready(channel)) {
uint32_t len = sizeof(buf); uint32_t len = sizeof(buf);
switch_event_t *event = NULL; switch_event_t *event = NULL;
char *fcommand = NULL; char *fcommand = NULL;
char db[2] = ""; char db[2] = "";
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
goto end; goto end;
} }
@ -605,7 +602,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
} }
if ((flags & ED_DTMF) && switch_channel_has_dtmf(channel)) { if ((flags & ED_DTMF) && switch_channel_has_dtmf(channel)) {
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
db[0] = dtmf.digit; db[0] = dtmf.digit;
fcommand = db; fcommand = db;
@ -613,9 +610,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
if (fcommand) { if (fcommand) {
char *d; char *d;
for(d = fcommand; *d; d++) { for (d = fcommand; *d; d++) {
int z = 1; int z = 1;
switch (*d) { switch (*d) {
case '1': case '1':
switch_set_flag(ep, ED_MUX_READ); switch_set_flag(ep, ED_MUX_READ);
@ -640,14 +637,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
break; break;
} }
if (z) { if (z) {
if (ep->r_buffer) { if (ep->r_buffer) {
switch_buffer_lock(ep->r_buffer); switch_buffer_lock(ep->r_buffer);
switch_buffer_zero(ep->r_buffer); switch_buffer_zero(ep->r_buffer);
switch_buffer_unlock(ep->r_buffer); switch_buffer_unlock(ep->r_buffer);
} }
if (ep->w_buffer) { if (ep->w_buffer) {
switch_buffer_lock(ep->w_buffer); switch_buffer_lock(ep->w_buffer);
switch_buffer_zero(ep->w_buffer); switch_buffer_zero(ep->w_buffer);
@ -671,49 +668,49 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
len = tlen; len = tlen;
} }
if (switch_buffer_inuse(ep->buffer) >= len) { if (switch_buffer_inuse(ep->buffer) >= len) {
switch_buffer_lock(ep->buffer); switch_buffer_lock(ep->buffer);
while (switch_buffer_inuse(ep->buffer) >= len) { while (switch_buffer_inuse(ep->buffer) >= len) {
write_frame.datalen = (uint32_t)switch_buffer_read(ep->buffer, buf, len); write_frame.datalen = (uint32_t) switch_buffer_read(ep->buffer, buf, len);
write_frame.samples = write_frame.datalen / 2; write_frame.samples = write_frame.datalen / 2;
if ((status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0)) != SWITCH_STATUS_SUCCESS) {
break; break;
} }
} }
switch_buffer_unlock(ep->buffer); switch_buffer_unlock(ep->buffer);
} }
}
end: }
end:
switch_core_codec_destroy(&codec); switch_core_codec_destroy(&codec);
if (bug) { if (bug) {
switch_core_media_bug_remove(tsession, &bug); switch_core_media_bug_remove(tsession, &bug);
} }
if (ep) { if (ep) {
if (ep->buffer) { if (ep->buffer) {
switch_buffer_destroy(&ep->buffer); switch_buffer_destroy(&ep->buffer);
} }
if (ep->r_buffer) { if (ep->r_buffer) {
switch_buffer_destroy(&ep->r_buffer); switch_buffer_destroy(&ep->r_buffer);
} }
if (ep->w_buffer) { if (ep->w_buffer) {
switch_buffer_destroy(&ep->w_buffer); switch_buffer_destroy(&ep->w_buffer);
} }
} }
switch_core_session_rwunlock(tsession); switch_core_session_rwunlock(tsession);
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
switch_core_session_set_read_codec(session, read_codec); switch_core_session_set_read_codec(session, read_codec);
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
} }
return status; return status;
} }
@ -747,7 +744,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
if ((p = switch_channel_get_variable(channel, "RECORD_ANSWER_REQ")) && switch_true(p)) { if ((p = switch_channel_get_variable(channel, "RECORD_ANSWER_REQ")) && switch_true(p)) {
flags |= SMBF_RECORD_ANSWER_REQ; flags |= SMBF_RECORD_ANSWER_REQ;
} }
fh->channels = channels; fh->channels = channels;
fh->samplerate = read_codec->implementation->actual_samples_per_second; fh->samplerate = read_codec->implementation->actual_samples_per_second;
@ -803,7 +800,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t
if (limit) { if (limit) {
to = switch_timestamp(NULL) + limit; to = switch_timestamp(NULL) + limit;
} }
if ((status = switch_core_media_bug_add(session, record_callback, fh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_media_bug_add(session, record_callback, fh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error adding media bug for file %s\n", file); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error adding media bug for file %s\n", file);
switch_core_file_close(fh); switch_core_file_close(fh);
@ -842,7 +839,7 @@ static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_da
teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str)); teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str));
if (digit_str[0]) { if (digit_str[0]) {
char *p = digit_str; char *p = digit_str;
while(p && *p) { while (p && *p) {
switch_dtmf_t dtmf; switch_dtmf_t dtmf;
dtmf.digit = *p; dtmf.digit = *p;
dtmf.duration = switch_core_default_dtmf_duration(0); dtmf.duration = switch_core_default_dtmf_duration(0);
@ -907,37 +904,37 @@ typedef struct {
switch_core_session_t *session; switch_core_session_t *session;
teletone_generation_session_t ts; teletone_generation_session_t ts;
switch_queue_t *digit_queue; switch_queue_t *digit_queue;
switch_buffer_t *audio_buffer; switch_buffer_t *audio_buffer;
switch_mutex_t *mutex; switch_mutex_t *mutex;
int read; int read;
int ready; int ready;
} switch_inband_dtmf_generate_t; } switch_inband_dtmf_generate_t;
static int teletone_dtmf_generate_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map) static int teletone_dtmf_generate_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
{ {
switch_buffer_t *audio_buffer = ts->user_data; switch_buffer_t *audio_buffer = ts->user_data;
int wrote; int wrote;
if (!audio_buffer) { if (!audio_buffer) {
return -1; return -1;
} }
wrote = teletone_mux_tones(ts, map); wrote = teletone_mux_tones(ts, map);
switch_buffer_write(audio_buffer, ts->buffer, wrote * 2); switch_buffer_write(audio_buffer, ts->buffer, wrote * 2);
return 0; return 0;
} }
static switch_status_t generate_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction) static switch_status_t generate_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_media_bug_t *bug = switch_channel_get_private(channel, "dtmf_generate"); switch_media_bug_t *bug = switch_channel_get_private(channel, "dtmf_generate");
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
if (bug) { if (bug) {
switch_inband_dtmf_generate_t *pvt = (switch_inband_dtmf_generate_t *) switch_core_media_bug_get_user_data(bug); switch_inband_dtmf_generate_t *pvt = (switch_inband_dtmf_generate_t *) switch_core_media_bug_get_user_data(bug);
if (pvt) { if (pvt) {
switch_mutex_lock(pvt->mutex); switch_mutex_lock(pvt->mutex);
if (pvt->ready) { if (pvt->ready) {
switch_dtmf_t *dt = NULL; switch_dtmf_t *dt = NULL;
@ -948,7 +945,7 @@ static switch_status_t generate_on_dtmf(switch_core_session_t *session, const sw
/* /*
SWITCH_STATUS_FALSE indicates pretend there never was a DTMF SWITCH_STATUS_FALSE indicates pretend there never was a DTMF
since we will be generating it inband now. since we will be generating it inband now.
*/ */
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else { } else {
free(dt); free(dt);
@ -1005,7 +1002,7 @@ static switch_bool_t inband_dtmf_generate_callback(switch_media_bug_t *bug, void
if (!pvt->ready) { if (!pvt->ready) {
switch_mutex_unlock(pvt->mutex); switch_mutex_unlock(pvt->mutex);
return SWITCH_FALSE; return SWITCH_FALSE;
} }
if (pvt->read) { if (pvt->read) {
@ -1013,7 +1010,7 @@ static switch_bool_t inband_dtmf_generate_callback(switch_media_bug_t *bug, void
} else { } else {
frame = switch_core_media_bug_get_write_replace_frame(bug); frame = switch_core_media_bug_get_write_replace_frame(bug);
} }
while (switch_queue_trypop(pvt->digit_queue, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop(pvt->digit_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_dtmf_t *dtmf = (switch_dtmf_t *) pop; switch_dtmf_t *dtmf = (switch_dtmf_t *) pop;
char buf[2] = ""; char buf[2] = "";
@ -1022,13 +1019,13 @@ static switch_bool_t inband_dtmf_generate_callback(switch_media_bug_t *bug, void
buf[0] = dtmf->digit; buf[0] = dtmf->digit;
if (duration > 8000) { if (duration > 8000) {
duration = 4000; duration = 4000;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Truncating ridiculous DTMF duration %d ms to 1/2 second.\n", switch_log_printf(SWITCH_CHANNEL_LOG, 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); switch_channel_get_name(switch_core_session_get_channel(pvt->session)), dtmf->duration / 8);
} }
pvt->ts.duration = duration; pvt->ts.duration = duration;
teletone_run(&pvt->ts, buf); teletone_run(&pvt->ts, buf);
} }
if (switch_buffer_inuse(pvt->audio_buffer) && (bytes = switch_buffer_read(pvt->audio_buffer, frame->data, frame->datalen))) { if (switch_buffer_inuse(pvt->audio_buffer) && (bytes = switch_buffer_read(pvt->audio_buffer, frame->data, frame->datalen))) {
if (bytes < frame->datalen) { if (bytes < frame->datalen) {
switch_byte_t *dp = frame->data; switch_byte_t *dp = frame->data;
@ -1087,7 +1084,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_generate_session(switch_c
pvt->session = session; pvt->session = session;
pvt->read = !!read_stream; pvt->read = !!read_stream;
if ((status = switch_core_media_bug_add(session, inband_dtmf_generate_callback, pvt, 0, if ((status = switch_core_media_bug_add(session, inband_dtmf_generate_callback, pvt, 0,
pvt->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) { pvt->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
@ -1108,7 +1105,7 @@ typedef struct {
} switch_tone_detect_t; } switch_tone_detect_t;
typedef struct { typedef struct {
switch_tone_detect_t list[MAX_TONES+1]; switch_tone_detect_t list[MAX_TONES + 1];
int index; int index;
switch_media_bug_t *bug; switch_media_bug_t *bug;
switch_core_session_t *session; switch_core_session_t *session;
@ -1133,11 +1130,11 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
if (!frame) { if (!frame) {
frame = switch_core_media_bug_get_write_replace_frame(bug); frame = switch_core_media_bug_get_write_replace_frame(bug);
} }
for (i = 0 ; i < cont->index; i++) { for (i = 0; i < cont->index; i++) {
if (cont->list[i].up && teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) { if (cont->list[i].up && teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
switch_event_t *event; switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
cont->list[i].up = 0; cont->list[i].up = 0;
@ -1154,11 +1151,11 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
switch_event_t *dup; switch_event_t *dup;
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Detected-Tone", "%s", cont->list[i].key); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Detected-Tone", "%s", cont->list[i].key);
if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) { if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
switch_event_fire(&dup); switch_event_fire(&dup);
} }
if (switch_core_session_queue_event(cont->session, &event) != SWITCH_STATUS_SUCCESS) { if (switch_core_session_queue_event(cont->session, &event) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event queue failed!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event queue failed!\n");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
@ -1180,7 +1177,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_"); switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_");
if (cont) { if (cont) {
switch_channel_set_private(channel, "_tone_detect_", NULL); switch_channel_set_private(channel, "_tone_detect_", NULL);
switch_core_media_bug_remove(session, &cont->bug); switch_core_media_bug_remove(session, &cont->bug);
@ -1189,110 +1186,110 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
const char *key, const char *tone_spec, const char *key, const char *tone_spec,
const char *flags, time_t timeout, const char *flags, time_t timeout, const char *app, const char *data)
const char *app, const char *data)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_codec_t *read_codec = switch_core_session_get_read_codec(session); switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
switch_status_t status; switch_status_t status;
switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_"); switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_");
char *p, *next; char *p, *next;
int i = 0, ok = 0; int i = 0, ok = 0;
switch_media_bug_flag_t bflags = 0; switch_media_bug_flag_t bflags = 0;
switch_assert(read_codec != NULL); switch_assert(read_codec != NULL);
if (switch_strlen_zero(key)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Key Specified!\n");
return SWITCH_STATUS_FALSE;
}
if (cont) {
if (cont->index >= MAX_TONES) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max Tones Reached!\n");
return SWITCH_STATUS_FALSE;
}
for(i = 0; i < cont->index; i++) { if (switch_strlen_zero(key)) {
if (!switch_strlen_zero(cont->list[cont->index].key) && !strcasecmp(key, cont->list[cont->index].key)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Key Specified!\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-enabling %s\n", key); return SWITCH_STATUS_FALSE;
cont->list[cont->index].up = 1; }
teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
return SWITCH_STATUS_SUCCESS;
}
}
}
if (switch_strlen_zero(tone_spec)) { if (cont) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Spec Specified!\n"); if (cont->index >= MAX_TONES) {
return SWITCH_STATUS_FALSE; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Max Tones Reached!\n");
} return SWITCH_STATUS_FALSE;
}
if (!cont && !(cont = switch_core_session_alloc(session, sizeof(*cont)))) { for (i = 0; i < cont->index; i++) {
return SWITCH_STATUS_MEMERR; if (!switch_strlen_zero(cont->list[cont->index].key) && !strcasecmp(key, cont->list[cont->index].key)) {
} switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-enabling %s\n", key);
cont->list[cont->index].up = 1;
teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
return SWITCH_STATUS_SUCCESS;
}
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding tone spec %s index %d\n", tone_spec, cont->index); if (switch_strlen_zero(tone_spec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Spec Specified!\n");
return SWITCH_STATUS_FALSE;
}
i = 0; if (!cont && !(cont = switch_core_session_alloc(session, sizeof(*cont)))) {
p = (char *) tone_spec; return SWITCH_STATUS_MEMERR;
}
do { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding tone spec %s index %d\n", tone_spec, cont->index);
teletone_process_t this;
next = strchr(p, ',');
while(*p == ' ') p++;
if ((this = (teletone_process_t) atof(p))) {
ok++;
cont->list[cont->index].map.freqs[i++] = this;
}
if (next) {
p = next + 1;
}
} while (next);
cont->list[cont->index].map.freqs[i++] = 0;
if (!ok) { i = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid tone spec!\n"); p = (char *) tone_spec;
return SWITCH_STATUS_FALSE;
}
cont->list[cont->index].key = switch_core_session_strdup(session, key); do {
teletone_process_t this;
next = strchr(p, ',');
while (*p == ' ')
p++;
if ((this = (teletone_process_t) atof(p))) {
ok++;
cont->list[cont->index].map.freqs[i++] = this;
}
if (next) {
p = next + 1;
}
} while (next);
cont->list[cont->index].map.freqs[i++] = 0;
if (app) { if (!ok) {
cont->list[cont->index].app = switch_core_session_strdup(session, app); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid tone spec!\n");
} return SWITCH_STATUS_FALSE;
}
if (data) {
cont->list[cont->index].data = switch_core_session_strdup(session, data);
}
cont->list[cont->index].up = 1; cont->list[cont->index].key = switch_core_session_strdup(session, key);
cont->list[cont->index].mt.sample_rate = read_codec->implementation->actual_samples_per_second;
teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
cont->session = session;
switch_channel_pre_answer(channel);
if (switch_strlen_zero(flags)) {
bflags = SMBF_READ_REPLACE;
} else {
if (strchr(flags, 'r')) {
bflags |= SMBF_READ_REPLACE;
} else if (strchr(flags, 'w')) {
bflags |= SMBF_WRITE_REPLACE;
}
}
if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) { if (app) {
return status; cont->list[cont->index].app = switch_core_session_strdup(session, app);
} }
switch_channel_set_private(channel, "_tone_detect_", cont); if (data) {
cont->index++; cont->list[cont->index].data = switch_core_session_strdup(session, data);
}
return SWITCH_STATUS_SUCCESS;
cont->list[cont->index].up = 1;
cont->list[cont->index].mt.sample_rate = read_codec->implementation->actual_samples_per_second;
teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
cont->session = session;
switch_channel_pre_answer(channel);
if (switch_strlen_zero(flags)) {
bflags = SMBF_READ_REPLACE;
} else {
if (strchr(flags, 'r')) {
bflags |= SMBF_READ_REPLACE;
} else if (strchr(flags, 'w')) {
bflags |= SMBF_WRITE_REPLACE;
}
}
if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
return status;
}
switch_channel_set_private(channel, "_tone_detect_", cont);
cont->index++;
return SWITCH_STATUS_SUCCESS;
} }
typedef struct { typedef struct {
@ -1304,7 +1301,7 @@ typedef struct {
typedef struct { typedef struct {
dtmf_meta_app_t map[10]; dtmf_meta_app_t map[10];
time_t last_digit; time_t last_digit;
switch_bool_t meta_on; switch_bool_t meta_on;
int up; int up;
} dtmf_meta_settings_t; } dtmf_meta_settings_t;
@ -1321,19 +1318,19 @@ static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch
time_t now = switch_timestamp(NULL); time_t now = switch_timestamp(NULL);
char digit[2] = ""; char digit[2] = "";
int dval; int dval;
if (!md || switch_channel_test_flag(channel, CF_INNER_BRIDGE)) { if (!md || switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if (direction == SWITCH_DTMF_RECV && !md->sr[SWITCH_DTMF_RECV].up) { if (direction == SWITCH_DTMF_RECV && !md->sr[SWITCH_DTMF_RECV].up) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if (direction == SWITCH_DTMF_SEND && !md->sr[SWITCH_DTMF_SEND].up) { if (direction == SWITCH_DTMF_SEND && !md->sr[SWITCH_DTMF_SEND].up) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if (md->sr[direction].meta_on && now - md->sr[direction].last_digit > 5) { if (md->sr[direction].meta_on && now - md->sr[direction].last_digit > 5) {
md->sr[direction].meta_on = SWITCH_FALSE; md->sr[direction].meta_on = SWITCH_FALSE;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel), dtmf->digit); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel), dtmf->digit);
@ -1358,9 +1355,9 @@ static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch
*digit = dtmf->digit; *digit = dtmf->digit;
dval = atoi(digit); dval = atoi(digit);
if (direction == SWITCH_DTMF_RECV && (md->sr[direction].map[dval].bind_flags & SBF_DIAL_ALEG)) { if (direction == SWITCH_DTMF_RECV && (md->sr[direction].map[dval].bind_flags & SBF_DIAL_ALEG)) {
ok = 1; ok = 1;
} else if (direction == SWITCH_DTMF_SEND && (md->sr[direction].map[dval].bind_flags & SBF_DIAL_BLEG)) { } else if (direction == SWITCH_DTMF_SEND && (md->sr[direction].map[dval].bind_flags & SBF_DIAL_BLEG)) {
ok = 1; ok = 1;
} }
@ -1387,41 +1384,41 @@ static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch
flags |= SMF_ECHO_ALEG; flags |= SMF_ECHO_ALEG;
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n",
switch_channel_get_name(channel), dtmf->digit, md->sr[direction].map[dval].app); switch_channel_get_name(channel), dtmf->digit, md->sr[direction].map[dval].app);
switch_ivr_broadcast(switch_core_session_get_uuid(session), md->sr[direction].map[dval].app, flags); switch_ivr_broadcast(switch_core_session_get_uuid(session), md->sr[direction].map[dval].app, flags);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Ignoring meta digit '%c' not mapped\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Ignoring meta digit '%c' not mapped\n",
switch_channel_get_name(channel), dtmf->digit); switch_channel_get_name(channel), dtmf->digit);
} }
} }
md->sr[direction].meta_on = SWITCH_FALSE; md->sr[direction].meta_on = SWITCH_FALSE;
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session) SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_set_private(channel, SWITCH_META_VAR_KEY, NULL); switch_channel_set_private(channel, SWITCH_META_VAR_KEY, NULL);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, 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) switch_bind_flag_t bind_flags, const char *app)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY); dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY);
if (key > 9) { if (key > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid key %u\n", key); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid key %u\n", key);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if (!md) { if (!md) {
md = switch_core_session_alloc(session, sizeof(*md)); md = switch_core_session_alloc(session, sizeof(*md));
switch_channel_set_private(channel, SWITCH_META_VAR_KEY, md); switch_channel_set_private(channel, SWITCH_META_VAR_KEY, md);
@ -1435,7 +1432,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_se
md->sr[SWITCH_DTMF_RECV].map[key].app = switch_core_session_strdup(session, app); 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].flags |= SMF_HOLD_BLEG;
md->sr[SWITCH_DTMF_RECV].map[key].bind_flags = bind_flags; md->sr[SWITCH_DTMF_RECV].map[key].bind_flags = bind_flags;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound A-Leg: %d %s\n", key, app); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound A-Leg: %d %s\n", key, app);
} }
if ((bind_flags & SBF_DIAL_BLEG)) { if ((bind_flags & SBF_DIAL_BLEG)) {
@ -1445,7 +1442,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_se
md->sr[SWITCH_DTMF_SEND].map[key].bind_flags = bind_flags; md->sr[SWITCH_DTMF_SEND].map[key].bind_flags = bind_flags;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound B-Leg: %d %s\n", key, app); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound B-Leg: %d %s\n", key, app);
} }
} else { } else {
if ((bind_flags & SBF_DIAL_ALEG)) { if ((bind_flags & SBF_DIAL_ALEG)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "UnBound A-Leg: %d\n", key); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "UnBound A-Leg: %d\n", key);
@ -1470,7 +1467,7 @@ struct speech_thread_handle {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
}; };
static void *SWITCH_THREAD_FUNC speech_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC speech_thread(switch_thread_t *thread, void *obj)
{ {
struct speech_thread_handle *sth = (struct speech_thread_handle *) obj; struct speech_thread_handle *sth = (struct speech_thread_handle *) obj;
switch_channel_t *channel = switch_core_session_get_channel(sth->session); switch_channel_t *channel = switch_core_session_get_channel(sth->session);
@ -1659,10 +1656,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_c
SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t *session,
const char *mod_name, const char *mod_name,
const char *grammar, const char *grammar, const char *path, const char *dest, switch_asr_handle_t *ah)
const char *path,
const char *dest,
switch_asr_handle_t *ah)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_codec_t *read_codec = switch_core_session_get_read_codec(session); switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@ -1816,7 +1810,7 @@ SWITCH_DECLARE(uint32_t) switch_ivr_schedule_transfer(time_t runtime, const char
} }
switch_zmalloc(cur, len); switch_zmalloc(cur, len);
helper = (struct transfer_helper *)cur; helper = (struct transfer_helper *) cur;
switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str)); switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
@ -1864,12 +1858,12 @@ SWITCH_DECLARE(uint32_t) switch_ivr_schedule_broadcast(time_t runtime, char *uui
char *cur = NULL; char *cur = NULL;
switch_zmalloc(cur, len); switch_zmalloc(cur, len);
helper = (struct broadcast_helper *)cur; helper = (struct broadcast_helper *) cur;
cur += sizeof(*helper); cur += sizeof(*helper);
switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str)); switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
helper->flags = flags; helper->flags = flags;
switch_copy_string(cur, path, len - sizeof(helper)); switch_copy_string(cur, path, len - sizeof(helper));
helper->path = cur; helper->path = cur;
@ -1898,7 +1892,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(const char *uuid, const cha
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
if ((switch_channel_test_flag(channel, CF_EVENT_PARSE))) { if ((switch_channel_test_flag(channel, CF_EVENT_PARSE))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel [%s][%s] already broadcasting...broadcast aborted\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel [%s][%s] already broadcasting...broadcast aborted\n",
switch_channel_get_name(channel), path); switch_channel_get_name(channel), path);
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -1914,8 +1908,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(const char *uuid, const cha
if ((nomedia = switch_channel_test_flag(channel, CF_PROXY_MODE))) { if ((nomedia = switch_channel_test_flag(channel, CF_PROXY_MODE))) {
switch_ivr_media(uuid, SMF_REBRIDGE); switch_ivr_media(uuid, SMF_REBRIDGE);
} }
if ((p = strchr(mypath, ':')) && *(p+1) == ':') { if ((p = strchr(mypath, ':')) && *(p + 1) == ':') {
app = mypath; app = mypath;
*p++ = '\0'; *p++ = '\0';
*p++ = '\0'; *p++ = '\0';
@ -1946,7 +1940,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_broadcast(const char *uuid, const cha
switch_core_session_queue_private_event(other_session, &event); switch_core_session_queue_private_event(other_session, &event);
} }
switch_core_session_rwunlock(other_session); switch_core_session_rwunlock(other_session);
master = other_session; master = other_session;
other_session = NULL; other_session = NULL;

View File

@ -50,16 +50,16 @@ static void *SWITCH_THREAD_FUNC video_bridge_thread(switch_thread_t *thread, voi
switch_status_t status; switch_status_t status;
switch_frame_t *read_frame; switch_frame_t *read_frame;
vh->up = 1; vh->up = 1;
while(switch_channel_ready(channel) && vh->up == 1) { while (switch_channel_ready(channel) && vh->up == 1) {
status = switch_core_session_read_video_frame(vh->session_a, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_video_frame(vh->session_a, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
} }
switch_core_session_write_video_frame(vh->session_b, read_frame, SWITCH_IO_FLAG_NONE, 0); switch_core_session_write_video_frame(vh->session_b, read_frame, SWITCH_IO_FLAG_NONE, 0);
} }
vh->up = 0; vh->up = 0;
return NULL; return NULL;
@ -70,10 +70,10 @@ static void launch_video(struct vid_helper *vh)
switch_thread_t *thread; switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL; switch_threadattr_t *thd_attr = NULL;
switch_threadattr_create(&thd_attr, switch_core_session_get_pool(vh->session_a)); switch_threadattr_create(&thd_attr, switch_core_session_get_pool(vh->session_a));
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&thread, thd_attr, video_bridge_thread, vh, switch_core_session_get_pool(vh->session_a)); switch_thread_create(&thread, thd_attr, video_bridge_thread, vh, switch_core_session_get_pool(vh->session_a));
} }
#endif #endif
@ -86,7 +86,7 @@ struct switch_ivr_bridge_data {
}; };
typedef struct switch_ivr_bridge_data switch_ivr_bridge_data_t; typedef struct switch_ivr_bridge_data switch_ivr_bridge_data_t;
static void *audio_bridge_thread(switch_thread_t * thread, void *obj) static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
{ {
switch_ivr_bridge_data_t *data = obj; switch_ivr_bridge_data_t *data = obj;
int stream_id = 0, pre_b = 0, ans_a = 0, ans_b = 0, originator = 0; int stream_id = 0, pre_b = 0, ans_a = 0, ans_b = 0, originator = 0;
@ -99,9 +99,9 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
uint32_t loop_count = 0; uint32_t loop_count = 0;
const char *app_name = NULL, *app_arg = NULL; const char *app_name = NULL, *app_arg = NULL;
const char *hook_var = NULL; const char *hook_var = NULL;
int inner_bridge = 0; int inner_bridge = 0;
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
struct vid_helper vh = { 0 }; struct vid_helper vh = { 0 };
uint32_t vid_launch = 0; uint32_t vid_launch = 0;
#endif #endif
@ -109,7 +109,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
if (!(session_b = switch_core_session_locate(data->b_uuid))) { if (!(session_b = switch_core_session_locate(data->b_uuid))) {
return NULL; return NULL;
} }
input_callback = data->input_callback; input_callback = data->input_callback;
user_data = data->session_data; user_data = data->session_data;
stream_id = data->stream_id; stream_id = data->stream_id;
@ -124,7 +124,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
} }
inner_bridge = switch_channel_test_flag(chan_a, CF_INNER_BRIDGE); inner_bridge = switch_channel_test_flag(chan_a, CF_INNER_BRIDGE);
switch_channel_set_flag(chan_a, CF_BRIDGED); switch_channel_set_flag(chan_a, CF_BRIDGED);
@ -170,20 +170,19 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
if (!inner_bridge && (switch_channel_test_flag(chan_a, CF_SUSPEND) || switch_channel_test_flag(chan_b, CF_SUSPEND))) { if (!inner_bridge && (switch_channel_test_flag(chan_a, CF_SUSPEND) || switch_channel_test_flag(chan_b, CF_SUSPEND))) {
status = switch_core_session_read_frame(session_a, &read_frame, SWITCH_IO_FLAG_NONE, stream_id); status = switch_core_session_read_frame(session_a, &read_frame, SWITCH_IO_FLAG_NONE, stream_id);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
goto end_of_bridge_loop; goto end_of_bridge_loop;
} }
continue; continue;
} }
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO) && !vid_launch) { if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO) && !vid_launch) {
vid_launch++; vid_launch++;
vh.session_a = session_a; vh.session_a = session_a;
vh.session_b = session_b; vh.session_b = session_b;
launch_video(&vh); launch_video(&vh);
} }
#endif #endif
/* if 1 channel has DTMF pass it to the other */ /* if 1 channel has DTMF pass it to the other */
@ -193,8 +192,8 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
int send_dtmf = 1; int send_dtmf = 1;
if (input_callback) { if (input_callback) {
switch_status_t cb_status = input_callback(session_a, (void *)&dtmf, SWITCH_INPUT_TYPE_DTMF, user_data, 0); switch_status_t cb_status = input_callback(session_a, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, user_data, 0);
if (cb_status == SWITCH_STATUS_IGNORE) { if (cb_status == SWITCH_STATUS_IGNORE) {
send_dtmf = 0; send_dtmf = 0;
} else if (cb_status != SWITCH_STATUS_SUCCESS) { } else if (cb_status != SWITCH_STATUS_SUCCESS) {
@ -203,7 +202,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
goto end_of_bridge_loop; goto end_of_bridge_loop;
} }
} }
if (send_dtmf) { if (send_dtmf) {
switch_core_session_send_dtmf(session_b, &dtmf); switch_core_session_send_dtmf(session_b, &dtmf);
} }
@ -250,16 +249,15 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
continue; continue;
} }
} }
#ifndef SWITCH_VIDEO_IN_THREADS #ifndef SWITCH_VIDEO_IN_THREADS
if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO)) { 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 */ /* read video from 1 channel and write it to the other */
status = switch_core_session_read_video_frame(session_a, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_video_frame(session_a, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
goto end_of_bridge_loop; goto end_of_bridge_loop;
} }
switch_core_session_write_video_frame(session_b, read_frame, SWITCH_IO_FLAG_NONE, 0); switch_core_session_write_video_frame(session_b, read_frame, SWITCH_IO_FLAG_NONE, 0);
} }
#endif #endif
@ -285,17 +283,17 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
} }
} }
end_of_bridge_loop: end_of_bridge_loop:
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
if (vh.up) { if (vh.up) {
vh.up = -1; vh.up = -1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ending video thread.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ending video thread.\n");
while(vh.up) { while (vh.up) {
switch_yield(100000); switch_yield(100000);
} }
} }
#endif #endif
if (!inner_bridge) { if (!inner_bridge) {
@ -314,9 +312,9 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nPost-Bridge Command %s(%s):\n%s\n", cmd, arg, switch_str_nil((char *) stream.data)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nPost-Bridge Command %s(%s):\n%s\n", cmd, arg, switch_str_nil((char *) stream.data));
switch_safe_free(stream.data); switch_safe_free(stream.data);
} }
if (switch_channel_get_state(chan_b) >= CS_HANGUP) { if (switch_channel_get_state(chan_b) >= CS_HANGUP) {
if (originator && switch_channel_ready(chan_a) && !switch_channel_test_flag(chan_a, CF_ANSWERED)) { if (originator && switch_channel_ready(chan_a) && !switch_channel_test_flag(chan_a, CF_ANSWERED)) {
switch_channel_hangup(chan_a, switch_channel_get_cause(chan_b)); switch_channel_hangup(chan_a, switch_channel_get_cause(chan_b));
} }
@ -326,7 +324,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
msg.from = __FILE__; msg.from = __FILE__;
switch_core_session_receive_message(session_a, &msg); switch_core_session_receive_message(session_a, &msg);
if (!inner_bridge && switch_channel_get_state(chan_a) < CS_HANGUP) { if (!inner_bridge && switch_channel_get_state(chan_a) < CS_HANGUP) {
if ((app_name = switch_channel_get_variable(chan_a, SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE))) { if ((app_name = switch_channel_get_variable(chan_a, SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE))) {
switch_caller_extension_t *extension = NULL; switch_caller_extension_t *extension = NULL;
@ -347,7 +345,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
} }
} }
end: end:
switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK); switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK);
switch_core_session_reset(session_a, SWITCH_TRUE); switch_core_session_reset(session_a, SWITCH_TRUE);
@ -379,7 +377,7 @@ static switch_status_t audio_bridge_on_exchange_media(switch_core_session_t *ses
switch_channel_clear_state_handler(channel, &audio_bridge_peer_state_handlers); switch_channel_clear_state_handler(channel, &audio_bridge_peer_state_handlers);
state = switch_channel_get_state(channel); state = switch_channel_get_state(channel);
if (!switch_channel_test_flag(channel, CF_TRANSFER) && state != CS_PARK && state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) { if (!switch_channel_test_flag(channel, CF_TRANSFER) && state != CS_PARK && state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
} }
@ -447,13 +445,12 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) { if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
if ((other_uuid = switch_channel_get_variable(channel, SWITCH_UUID_BRIDGE)) && if ((other_uuid = switch_channel_get_variable(channel, SWITCH_UUID_BRIDGE)) && (other_session = switch_core_session_locate(other_uuid))) {
(other_session = switch_core_session_locate(other_uuid))) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session); switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
switch_event_t *event; switch_event_t *event;
uint8_t ready_a, ready_b; uint8_t ready_a, ready_b;
switch_channel_set_variable(channel, SWITCH_UUID_BRIDGE, NULL); switch_channel_set_variable(channel, SWITCH_UUID_BRIDGE, NULL);
switch_channel_wait_for_state(channel, other_channel, CS_RESET); switch_channel_wait_for_state(channel, other_channel, CS_RESET);
@ -474,7 +471,7 @@ static switch_status_t uuid_bridge_on_soft_execute(switch_core_session_t *sessio
switch_channel_clear_flag(other_channel, CF_TRANSFER); switch_channel_clear_flag(other_channel, CF_TRANSFER);
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
switch_core_session_reset(other_session, SWITCH_TRUE); switch_core_session_reset(other_session, SWITCH_TRUE);
ready_a = switch_channel_ready(channel); ready_a = switch_channel_ready(channel);
ready_b = switch_channel_ready(other_channel); ready_b = switch_channel_ready(other_channel);
@ -524,8 +521,8 @@ static const switch_state_handler_table_t uuid_bridge_state_handlers = {
/*.on_exchange_media */ NULL, /*.on_exchange_media */ NULL,
/*.on_soft_execute */ uuid_bridge_on_soft_execute, /*.on_soft_execute */ uuid_bridge_on_soft_execute,
/*.on_consume_media */ NULL, /*.on_consume_media */ NULL,
/*.on_hibernate*/ NULL, /*.on_hibernate */ NULL,
/*.on_reset*/ uuid_bridge_on_reset /*.on_reset */ uuid_bridge_on_reset
}; };
static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session) static switch_status_t signal_bridge_on_hibernate(switch_core_session_t *session)
@ -548,7 +545,7 @@ static switch_status_t signal_bridge_on_hangup(switch_core_session_t *session)
switch_core_session_t *other_session; switch_core_session_t *other_session;
switch_event_t *event; switch_event_t *event;
if (switch_channel_test_flag(channel, CF_ORIGINATOR)) { if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
switch_channel_clear_flag(channel, CF_ORIGINATOR); switch_channel_clear_flag(channel, CF_ORIGINATOR);
if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event); switch_channel_event_set_data(channel, event);
@ -636,7 +633,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
switch_channel_set_state_flag(caller_channel, CF_TRANSFER); switch_channel_set_state_flag(caller_channel, CF_TRANSFER);
switch_channel_set_state_flag(peer_channel, CF_TRANSFER); switch_channel_set_state_flag(peer_channel, CF_TRANSFER);
switch_channel_set_state(caller_channel, CS_HIBERNATE); switch_channel_set_state(caller_channel, CS_HIBERNATE);
switch_channel_set_state(peer_channel, CS_HIBERNATE); switch_channel_set_state(peer_channel, CS_HIBERNATE);
@ -659,7 +656,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_event_t *event; switch_event_t *event;
int br = 0; int br = 0;
int inner_bridge = switch_channel_test_flag(caller_channel, CF_INNER_BRIDGE); int inner_bridge = switch_channel_test_flag(caller_channel, CF_INNER_BRIDGE);
switch_channel_set_flag(caller_channel, CF_ORIGINATOR); switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
switch_channel_clear_flag(caller_channel, CF_TRANSFER); switch_channel_clear_flag(caller_channel, CF_TRANSFER);
switch_channel_clear_flag(peer_channel, CF_TRANSFER); switch_channel_clear_flag(peer_channel, CF_TRANSFER);
@ -695,7 +692,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_event_fire(&event); switch_event_fire(&event);
br = 1; br = 1;
} }
if (switch_core_session_read_lock(peer_session) == SWITCH_STATUS_SUCCESS) { if (switch_core_session_read_lock(peer_session) == SWITCH_STATUS_SUCCESS) {
switch_channel_set_variable(caller_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session)); 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)); switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
@ -748,14 +745,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_CHANNEL_VARIABLE, switch_channel_get_name(caller_channel)); switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_CHANNEL_VARIABLE, switch_channel_get_name(caller_channel));
switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(session)); switch_channel_set_variable(peer_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(session));
switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session)); switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session));
if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_app"))) { if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_app"))) {
data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_data"); data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_data");
if ((application_interface = switch_loadable_module_get_application_interface(app))) { if ((application_interface = switch_loadable_module_get_application_interface(app))) {
switch_core_session_exec(session, application_interface, data); switch_core_session_exec(session, application_interface, data);
} }
} }
if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_app"))) { if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_app"))) {
data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data"); data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data");
if ((application_interface = switch_loadable_module_get_application_interface(app))) { if ((application_interface = switch_loadable_module_get_application_interface(app))) {
@ -768,7 +765,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
audio_bridge_thread(NULL, (void *) a_leg); audio_bridge_thread(NULL, (void *) a_leg);
switch_channel_clear_flag(caller_channel, CF_ORIGINATOR); switch_channel_clear_flag(caller_channel, CF_ORIGINATOR);
if (!switch_channel_test_flag(peer_channel, CF_TRANSFER) && switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) { if (!switch_channel_test_flag(peer_channel, CF_TRANSFER) && switch_channel_get_state(peer_channel) == CS_EXCHANGE_MEDIA) {
switch_channel_set_state(peer_channel, CS_RESET); switch_channel_set_state(peer_channel, CS_RESET);
} }
@ -801,10 +798,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
} }
state = switch_channel_get_state(caller_channel); state = switch_channel_get_state(caller_channel);
if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !inner_bridge) { if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !inner_bridge) {
if ((state != CS_EXECUTE && state != CS_PARK && state != CS_ROUTING) || if ((state != CS_EXECUTE && state != CS_PARK && state != CS_ROUTING) ||
(switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP && (switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP &&
switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE)))) { switch_true(switch_channel_get_variable(caller_channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE)))) {
switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel)); switch_channel_hangup(caller_channel, switch_channel_get_cause(peer_channel));
} }
@ -837,7 +834,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
swap_session = originator_session; swap_session = originator_session;
originator_session = originatee_session; originator_session = originatee_session;
originatee_session = swap_session; originatee_session = swap_session;
swap_channel = originator_channel; swap_channel = originator_channel;
originator_channel = originatee_channel; originator_channel = originatee_channel;
originatee_channel = swap_channel; originatee_channel = swap_channel;
@ -856,7 +853,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
* inturrupt anything they are already doing. * inturrupt anything they are already doing.
* originatee_session will fall asleep and originator_session will bridge to it * originatee_session will fall asleep and originator_session will bridge to it
*/ */
switch_channel_clear_state_handler(originator_channel, NULL); switch_channel_clear_state_handler(originator_channel, NULL);
switch_channel_clear_state_handler(originatee_channel, NULL); switch_channel_clear_state_handler(originatee_channel, NULL);
switch_channel_set_state_flag(originator_channel, CF_ORIGINATOR); switch_channel_set_state_flag(originator_channel, CF_ORIGINATOR);
@ -864,7 +861,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers); switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers);
switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers); switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers);
switch_channel_set_variable(originator_channel, SWITCH_UUID_BRIDGE, switch_core_session_get_uuid(originatee_session)); 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_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)); switch_channel_set_variable(originator_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(originatee_session));
switch_channel_set_variable(originator_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(originatee_session)); switch_channel_set_variable(originator_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(originatee_session));
@ -872,10 +869,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
switch_channel_set_variable(originatee_channel, SWITCH_BRIDGE_UUID_VARIABLE, switch_core_session_get_uuid(originator_session)); 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)); 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); originator_cp = switch_channel_get_caller_profile(originator_channel);
originatee_cp = switch_channel_get_caller_profile(originatee_channel); originatee_cp = switch_channel_get_caller_profile(originatee_channel);
switch_channel_set_variable(originatee_channel, "original_destination_number", originatee_cp->destination_number); switch_channel_set_variable(originatee_channel, "original_destination_number", originatee_cp->destination_number);
switch_channel_set_variable(originatee_channel, "original_caller_id_name", originatee_cp->caller_id_name); switch_channel_set_variable(originatee_channel, "original_caller_id_name", originatee_cp->caller_id_name);
@ -891,7 +888,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
cp->caller_id_name = switch_core_strdup(cp->pool, originator_cp->caller_id_name); cp->caller_id_name = switch_core_strdup(cp->pool, originator_cp->caller_id_name);
switch_channel_set_caller_profile(originatee_channel, cp); switch_channel_set_caller_profile(originatee_channel, cp);
switch_channel_set_originator_caller_profile(originatee_channel, switch_caller_profile_clone(originatee_session, originator_cp)); switch_channel_set_originator_caller_profile(originatee_channel, switch_caller_profile_clone(originatee_session, originator_cp));
cp = switch_caller_profile_clone(originator_session, originator_cp); cp = switch_caller_profile_clone(originator_session, originator_cp);
cp->destination_number = switch_core_strdup(cp->pool, originatee_cp->caller_id_number); cp->destination_number = switch_core_strdup(cp->pool, originatee_cp->caller_id_number);
cp->caller_id_number = switch_core_strdup(cp->pool, originatee_cp->caller_id_number); cp->caller_id_number = switch_core_strdup(cp->pool, originatee_cp->caller_id_number);
@ -907,7 +904,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
switch_channel_clear_flag(originator_channel, CF_ORIGINATING); switch_channel_clear_flag(originator_channel, CF_ORIGINATING);
switch_channel_clear_flag(originatee_channel, CF_ORIGINATING); switch_channel_clear_flag(originatee_channel, CF_ORIGINATING);
/* change the states and let the chips fall where they may */ /* change the states and let the chips fall where they may */
switch_channel_set_state(originator_channel, CS_RESET); switch_channel_set_state(originator_channel, CS_RESET);
switch_channel_set_state(originatee_channel, CS_RESET); switch_channel_set_state(originatee_channel, CS_RESET);
@ -935,7 +932,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_find_bridged_uuid(const char *uuid, c
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(uuid); switch_assert(uuid);
if ((rsession = switch_core_session_locate(uuid))) { if ((rsession = switch_core_session_locate(uuid))) {
switch_channel_t *rchannel = switch_core_session_get_channel(rsession); switch_channel_t *rchannel = switch_core_session_get_channel(rsession);
const char *brto; const char *brto;
@ -946,7 +943,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_find_bridged_uuid(const char *uuid, c
} }
switch_core_session_rwunlock(rsession); switch_core_session_rwunlock(rsession);
} }
return status; return status;
} }
@ -972,7 +969,7 @@ SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session
return; return;
} }
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
rchannel = switch_core_session_get_channel(rsession); rchannel = switch_core_session_get_channel(rsession);
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
@ -983,7 +980,7 @@ SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session
if (!switch_channel_test_flag(rchannel, CF_ANSWERED)) { if (!switch_channel_test_flag(rchannel, CF_ANSWERED)) {
switch_channel_answer(rchannel); switch_channel_answer(rchannel);
} }
//switch_ivr_park_session(rsession); //switch_ivr_park_session(rsession);
switch_channel_set_state_flag(rchannel, CF_TRANSFER); switch_channel_set_state_flag(rchannel, CF_TRANSFER);
switch_channel_set_state(rchannel, CS_RESET); switch_channel_set_state(rchannel, CS_RESET);

View File

@ -37,13 +37,13 @@ static const switch_state_handler_table_t originate_state_handlers;
static switch_status_t originate_on_consume_media_transmit(switch_core_session_t *session) static switch_status_t originate_on_consume_media_transmit(switch_core_session_t *session)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) { if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) {
while(switch_channel_get_state(channel) == CS_CONSUME_MEDIA && !switch_channel_test_flag(channel, CF_TAGGED)) { while (switch_channel_get_state(channel) == CS_CONSUME_MEDIA && !switch_channel_test_flag(channel, CF_TAGGED)) {
switch_ivr_sleep(session, 10); switch_ivr_sleep(session, 10);
} }
} }
switch_channel_clear_state_handler(channel, &originate_state_handlers); switch_channel_clear_state_handler(channel, &originate_state_handlers);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -81,7 +81,7 @@ struct key_collect {
switch_core_session_t *session; switch_core_session_t *session;
}; };
static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void *obj)
{ {
struct key_collect *collect = (struct key_collect *) obj; struct key_collect *collect = (struct key_collect *) obj;
switch_channel_t *channel = switch_core_session_get_channel(collect->session); switch_channel_t *channel = switch_core_session_get_channel(collect->session);
@ -117,7 +117,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t * thread, voi
switch_channel_set_state(channel, CS_SOFT_EXECUTE); switch_channel_set_state(channel, CS_SOFT_EXECUTE);
switch_core_session_exec(collect->session, application_interface, app_data); switch_core_session_exec(collect->session, application_interface, app_data);
if (switch_channel_get_state(channel) < CS_HANGUP) { if (switch_channel_get_state(channel) < CS_HANGUP) {
switch_channel_set_flag(channel, CF_WINNER); switch_channel_set_flag(channel, CF_WINNER);
} }
@ -166,13 +166,14 @@ static void launch_collect_thread(struct key_collect *collect)
static uint8_t check_channel_status(switch_channel_t **peer_channels, static uint8_t check_channel_status(switch_channel_t **peer_channels,
switch_core_session_t **peer_sessions, switch_core_session_t **peer_sessions,
uint32_t len, int32_t *idx, uint32_t * hups, char *file, char *key, uint8_t early_ok, uint8_t *ring_ready, uint8_t return_ring_ready) uint32_t len, int32_t *idx, uint32_t *hups, char *file, char *key, uint8_t early_ok, uint8_t *ring_ready,
uint8_t return_ring_ready)
{ {
uint32_t i; uint32_t i;
*hups = 0; *hups = 0;
*idx = IDX_NADA; *idx = IDX_NADA;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
switch_channel_state_t state; switch_channel_state_t state;
if (!peer_channels[i]) { if (!peer_channels[i]) {
@ -183,17 +184,16 @@ static uint8_t check_channel_status(switch_channel_t **peer_channels,
} }
state = switch_channel_get_state(peer_channels[i]); state = switch_channel_get_state(peer_channels[i]);
if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) ||
switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || !switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
!switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
) { ) {
(*hups)++; (*hups)++;
} else if ((switch_channel_test_flag(peer_channels[i], CF_ANSWERED) || } else if ((switch_channel_test_flag(peer_channels[i], CF_ANSWERED) ||
(early_ok && len == 1 && switch_channel_test_flag(peer_channels[i], CF_EARLY_MEDIA)) || (early_ok && len == 1 && switch_channel_test_flag(peer_channels[i], CF_EARLY_MEDIA)) ||
(*ring_ready && return_ring_ready && len == 1 && switch_channel_test_flag(peer_channels[i], CF_RING_READY)) (*ring_ready && return_ring_ready && len == 1 && switch_channel_test_flag(peer_channels[i], CF_RING_READY))
) )
&& !switch_channel_test_flag(peer_channels[i], CF_TAGGED) && !switch_channel_test_flag(peer_channels[i], CF_TAGGED)
) { ) {
if (!switch_strlen_zero(key)) { if (!switch_strlen_zero(key)) {
struct key_collect *collect; struct key_collect *collect;
@ -236,7 +236,7 @@ struct ringback {
typedef struct ringback ringback_t; typedef struct ringback ringback_t;
static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map) static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
{ {
ringback_t *tto = ts->user_data; ringback_t *tto = ts->user_data;
int wrote; int wrote;
@ -255,7 +255,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
{ {
switch_channel_t *caller_channel = switch_core_session_get_channel(session); switch_channel_t *caller_channel = switch_core_session_get_channel(session);
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
const char *ringback_data = NULL; const char *ringback_data = NULL;
switch_frame_t write_frame = { 0 }; switch_frame_t write_frame = { 0 };
switch_codec_t write_codec = { 0 }; switch_codec_t write_codec = { 0 };
switch_codec_t *read_codec = switch_core_session_get_read_codec(session); switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@ -267,7 +267,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
int timelimit = 60; int timelimit = 60;
const char *var = switch_channel_get_variable(caller_channel, "call_timeout"); const char *var = switch_channel_get_variable(caller_channel, "call_timeout");
switch_time_t start = 0; switch_time_t start = 0;
if ((switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) { if ((switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -287,14 +287,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) { if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) {
ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback"); ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback");
} }
if (!ringback_data) { if (!ringback_data) {
ringback_data = switch_channel_get_variable(caller_channel, "ringback"); ringback_data = switch_channel_get_variable(caller_channel, "ringback");
} }
if (read_codec && (ringback_data || if (read_codec && (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_MODE) && switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA))))) {
if (!(pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) { if (!(pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) {
if (switch_core_codec_init(&write_codec, if (switch_core_codec_init(&write_codec,
@ -302,14 +302,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
NULL, NULL,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
read_codec->implementation->microseconds_per_frame / 1000, read_codec->implementation->microseconds_per_frame / 1000,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n", "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_frame / 1000); read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
write_frame.codec = &write_codec; write_frame.codec = &write_codec;
write_frame.datalen = read_codec->implementation->bytes_per_frame; write_frame.datalen = read_codec->implementation->bytes_per_frame;
write_frame.samples = write_frame.datalen / 2; write_frame.samples = write_frame.datalen / 2;
@ -317,13 +317,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
if (ringback_data) { if (ringback_data) {
char *tmp_data = NULL; char *tmp_data = NULL;
switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0); switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
switch_buffer_set_loops(ringback.audio_buffer, -1); switch_buffer_set_loops(ringback.audio_buffer, -1);
if (switch_is_file_path(ringback_data)) { if (switch_is_file_path(ringback_data)) {
char *ext; char *ext;
if (strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR)) { if (strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR)) {
switch_core_session_set_read_codec(session, &write_codec); switch_core_session_set_read_codec(session, &write_codec);
} else { } else {
@ -342,8 +342,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
ringback_data, ringback_data,
read_codec->implementation->number_of_channels, read_codec->implementation->number_of_channels,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing File\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing File\n");
switch_safe_free(tmp_data); switch_safe_free(tmp_data);
goto done; goto done;
@ -370,9 +369,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
} }
} }
while (switch_channel_ready(peer_channel) && !(switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) { while (switch_channel_ready(peer_channel)
int diff = (int)(switch_timestamp_now() - start); && !(switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
int diff = (int) (switch_timestamp_now() - start);
if (diff > timelimit) { if (diff > timelimit) {
status = SWITCH_STATUS_TIMEOUT; status = SWITCH_STATUS_TIMEOUT;
goto done; goto done;
@ -390,7 +390,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
break; break;
} }
if (read_frame && !pass) { if (read_frame && !pass) {
if (ringback.fh) { if (ringback.fh) {
switch_size_t mlen, olen; switch_size_t mlen, olen;
@ -431,8 +431,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
} }
} }
done: done:
if (ringback.fh) { if (ringback.fh) {
switch_core_file_close(ringback.fh); switch_core_file_close(ringback.fh);
ringback.fh = NULL; ringback.fh = NULL;
@ -461,10 +461,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
const char *bridgeto, const char *bridgeto,
uint32_t timelimit_sec, uint32_t timelimit_sec,
const switch_state_handler_table_t *table, const switch_state_handler_table_t *table,
const char *cid_name_override, const char *cid_name_override,
const char *cid_num_override, const char *cid_num_override,
switch_caller_profile_t *caller_profile_override, switch_caller_profile_t *caller_profile_override, switch_originate_flag_t flags)
switch_originate_flag_t flags)
{ {
switch_originate_flag_t myflags = SOF_NONE; switch_originate_flag_t myflags = SOF_NONE;
char *pipe_names[MAX_PEERS] = { 0 }; char *pipe_names[MAX_PEERS] = { 0 };
@ -516,10 +515,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
while (data && *data && *data == ' ') { while (data && *data && *data == ' ') {
data++; data++;
} }
if (*data == '{') { if (*data == '{') {
char *e = switch_find_end_paren(data, '{', '}'); char *e = switch_find_end_paren(data, '{', '}');
if (e) { if (e) {
vars = data + 1; vars = data + 1;
*e++ = '\0'; *e++ = '\0';
@ -558,47 +557,47 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if ((hi = switch_channel_variable_first(caller_channel))) { if ((hi = switch_channel_variable_first(caller_channel))) {
for (; hi; hi = hi->next) { for (; hi; hi = hi->next) {
int ok = 0; int ok = 0;
if (!strcasecmp((char *)hi->name, "group_confirm_key")) { if (!strcasecmp((char *) hi->name, "group_confirm_key")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "group_confirm_file")) { } else if (!strcasecmp((char *) hi->name, "group_confirm_file")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "forked_dial")) { } else if (!strcasecmp((char *) hi->name, "forked_dial")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "fail_on_single_reject")) { } else if (!strcasecmp((char *) hi->name, "fail_on_single_reject")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "ignore_early_media")) { } else if (!strcasecmp((char *) hi->name, "ignore_early_media")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "return_ring_ready")) { } else if (!strcasecmp((char *) hi->name, "return_ring_ready")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "originate_retries")) { } else if (!strcasecmp((char *) hi->name, "originate_retries")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "originate_timeout")) { } else if (!strcasecmp((char *) hi->name, "originate_timeout")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "originate_retry_sleep_ms")) { } else if (!strcasecmp((char *) hi->name, "originate_retry_sleep_ms")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "origination_caller_id_name")) { } else if (!strcasecmp((char *) hi->name, "origination_caller_id_name")) {
ok = 1; ok = 1;
} else if (!strcasecmp((char *)hi->name, "origination_caller_id_number")) { } else if (!strcasecmp((char *) hi->name, "origination_caller_id_number")) {
ok = 1; ok = 1;
} }
if (ok) { if (ok) {
switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (char *)hi->name, "%s", (char *) hi->value); switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (char *) hi->name, "%s", (char *) hi->value);
} }
} }
switch_channel_variable_last(caller_channel); switch_channel_variable_last(caller_channel);
} }
/* /*
if ((hi = switch_channel_variable_first(caller_channel))) { if ((hi = switch_channel_variable_first(caller_channel))) {
for (; hi; hi = switch_hash_next(hi)) { for (; hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, &vvar, NULL, &vval); switch_hash_this(hi, &vvar, NULL, &vval);
if (vvar && vval) { if (vvar && vval) {
switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, "%s", (char *) vval); switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, "%s", (char *) vval);
} }
} }
switch_channel_variable_last(caller_channel); switch_channel_variable_last(caller_channel);
} }
*/ */
} }
if (vars) { /* Parse parameters specified from the dialstring */ if (vars) { /* Parse parameters specified from the dialstring */
@ -609,7 +608,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
for (x = 0; x < var_count; x++) { for (x = 0; x < var_count; x++) {
char *inner_var_array[2] = { 0 }; char *inner_var_array[2] = { 0 };
int inner_var_count; int inner_var_count;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"variable string %d = [%s]\n", x, var_array[x]); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "variable string %d = [%s]\n", x, var_array[x]);
if ((inner_var_count = if ((inner_var_count =
switch_separate_string(var_array[x], '=', inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) { switch_separate_string(var_array[x], '=', inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) {
@ -624,12 +623,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) { if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) {
ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback"); ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback");
} }
if (!ringback_data) { if (!ringback_data) {
ringback_data = switch_channel_get_variable(caller_channel, "ringback"); ringback_data = switch_channel_get_variable(caller_channel, "ringback");
} }
switch_channel_set_variable(caller_channel, "originate_disposition", "failure"); switch_channel_set_variable(caller_channel, "originate_disposition", "failure");
} }
@ -736,7 +735,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Only calling the first element in the list in this mode.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Only calling the first element in the list in this mode.\n");
and_argc = 1; and_argc = 1;
} }
for (i = 0; i < and_argc; i++) { for (i = 0; i < and_argc; i++) {
char *vdata; char *vdata;
char *e = NULL; char *e = NULL;
@ -748,7 +747,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
vdata = chan_type; vdata = chan_type;
e = switch_find_end_paren(vdata, '[', ']'); e = switch_find_end_paren(vdata, '[', ']');
if (e) { if (e) {
vdata++; vdata++;
*e++ = '\0'; *e++ = '\0';
@ -756,7 +755,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} else { } else {
vdata = NULL; vdata = NULL;
} }
if ((chan_data = strchr(chan_type, '/')) != 0) { if ((chan_data = strchr(chan_type, '/')) != 0) {
*chan_data = '\0'; *chan_data = '\0';
chan_data++; chan_data++;
@ -801,18 +800,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
new_profile = switch_caller_profile_new(pool, new_profile = switch_caller_profile_new(pool,
NULL, NULL,
NULL, NULL,
cid_name_override, cid_name_override, cid_num_override, NULL, NULL, NULL, NULL, __FILE__, NULL, chan_data);
cid_num_override,
NULL, NULL, NULL, NULL, __FILE__, NULL,
chan_data);
} }
} }
caller_profiles[i] = NULL; caller_profiles[i] = NULL;
peer_channels[i] = NULL; peer_channels[i] = NULL;
peer_sessions[i] = NULL; peer_sessions[i] = NULL;
new_session = NULL; new_session = NULL;
if (and_argc > 1 || or_argc > 1) { if (and_argc > 1 || or_argc > 1) {
myflags |= SOF_FORKED_DIAL; myflags |= SOF_FORKED_DIAL;
} else if (var_event) { } else if (var_event) {
@ -821,9 +817,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
myflags |= SOF_FORKED_DIAL; myflags |= SOF_FORKED_DIAL;
} }
} }
if ((reason = switch_core_session_outgoing_channel(session, var_event, chan_type, new_profile, &new_session, &pool, myflags)) != SWITCH_CAUSE_SUCCESS) { if ((reason =
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel of type [%s] cause: [%s]\n", switch_core_session_outgoing_channel(session, var_event, chan_type, new_profile, &new_session, &pool,
chan_type, switch_channel_cause2str(reason)); myflags)) != SWITCH_CAUSE_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel of type [%s] cause: [%s]\n", chan_type,
switch_channel_cause2str(reason));
if (pool) { if (pool) {
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
} }
@ -837,7 +835,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
peer_sessions[i] = new_session; peer_sessions[i] = new_session;
peer_channels[i] = switch_core_session_get_channel(new_session); peer_channels[i] = switch_core_session_get_channel(new_session);
switch_channel_set_flag(peer_channels[i], CF_ORIGINATING); switch_channel_set_flag(peer_channels[i], CF_ORIGINATING);
if (vdata) { if (vdata) {
char *var_array[1024] = { 0 }; char *var_array[1024] = { 0 };
int var_count = 0; int var_count = 0;
@ -847,15 +845,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
char *inner_var_array[2] = { 0 }; char *inner_var_array[2] = { 0 };
int inner_var_count; int inner_var_count;
if ((inner_var_count = if ((inner_var_count =
switch_separate_string(var_array[x], '=', switch_separate_string(var_array[x], '=',
inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) { inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) {
switch_channel_set_variable(peer_channels[i], inner_var_array[0], inner_var_array[1]); switch_channel_set_variable(peer_channels[i], inner_var_array[0], inner_var_array[1]);
} }
} }
} }
} }
if (var_event) { if (var_event) {
switch_event_t *event; switch_event_t *event;
switch_event_header_t *header; switch_event_header_t *header;
@ -883,15 +881,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
*cause = SWITCH_CAUSE_SUCCESS; *cause = SWITCH_CAUSE_SUCCESS;
goto outer_for; goto outer_for;
} }
if (!switch_core_session_running(peer_sessions[i])) { if (!switch_core_session_running(peer_sessions[i])) {
//if (!(flags & SOF_NOBLOCK)) { //if (!(flags & SOF_NOBLOCK)) {
//switch_channel_set_state(peer_channels[i], CS_ROUTING); //switch_channel_set_state(peer_channels[i], CS_ROUTING);
//} //}
//} else { //} else {
switch_core_session_thread_launch(peer_sessions[i]); switch_core_session_thread_launch(peer_sessions[i]);
} }
} }
switch_timestamp(&start); switch_timestamp(&start);
@ -928,7 +926,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_yield(10000); switch_yield(10000);
} }
if (valid_channels == 0) { if (valid_channels == 0) {
status = SWITCH_STATUS_GENERR; status = SWITCH_STATUS_GENERR;
goto done; goto done;
@ -936,7 +934,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
endfor1: endfor1:
if (ringback_data && !switch_channel_test_flag(caller_channel, CF_ANSWERED) if (ringback_data && !switch_channel_test_flag(caller_channel, CF_ANSWERED)
&& !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) { && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
@ -947,7 +945,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
if (session && (read_codec = switch_core_session_get_read_codec(session)) && if (session && (read_codec = switch_core_session_get_read_codec(session)) &&
(ringback_data || (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_MODE) && switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA))))) {
if (!(pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) { if (!(pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) {
@ -956,13 +954,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
NULL, NULL,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
read_codec->implementation->microseconds_per_frame / 1000, read_codec->implementation->microseconds_per_frame / 1000,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n", "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_frame / 1000); read_codec->implementation->actual_samples_per_second,
read_codec->implementation->microseconds_per_frame / 1000);
write_frame.codec = &write_codec; write_frame.codec = &write_codec;
write_frame.datalen = read_codec->implementation->bytes_per_frame; write_frame.datalen = read_codec->implementation->bytes_per_frame;
write_frame.samples = write_frame.datalen / 2; write_frame.samples = write_frame.datalen / 2;
@ -973,10 +972,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0); switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
switch_buffer_set_loops(ringback.audio_buffer, -1); switch_buffer_set_loops(ringback.audio_buffer, -1);
if (switch_is_file_path(ringback_data)) { if (switch_is_file_path(ringback_data)) {
char *ext; char *ext;
if (strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR)) { if (strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR)) {
switch_core_session_set_read_codec(session, &write_codec); switch_core_session_set_read_codec(session, &write_codec);
} else { } else {
@ -995,8 +994,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
ringback_data, ringback_data,
read_codec->implementation->number_of_channels, read_codec->implementation->number_of_channels,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing File\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Playing File\n");
switch_safe_free(tmp_data); switch_safe_free(tmp_data);
goto notready; goto notready;
@ -1038,7 +1036,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_channel_ring_ready(caller_channel); switch_channel_ring_ready(caller_channel);
sent_ring = 1; sent_ring = 1;
} }
// When the AND operator is being used, and fail_on_single_reject is set, a hangup indicates that the call should fail. // When the AND operator is being used, and fail_on_single_reject is set, a hangup indicates that the call should fail.
if ((to = (uint8_t) ((switch_timestamp(NULL) - start) >= (time_t) timelimit_sec)) if ((to = (uint8_t) ((switch_timestamp(NULL) - start) >= (time_t) timelimit_sec))
|| (fail_on_single_reject && hups)) { || (fail_on_single_reject && hups)) {
@ -1059,23 +1056,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
} }
/* read from the channel while we wait if the audio is up on it */ /* read from the channel while we wait if the audio is up on it */
if (session && if (session &&
!switch_channel_test_flag(caller_channel, CF_PROXY_MODE) && !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) &&
(ringback_data || (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)))) { (ringback_data
|| (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)))) {
switch_status_t tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); switch_status_t tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(tstatus)) { if (!SWITCH_READ_ACCEPTABLE(tstatus)) {
break; break;
} }
if (ring_ready && read_frame && !pass) { if (ring_ready && read_frame && !pass) {
if (ringback.fh) { if (ringback.fh) {
switch_size_t mlen, olen; switch_size_t mlen, olen;
unsigned int pos = 0; unsigned int pos = 0;
if (ringback.asis) { if (ringback.asis) {
mlen = write_frame.codec->implementation->encoded_bytes_per_frame; mlen = write_frame.codec->implementation->encoded_bytes_per_frame;
@ -1103,7 +1101,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
break; break;
} }
} }
if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
break; break;
} }
@ -1121,19 +1119,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
idx = IDX_CANCEL; idx = IDX_CANCEL;
} }
if (session && (ringback_data || !(switch_channel_test_flag(caller_channel, CF_PROXY_MODE) && if (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(session, SWITCH_FALSE); switch_core_session_reset(session, SWITCH_FALSE);
} }
for (i = 0; i < and_argc; i++) { for (i = 0; i < and_argc; i++) {
if (!peer_channels[i]) { if (!peer_channels[i]) {
continue; continue;
} }
if (switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || if (switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || switch_channel_test_flag(peer_channels[i], CF_BRIDGED) ||
switch_channel_get_state(peer_channels[i]) == CS_RESET || switch_channel_get_state(peer_channels[i]) == CS_RESET || !switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
!switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
) { ) {
continue; continue;
} }
@ -1194,8 +1191,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
} }
if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || if (switch_channel_test_flag(peer_channel, CF_ANSWERED) ||
(early_ok && switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) || (early_ok && switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) ||
(return_ring_ready && switch_channel_test_flag(peer_channel, CF_RING_READY)) (return_ring_ready && switch_channel_test_flag(peer_channel, CF_RING_READY))
) { ) {
*bleg = peer_session; *bleg = peer_session;
@ -1275,7 +1272,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
switch_core_codec_destroy(&write_codec); switch_core_codec_destroy(&write_codec);
} }
for (i = 0; i < and_argc; i++) { for (i = 0; i < and_argc; i++) {
if (!peer_channels[i]) { if (!peer_channels[i]) {
@ -1287,7 +1284,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
switch_core_session_rwunlock(peer_sessions[i]); switch_core_session_rwunlock(peer_sessions[i]);
} }
if (status == SWITCH_STATUS_SUCCESS) { if (status == SWITCH_STATUS_SUCCESS) {
goto outer_for; goto outer_for;
} }
@ -1301,7 +1298,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
*bleg = NULL; *bleg = NULL;
} }
if (var_event) { if (var_event) {
switch_event_destroy(&var_event); switch_event_destroy(&var_event);
} }

View File

@ -121,14 +121,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
switch_event_create(&hint_data, SWITCH_EVENT_MESSAGE); switch_event_create(&hint_data, SWITCH_EVENT_MESSAGE);
switch_assert(hint_data); switch_assert(hint_data);
switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "macro_name", macro_name); switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "macro_name", macro_name);
switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "lang", chan_lang); switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "lang", chan_lang);
if (data) { if (data) {
switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "data", data); switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "data", data);
} else { } else {
data = ""; data = "";
} }
switch_channel_event_set_data(channel, hint_data); switch_channel_event_set_data(channel, hint_data);
if (switch_xml_locate("phrases", NULL, NULL, NULL, &xml, &cfg, hint_data) != SWITCH_STATUS_SUCCESS) { if (switch_xml_locate("phrases", NULL, NULL, NULL, &xml, &cfg, hint_data) != SWITCH_STATUS_SUCCESS) {
@ -170,7 +170,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
if (!(tts_engine = (char *) switch_xml_attr(language, "tts-engine"))) { if (!(tts_engine = (char *) switch_xml_attr(language, "tts-engine"))) {
tts_engine = (char *) switch_xml_attr(language, "tts_engine"); tts_engine = (char *) switch_xml_attr(language, "tts_engine");
} }
if (!(tts_voice = (char *) switch_xml_attr(language, "tts-voice"))) { if (!(tts_voice = (char *) switch_xml_attr(language, "tts-voice"))) {
tts_voice = (char *) switch_xml_attr(language, "tts_voice"); tts_voice = (char *) switch_xml_attr(language, "tts_voice");
} }
@ -210,7 +210,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
while (input && !done) { while (input && !done) {
char *pattern = (char *) switch_xml_attr(input, "pattern"); char *pattern = (char *) switch_xml_attr(input, "pattern");
const char *do_break = switch_xml_attr_soft(input, "break_on_match"); const char *do_break = switch_xml_attr_soft(input, "break_on_match");
if (pattern) { if (pattern) {
switch_regex_t *re = NULL; switch_regex_t *re = NULL;
int proceed = 0, ovector[30]; int proceed = 0, ovector[30];
@ -221,7 +221,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
switch_xml_t match = NULL; switch_xml_t match = NULL;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
if ((proceed = switch_regex_perform(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { if ((proceed = switch_regex_perform(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
match = switch_xml_child(input, "match"); match = switch_xml_child(input, "match");
} else { } else {
@ -233,7 +233,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
for (action = switch_xml_child(match, "action"); action && status == SWITCH_STATUS_SUCCESS; action = action->next) { for (action = switch_xml_child(match, "action"); action && status == SWITCH_STATUS_SUCCESS; action = action->next) {
char *adata = (char *) switch_xml_attr_soft(action, "data"); char *adata = (char *) switch_xml_attr_soft(action, "data");
char *func = (char *) switch_xml_attr_soft(action, "function"); char *func = (char *) switch_xml_attr_soft(action, "function");
if (strchr(pattern, '(') && strchr(adata, '$')) { if (strchr(pattern, '(') && strchr(adata, '$')) {
len = (uint32_t) (strlen(data) + strlen(adata) + 10); len = (uint32_t) (strlen(data) + strlen(adata) + 10);
if (!(substituted = malloc(len))) { if (!(substituted = malloc(len))) {
@ -278,7 +278,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
cmd_args = switch_separate_paren_args(cmd); cmd_args = switch_separate_paren_args(cmd);
if (!cmd_args ) { if (!cmd_args) {
cmd_args = ""; cmd_args = "";
} }
@ -293,14 +293,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
char *say_type = (char *) switch_xml_attr_soft(action, "type"); char *say_type = (char *) switch_xml_attr_soft(action, "type");
char *say_method = (char *) switch_xml_attr_soft(action, "method"); char *say_method = (char *) switch_xml_attr_soft(action, "method");
status = si->say_function(session, odata, switch_ivr_get_say_type_by_name(say_type), switch_ivr_get_say_method_by_name(say_method), args); status =
si->say_function(session, odata, switch_ivr_get_say_type_by_name(say_type), switch_ivr_get_say_method_by_name(say_method),
args);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid SAY Interface [%s]!\n", module_name);
} }
} else if (!strcasecmp(func, "speak-text")) { } else if (!strcasecmp(func, "speak-text")) {
const char *my_tts_engine = switch_xml_attr(action, "tts-engine"); const char *my_tts_engine = switch_xml_attr(action, "tts-engine");
const char *my_tts_voice = switch_xml_attr(action, "tts-voice"); const char *my_tts_voice = switch_xml_attr(action, "tts-voice");
if (!my_tts_engine) { if (!my_tts_engine) {
my_tts_engine = tts_engine; my_tts_engine = tts_engine;
} }
@ -321,11 +323,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
switch_safe_free(expanded); switch_safe_free(expanded);
switch_safe_free(substituted); switch_safe_free(substituted);
if (match && do_break && switch_true(do_break)) { if (match && do_break && switch_true(do_break)) {
break; break;
} }
} }
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
@ -337,7 +339,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
} }
done: done:
if (hint_data) { if (hint_data) {
switch_event_destroy(&hint_data); switch_event_destroy(&hint_data);
} }
@ -360,7 +362,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
switch_file_handle_t *fh, const char *file, switch_input_args_t *args, uint32_t limit) switch_file_handle_t *fh, const char *file, switch_input_args_t *args, uint32_t limit)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
switch_file_handle_t lfh = { 0 }; switch_file_handle_t lfh = { 0 };
switch_frame_t *read_frame; switch_frame_t *read_frame;
switch_codec_t codec, *read_codec = switch_core_session_get_read_codec(session); switch_codec_t codec, *read_codec = switch_core_session_get_read_codec(session);
@ -463,9 +465,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
org_silence_hits = fh->silence_hits; org_silence_hits = fh->silence_hits;
} }
for(;;) { for (;;) {
switch_size_t len; switch_size_t len;
if (!switch_channel_ready(channel)) { if (!switch_channel_ready(channel)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
break; break;
@ -476,7 +478,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
status = SWITCH_STATUS_BREAK; status = SWITCH_STATUS_BREAK;
break; break;
} }
if (switch_core_session_private_event_count(session)) { if (switch_core_session_private_event_count(session)) {
switch_ivr_parse_all_events(session); switch_ivr_parse_all_events(session);
} }
@ -497,9 +499,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
} }
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
if (args->input_callback) { if (args->input_callback) {
status = args->input_callback(session, (void *)&dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
} else { } else {
switch_copy_string((char *) args->buf, (void *)&dtmf, args->buflen); switch_copy_string((char *) args->buf, (void *) &dtmf, args->buflen);
status = SWITCH_STATUS_BREAK; status = SWITCH_STATUS_BREAK;
} }
} }
@ -535,7 +537,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
uint32_t score, count = 0, j = 0; uint32_t score, count = 0, j = 0;
double energy = 0; double energy = 0;
int divisor = 0; int divisor = 0;
for (count = 0; count < samples; count++) { for (count = 0; count < samples; count++) {
energy += abs(fdata[j]); energy += abs(fdata[j]);
j += read_codec->implementation->number_of_channels; j += read_codec->implementation->number_of_channels;
@ -544,7 +546,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
if (!(divisor = read_codec->implementation->actual_samples_per_second / 8000)) { if (!(divisor = read_codec->implementation->actual_samples_per_second / 8000)) {
divisor = 1; divisor = 1;
} }
score = (uint32_t) (energy / (samples / divisor)); score = (uint32_t) (energy / (samples / divisor));
if (score < fh->thresh) { if (score < fh->thresh) {
if (!--fh->silence_hits) { if (!--fh->silence_hits) {
@ -558,7 +560,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
if (!switch_test_flag(fh, SWITCH_FILE_PAUSE) && !switch_test_flag(read_frame, SFF_CNG)) { if (!switch_test_flag(fh, SWITCH_FILE_PAUSE) && !switch_test_flag(read_frame, SFF_CNG)) {
int16_t *data = read_frame->data; int16_t *data = read_frame->data;
len = (switch_size_t) read_frame->datalen / 2; len = (switch_size_t) read_frame->datalen / 2;
if (switch_core_file_write(fh, data, &len) != SWITCH_STATUS_SUCCESS) { if (switch_core_file_write(fh, data, &len) != SWITCH_STATUS_SUCCESS) {
break; break;
} }
@ -571,7 +573,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
return status; return status;
} }
static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map) static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
{ {
switch_buffer_t *audio_buffer = ts->user_data; switch_buffer_t *audio_buffer = ts->user_data;
int wrote; int wrote;
@ -589,7 +591,7 @@ static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_ma
SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args) SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args)
{ {
teletone_generation_session_t ts; teletone_generation_session_t ts;
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
switch_buffer_t *audio_buffer; switch_buffer_t *audio_buffer;
switch_frame_t *read_frame = NULL; switch_frame_t *read_frame = NULL;
switch_codec_t *read_codec = NULL, write_codec = { 0 }; switch_codec_t *read_codec = NULL, write_codec = { 0 };
@ -599,13 +601,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
read_codec = switch_core_session_get_read_codec(session); read_codec = switch_core_session_get_read_codec(session);
if (switch_core_codec_init(&write_codec, if (switch_core_codec_init(&write_codec,
"L16", "L16",
NULL, NULL,
read_codec->implementation->actual_samples_per_second, read_codec->implementation->actual_samples_per_second,
read_codec->implementation->microseconds_per_frame / 1000, read_codec->implementation->microseconds_per_frame / 1000,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -624,14 +626,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
switch_buffer_set_loops(audio_buffer, loops); switch_buffer_set_loops(audio_buffer, loops);
} }
for(;;) { for (;;) {
int done = 0; int done = 0;
switch_status_t status; switch_status_t status;
if (!switch_channel_ready(channel)) { if (!switch_channel_ready(channel)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
break; break;
} }
if (switch_channel_test_flag(channel, CF_BREAK)) { if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK); switch_channel_clear_flag(channel, CF_BREAK);
@ -658,9 +660,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
} }
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
if (args->input_callback) { if (args->input_callback) {
status = args->input_callback(session, (void *)&dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
} else { } else {
*((char *)args->buf) = dtmf.digit; *((char *) args->buf) = dtmf.digit;
status = SWITCH_STATUS_BREAK; status = SWITCH_STATUS_BREAK;
} }
} }
@ -680,13 +682,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *sessi
} }
} }
if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(audio_buffer, write_frame.data, if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(audio_buffer, write_frame.data, read_codec->implementation->bytes_per_frame)) <= 0) {
read_codec->implementation->bytes_per_frame)) <= 0) {
break; break;
} }
write_frame.samples = write_frame.datalen / 2; write_frame.samples = write_frame.datalen / 2;
if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
break; break;
} }
@ -708,7 +709,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
int16_t *abuf = NULL; int16_t *abuf = NULL;
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
uint32_t interval = 0, samples = 0, framelen, sample_start = 0; uint32_t interval = 0, samples = 0, framelen, sample_start = 0;
uint32_t ilen = 0; uint32_t ilen = 0;
switch_size_t olen = 0, llen = 0; switch_size_t olen = 0, llen = 0;
@ -750,7 +751,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
const char *lang = switch_channel_get_variable(channel, "language"); const char *lang = switch_channel_get_variable(channel, "language");
alt = file + 7; alt = file + 7;
dup = switch_core_session_strdup(session, alt); dup = switch_core_session_strdup(session, alt);
if (dup) { if (dup) {
if ((arg = strchr(dup, ':'))) { if ((arg = strchr(dup, ':'))) {
*arg++ = '\0'; *arg++ = '\0';
@ -763,7 +764,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
} else if (!strncasecmp(file, "say:", 4)) { } else if (!strncasecmp(file, "say:", 4)) {
char *engine = NULL, *voice = NULL, *text = NULL; char *engine = NULL, *voice = NULL, *text = NULL;
alt = file + 4; alt = file + 4;
dup = switch_core_session_strdup(session, alt); dup = switch_core_session_strdup(session, alt);
engine = dup; engine = dup;
if (!switch_strlen_zero(engine)) { if (!switch_strlen_zero(engine)) {
@ -779,8 +780,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
return switch_ivr_speak_text(session, engine, voice, text, args); return switch_ivr_speak_text(session, engine, voice, text, args);
} else if (!switch_strlen_zero(engine) && !(voice && text)) { } else if (!switch_strlen_zero(engine) && !(voice && text)) {
text = engine; text = engine;
engine = (char *)switch_channel_get_variable(channel, "tts_engine"); engine = (char *) switch_channel_get_variable(channel, "tts_engine");
voice = (char *)switch_channel_get_variable(channel, "tts_voice"); voice = (char *) switch_channel_get_variable(channel, "tts_voice");
if (engine && text) { if (engine && text) {
return switch_ivr_speak_text(session, engine, voice, text, args); return switch_ivr_speak_text(session, engine, voice, text, args);
} }
@ -789,7 +790,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
} }
} }
if (!prefix) { if (!prefix) {
@ -946,15 +947,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
ilen = samples; ilen = samples;
for(;;) { for (;;) {
int done = 0; int done = 0;
int do_speed = 1; int do_speed = 1;
int last_speed = -1; int last_speed = -1;
if (!switch_channel_ready(channel)) { if (!switch_channel_ready(channel)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
break; break;
} }
if (switch_channel_test_flag(channel, CF_BREAK)) { if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK); switch_channel_clear_flag(channel, CF_BREAK);
@ -979,9 +980,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
} }
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
if (args->input_callback) { if (args->input_callback) {
status = args->input_callback(session, (void *)&dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
} else { } else {
*((char *)args->buf) = dtmf.digit; *((char *) args->buf) = dtmf.digit;
status = SWITCH_STATUS_BREAK; status = SWITCH_STATUS_BREAK;
} }
} }
@ -1062,7 +1063,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
supplement = 1; supplement = 1;
} }
newlen = (fh->speed > 0) ? olen - supplement : olen + supplement; newlen = (fh->speed > 0) ? olen - supplement : olen + supplement;
step = (fh->speed > 0) ? (newlen / supplement) : (olen / supplement); step = (fh->speed > 0) ? (newlen / supplement) : (olen / supplement);
if (!fh->sp_audio_buffer) { if (!fh->sp_audio_buffer) {
@ -1099,10 +1100,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
olen = llen; olen = llen;
} }
write_frame.samples = (uint32_t)olen; write_frame.samples = (uint32_t) olen;
if (asis) { if (asis) {
write_frame.datalen = (uint32_t)olen; write_frame.datalen = (uint32_t) olen;
} else { } else {
write_frame.datalen = write_frame.samples * 2; write_frame.datalen = write_frame.samples * 2;
} }
@ -1125,7 +1126,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
fh->offset_pos += write_frame.samples / 2; fh->offset_pos += write_frame.samples / 2;
status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
if (status == SWITCH_STATUS_MORE_DATA) { if (status == SWITCH_STATUS_MORE_DATA) {
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
continue; continue;
@ -1150,7 +1151,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
} }
tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(tstatus)) { if (!SWITCH_READ_ACCEPTABLE(tstatus)) {
break; break;
} }
@ -1171,7 +1172,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "done playing file\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "done playing file\n");
switch_core_file_seek(fh, &fh->last_pos, 0, SEEK_CUR); switch_core_file_seek(fh, &fh->last_pos, 0, SEEK_CUR);
switch_core_file_close(fh); switch_core_file_close(fh);
switch_buffer_destroy(&fh->audio_buffer); switch_buffer_destroy(&fh->audio_buffer);
switch_buffer_destroy(&fh->sp_audio_buffer); switch_buffer_destroy(&fh->sp_audio_buffer);
@ -1185,7 +1186,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
} }
end: end:
switch_safe_free(abuf); switch_safe_free(abuf);
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
@ -1197,10 +1198,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
uint32_t max_digits, uint32_t max_digits,
const char *prompt_audio_file, const char *prompt_audio_file,
const char *var_name, const char *var_name,
char *digit_buffer, char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators)
switch_size_t digit_buffer_length,
uint32_t timeout,
const char *valid_terminators)
{ {
switch_channel_t *channel; switch_channel_t *channel;
switch_input_args_t args = { 0 }; switch_input_args_t args = { 0 };
@ -1221,34 +1219,34 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session,
memset(digit_buffer, 0, digit_buffer_length); memset(digit_buffer, 0, digit_buffer_length);
args.buf = digit_buffer; args.buf = digit_buffer;
args.buflen = (uint32_t)digit_buffer_length; args.buflen = (uint32_t) digit_buffer_length;
if (!switch_strlen_zero(prompt_audio_file) && strcasecmp(prompt_audio_file, "silence")) { if (!switch_strlen_zero(prompt_audio_file) && strcasecmp(prompt_audio_file, "silence")) {
status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args); status = switch_ivr_play_file(session, NULL, prompt_audio_file, &args);
} }
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
goto end; goto end;
} }
len = strlen(digit_buffer); len = strlen(digit_buffer);
if (len < min_digits && len < max_digits) { if (len < min_digits && len < max_digits) {
args.buf = digit_buffer + len; args.buf = digit_buffer + len;
args.buflen = (uint32_t)(digit_buffer_length - len); args.buflen = (uint32_t) (digit_buffer_length - len);
status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0); status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
} }
end: end:
if (var_name && !switch_strlen_zero(digit_buffer)) { if (var_name && !switch_strlen_zero(digit_buffer)) {
switch_channel_set_variable(channel, var_name, digit_buffer); switch_channel_set_variable(channel, var_name, digit_buffer);
} }
return status; return status;
} }
@ -1357,7 +1355,7 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
} }
} }
done: done:
//if we got here, we got no digits or lost the channel //if we got here, we got no digits or lost the channel
digit_buffer = "\0"; digit_buffer = "\0";
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -1370,7 +1368,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
short abuf[960]; short abuf[960];
switch_dtmf_t dtmf = {0}; switch_dtmf_t dtmf = { 0 };
uint32_t len = 0; uint32_t len = 0;
switch_size_t ilen = 0; switch_size_t ilen = 0;
switch_frame_t write_frame = { 0 }; switch_frame_t write_frame = { 0 };
@ -1395,9 +1393,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
write_frame.buflen = sizeof(abuf); write_frame.buflen = sizeof(abuf);
len = sh->samples * 2; len = sh->samples * 2;
flags = 0; flags = 0;
if (!(star = switch_channel_get_variable(channel, "star_replace"))) { if (!(star = switch_channel_get_variable(channel, "star_replace"))) {
star = "star"; star = "star";
} }
@ -1408,7 +1406,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
poundlen = strlen(pound); poundlen = strlen(pound);
for(p = text; p && *p; p++) { for (p = text; p && *p; p++) {
if (*p == '*') { if (*p == '*') {
extra += starlen; extra += starlen;
} else if (*p == '#') { } else if (*p == '#') {
@ -1429,14 +1427,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
if (*p == '*') { if (*p == '*') {
strncat(tp, star, starlen); strncat(tp, star, starlen);
tp += starlen; tp += starlen;
} else if (*p == '#') { } else if (*p == '#') {
strncat(tp, pound, poundlen); strncat(tp, pound, poundlen);
tp += poundlen; tp += poundlen;
} else { } else {
*tp++ = *p; *tp++ = *p;
} }
} }
text = tmp; text = tmp;
} }
@ -1466,13 +1464,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text_handle(switch_core_session
} }
ilen = len; ilen = len;
for(;;) { for (;;) {
switch_event_t *event; switch_event_t *event;
if (!switch_channel_ready(channel)) { if (!switch_channel_ready(channel)) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
break; break;
} }
if (switch_channel_test_flag(channel, CF_BREAK)) { if (switch_channel_test_flag(channel, CF_BREAK)) {
switch_channel_clear_flag(channel, CF_BREAK); switch_channel_clear_flag(channel, CF_BREAK);
@ -1628,7 +1626,7 @@ struct cached_speech_handle {
}; };
typedef struct cached_speech_handle cached_speech_handle_t; typedef struct cached_speech_handle cached_speech_handle_t;
SWITCH_DECLARE(void) switch_ivr_clear_speech_cache(switch_core_session_t *session) SWITCH_DECLARE(void) switch_ivr_clear_speech_cache(switch_core_session_t *session)
{ {
cached_speech_handle_t *cache_obj = NULL; cached_speech_handle_t *cache_obj = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
@ -1698,13 +1696,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
read_codec = switch_core_session_get_read_codec(session); read_codec = switch_core_session_get_read_codec(session);
rate = read_codec->implementation->actual_samples_per_second; rate = read_codec->implementation->actual_samples_per_second;
interval = read_codec->implementation->microseconds_per_frame / 1000; interval = read_codec->implementation->microseconds_per_frame / 1000;
if (need_create) { if (need_create) {
memset(sh, 0, sizeof(*sh)); memset(sh, 0, sizeof(*sh));
if (switch_core_speech_open(sh, tts_name, voice_name, (uint32_t) rate, interval, if (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_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n");
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
@ -1727,7 +1725,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
if (need_create) { if (need_create) {
if (switch_core_codec_init(codec, if (switch_core_codec_init(codec,
codec_name, codec_name,
NULL, (int) rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) { NULL, (int) rate, interval, 1, 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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz 1 channel %dms\n", codec_name, rate, interval); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz 1 channel %dms\n", codec_name, rate, interval);
@ -1740,7 +1739,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
} }
write_frame.codec = codec; write_frame.codec = codec;
if (timer_name) { if (timer_name) {
@ -1762,7 +1761,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses
switch_core_service_session(session, &thread_session, 0); switch_core_service_session(session, &thread_session, 0);
} }
status = switch_ivr_speak_text_handle(session, sh, write_frame.codec, timer_name ? timer : NULL, text, args); status = switch_ivr_speak_text_handle(session, sh, write_frame.codec, timer_name ? timer : NULL, text, args);
flags = 0; flags = 0;
@ -1790,8 +1789,8 @@ static switch_status_t hold_on_dtmf(switch_core_session_t *session, void *input,
switch (itype) { switch (itype) {
case SWITCH_INPUT_TYPE_DTMF: case SWITCH_INPUT_TYPE_DTMF:
{ {
switch_dtmf_t *dtmf = (switch_dtmf_t *) input; switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
if (dtmf->digit == *stop_key) { if (dtmf->digit == *stop_key) {
return SWITCH_STATUS_BREAK; return SWITCH_STATUS_BREAK;
} }
@ -1813,8 +1812,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
switch_input_args_t args = { 0 }; switch_input_args_t args = { 0 };
args.input_callback = hold_on_dtmf; args.input_callback = hold_on_dtmf;
args.buf = (void *) unhold_key; args.buf = (void *) unhold_key;
args.buflen = (uint32_t)strlen(unhold_key); args.buflen = (uint32_t) strlen(unhold_key);
switch_assert(session != NULL); switch_assert(session != NULL);
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL); switch_assert(channel != NULL);
@ -1825,7 +1824,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
other_channel = switch_core_session_get_channel(other_session); other_channel = switch_core_session_get_channel(other_session);
if (moh_b) { if (moh_b) {
moh = moh_b; moh = moh_b;
} else { } else {
moh = switch_channel_get_variable(other_channel, "hold_music"); moh = switch_channel_get_variable(other_channel, "hold_music");
} }
@ -1834,18 +1833,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
switch_ivr_broadcast(other_uuid, moh, SMF_ECHO_ALEG | SMF_LOOP); switch_ivr_broadcast(other_uuid, moh, SMF_ECHO_ALEG | SMF_LOOP);
moh_br++; moh_br++;
} }
if (moh_a) { if (moh_a) {
moh = moh_a; moh = moh_a;
} else { } else {
moh = switch_channel_get_variable(channel, "hold_music"); moh = switch_channel_get_variable(channel, "hold_music");
} }
if (!switch_strlen_zero(moh) && strcasecmp(moh, "silence")) { if (!switch_strlen_zero(moh) && strcasecmp(moh, "silence")) {
switch_ivr_play_file(session, NULL, moh, &args); switch_ivr_play_file(session, NULL, moh, &args);
} else { } else {
switch_ivr_collect_digits_callback(session, &args, 0); switch_ivr_collect_digits_callback(session, &args, 0);
} }
if (moh_br) { if (moh_br) {
switch_channel_stop_broadcast(other_channel); switch_channel_stop_broadcast(other_channel);
@ -1856,9 +1855,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel %s is not in a bridge\n", switch_channel_get_name(channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel %s is not in a bridge\n", switch_channel_get_name(channel));
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;

View File

@ -75,7 +75,7 @@ struct switch_loadable_module_container {
static struct switch_loadable_module_container loadable_modules; static struct switch_loadable_module_container loadable_modules;
static void do_shutdown(switch_loadable_module_t *module); static void do_shutdown(switch_loadable_module_t *module);
static void *switch_loadable_module_exec(switch_thread_t * thread, void *obj) static void *switch_loadable_module_exec(switch_thread_t *thread, void *obj)
{ {
@ -126,7 +126,7 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
switch_event_t *event; switch_event_t *event;
new_module->key = switch_core_strdup(new_module->pool, key); new_module->key = switch_core_strdup(new_module->pool, key);
switch_mutex_lock(loadable_modules.mutex); switch_mutex_lock(loadable_modules.mutex);
switch_core_hash_insert(loadable_modules.module_hash, key, new_module); switch_core_hash_insert(loadable_modules.module_hash, key, new_module);
@ -155,13 +155,15 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
if (!impl->iananame) { if (!impl->iananame) {
load_interface = 0; load_interface = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Failed to load codec interface %s from %s due to no iana name in an implementation.\n", ptr->interface_name, key); "Failed to load codec interface %s from %s due to no iana name in an implementation.\n", ptr->interface_name,
key);
break; break;
} }
if (impl->bytes_per_frame > SWITCH_RECOMMENDED_BUFFER_SIZE) { if (impl->bytes_per_frame > SWITCH_RECOMMENDED_BUFFER_SIZE) {
load_interface = 0; load_interface = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Failed to load codec interface %s from %s due to bytes per frame exceeding buffer size.\n", ptr->interface_name, key); "Failed to load codec interface %s from %s due to bytes per frame exceeding buffer size.\n", ptr->interface_name,
key);
break; break;
} }
} }
@ -590,7 +592,7 @@ static switch_status_t switch_loadable_module_unprocess(switch_loadable_module_t
const switch_chat_interface_t *ptr; const switch_chat_interface_t *ptr;
for (ptr = old_module->module_interface->chat_interface; ptr; ptr = ptr->next) { for (ptr = old_module->module_interface->chat_interface; ptr; ptr = ptr->next) {
if (ptr->interface_name) { if (ptr->interface_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Chat interface '%s'\n", ptr->interface_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deleting Chat interface '%s'\n", ptr->interface_name);
if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_MODULE_UNLOAD) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "%s", "chat"); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "type", "%s", "chat");
@ -718,12 +720,12 @@ static switch_status_t switch_loadable_module_load_file(char *path, char *filena
} }
if (status == SWITCH_STATUS_NOUNLOAD) { if (status == SWITCH_STATUS_NOUNLOAD) {
module->perm++; module->perm++;
} }
loading = 0; loading = 0;
} }
if (err) { if (err) {
if (pool) { if (pool) {
@ -778,7 +780,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_load_module(char *dir, ch
if (switch_is_file_path(file)) { if (switch_is_file_path(file)) {
path = switch_core_strdup(loadable_modules.pool, file); path = switch_core_strdup(loadable_modules.pool, file);
file = (char *)switch_cut_path(file); file = (char *) switch_cut_path(file);
if ((dot = strchr(file, '.'))) { if ((dot = strchr(file, '.'))) {
dot = '\0'; dot = '\0';
} }
@ -841,8 +843,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir,
SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filename, SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filename,
switch_module_load_t switch_module_load, switch_module_load_t switch_module_load,
switch_module_runtime_t switch_module_runtime, switch_module_runtime_t switch_module_runtime,
switch_module_shutdown_t switch_module_shutdown, switch_module_shutdown_t switch_module_shutdown, switch_bool_t runtime)
switch_bool_t runtime)
{ {
switch_loadable_module_t *module = NULL; switch_loadable_module_t *module = NULL;
switch_module_load_t load_func_ptr = NULL; switch_module_load_t load_func_ptr = NULL;
@ -851,7 +852,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_build_dynamic(char *filen
switch_loadable_module_interface_t *module_interface = NULL; switch_loadable_module_interface_t *module_interface = NULL;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
abort(); abort();
@ -1058,7 +1059,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
} }
apr_dir_close(module_dir_handle); apr_dir_close(module_dir_handle);
} }
switch_loadable_module_runtime(); switch_loadable_module_runtime();
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -1093,7 +1094,7 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
switch_hash_index_t *hi; switch_hash_index_t *hi;
void *val; void *val;
switch_loadable_module_t *module; switch_loadable_module_t *module;
for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
module = (switch_loadable_module_t *) val; module = (switch_loadable_module_t *) val;
@ -1227,7 +1228,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_impleme
/* oh well we will use what we have */ /* oh well we will use what we have */
array[i++] = codec_interface->implementations; array[i++] = codec_interface->implementations;
found: found:
if (i > arraylen) { if (i > arraylen) {
break; break;
@ -1235,7 +1236,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_impleme
} }
switch_mutex_unlock(loadable_modules.mutex); switch_mutex_unlock(loadable_modules.mutex);
return i; return i;
} }
@ -1247,7 +1248,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
const switch_codec_implementation_t *imp; const switch_codec_implementation_t *imp;
switch_mutex_lock(loadable_modules.mutex); switch_mutex_lock(loadable_modules.mutex);
for (x = 0; x < preflen; x++) { for (x = 0; x < preflen; x++) {
char *cur, *last = NULL, *next = NULL, *name, *p, buf[256]; char *cur, *last = NULL, *next = NULL, *name, *p, buf[256];
uint32_t interval = 0, rate = 8000; uint32_t interval = 0, rate = 8000;
@ -1259,7 +1260,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
if (!next) { if (!next) {
break; break;
} }
if ((p = strchr(next, '@'))) { if ((p = strchr(next, '@'))) {
*p++ = '\0'; *p++ = '\0';
} }
@ -1318,7 +1319,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
} }
} }
found: found:
if (i > arraylen) { if (i > arraylen) {
break; break;
@ -1327,7 +1328,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
} }
switch_mutex_unlock(loadable_modules.mutex); switch_mutex_unlock(loadable_modules.mutex);
return i; return i;
} }
@ -1383,7 +1384,7 @@ SWITCH_DECLARE(switch_loadable_module_interface_t *) switch_loadable_module_crea
mod->pool = pool; mod->pool = pool;
mod->module_name = switch_core_strdup(mod->pool, name); mod->module_name = switch_core_strdup(mod->pool, name);
return mod; return mod;
} }
@ -1404,46 +1405,46 @@ SWITCH_DECLARE(switch_loadable_module_interface_t *) switch_loadable_module_crea
SWITCH_DECLARE(void *) switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname) SWITCH_DECLARE(void *) switch_loadable_module_create_interface(switch_loadable_module_interface_t *mod, switch_module_interface_name_t iname)
{ {
switch(iname) { switch (iname) {
case SWITCH_ENDPOINT_INTERFACE: case SWITCH_ENDPOINT_INTERFACE:
ALLOC_INTERFACE(endpoint) ALLOC_INTERFACE(endpoint)
case SWITCH_TIMER_INTERFACE: case SWITCH_TIMER_INTERFACE:
ALLOC_INTERFACE(timer) ALLOC_INTERFACE(timer)
case SWITCH_DIALPLAN_INTERFACE: case SWITCH_DIALPLAN_INTERFACE:
ALLOC_INTERFACE(dialplan) ALLOC_INTERFACE(dialplan)
case SWITCH_CODEC_INTERFACE: case SWITCH_CODEC_INTERFACE:
ALLOC_INTERFACE(codec) ALLOC_INTERFACE(codec)
case SWITCH_APPLICATION_INTERFACE: case SWITCH_APPLICATION_INTERFACE:
ALLOC_INTERFACE(application) ALLOC_INTERFACE(application)
case SWITCH_API_INTERFACE: case SWITCH_API_INTERFACE:
ALLOC_INTERFACE(api) ALLOC_INTERFACE(api)
case SWITCH_FILE_INTERFACE: case SWITCH_FILE_INTERFACE:
ALLOC_INTERFACE(file) ALLOC_INTERFACE(file)
case SWITCH_SPEECH_INTERFACE: case SWITCH_SPEECH_INTERFACE:
ALLOC_INTERFACE(speech) ALLOC_INTERFACE(speech)
case SWITCH_DIRECTORY_INTERFACE: case SWITCH_DIRECTORY_INTERFACE:
ALLOC_INTERFACE(directory) ALLOC_INTERFACE(directory)
case SWITCH_CHAT_INTERFACE: case SWITCH_CHAT_INTERFACE:
ALLOC_INTERFACE(chat) ALLOC_INTERFACE(chat)
case SWITCH_SAY_INTERFACE: case SWITCH_SAY_INTERFACE:
ALLOC_INTERFACE(say) ALLOC_INTERFACE(say)
case SWITCH_ASR_INTERFACE: case SWITCH_ASR_INTERFACE:
ALLOC_INTERFACE(asr) ALLOC_INTERFACE(asr)
case SWITCH_MANAGEMENT_INTERFACE: case SWITCH_MANAGEMENT_INTERFACE:
ALLOC_INTERFACE(management) ALLOC_INTERFACE(management)
default: default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Module Type!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Module Type!\n");
return NULL; return NULL;

View File

@ -145,7 +145,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_bind_logger(switch_log_function_t fun
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t *thread, void *obj)
{ {
if (!obj) { if (!obj) {
@ -174,7 +174,7 @@ static void *SWITCH_THREAD_FUNC log_thread(switch_thread_t * thread, void *obj)
} }
} }
switch_mutex_unlock(BINDLOCK); switch_mutex_unlock(BINDLOCK);
switch_safe_free(node->data); switch_safe_free(node->data);
if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) { if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
free(node); free(node);
@ -263,13 +263,13 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
fd_set can_write; fd_set can_write;
int fd; int fd;
struct timeval to; struct timeval to;
fd = fileno(handle); fd = fileno(handle);
memset(&to, 0, sizeof(to)); memset(&to, 0, sizeof(to));
FD_SET(fd, &can_write); FD_SET(fd, &can_write);
to.tv_sec = 0; to.tv_sec = 0;
to.tv_usec = 100000; to.tv_usec = 100000;
if (select(fd+1, NULL, &can_write, NULL, &to) > 0) { if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
aok = FD_ISSET(fd, &can_write); aok = FD_ISSET(fd, &can_write);
} else { } else {
aok = 0; aok = 0;
@ -287,7 +287,7 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
node = (switch_log_node_t *) pop; node = (switch_log_node_t *) pop;
} else { } else {
node = malloc(sizeof(*node)); node = malloc(sizeof(*node));
switch_assert(node); switch_assert(node);
} }
node->data = data; node->data = data;
@ -308,8 +308,8 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
node = NULL; node = NULL;
} }
} }
end: end:
switch_safe_free(data); switch_safe_free(data);
switch_safe_free(new_fmt); switch_safe_free(new_fmt);
@ -347,7 +347,8 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void)
{ {
void *pop; void *pop;
int size = switch_queue_size(LOG_RECYCLE_QUEUE); int size = switch_queue_size(LOG_RECYCLE_QUEUE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled log node(s) %d bytes\n", size, (int)sizeof(switch_log_node_t) * size); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Returning %d recycled log node(s) %d bytes\n", size,
(int) sizeof(switch_log_node_t) * size);
while (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop(LOG_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) {
free(pop); free(pop);
} }
@ -362,7 +363,7 @@ SWITCH_DECLARE(switch_status_t) switch_log_shutdown(void)
switch_yield(1000); switch_yield(1000);
} }
switch_core_memory_reclaim_logger(); switch_core_memory_reclaim_logger();
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -50,7 +50,7 @@ SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(char *dsn, char *u
if (!(new_handle = malloc(sizeof(*new_handle)))) { if (!(new_handle = malloc(sizeof(*new_handle)))) {
goto err; goto err;
} }
memset(new_handle, 0, sizeof(*new_handle)); memset(new_handle, 0, sizeof(*new_handle));
if (!(new_handle->dsn = strdup(dsn))) { if (!(new_handle->dsn = strdup(dsn))) {
@ -96,7 +96,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_h
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", handle->dsn); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", handle->dsn);
} }
} }
handle->state = SWITCH_ODBC_STATE_DOWN; handle->state = SWITCH_ODBC_STATE_DOWN;
@ -143,19 +143,21 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", handle->dsn); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", handle->dsn);
if(!strstr(handle->dsn, "DRIVER")) { if (!strstr(handle->dsn, "DRIVER")) {
result = SQLConnect(handle->con, (SQLCHAR *) handle->dsn, SQL_NTS, (SQLCHAR *) handle->username, SQL_NTS, (SQLCHAR *) handle->password, SQL_NTS); result = SQLConnect(handle->con, (SQLCHAR *) handle->dsn, SQL_NTS, (SQLCHAR *) handle->username, SQL_NTS, (SQLCHAR *) handle->password, SQL_NTS);
} else { } else {
SQLCHAR outstr[1024] = {0}; SQLCHAR outstr[1024] = { 0 };
SQLSMALLINT outstrlen = 0; SQLSMALLINT outstrlen = 0;
result = SQLDriverConnect(handle->con, NULL, (SQLCHAR *) handle->dsn, (SQLSMALLINT)strlen(handle->dsn), outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT); result =
} SQLDriverConnect(handle->con, NULL, (SQLCHAR *) handle->dsn, (SQLSMALLINT) strlen(handle->dsn), outstr, sizeof(outstr), &outstrlen,
SQL_DRIVER_NOPROMPT);
}
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) { if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
char *err_str; char *err_str;
if ((err_str = switch_odbc_handle_get_error(handle, NULL))) { if ((err_str = switch_odbc_handle_get_error(handle, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n",err_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s\n", err_str);
free(err_str); free(err_str);
} else { } else {
SQLGetDiagRec(SQL_HANDLE_DBC, handle->con, 1, stat, &err, msg, 100, &mlen); SQLGetDiagRec(SQL_HANDLE_DBC, handle->con, 1, stat, &err, msg, 100, &mlen);
@ -165,10 +167,10 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand
return SWITCH_ODBC_FAIL; return SWITCH_ODBC_FAIL;
} }
result = SQLGetInfo(handle->con, SQL_DRIVER_NAME, (SQLCHAR*)handle->odbc_driver, 255, &valueLength); result = SQLGetInfo(handle->con, SQL_DRIVER_NAME, (SQLCHAR *) handle->odbc_driver, 255, &valueLength);
if ( result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) { if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
for (i = 0; i < valueLength; ++i) for (i = 0; i < valueLength; ++i)
handle->odbc_driver[i] = (char)toupper(handle->odbc_driver[i]); handle->odbc_driver[i] = (char) toupper(handle->odbc_driver[i]);
} }
if (strstr(handle->odbc_driver, "FIREBIRD") != 0 || strstr(handle->odbc_driver, "FB32") != 0 || strstr(handle->odbc_driver, "FB64") != 0) { if (strstr(handle->odbc_driver, "FIREBIRD") != 0 || strstr(handle->odbc_driver, "FB32") != 0 || strstr(handle->odbc_driver, "FB64") != 0) {
@ -194,28 +196,28 @@ static int db_is_up(switch_odbc_handle_t *handle)
SQLCHAR sql[255] = ""; SQLCHAR sql[255] = "";
int max_tries = 120; int max_tries = 120;
top: top:
if (!handle) { if (!handle) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle\n");
goto done; goto done;
} }
if (handle->is_firebird) { if (handle->is_firebird) {
strcpy((char*)sql, "select first 1 * from RDB$RELATIONS"); strcpy((char *) sql, "select first 1 * from RDB$RELATIONS");
} else { } else {
strcpy((char*)sql, "select 1"); strcpy((char *) sql, "select 1");
} }
if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) { if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
goto error; goto error;
} }
if (SQLPrepare(stmt, sql, SQL_NTS) != SQL_SUCCESS) { if (SQLPrepare(stmt, sql, SQL_NTS) != SQL_SUCCESS) {
goto error; goto error;
} }
result = SQLExecute(stmt); result = SQLExecute(stmt);
SQLRowCount(stmt, &m); SQLRowCount(stmt, &m);
ret = (int) m; ret = (int) m;
@ -226,14 +228,14 @@ static int db_is_up(switch_odbc_handle_t *handle)
goto done; goto done;
error: error:
err_str = switch_odbc_handle_get_error(handle, stmt); err_str = switch_odbc_handle_get_error(handle, stmt);
recon = switch_odbc_handle_connect(handle); recon = switch_odbc_handle_connect(handle);
max_tries--; max_tries--;
if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s]", switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s]",
switch_str_nil(handle->dsn), switch_str_nil(err_str)); switch_str_nil(handle->dsn), switch_str_nil(err_str));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s]\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s]\n",
switch_str_nil(handle->dsn), switch_str_nil(err_str)); switch_str_nil(handle->dsn), switch_str_nil(err_str));
@ -260,8 +262,8 @@ static int db_is_up(switch_odbc_handle_t *handle)
switch_safe_free(err_str); switch_safe_free(err_str);
switch_yield(1000000); switch_yield(1000000);
goto top; goto top;
done: done:
switch_safe_free(err_str); switch_safe_free(err_str);
@ -269,10 +271,10 @@ static int db_is_up(switch_odbc_handle_t *handle)
SQLFreeHandle(SQL_HANDLE_STMT, stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} }
return ret; return ret;
} }
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT *rstmt) SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT * rstmt)
{ {
SQLHSTMT stmt = NULL; SQLHSTMT stmt = NULL;
int result; int result;
@ -280,7 +282,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
if (!db_is_up(handle)) { if (!db_is_up(handle)) {
goto error; goto error;
} }
if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) { if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
goto error; goto error;
} }
@ -303,13 +305,13 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
return SWITCH_ODBC_SUCCESS; return SWITCH_ODBC_SUCCESS;
error: error:
if (rstmt) { if (rstmt) {
*rstmt = stmt; *rstmt = stmt;
} else if (stmt) { } else if (stmt) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} }
return SWITCH_ODBC_FAIL; return SWITCH_ODBC_FAIL;
} }
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle, SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
@ -349,14 +351,14 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
char **names; char **names;
char **vals; char **vals;
int y = 0; int y = 0;
if (!(result = SQLFetch(stmt)) == SQL_SUCCESS) { if (!(result = SQLFetch(stmt)) == SQL_SUCCESS) {
goto error; goto error;
} }
names = calloc(c, sizeof(*names)); names = calloc(c, sizeof(*names));
vals = calloc(c, sizeof(*vals)); vals = calloc(c, sizeof(*vals));
switch_assert(names && vals); switch_assert(names && vals);
for (x = 1; x <= c; x++) { for (x = 1; x <= c; x++) {
@ -365,7 +367,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
names[y] = malloc(name_len); names[y] = malloc(name_len);
memset(names[y], 0, name_len); memset(names[y], 0, name_len);
SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], (SQLSMALLINT)name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable); SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], (SQLSMALLINT) name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
ColumnSize++; ColumnSize++;
vals[y] = malloc(ColumnSize); vals[y] = malloc(ColumnSize);
@ -373,7 +375,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL); SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL);
y++; y++;
} }
if (callback(pdata, y, vals, names)) { if (callback(pdata, y, vals, names)) {
break; break;
} }
@ -435,8 +437,8 @@ SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle
SQLSMALLINT length; SQLSMALLINT length;
char *ret = NULL; char *ret = NULL;
if (SQLError(handle->env, handle->con, stmt, (SQLCHAR *)sqlstate, &sqlcode, (SQLCHAR *)buffer, sizeof(buffer), &length) == SQL_SUCCESS) { if (SQLError(handle->env, handle->con, stmt, (SQLCHAR *) sqlstate, &sqlcode, (SQLCHAR *) buffer, sizeof(buffer), &length) == SQL_SUCCESS) {
ret = switch_mprintf("STATE: %s CODE %ld ERROR: %s\n", sqlstate, sqlcode, buffer); ret = switch_mprintf("STATE: %s CODE %ld ERROR: %s\n", sqlstate, sqlcode, buffer);
}; };
return ret; return ret;

View File

@ -58,11 +58,10 @@ static switch_status_t switch_raw_encode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
unsigned int *flag)
{ {
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */ /* 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 && if (codec && other_codec && codec->implementation && other_codec->implementation &&
codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) { codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
memcpy(encoded_data, decoded_data, decoded_data_len); memcpy(encoded_data, decoded_data, decoded_data_len);
*encoded_data_len = decoded_data_len; *encoded_data_len = decoded_data_len;
@ -75,8 +74,7 @@ static switch_status_t switch_raw_decode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
unsigned int *flag)
{ {
if (codec && other_codec && codec->implementation && other_codec->implementation && if (codec && other_codec && codec->implementation && other_codec->implementation &&
codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) { codec->implementation->actual_samples_per_second != other_codec->implementation->actual_samples_per_second) {
@ -100,21 +98,21 @@ static switch_status_t switch_proxy_init(switch_codec_t *codec, switch_codec_fla
} }
static switch_status_t switch_proxy_encode(switch_codec_t *codec, static switch_status_t switch_proxy_encode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
static switch_status_t switch_proxy_decode(switch_codec_t *codec, static switch_status_t switch_proxy_decode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -143,7 +141,7 @@ static switch_status_t switch_g711u_encode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
@ -166,7 +164,7 @@ static switch_status_t switch_g711u_decode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
@ -214,7 +212,7 @@ static switch_status_t switch_g711a_encode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *decoded_data, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_data_len,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
@ -237,7 +235,7 @@ static switch_status_t switch_g711a_decode(switch_codec_t *codec,
switch_codec_t *other_codec, switch_codec_t *other_codec,
void *encoded_data, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_data_len,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
@ -270,40 +268,39 @@ static switch_status_t switch_g711a_destroy(switch_codec_t *codec)
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; switch_codec_interface_t *codec_interface;
int mpf = 10000, spf = 80, bpf = 160, ebpf = 80, count; int mpf = 10000, spf = 80, bpf = 160, ebpf = 80, count;
SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw"); SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
for (count = 12; count > 0; count--) { for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface, switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000, SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12, mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy); switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
} }
SWITCH_ADD_CODEC(codec_interface, "G.711 alaw"); SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
for (count = 12; count > 0; count--) { for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface, switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000, SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12, mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy); switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
} }
} }
SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load) SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load)
{ {
switch_codec_interface_t *codec_interface; switch_codec_interface_t *codec_interface;
int mpf = 10000, spf = 80, bpf = 160, ebpf = 160, bps = 128000, rate = 8000, counta = 1, countb = 12; int mpf = 10000, spf = 80, bpf = 160, ebpf = 160, bps = 128000, rate = 8000, counta = 1, countb = 12;
switch_payload_t ianacode[4] = { 0, 10, 117, 119 }; switch_payload_t ianacode[4] = { 0, 10, 117, 119 };
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_CODEC(codec_interface, "PROXY VIDEO PASS-THROUGH"); SWITCH_ADD_CODEC(codec_interface, "PROXY VIDEO PASS-THROUGH");
switch_core_codec_add_implementation(pool, codec_interface, switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_VIDEO, 31, "PROXY-VID", NULL, 90000, 90000, 0, SWITCH_CODEC_TYPE_VIDEO, 31, "PROXY-VID", NULL, 90000, 90000, 0,
0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, switch_proxy_init, switch_proxy_encode, switch_proxy_decode, switch_proxy_destroy);
switch_proxy_init, switch_proxy_encode, switch_proxy_decode, switch_proxy_destroy);
SWITCH_ADD_CODEC(codec_interface, "PROXY PASS-THROUGH"); SWITCH_ADD_CODEC(codec_interface, "PROXY PASS-THROUGH");
@ -311,34 +308,32 @@ SWITCH_MODULE_LOAD_FUNCTION(core_pcm_load)
SWITCH_CODEC_TYPE_AUDIO, 0, "PROXY", NULL, 8000, 8000, 0, SWITCH_CODEC_TYPE_AUDIO, 0, "PROXY", NULL, 8000, 8000, 0,
20000, 160, 320, 320, 1, 1, 12, 20000, 160, 320, 320, 1, 1, 12,
switch_proxy_init, switch_proxy_encode, switch_proxy_decode, switch_proxy_destroy); switch_proxy_init, switch_proxy_encode, switch_proxy_decode, switch_proxy_destroy);
SWITCH_ADD_CODEC(codec_interface, "RAW Signed Linear (16 bit)"); SWITCH_ADD_CODEC(codec_interface, "RAW Signed Linear (16 bit)");
for (counta = 1; counta <= 3; counta++) { for (counta = 1; counta <= 3; counta++) {
for (countb = 12; countb > 0; countb--) { for (countb = 12; countb > 0; countb--) {
switch_core_codec_add_implementation(pool, codec_interface, switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "L16", NULL, rate, rate, bps, SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "L16", NULL, rate, rate, bps,
mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 12, mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 12,
switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy); switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
} }
rate = rate * 2; rate = rate * 2;
bps = bps * 2; bps = bps * 2;
spf = spf * 2; spf = spf * 2;
bpf = bpf * 2; bpf = bpf * 2;
ebpf = ebpf * 2; ebpf = ebpf * 2;
} }
/* these formats below are for file playing. */ /* these formats below are for file playing. */
switch_core_codec_add_implementation(pool, codec_interface, switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 118, "L16", NULL, 22050, 22050, 352800, SWITCH_CODEC_TYPE_AUDIO, 118, "L16", NULL, 22050, 22050, 352800,
20000, 441, 882, 882, 1, 1, 1, 20000, 441, 882, 882, 1, 1, 1, switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 118, "L16", NULL, 11025, 11025, 176400,
40000, 441, 882, 882, 1, 1, 1, switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 118, "L16", NULL, 11025, 11025, 176400,
40000, 441, 882, 882, 1, 1, 1,
switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */

View File

@ -34,11 +34,10 @@
#include <pcre.h> #include <pcre.h>
SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern, SWITCH_DECLARE(switch_regex_t *) switch_regex_compile(const char *pattern,
int options, const char **errorptr, int *erroroffset, int options, const char **errorptr, int *erroroffset, const unsigned char *tables)
const unsigned char *tables)
{ {
return pcre_compile(pattern, options, errorptr, erroroffset, tables); return pcre_compile(pattern, options, errorptr, erroroffset, tables);
} }
@ -51,7 +50,7 @@ SWITCH_DECLARE(void) switch_regex_free(void *data)
{ {
pcre_free(data); pcre_free(data);
} }
SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen) SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expression, switch_regex_t **new_re, int *ovector, uint32_t olen)
{ {
@ -87,7 +86,7 @@ SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expressi
} }
re = pcre_compile(expression, /* the pattern */ re = pcre_compile(expression, /* the pattern */
flags, /* default options */ flags, /* default options */
&error, /* for error message */ &error, /* for error message */
&erroffset, /* for error offset */ &erroffset, /* for error offset */
NULL); /* use default character tables */ NULL); /* use default character tables */
@ -114,7 +113,7 @@ SWITCH_DECLARE(int) switch_regex_perform(const char *field, const char *expressi
*new_re = (switch_regex_t *) re; *new_re = (switch_regex_t *) re;
end: end:
switch_safe_free(tmp); switch_safe_free(tmp);
return match_count; return match_count;
} }

View File

@ -76,9 +76,9 @@ SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t
resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor); resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate,
resampler->factor); resampler->factor);
resampler->from_size = resample_buffer(to_rate, from_rate, (uint32_t)from_size); resampler->from_size = resample_buffer(to_rate, from_rate, (uint32_t) from_size);
resampler->from = (float *) switch_core_alloc(pool, resampler->from_size * sizeof(float)); resampler->from = (float *) switch_core_alloc(pool, resampler->from_size * sizeof(float));
resampler->to_size = resample_buffer(to_rate, from_rate, (uint32_t)to_size); ; resampler->to_size = resample_buffer(to_rate, from_rate, (uint32_t) to_size);;
resampler->to = (float *) switch_core_alloc(pool, resampler->to_size * sizeof(float)); resampler->to = (float *) switch_core_alloc(pool, resampler->to_size * sizeof(float));
*new_resampler = resampler; *new_resampler = resampler;
@ -231,7 +231,7 @@ SWITCH_DECLARE(uint32_t) switch_merge_sln(int16_t *data, uint32_t samples, int16
x = samples; x = samples;
} }
for(i = 0; i < x; i++) { for (i = 0; i < x; i++) {
z = data[i] + other_data[i]; z = data[i] + other_data[i];
switch_normalize_to_16bit(z); switch_normalize_to_16bit(z);
data[i] = (int16_t) z; data[i] = (int16_t) z;

View File

@ -137,7 +137,7 @@ struct switch_rtp {
srtp_policy_t send_policy; srtp_policy_t send_policy;
srtp_policy_t recv_policy; srtp_policy_t recv_policy;
uint32_t srtp_errs; uint32_t srtp_errs;
uint16_t seq; uint16_t seq;
uint32_t ssrc; uint32_t ssrc;
uint8_t sending_dtmf; uint8_t sending_dtmf;
@ -185,13 +185,8 @@ struct switch_rtp {
}; };
static int global_init = 0; static int global_init = 0;
static int rtp_common_write(switch_rtp_t *rtp_session, static int rtp_common_write(switch_rtp_t *rtp_session,
rtp_msg_t *send_msg, rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags);
void *data,
uint32_t datalen,
switch_payload_t payload,
uint32_t timestamp,
switch_frame_flag_t *flags);
static switch_status_t ice_out(switch_rtp_t *rtp_session) static switch_status_t ice_out(switch_rtp_t *rtp_session)
@ -201,7 +196,7 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session)
unsigned int elapsed; unsigned int elapsed;
switch_size_t bytes; switch_size_t bytes;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_assert(rtp_session != NULL); switch_assert(rtp_session != NULL);
switch_assert(rtp_session->ice_user != NULL); switch_assert(rtp_session->ice_user != NULL);
@ -228,9 +223,9 @@ static switch_status_t ice_out(switch_rtp_t *rtp_session)
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *) packet, &bytes); switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void *) packet, &bytes);
rtp_session->stuncount = 25; rtp_session->stuncount = 25;
end: end:
WRITE_DEC(rtp_session); WRITE_DEC(rtp_session);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -249,7 +244,7 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len)
READ_INC(rtp_session); READ_INC(rtp_session);
WRITE_INC(rtp_session); WRITE_INC(rtp_session);
if (!switch_rtp_ready(rtp_session)) { if (!switch_rtp_ready(rtp_session)) {
goto end; goto end;
} }
@ -299,12 +294,12 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len)
rpacket = switch_stun_packet_build_header(SWITCH_STUN_BINDING_RESPONSE, packet->header.id, stunbuf); rpacket = switch_stun_packet_build_header(SWITCH_STUN_BINDING_RESPONSE, packet->header.id, stunbuf);
switch_stun_packet_attribute_add_username(rpacket, username, 32); switch_stun_packet_attribute_add_username(rpacket, username, 32);
remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr); remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr);
switch_stun_packet_attribute_add_binded_address(rpacket, (char *)remote_ip, switch_sockaddr_get_port(rtp_session->from_addr)); switch_stun_packet_attribute_add_binded_address(rpacket, (char *) remote_ip, switch_sockaddr_get_port(rtp_session->from_addr));
bytes = switch_stun_packet_length(rpacket); bytes = switch_stun_packet_length(rpacket);
switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void *) rpacket, &bytes); switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void *) rpacket, &bytes);
} }
end: end:
READ_DEC(rtp_session); READ_DEC(rtp_session);
WRITE_DEC(rtp_session); WRITE_DEC(rtp_session);
@ -349,8 +344,8 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_start_port(switch_port_t port)
if (port_lock) { if (port_lock) {
switch_mutex_unlock(port_lock); switch_mutex_unlock(port_lock);
} }
} }
return START_PORT; return START_PORT;
} }
SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port) SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port)
@ -366,8 +361,8 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port)
if (port_lock) { if (port_lock) {
switch_mutex_unlock(port_lock); switch_mutex_unlock(port_lock);
} }
} }
return END_PORT; return END_PORT;
} }
SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port) SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port)
@ -378,8 +373,8 @@ SWITCH_DECLARE(void) switch_rtp_release_port(const char *ip, switch_port_t port)
return; return;
} }
switch_mutex_lock(port_lock); switch_mutex_lock(port_lock);
if ((alloc = switch_core_hash_find(alloc_hash, ip))) { if ((alloc = switch_core_hash_find(alloc_hash, ip))) {
switch_core_port_allocator_free_port(alloc, port); switch_core_port_allocator_free_port(alloc, port);
} }
switch_mutex_unlock(port_lock); switch_mutex_unlock(port_lock);
@ -390,7 +385,7 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip)
{ {
switch_port_t port = 0; switch_port_t port = 0;
switch_core_port_allocator_t *alloc = NULL; switch_core_port_allocator_t *alloc = NULL;
switch_mutex_lock(port_lock); switch_mutex_lock(port_lock);
alloc = switch_core_hash_find(alloc_hash, ip); alloc = switch_core_hash_find(alloc_hash, ip);
if (!alloc) { if (!alloc) {
@ -400,7 +395,7 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(const char *ip)
switch_core_hash_insert(alloc_hash, ip, alloc); switch_core_hash_insert(alloc_hash, ip, alloc);
} }
if (switch_core_port_allocator_request_port(alloc, &port) != SWITCH_STATUS_SUCCESS) { if (switch_core_port_allocator_request_port(alloc, &port) != SWITCH_STATUS_SUCCESS) {
port = 0; port = 0;
} }
@ -463,7 +458,6 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s
*err = "Bind Error!"; *err = "Bind Error!";
goto done; goto done;
} }
#ifndef WIN32 #ifndef WIN32
len = sizeof(i); len = sizeof(i);
switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, TRUE); switch_socket_opt_set(new_sock, SWITCH_SO_NONBLOCK, TRUE);
@ -471,7 +465,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s
switch_socket_sendto(new_sock, rtp_session->local_addr, 0, (void *) o, &len); switch_socket_sendto(new_sock, rtp_session->local_addr, 0, (void *) o, &len);
x = 0; x = 0;
while(!ilen) { while (!ilen) {
switch_status_t status; switch_status_t status;
ilen = len; ilen = len;
status = switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &ilen); status = switch_socket_recvfrom(rtp_session->from_addr, new_sock, 0, (void *) i, &ilen);
@ -511,7 +505,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s
if (old_sock) { if (old_sock) {
switch_socket_close(old_sock); switch_socket_close(old_sock);
} }
if (rtp_session->ready != 1) { if (rtp_session->ready != 1) {
WRITE_DEC(rtp_session); WRITE_DEC(rtp_session);
READ_DEC(rtp_session); READ_DEC(rtp_session);
@ -529,7 +523,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_
{ {
switch_sockaddr_t *remote_addr; switch_sockaddr_t *remote_addr;
*err = "Success"; *err = "Success";
if (switch_sockaddr_info_get(&remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !remote_addr) { if (switch_sockaddr_info_get(&remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS || !remote_addr) {
*err = "Remote Address Error!"; *err = "Remote Address Error!";
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -545,10 +539,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_address(switch_rtp_t *rtp_
SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_session, SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_session,
switch_rtp_crypto_direction_t direction, switch_rtp_crypto_direction_t direction,
uint32_t index, uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen)
switch_rtp_crypto_key_type_t type,
unsigned char *key,
switch_size_t keylen)
{ {
switch_rtp_crypto_key_t *crypto_key; switch_rtp_crypto_key_t *crypto_key;
srtp_policy_t *policy; srtp_policy_t *policy;
@ -557,10 +548,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess
if (direction >= SWITCH_RTP_CRYPTO_MAX || keylen > SWITCH_RTP_MAX_CRYPTO_LEN) { if (direction >= SWITCH_RTP_CRYPTO_MAX || keylen > SWITCH_RTP_MAX_CRYPTO_LEN) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
crypto_key = switch_core_alloc(rtp_session->pool, sizeof(*crypto_key)); crypto_key = switch_core_alloc(rtp_session->pool, sizeof(*crypto_key));
if (direction == SWITCH_RTP_CRYPTO_RECV) { if (direction == SWITCH_RTP_CRYPTO_RECV) {
policy = &rtp_session->recv_policy; policy = &rtp_session->recv_policy;
} else { } else {
@ -575,7 +566,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess
memset(policy, 0, sizeof(*policy)); memset(policy, 0, sizeof(*policy));
switch(crypto_key->type) { switch (crypto_key->type) {
case AES_CM_128_HMAC_SHA1_80: case AES_CM_128_HMAC_SHA1_80:
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp); crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy->rtp);
break; break;
@ -586,13 +577,13 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess
break; break;
} }
policy->next = NULL; policy->next = NULL;
policy->key = (uint8_t *) crypto_key->key; policy->key = (uint8_t *) crypto_key->key;
crypto_policy_set_rtcp_default(&policy->rtcp); crypto_policy_set_rtcp_default(&policy->rtcp);
policy->rtcp.sec_serv = sec_serv_none; policy->rtcp.sec_serv = sec_serv_none;
policy->rtp.sec_serv = sec_serv_conf_and_auth; policy->rtp.sec_serv = sec_serv_conf_and_auth;
switch(direction) { switch (direction) {
case SWITCH_RTP_CRYPTO_RECV: case SWITCH_RTP_CRYPTO_RECV:
policy->ssrc.type = ssrc_any_inbound; policy->ssrc.type = ssrc_any_inbound;
@ -645,10 +636,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
switch_payload_t payload, switch_payload_t payload,
uint32_t samples_per_interval, uint32_t samples_per_interval,
uint32_t ms_per_packet, uint32_t ms_per_packet,
switch_rtp_flag_t flags, switch_rtp_flag_t flags, char *timer_name, const char **err, switch_memory_pool_t *pool)
char *timer_name,
const char **err,
switch_memory_pool_t *pool)
{ {
switch_rtp_t *rtp_session = NULL; switch_rtp_t *rtp_session = NULL;
uint32_t ssrc = rand() & 0xffff; uint32_t ssrc = rand() & 0xffff;
@ -718,9 +706,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
} }
if (!switch_strlen_zero(timer_name)) { if (!switch_strlen_zero(timer_name)) {
if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, samples_per_interval, pool) == if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, samples_per_interval, pool) == SWITCH_STATUS_SUCCESS) {
SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet); "Starting timer [%s] %d bytes per %dms\n", timer_name, samples_per_interval, ms_per_packet);
} else { } else {
memset(&rtp_session->timer, 0, sizeof(rtp_session->timer)); memset(&rtp_session->timer, 0, sizeof(rtp_session->timer));
@ -742,10 +729,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host,
switch_payload_t payload, switch_payload_t payload,
uint32_t samples_per_interval, uint32_t samples_per_interval,
uint32_t ms_per_packet, uint32_t ms_per_packet,
switch_rtp_flag_t flags, switch_rtp_flag_t flags, char *timer_name, const char **err, switch_memory_pool_t *pool)
char *timer_name,
const char **err,
switch_memory_pool_t *pool)
{ {
switch_rtp_t *rtp_session = NULL; switch_rtp_t *rtp_session = NULL;
@ -768,26 +752,26 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host,
*err = "Missing remote port"; *err = "Missing remote port";
goto end; goto end;
} }
if (switch_rtp_create(&rtp_session, payload, samples_per_interval, ms_per_packet, flags, timer_name, err, pool) != SWITCH_STATUS_SUCCESS) { if (switch_rtp_create(&rtp_session, payload, samples_per_interval, ms_per_packet, flags, timer_name, err, pool) != SWITCH_STATUS_SUCCESS) {
goto end; goto end;
} }
switch_mutex_lock(rtp_session->flag_mutex); switch_mutex_lock(rtp_session->flag_mutex);
if (switch_rtp_set_local_address(rtp_session, rx_host, rx_port, err) != SWITCH_STATUS_SUCCESS) { if (switch_rtp_set_local_address(rtp_session, rx_host, rx_port, err) != SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(rtp_session->flag_mutex); switch_mutex_unlock(rtp_session->flag_mutex);
rtp_session = NULL; rtp_session = NULL;
goto end; goto end;
} }
if (switch_rtp_set_remote_address(rtp_session, tx_host, tx_port, err) != SWITCH_STATUS_SUCCESS) { if (switch_rtp_set_remote_address(rtp_session, tx_host, tx_port, err) != SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(rtp_session->flag_mutex); switch_mutex_unlock(rtp_session->flag_mutex);
rtp_session = NULL; rtp_session = NULL;
goto end; goto end;
} }
end: end:
if (rtp_session) { if (rtp_session) {
switch_mutex_unlock(rtp_session->flag_mutex); switch_mutex_unlock(rtp_session->flag_mutex);
@ -815,7 +799,7 @@ SWITCH_DECLARE(void) switch_rtp_set_cng_pt(switch_rtp_t *rtp_session, switch_pay
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *rtp_session, uint32_t queue_frames) SWITCH_DECLARE(switch_status_t) switch_rtp_activate_jitter_buffer(switch_rtp_t *rtp_session, uint32_t queue_frames)
{ {
rtp_session->jb = stfu_n_init(queue_frames); rtp_session->jb = stfu_n_init(queue_frames);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -844,7 +828,7 @@ SWITCH_DECLARE(void) switch_rtp_break(switch_rtp_t *rtp_session)
switch_size_t len = sizeof(o); switch_size_t len = sizeof(o);
switch_assert(rtp_session != NULL); switch_assert(rtp_session != NULL);
switch_mutex_lock(rtp_session->flag_mutex); switch_mutex_lock(rtp_session->flag_mutex);
if (rtp_session->sock) { if (rtp_session->sock) {
switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK); switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
switch_socket_sendto(rtp_session->sock, rtp_session->local_addr, 0, (void *) &o, &len); switch_socket_sendto(rtp_session->sock, rtp_session->local_addr, 0, (void *) &o, &len);
@ -898,16 +882,16 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session)
READ_DEC((*rtp_session)); READ_DEC((*rtp_session));
WRITE_DEC((*rtp_session)); WRITE_DEC((*rtp_session));
switch_mutex_lock((*rtp_session)->flag_mutex); switch_mutex_lock((*rtp_session)->flag_mutex);
switch_rtp_kill_socket(*rtp_session); switch_rtp_kill_socket(*rtp_session);
while(switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_safe_free(pop); switch_safe_free(pop);
} }
while(switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) { while (switch_queue_trypop((*rtp_session)->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_safe_free(pop); switch_safe_free(pop);
} }
@ -1014,25 +998,18 @@ static void do_2833(switch_rtp_t *rtp_session)
rtp_session->dtmf_data.out_digit_packet[1] |= 0x80; rtp_session->dtmf_data.out_digit_packet[1] |= 0x80;
loops = 3; loops = 3;
} }
rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (rtp_session->dtmf_data.out_digit_sub_sofar >> 8); rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (rtp_session->dtmf_data.out_digit_sub_sofar >> 8);
rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) rtp_session->dtmf_data.out_digit_sub_sofar; rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) rtp_session->dtmf_data.out_digit_sub_sofar;
for (x = 0; x < loops; x++) { for (x = 0; x < loops; x++) {
switch_rtp_write_manual(rtp_session, switch_rtp_write_manual(rtp_session,
rtp_session->dtmf_data.out_digit_packet, rtp_session->dtmf_data.out_digit_packet, 4, 0, rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf, &flags);
4,
0,
rtp_session->te,
rtp_session->dtmf_data.timestamp_dtmf,
&flags);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send %s packet for [%c] ts=%u dur=%d/%d/%d seq=%d\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send %s packet for [%c] ts=%u dur=%d/%d/%d seq=%d\n",
loops == 1 ? "middle" : "end", rtp_session->dtmf_data.out_digit, loops == 1 ? "middle" : "end", rtp_session->dtmf_data.out_digit,
rtp_session->dtmf_data.timestamp_dtmf, rtp_session->dtmf_data.timestamp_dtmf,
rtp_session->dtmf_data.out_digit_sofar, rtp_session->dtmf_data.out_digit_sofar,
rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_dur, rtp_session->seq);
rtp_session->dtmf_data.out_digit_dur,
rtp_session->seq);
} }
if (loops != 1) { if (loops != 1) {
@ -1054,7 +1031,7 @@ static void do_2833(switch_rtp_t *rtp_session)
return; return;
} }
} }
if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) { if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_dtmf_t *rdigit = pop; switch_dtmf_t *rdigit = pop;
int64_t offset; int64_t offset;
@ -1071,12 +1048,12 @@ static void do_2833(switch_rtp_t *rtp_session)
rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (rtp_session->dtmf_data.out_digit_sub_sofar >> 8); rtp_session->dtmf_data.out_digit_packet[2] = (unsigned char) (rtp_session->dtmf_data.out_digit_sub_sofar >> 8);
rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) rtp_session->dtmf_data.out_digit_sub_sofar; rtp_session->dtmf_data.out_digit_packet[3] = (unsigned char) rtp_session->dtmf_data.out_digit_sub_sofar;
rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples; rtp_session->dtmf_data.timestamp_dtmf = rtp_session->last_write_ts + samples;
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
offset = rtp_session->timer.samplecount - rtp_session->last_write_samplecount; offset = rtp_session->timer.samplecount - rtp_session->last_write_samplecount;
if (offset > 0) { if (offset > 0) {
rtp_session->dtmf_data.timestamp_dtmf = (uint32_t)(rtp_session->dtmf_data.timestamp_dtmf + offset); rtp_session->dtmf_data.timestamp_dtmf = (uint32_t) (rtp_session->dtmf_data.timestamp_dtmf + offset);
} }
} }
@ -1084,17 +1061,13 @@ static void do_2833(switch_rtp_t *rtp_session)
rtp_session->dtmf_data.out_digit_packet, rtp_session->dtmf_data.out_digit_packet,
4, 4,
switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BUGGY_2833) ? 0 : 1, switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BUGGY_2833) ? 0 : 1,
rtp_session->te, rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf, &flags);
rtp_session->dtmf_data.timestamp_dtmf,
&flags);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send start packet for [%c] ts=%u dur=%d/%d/%d seq=%d\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send start packet for [%c] ts=%u dur=%d/%d/%d seq=%d\n",
rtp_session->dtmf_data.out_digit, rtp_session->dtmf_data.out_digit,
rtp_session->dtmf_data.timestamp_dtmf, rtp_session->dtmf_data.timestamp_dtmf,
rtp_session->dtmf_data.out_digit_sofar, rtp_session->dtmf_data.out_digit_sofar,
rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_sub_sofar, rtp_session->dtmf_data.out_digit_dur, rtp_session->seq);
rtp_session->dtmf_data.out_digit_dur,
rtp_session->seq);
free(rdigit); free(rdigit);
} }
@ -1108,7 +1081,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
uint8_t check = 0; uint8_t check = 0;
stfu_frame_t *jb_frame; stfu_frame_t *jb_frame;
int ret = -1; int ret = -1;
if (!switch_rtp_ready(rtp_session)) { if (!switch_rtp_ready(rtp_session)) {
return -1; return -1;
} }
@ -1124,12 +1097,12 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
bytes = sizeof(rtp_msg_t); bytes = sizeof(rtp_msg_t);
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes);
if (bytes < 0) { if (bytes < 0) {
ret = (int) bytes; ret = (int) bytes;
goto end; goto end;
} }
if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) { if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
const char *tx_host; const char *tx_host;
const char *old_host; const char *old_host;
@ -1178,12 +1151,12 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) { if (!bytes && (io_flags & SWITCH_IO_FLAG_NOBLOCK)) {
do_cng = 1; do_cng = 1;
goto cng; goto cng;
} }
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
check = (uint8_t) (switch_core_timer_check(&rtp_session->timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS); check = (uint8_t) (switch_core_timer_check(&rtp_session->timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS);
if (bytes) { if (bytes) {
switch_core_timer_sync(&rtp_session->timer); switch_core_timer_sync(&rtp_session->timer);
} else { } else {
@ -1199,7 +1172,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
} else if (bytes) { } else if (bytes) {
check++; check++;
} }
if (check || bytes) { if (check || bytes) {
do_2833(rtp_session); do_2833(rtp_session);
} }
@ -1213,25 +1186,25 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (rtp_session->invalid_handler) { if (rtp_session->invalid_handler) {
rtp_session->invalid_handler(rtp_session, rtp_session->sock, (void *) &rtp_session->recv_msg, bytes, rtp_session->from_addr); rtp_session->invalid_handler(rtp_session, rtp_session->sock, (void *) &rtp_session->recv_msg, bytes, rtp_session->from_addr);
} }
memset(data, 0, 2); memset(data, 0, 2);
data[0] = 65; data[0] = 65;
rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD; rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD;
*flags |= SFF_CNG; *flags |= SFF_CNG;
*payload_type = (switch_payload_t)rtp_session->recv_msg.header.pt; *payload_type = (switch_payload_t) rtp_session->recv_msg.header.pt;
ret = 2 + rtp_header_len; ret = 2 + rtp_header_len;
goto end; goto end;
} }
if (rtp_session->jb && ((bytes && rtp_session->recv_msg.header.pt == rtp_session->payload) || check)) { if (rtp_session->jb && ((bytes && rtp_session->recv_msg.header.pt == rtp_session->payload) || check)) {
if (bytes) { if (bytes) {
if (rtp_session->recv_msg.header.m) { if (rtp_session->recv_msg.header.m) {
stfu_n_reset(rtp_session->jb); stfu_n_reset(rtp_session->jb);
} }
stfu_n_eat(rtp_session->jb, ntohl(rtp_session->recv_msg.header.ts), 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.body, bytes - rtp_header_len);
bytes = 0; bytes = 0;
} }
@ -1248,7 +1221,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
goto cng; goto cng;
} }
} }
if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_RECV)) { if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_RECV)) {
int sbytes = (int) bytes; int sbytes = (int) bytes;
@ -1274,7 +1247,8 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (++rtp_session->srtp_errs >= MAX_SRTP_ERRS) { if (++rtp_session->srtp_errs >= MAX_SRTP_ERRS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"error: srtp unprotection failed with code %d%s\n", stat, "error: srtp unprotection failed with code %d%s\n", stat,
stat == err_status_replay_fail ? " (replay check failed)" : stat == err_status_auth_fail ? " (auth check failed)" : ""); stat == err_status_replay_fail ? " (replay check failed)" : stat ==
err_status_auth_fail ? " (auth check failed)" : "");
ret = -1; ret = -1;
goto end; goto end;
} else { } else {
@ -1300,13 +1274,13 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
uint16_t duration = (packet[2] << 8) + packet[3]; uint16_t duration = (packet[2] << 8) + packet[3];
char key = switch_rfc2833_to_char(packet[0]); char key = switch_rfc2833_to_char(packet[0]);
uint16_t in_digit_seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq); uint16_t in_digit_seq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
if (in_digit_seq > rtp_session->dtmf_data.in_digit_seq) { if (in_digit_seq > rtp_session->dtmf_data.in_digit_seq) {
uint32_t ts = htonl(rtp_session->recv_msg.header.ts); uint32_t ts = htonl(rtp_session->recv_msg.header.ts);
//int m = rtp_session->recv_msg.header.m; //int m = rtp_session->recv_msg.header.m;
rtp_session->dtmf_data.in_digit_seq = in_digit_seq; rtp_session->dtmf_data.in_digit_seq = in_digit_seq;
//printf("%c %u %u %u\n", key, in_digit_seq, ts, duration); //printf("%c %u %u %u\n", key, in_digit_seq, ts, duration);
if (rtp_session->dtmf_data.last_duration > duration && ts == rtp_session->dtmf_data.in_digit_ts) { if (rtp_session->dtmf_data.last_duration > duration && ts == rtp_session->dtmf_data.in_digit_ts) {
@ -1316,7 +1290,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (end) { if (end) {
if (rtp_session->dtmf_data.in_digit_ts) { if (rtp_session->dtmf_data.in_digit_ts) {
switch_dtmf_t dtmf = { key, duration }; switch_dtmf_t dtmf = { key, duration };
if (ts > rtp_session->dtmf_data.in_digit_ts) { if (ts > rtp_session->dtmf_data.in_digit_ts) {
dtmf.duration += (ts - rtp_session->dtmf_data.in_digit_ts); dtmf.duration += (ts - rtp_session->dtmf_data.in_digit_ts);
} }
@ -1325,7 +1299,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
rtp_session->dtmf_data.flip = 0; rtp_session->dtmf_data.flip = 0;
//printf("you're welcome!\n"); //printf("you're welcome!\n");
} }
//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); //dtmf.digit, ts, rtp_session->dtmf_data.in_digit_ts, duration, dtmf.duration);
switch_rtp_queue_rfc2833_in(rtp_session, &dtmf); switch_rtp_queue_rfc2833_in(rtp_session, &dtmf);
@ -1336,8 +1309,8 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
} else if (!rtp_session->dtmf_data.in_digit_ts) { } else if (!rtp_session->dtmf_data.in_digit_ts) {
rtp_session->dtmf_data.in_digit_ts = ts; rtp_session->dtmf_data.in_digit_ts = ts;
rtp_session->dtmf_data.first_digit = key; rtp_session->dtmf_data.first_digit = key;
} }
rtp_session->dtmf_data.last_duration = duration; rtp_session->dtmf_data.last_duration = duration;
} }
@ -1345,7 +1318,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
do_cng = 1; do_cng = 1;
} }
cng: cng:
if (do_cng) { if (do_cng) {
memset(&rtp_session->recv_msg.body, 0, 2); memset(&rtp_session->recv_msg.body, 0, 2);
rtp_session->recv_msg.body[0] = 127; rtp_session->recv_msg.body[0] = 127;
@ -1364,7 +1337,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
goto end; goto end;
} }
} }
if (rtp_session->jb && (jb_frame = stfu_n_read_a_frame(rtp_session->jb))) { if (rtp_session->jb && (jb_frame = stfu_n_read_a_frame(rtp_session->jb))) {
memcpy(rtp_session->recv_msg.body, jb_frame->data, jb_frame->dlen); memcpy(rtp_session->recv_msg.body, jb_frame->data, jb_frame->dlen);
if (jb_frame->plc) { if (jb_frame->plc) {
@ -1372,20 +1345,20 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
} }
bytes = jb_frame->dlen + rtp_header_len; bytes = jb_frame->dlen + rtp_header_len;
rtp_session->recv_msg.header.ts = htonl(jb_frame->ts); rtp_session->recv_msg.header.ts = htonl(jb_frame->ts);
} else if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { /* We're late! We're Late! */ } else if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { /* We're late! We're Late! */
uint8_t *data = (uint8_t *) rtp_session->recv_msg.body; uint8_t *data = (uint8_t *) rtp_session->recv_msg.body;
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) { if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {
switch_yield(1000); switch_yield(1000);
continue; continue;
} }
memset(data, 0, 2); memset(data, 0, 2);
data[0] = 65; data[0] = 65;
rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD; rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD;
*flags |= SFF_CNG; *flags |= SFF_CNG;
*payload_type = (switch_payload_t)rtp_session->recv_msg.header.pt; *payload_type = (switch_payload_t) rtp_session->recv_msg.header.pt;
ret = 2 + rtp_header_len; ret = 2 + rtp_header_len;
goto end; goto end;
} }
@ -1398,7 +1371,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
ret = 0; ret = 0;
goto end; goto end;
} }
if (bytes && rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) { if (bytes && rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
goto do_continue; goto do_continue;
} }
@ -1411,7 +1384,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
break; break;
do_continue: do_continue:
switch_yield(1000); switch_yield(1000);
} }
@ -1428,7 +1401,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
ret = -1; ret = -1;
} }
end: end:
READ_DEC(rtp_session); READ_DEC(rtp_session);
@ -1453,7 +1426,7 @@ SWITCH_DECLARE(switch_size_t) switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session,
switch_size_t bytes = 0; switch_size_t bytes = 0;
switch_dtmf_t *_dtmf = NULL; switch_dtmf_t *_dtmf = NULL;
void *pop; void *pop;
if (!switch_rtp_ready(rtp_session)) { if (!switch_rtp_ready(rtp_session)) {
return bytes; return bytes;
} }
@ -1483,7 +1456,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_queue_rfc2833(switch_rtp_t *rtp_sessi
if (rdigit->duration < switch_core_default_dtmf_duration(0)) { if (rdigit->duration < switch_core_default_dtmf_duration(0)) {
rdigit->duration = switch_core_default_dtmf_duration(0); rdigit->duration = switch_core_default_dtmf_duration(0);
} }
if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_queue, rdigit)) != SWITCH_STATUS_SUCCESS) { if ((switch_queue_trypush(rtp_session->dtmf_data.dtmf_queue, rdigit)) != SWITCH_STATUS_SUCCESS) {
free(rdigit); free(rdigit);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -1491,7 +1464,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_queue_rfc2833(switch_rtp_t *rtp_sessi
} else { } else {
abort(); abort();
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1502,7 +1475,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_queue_rfc2833_in(switch_rtp_t *rtp_se
if (!switch_rtp_ready(rtp_session)) { if (!switch_rtp_ready(rtp_session)) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if ((rdigit = malloc(sizeof(*rdigit))) != 0) { if ((rdigit = malloc(sizeof(*rdigit))) != 0) {
*rdigit = *dtmf; *rdigit = *dtmf;
if (rdigit->duration < switch_core_default_dtmf_duration(0)) { if (rdigit->duration < switch_core_default_dtmf_duration(0)) {
@ -1516,11 +1489,11 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_queue_rfc2833_in(switch_rtp_t *rtp_se
} else { } else {
abort(); abort();
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t * datalen, SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen,
switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags) switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags)
{ {
int bytes = 0; int bytes = 0;
@ -1567,7 +1540,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp
frame->flags |= SFF_RFC2833; frame->flags |= SFF_RFC2833;
} }
frame->timestamp = ntohl(rtp_session->recv_msg.header.ts); frame->timestamp = ntohl(rtp_session->recv_msg.header.ts);
frame->seq = (uint16_t)ntohs((u_short)rtp_session->recv_msg.header.seq); frame->seq = (uint16_t) ntohs((u_short) rtp_session->recv_msg.header.seq);
frame->ssrc = ntohl(rtp_session->recv_msg.header.ssrc); frame->ssrc = ntohl(rtp_session->recv_msg.header.ssrc);
frame->m = rtp_session->recv_msg.header.m ? SWITCH_TRUE : SWITCH_FALSE; frame->m = rtp_session->recv_msg.header.m ? SWITCH_TRUE : SWITCH_FALSE;
@ -1580,14 +1553,15 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp
} else { } else {
bytes -= rtp_header_len; bytes -= rtp_header_len;
} }
frame->datalen = bytes; frame->datalen = bytes;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session, SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_session,
void **data, uint32_t * datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags, switch_io_flag_t io_flags) void **data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags,
switch_io_flag_t io_flags)
{ {
int bytes = 0; int bytes = 0;
@ -1609,13 +1583,8 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_sessi
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static int rtp_common_write(switch_rtp_t *rtp_session, static int rtp_common_write(switch_rtp_t *rtp_session,
rtp_msg_t *send_msg, rtp_msg_t *send_msg, void *data, uint32_t datalen, switch_payload_t payload, uint32_t timestamp, switch_frame_flag_t *flags)
void *data,
uint32_t datalen,
switch_payload_t payload,
uint32_t timestamp,
switch_frame_flag_t *flags)
{ {
switch_size_t bytes; switch_size_t bytes;
uint8_t send = 1; uint8_t send = 1;
@ -1633,11 +1602,11 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
if (flags && *flags & SFF_RFC2833) { if (flags && *flags & SFF_RFC2833) {
send_msg->header.pt = rtp_session->te; send_msg->header.pt = rtp_session->te;
} }
data = send_msg->body; data = send_msg->body;
datalen -= rtp_header_len; datalen -= rtp_header_len;
} else { } else {
uint8_t m = 0; uint8_t m = 0;
if (*flags & SFF_RFC2833) { if (*flags & SFF_RFC2833) {
payload = rtp_session->te; payload = rtp_session->te;
} }
@ -1655,10 +1624,10 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
} else { } else {
rtp_session->ts += rtp_session->samples_per_interval; rtp_session->ts += rtp_session->samples_per_interval;
} }
rtp_session->send_msg.header.ts = htonl(rtp_session->ts); rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
if ((rtp_session->ts > (rtp_session->last_write_ts + (rtp_session->samples_per_interval * 10))) if ((rtp_session->ts > (rtp_session->last_write_ts + (rtp_session->samples_per_interval * 10)))
|| rtp_session->ts == rtp_session->samples_per_interval) { || rtp_session->ts == rtp_session->samples_per_interval) {
m++; m++;
} }
@ -1681,8 +1650,8 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD) && if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD) &&
rtp_session->recv_msg.header.pt == rtp_session->vad_data.read_codec->implementation->ianacode) { rtp_session->recv_msg.header.pt == rtp_session->vad_data.read_codec->implementation->ianacode) {
int16_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE / sizeof(int16_t)] = {0}; int16_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE / sizeof(int16_t)] = { 0 };
uint32_t rate = 0; uint32_t rate = 0;
uint32_t codec_flags = 0; uint32_t codec_flags = 0;
uint32_t len = sizeof(decoded); uint32_t len = sizeof(decoded);
@ -1706,7 +1675,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
uint32_t score = 0; uint32_t score = 0;
int divisor = 0; int divisor = 0;
if (z) { if (z) {
if (!(divisor = rtp_session->vad_data.read_codec->implementation->actual_samples_per_second / 8000)) { if (!(divisor = rtp_session->vad_data.read_codec->implementation->actual_samples_per_second / 8000)) {
divisor = 1; divisor = 1;
} }
@ -1715,7 +1684,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
energy += abs(decoded[y]); energy += abs(decoded[y]);
y += rtp_session->vad_data.read_codec->implementation->number_of_channels; y += rtp_session->vad_data.read_codec->implementation->number_of_channels;
} }
if (++rtp_session->vad_data.start_count < rtp_session->vad_data.start) { if (++rtp_session->vad_data.start_count < rtp_session->vad_data.start) {
send = 1; send = 1;
} else { } else {
@ -1770,7 +1739,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) { if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
send = 1; send = 1;
} }
} }
} else { } else {
ret = -1; ret = -1;
@ -1786,11 +1755,11 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
if (send) { if (send) {
send_msg->header.seq = htons(++rtp_session->seq); send_msg->header.seq = htons(++rtp_session->seq);
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND)) {
int sbytes = (int) bytes; int sbytes = (int) bytes;
err_status_t stat; err_status_t stat;
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND_RESET)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND_RESET)) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND_RESET); switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_SECURE_SEND_RESET);
@ -1804,13 +1773,13 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "RE-Activating Secure RTP SEND\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "RE-Activating Secure RTP SEND\n");
} }
} }
stat = srtp_protect(rtp_session->send_ctx, &send_msg->header, &sbytes); stat = srtp_protect(rtp_session->send_ctx, &send_msg->header, &sbytes);
if (stat) { if (stat) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error: srtp protection failed with code %d\n", stat); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error: srtp protection failed with code %d\n", stat);
} }
bytes = sbytes; bytes = sbytes;
} }
@ -1819,7 +1788,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
ret = -1; ret = -1;
goto end; goto end;
} }
if (rtp_session->timer.interval) { if (rtp_session->timer.interval) {
rtp_session->last_write_samplecount = rtp_session->timer.samplecount; rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
} }
@ -1835,7 +1804,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session,
ret = (int) bytes; ret = (int) bytes;
end: end:
WRITE_DEC(rtp_session); WRITE_DEC(rtp_session);
@ -1879,7 +1848,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Activate VAD codec %s %dms\n", codec->implementation->iananame, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Activate VAD codec %s %dms\n", codec->implementation->iananame,
codec->implementation->microseconds_per_frame / 1000); codec->implementation->microseconds_per_frame / 1000);
rtp_session->vad_data.diff_level = 400; rtp_session->vad_data.diff_level = 400;
rtp_session->vad_data.hangunder = 15; rtp_session->vad_data.hangunder = 15;
@ -1907,14 +1876,14 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra
uint32_t len, ts = 0; uint32_t len, ts = 0;
switch_payload_t payload; switch_payload_t payload;
rtp_msg_t *send_msg = NULL; rtp_msg_t *send_msg = NULL;
if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr) { if (!switch_rtp_ready(rtp_session) || !rtp_session->remote_addr) {
return -1; return -1;
} }
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) { if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA)) {
switch_size_t bytes; switch_size_t bytes;
/* Fast PASS! */ /* Fast PASS! */
if (!switch_test_flag(frame, SFF_PROXY_PACKET)) { if (!switch_test_flag(frame, SFF_PROXY_PACKET)) {
return 0; return 0;
@ -1938,8 +1907,7 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra
} }
if (switch_test_flag(frame, SFF_RTP_HEADER)) { if (switch_test_flag(frame, SFF_RTP_HEADER)) {
return switch_rtp_write_manual(rtp_session, frame->data, frame->datalen, frame->m, frame->payload, return switch_rtp_write_manual(rtp_session, frame->data, frame->datalen, frame->m, frame->payload, (uint32_t) (frame->timestamp), &frame->flags);
(uint32_t)(frame->timestamp), &frame->flags);
} }
if (fwd) { if (fwd) {
@ -1949,16 +1917,14 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra
} else { } else {
data = frame->data; data = frame->data;
len = frame->datalen; len = frame->datalen;
ts = (uint32_t)frame->timestamp; ts = (uint32_t) frame->timestamp;
} }
return rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags); return rtp_common_write(rtp_session, send_msg, data, len, payload, ts, &frame->flags);
} }
SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session, SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session,
void *data, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags)
uint32_t datalen,
uint8_t m, switch_payload_t payload, uint32_t ts, switch_frame_flag_t *flags)
{ {
switch_size_t bytes; switch_size_t bytes;
int ret = -1; int ret = -1;
@ -2011,8 +1977,8 @@ SWITCH_DECLARE(int) switch_rtp_write_manual(switch_rtp_t *rtp_session,
rtp_session->last_write_ts = ts; rtp_session->last_write_ts = ts;
ret = (int) bytes; ret = (int) bytes;
end: end:
WRITE_DEC(rtp_session); WRITE_DEC(rtp_session);

View File

@ -53,7 +53,7 @@ static struct {
switch_memory_pool_t *memory_pool; switch_memory_pool_t *memory_pool;
} globals; } globals;
static void switch_scheduler_execute(switch_scheduler_task_container_t * tp) static void switch_scheduler_execute(switch_scheduler_task_container_t *tp)
{ {
switch_event_t *event; switch_event_t *event;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing task %u %s (%s)\n", tp->task.task_id, tp->desc, switch_str_nil(tp->task.group)); //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Executing task %u %s (%s)\n", tp->task.task_id, tp->desc, switch_str_nil(tp->task.group));
@ -81,7 +81,7 @@ static void switch_scheduler_execute(switch_scheduler_task_container_t * tp)
} }
} }
static void *SWITCH_THREAD_FUNC task_own_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC task_own_thread(switch_thread_t *thread, void *obj)
{ {
switch_scheduler_task_container_t *tp = (switch_scheduler_task_container_t *) obj; switch_scheduler_task_container_t *tp = (switch_scheduler_task_container_t *) obj;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
@ -109,7 +109,7 @@ static int task_thread_loop(int done)
} else { } else {
int64_t now = switch_timestamp(NULL); int64_t now = switch_timestamp(NULL);
if (now >= tp->task.runtime && !tp->in_thread) { if (now >= tp->task.runtime && !tp->in_thread) {
int32_t diff = (int32_t)(now - tp->task.runtime); int32_t diff = (int32_t) (now - tp->task.runtime);
if (diff > 1) { if (diff > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Task was executed late by %d seconds %u %s (%s)\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Task was executed late by %d seconds %u %s (%s)\n",
diff, tp->task.task_id, tp->desc, switch_str_nil(tp->task.group)); diff, tp->task.task_id, tp->desc, switch_str_nil(tp->task.group));
@ -158,7 +158,7 @@ static int task_thread_loop(int done)
return done; return done;
} }
static void *SWITCH_THREAD_FUNC switch_scheduler_task_thread(switch_thread_t * thread, void *obj) static void *SWITCH_THREAD_FUNC switch_scheduler_task_thread(switch_thread_t *thread, void *obj)
{ {
globals.task_thread_running = 1; globals.task_thread_running = 1;
@ -234,7 +234,7 @@ SWITCH_DECLARE(uint32_t) switch_scheduler_del_task_id(uint32_t task_id)
for (tp = globals.task_list; tp; tp = tp->next) { for (tp = globals.task_list; tp; tp = tp->next) {
if (tp->task.task_id == task_id) { if (tp->task.task_id == task_id) {
if (switch_test_flag(tp, SSHF_NO_DEL)) { if (switch_test_flag(tp, SSHF_NO_DEL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeleteable task #%u (group %s)\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeleteable task #%u (group %s)\n",
tp->task.task_id, tp->task.group); tp->task.task_id, tp->task.group);
break; break;
} }

View File

@ -114,7 +114,7 @@ SWITCH_DECLARE(void) switch_stun_random_string(char *buf, uint16_t len, char *se
} }
SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, uint32_t len) SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t *buf, uint32_t len)
{ {
switch_stun_packet_t *packet; switch_stun_packet_t *packet;
switch_stun_packet_attribute_t *attr; switch_stun_packet_attribute_t *attr;
@ -133,7 +133,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
/* /*
* Check packet type (RFC3489(bis?) values) * Check packet type (RFC3489(bis?) values)
*/ */
switch(packet->header.type) { switch (packet->header.type) {
case SWITCH_STUN_BINDING_REQUEST: case SWITCH_STUN_BINDING_REQUEST:
case SWITCH_STUN_BINDING_RESPONSE: case SWITCH_STUN_BINDING_RESPONSE:
case SWITCH_STUN_BINDING_ERROR_RESPONSE: case SWITCH_STUN_BINDING_ERROR_RESPONSE:
@ -180,7 +180,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
do { do {
attr->length = ntohs(attr->length); attr->length = ntohs(attr->length);
attr->type = ntohs(attr->type); attr->type = ntohs(attr->type);
bytes_left -= 4; /* attribute header consumed */ bytes_left -= 4; /* attribute header consumed */
if (!attr->length || switch_stun_attribute_padded_length(attr) > bytes_left) { if (!attr->length || switch_stun_attribute_padded_length(attr) > bytes_left) {
/* /*
@ -195,7 +195,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
* Handle STUN attributes * Handle STUN attributes
*/ */
switch (attr->type) { switch (attr->type) {
case SWITCH_STUN_ATTR_MAPPED_ADDRESS: /* Address, we only care about this one, but parse the others too */ case SWITCH_STUN_ATTR_MAPPED_ADDRESS: /* Address, we only care about this one, but parse the others too */
case SWITCH_STUN_ATTR_RESPONSE_ADDRESS: case SWITCH_STUN_ATTR_RESPONSE_ADDRESS:
case SWITCH_STUN_ATTR_SOURCE_ADDRESS: case SWITCH_STUN_ATTR_SOURCE_ADDRESS:
case SWITCH_STUN_ATTR_CHANGED_ADDRESS: case SWITCH_STUN_ATTR_CHANGED_ADDRESS:
@ -231,7 +231,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
} }
break; break;
case SWITCH_STUN_ATTR_CHANGE_REQUEST: /* UInt32 */ case SWITCH_STUN_ATTR_CHANGE_REQUEST: /* UInt32 */
case SWITCH_STUN_ATTR_LIFETIME: case SWITCH_STUN_ATTR_LIFETIME:
case SWITCH_STUN_ATTR_BANDWIDTH: case SWITCH_STUN_ATTR_BANDWIDTH:
case SWITCH_STUN_ATTR_OPTIONS: case SWITCH_STUN_ATTR_OPTIONS:
@ -247,16 +247,16 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
} }
break; break;
case SWITCH_STUN_ATTR_USERNAME: /* ByteString, multiple of 4 bytes */ case SWITCH_STUN_ATTR_USERNAME: /* ByteString, multiple of 4 bytes */
case SWITCH_STUN_ATTR_PASSWORD: /* ByteString, multiple of 4 bytes */ case SWITCH_STUN_ATTR_PASSWORD: /* ByteString, multiple of 4 bytes */
if (attr->length % 4 != 0) { if (attr->length % 4 != 0) {
/* Invalid */ /* Invalid */
return NULL; return NULL;
} }
break; break;
case SWITCH_STUN_ATTR_DATA: /* ByteString */ case SWITCH_STUN_ATTR_DATA: /* ByteString */
case SWITCH_STUN_ATTR_ERROR_CODE: /* ErrorCode */ case SWITCH_STUN_ATTR_ERROR_CODE: /* ErrorCode */
case SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES: /* TransportPrefs */ case SWITCH_STUN_ATTR_TRANSPORT_PREFERENCES: /* TransportPrefs */
/* /*
* No length checking here, since we already checked against the padded length * No length checking here, since we already checked against the padded length
@ -271,7 +271,7 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
} }
break; break;
case SWITCH_STUN_ATTR_MAGIC_COOKIE: /* ByteString, 4 bytes */ case SWITCH_STUN_ATTR_MAGIC_COOKIE: /* ByteString, 4 bytes */
if (attr->length != 4) { if (attr->length != 4) {
/* Invalid */ /* Invalid */
return NULL; return NULL;
@ -295,12 +295,12 @@ SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_parse(uint8_t * buf, u
} while (bytes_left >= SWITCH_STUN_ATTRIBUTE_MIN_LEN && switch_stun_packet_next_attribute(attr, end_buf)); } while (bytes_left >= SWITCH_STUN_ATTRIBUTE_MIN_LEN && switch_stun_packet_next_attribute(attr, end_buf));
if ((uint32_t)(packet->header.length + 20) > (uint32_t)(len - bytes_left)) { if ((uint32_t) (packet->header.length + 20) > (uint32_t) (len - bytes_left)) {
/* /*
* the packet length is longer than the length of all attributes? * the packet length is longer than the length of all attributes?
* for now simply decrease the packet size * for now simply decrease the packet size
*/ */
packet->header.length = (uint16_t)((len - bytes_left) - 20); packet->header.length = (uint16_t) ((len - bytes_left) - 20);
} }
return packet; return packet;
@ -336,14 +336,14 @@ SWITCH_DECLARE(const char *) switch_stun_value_to_name(int32_t type, uint32_t va
return "INVALID"; return "INVALID";
} }
SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t * port) SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_get_mapped_address(switch_stun_packet_attribute_t *attribute, char *ipstr, uint16_t *port)
{ {
switch_stun_ip_t *ip; switch_stun_ip_t *ip;
uint8_t x, *i; uint8_t x, *i;
char *p = ipstr; char *p = ipstr;
ip = (switch_stun_ip_t *) attribute->value; ip = (switch_stun_ip_t *) attribute->value;
i = (uint8_t *) & ip->address; i = (uint8_t *) &ip->address;
*ipstr = 0; *ipstr = 0;
for (x = 0; x < 4; x++) { for (x = 0; x < 4; x++) {
sprintf(p, "%u%s", i[x], x == 3 ? "" : "."); sprintf(p, "%u%s", i[x], x == 3 ? "" : ".");
@ -361,7 +361,7 @@ SWITCH_DECLARE(char *) switch_stun_packet_attribute_get_username(switch_stun_pac
return memcpy(username, attribute->value, cpylen); return memcpy(username, attribute->value, cpylen);
} }
SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t * buf) SWITCH_DECLARE(switch_stun_packet_t *) switch_stun_packet_build_header(switch_stun_message_t type, char *id, uint8_t *buf)
{ {
switch_stun_packet_header_t *header; switch_stun_packet_header_t *header;
@ -386,14 +386,14 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_binded_address(switch_s
uint8_t *i, x; uint8_t *i, x;
char *p = ipstr; 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->type = htons(SWITCH_STUN_ATTR_MAPPED_ADDRESS);
attribute->length = htons(8); attribute->length = htons(8);
ip = (switch_stun_ip_t *) attribute->value; ip = (switch_stun_ip_t *) attribute->value;
ip->port = htons(port); ip->port = htons(port);
ip->family = 1; ip->family = 1;
i = (uint8_t *) & ip->address; i = (uint8_t *) &ip->address;
for (x = 0; x < 4; x++) { for (x = 0; x < 4; x++) {
i[x] = (uint8_t) atoi(p); i[x] = (uint8_t) atoi(p);
@ -415,7 +415,7 @@ SWITCH_DECLARE(uint8_t) switch_stun_packet_attribute_add_username(switch_stun_pa
if (ulen % 4 != 0) { if (ulen % 4 != 0) {
return 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->type = htons(SWITCH_STUN_ATTR_USERNAME);
attribute->length = htons(ulen); attribute->length = htons(ulen);
if (username) { if (username) {

View File

@ -243,7 +243,7 @@ int fs_switch_ivr_originate(switch_core_session_t *session, switch_core_session_
return; return;
} else { } else {
switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);
switch_core_session_rwunlock(peer_session); switch_core_session_rwunlock(peer_session);
} }
} }

View File

@ -102,7 +102,7 @@ static int MONO = 0;
#endif #endif
SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable) SWITCH_DECLARE(void) switch_time_set_monotonic(switch_bool_t enable)
{ {
MONO = enable ? 1 : 0; MONO = enable ? 1 : 0;
switch_time_sync(); switch_time_sync();
@ -116,7 +116,7 @@ static switch_time_t time_now(int64_t offset)
if (MONO) { if (MONO) {
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec/1000) + offset; now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000) + offset;
} else { } else {
#endif #endif
now = switch_time_now(); now = switch_time_now();
@ -138,13 +138,13 @@ SWITCH_DECLARE(void) switch_time_sync(void)
SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t) SWITCH_DECLARE(void) switch_sleep(switch_interval_time_t t)
{ {
#if defined(HAVE_CLOCK_NANOSLEEP) && defined(SWITCH_USE_CLOCK_FUNCS) #if defined(HAVE_CLOCK_NANOSLEEP) && defined(SWITCH_USE_CLOCK_FUNCS)
struct timespec ts; struct timespec ts;
ts.tv_sec = t / APR_USEC_PER_SEC; ts.tv_sec = t / APR_USEC_PER_SEC;
ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000; ts.tv_nsec = (t % APR_USEC_PER_SEC) * 1000;
clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
#elif defined(HAVE_USLEEP) #elif defined(HAVE_USLEEP)
usleep(t); usleep(t);
#elif defined(WIN32) #elif defined(WIN32)
@ -161,7 +161,7 @@ static switch_status_t timer_init(switch_timer_t *timer)
timer_private_t *private_info; timer_private_t *private_info;
int sanity = 0; int sanity = 0;
while(globals.STARTED == 0) { while (globals.STARTED == 0) {
switch_yield(100000); switch_yield(100000);
if (++sanity == 10) { if (++sanity == 10) {
break; break;
@ -193,8 +193,8 @@ static switch_status_t timer_init(switch_timer_t *timer)
private_info->roll++; \ private_info->roll++; \
private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick; \ private_info->reference = private_info->start = TIMER_MATRIX[timer->interval].tick; \
} \ } \
static switch_status_t timer_step(switch_timer_t *timer) static switch_status_t timer_step(switch_timer_t *timer)
{ {
timer_private_t *private_info = timer->private_info; timer_private_t *private_info = timer->private_info;
@ -203,7 +203,7 @@ static switch_status_t timer_step(switch_timer_t *timer)
if (globals.RUNNING != 1 || private_info->ready == 0) { if (globals.RUNNING != 1 || private_info->ready == 0) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
check_roll(); check_roll();
samples = timer->samples * (private_info->reference - private_info->start); samples = timer->samples * (private_info->reference - private_info->start);
@ -214,7 +214,7 @@ static switch_status_t timer_step(switch_timer_t *timer)
timer->samplecount = (uint32_t) samples; timer->samplecount = (uint32_t) samples;
private_info->reference++; private_info->reference++;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -234,7 +234,7 @@ static switch_status_t timer_sync(switch_timer_t *timer)
/* push the reference into the future 2 more intervals to prevent collision */ /* push the reference into the future 2 more intervals to prevent collision */
private_info->reference += 2; private_info->reference += 2;
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -249,7 +249,7 @@ static switch_status_t timer_next(switch_timer_t *timer)
check_roll(); check_roll();
switch_yield(1000); switch_yield(1000);
} }
if (globals.RUNNING == 1) { if (globals.RUNNING == 1) {
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -275,8 +275,8 @@ static switch_status_t timer_check(switch_timer_t *timer, switch_bool_t step)
} else { } else {
timer->diff = 0; timer->diff = 0;
} }
if (timer->diff) { if (timer->diff) {
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else if (step) { } else if (step) {
timer_step(timer); timer_step(timer);
@ -311,7 +311,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
memset(&globals, 0, sizeof(globals)); memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
globals.STARTED = globals.RUNNING = 1; globals.STARTED = globals.RUNNING = 1;
switch_mutex_lock(runtime.throttle_mutex); switch_mutex_lock(runtime.throttle_mutex);
runtime.sps = runtime.sps_total; runtime.sps = runtime.sps_total;
@ -319,9 +319,9 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
if (MONO) { if (MONO) {
int loops; int loops;
for(loops = 0; loops < 3; loops++) { for (loops = 0; loops < 3; loops++) {
ts = time_now(0); ts = time_now(0);
/* if it returns the same value every time it won't be of much use.*/ /* if it returns the same value every time it won't be of much use. */
if (ts == last) { if (ts == last) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Broken MONOTONIC Clock Detected!, Support Disabled.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Broken MONOTONIC Clock Detected!, Support Disabled.\n");
MONO = 0; MONO = 0;
@ -337,7 +337,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
ts = 0; ts = 0;
last = 0; last = 0;
fwd_errs = rev_errs = 0; fwd_errs = rev_errs = 0;
while (globals.RUNNING == 1) { while (globals.RUNNING == 1) {
runtime.reference += STEP_MIC; runtime.reference += STEP_MIC;
while ((ts = time_now(runtime.offset)) < runtime.reference) { while ((ts = time_now(runtime.offset)) < runtime.reference) {
@ -346,7 +346,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Virtual Migration Detected! Syncing Clock\n");
switch_time_sync(); switch_time_sync();
} else { } else {
int64_t diff = (int64_t)(ts - last); int64_t diff = (int64_t) (ts - last);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Reverse Clock Skew Detected!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Reverse Clock Skew Detected!\n");
runtime.reference = switch_time_now(); runtime.reference = switch_time_now();
current_ms = 0; current_ms = 0;
@ -359,8 +359,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
} }
switch_yield(STEP_MIC); switch_yield(STEP_MIC);
last = ts; last = ts;
} }
if (ts > (runtime.reference + too_late)) { if (ts > (runtime.reference + too_late)) {
if (MONO) { if (MONO) {
@ -378,7 +378,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
} else { } else {
fwd_errs = 0; fwd_errs = 0;
} }
if (fwd_errs > 9 || rev_errs > 9) { if (fwd_errs > 9 || rev_errs > 9) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Auto Re-Syncing clock.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Auto Re-Syncing clock.\n");
switch_time_sync(); switch_time_sync();
@ -388,7 +388,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
runtime.timestamp = ts; runtime.timestamp = ts;
current_ms += STEP_MS; current_ms += STEP_MS;
tick += STEP_MS; tick += STEP_MS;
if (tick >= 1000) { if (tick >= 1000) {
if (runtime.sps <= 0) { if (runtime.sps <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Rate of %d!\n", runtime.sps_total); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Over Session Rate of %d!\n", runtime.sps_total);
@ -457,7 +457,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown)
switch_yield(10000); switch_yield(10000);
} }
} }
#if defined(WIN32) #if defined(WIN32)
timeEndPeriod(1); timeEndPeriod(1);
#endif #endif

View File

@ -63,7 +63,7 @@ int switch_inet_pton(int af, const char *src, void *dst)
SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, switch_bool_t default_type, switch_memory_pool_t *pool) SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, switch_bool_t default_type, switch_memory_pool_t *pool)
{ {
switch_network_list_t *new_list; switch_network_list_t *new_list;
if (!pool) { if (!pool) {
switch_core_new_memory_pool(&pool); switch_core_new_memory_pool(&pool);
} }
@ -82,7 +82,7 @@ SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip(switch_network_lis
switch_network_node_t *node; switch_network_node_t *node;
switch_bool_t ok = list->default_type; switch_bool_t ok = list->default_type;
uint32_t bits = 0; uint32_t bits = 0;
for (node = list->node_head; node; node = node->next) { for (node = list->node_head; node; node = node->next) {
if (node->bits > bits && switch_test_subnet(ip, node->ip, node->mask)) { if (node->bits > bits && switch_test_subnet(ip, node->ip, node->mask)) {
if (node->ok) { if (node->ok) {
@ -93,7 +93,7 @@ SWITCH_DECLARE(switch_bool_t) switch_network_list_validate_ip(switch_network_lis
bits = node->bits; bits = node->bits;
} }
} }
return ok; return ok;
} }
@ -102,11 +102,11 @@ SWITCH_DECLARE(switch_status_t) switch_network_list_add_cidr(switch_network_list
{ {
uint32_t ip, mask, bits; uint32_t ip, mask, bits;
switch_network_node_t *node; switch_network_node_t *node;
if (switch_parse_cidr(cidr_str, &ip, &mask, &bits)) { if (switch_parse_cidr(cidr_str, &ip, &mask, &bits)) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
node = switch_core_alloc(list->pool, sizeof(*node)); node = switch_core_alloc(list->pool, sizeof(*node));
node->ip = ip; node->ip = ip;
@ -116,7 +116,7 @@ SWITCH_DECLARE(switch_status_t) switch_network_list_add_cidr(switch_network_list
node->next = list->node_head; node->next = list->node_head;
list->node_head = node; list->node_head = node;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -128,21 +128,21 @@ SWITCH_DECLARE(switch_status_t) switch_network_list_add_host_mask(switch_network
switch_inet_pton(AF_INET, host, &ip); switch_inet_pton(AF_INET, host, &ip);
switch_inet_pton(AF_INET, mask_str, &mask); switch_inet_pton(AF_INET, mask_str, &mask);
node = switch_core_alloc(list->pool, sizeof(*node)); node = switch_core_alloc(list->pool, sizeof(*node));
node->ip = ip; node->ip = ip;
node->mask = mask; node->mask = mask;
node->ok = ok; node->ok = ok;
/* http://graphics.stanford.edu/~seander/bithacks.html */ /* http://graphics.stanford.edu/~seander/bithacks.html */
mask = mask - ((mask >> 1) & 0x55555555); mask = mask - ((mask >> 1) & 0x55555555);
mask = (mask & 0x33333333) + ((mask >> 2) & 0x33333333); mask = (mask & 0x33333333) + ((mask >> 2) & 0x33333333);
node->bits = (((mask + (mask >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; node->bits = (((mask + (mask >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
node->next = list->node_head; node->next = list->node_head;
list->node_head = node; list->node_head = node;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -162,7 +162,7 @@ SWITCH_DECLARE(int) switch_parse_cidr(const char *string, uint32_t *ip, uint32_t
*bit_str++ = '\0'; *bit_str++ = '\0';
bits = atoi(bit_str); bits = atoi(bit_str);
if (bits < 0 || bits > 32) { if (bits < 0 || bits > 32) {
return -2; return -2;
} }
@ -180,7 +180,7 @@ SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char clos
{ {
const char *e = NULL; const char *e = NULL;
int depth = 0; int depth = 0;
while (s && *s && *s == ' ') { while (s && *s && *s == ' ') {
s++; s++;
} }
@ -199,7 +199,7 @@ SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char clos
} }
} }
return (char *)e; return (char *) e;
} }
SWITCH_DECLARE(switch_size_t) switch_fd_read_line(int fd, char *buf, switch_size_t len) SWITCH_DECLARE(switch_size_t) switch_fd_read_line(int fd, char *buf, switch_size_t len)
@ -230,10 +230,10 @@ SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len)
q = buf; q = buf;
for(p = s; x < len; p++) { for (p = s; x < len; p++) {
switch(*p) { switch (*p) {
case '<': case '<':
if (x + 4 > len -1) { if (x + 4 > len - 1) {
goto end; goto end;
} }
*q++ = '&'; *q++ = '&';
@ -243,7 +243,7 @@ SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len)
x += 4; x += 4;
break; break;
case '>': case '>':
if (x + 4 > len -1) { if (x + 4 > len - 1) {
goto end; goto end;
} }
*q++ = '&'; *q++ = '&';
@ -253,7 +253,7 @@ SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len)
x += 4; x += 4;
break; break;
default: default:
if (x + 1 > len -1) { if (x + 1 > len - 1) {
goto end; goto end;
} }
*q++ = *p; *q++ = *p;
@ -265,7 +265,7 @@ SWITCH_DECLARE(char *) switch_amp_encode(char *s, char *buf, switch_size_t len)
} }
} }
end: end:
return buf; return buf;
} }
@ -274,33 +274,33 @@ static const char switch_b64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl
#define B64BUFFLEN 1024 #define B64BUFFLEN 1024
SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen) SWITCH_DECLARE(switch_status_t) switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen)
{ {
int y = 0, bytes = 0; int y = 0, bytes = 0;
size_t x = 0; size_t x = 0;
unsigned int b = 0,l = 0; unsigned int b = 0, l = 0;
for(x = 0; x < ilen; x++) { for (x = 0; x < ilen; x++) {
b = (b<<8) + in[x]; b = (b << 8) + in[x];
l += 8; l += 8;
while (l >= 6) { while (l >= 6) {
out[bytes++] = switch_b64_table[(b>>(l-=6))%64]; out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64];
if (++y != 72) { if (++y != 72) {
continue; continue;
} }
//out[bytes++] = '\n'; //out[bytes++] = '\n';
y=0; y = 0;
} }
} }
if (l > 0) { if (l > 0) {
out[bytes++] = switch_b64_table[((b%16)<<(6-l))%64]; out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64];
} }
if (l != 0) { if (l != 0) {
while (l < 6) { while (l < 6) {
out[bytes++] = '=', l += 2; out[bytes++] = '=', l += 2;
} }
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size_t olen) SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size_t olen)
@ -311,16 +311,16 @@ SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size
char *ip, *op = out; char *ip, *op = out;
size_t ol = 0; size_t ol = 0;
for (i=0; i<256; i++) { for (i = 0; i < 256; i++) {
l64[i] = -1; l64[i] = -1;
} }
for (i=0; i<64; i++) { for (i = 0; i < 64; i++) {
l64[(int)switch_b64_table[i]] = (char)i; l64[(int) switch_b64_table[i]] = (char) i;
} }
for (ip = in; ip && *ip; ip++) { for (ip = in; ip && *ip; ip++) {
c = l64[(int)*ip]; c = l64[(int) *ip];
if (c == -1) { if (c == -1) {
continue; continue;
} }
@ -329,14 +329,14 @@ SWITCH_DECLARE(switch_size_t) switch_b64_decode(char *in, char *out, switch_size
l += 6; l += 6;
while (l >= 8) { while (l >= 8) {
op[ol++] = (char)((b >> (l -= 8)) % 256); op[ol++] = (char) ((b >> (l -= 8)) % 256);
if (ol >= olen -2) { if (ol >= olen - 2) {
goto end; goto end;
} }
} }
} }
end: end:
op[ol++] = '\0'; op[ol++] = '\0';
@ -366,40 +366,40 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
unsigned char in[B64BUFFLEN]; unsigned char in[B64BUFFLEN];
unsigned char out[B64BUFFLEN + 512]; unsigned char out[B64BUFFLEN + 512];
switch_snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int)switch_timestamp(NULL), rand() & 0xffff); switch_snprintf(filename, 80, "%smail.%d%04x", SWITCH_GLOBAL_dirs.temp_dir, (int) switch_timestamp(NULL), rand() & 0xffff);
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
if (file) {
if ((ifd = open(file, O_RDONLY)) < 1) {
return SWITCH_FALSE;
}
}
switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
if (!write_buf(fd, buf)) {
return SWITCH_FALSE;
}
if (headers && !write_buf(fd, headers)) if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644))) {
return SWITCH_FALSE; if (file) {
if ((ifd = open(file, O_RDONLY)) < 1) {
return SWITCH_FALSE;
}
}
switch_snprintf(buf, B64BUFFLEN, "MIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"%s\"\n", bound);
if (!write_buf(fd, buf)) {
return SWITCH_FALSE;
}
if (!write_buf(fd, "\n\n")) if (headers && !write_buf(fd, headers))
return SWITCH_FALSE; return SWITCH_FALSE;
if (!write_buf(fd, "\n\n"))
return SWITCH_FALSE;
if (body && switch_stristr("content-type", body)) { if (body && switch_stristr("content-type", body)) {
switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound); switch_snprintf(buf, B64BUFFLEN, "--%s\n", bound);
} else { } else {
switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound); switch_snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
} }
if (!write_buf(fd, buf)) if (!write_buf(fd, buf))
return SWITCH_FALSE; return SWITCH_FALSE;
if (body) { if (body) {
if (!write_buf(fd, body)) { if (!write_buf(fd, body)) {
return SWITCH_FALSE; return SWITCH_FALSE;
} }
} }
if (file) { if (file) {
const char *stipped_file = switch_cut_path(file); const char *stipped_file = switch_cut_path(file);
const char *new_type; const char *new_type;
char *ext; char *ext;
@ -412,82 +412,81 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
} }
switch_snprintf(buf, B64BUFFLEN, switch_snprintf(buf, B64BUFFLEN,
"\n\n--%s\nContent-Type: %s; name=\"%s\"\n" "\n\n--%s\nContent-Type: %s; name=\"%s\"\n"
"Content-ID: <ATTACHED@freeswitch.org>\n" "Content-ID: <ATTACHED@freeswitch.org>\n"
"Content-Transfer-Encoding: base64\n" "Content-Transfer-Encoding: base64\n"
"Content-Description: Sound attachment.\n" "Content-Description: Sound attachment.\n"
"Content-Disposition: attachment; filename=\"%s\"\n\n", "Content-Disposition: attachment; filename=\"%s\"\n\n", bound, mime_type, stipped_file, stipped_file);
bound, mime_type, stipped_file, stipped_file); if (!write_buf(fd, buf))
if (!write_buf(fd, buf)) return SWITCH_FALSE;
return SWITCH_FALSE;
while ((ilen = read(ifd, in, B64BUFFLEN))) { while ((ilen = read(ifd, in, B64BUFFLEN))) {
for (x = 0; x < ilen; x++) { for (x = 0; x < ilen; x++) {
b = (b << 8) + in[x]; b = (b << 8) + in[x];
l += 8; l += 8;
while (l >= 6) { while (l >= 6) {
out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64]; out[bytes++] = switch_b64_table[(b >> (l -= 6)) % 64];
if (++y != 72) if (++y != 72)
continue; continue;
out[bytes++] = '\n'; out[bytes++] = '\n';
y = 0; y = 0;
} }
} }
if (write(fd, &out, bytes) != bytes) { if (write(fd, &out, bytes) != bytes) {
return -1; return -1;
} else } else
bytes = 0; bytes = 0;
} }
if (l > 0) { if (l > 0) {
out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64]; out[bytes++] = switch_b64_table[((b % 16) << (6 - l)) % 64];
} }
if (l != 0) if (l != 0)
while (l < 6) { while (l < 6) {
out[bytes++] = '=', l += 2; out[bytes++] = '=', l += 2;
} }
if (write(fd, &out, bytes) != bytes) { if (write(fd, &out, bytes) != bytes) {
return -1; return -1;
} }
} }
switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound); switch_snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
if (!write_buf(fd, buf)) if (!write_buf(fd, buf))
return SWITCH_FALSE; return SWITCH_FALSE;
} }
if (fd) { if (fd) {
close(fd); close(fd);
} }
if (ifd) { if (ifd) {
close(ifd); close(ifd);
} }
switch_snprintf(buf, B64BUFFLEN, "/bin/cat %s | %s %s %s", filename, runtime.mailer_app, runtime.mailer_app_args, to); switch_snprintf(buf, B64BUFFLEN, "/bin/cat %s | %s %s %s", filename, runtime.mailer_app, runtime.mailer_app_args, to);
if (system(buf)) { if (system(buf)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to execute command: %s\n", buf);
} }
if (unlink(filename) != 0) { if (unlink(filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "failed to delete file [%s]\n", filename); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "failed to delete file [%s]\n", filename);
} }
if (file) { if (file) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed file [%s] to [%s]\n", filename, to);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Emailed data to [%s]\n", to);
} }
return SWITCH_TRUE; return SWITCH_TRUE;
} }
SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip) SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip)
{ {
if (switch_strlen_zero(ip)) return SWITCH_FALSE; if (switch_strlen_zero(ip))
return SWITCH_FALSE;
return ( return (strncmp(ip, "10.", 3) &&
strncmp(ip, "10.", 3) &&
strncmp(ip, "192.168.", 8) && strncmp(ip, "192.168.", 8) &&
strncmp(ip, "127.", 4) && strncmp(ip, "127.", 4) &&
strncmp(ip, "255.", 4) && strncmp(ip, "255.", 4) &&
@ -498,12 +497,8 @@ SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip)
strncmp(ip, "172.17.", 7) && strncmp(ip, "172.17.", 7) &&
strncmp(ip, "172.18.", 7) && strncmp(ip, "172.18.", 7) &&
strncmp(ip, "172.19.", 7) && strncmp(ip, "172.19.", 7) &&
strncmp(ip, "172.2", 5) && strncmp(ip, "172.2", 5) && strncmp(ip, "172.30.", 7) && strncmp(ip, "172.31.", 7) && strncmp(ip, "192.0.2.", 8) && strncmp(ip, "169.254.", 8)
strncmp(ip, "172.30.", 7) && )? SWITCH_FALSE : SWITCH_TRUE;
strncmp(ip, "172.31.", 7) &&
strncmp(ip, "192.0.2.", 8) &&
strncmp(ip, "169.254.", 8)
) ? SWITCH_FALSE : SWITCH_TRUE;
} }
SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len) SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len)
@ -515,10 +510,10 @@ SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len
} }
memset(rbuf, 0, len); memset(rbuf, 0, len);
*(rbuf + strlen(rbuf)) = '^'; *(rbuf + strlen(rbuf)) = '^';
while(p && *p) { while (p && *p) {
if (*p == 'N') { if (*p == 'N') {
strncat(rbuf, "[2-9]", len - strlen(rbuf)); strncat(rbuf, "[2-9]", len - strlen(rbuf));
} else if (*p == 'X') { } else if (*p == 'X') {
@ -534,7 +529,7 @@ SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len
} }
*(rbuf + strlen(rbuf)) = '$'; *(rbuf + strlen(rbuf)) = '$';
return strcmp(pat,rbuf) ? SWITCH_TRUE : SWITCH_FALSE; return strcmp(pat, rbuf) ? SWITCH_TRUE : SWITCH_FALSE;
} }
SWITCH_DECLARE(char *) switch_replace_char(char *str, char from, char to, switch_bool_t dup) SWITCH_DECLARE(char *) switch_replace_char(char *str, char from, char to, switch_bool_t dup)
@ -548,7 +543,7 @@ SWITCH_DECLARE(char *) switch_replace_char(char *str, char from, char to, switch
p = str; p = str;
} }
for(;p && *p; p++) { for (; p && *p; p++) {
if (*p == from) { if (*p == from) {
*p = to; *p = to;
} }
@ -561,23 +556,25 @@ SWITCH_DECLARE(char *) switch_strip_spaces(const char *str)
{ {
const char *sp = str; const char *sp = str;
char *p, *s = NULL; char *p, *s = NULL;
if (!sp) return NULL;
while(*sp == ' ') { if (!sp)
return NULL;
while (*sp == ' ') {
sp++; sp++;
} }
s = strdup(sp); s = strdup(sp);
if (!s) return NULL; if (!s)
return NULL;
p = s + (strlen(s) - 1); p = s + (strlen(s) - 1);
while(*p == ' ') { while (*p == ' ') {
*p-- = '\0'; *p-- = '\0';
} }
return s; return s;
} }
@ -589,12 +586,12 @@ SWITCH_DECLARE(char *) switch_separate_paren_args(char *str)
if ((args = strchr(str, '('))) { if ((args = strchr(str, '('))) {
e = args - 1; e = args - 1;
*args++ = '\0'; *args++ = '\0';
while(*e == ' ') { while (*e == ' ') {
*e-- = '\0'; *e-- = '\0';
} }
e = args; e = args;
br = 1; br = 1;
while(e && *e) { while (e && *e) {
if (*e == '(') { if (*e == '(') {
br++; br++;
} else if (br > 1 && *e == ')') { } else if (br > 1 && *e == ')') {
@ -642,7 +639,7 @@ SWITCH_DECLARE(const char *) switch_stristr(const char *instr, const char *str)
for (start = str; *start; start++) { for (start = str; *start; start++) {
/* find start of pattern in string */ /* find start of pattern in string */
for ( ; ((*start) && (toupper(*start) != toupper(*instr))); start++); for (; ((*start) && (toupper(*start) != toupper(*instr))); start++);
if (!*start) if (!*start)
return NULL; return NULL;
@ -709,8 +706,9 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int fam
getaddrinfo(base, NULL, NULL, &address_info); getaddrinfo(base, NULL, NULL, &address_info);
if (!address_info || WSAIoctl(tmp_socket, if (!address_info || WSAIoctl(tmp_socket,
SIO_ROUTING_INTERFACE_QUERY, SIO_ROUTING_INTERFACE_QUERY,
address_info->ai_addr, (DWORD) address_info->ai_addrlen, &l_address, sizeof(l_address), (LPDWORD) & l_address_len, NULL, NULL)) { address_info->ai_addr, (DWORD) address_info->ai_addrlen, &l_address, sizeof(l_address), (LPDWORD) & l_address_len, NULL,
NULL)) {
closesocket(tmp_socket); closesocket(tmp_socket);
if (address_info) if (address_info)
@ -921,8 +919,7 @@ static const char *switch_inet_ntop6(const unsigned char *src, char *dst, size_t
* author: * author:
* Paul Vixie, 1996. * Paul Vixie, 1996.
*/ */
const char * const char *switch_inet_ntop(int af, void const *src, char *dst, size_t size)
switch_inet_ntop(int af, void const *src, char *dst, size_t size)
{ {
switch (af) { switch (af) {
@ -949,14 +946,12 @@ switch_inet_ntop(int af, void const *src, char *dst, size_t size)
* author: * author:
* Paul Vixie, 1996. * Paul Vixie, 1996.
*/ */
static const char * static const char *switch_inet_ntop4(const unsigned char *src, char *dst, size_t size)
switch_inet_ntop4(const unsigned char *src, char *dst, size_t size)
{ {
static const char fmt[] = "%u.%u.%u.%u"; static const char fmt[] = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"]; char tmp[sizeof "255.255.255.255"];
if (switch_snprintf(tmp, sizeof tmp, fmt, if (switch_snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3]) >= (int) size) {
src[0], src[1], src[2], src[3]) >= (int)size) {
return NULL; return NULL;
} }
@ -970,8 +965,7 @@ switch_inet_ntop4(const unsigned char *src, char *dst, size_t size)
* author: * author:
* Paul Vixie, 1996. * Paul Vixie, 1996.
*/ */
static const char * static const char *switch_inet_ntop6(unsigned char const *src, char *dst, size_t size)
switch_inet_ntop6(unsigned char const *src, char *dst, size_t size)
{ {
/* /*
* Note that int32_t and int16_t need only be "at least" large enough * Note that int32_t and int16_t need only be "at least" large enough
@ -981,14 +975,18 @@ switch_inet_ntop6(unsigned char const *src, char *dst, size_t size)
* to use pointer overlays. All the world's not a VAX. * to use pointer overlays. All the world's not a VAX.
*/ */
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
struct { int base, len; } best = { -1 , 0 }, cur = { -1, 0 }; struct {
int base, len;
} best = {
-1, 0}, cur = {
-1, 0};
unsigned int words[8]; unsigned int words[8];
int i; int i;
/* /*
* Preprocess: * Preprocess:
* Copy the input (bytewise) array into a wordwise array. * Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding. * Find the longest run of 0x00's in src[] for :: shorthanding.
*/ */
for (i = 0; i < 16; i += 2) for (i = 0; i < 16; i += 2)
words[i / 2] = (src[i] << 8) | (src[i + 1]); words[i / 2] = (src[i] << 8) | (src[i + 1]);
@ -1021,8 +1019,7 @@ switch_inet_ntop6(unsigned char const *src, char *dst, size_t size)
tp = tmp; tp = tmp;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
/* Are we inside the best run of 0x00's? */ /* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= best.base && if (best.base != -1 && i >= best.base && i < (best.base + best.len)) {
i < (best.base + best.len)) {
if (i == best.base) if (i == best.base)
*tp++ = ':'; *tp++ = ':';
continue; continue;
@ -1031,9 +1028,8 @@ switch_inet_ntop6(unsigned char const *src, char *dst, size_t size)
if (i != 0) if (i != 0)
*tp++ = ':'; *tp++ = ':';
/* Is this address an encapsulated IPv4? */ /* Is this address an encapsulated IPv4? */
if (i == 6 && best.base == 0 && if (i == 6 && best.base == 0 && (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { if (!inet_ntop4(src + 12, tp, sizeof tmp - (tp - tmp)))
if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
return (NULL); return (NULL);
tp += strlen(tp); tp += strlen(tp);
break; break;
@ -1048,7 +1044,7 @@ switch_inet_ntop6(unsigned char const *src, char *dst, size_t size)
/* /*
* Check for overflow, copy, and we're done. * Check for overflow, copy, and we're done.
*/ */
if ((size_t)(tp - tmp) >= size) { if ((size_t) (tp - tmp) >= size) {
return NULL; return NULL;
} }
@ -1144,20 +1140,20 @@ static char unescape_char(char escaped)
char unescaped; char unescaped;
switch (escaped) { switch (escaped) {
case 'n': case 'n':
unescaped = '\n'; unescaped = '\n';
break; break;
case 'r': case 'r':
unescaped = '\r'; unescaped = '\r';
break; break;
case 't': case 't':
unescaped = '\t'; unescaped = '\t';
break; break;
case 's': case 's':
unescaped = ' '; unescaped = ' ';
break; break;
default: default:
unescaped = escaped; unescaped = escaped;
} }
return unescaped; return unescaped;
} }
@ -1181,8 +1177,8 @@ static char *cleanup_separated_string(char *str, char delim)
int esc = 0; int esc = 0;
if (*ptr == ESCAPE_META) { if (*ptr == ESCAPE_META) {
e = *(ptr+1); e = *(ptr + 1);
if (e == '\'' || e == '"' || (delim && e == delim) || (e = unescape_char(*(ptr+1))) != *(ptr+1)) { if (e == '\'' || e == '"' || (delim && e == delim) || (e = unescape_char(*(ptr + 1))) != *(ptr + 1)) {
++ptr; ++ptr;
*dest++ = e; *dest++ = e;
end = dest; end = dest;
@ -1216,28 +1212,28 @@ static unsigned int separate_string_char_delim(char *buf, char delim, char **arr
unsigned int count = 0; unsigned int count = 0;
char *ptr = buf; char *ptr = buf;
int inside_quotes = 0; int inside_quotes = 0;
unsigned int i; unsigned int i;
while (*ptr && count < arraylen) { while (*ptr && count < arraylen) {
switch (state) { switch (state) {
case START: case START:
array[count++] = ptr; array[count++] = ptr;
state = FIND_DELIM; state = FIND_DELIM;
break; break;
case FIND_DELIM: case FIND_DELIM:
/* escaped characters are copied verbatim to the destination string */ /* escaped characters are copied verbatim to the destination string */
if (*ptr == ESCAPE_META) { if (*ptr == ESCAPE_META) {
++ptr;
} else if (*ptr == '\'') {
inside_quotes = (1 - inside_quotes);
} else if (*ptr == delim && !inside_quotes) {
*ptr = '\0';
state = START;
}
++ptr; ++ptr;
break; } else if (*ptr == '\'') {
inside_quotes = (1 - inside_quotes);
} else if (*ptr == delim && !inside_quotes) {
*ptr = '\0';
state = START;
}
++ptr;
break;
} }
} }
/* strip quotes, escaped chars and leading / trailing spaces */ /* strip quotes, escaped chars and leading / trailing spaces */
@ -1259,43 +1255,43 @@ static unsigned int separate_string_blank_delim(char *buf, char **array, unsigne
unsigned int count = 0; unsigned int count = 0;
char *ptr = buf; char *ptr = buf;
int inside_quotes = 0; int inside_quotes = 0;
unsigned int i; unsigned int i;
while (*ptr && count < arraylen) { while (*ptr && count < arraylen) {
switch (state) { switch (state) {
case START: case START:
array[count++] = ptr; array[count++] = ptr;
state = SKIP_INITIAL_SPACE; state = SKIP_INITIAL_SPACE;
break; break;
case SKIP_INITIAL_SPACE: case SKIP_INITIAL_SPACE:
if (*ptr == ' ') { if (*ptr == ' ') {
++ptr;
} else {
state = FIND_DELIM;
}
break;
case FIND_DELIM:
if (*ptr == ESCAPE_META) {
++ptr;
} else if (*ptr == '\'') {
inside_quotes = (1 - inside_quotes);
} else if (*ptr == ' ' && !inside_quotes) {
*ptr = '\0';
state = SKIP_ENDING_SPACE;
}
++ptr; ++ptr;
break; } else {
state = FIND_DELIM;
}
break;
case SKIP_ENDING_SPACE: case FIND_DELIM:
if (*ptr == ' ') { if (*ptr == ESCAPE_META) {
++ptr; ++ptr;
} else { } else if (*ptr == '\'') {
state = START; inside_quotes = (1 - inside_quotes);
} } else if (*ptr == ' ' && !inside_quotes) {
break; *ptr = '\0';
state = SKIP_ENDING_SPACE;
}
++ptr;
break;
case SKIP_ENDING_SPACE:
if (*ptr == ' ') {
++ptr;
} else {
state = START;
}
break;
} }
} }
/* strip quotes, escaped chars and leading / trailing spaces */ /* strip quotes, escaped chars and leading / trailing spaces */
@ -1311,11 +1307,9 @@ SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char
return 0; return 0;
} }
memset(array, 0, arraylen * sizeof (*array)); memset(array, 0, arraylen * sizeof(*array));
return (delim == ' ' ? return (delim == ' ' ? separate_string_blank_delim(buf, array, arraylen) : separate_string_char_delim(buf, delim, array, arraylen));
separate_string_blank_delim(buf, array, arraylen) :
separate_string_char_delim(buf, delim, array, arraylen));
} }
SWITCH_DECLARE(const char *) switch_cut_path(const char *in) SWITCH_DECLARE(const char *) switch_cut_path(const char *in)
@ -1389,7 +1383,7 @@ SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *sea
return dest; return dest;
} }
SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t * poll, int ms) SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
{ {
int nsds = 0; int nsds = 0;