1 /* 2 * ircaux.h: header file for ircaux.c 3 * 4 * Written By Michael Sandrof 5 * 6 * Copyright(c) 1990 7 * 8 * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT 9 * 10 * @(#)$Id: ircaux.h 382 2013-10-09 21:40:55Z keaston $ 11 */ 12 13 #ifndef _IRCAUX_H_ 14 #define _IRCAUX_H_ 15 16 #include "irc.h" 17 #include "irc_std.h" 18 #include <stdio.h> 19 #ifdef WANT_TCL 20 #undef USE_TCLALLOC 21 #include <tcl.h> 22 #endif 23 24 typedef int comp_len_func (char *, char *, int); 25 typedef int comp_func (char *, char *); 26 27 extern unsigned char stricmp_table[]; 28 29 30 char * BX_check_nickname (char *); 31 char * BX_next_arg (char *, char **); 32 char * BX_new_next_arg (char *, char **); 33 char * BX_new_new_next_arg (char *, char **, char *); 34 char * BX_last_arg (char **); 35 char * BX_expand_twiddle (char *); 36 char * BX_upper (char *); 37 char * BX_lower (char *); 38 char * BX_sindex (register char *, char *); 39 char * BX_rsindex (register char *, char *, char *, int); 40 char * BX_path_search (char *, char *); 41 char * BX_double_quote (const char *, const char *, char *); 42 char * quote_it (const char *, const char *, char *); 43 44 char * n_malloc_strcpy (char **, const char *, const char *, const char *, const int); 45 char * BX_malloc_str2cpy (char **, const char *, const char *); 46 char * n_malloc_strcat (char **, const char *, const char *, const char *, const int); 47 48 char * BX_m_s3cat_s (char **, const char *, const char *); 49 char * BX_m_s3cat (char **, const char *, const char *); 50 char * BX_m_3cat (char **, const char *, const char *); 51 char * BX_m_e3cat (char **, const char *, const char *); 52 char * BX_m_2dup (const char *, const char *); 53 char * BX_m_3dup (const char *, const char *, const char *); 54 char * BX_m_opendup (const char *, ...); 55 char * n_m_strdup (const char *, const char *, const char *, const int); 56 char * BX_malloc_sprintf (char **, const char *, ...); 57 char * BX_m_sprintf (const char *, ...); 58 int BX_is_number (const char *); 59 char * BX_my_ctime (time_t); 60 61 #if 0 62 #define my_stricmp(x, y) strcasecmp(x, y) /* unable to use these for reasons of case sensitivity and finish */ 63 #define my_strnicmp(x, y, n) strncasecmp(x, y, n) 64 #else 65 int BX_my_stricmp (const char *, const char *); 66 int BX_my_strnicmp (const char *, const char *, size_t); 67 #endif 68 69 int BX_my_strnstr (const unsigned char *, const unsigned char *, size_t); 70 int BX_scanstr (char *, char *); 71 void really_free (int); 72 char * BX_chop (char *, int); 73 char * BX_strmcpy (char *, const char *, int); 74 char * BX_strmcat (char *, const char *, int); 75 char * strmcat_ue (char *, const char *, int); 76 char * n_m_strcat_ues (char **, char *, int, const char *, const char *, const int); 77 char * BX_stristr (const char *, const char *); 78 char * BX_rstristr (char *, char *); 79 FILE * BX_uzfopen (char **, char *, int); 80 int BX_end_strcmp (const char *, const char *, int); 81 void BX_ircpanic (char *, ...); 82 int fw_strcmp (comp_len_func *, char *, char *); 83 int lw_strcmp (comp_func *, char *, char *); 84 int open_to (char *, int, off_t); 85 struct timeval BX_get_time (struct timeval *); 86 double BX_time_diff (struct timeval, struct timeval); 87 char * BX_plural (int); 88 int BX_time_to_next_minute (void); 89 char * BX_remove_trailing_spaces (char *); 90 char * BX_my_ltoa (long); 91 char * BX_strformat (char *, const char *, int, char); 92 char * chop_word (char *); 93 int BX_splitw (char *, char ***); 94 char * BX_unsplitw (char ***, int); 95 int BX_check_val (char *); 96 char * BX_strextend (char *, char, int); 97 char * strext (char *, char *); 98 char * BX_pullstr (char *, char *); 99 int BX_empty (const char *); 100 char * safe_new_next_arg (char *, char **); 101 char * BX_MatchingBracket (register char *, register char, register char); 102 int BX_word_count (char *); 103 int BX_parse_number (char **); 104 char * BX_remove_brackets (const char *, const char *, int *); 105 u_long hashpjw (char *, u_long); 106 char * BX_m_dupchar (int); 107 char * BX_strmccat (char *, char, int); 108 off_t file_size (char *); 109 int is_root (char *, char *, int); 110 size_t BX_streq (const char *, const char *); 111 size_t BX_strieq (const char *, const char *); 112 char * n_m_strndup (const char *, size_t, const char *, const char *, const int); 113 char * BX_on_off (int); 114 char * BX_rfgets (char *, int, FILE *); 115 char * BX_strmopencat (char *, int, ...); 116 long BX_my_atol (const char *); 117 char * s_next_arg (char **); 118 char * BX_next_in_comma_list (char *, char **); 119 void BX_strip_control (const char *, char *); 120 int BX_figure_out_address (char *, char **, char **, char **, char **, int *); 121 int count_char (const unsigned char *, const unsigned char); 122 char * BX_strnrchr (char *, char, int); 123 void BX_mask_digits (char **); 124 const char *BX_strfill (char, int); 125 char * BX_ov_strcpy (char *, const char *); 126 char * BX_strpcat (char *, const char *, ...); 127 char * BX_strmpcat (char *, size_t, const char *, ...); 128 char * chomp (char *); 129 size_t BX_ccspan (const char *, int); 130 u_char *BX_strcpy_nocolorcodes (u_char *, const u_char *); 131 unsigned long randm(unsigned long); 132 unsigned long randt(unsigned long); 133 unsigned long randd(unsigned long); 134 unsigned long BX_random_number(unsigned long); 135 char * get_userhost (void); 136 137 char * urlencode (const char *); 138 char * urldecode (char *); 139 char * base64_encode (const void *data, size_t size); 140 141 /* From words.c */ 142 #define SOS -32767 143 #define EOS 32767 144 char *BX_strsearch (register char *, char *, char *, int); 145 char *BX_move_to_abs_word (const register char *, char **, int); 146 char *BX_move_word_rel (const register char *, char **, int); 147 char *BX_extract (char *, int, int); 148 char *BX_extract2 (const char *, int, int); 149 int BX_wild_match (const char *, const char *); 150 151 /* Used for connect_by_number */ 152 #define SERVICE_SERVER 0 153 #define SERVICE_CLIENT 1 154 #define PROTOCOL_TCP 0 155 #define PROTOCOL_UDP 1 156 157 /* Used from network.c */ 158 int BX_connect_by_number (char *, unsigned short *, int, int, int); 159 struct sockaddr_foobar * BX_lookup_host(const char *); 160 char * BX_host_to_ip (const char *); 161 char * BX_ip_to_host (const char *); 162 char * BX_one_to_another (const char *); 163 int BX_set_blocking (int); 164 int BX_set_non_blocking (int); 165 int my_accept (int, struct sockaddr *, socklen_t *); 166 int lame_resolv (const char *, struct sockaddr_foobar *); 167 168 #define my_isspace(x) \ 169 ((x) == 9 || (x) == 10 || (x) == 11 || (x) == 12 || (x) == 13 || (x) == 32) 170 171 #define my_isdigit(x) \ 172 (*x >= '0' && *x <= '9') || \ 173 ((*x == '-' || *x == '+') && (x[1] >= '0' && x[1] <= '9')) 174 175 #define LOCAL_COPY(y) strcpy(alloca(strlen((y)) + 1), y) 176 177 178 #define _1KB ((double) 1000) 179 #define _1MEG (_1KB * _1KB) 180 #define _1GIG (_1KB * _1KB * _1KB) 181 #define _1TER (_1KB * _1KB * _1KB * _1KB) 182 #define _1ETA (_1KB * _1KB * _1KB * _1KB * _1KB) 183 184 #if 0 185 #define _1MEG (1024.0*1024.0) 186 #define _1GIG (1024.0*1024.0*1024.0) 187 #define _1TER (1024.0*1024.0*1024.0*1024.0) 188 #define _1ETA (1024.0*1024.0*1024.0*1024.0*1024.0) 189 #endif 190 191 #define _GMKs(x) ( ((double)x > _1ETA) ? "eb" : \ 192 (((double)x > _1TER) ? "tb" : (((double)x > _1GIG) ? "gb" : \ 193 (((double)x > _1MEG) ? "mb" : (((double)x > _1KB)? "kb" : "bytes"))))) 194 195 #define _GMKv(x) (((double)x > _1ETA) ? \ 196 ((double)x/_1ETA) : (((double)x > _1TER) ? \ 197 ((double)x/_1TER) : (((double)x > _1GIG) ? \ 198 ((double)x/_1GIG) : (((double)x > _1MEG) ? \ 199 ((double)x/_1MEG) : (((double)x > _1KB) ? \ 200 ((double)x/_1KB): (double)x)))) ) 201 202 void *n_malloc (size_t, const char *, const char *, const int); 203 void *n_realloc (void *, size_t, const char *, const char *, const int); 204 205 void *n_free (void *, const char *, const char *, const int); 206 207 #define MODULENAME NULL 208 209 #define new_malloc(x) n_malloc(x, MODULENAME, __FILE__, __LINE__) 210 #define new_free(x) (*(x) = n_free(*(x), MODULENAME, __FILE__, __LINE__)) 211 212 #define RESIZE(x, y, z) ((x) = n_realloc((x), sizeof(y) * (z), MODULENAME, __FILE__, __LINE__)) 213 #define malloc_strcpy(x, y) n_malloc_strcpy((char **)x, (char *)y, MODULENAME, __FILE__, __LINE__) 214 #define malloc_strcat(x, y) n_malloc_strcat((char **)x, (char *)y, MODULENAME, __FILE__, __LINE__) 215 #define m_strdup(x) n_m_strdup(x, MODULENAME, __FILE__, __LINE__) 216 #define m_strcat_ues(x, y, z) n_m_strcat_ues(x, y, z, MODULENAME, __FILE__, __LINE__) 217 #define m_strndup(x, y) n_m_strndup(x, y, MODULENAME, __FILE__, __LINE__) 218 219 char *encode (const char *, int); 220 char *decode (const char *); 221 char *BX_cryptit (const char *); 222 int checkpass (const char *, const char *); 223 224 225 /* Used for the inbound mangling stuff */ 226 227 #define MANGLE_ESCAPES 1 << 0 228 #define MANGLE_ANSI_CODES 1 << 1 229 #define STRIP_COLOR 1 << 2 230 #define STRIP_REVERSE 1 << 3 231 #define STRIP_UNDERLINE 1 << 4 232 #define STRIP_BOLD 1 << 5 233 #define STRIP_BLINK 1 << 6 234 #define STRIP_ROM_CHAR 1 << 7 235 #define STRIP_ND_SPACE 1 << 8 236 #define STRIP_ALL_OFF 1 << 9 237 #define STRIP_ALT_CHAR 1 << 10 238 #define PRE_MANGLE 1 << 11 239 240 extern int outbound_line_mangler; 241 extern int inbound_line_mangler; 242 extern int logfile_line_mangler; 243 extern int operlog_line_mangler; 244 245 size_t BX_mangle_line (char *, int, size_t); 246 int BX_charcount (const char *, char); 247 char *BX_stripdev (char *); 248 char *convert_dos (char *); 249 char *convert_unix (char *); 250 int is_dos (char *); 251 void strip_chars (char *, char *, char); 252 char *longcomma (long); 253 char *ulongcomma (unsigned long); 254 255 #define SAFE(x) (((x) && *(x)) ? (x) : empty_string) 256 257 /* Used in compat.c */ 258 #ifndef HAVE_TPARM 259 char *tparm (const char *, ...); 260 #endif 261 262 #ifndef HAVE_STRTOUL 263 unsigned long strtoul (const char *, char **, int); 264 #endif 265 266 #ifndef HAVE_SETENV 267 char * bsd_getenv (const char *); 268 int bsd_putenv (const char *); 269 int bsd_setenv (const char *, const char *, int); 270 void bsd_unsetenv (const char *); 271 #define setenv bsd_setenv 272 #endif 273 274 #ifndef HAVE_INET_ATON 275 int inet_aton (const char *, struct in_addr *); 276 #endif 277 278 #ifndef HAVE_STRLCPY 279 size_t strlcpy (char *, const char *, size_t); 280 #endif 281 282 #ifndef HAVE_STRLCAT 283 size_t strlcat (char *, const char *, size_t); 284 #endif 285 286 #ifndef HAVE_VSNPRINTF 287 int vsnprintf (char *, size_t, const char *, va_list); 288 #endif 289 290 #ifndef HAVE_SNPRINTF 291 int snprintf (char *, size_t, const char *, ...); 292 #endif 293 294 #ifndef HAVE_SETSID 295 int setsid (void); 296 #endif 297 298 #endif /* _IRCAUX_H_ */ 299