diff --git a/libs/freetdm/freetdm.2008.sln b/libs/freetdm/freetdm.2008.sln
index 75e6572252..e0094cbcc5 100644
--- a/libs/freetdm/freetdm.2008.sln
+++ b/libs/freetdm/freetdm.2008.sln
@@ -73,7 +73,6 @@ Global
{BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.ActiveCfg = Release|Win32
{BB833648-BAFF-4BE2-94DB-F8BB043C588C}.Release|Win32.Build.0 = Release|Win32
{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.ActiveCfg = Debug|Win32
- {6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Debug|Win32.Build.0 = Debug|Win32
{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.ActiveCfg = Release|Win32
{6DA6FD42-641D-4147-92F5-3BC4AAA6589B}.Release|Win32.Build.0 = Release|Win32
{FE3540C5-3303-46E0-A69E-D92F775687F1}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -89,7 +88,6 @@ Global
{B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.ActiveCfg = Release|Win32
{B3F49375-2834-4937-9D8C-4AC2EC911010}.Release|Win32.Build.0 = Release|Win32
{729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.ActiveCfg = Debug|Win32
- {729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Debug|Win32.Build.0 = Debug|Win32
{729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.ActiveCfg = Release|Win32
{729344A5-D5E9-434D-8EE8-AF8C6C795D15}.Release|Win32.Build.0 = Release|Win32
{E886B4D5-AB4F-4092-B8F4-3B06E1E462EF}.Debug|Win32.ActiveCfg = Debug|Win32
diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c
index 842bde8347..b5dfdaa952 100644
--- a/libs/freetdm/mod_freetdm/mod_freetdm.c
+++ b/libs/freetdm/mod_freetdm/mod_freetdm.c
@@ -241,7 +241,7 @@ static void cycle_foreground(ftdm_channel_t *ftdmchan, int flash, const char *bc
switch_core_session_t *session;
switch_channel_t *channel;
private_t *tech_pvt;
- int32_t tokencnt = ftdm_channel_get_token_count(ftdmchan);
+ uint32_t tokencnt = ftdm_channel_get_token_count(ftdmchan);
for (i = 0; i < tokencnt; i++) {
diff --git a/libs/freetdm/msvc/freetdm.2008.vcproj b/libs/freetdm/msvc/freetdm.2008.vcproj
index 801c368aef..848be23e90 100644
--- a/libs/freetdm/msvc/freetdm.2008.vcproj
+++ b/libs/freetdm/msvc/freetdm.2008.vcproj
@@ -1,459 +1,471 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c
index e980ab8936..3715e9844c 100644
--- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c
+++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c
@@ -38,7 +38,7 @@
#define __EXTENSIONS__
#endif
-#include "freetdm.h"
+#include "private/ftdm_core.h"
#include "Q931.h"
#include "Q921.h"
#ifdef WIN32
diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj
index b7698ec7a7..4597b1f107 100644
--- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj
+++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.2008.vcproj
@@ -1,355 +1,355 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h
index c3bf93392d..28895f8097 100644
--- a/libs/freetdm/src/include/freetdm.h
+++ b/libs/freetdm/src/include/freetdm.h
@@ -412,13 +412,13 @@ typedef void *(*ftdm_malloc_func_t)(void *pool, ftdm_size_t len);
typedef void *(*ftdm_calloc_func_t)(void *pool, ftdm_size_t elements, ftdm_size_t len);
typedef void *(*ftdm_realloc_func_t)(void *pool, void *buff, ftdm_size_t len);
typedef void (*ftdm_free_func_t)(void *pool, void *ptr);
-typedef struct ftdm_memory_handler {
+struct ftdm_memory_handler {
void *pool;
ftdm_malloc_func_t malloc;
ftdm_calloc_func_t calloc;
ftdm_realloc_func_t realloc;
ftdm_free_func_t free;
-} ftdm_memory_handler_t;
+};
/*! \brief FreeTDM I/O layer interface argument macros
diff --git a/libs/freetdm/src/include/ftdm_declare.h b/libs/freetdm/src/include/ftdm_declare.h
index 3f8849d4c1..849e3f91bc 100644
--- a/libs/freetdm/src/include/ftdm_declare.h
+++ b/libs/freetdm/src/include/ftdm_declare.h
@@ -39,7 +39,16 @@
extern "C" {
#endif
-/* ######## start utility macros not to be used by customers, but needed in this header, may be move to another header ############ */
+#if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__)
+#define _XOPEN_SOURCE 600
+#endif
+
+#ifndef HAVE_STRINGS_H
+#define HAVE_STRINGS_H 1
+#endif
+#ifndef HAVE_SYS_SOCKET_H
+#define HAVE_SYS_SOCKET_H 1
+#endif
#ifndef __WINDOWS__
#if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
@@ -75,6 +84,41 @@ extern "C" {
#define EX_DECLARE_DATA
#endif
+#ifdef _MSC_VER
+#ifndef __inline__
+#define __inline__ __inline
+#endif
+#if (_MSC_VER >= 1400) /* VC8+ */
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE
+#endif
+#ifndef _CRT_NONSTDC_NO_DEPRECATE
+#define _CRT_NONSTDC_NO_DEPRECATE
+#endif
+#endif
+#ifndef strcasecmp
+#define strcasecmp(s1, s2) _stricmp(s1, s2)
+#endif
+#ifndef strncasecmp
+#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
+#endif
+#ifndef snprintf
+#define snprintf _snprintf
+#endif
+#ifndef S_IRUSR
+#define S_IRUSR _S_IREAD
+#endif
+#ifndef S_IWUSR
+#define S_IWUSR _S_IWRITE
+#endif
+#undef HAVE_STRINGS_H
+#undef HAVE_SYS_SOCKET_H
+/* disable warning for zero length array in a struct */
+/* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */
+#pragma warning(disable:4706)
+#pragma comment(lib, "Winmm")
+#endif
+
#define FTDM_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) FT_DECLARE(_TYPE) _FUNC1 (const char *name); FT_DECLARE(const char *) _FUNC2 (_TYPE type);
#define FTDM_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \
FT_DECLARE(_TYPE) _FUNC1 (const char *name) \
@@ -100,6 +144,7 @@ extern "C" {
} \
#ifdef WIN32
+#include
#include
#define FTDM_INVALID_SOCKET INVALID_HANDLE_VALUE
typedef HANDLE ftdm_socket_t;
@@ -142,6 +187,7 @@ typedef struct ftdm_sigmsg ftdm_sigmsg_t;
typedef struct ftdm_io_interface ftdm_io_interface_t;
typedef struct ftdm_stream_handle ftdm_stream_handle_t;
typedef struct ftdm_queue ftdm_queue_t;
+typedef struct ftdm_memory_handler ftdm_memory_handler_t;
#ifdef __cplusplus
} /* extern C */
diff --git a/libs/freetdm/src/include/ftdm_os.h b/libs/freetdm/src/include/ftdm_os.h
index 78f484fa28..8308e70705 100644
--- a/libs/freetdm/src/include/ftdm_os.h
+++ b/libs/freetdm/src/include/ftdm_os.h
@@ -48,17 +48,67 @@ extern "C" {
#include
#endif
+/*! \brief sleep x amount of milliseconds */
#ifdef __WINDOWS__
#define ftdm_sleep(x) Sleep(x)
#else
#define ftdm_sleep(x) usleep(x * 1000)
#endif
+/*! \brief strncpy replacement */
#define ftdm_copy_string(x,y,z) strncpy(x, y, z - 1)
+
+/*! \brief strncpy into a fixed-length buffer */
#define ftdm_set_string(x,y) strncpy(x, y, sizeof(x)-1)
+
+/*! \brief check for null or zero length string buffer */
#define ftdm_strlen_zero(s) (!s || *s == '\0')
+
+/*! \brief check for zero length string buffer */
#define ftdm_strlen_zero_buf(s) (*s == '\0')
+/*! \brief The memory handler.
+ Do not use directly this variable, use the memory macros and ftdm_global_set_memory_handler to override */
+FT_DECLARE_DATA extern ftdm_memory_handler_t g_ftdm_mem_handler;
+
+/*!
+ \brief Allocate uninitialized memory
+ \param chunksize the chunk size
+*/
+#define ftdm_malloc(chunksize) g_ftdm_mem_handler.malloc(g_ftdm_mem_handler.pool, chunksize)
+
+/*!
+ \brief Reallocates memory
+ \param buff the buffer
+ \param chunksize the chunk size
+*/
+#define ftdm_realloc(buff, chunksize) g_ftdm_mem_handler.realloc(g_ftdm_mem_handler.pool, buff, chunksize)
+
+/*!
+ \brief Allocate initialized memory
+ \param chunksize the chunk size
+*/
+#define ftdm_calloc(elements, chunksize) g_ftdm_mem_handler.calloc(g_ftdm_mem_handler.pool, elements, chunksize)
+
+/*!
+ \brief Free chunk of memory
+ \param chunksize the chunk size
+*/
+#define ftdm_free(chunk) g_ftdm_mem_handler.free(g_ftdm_mem_handler.pool, chunk)
+
+/*!
+ \brief Free a pointer and set it to NULL unless it already is NULL
+ \param it the pointer
+*/
+#define ftdm_safe_free(it) if (it) { ftdm_free(it); it = NULL; }
+
+/*! \brief Duplicate string */
+FT_DECLARE(char *) ftdm_strdup(const char *str);
+
+/*! \brief Duplicate string with limit */
+FT_DECLARE(char *) ftdm_strndup(const char *str, ftdm_size_t inlen);
+
+
#ifdef __cplusplus
} /* extern C */
#endif
diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h
index d62c0ae921..d690b1c8a5 100644
--- a/libs/freetdm/src/include/private/ftdm_core.h
+++ b/libs/freetdm/src/include/private/ftdm_core.h
@@ -32,6 +32,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "freetdm.h"
+
#ifndef __PRIVATE_FTDM_CORE__
#define __PRIVATE_FTDM_CORE__
@@ -500,12 +502,6 @@ struct ftdm_group {
FT_DECLARE_DATA extern ftdm_crash_policy_t g_ftdm_crash_policy;
-FT_DECLARE_DATA extern ftdm_memory_handler_t g_ftdm_mem_handler;
-
-/*! \brief Duplicate string */
-FT_DECLARE(char *) ftdm_strdup(const char *str);
-FT_DECLARE(char *) ftdm_strndup(const char *str, ftdm_size_t inlen);
-
FT_DECLARE(ftdm_size_t) ftdm_fsk_modulator_generate_bit(ftdm_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, ftdm_size_t buflen);
FT_DECLARE(int32_t) ftdm_fsk_modulator_generate_carrier_bits(ftdm_fsk_modulator_t *fsk_trans, uint32_t bits);
FT_DECLARE(void) ftdm_fsk_modulator_generate_chan_sieze(ftdm_fsk_modulator_t *fsk_trans);
@@ -598,37 +594,6 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan);
} \
}
-/*!
- \brief Allocate uninitialized memory
- \command chunksize the chunk size
-*/
-#define ftdm_malloc(chunksize) g_ftdm_mem_handler.malloc(g_ftdm_mem_handler.pool, chunksize)
-
-/*!
- \brief Reallocates memory
- \command buff the buffer
- \command chunksize the chunk size
-*/
-#define ftdm_realloc(buff, chunksize) g_ftdm_mem_handler.realloc(g_ftdm_mem_handler.pool, buff, chunksize)
-
-/*!
- \brief Allocate initialized memory
- \command chunksize the chunk size
-*/
-#define ftdm_calloc(elements, chunksize) g_ftdm_mem_handler.calloc(g_ftdm_mem_handler.pool, elements, chunksize)
-
-/*!
- \brief Free chunk of memory
- \command chunksize the chunk size
-*/
-#define ftdm_free(chunk) g_ftdm_mem_handler.free(g_ftdm_mem_handler.pool, chunk)
-
-/*!
- \brief Free a pointer and set it to NULL unless it already is NULL
- \command it the pointer
-*/
-#define ftdm_safe_free(it) if (it) { ftdm_free(it); it = NULL; }
-
/*!
\brief Socket the given socket
\command it the socket
diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c
index 83bace9b4a..84d09f73c9 100644
--- a/libs/freetdm/src/testanalog.c
+++ b/libs/freetdm/src/testanalog.c
@@ -9,7 +9,7 @@ static void *test_call(ftdm_thread_t *me, void *obj)
ftdm_channel_t *chan = (ftdm_channel_t *) obj;
uint8_t frame[1024];
ftdm_size_t len;
- char *number = strdup("5551212");
+ char *number = ftdm_strdup("5551212");
ftdm_sleep(10 * 1000);
@@ -40,7 +40,7 @@ static void *test_call(ftdm_thread_t *me, void *obj)
}
ftdm_log(FTDM_LOG_DEBUG, "call over\n");
- free(number);
+ ftdm_safe_free(number);
return NULL;
}