/* * Extract all urls from a given string. * * Return: a string of urls separated by \n * */ char *extract_urls(const char *to_match) { char *urls = NULL; if (!regex_init()) return NULL; const char *p = to_match; regmatch_t m; while (1) { int nomatch = regexec(&cregex, p, 1, &m, 0); if (nomatch) { return urls; } int start; int finish; if (m.rm_so == -1) { break; } start = m.rm_so + (p - to_match); finish = m.rm_eo + (p - to_match); char *match = g_strndup(to_match + start, finish - start); urls = string_append(urls, match, "\n"); g_free(match); p += m.rm_eo; } return urls; }
/* * Function test */ int main(int argc, char *argv[]) { #ifdef HAS_POSIX_REGEX char buf[MAXINETADDR]; regex_init(); # if 0 do { printf("Enter regex pattern [ENTER=end of list]: "); fflush(stdout); fgets(buffer, sizeof(buffer), stdin); strip_crlf(buffer); if(buffer[0]) regex_do_entry(buffer); } while(buffer[0]); printf("\n"); # endif /* Read strings to match */ do { printf("Enter string [ENTER=end]: "); fflush(stdout); fgets(buffer, sizeof(buffer), stdin); strip_crlf(buffer); if(buffer[0]) { if(regex_match(buffer)) { printf("MATCH, "); debug_subs(); str_regex_match_sub(buf, sizeof(buf), 1, buffer); printf(" (1) = \"%s\"\n", buf); } else { printf("NO MATCH\n"); } } } while(buffer[0]); #endif exit(0); }
u32 dcdm_dp_init_ac_engine(void *buf) { u32 size; dcdmd_sig_ac_spec_s *ac_spec; if(NULL == buf) { return 1; } ac_spec = (dcdmd_sig_ac_spec_s *)buf; if(regex_init()) { return ERROR_NO_MEMORY; } memset(&g_dcdm_ac_engine, 0, sizeof(dcdm_ac_engine_s)); g_dcdm_ac_engine.ac.method = ac_spec->ac_method; g_dcdm_ac_engine.ac.threshold_state = ac_spec->ac_threshold_state; size = g_dp_ac_full_num_states * AC_BITMAP_STATE_NUM_RATIO * (sizeof(ac_bitmap_s) + sizeof(u32)); g_dcdm_ac_engine.ac.bitmap_state_table = conplat_malloc (size, MODULEID_DCDM); if(NULL == g_dcdm_ac_engine.ac.bitmap_state_table) { printk("<0>Fail to alloc memory for ac bitmap state table!\r\n"); return ERROR_NO_MEMORY; } g_dcdm_ac_engine.bitmap_state_table_size = size; size = g_dp_ac_full_num_states * (AC_BITMAP_STATE_NUM_RATIO + 1) * sizeof(ac_search_match_s); g_dcdm_ac_engine.ac.match_table = conplat_malloc (size, MODULEID_DCDM); if(NULL == g_dcdm_ac_engine.ac.match_table) { printk("<0>Fail to alloc memory for ac match state table!\r\n"); return ERROR_NO_MEMORY; } g_dcdm_ac_engine.match_state_table_size = size; ac_init(); return ERROR_SUCCESS; }
int main(int argc, char *argv[]) { char **newargv; char *name; int i; if (argc <= 1) return 0; regex_init(); for (i = 0, name = environ[i]; name != NULL; name = environ[++i]) { if (regex_rmcheck(name)) { if (! regex_keepcheck(name)) namelist_add(name); } } namelist_unset(); newargv = mkargs(argc, argv); execvp(newargv[0], newargv); printf(PNAME ": failed to execute %s\n", newargv[0]); return 1; }
int main(int argc, char **argv) { char config_file[PATH_MAX+1]; /* Parse command line arguments. */ { int ch, dflag = 0; opterr = 0; while((ch = getopt(argc, argv, "dvc:")) != -1) { switch(ch) { case 'd': dflag = 1; break; case 'v': if(++vlevel > 3) vlevel = 3; break; case 'c': strncpy(config_file, optarg, PATH_MAX); break; case '?': default: usage(argv[0]); exit(1); break; } } if(dflag == 1) daemonize(); } /* Determine what configuration file to use. */ if(strlen(config_file) > 0) { if(access(config_file, F_OK|R_OK) != 0) { switch(errno) { case ENOENT: if(vlevel > 0) fprintf(stderr, "[INFO] Can't find configuration file (%s).\n", config_file); break; case EACCES: if(vlevel > 0) fprintf(stderr, "[INFO] Can't access the file (%s).\n", config_file); break; } exit(1); } } else { char *homedir = getenv("HOME"); snprintf(config_file, PATH_MAX, "%s/%s", homedir, CONFIG_FILENAME); if(access(config_file, F_OK|R_OK) != 0) { switch(errno) { case ENOENT: if(vlevel > 0) fprintf(stderr, "[INFO] Can't find configuration file (%s).\n", config_file); break; case EACCES: if(vlevel > 0) fprintf(stderr, "[INFO] Can't access the file (%s).\n", config_file); break; } if(vlevel > 0) fprintf(stderr, "[INFO] Attempting to use default configuration in %s.\n", CONFIG_DEFAULT_PATH); if(access(CONFIG_DEFAULT_PATH, F_OK|R_OK) != 0) { fprintf(stderr, "No configuration file was found.\n"); exit(1); } strncpy(config_file, CONFIG_DEFAULT_PATH, PATH_MAX); } } /* Initialize our module system just before we read our configs. */ mod_init(); /* Get bot configurations and place in bots. */ bots = calloc(1, sizeof(*bots)); if(bots == NULL) return -1; read_config(config_file); #ifdef OPENSSL_ENABLED /* If compiled with OpenSSL support, setup thread locking callbacks and locks. */ ssl_init(); #endif /* OPENSSL_ENABLED */ /* Initialize our regular expressions. */ regex_init(); /* XXX Remove this for release. */ //mod_load("libmod_urltools.dylib"); /* Create all nessesary threads. */ { struct bot_in *next_bot = bots->b_first; /* Make our threads detachable. */ pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); /* Set some thread specific stuffs. */ pthread_key_create(&m_sock_fds, NULL); pthread_key_create(&bot, NULL); pthread_key_create(&irc_s, NULL); /* Launch a new thread per bot. */ for(; next_bot != NULL; next_bot = next_bot->next) bot_spawn(next_bot); } /* Exit the current thread and allow the others to continue. */ pthread_exit(NULL); return(0); }