Line data Source code
1 : #include "burp.h" 2 : #include "alloc.h" 3 : #include "log.h" 4 : #include "regexp.h" 5 : 6 12 : static regex_t *do_regex_compile(const char *str, int flags) 7 : { 8 12 : regex_t *regex=NULL; 9 12 : if((regex=(regex_t *)malloc_w(sizeof(regex_t), __func__)) 10 12 : && !regcomp(regex, str, flags)) 11 10 : return regex; 12 : 13 2 : regex_free(®ex); 14 2 : return NULL; 15 : } 16 : 17 0 : static regex_t *regex_compile_insensitive(const char *str) 18 : { 19 0 : return do_regex_compile(str, REG_EXTENDED|REG_ICASE); 20 : } 21 : 22 12 : static regex_t *regex_compile_sensitive(const char *str) 23 : { 24 12 : return do_regex_compile(str, REG_EXTENDED); 25 : } 26 : 27 6 : regex_t *regex_compile_backup(const char *str) 28 : { 29 : #ifdef HAVE_WIN32 30 : // Give Windows another helping hand and make the regular expressions 31 : // always case insensitive. 32 : return regex_compile_insensitive(str); 33 : #else 34 6 : return regex_compile_sensitive(str); 35 : #endif 36 : } 37 : 38 6 : regex_t *regex_compile_restore(const char *str, int insensitive) 39 : { 40 6 : if(insensitive) 41 0 : return regex_compile_insensitive(str); 42 : 43 6 : return regex_compile_sensitive(str); 44 : } 45 : 46 55 : int regex_check(regex_t *regex, const char *buf) 47 : { 48 55 : if(!regex) return 0; 49 55 : switch(regexec(regex, buf, 0, NULL, 0)) 50 : { 51 : case 0: return 1; 52 : case REG_NOMATCH: return 0; 53 : default: return 0; 54 : } 55 : } 56 : 57 893 : void regex_free(regex_t **regex) 58 : { 59 893 : if(!regex || !*regex) return; 60 12 : regfree(*regex); 61 12 : free_v((void **)regex); 62 : }