void init_domains(Filter *filters, char *domain_input, const char delimiter){ /* * domain_input is a comma separated list of Wikipedia * (parts of) domain names. Valid examples include: * - en.wikipedia * - en.m.wikipedia * - wikipedia.org * - commons,wikimediafoundation */ int i=0; int error=0; char *input = strdup(domain_input); char *startToken = input; for (;;){ char *endToken; endToken = strchr(startToken, delimiter); if (endToken) { *endToken='\0'; } switch(search){ case STRING: { size_t s = strlen(startToken) + 1; filters[i].domain.string= malloc(sizeof(char)*s); if(filters[i].domain.string==NULL) { error=1; break; } strcpy(filters[i].domain.string,startToken); filters[i].searchtype = DOMAIN_FILTER; break; } case REGEX:{ filters[i].domain.regex= malloc(sizeof(regex_t)); if (filters[i].domain.regex==NULL){ error=1; break; } filters[i].domain.regex = init_regex(startToken); filters[i].searchtype = DOMAIN_FILTER; break; } } if (!endToken){ break; } i++; startToken = endToken + 1; } if (error==1){ fprintf(stderr, "DOMAIN: Could not allocate memory. This should never happen"); exit(EXIT_FAILURE); } free(input); }
void init_http_status(Filter *filters, char *http_status_input, const char delimiter){ /* * http_status_input is a comma separated list of http response status codes * - 200 * - 400 * - 404 * - 501 */ int i=0; int error=0; char *input = strdup(http_status_input); char *startToken = input; for (;;){ char *endToken; endToken = strchr(startToken, delimiter); if (endToken) { *endToken='\0'; } switch(search){ case STRING: { size_t s = strlen(startToken) + 1; filters[i].http_status.string= malloc(sizeof(char)*s); if(filters[i].http_status.string==NULL) { error=1; break; } strcpy(filters[i].http_status.string,startToken); filters[i].searchtype = HTTP_STATUS_FILTER; break; } case REGEX:{ filters[i].http_status.regex= malloc(sizeof(regex_t)); if (filters[i].http_status.regex==NULL){ error=1; break; } filters[i].http_status.regex = init_regex(startToken); filters[i].searchtype = HTTP_STATUS_FILTER; break; } } if (!endToken){ break; } i++; startToken = endToken + 1; } if (error==1){ fprintf(stderr, "HTTP_STATUS: Could not allocate memory. This should never happen"); exit(EXIT_FAILURE); } free(input); }
void init_paths(Filter *filters, char *path_input, const char delimiter) { /* path_input is a string *excluding* the full qualified domain name * path_input can be comma delimited, so we first need to determine the * different parts and then depending on whether the regex_flag is activated * we need to compile the string or else we just store it right away. */ int i=0; int error=0; char *input = strdup(path_input); char *startToken = input; for (;;){ char *endToken; endToken = strchr(startToken, delimiter); if (endToken) { *endToken = '\0'; } switch(search) { case STRING: { size_t s = strlen(startToken) + 1; filters[i].path.string= malloc(sizeof(char)*s); if (filters[i].path.string==NULL) { error=1; break; } strcpy(filters[i].path.string, startToken); filters[i].searchtype = PATH_FILTER; break; } case REGEX:{ filters[i].path.regex =malloc(sizeof(regex_t)); if (filters[i].path.regex==NULL) { error=1; break; } filters[i].path.regex = init_regex(startToken); filters[i].searchtype = PATH_FILTER; break; } } if (!endToken) { break; } i++; startToken = endToken + 1; } if (error==1){ fprintf(stderr, "PATH: Could not allocate memory. This should never happen"); exit(EXIT_FAILURE); } free(input); }
END_TEST START_TEST (test_regex_matching){ Filter filters[1]; int result; int num_path_filters =1; int num_domain_filters =1; regex_t *path_re = init_regex(path_str); regex_t *domain_re = init_regex(domain_str); fail_unless(path_re==NULL); fail_unless(domain_re==NULL); filters[1].path.regex =path_re; filters[1].domain.regex =domain_re; filters[1].searchtype = REGEX; result = match_path(url_str, filters, num_path_filters); fail_unless(result==1); result = match_domain(url_str, filters, num_domain_filters); fail_unless(result==1); }
LcmTunnel::LcmTunnel(bool verbose, const char *lcm_channel) : verbose(verbose), regex(NULL), buf_sz(65536), buf((char*) calloc(65536, sizeof(char))), channel_sz(65536), channel( (char*) calloc(65536, sizeof(char))), recFlags_sz(1024), recFlags((char*) calloc(1024, sizeof(char))), ldpc_dec( NULL), udp_fd(-1), server_udp_port(-1), udp_send_seqno(0), stopSendThread(false), bytesInQueue(0), cur_seqno(0), errorStartTime(-1), numSuccessful(0), lastErrorPrintTime(-1) { //allocate and initialize things init_regex(lcm_channel); //sendThread stuff sendQueueLock = g_mutex_new(); sendQueueCond = g_cond_new(); sendThread = g_thread_create(sendThreadFunc, (void *) this, 1, NULL); }
/* --- */ int init_parser(int argc, char **argv) { print_welcome(); process_cla(argc, argv, 1); print_hs_1(); init_storage(); init_subrs(); init_trace(); init_slibu(); init_ss(); init_ndbm(); init_regex(); init_tar(); return 0; }
void init_monitor(int argc, char *argv[]) { /* Perform some global initialization */ /* Open the log file. */ init_log(); /* Load the string table and symbol table from the ELF file for future use. */ load_elf_tables(argc, argv); /* Compile the regular expressions. */ init_regex(); /* Initialize the watchpoint pool. */ init_wp_pool(); /* Display welcome message. */ welcome(); }
/* --- */ int init_parser(int argc, char **argv) { print_welcome(); process_cla(siod_argc, siod_argv, 1); process_cla(argc, argv, 1); print_hs_1(); init_storage(); init_subrs(); init_trace(); init_slibu(); init_ss(); init_ndbm(); init_regex(); init_tar(); init_subr_0("row", get_row); init_subr_0("col", get_col); init_subr_2("exec-expr", lexec_expr); /*XtAppAddActions(app_context, actions, XtNumber(actions));*/ return register_interpreter("SIOD", NULL, execute_siod); }
void load_builtins() { duplicate_rule( "Always" , bind_builtin( "ALWAYS" , builtin_flags, T_FLAG_TOUCHED, 0 ) ); duplicate_rule( "Depends" , bind_builtin( "DEPENDS" , builtin_depends, 0, 0 ) ); duplicate_rule( "echo" , duplicate_rule( "Echo" , bind_builtin( "ECHO" , builtin_echo, 0, 0 ) ) ); { char * args[] = { "message", "*", ":", "result-value", "?", 0 }; duplicate_rule( "exit" , duplicate_rule( "Exit" , bind_builtin( "EXIT" , builtin_exit, 0, args ) ) ); } { char * args[] = { "directories", "*", ":", "patterns", "*", ":", "case-insensitive", "?", 0 }; duplicate_rule( "Glob" , bind_builtin( "GLOB" , builtin_glob, 0, args ) ); } { char * args[] = { "patterns", "*", 0 }; bind_builtin( "GLOB-RECURSIVELY" , builtin_glob_recursive, 0, args ); } duplicate_rule( "Includes" , bind_builtin( "INCLUDES" , builtin_depends, 1, 0 ) ); { char * args[] = { "targets", "*", ":", "targets-to-rebuild", "*", 0 }; bind_builtin( "REBUILDS" , builtin_rebuilds, 0, args ); } duplicate_rule( "Leaves" , bind_builtin( "LEAVES" , builtin_flags, T_FLAG_LEAVES, 0 ) ); duplicate_rule( "Match" , bind_builtin( "MATCH" , builtin_match, 0, 0 ) ); duplicate_rule( "NoCare" , bind_builtin( "NOCARE" , builtin_flags, T_FLAG_NOCARE, 0 ) ); duplicate_rule( "NOTIME" , duplicate_rule( "NotFile" , bind_builtin( "NOTFILE" , builtin_flags, T_FLAG_NOTFILE, 0 ) ) ); duplicate_rule( "NoUpdate" , bind_builtin( "NOUPDATE" , builtin_flags, T_FLAG_NOUPDATE, 0 ) ); duplicate_rule( "Temporary" , bind_builtin( "TEMPORARY" , builtin_flags, T_FLAG_TEMP, 0 ) ); { char * args[] = { "targets", "*", 0 }; bind_builtin( "ISFILE", builtin_flags, T_FLAG_ISFILE, 0 ); } duplicate_rule( "HdrMacro" , bind_builtin( "HDRMACRO" , builtin_hdrmacro, 0, 0 ) ); /* FAIL_EXPECTED is used to indicate that the result of a target build */ /* action should be inverted (ok <=> fail) this can be useful when */ /* performing test runs from Jamfiles.. */ bind_builtin( "FAIL_EXPECTED" , builtin_flags, T_FLAG_FAIL_EXPECTED, 0 ); bind_builtin( "RMOLD" , builtin_flags, T_FLAG_RMOLD, 0 ); { char * args[] = { "targets", "*", 0 }; bind_builtin( "UPDATE", builtin_update, 0, args ); } { char * args[] = { "string", "pattern", "replacements", "+", 0 }; duplicate_rule( "subst" , bind_builtin( "SUBST" , builtin_subst, 0, args ) ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "RULENAMES" , builtin_rulenames, 0, args ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "VARNAMES" , builtin_varnames, 0, args ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "DELETE_MODULE" , builtin_delete_module, 0, args ); } { char * args[] = { "source_module", "?", ":", "source_rules", "*", ":", "target_module", "?", ":", "target_rules", "*", ":", "localize", "?", 0 }; bind_builtin( "IMPORT" , builtin_import, 0, args ); } { char * args[] = { "module", "?", ":", "rules", "*", 0 }; bind_builtin( "EXPORT" , builtin_export, 0, args ); } { char * args[] = { "levels", "?", 0 }; bind_builtin( "CALLER_MODULE" , builtin_caller_module, 0, args ); } { char * args[] = { "levels", "?", 0 }; bind_builtin( "BACKTRACE" , builtin_backtrace, 0, args ); } { char * args[] = { 0 }; bind_builtin( "PWD" , builtin_pwd, 0, args ); } { char * args[] = { "target", "*", ":", "path", "*", 0 }; bind_builtin( "SEARCH_FOR_TARGET", builtin_search_for_target, 0, args ); } { char * args[] = { "modules_to_import", "+", ":", "target_module", "?", 0 }; bind_builtin( "IMPORT_MODULE", builtin_import_module, 0, args ); } { char * args[] = { "module", "?", 0 }; bind_builtin( "IMPORTED_MODULES", builtin_imported_modules, 0, args ); } { char * args[] = { "instance_module", ":", "class_module", 0 }; bind_builtin( "INSTANCE", builtin_instance, 0, args ); } { char * args[] = { "sequence", "*", 0 }; bind_builtin( "SORT", builtin_sort, 0, args ); } { char * args[] = { "path_parts", "*", 0 }; bind_builtin( "NORMALIZE_PATH", builtin_normalize_path, 0, args ); } { char * args[] = { "args", "*", 0 }; bind_builtin( "CALC", builtin_calc, 0, args ); } { char * args[] = { "module", ":", "rule", 0 }; bind_builtin( "NATIVE_RULE", builtin_native_rule, 0, args ); } { char * args[] = { "module", ":", "rule", ":", "version", 0 }; bind_builtin( "HAS_NATIVE_RULE", builtin_has_native_rule, 0, args ); } { char * args[] = { "module", "*", 0 }; bind_builtin( "USER_MODULE", builtin_user_module, 0, args ); } { char * args[] = { 0 }; bind_builtin( "NEAREST_USER_LOCATION", builtin_nearest_user_location, 0, args ); } { char * args[] = { "file", 0 }; bind_builtin( "CHECK_IF_FILE", builtin_check_if_file, 0, args ); } #ifdef HAVE_PYTHON { char * args[] = { "python-module", ":", "function", ":", "jam-module", ":", "rule-name", 0 }; bind_builtin( "PYTHON_IMPORT_RULE", builtin_python_import_rule, 0, args ); } #endif # if defined( OS_NT ) || defined( OS_CYGWIN ) { char * args[] = { "key_path", ":", "data", "?", 0 }; bind_builtin( "W32_GETREG", builtin_system_registry, 0, args ); } { char * args[] = { "key_path", ":", "result-type", 0 }; bind_builtin( "W32_GETREGNAMES", builtin_system_registry_names, 0, args ); } # endif { char * args[] = { "command", ":", "*", 0 }; bind_builtin( "SHELL", builtin_shell, 0, args ); bind_builtin( "COMMAND", builtin_shell, 0, args ); } /* Initialize builtin modules */ init_set(); init_path(); init_regex(); init_property_set(); init_sequence(); init_order(); }