unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
debug.c (3545B)
1 /* 2 * Unreal Internet Relay Chat Daemon, src/debug.c 3 * Copyright (C) 1990 Jarkko Oikarinen and 4 * University of Oulu, Computing Center 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 1, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 /** @file 22 * @brief Some debugging functions that should probably be moved elsewhere. 23 */ 24 25 /* debug.c 2.30 1/3/94 (C) 1988 University of Oulu, Computing Center and Jarkko Oikarinen */ 26 27 #include "unrealircd.h" 28 29 /** String of server options in this compile (eg 'D' for debug mode). 30 */ 31 MODVAR char serveropts[] = { 32 #ifdef DEBUGMODE 33 'D', 34 #endif 35 /* FDLIST (always) */ 36 'F', 37 /* Hub (always) */ 38 'h', 39 /* NOSPOOF (always) */ 40 'n', 41 #ifdef VALLOC 42 'V', 43 #endif 44 #ifdef _WIN32 45 'W', 46 #endif 47 #ifdef USE_SYSLOG 48 'Y', 49 #endif 50 '6', 51 #ifndef NO_OPEROVERRIDE 52 'O', 53 #endif 54 #ifndef OPEROVERRIDE_VERIFY 55 'o', 56 #endif 57 'E', 58 #ifdef USE_LIBCURL 59 'r', 60 #endif 61 '\0', /* Don't change those nuls. -- Syzop */ 62 '\0', 63 '\0', 64 '\0', 65 '\0' 66 }; 67 68 char *extraflags = NULL; 69 70 MODVAR int debugfd = 2; 71 72 void flag_add(char ch) 73 { 74 char *newextra; 75 if (extraflags) 76 { 77 char tmp[2] = { ch, 0 }; 78 newextra = safe_alloc(strlen(extraflags) + 2); 79 strcpy(newextra, extraflags); 80 strcat(newextra, tmp); 81 safe_free(extraflags); 82 extraflags = newextra; 83 } 84 else 85 { 86 extraflags = safe_alloc(2); 87 extraflags[0] = ch; 88 extraflags[1] = '\0'; 89 } 90 } 91 92 void flag_del(char ch) 93 { 94 int newsz; 95 char *p, *op; 96 char *newflags; 97 newsz = 0; 98 p = extraflags; 99 for (newsz = 0, p = extraflags; *p; p++) 100 if (*p != ch) 101 newsz++; 102 newflags = safe_alloc(newsz + 1); 103 for (p = newflags, op = extraflags; (*op) && (newsz); newsz--, op++) 104 if (*op != ch) 105 *p++ = *op; 106 *p = '\0'; 107 safe_free(extraflags); 108 extraflags = newflags; 109 } 110 111 112 113 #ifdef DEBUGMODE 114 115 #ifndef _WIN32 116 #define SET_ERRNO(x) errno = x 117 #else 118 #define SET_ERRNO(x) WSASetLastError(x) 119 #endif /* _WIN32 */ 120 121 static char debugbuf[4096]; 122 123 void debug(int level, FORMAT_STRING(const char *form), ...) 124 { 125 int err = ERRNO; 126 127 va_list vl; 128 va_start(vl, form); 129 130 if ((debuglevel >= 0) && (level <= debuglevel)) 131 { 132 (void)ircvsnprintf(debugbuf, sizeof(debugbuf), form, vl); 133 134 #ifndef _WIN32 135 strlcat(debugbuf, "\n", sizeof(debugbuf)); 136 if (write(debugfd, debugbuf, strlen(debugbuf)) < 0) 137 { 138 /* Yeah.. what can we do if output isn't working? Outputting an error makes no sense */ 139 ; 140 } 141 #else 142 strlcat(debugbuf, "\r\n", sizeof(debugbuf)); 143 OutputDebugString(debugbuf); 144 #endif 145 } 146 va_end(vl); 147 SET_ERRNO(err); 148 } 149 150 int checkprotoflags(Client *client, int flags, const char *file, int line) 151 { 152 if (!MyConnect(client)) 153 { 154 unreal_log(ULOG_ERROR, "main", "BUG_ISTOKEN_REMOTE_CLIENT", client, 155 "IsToken($token_value) used on remote client in $file:$line", 156 log_data_integer("token_value", flags), 157 log_data_string("file", file), 158 log_data_integer("line", line)); 159 } 160 return ((client->local->proto & flags) == flags) ? 1 : 0; 161 } 162 #endif