int main(int cgc_argc, char *cgc_argv[]) { cgc_negotiate_type1(0x0, 0x0, 0); do { //*** writing data static unsigned char write_00000_00000[] = "\x04\x04\x00\x00"; static unsigned int write_00000_00000_len = 4; unsigned char *write_00000 = NULL; unsigned int write_00000_len = 0; write_00000 = cgc_append_buf(write_00000, &write_00000_len, write_00000_00000, write_00000_00000_len); if (write_00000_len > 0) { cgc_transmit_all(1, write_00000, write_00000_len); } cgc_free(write_00000); } while (0); do { //*** writing data static unsigned char write_00001_00000[] = "\x01\x00\x00\x00\x01\x00\x00\x00\xf0\x03\x00\x00\xe8\x03\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\xe8\x03\x00\x00\x7c\x79\x4b\xe0" "\xa2\xde\xae\xe4\xa4\xb0\xd8\x82\xe7\x00\x00\x00\xb3\x0d\xf3\x2a" "\x07\x16\x63\x9f\x65\xf8\x80\x71\xd2\x25\xb7\x83\x72\x59\x6a\x3b" "\x58\xa3\x39\x33\x55\x1c\xe4\xd5\xf7\xfa\x04\x31\x4c\x56\x15\x2e" "\xa1\xa3\xd7\xa0\xf9\x75\x54\x69\x44\x49\x79\x49\xfb\x15\x55\x64" "\x5d\x00\xec\x99\x87\x9c\xdc\x4d\x2c\x3c\x6a\xee\xca\xdd\x1b\xa1" "\x69\x29\x0e\x8a\xcd\x2a\x50\x10\x5a\x33\x4b\x77\x29\xd2\xf0\x7c" "\xe0\xa5\x4f\x1d\x11\x76\x5f\x1f\xb2\x6e\xba\xef\xc0\x00\xce\xbc" "\x43\x76\x47\x88\x36\x75\x2c\x88\x31\x55\x78\xa3\xfb\xb1\x37\x68" "\xb3\xea\x39\x65\x62\x64\xc7\x5d\xfe\xa7\xa9\x96\x23\xf5\x0f\x35" "\x29\x61\x55\x46\x4a\x2c\xb6\xc3\xe1\xd3\x88\x4c\x88\x22\xfa\x5d" "\x05\xde\x5c\x04\x65\xbc\x4a\x97\x4c\x44\x15\xc3\x02\x7a\xe9\x21" "\x5a\xe0\xcc\xac\x9b\xc8\xfa\x3d\xcf\x50\x11\x79\x47\xf2\x6a\x22" "\x63\x58\xc5\x0d\x4d\x17\xe9\x33\xe7\xc9\xa6\x2c\x98\x31\xa3\x17" "\x4d\x2f\xe4\xce\x50\xa9\x15\x44\x0e\x58\x58\x29\xed\x58\x00\xfa" "\xa2\x25\x1f\x3f\xa0\xd0\xb5\x1f\xc5\x58\x15\x83\x3b\xa2\xd7\x33" "\xd7\x4e\x58\x58\x20\x3a\xb1\xec\xe4\x13\x30\x29\x6a\xf4\x89\x97" "\x80\x03\x87\xa6\xce\x76\x08\x3c\xa5\x87\xab\xf9\x24\x49\x66\x17" "\xb5\x03\x50\xac\x53\x4b\xe6\x9d\xfd\xe3\x8f\xe5\xba\xff\x68\x38" "\xd5\xc5\x9e\x23\xb6\x80\xa9\x8e\x7d\x8f\xa0\x94\x4e\xe1\xb9\x62" "\x3e\x15\xef\xf7\xe8\x39\x9c\x54\xff\xb0\xe5\xff\x83\x8d\x7b\xe4" "\x11\x0b\xa7\x05\x2f\x88\x9b\x75\xf9\x6c\xbc\xe3\x26\x32\x9d\xec" "\xd3\xfa\xe6\x7a\x19\xdb\xa2\xaa\x14\xa7\xde\xab\x38\xdb\xa8\x49" "\x39\xa2\x76\x4e\xc6\xb0\xa0\xe0\x87\x6c\xe2\x8e\xee\x81\xe4\xaa" "\x09\x53\x6e\xd5\x89\x50\x63\xc8\xf4\xb6\x33\xcd\x6e\x6a\x25\x4a" "\xb5\xb0\x09\x43\x68\x35\x0d\xa3\x58\x00\x9d\xcd\xaa\x43\x58\xdb" "\x58\x00\x11\x00\x74\xb8\x43\x8f\x6a\x07\x5b\x40\x4b\x6e\x1e\x21" "\xd0\xab\x5c\x9d\xa6\x8f\x91\x15\xb3\xcf\x2e\xb0\x82\x10\x39\xdd" "\xfd\x47\x73\x64\xa7\x1b\x8c\x0b\x30\x3b\xf7\x7c\xc3\x32\x60\x62" "\x8e\xfe\x77\xc2\xbc\x16\x2c\x00\x8f\x3e\xc3\xd8\x8f\x9d\x31\x18" "\xd3\x93\x3d\x95\x65\x3c\x97\x9f\xf8\xc1\x7c\xc8\x50\xdf\xdd\xe9" "\x8f\x76\x4c\x04\xe3\x9a\x37\xf1\xb8\x80\x7b\x7f\x73\xbe\x85\x46" "\xa7\xd7\xfb\x3d\x40\xb8\xfc\x74\xb9\xc6\x18\x82\x6c\x99\xd3\xd1" "\x04\x1d\x3f\xae\x1a\x7e\xf5\x9a\x40\xff\xc3\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" "\x20\x20\x20\x20"; static unsigned int write_00001_00000_len = 1028; unsigned char *write_00001 = NULL; unsigned int write_00001_len = 0; write_00001 = cgc_append_buf(write_00001, &write_00001_len, write_00001_00000, write_00001_00000_len); if (write_00001_len > 0) { cgc_transmit_all(1, write_00001, write_00001_len); } cgc_free(write_00001); } while (0); do { unsigned char *read_00000; unsigned int read_00000_len; unsigned int read_00000_ptr = 0; //**** delimited read static unsigned char read_00000_delim[] = "\x0a"; read_00000 = NULL; read_00000_len = 0; int read_00000_res = cgc_delimited_read(0, &read_00000, &read_00000_len, read_00000_delim, 1); if (read_00000_res) {} //silence unused variable warning //**** read match data static unsigned char match_00000_00000[] = "\x53\x74\x61\x72\x74\x69\x6e\x67\x20\x64\x69\x73\x73\x65\x63\x74" "\x69\x6f\x6e\x2e\x2e\x2e"; read_00000_ptr += cgc_data_match(read_00000 + read_00000_ptr, read_00000_len - read_00000_ptr, match_00000_00000, 22); cgc_free(read_00000); if (read_00000_ptr) {} //silence unused variable warning if any } while (0); do { unsigned char *read_00001; unsigned int read_00001_len; unsigned int read_00001_ptr = 0; //**** delimited read static unsigned char read_00001_delim[] = "\x3d\x3d\x3d\x3d\x0a"; read_00001 = NULL; read_00001_len = 0; int read_00001_res = cgc_delimited_read(0, &read_00001, &read_00001_len, read_00001_delim, 5); if (read_00001_res) {} //silence unused variable warning /* read match pcre: .*New Packet */ static char read_00001_00000_regex[] = "\x2e\x2a\x4e\x65\x77\x20\x50\x61\x63\x6b\x65\x74"; static match_result read_00001_00000_match; pcre *read_00001_00000_pcre = cgc_init_regex(read_00001_00000_regex); if (read_00001_00000_pcre != NULL) { int rc = cgc_regex_match(read_00001_00000_pcre, 0, read_00001 + read_00001_ptr, read_00001_len - read_00001_ptr, &read_00001_00000_match); if (rc > 0) { read_00001_ptr += read_00001_00000_match.match_end - read_00001_00000_match.match_start; } else { //this is a pov so what does this even mean? //why would we quit on failed match, just keep sending stuff. } pcre_free(read_00001_00000_pcre); } else { //this is a pov so what does this even mean? //why would we quit on failed regex compile, just keep sending stuff. } cgc_free(read_00001); if (read_00001_ptr) {} //silence unused variable warning if any } while (0); do { unsigned char *read_00002; unsigned int read_00002_len; unsigned int read_00002_ptr = 0; //**** delimited read static unsigned char read_00002_delim[] = "\x3d\x3d\x3d\x0a"; read_00002 = NULL; read_00002_len = 0; int read_00002_res = cgc_delimited_read(0, &read_00002, &read_00002_len, read_00002_delim, 4); if (read_00002_res) {} //silence unused variable warning /* read match pcre: .*===lol */ static char read_00002_00000_regex[] = "\x2e\x2a\x3d\x3d\x3d\x6c\x6f\x6c"; static match_result read_00002_00000_match; pcre *read_00002_00000_pcre = cgc_init_regex(read_00002_00000_regex); if (read_00002_00000_pcre != NULL) { int rc = cgc_regex_match(read_00002_00000_pcre, 0, read_00002 + read_00002_ptr, read_00002_len - read_00002_ptr, &read_00002_00000_match); if (rc > 0) { read_00002_ptr += read_00002_00000_match.match_end - read_00002_00000_match.match_start; } else { //this is a pov so what does this even mean? //why would we quit on failed match, just keep sending stuff. } pcre_free(read_00002_00000_pcre); } else { //this is a pov so what does this even mean? //why would we quit on failed regex compile, just keep sending stuff. } cgc_free(read_00002); if (read_00002_ptr) {} //silence unused variable warning if any } while (0); do { unsigned char *read_00003; unsigned int read_00003_len; unsigned int read_00003_ptr = 0; //**** delimited read static unsigned char read_00003_delim[] = "\x3d\x3d\x3d\x0a"; read_00003 = NULL; read_00003_len = 0; int read_00003_res = cgc_delimited_read(0, &read_00003, &read_00003_len, read_00003_delim, 4); if (read_00003_res) {} //silence unused variable warning /* read match pcre: .*===pentaptychBantingism */ static char read_00003_00000_regex[] = "\x2e\x2a\x3d\x3d\x3d\x70\x65\x6e\x74\x61\x70\x74\x79\x63\x68\x42" "\x61\x6e\x74\x69\x6e\x67\x69\x73\x6d"; static match_result read_00003_00000_match; pcre *read_00003_00000_pcre = cgc_init_regex(read_00003_00000_regex); if (read_00003_00000_pcre != NULL) { int rc = cgc_regex_match(read_00003_00000_pcre, 0, read_00003 + read_00003_ptr, read_00003_len - read_00003_ptr, &read_00003_00000_match); if (rc > 0) { read_00003_ptr += read_00003_00000_match.match_end - read_00003_00000_match.match_start; } else { //this is a pov so what does this even mean? //why would we quit on failed match, just keep sending stuff. } pcre_free(read_00003_00000_pcre); } else { //this is a pov so what does this even mean? //why would we quit on failed regex compile, just keep sending stuff. } cgc_free(read_00003); if (read_00003_ptr) {} //silence unused variable warning if any } while (0); do { unsigned char *read_00004; unsigned int read_00004_len; unsigned int read_00004_ptr = 0; //**** delimited read static unsigned char read_00004_delim[] = "\x3d\x3d\x3d\x0a"; read_00004 = NULL; read_00004_len = 0; int read_00004_res = cgc_delimited_read(0, &read_00004, &read_00004_len, read_00004_delim, 4); if (read_00004_res) {} //silence unused variable warning /* read match pcre: .*===crossboltedasexually */ static char read_00004_00000_regex[] = "\x2e\x2a\x3d\x3d\x3d\x63\x72\x6f\x73\x73\x62\x6f\x6c\x74\x65\x64" "\x61\x73\x65\x78\x75\x61\x6c\x6c\x79"; static match_result read_00004_00000_match; pcre *read_00004_00000_pcre = cgc_init_regex(read_00004_00000_regex); if (read_00004_00000_pcre != NULL) { int rc = cgc_regex_match(read_00004_00000_pcre, 0, read_00004 + read_00004_ptr, read_00004_len - read_00004_ptr, &read_00004_00000_match); if (rc > 0) { read_00004_ptr += read_00004_00000_match.match_end - read_00004_00000_match.match_start; } else { //this is a pov so what does this even mean? //why would we quit on failed match, just keep sending stuff. } pcre_free(read_00004_00000_pcre); } else { //this is a pov so what does this even mean? //why would we quit on failed regex compile, just keep sending stuff. } cgc_free(read_00004); if (read_00004_ptr) {} //silence unused variable warning if any } while (0); do { unsigned char *read_00005; unsigned int read_00005_len; unsigned int read_00005_ptr = 0; //**** delimited read static unsigned char read_00005_delim[] = "\x3d\x3d\x3d\x0a"; read_00005 = NULL; read_00005_len = 0; int read_00005_res = cgc_delimited_read(0, &read_00005, &read_00005_len, read_00005_delim, 4); if (read_00005_res) {} //silence unused variable warning /* read match pcre: .*Dissection finished */ static char read_00005_00000_regex[] = "\x2e\x2a\x44\x69\x73\x73\x65\x63\x74\x69\x6f\x6e\x20\x66\x69\x6e" "\x69\x73\x68\x65\x64"; static match_result read_00005_00000_match; pcre *read_00005_00000_pcre = cgc_init_regex(read_00005_00000_regex); if (read_00005_00000_pcre != NULL) { int rc = cgc_regex_match(read_00005_00000_pcre, 0, read_00005 + read_00005_ptr, read_00005_len - read_00005_ptr, &read_00005_00000_match); if (rc > 0) { read_00005_ptr += read_00005_00000_match.match_end - read_00005_00000_match.match_start; } else { //this is a pov so what does this even mean? //why would we quit on failed match, just keep sending stuff. } pcre_free(read_00005_00000_pcre); } else { //this is a pov so what does this even mean? //why would we quit on failed regex compile, just keep sending stuff. } cgc_free(read_00005); if (read_00005_ptr) {} //silence unused variable warning if any } while (0); }
VRegexp::~VRegexp() { if ( re ) pcre_free( re ); if ( pt ) delete pt; };
int main(int argc, char **argv) { set_log_level(LOG_LEVEL_WARN); char **paths = NULL; int i; int pcre_opts = PCRE_MULTILINE; int study_opts = 0; const char *pcre_err = NULL; int pcre_err_offset = 0; pcre *re = NULL; pcre_extra *re_extra = NULL; double time_diff = 0.0; memset(&stats, 0, sizeof(stats)); /* What's the point of an init function if it's going to be this one-liner? */ gettimeofday(&(stats.time_start), NULL); parse_options(argc, argv, &paths); log_debug("PCRE Version: %s", pcre_version()); if (opts.casing == CASE_INSENSITIVE) { pcre_opts = pcre_opts | PCRE_CASELESS; } if (!is_regex(opts.query)) { /* No special chars. Do a literal match */ opts.literal = 1; } if (opts.literal) { generate_skip_lookup(opts.query, opts.query_len, skip_lookup, opts.casing == CASE_SENSITIVE); } else { re = pcre_compile(opts.query, pcre_opts, &pcre_err, &pcre_err_offset, NULL); if (re == NULL) { log_err("pcre_compile failed at position %i. Error: %s", pcre_err_offset, pcre_err); exit(1); } #ifdef USE_PCRE_JIT int has_jit = 0; pcre_config(PCRE_CONFIG_JIT, &has_jit); if (has_jit) { study_opts |= PCRE_STUDY_JIT_COMPILE; } #endif re_extra = pcre_study(re, study_opts, &pcre_err); if (re_extra == NULL) { log_debug("pcre_study returned nothing useful. Error: %s", pcre_err); } } if (opts.search_stream) { search_stdin(re, re_extra); } else { for (i = 0; paths[i] != NULL; i++) { log_debug("searching path %s for %s", paths[i], opts.query); search_dir(re, re_extra, paths[i], 0); free(paths[i]); } } if (opts.stats) { gettimeofday(&(stats.time_end), NULL); time_diff = ((long)stats.time_end.tv_sec * 1000000 + stats.time_end.tv_usec) - ((long)stats.time_start.tv_sec * 1000000 + stats.time_start.tv_usec); time_diff = time_diff / 1000000; printf("%ld matches\n%ld files searched\n%ld bytes searched\n%f seconds\n", stats.total_matches, stats.total_files, stats.total_bytes, time_diff); } pcre_free(re); pcre_free(re_extra); /* Using pcre_free_study here segfaults on some versions of PCRE */ free(paths); cleanup_ignore_patterns(); return(0); }
/* * 执行命令:./regex-second 127.0.0.1 127.0.0.1/23 \"gelgejlge-lxjgle-\"{ */ int main(int argc, char ** argv) { const char * pPattern = "^(?:(?:25[0-5]|2[0-4][0-9]" "|[01]?[0-9][0-9]?)\\.){3}" "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; const char * p1Pattern = "^((?:(?:25[0-5]|2[0-4][0-9]" "|[01]?[0-9][0-9]?)\\.){3}" "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))" "/([0-9]|[1-2][0-9]|3[0-2])[ ]*?$"; const char * p2Pattern = "^\"([a-zA-Z][a-zA-Z-]*?)\"{[ ]*?$"; const char * pErrMsg = NULL; const char *subMatchStr = NULL; char * pText = NULL;; pcre * pPcre = NULL; int eOffset = -1; int nOffset[256]; int ret; if (argc != 4) { printf("Unvalidate argument!\n"); return 0; } pText = argv[1]; if (NULL == (pPcre = pcre_compile(pPattern, 0, &pErrMsg, &eOffset, NULL))) { printf("ErrMsg=%s, Offset=%d\n", pErrMsg, eOffset); return 1; } else { if (pcre_exec(pPcre, NULL, pText, strlen(pText), 0, 0, NULL, 0) < 0) { printf("%s doesn't match %s\n", pText, pPattern); } else { printf("%s matches %s\n", pText, pPattern); } } // 127.0.0.1/32 pText = argv[2]; if (NULL == (pPcre = pcre_compile(p1Pattern, 0, &pErrMsg, &eOffset, NULL))) { printf("ErrMsg=%s, Offset=%d\n", pErrMsg, eOffset); return 1; } else { ret = pcre_exec(pPcre, NULL, pText, strlen(pText), 0, 0, (int*)&nOffset, 256); if (ret < 0) { printf("%s doesn't match %s\n", pText, p1Pattern); } else { printf("%s matches %s, matchNumber=%d\n", pText, p1Pattern, ret); int i; for (i=0; i<ret; i++) { printf("位置:%d\n", nOffset[2*i]); } pcre_get_substring(pText, nOffset, ret, 1, &(subMatchStr)); printf("匹配的Ip地址:%s\n", subMatchStr); } } // "guangdong-tel"{,shell's value is equal to \"gelgejlge-lxjgle-\"{ pText = argv[3]; if (NULL == (pPcre = pcre_compile(p2Pattern, 0, &pErrMsg, &eOffset, NULL))) { printf("ErrMsg=%s, Offset=%d\n", pErrMsg, eOffset); return 1; } else { ret = pcre_exec(pPcre, NULL, pText, strlen(pText), 0, 0, (int*)&nOffset, 256); if (ret < 0) { printf("%s doesn't match %s\n", pText, p2Pattern); } else { printf("%s matches %s\n", pText, p2Pattern); int i; for (i=0; i<ret; i++) { printf("位置:%d\n", nOffset[2*i]); } pcre_get_substring(pText, nOffset, ret, 1, &(subMatchStr)); printf("匹配的position地址:%s\n", subMatchStr); } } pcre_free(pPcre); return 0; }
RegularExpression::Private::~Private() { pcre_free(regex); }
int vcfCanProp( VcProp *const propp ){ /*note: REFERENCE: the regex code in this section has been * LARGLY copied/influenced by * http://www.ncbi.nlm.nih.gov/IEB/ToolBox/C_DOC/lxr/source/regexp/demo/pcredemo.c*/ //Declaring regex stuff pcre *re; const char *error; int erroffset; int ovector[30]; int rc; if (propp->name == VCP_GEO){ char * namecpy = strdup(propp->value); assert(namecpy); re = pcre_compile( "(-?90\\.0{6}|-?[0-8]?[0-9]\\.[0-9]{6});(-?180\\.0{6}|-?1?[0-7]?[0-9]\\.[0-9]{6})",0,&error,&erroffset,NULL); if (re == NULL){ fprintf(stderr,"Regex failed to compile\n"); return 3; } /*Attempting to match with the canon form of geo*/ rc = pcre_exec(re,NULL,namecpy,(int)strlen(namecpy),0,0,ovector,30); if (rc < 0){ switch(rc) { case PCRE_ERROR_NOMATCH: pcre_free(re); re = pcre_compile( "(-?90\\.0{6}|-?[0-8]?[0-9]\\.[0-9]{0,6})[;, ](-?180\\.0{6}|-?1?[0-7]?[0-9]\\.[0-9]{0,6})",0,&error,&erroffset,NULL); /*Now attempting to put geo in canon form*/ rc = pcre_exec(re,NULL,namecpy,(int)strlen(namecpy),0,0,ovector,30); if (rc < 0){ free(namecpy); pcre_free(re); return 3; } else{ /*Replacing space or , with a semi colon*/ int substring_length = ovector[1] - ovector[0]; if (substring_length == strlen(namecpy)){ char * temp; if ((temp = strchr(namecpy,',')) != NULL){ temp[0] = ';'; free(propp->value); propp->value = strdup(namecpy); } else{ temp = strchr(namecpy,' '); temp[0] = ';'; free(propp->value); propp->value = strdup(namecpy); } pcre_free(re); free(namecpy); return 2; } else{ pcre_free(re); free(namecpy); return 3; } } break; default:free(namecpy); pcre_free(re); return 3; break; } } else{ /*There is a match!!*/ int substring_length = ovector[1] - ovector[0]; if (substring_length == strlen(namecpy)){ free(namecpy); pcre_free(re); return 1; } else{ free(namecpy); pcre_free(re); return 3; } } } else if (propp->name == VCP_N){ char * namecpy = strdup(propp->value); assert(namecpy); re = pcre_compile( "(\\(none\\)|[A-Z][a-z ']*);(\\(none\\)|[A-Z][a-z ']*)",0,&error,&erroffset,NULL); if (re == NULL){ fprintf(stderr,"Regex failed to compile\n"); free(namecpy); return 3; } /*Attempting to match the regex for canon name*/ rc = pcre_exec(re,NULL,namecpy,(int)strlen(namecpy),0,0,ovector,30); if (rc < 0){ switch(rc) { case PCRE_ERROR_NOMATCH: pcre_free(re); re = pcre_compile( "[a-z][a-z0-9 ']*;[a-z][a-z0-9 ']*",0,&error,&erroffset,NULL); /*Attempting to put name into canon form*/ rc = pcre_exec(re,NULL,namecpy,(int)strlen(namecpy),0,0,ovector,30); if (rc < 0){ if (strchr(namecpy,';') == NULL){ if (strcmp(namecpy,"\0") == 0){ free(propp->value); propp->value = malloc(sizeof(char)*20); strcpy(propp->value,"(none);(none)\0"); free(namecpy); pcre_free(re); return 2; } propp->value = realloc(propp->value, sizeof(char)*(strlen(propp->value)+10)); assert(propp->value); propp->value[0] = toupper(propp->value[0]); strcat(propp->value,";(none)\0"); free(namecpy); pcre_free(re); return 2; } if (namecpy[0] == ';'){ free(propp->value); propp->value = malloc(sizeof(char)*strlen(namecpy)+20); assert(propp->value); strcpy(propp->value,"(none)\0"); char * temp = strchr(namecpy+1,';'); if (temp != NULL){ if (temp[1] == '\0'){ strcat(propp->value,";(none)\0"); } else if (temp[1] == ';'){ strcat(propp->value,";(none);\0"); } else{ temp[1] = toupper(temp[1]); } } else{ strcat(propp->value,";(none)\0"); } free(namecpy); pcre_free(re); return 2; } else{ propp->value[0] = toupper(propp->value[0]); propp->value = realloc(propp->value, (strlen(propp->value)+20)*sizeof(char)); char * temp = strchr(namecpy+1,';'); if (temp != NULL){ if (temp[1] == '\0'){ strcat(propp->value,"(none)\0"); } else if (temp[1] == ';'){ strcat(propp->value,"(none);\0"); } else{ temp[1] = toupper(temp[1]); } } } free(namecpy); pcre_free(re); return 2; } else{ namecpy[0] = toupper(namecpy[0]); char * next = strchr(namecpy,';') +1; next[0] = toupper(next[0]); free(propp->value); propp->value =strdup(namecpy); assert(propp->value); free(namecpy); pcre_free(re); return 2; } break; default:free(namecpy); pcre_free(re); return 3; break; } } else{ free(namecpy); pcre_free(re); return 1; } } else if (propp->name == VCP_TEL){ return 1; } else if (propp->name == VCP_ADR){ return 1; } else return 0; }
static bool load_config(plugin_state_t *pstate, invalidate_t **ilist) { FILE *fs; struct stat s; size_t path_len; char *path; char line[LINE_MAX]; time_t now; pcre *config_re; const char *errptr; int erroffset, ovector[OVECTOR_SIZE], rc; int ln = 0; invalidate_t *iptr, *i; if (pstate->config_file[0] != '/') { path_len = strlen(TSConfigDirGet()) + strlen(pstate->config_file) + 2; path = alloca(path_len); snprintf(path, path_len, "%s/%s", TSConfigDirGet(), pstate->config_file); } else { path = pstate->config_file; } if (stat(path, &s) < 0) { TSDebug(LOG_PREFIX, "Could not stat %s", path); return false; } if (s.st_mtime > pstate->last_load) { now = time(NULL); if (!(fs = fopen(path, "r"))) { TSDebug(LOG_PREFIX, "Could not open %s for reading", path); return false; } config_re = pcre_compile("^([^#].+?)\\s+(\\d+)\\s*$", 0, &errptr, &erroffset, NULL); while (fgets(line, LINE_MAX, fs) != NULL) { ln++; TSDebug(LOG_PREFIX, "Processing: %d %s", ln, line); rc = pcre_exec(config_re, NULL, line, strlen(line), 0, 0, ovector, OVECTOR_SIZE); if (rc == 3) { i = (invalidate_t *)TSmalloc(sizeof(invalidate_t)); init_invalidate_t(i); pcre_get_substring(line, ovector, rc, 1, &i->regex_text); i->epoch = now; i->expiry = atoi(line + ovector[4]); i->regex = pcre_compile(i->regex_text, 0, &errptr, &erroffset, NULL); if (i->expiry <= i->epoch) { TSDebug(LOG_PREFIX, "Rule is already expired!"); free_invalidate_t(i); } else if (i->regex == NULL) { TSDebug(LOG_PREFIX, "%s did not compile", i->regex_text); free_invalidate_t(i); } else { i->regex_extra = pcre_study(i->regex, 0, &errptr); if (!*ilist) { *ilist = i; TSDebug(LOG_PREFIX, "Created new list and Loaded %s %d %d", i->regex_text, (int)i->epoch, (int)i->expiry); } else { iptr = *ilist; while (1) { if (strcmp(i->regex_text, iptr->regex_text) == 0) { if (iptr->expiry != i->expiry) { TSDebug(LOG_PREFIX, "Updating duplicate %s", i->regex_text); iptr->epoch = i->epoch; iptr->expiry = i->expiry; } free_invalidate_t(i); i = NULL; break; } else if (!iptr->next) { break; } else { iptr = iptr->next; } } if (i) { iptr->next = i; TSDebug(LOG_PREFIX, "Loaded %s %d %d", i->regex_text, (int)i->epoch, (int)i->expiry); } } } } else { TSDebug(LOG_PREFIX, "Skipping line %d", ln); } } pcre_free(config_re); fclose(fs); pstate->last_load = s.st_mtime; return true; } else { TSDebug(LOG_PREFIX, "File mod time is not newer: %d >= %d", (int)pstate->last_load, (int)s.st_mtime); } return false; }