static void ebt_load_watcher(const char *name) { struct xtables_target *watcher; size_t size; watcher = xtables_find_target(name, XTF_LOAD_MUST_SUCCEED); if (!watcher) xtables_error(OTHER_PROBLEM, "Unable to load %s watcher", name); size = XT_ALIGN(sizeof(struct xt_entry_target)) + watcher->size; watcher->t = xtables_calloc(1, size); watcher->t->u.target_size = size; strncpy(watcher->t->u.user.name, name, sizeof(watcher->t->u.user.name)); watcher->t->u.user.name[sizeof(watcher->t->u.user.name)-1] = '\0'; watcher->t->u.user.revision = watcher->revision; xs_init_target(watcher); opts = merge_options(opts, watcher->extra_opts, &watcher->option_offset); if (opts == NULL) xtables_error(OTHER_PROBLEM, "Can't alloc memory"); }
/* * More glue code. */ static struct xtables_target *command_jump(struct ebtables_command_state *cs, const char *jumpto) { struct xtables_target *target; size_t size; /* XTF_TRY_LOAD (may be chain name) */ target = xtables_find_target(jumpto, XTF_TRY_LOAD); if (!target) return NULL; size = XT_ALIGN(sizeof(struct xt_entry_target)) + target->size; target->t = xtables_calloc(1, size); target->t->u.target_size = size; strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name)); target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0'; target->t->u.user.revision = target->revision; xs_init_target(target); opts = merge_options(opts, target->extra_opts, &target->option_offset); if (opts == NULL) xtables_error(OTHER_PROBLEM, "Can't alloc memory"); return target; }
void NumericalExpressionNormalizer::fix_by_range_expression(const pfi::data::string::ustring& utext, std::vector<NumericalExpression>& numexps) { for(int i=0; i<static_cast<int>(numexps.size()-1); i++){ if(have_kara_suffix(numexps[i].options) && have_kara_prefix(numexps[i+1].options) && numexps[i].position_end +2 >= numexps[i+1].position_start){ if(!suffix_match_counter(numexps[i].counter, numexps[i+1].counter)) continue; numexps[i].value_upperbound = numexps[i+1].value_upperbound; numexps[i].position_end = numexps[i+1].position_end; numexps[i].set_original_expression_from_position(utext); //memo :単位のマージは、必ずiの方がi+1よりも長いので、する必要なし merge_options(numexps[i].options, numexps[i+1].options); numexps.erase(numexps.begin()+i+1); } } }
void action_t::parse_options( option_t* options, const std::string& options_str ) { option_t base_options[] = { { "P400", OPT_BOOL, &P400 }, { "bloodlust", OPT_BOOL, &bloodlust_active }, { "haste<", OPT_FLT, &max_haste }, { "haste_gain_percentage>", OPT_FLT, &haste_gain_percentage }, { "health_percentage<", OPT_FLT, &max_health_percentage }, { "health_percentage>", OPT_FLT, &min_health_percentage }, { "if", OPT_STRING, &if_expr_str }, { "invulnerable", OPT_BOOL, &invulnerable }, { "moving", OPT_BOOL, &moving }, { "rank", OPT_INT, &rank_index }, { "sync", OPT_STRING, &sync_str }, { "time<", OPT_FLT, &max_current_time }, { "time>", OPT_FLT, &min_current_time }, { "time_to_die<", OPT_FLT, &max_time_to_die }, { "time_to_die>", OPT_FLT, &min_time_to_die }, { "travel_speed", OPT_FLT, &travel_speed }, { "vulnerable", OPT_BOOL, &vulnerable }, { "wait_on_ready", OPT_BOOL, &wait_on_ready }, { NULL, 0, NULL } }; std::vector<option_t> merged_options; merge_options( merged_options, options, base_options ); std::string::size_type cut_pt = options_str.find_first_of( ":" ); std::string options_buffer; if ( cut_pt != options_str.npos ) { options_buffer = options_str.substr( cut_pt + 1 ); } else options_buffer = options_str; if ( options_buffer.empty() ) return; if ( options_buffer.size() == 0 ) return; if ( ! option_t::parse( sim, name(), merged_options, options_buffer ) ) { sim -> errorf( "%s %s: Unable to parse options str '%s'.\n", player -> name(), name(), options_str.c_str() ); sim -> cancel(); } }
/* This code is very similar to iptables/xtables.c:command_match() */ static void ebt_load_match(const char *name) { struct xtables_match *m; size_t size; m = xtables_find_match(name, XTF_LOAD_MUST_SUCCEED, NULL); if (m == NULL) xtables_error(OTHER_PROBLEM, "Unable to load %s match", name); size = XT_ALIGN(sizeof(struct xt_entry_match)) + m->size; m->m = xtables_calloc(1, size); m->m->u.match_size = size; strcpy(m->m->u.user.name, m->name); m->m->u.user.revision = m->revision; xs_init_match(m); opts = merge_options(opts, m->extra_opts, &m->option_offset); if (opts == NULL) xtables_error(OTHER_PROBLEM, "Can't alloc memory"); }
static int print_ipt(struct action_util *au, FILE * f, struct rtattr *arg) { struct rtattr *tb[TCA_IPT_MAX + 1]; struct xt_entry_target *t = NULL; if (arg == NULL) return -1; set_lib_dir(); parse_rtattr_nested(tb, TCA_IPT_MAX, arg); if (tb[TCA_IPT_TABLE] == NULL) { fprintf(f, "[NULL ipt table name ] assuming mangle "); } else { fprintf(f, "tablename: %s ", rta_getattr_str(tb[TCA_IPT_TABLE])); } if (tb[TCA_IPT_HOOK] == NULL) { fprintf(f, "[NULL ipt hook name ]\n "); return -1; } else { __u32 hook; hook = rta_getattr_u32(tb[TCA_IPT_HOOK]); fprintf(f, " hook: %s\n", ipthooks[hook]); } if (tb[TCA_IPT_TARG] == NULL) { fprintf(f, "\t[NULL ipt target parameters ]\n"); return -1; } else { struct xtables_target *m = NULL; t = RTA_DATA(tb[TCA_IPT_TARG]); m = find_target(t->u.user.name, TRY_LOAD); if (m != NULL) { if (build_st(m, t) < 0) { fprintf(stderr, " %s error\n", m->name); return -1; } opts = merge_options(opts, m->extra_opts, &m->option_offset); } else { fprintf(stderr, " failed to find target %s\n\n", t->u.user.name); return -1; } fprintf(f, "\ttarget "); m->print(NULL, m->t, 0); if (tb[TCA_IPT_INDEX] == NULL) { fprintf(f, " [NULL ipt target index ]\n"); } else { __u32 index; index = rta_getattr_u32(tb[TCA_IPT_INDEX]); fprintf(f, "\n\tindex %u", index); } if (tb[TCA_IPT_CNT]) { struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]); fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt); } if (show_stats) { if (tb[TCA_IPT_TM]) { struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]); print_tm(f, tm); } } fprintf(f, "\n"); } free_opts(opts); return 0; }
static int parse_ipt(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) { struct xtables_target *m = NULL; struct ipt_entry fw; struct rtattr *tail; int c; int rargc = *argc_p; char **argv = *argv_p; int argc = 0, iargc = 0; char k[FILTER_NAMESZ]; int size = 0; int iok = 0, ok = 0; __u32 hook = 0, index = 0; set_lib_dir(); { int i; for (i = 0; i < rargc; i++) { if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) { break; } } iargc = argc = i; } if (argc <= 2) { fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc); return -1; } while (1) { c = getopt_long(argc, argv, "j:", opts, NULL); if (c == -1) break; switch (c) { case 'j': m = find_target(optarg, TRY_LOAD); if (m != NULL) { if (build_st(m, NULL) < 0) { printf(" %s error\n", m->name); return -1; } opts = merge_options(opts, m->extra_opts, &m->option_offset); } else { fprintf(stderr, " failed to find target %s\n\n", optarg); return -1; } ok++; break; default: memset(&fw, 0, sizeof(fw)); if (m) { m->parse(c - m->option_offset, argv, 0, &m->tflags, NULL, &m->t); } else { fprintf(stderr, " failed to find target %s\n\n", optarg); return -1; } ok++; break; } } if (iargc > optind) { if (matches(argv[optind], "index") == 0) { if (get_u32(&index, argv[optind + 1], 10)) { fprintf(stderr, "Illegal \"index\"\n"); free_opts(opts); return -1; } iok++; optind += 2; } } if (!ok && !iok) { fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv); return -1; } /* check that we passed the correct parameters to the target */ if (m) m->final_check(m->tflags); { struct tcmsg *t = NLMSG_DATA(n); if (t->tcm_parent != TC_H_ROOT && t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) { hook = NF_IP_PRE_ROUTING; } else { hook = NF_IP_POST_ROUTING; } } tail = addattr_nest(n, MAX_MSG, tca_id); fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]); fprintf(stdout, "\ttarget: "); if (m) m->print(NULL, m->t, 0); fprintf(stdout, " index %d\n", index); if (strlen(tname) > 16) { size = 16; k[15] = 0; } else { size = 1 + strlen(tname); } strncpy(k, tname, size); addattr_l(n, MAX_MSG, TCA_IPT_TABLE, k, size); addattr_l(n, MAX_MSG, TCA_IPT_HOOK, &hook, 4); addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4); if (m) addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size); addattr_nest_end(n, tail); argc -= optind; argv += optind; *argc_p = rargc - iargc; *argv_p = argv; optind = 0; free_opts(opts); /* Clear flags if target will be used again */ m->tflags = 0; m->used = 0; /* Free allocated memory */ if (m->t) free(m->t); return 0; }
static void merge_target(struct ebt_u_target *t) { ebt_options = merge_options (ebt_options, t->extra_ops, &(t->option_offset)); }
static void merge_match(struct ebt_u_match *m) { ebt_options = merge_options (ebt_options, m->extra_ops, &(m->option_offset)); }
static void merge_watcher(struct ebt_u_watcher *w) { ebt_options = merge_options (ebt_options, w->extra_ops, &(w->option_offset)); }