1 /* 2 * Copyright (c) 2003-2004 E. Will et al. 3 * Copyright (c) 2005-2006 Atheme Development Group 4 * Rights to this code are as defined in doc/LICENSE. 5 * 6 * String matching 7 * 8 */ 9 10 #ifndef ATHEME_MATCH_H 11 #define ATHEME_MATCH_H 12 13 /* cidr.c */ 14 E int match_ips(const char *mask, const char *address); 15 E int match_cidr(const char *mask, const char *address); 16 17 /* match.c */ 18 #define MATCH_RFC1459 0 19 #define MATCH_ASCII 1 20 21 E int match_mapping; 22 23 #define IsLower(c) ((unsigned char)(c) > 0x5f) 24 #define IsUpper(c) ((unsigned char)(c) < 0x60) 25 26 #define C_ALPHA 0x00000001 27 #define C_DIGIT 0x00000002 28 #define C_NICK 0x00000004 29 #define C_USER 0x00000008 30 31 E const unsigned int charattrs[]; 32 33 #define IsAlpha(c) (charattrs[(unsigned char) (c)] & C_ALPHA) 34 #define IsDigit(c) (charattrs[(unsigned char) (c)] & C_DIGIT) 35 #define IsNickChar(c) (charattrs[(unsigned char) (c)] & C_NICK) 36 #define IsUserChar(c) (charattrs[(unsigned char) (c)] & C_USER) 37 #define IsAlphaNum(c) (IsAlpha((c)) || IsDigit((c))) 38 #define IsNon(c) (!IsAlphaNum((c))) 39 40 E const unsigned char ToLowerTab[]; 41 E const unsigned char ToUpperTab[]; 42 43 void set_match_mapping(int); 44 45 E int ToLower(int); 46 E int ToUpper(int); 47 48 E int irccasecmp(const char *, const char *); 49 E int ircncasecmp(const char *, const char *, size_t); 50 51 E void irccasecanon(char *); 52 E void strcasecanon(char *); 53 E void noopcanon(char *); 54 55 E int match(const char *, const char *); 56 E char *collapse(char *); 57 58 /* regex_create() flags */ 59 #define AREGEX_ICASE 1 /* case insensitive */ 60 #define AREGEX_PCRE 2 /* use libpcre engine */ 61 #define AREGEX_KLINE 4 /* XXX for rwatch, match kline */ 62 63 typedef struct atheme_regex_ atheme_regex_t; 64 65 E atheme_regex_t *regex_create(char *pattern, int flags); 66 E char *regex_extract(char *pattern, char **pend, int *pflags); 67 E bool regex_match(atheme_regex_t *preg, char *string); 68 E bool regex_destroy(atheme_regex_t *preg); 69 70 #endif 71 72 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs 73 * vim:ts=8 74 * vim:sw=8 75 * vim:noexpandtab 76 */ 77