1 /* 2 * Copyright (c) 2010, Sangoma Technologies 3 * Moises Silva <moy@sangoma.com> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * * Neither the name of the original author; nor the names of any contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef __FTDM_DECLARE_H__ 36 #define __FTDM_DECLARE_H__ 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) 43 #define _XOPEN_SOURCE 600 44 #endif 45 46 #ifndef HAVE_STRINGS_H 47 #define HAVE_STRINGS_H 1 48 #endif 49 #ifndef HAVE_SYS_SOCKET_H 50 #define HAVE_SYS_SOCKET_H 1 51 #endif 52 53 #ifndef __WINDOWS__ 54 #if defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64) 55 #define __WINDOWS__ 56 #endif 57 #endif 58 59 #ifdef _MSC_VER 60 #define __FTDM_FUNC__ __FUNCTION__ 61 #if defined(FT_DECLARE_STATIC) 62 #define FT_DECLARE(type) type __stdcall 63 #define FT_DECLARE_NONSTD(type) type __cdecl 64 #define FT_DECLARE_DATA 65 #elif defined(FREETDM_EXPORTS) 66 #define FT_DECLARE(type) __declspec(dllexport) type __stdcall 67 #define FT_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl 68 #define FT_DECLARE_DATA __declspec(dllexport) 69 #else 70 #define FT_DECLARE(type) __declspec(dllimport) type __stdcall 71 #define FT_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl 72 #define FT_DECLARE_DATA __declspec(dllimport) 73 #endif 74 #define FT_DECLARE_INLINE(type) extern __inline__ type /* why extern? see http://support.microsoft.com/kb/123768 */ 75 #define EX_DECLARE_DATA __declspec(dllexport) 76 #else 77 #define __FTDM_FUNC__ (const char *)__func__ 78 #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(HAVE_VISIBILITY) 79 #define FT_DECLARE(type) __attribute__((visibility("default"))) type 80 #define FT_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type 81 #define FT_DECLARE_DATA __attribute__((visibility("default"))) 82 #else 83 #define FT_DECLARE(type) type 84 #define FT_DECLARE_NONSTD(type) type 85 #define FT_DECLARE_DATA 86 #endif 87 #define FT_DECLARE_INLINE(type) __inline__ type 88 #define EX_DECLARE_DATA 89 #endif 90 91 #ifdef _MSC_VER 92 #ifndef __inline__ 93 #define __inline__ __inline 94 #endif 95 #if (_MSC_VER >= 1400) /* VC8+ */ 96 #ifndef _CRT_SECURE_NO_DEPRECATE 97 #define _CRT_SECURE_NO_DEPRECATE 98 #endif 99 #ifndef _CRT_NONSTDC_NO_DEPRECATE 100 #define _CRT_NONSTDC_NO_DEPRECATE 101 #endif 102 #endif 103 #ifndef strcasecmp 104 #define strcasecmp(s1, s2) _stricmp(s1, s2) 105 #endif 106 #ifndef strncasecmp 107 #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n) 108 #endif 109 #if _MSC_VER < 1900 110 #define snprintf _snprintf 111 #endif 112 #ifndef S_IRUSR 113 #define S_IRUSR _S_IREAD 114 #endif 115 #ifndef S_IWUSR 116 #define S_IWUSR _S_IWRITE 117 #endif 118 #undef HAVE_STRINGS_H 119 #undef HAVE_SYS_SOCKET_H 120 /* disable warning for zero length array in a struct */ 121 /* this will cause errors on c99 and ansi compliant compilers and will need to be fixed in the wanpipe header files */ 122 #pragma warning(disable:4706) 123 #pragma comment(lib, "Winmm") 124 #endif 125 126 /* 127 * Compiler-specific format checking attributes 128 * use these on custom functions that use printf/scanf-style 129 * format strings (e.g. ftdm_log()) 130 */ 131 #if defined(__GNUC__) 132 /** 133 * Enable compiler-specific printf()-style format and argument checks on a function 134 * @param fmtp Position of printf()-style format string parameter 135 * @param argp Position of variable argument list ("...") parameter 136 * @code 137 * void log(const int level, const char *fmt, ...) __ftdm_check_printf(2, 3); 138 * @endcode 139 */ 140 #define __ftdm_check_printf(fmtp, argp) __attribute__((format (printf, fmtp, argp))) 141 /** 142 * Enable compiler-specific scanf()-style format and argument checks on a function 143 * @param fmtp Position of scanf()-style format string parameter 144 * @param argp Position of variable argument list ("...") parameter 145 * @code 146 * void parse(struct foo *ctx, const char *fmt, ...) __ftdm_check_scanf(2, 3); 147 * @endcode 148 */ 149 #define __ftdm_check_scanf(fmtp, argp) __attribute__((format (scanf, fmtp, argp))) 150 #else 151 #define __ftdm_check_printf(fmtp, argp) 152 #define __ftdm_check_scanf(fmtp, argp) 153 #endif 154 155 156 #define FTDM_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) FT_DECLARE(_TYPE) _FUNC1 (const char *name); FT_DECLARE(const char *) _FUNC2 (_TYPE type); 157 #define FTDM_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ 158 FT_DECLARE(_TYPE) _FUNC1 (const char *name) \ 159 { \ 160 int i; \ 161 _TYPE t = _MAX ; \ 162 \ 163 for (i = 0; i < _MAX ; i++) { \ 164 if (!strcasecmp(name, _STRINGS[i])) { \ 165 t = (_TYPE) i; \ 166 break; \ 167 } \ 168 } \ 169 \ 170 return t; \ 171 } \ 172 FT_DECLARE(const char *) _FUNC2 (_TYPE type) \ 173 { \ 174 if (type > _MAX) { \ 175 type = _MAX; \ 176 } \ 177 return _STRINGS[(int)type]; \ 178 } \ 179 180 #ifdef __WINDOWS__ 181 #include <stdio.h> 182 #include <windows.h> 183 #define FTDM_INVALID_SOCKET INVALID_HANDLE_VALUE 184 typedef HANDLE ftdm_socket_t; 185 typedef unsigned __int64 uint64_t; 186 typedef unsigned __int32 uint32_t; 187 typedef unsigned __int16 uint16_t; 188 typedef unsigned __int8 uint8_t; 189 typedef __int64 int64_t; 190 typedef __int32 int32_t; 191 typedef __int16 int16_t; 192 typedef __int8 int8_t; 193 #define FTDM_O_BINARY O_BINARY 194 #define FTDM_SIZE_FMT "Id" 195 #define FTDM_INT64_FMT "lld" 196 #define FTDM_UINT64_FMT "llu" 197 #define FTDM_XINT64_FMT "llx" 198 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 199 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 200 #else 201 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 202 #endif /* _MSC_VER */ 203 #else /* __WINDOWS__ */ 204 #define FTDM_O_BINARY 0 205 #define FTDM_SIZE_FMT "zd" 206 #if (defined(__SIZEOF_LONG__) && (__SIZEOF_LONG__ == 8)) || defined(__LP64__) || defined(__LLP64__) 207 #define FTDM_INT64_FMT "ld" 208 #define FTDM_UINT64_FMT "lu" 209 #define FTDM_XINT64_FMT "lx" 210 #else 211 #define FTDM_INT64_FMT "lld" 212 #define FTDM_UINT64_FMT "llu" 213 #define FTDM_XINT64_FMT "llx" 214 #endif 215 #define FTDM_INVALID_SOCKET -1 216 typedef int ftdm_socket_t; 217 #include <stdio.h> 218 #include <stdint.h> 219 #include <stdarg.h> 220 #endif 221 222 /*! \brief FreeTDM APIs possible return codes */ 223 typedef enum { 224 FTDM_SUCCESS, /*!< Success */ 225 FTDM_FAIL, /*!< Failure, generic error return code when no more specific return code can be used */ 226 227 FTDM_MEMERR, /*!< Allocation failure */ 228 FTDM_ENOMEM = FTDM_MEMERR, 229 230 FTDM_TIMEOUT, /*!< Operation timed out (ie: polling on a device)*/ 231 FTDM_ETIMEDOUT = FTDM_TIMEOUT, 232 233 FTDM_NOTIMPL, /*!< Operation not implemented */ 234 FTDM_ENOSYS = FTDM_NOTIMPL, /*!< The function is not implemented */ 235 236 FTDM_BREAK, /*!< Request the caller to perform a break (context-dependant, ie: stop getting DNIS/ANI) */ 237 238 /*!< Any new return codes should try to mimc unix style error codes, no need to reinvent */ 239 FTDM_EINVAL, /*!< Invalid argument */ 240 FTDM_ECANCELED, /*!< Operation cancelled */ 241 FTDM_EBUSY, /*!< Device busy */ 242 } ftdm_status_t; 243 244 /*! \brief FreeTDM bool type. */ 245 typedef enum { 246 FTDM_FALSE, 247 FTDM_TRUE 248 } ftdm_bool_t; 249 250 /*! \brief I/O waiting flags */ 251 typedef enum { 252 FTDM_NO_FLAGS = 0, 253 FTDM_READ = (1 << 0), 254 FTDM_WRITE = (1 << 1), 255 FTDM_EVENTS = (1 << 2) 256 } ftdm_wait_flag_t; 257 258 /*! 259 * \brief FreeTDM channel. 260 * This is the basic data structure used to place calls and I/O operations 261 */ 262 typedef struct ftdm_channel ftdm_channel_t; 263 264 /*! 265 * \brief FreeTDM span. 266 * Channel and signaling configuration container. 267 * This is a logical span structure, a span may ( or may note ) contain channels 268 * of other physical spans, depending on configuration (freetdm.conf) or if you 269 * are not using configuration depends on how you call ftdm_span_add_channel 270 */ 271 typedef struct ftdm_span ftdm_span_t; 272 273 typedef struct ftdm_event ftdm_event_t; 274 typedef struct ftdm_conf_node ftdm_conf_node_t; 275 typedef struct ftdm_group ftdm_group_t; 276 typedef size_t ftdm_size_t; 277 typedef struct ftdm_sigmsg ftdm_sigmsg_t; 278 typedef struct ftdm_usrmsg ftdm_usrmsg_t; 279 typedef struct ftdm_io_interface ftdm_io_interface_t; 280 typedef struct ftdm_stream_handle ftdm_stream_handle_t; 281 typedef struct ftdm_queue ftdm_queue_t; 282 typedef struct ftdm_memory_handler ftdm_memory_handler_t; 283 284 #ifdef __cplusplus 285 } /* extern C */ 286 #endif 287 288 #endif 289 290 /* For Emacs: 291 * Local Variables: 292 * mode:c 293 * indent-tabs-mode:t 294 * tab-width:4 295 * c-basic-offset:4 296 * End: 297 * For VIM: 298 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: 299 */ 300