1 /* Copyright (C) 2002 GFRN systems 2 3 This program is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public License as 5 published by the Free Software Foundation; either version 2 of the 6 License, or (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, but 9 WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 16 02111-1307, USA. 17 18 The latest version of this program may be found at 19 http://CQiNet.sourceforge.net 20 21 This is the common header for all project files. 22 23 $Log: common.h,v $ 24 Revision 1.25 2009/09/13 19:48:52 wb6ymh 25 Added DLOG_PTT. 26 27 Revision 1.24 2009/05/25 16:19:26 wb6ymh 28 Added DLOG_RX_CTCSS. 29 30 Revision 1.23 2009/05/24 03:55:58 beta2k 31 Added ERR_SPAWN_FAIL 32 33 Revision 1.22 2009/03/28 15:36:51 wb6ymh 34 Added PATH_MAX checks from va3jss. 35 36 Revision 1.21 2009/02/16 00:22:34 wb6ymh 37 Added DLOG_RTP. 38 39 Revision 1.20 2009/02/13 19:22:04 wb6ymh 40 Added DLOG_TBURST. 41 42 Revision 1.19 2008/12/30 00:20:13 wb6ymh 43 Added DLOG_COS_CTSS, ERR_SERIAL_SHARE_ERR, ERR_NOT_SUPPORTED. 44 45 Revision 1.18 2008/06/26 20:44:12 wb6ymh 46 Added DLOG_LINKS, DLOG_DTMF, DLOG_EVENTS. 47 48 Revision 1.17 2008/06/15 13:35:37 wb6ymh 49 LogErr -> Log for Windoze builds. 50 51 Revision 1.16 2008/05/14 18:12:59 wb6ymh 52 1. Changed a bunch of functions to take const char * rather than char * 53 to fix compile problems with GCC 4.2.x. 54 2. Added LogHex, DLOG_RIG_CTRL. 55 3. Changed Debug to unsigned int. 56 57 Revision 1.15 2008/04/25 00:04:49 wb6ymh 58 Added ERR_CTCSS_RX_INIT. 59 60 Revision 1.14 2008/04/11 16:54:31 wb6ymh 61 Added DLOG_TONEGEN. 62 63 Revision 1.13 2008/03/11 14:03:50 wb6ymh 64 Added DLOG_VOIP_AUDIO. 65 66 Revision 1.12 2008/03/09 15:59:41 wb6ymh 67 Added min, max and CORE_DUMP. 68 69 Revision 1.11 2008/02/26 18:04:04 wb6ymh 70 1. Added DLOG macro to allow logging to be conditioned on new config 71 variable Debug. 72 2. Added Debug and DLOG_CODEC_TYPE. 73 74 Revision 1.10 2007/12/01 00:55:52 wb6ymh 75 1. Move STRCMP macro here from various places. 76 2. Added DFLUSH macro. 77 78 Revision 1.9 2007/11/26 06:58:13 wb6ymh 79 Added extern "C" around prototypes when compiled for C++. 80 81 Revision 1.8 2007/11/21 17:27:47 wb6ymh 82 Added ERR_INPUT_DEV_OPEN, ERR_USB_DEV_OPEN, ERR_KRLP_LOCKFILE_OPEN. 83 84 Revision 1.7 2007/06/12 23:38:59 wb6ymh 85 1. Added PATH_SEP, new error codes for thelinkbox. 86 2. Added typedefs for basic integer types. 87 88 Revision 1.6 2006/08/05 23:50:08 wb6ymh 89 Added #define for socklen_t for Windoze builds. 90 91 Revision 1.5 2003/08/16 13:45:59 wb6ymh 92 Added FOPEN macro. 93 Moved prototypes for Log(), CloseLog() outside of _WIN32 ifdef. 94 Added ERR_DECOMPRESS_ERR. 95 96 Revision 1.4 2003/04/30 22:06:12 wb6ymh 97 Added ERR_BIND_IP. 98 99 Revision 1.3 2002/12/18 00:49:54 wb6ymh 100 Enabled logging for Windows. 101 Added ERR_SERVICE_OPTION. 102 103 Revision 1.2 2002/11/02 19:06:51 wb6ymh 104 Added ERR_CMD_LINE_OPTION. 105 106 Revision 1.1.1.1 2002/10/06 17:00:22 wb6ymh 107 Move common header files to inc subdirectory from src. 108 109 Revision 1.6 2002/09/14 16:42:57 wb6ymh 110 Added ERR_WORKING_DIR. 111 112 Revision 1.5 2002/09/02 15:18:44 wb6ymh 113 Added ERR_SERVER_TIMEOUT. 114 115 Revision 1.4 2002/08/31 23:38:15 wb6ymh 116 Added MODE_RD_BIN, ERROR_CODE2MSG, ERR_SERVER_ERR. 117 118 Revision 1.3 2002/08/15 05:34:17 wb6ymh 119 Added #define OUR_HOST for Windows build 120 121 Revision 1.2 2002/08/12 17:10:47 wb6ymh 122 Made TimeNow a global. 123 Removed argument to GetTimeNow(). 124 125 Revision 1.1.1.1 2002/08/10 20:33:41 wb6ymh 126 initial import 127 128 */ 129 130 #ifndef COMMON_H_ 131 #define COMMON_H_ 132 133 #ifndef _WIN32 134 // FreeBSD, Linux, etc.. 135 #include <config.h> 136 #include <stdio.h> 137 #define READ(x,y,z) read(x,y,z) 138 #define WRITE(x,y,z) write(x,y,z) 139 #define CLOSE(x) close(x) 140 #define ERROR_CODE errno 141 #define ERROR_WOULD_BLOCK EAGAIN 142 #define ERROR_CONNECTED EISCONN 143 #define ERROR_IN_PROGRESS EINPROGRESS 144 #define SOCKET_ERROR -1 145 #define SOCKET int 146 #define INVALID_SOCKET -1 147 #define MODE_WRITE_TXT "w" 148 #define MODE_WRITE_BIN "w" 149 #define MODE_RDWR_BIN "w+" 150 #define MODE_RD_BIN "r" 151 #define ERROR_CODE2MSG "%m" 152 #define PATH_SEP '/' 153 #ifndef PATH_MAX 154 #define PATH_MAX 124 155 #endif 156 FILE *FOPEN(const char *fmt,const char *mode); 157 #else 158 // Windoze 159 #include <config.h.win32> 160 // The following defines replace config.h for Windows 161 #define HAVE_FTIME 162 #define HAVE_STRICMP 163 #define READ(x,y,z) recv(x,y,z,0) 164 #define WRITE(x,y,z) send(x,y,z,0) 165 #define CLOSE(x) closesocket(x) 166 #define ERROR_CODE WSAGetLastError() 167 #define ERROR_WOULD_BLOCK WSAEWOULDBLOCK 168 #define ERROR_CONNECTED WSAEISCONN 169 #define ERROR_IN_PROGRESS WSAEWOULDBLOCK 170 #define snprintf _snprintf 171 #define vsnprintf _vsnprintf 172 #define MODE_WRITE_TXT "w" 173 #define MODE_WRITE_BIN "wb" 174 #define MODE_RDWR_BIN "w+b" 175 #define MODE_RD_BIN "rb" 176 #define ERROR_CODE2MSG "err=%d.\n" 177 #define OUR_HOST "Windows" 178 #define FOPEN fopen 179 #define socklen_t size_t 180 #define PATH_SEP '\\' 181 #ifndef PATH_MAX 182 #define PATH_MAX 124 183 #endif 184 #endif 185 186 // Use a non-case sensitive compare function if one is available 187 #ifdef HAVE_STRICMP 188 #define STRCMP stricmp 189 #else 190 #ifdef HAVE_STRCASECMP 191 #define STRCMP strcasecmp 192 #else 193 #define STRCMP strcmp 194 #endif 195 #endif 196 197 #ifdef __cplusplus 198 extern "C" { 199 #endif 200 201 202 #ifndef FALSE 203 #define FALSE 0 204 #endif 205 206 #ifndef TRUE 207 #define TRUE !FALSE 208 #endif 209 210 #define DPRINTF(x) if(DebugLevel) printf x 211 #define D2PRINTF(x) if(DebugLevel > 1) printf x 212 #define D3PRINTF(x) if(DebugLevel > 2) printf x 213 214 #define DFLUSH() if(DebugLevel > 0) fflush(stdout) 215 216 #ifndef _WIN32 217 void LogNorm(const char *fmt, ...); 218 void LogWarn(const char *fmt, ...); 219 void LogErr(const char *fmt, ...); 220 #define LOG_NORM(x) LogNorm x 221 #define LOG_WARN(x) LogWarn x 222 #define LOG_ERROR(x) LogErr x 223 #define DLOG(x,y) if(Debug & x) LogErr y 224 #else 225 #define LOG_NORM(x) Log x 226 #define LOG_WARN(x) Log x 227 #define LOG_ERROR(x) Log x 228 #define DLOG(x,y) if(Debug & x) Log y 229 #endif 230 231 void LogHex(void *AdrIn,int Len); 232 233 #ifndef min 234 #define min(a,b) (((a) < (b)) ? (a) : (b)) 235 #endif /* min */ 236 237 #ifndef max 238 #define max(a,b) (((a) > (b)) ? (a) : (b)) 239 #endif /* min */ 240 241 // Bits for DLOG 242 #define DLOG_CODEC_TYPE 0x8 // Verbose logging of RTP SF codec problems 243 #define DLOG_VOIP_AUDIO 0x10 // Verbose audio queuing in voip.cpp 244 #define DLOG_TONEGEN 0x20 // Verbose tonegen parser logging 245 #define DLOG_RIG_CTRL 0x40 // Verbose frequency control logging 246 #define DLOG_LINKS 0x80 // Verbose node linking logging 247 #define DLOG_DTMF 0x100 // Verbose DTMF and command decoding logging 248 #define DLOG_EVENTS 0x200 // Verbose event generation logging 249 #define DLOG_COS_CTCSS 0x400 // Verbose cos and ctcss detect logging 250 #define DLOG_TBURST 0x800 // Verbose tone burst access logging 251 #define DLOG_RTP 0x1000 // Verbose RTP sequence number logging 252 #define DLOG_RX_CTCSS 0x2000 // Verbose software CTCSS logging 253 #define DLOG_PTT 0x4000 // Verbose PTT logging 254 255 // Local Error codes 256 #define ERR_LOCAL_BASE 100000 257 #define ERR_CONNECTION_CLOSED ERR_LOCAL_BASE + 1 258 #define ERR_CONFIG_FILE ERR_LOCAL_BASE + 2 259 #define ERR_CREATE_AVL ERR_LOCAL_BASE + 3 260 #define ERR_SERVER_ERR ERR_LOCAL_BASE + 4 261 #define ERR_SERVER_TIMEOUT ERR_LOCAL_BASE + 5 262 #define ERR_WORKING_DIR ERR_LOCAL_BASE + 6 263 #define ERR_AVL_CREATE ERR_LOCAL_BASE + 7 264 #define ERR_MALLOC ERR_LOCAL_BASE + 8 265 #define ERR_CMD_LINE_OPTION ERR_LOCAL_BASE + 9 266 #define ERR_SERVICE_OPTION ERR_LOCAL_BASE + 10 267 #define ERR_BIND_IP ERR_LOCAL_BASE + 11 268 #define ERR_DECOMPRESS_ERR ERR_LOCAL_BASE + 12 269 #define ERR_AUDIO_DEV_OPEN ERR_LOCAL_BASE + 13 270 #define ERR_AUDIO_FMT ERR_LOCAL_BASE + 14 271 #define ERR_GSM_INIT ERR_LOCAL_BASE + 15 272 #define ERR_SERIAL_DEV_OPEN ERR_LOCAL_BASE + 16 273 #define ERR_SERIAL_GET_ATTR ERR_LOCAL_BASE + 17 274 #define ERR_SERIAL_SET_ATTR ERR_LOCAL_BASE + 18 275 #define ERR_SERIAL_SET_BAUD ERR_LOCAL_BASE + 19 276 #define ERR_AUDIO_SET_FRAG ERR_LOCAL_BASE + 20 277 #define ERR_IRLP_DEV_OPEN ERR_LOCAL_BASE + 21 278 #define ERR_IRLP_DEV_CLAIM ERR_LOCAL_BASE + 22 279 #define ERR_INPUT_DEV_OPEN ERR_LOCAL_BASE + 23 280 #define ERR_USB_DEV_OPEN ERR_LOCAL_BASE + 24 281 #define ERR_IRLP_LOCKFILE_OPEN ERR_LOCAL_BASE + 25 282 #define ERR_CTCSS_RX_INIT ERR_LOCAL_BASE + 26 283 #define ERR_SERIAL_SHARE_ERR ERR_LOCAL_BASE + 27 284 #define ERR_NOT_SUPPORTED ERR_LOCAL_BASE + 28 285 #define ERR_SPAWN_FAIL ERR_LOCAL_BASE + 29 286 287 288 /* 289 * The type definitions below are valid for 32-bit architectures and 290 * may have to be adjusted for 16- or 64-bit architectures. 291 */ 292 typedef unsigned char u_int8; 293 typedef unsigned short u_int16; 294 typedef unsigned int u_int32; 295 typedef short int16; 296 297 extern int DebugLevel; // 0 = no debug, 1 = debug, 2 = more debug ... 298 // Same as above but a bit map, bottom 3 bits are the same as DebugLevel 299 extern unsigned int Debug; 300 301 int ReadConfig(); 302 void Log(char *fmt, ...); 303 void CloseLog(); 304 305 #define CORE_DUMP() \ 306 LOG_ERROR(("%s#%d: dumping core\n",__FUNCTION__,__LINE__)); \ 307 DumpMe() 308 309 #ifdef __cplusplus 310 } 311 #endif 312 313 #endif 314