1 /* 2 * $Id: sipsak.h 397 2006-01-28 21:11:50Z calrissian $ 3 * 4 * Copyright (C) 2002-2004 Fhg Fokus 5 * Copyright (C) 2004-2005 Nils Ohlmeier 6 * 7 * This file belongs to sipsak, a free sip testing tool. 8 * 9 * sipsak is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * sipsak is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 */ 19 20 #ifndef SIPSAK_H 21 #define SIPSAK_H 22 23 #if HAVE_CONFIG_H 24 # include "config.h" 25 #endif 26 27 #ifdef HAVE_STDIO_H 28 # include <stdio.h> 29 #endif 30 #ifdef HAVE_STDLIB_H 31 # include <stdlib.h> 32 #endif 33 #ifdef HAVE_SYS_TYPES_H 34 # include <sys/types.h> 35 #endif 36 #ifdef HAVE_REGEX_H 37 # include <regex.h> 38 #endif 39 #ifdef HAVE_SYS_PARAM_H 40 # include <sys/param.h> 41 #endif 42 #ifdef HAVE_NETINET_IN_H 43 # include <netinet/in.h> 44 #endif 45 #ifndef INET_ADDRSTRLEN 46 # define INET_ADDRSTRLEN 16 47 #endif 48 #ifdef HAVE_SIGNAL_H 49 # include <signal.h> 50 #endif 51 52 #ifdef HAVE_LIMITS_H 53 # include <limits.h> 54 #endif 55 #ifndef INT_MAX 56 # define INT_MAX 2147483648 57 #endif 58 59 #ifdef HAVE_STRCASESTR 60 # define __USE_GNU 61 # define STRCASESTR(s1,s2) strcasestr(s1,s2) 62 #else 63 # define STRCASESTR(s1,s2) strstr(s1,s2) 64 #endif 65 #ifdef HAVE_STRNCASECMP 66 # define STRNCASECMP(s1,s2,s3) strncasecmp(s1,s2,s3) 67 #else 68 # define STRNCASECMP(s1,s2,s3) strncmp(s1,s2,s3) 69 #endif 70 #ifdef HAVE_STRING_H 71 # include <string.h> 72 #endif 73 74 #ifdef HAVE_GNUTLS 75 # define HAVE_EXTERNAL_MD5 76 #else 77 # ifdef HAVE_OPENSSL_MD5_H 78 # ifdef HAVE_CRYPTO_WITH_MD5 79 # define HAVE_FULL_OPENSSL 80 # define HAVE_EXTERNAL_MD5 81 # endif 82 # endif 83 #endif 84 85 #ifdef HAVE_OPENSSL_SHA_H 86 # ifdef HAVE_CRYPTO_WITH_SHA1 87 # define HAVE_OPENSSL_SHA1 88 # endif 89 #endif 90 91 #ifndef REG_NOERROR 92 # define REG_NOERROR 0 93 #endif 94 95 #ifdef HAVE_SYS_PARAM_H 96 # ifdef MAXHOSTNAMELEN 97 # define FQDN_SIZE MAXHOSTNAMELEN + 1 98 # else 99 # define FQDN_SIZE 100 100 # endif 101 #else 102 # define FQDN_SIZE 100 103 #endif 104 105 #ifdef HAVE_CONFIG_H 106 # define SIP_T1 DEFAULT_TIMEOUT 107 #else 108 # define SIP_T1 500 109 #endif 110 111 #define SIP_T2 8*SIP_T1 112 113 #define SIPSAK_VERSION PACKAGE_VERSION 114 #define BUFSIZE 4096 115 116 #define SIPSAK_MAX_PASSWD_LEN 20 117 118 #define REQ_REG 1 119 #define REQ_REM 2 120 #define REQ_INV 3 121 #define REQ_MES 4 122 #define REQ_OPT 5 123 #define REQ_FLOOD 6 124 #define REQ_RAND 7 125 126 #undef WITH_TLS_TRANSP 127 128 #define SIP_TLS_TRANSPORT 1 129 #define SIP_TCP_TRANSPORT 2 130 #define SIP_UDP_TRANSPORT 3 131 132 #define TRANSPORT_TLS_STR "TLS" 133 #define TRANSPORT_TCP_STR "TCP" 134 #define TRANSPORT_UDP_STR "UDP" 135 #define TRANSPORT_STR_LEN 3 136 137 #define VIA_SIP_STR "Via: SIP/2.0/" 138 #define VIA_SIP_STR_LEN (sizeof(VIA_SIP_STR) - 1) 139 140 #define SIP20_STR " SIP/2.0\r\n" 141 #define SIP20_STR_LEN (sizeof(SIP20_STR) - 1) 142 143 #define SIP200_STR "SIP/2.0 200 OK\r\n" 144 #define SIP200_STR_LEN (sizeof(SIP200_STR) - 1) 145 146 #define INV_STR "INVITE" 147 #define INV_STR_LEN (sizeof(INV_STR) - 1) 148 149 #define REG_STR "REGISTER" 150 #define REG_STR_LEN (sizeof(REG_STR) - 1) 151 152 #define OPT_STR "OPTIONS" 153 #define OPT_STR_LEN (sizeof(OPT_STR) - 1) 154 155 #define MES_STR "MESSAGE" 156 #define MES_STR_LEN (sizeof(MES_STR) - 1) 157 158 #define ACK_STR "ACK" 159 #define ACK_STR_LEN (sizeof(ACK_STR) - 1) 160 161 #define FROM_STR "From: " 162 #define FROM_STR_LEN (sizeof(FROM_STR) - 1) 163 #define FROM_SHORT_STR "\nf: " 164 #define FROM_SHORT_STR_LEN (sizeof(FROM_SHORT_STR) - 1) 165 166 #define TO_STR "To: " 167 #define TO_STR_LEN (sizeof(TO_STR) - 1) 168 #define TO_SHORT_STR "\nt: " 169 #define TO_SHORT_STR_LEN (sizeof(TO_SHORT_STR) - 1) 170 171 #define VIA_STR "Via: " 172 #define VIA_STR_LEN (sizeof(VIA_STR) - 1) 173 #define VIA_SHORT_STR "\nv: " 174 #define VIA_SHORT_STR_LEN (sizeof(VIA_SHORT_STR) - 1) 175 176 #define CALL_STR "Call-ID: " 177 #define CALL_STR_LEN (sizeof(CALL_STR) - 1) 178 #define CALL_SHORT_STR "\ni: " 179 #define CALL_SHORT_STR_LEN (sizeof(CALL_SHORT_STR) - 1) 180 181 #define MAX_FRW_STR "Max-Forwards: " 182 #define MAX_FRW_STR_LEN (sizeof(MAX_FRW_STR) - 1) 183 184 #define CSEQ_STR "CSeq: " 185 #define CSEQ_STR_LEN (sizeof(CSEQ_STR) - 1) 186 187 #define CONT_STR "Contact: " 188 #define CONT_STR_LEN (sizeof(CONT_STR) - 1) 189 #define CONT_SHORT_STR "\nm: " 190 #define CONT_SHORT_STR_LEN (sizeof(CONT_SHORT_STR) - 1) 191 192 #define CON_TYP_STR "Content-Type: " 193 #define CON_TYP_STR_LEN (sizeof(CON_TYP_STR) - 1) 194 #define CON_TYP_SHORT_STR "\nc: " 195 #define CON_TYP_SHORT_STR_LEN (sizeof(CON_TYP_SHORT_STR) - 1) 196 197 #define CON_DIS_STR "Content-Disposition: " 198 #define CON_DIS_STR_LEN (sizeof(CON_DIS_STR) - 1) 199 200 #define TXT_PLA_STR "text/plain" 201 #define TXT_PLA_STR_LEN (sizeof(TXT_PLA_STR) - 1) 202 203 #define ACP_STR "Accept: " 204 #define ACP_STR_LEN (sizeof(ACP_STR) - 1) 205 206 #define CON_LEN_STR "Content-Length: " 207 #define CON_LEN_STR_LEN (sizeof(CON_LEN_STR) - 1) 208 #define CON_LEN_SHORT_STR "\nl: " 209 #define CON_LEN_SHORT_STR_LEN (sizeof(CON_LEN_SHORT_STR) - 1) 210 211 #define RR_STR "Record-Route: " 212 #define RR_STR_LEN (sizeof(RR_STR) - 1) 213 214 #define ROUTE_STR "Route: " 215 #define ROUTE_STR_LEN (sizeof(ROUTE_STR) - 1) 216 217 #define SIPSAK_MES_STR "test message from SIPsak for user " 218 #define SIPSAK_MES_STR_LEN (sizeof(SIPSAK_MES_STR) - 1) 219 220 #define EXP_STR "Expires: " 221 #define EXP_STR_LEN (sizeof(EXP_STR) - 1) 222 223 #define CON_EXP_STR "expires=" 224 #define CON_EXP_STR_LEN (sizeof(CON_EXP_STR) - 1) 225 226 #define WWWAUTH_STR "WWW-Authenticate: " 227 #define WWWAUTH_STR_LEN (sizeof(WWWAUTH_STR) - 1) 228 229 #define PROXYAUTH_STR "Proxy-Authenticate: " 230 #define PROXYAUTH_STR_LEN (sizeof(PROXYAUTH_STR) - 1) 231 232 #define AUTH_STR "Authorization: Digest " 233 #define AUTH_STR_LEN (sizeof(AUTH_STR) - 1) 234 235 #define PROXYAUZ_STR "Proxy-Authorization: Digest " 236 #define PROXYAUZ_STR_LEN (sizeof(PROXYAUZ_STR) - 1) 237 238 #define ALGO_STR "algorithm=" 239 #define ALGO_STR_LEN (sizeof(ALGO_STR) - 1) 240 241 #define MD5_STR "MD5, " 242 #define MD5_STR_LEN (sizeof(MD5_STR) - 1) 243 244 #define SHA1_STR "SHA1, " 245 #define SHA1_STR_LEN (sizeof(SHA1_STR) - 1) 246 247 #define REALM_STR "realm=" 248 #define REALM_STR_LEN (sizeof(REALM_STR) - 1) 249 250 #define OPAQUE_STR "opaque=" 251 #define OPAQUE_STR_LEN (sizeof(OPAQUEE_STR) - 1) 252 253 #define NONCE_STR "nonce=" 254 #define NONCE_STR_LEN (sizeof(NONCE_STR) - 1) 255 256 #define RESPONSE_STR "response=" 257 #define RESPONSE_STR_LEN (sizeof(RESPONSE_STR) - 1) 258 259 #define QOP_STR "qop=" 260 #define QOP_STR_LEN (sizeof(QOP_STR) - 1) 261 262 #define QOPAUTH_STR "auth" 263 #define QOPAUTH_STR_LEN (sizeof(QOPAUTH_STR) - 1) 264 265 #define NC_STR "nc=" 266 #define NC_STR_LEN (sizeof(NC_STR) - 1) 267 268 #define EMPTY_STR "" 269 #define EMPTY_STR_LEN (sizeof(EMPTY_STR) - 1) 270 271 #define UA_STR "User-Agent: " 272 #define UA_STR_LEN (sizeof(UA_STR) - 1) 273 274 #define SUB_STR "Subject: " 275 #define SUB_STR_LEN (sizeof(SUB_STR) - 1) 276 277 #define SIP100_STR "SIP/2.0 100" 278 #define SIP100_STR_LEN (sizeof(SIP100_STR) - 1) 279 280 #define TRANSPORT_PARAMETER_STR ";transport=" 281 #define TRANSPORT_PARAMETER_STR_LEN (sizeof(TRANSPORT_PARAMETER_STR) - 1) 282 283 #define USRLOC_EXP_DEF 15 284 #define FLOOD_METH "OPTIONS" 285 286 #define SIPSAK_HASHLEN_MD5 16 287 #define SIPSAK_HASHHEXLEN_MD5 2 * SIPSAK_HASHLEN_MD5 288 #ifdef HAVE_OPENSSL_SHA1 289 # define SIPSAK_HASHLEN_SHA1 20 290 # define SIPSAK_HASHLEN SIPSAK_HASHLEN_SHA1 291 # define SIPSAK_HASHHEXLEN_SHA1 2 * SIPSAK_HASHLEN_SHA1 292 #else 293 # define SIPSAK_HASHLEN SIPSAK_HASHLEN_MD5 294 #endif 295 #define SIPSAK_HASHHEXLEN 2 * SIPSAK_HASHLEN 296 297 /* lots of global variables. ugly but makes life easier. */ 298 unsigned long address; 299 unsigned int nonce_count, transport; 300 int sleep_ms, processes, cseq_counter; 301 int verbose, nameend, namebeg, expires_t, flood, warning_ext, invite, message; 302 int maxforw, lport, rport, randtrash, trashchar, numeric, symmetric; 303 int file_b, uri_b, trace, via_ins, usrloc, redirects, rand_rem, replace_b; 304 int empty_contact, nagios_warn, fix_crlf, timing, outbound_proxy, inv_final; 305 char *username, *domainname, *password, *replace_str, *hostname, *contact_uri; 306 char *mes_body, *con_dis, *auth_username, *from_uri, *headers; 307 char fqdn[FQDN_SIZE]; 308 char target_dot[INET_ADDRSTRLEN], source_dot[INET_ADDRSTRLEN]; 309 char *req, *rep, *rec, *transport_str; 310 regex_t* re; 311 312 #endif 313