/** fixup variable-pve-string. * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string) * or string. * PVAR, AVP and select and non-static PVEs identifiers will be resolved to * their values during runtime. * The parameter value will be converted to fparam structure * @param param - double pointer to param, as for normal fixup functions. * @param param_no - parameter number, ignored. * @return -1 on an error, 0 on success. */ int fixup_var_pve_str_12(void** param, int param_no) { int ret; fparam_t* fp; if (fixup_get_param_type(param) != STRING_RVE_ST) { /* if called with a RVE already converted to string => * don't try AVP, PVAR, SELECT or PVE again (to avoid double * deref., e.g.: $foo="$bar"; f($foo) ) */ if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret; if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret; if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret; if ((ret = fix_param(FPARAM_PVE, param)) <= 0) { if (ret < 0) return ret; /* check if it resolved to a dynamic or "static" PVE. * If the resulting PVE is static (normal string), discard * it and use the normal string fixup (faster at runtime) */ fp = (fparam_t*)*param; if (fp->v.pve->spec == 0 || fp->v.pve->spec->getf == 0) fparam_free_restore(param); /* fallback to STR below */ else return ret; /* dynamic PVE => return */ } } if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret; LM_ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions" " failed\n"); return -1; }
/* (char *$proto, char *$host:port) ==> (fparam, fparam) */ static int fixup_proto_hostport2proxy(void** param, int param_no) { int ret; ret = fix_param(FPARAM_AVP, param); if (ret <= 0) return ret; /* if (param_no = 1) { FIXME: param_str currently does not offer INT/STR overloading ret = fix_param(FPARAM_INT, param); if (ret <= 0) return ret; } */ return fix_param(FPARAM_STRING, param); }
static int fixup_ping_contact(void **param, int param_no) { int ret; if (param_no == 1) { ret = fix_param(FPARAM_AVP, param); if (ret <= 0) return ret; if (fix_param(FPARAM_STR, param) != 0) return -1; } return 0; }
static int fixup_t_reply(void** param, int param_no) { int ret; if (param_no == 1) { ret = fix_param(FPARAM_AVP, param); if (ret <= 0) return ret; return fix_param(FPARAM_INT, param); } else if (param_no == 2) { return fixup_var_str_12(param, 2); } return 0; }
/* * Fixup variable integer, the parameter can be * AVP, SELECT, or ordinary integer. AVP and select * identifiers will be resolved to their values and * converted to int if necessary during runtime * * The parameter value will be converted to fparam structure * This function returns -1 on an error */ int fixup_var_int_12(void** param, int param_no) { int ret; if (fixup_get_param_type(param) != STRING_RVE_ST) { /* if called with a RVE already converted to string => * don't try AVP, PVAR or SELECT (to avoid double * deref., e.g.: $foo="$bar"; f($foo) ) */ if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret; if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret; if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret; } if ((ret = fix_param(FPARAM_INT, param)) <= 0) return ret; LM_ERR("Error while fixing parameter, PV, AVP, SELECT, and int conversions" " failed\n"); return -1; }
static int fixup_rl_drop(void **param, int param_no) { if (param_no == 1) return fix_param(FPARAM_INT, param); else return fixup_var_int_12(param, 2); }
/* * The parameter must be a regular expression which must compile, the * parameter will be converted to compiled regex */ int fixup_regex_12(void** param, int param_no) { int ret; if ((ret = fix_param(FPARAM_REGEX, param)) <= 0) return ret; LM_ERR("Error while compiling regex in function parameter\n"); return -1; }
/* * Parse the parameter as static string, do not resolve * AVPs or selects, convert the parameter to str structure */ int fixup_str_12(void** param, int param_no) { int ret; if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret; LM_ERR("Cannot function parameter to string\n"); return -1; }
static int avpid_fixup(void** param, int param_no) { if (param_no == 1) { if (fix_param(FPARAM_AVP, param) == 0) return 0; ERR("Invalid AVP identifier: '%s'\n", (char*)*param); return -1; } return 0; }
/* * The string parameter will be converted to integer */ int fixup_int_12(void** param, int param_no) { int ret; if ((ret = fix_param(FPARAM_INT, param)) <= 0) return ret; LM_ERR("Cannot function parameter to integer\n"); return -1; }
static int subst_attr_fixup(void** param, int param_no) { if (param_no == 1) { return avpid_fixup(param, 1); } if (param_no == 2) { if (fix_param(FPARAM_SUBST, param) != 0) return -1; } return 0; }
/* ---------------------------------------------- */ static int fix_header_len(tvbuff_t *tvb, int offset) { int base_offset, ctrla_offset; char *value; int size; fix_parameter *tag; base_offset = offset; /* get at least the fix version: 8=FIX.x.x */ if (fix_marker(tvb, offset) != 0) { return fix_next_header(tvb, offset); } /* begin string */ ctrla_offset = tvb_find_guint8(tvb, offset, -1, 0x01); if (ctrla_offset == -1) { /* it should be there, (minimum size is big enough) * if not maybe it's not really * a FIX packet but it's too late to bail out. */ return fix_next_header(tvb, offset +MARKER_LEN) +MARKER_LEN; } offset = ctrla_offset + 1; /* msg length */ if (!(tag = fix_param(tvb, offset)) || tvb_strneql(tvb, offset, "9=", 2)) { /* not a tag or not the BodyLength tag, give up */ return fix_next_header(tvb, offset); } value = tvb_get_ephemeral_string(tvb, tag->value_offset, tag->value_len); /* Fix version, msg type, length and checksum aren't in body length. * If the packet is big enough find the checksum */ size = atoi(value) +tag->ctrla_offset - base_offset +1; if (tvb_length_remaining(tvb, base_offset) > size +4) { /* 10= should be there */ offset = base_offset +size; if (tvb_strneql(tvb, offset, "10=", 3) != 0) { /* No? bogus packet, try to find the next header */ return fix_next_header(tvb, base_offset +MARKER_LEN) +MARKER_LEN; } ctrla_offset = tvb_find_guint8(tvb, offset, -1, 0x01); if (ctrla_offset == -1) { /* assume checksum is 7 bytes 10=xxx\01 */ return size+7; } return size +ctrla_offset -offset +1; } else { } /* assume checksum is 7 bytes 10=xxx\01 */ return size +7; }
static int fixup_part(void** param, int param_no) { int i; fparam_t* fp; static struct { char* s; int i; } fixup_parse[] = { {"", SET_URI_T}, {"prefix", PREFIX_T}, {"uri", SET_URI_T}, {"username", SET_USER_T}, {"user", SET_USER_T}, {"usernamepassword", SET_USERPASS_T}, {"userpass", SET_USERPASS_T}, {"domain", SET_HOST_T}, {"host", SET_HOST_T}, {"domainport", SET_HOSTPORT_T}, {"hostport", SET_HOSTPORT_T}, {"port", SET_PORT_T}, {"strip", STRIP_T}, {"strip_tail", STRIP_TAIL_T}, {0, 0} }; if (param_no == 1) { return avpid_fixup(param, 1); } else if (param_no == 2) { /* Create fparam structure */ if (fix_param(FPARAM_STRING, param) != 0) return -1; /* We will parse the string now and store the value * as int */ fp = (fparam_t*)*param; fp->type = FPARAM_INT; for(i = 0; fixup_parse[i].s; i++) { if (!strcasecmp(fp->orig, fixup_parse[i].s)) { fp->v.i = fixup_parse[i].i; return 1; } } ERR("Invalid parameter value: '%s'\n", fp->orig); return -1; } return 0; }
/* fixup function for w_ipmatch_* */ static int fixup_w_im(void **param, int param_no) { int ret; str *s; if (param_no == 1) { ret = fix_param(FPARAM_AVP, param); if (ret <= 0) return ret; ret = fix_param(FPARAM_SELECT, param); if (ret <= 0) return ret; ret = fix_param(FPARAM_STR, param); if (ret == 0) { s = &((fparam_t *)*param)->v.str; if ((s->len == 3) && (memcmp(s->s, "src", 3) == 0)) return 0; if ((s->len == 4) && (memcmp(s->s, "via2", 4) == 0)) return 0; LOG(L_ERR, "ERROR: fixup_w_im(): unknown string parameter\n"); return -1; } else if (ret < 0) { return ret; } LOG(L_ERR, "ERROR: fixup_w_im(): unknown parameter type\n"); return -1; } else if (param_no == 2) { if (fix_param(FPARAM_AVP, param) != 0) { LOG(L_ERR, "ERROR: fixup_w_im(): unknown AVP identifier: %s\n", (char*)*param); return -1; } return 0; } return 0; }
/** fix a param to one of the given types (mask). * * @param types - bitmap of the allowed types (e.g. FPARAM_INT|FPARAM_STR) * @param param - value/result * @return - 0 on success, -1 on error, 1 if param doesn't * match any of the types */ int fix_param_types(int types, void** param) { int ret; int t; if (fixup_get_param_type(param) == STRING_RVE_ST && (types & (FPARAM_INT|FPARAM_STR|FPARAM_STRING))) { /* if called with a RVE already converted to string => * don't try AVP, PVAR or SELECT (to avoid double * deref., e.g.: $foo="$bar"; f($foo) ) */ types &= ~ (FPARAM_AVP|FPARAM_PVS|FPARAM_SELECT|FPARAM_PVE); } for (t=types & ~(types-1); types; types&=(types-1), t=types & ~(types-1)){ if ((ret=fix_param(t, param))<=0) return ret; } return E_UNSPEC; }
static int fixup_rl_check(void **param, int param_no) { return fix_param(FPARAM_INT, param); }
void voigt::init(ICOS_Float*a) { if ( fix_lwidth) fix_param(gl_idx); func_line::init(a); }
void voigt::line_fix() { fix_param(gl_idx); func_line::line_fix(); }
/* ---------------------------------------------- */ static void dissect_fix_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { /* Set up structures needed to add the protocol subtree and manage it */ proto_item *ti; proto_tree *fix_tree; int pdu_len; int offset = 0; int field_offset, ctrla_offset; int tag_value; char *value; char *tag_str; fix_parameter *tag; /* Make entries in Protocol column and Info column on summary display */ col_set_str(pinfo->cinfo, COL_PROTOCOL, "FIX"); col_clear(pinfo->cinfo, COL_INFO); /* get at least the fix version: 8=FIX.x.x */ if (fix_marker(tvb, 0) != 0) { /* not a fix packet start but it's a fix packet */ col_set_str(pinfo->cinfo, COL_INFO, "[FIX continuation]"); ti = proto_tree_add_item(tree, proto_fix, tvb, 0, -1, ENC_NA); fix_tree = proto_item_add_subtree(ti, ett_fix); proto_tree_add_item(fix_tree, hf_fix_data, tvb, 0, -1, ENC_NA); return; } pdu_len = tvb_reported_length(tvb); ti = proto_tree_add_item(tree, proto_fix, tvb, 0, -1, ENC_NA); fix_tree = proto_item_add_subtree(ti, ett_fix); /* begin string */ ctrla_offset = tvb_find_guint8(tvb, offset, -1, 0x01); if (ctrla_offset == -1) { return; } offset = ctrla_offset + 1; /* msg length */ ctrla_offset = tvb_find_guint8(tvb, offset, -1, 0x01); if (ctrla_offset == -1) { return; } offset = ctrla_offset + 1; /* msg type */ if (!(tag = fix_param(tvb, offset)) || tag->value_len < 1) { return; } if (check_col(pinfo->cinfo, COL_INFO)) { const char *msg_type; value = tvb_get_ephemeral_string(tvb, tag->value_offset, tag->value_len); msg_type = str_to_str(value, messages_val, "FIX Message (%s)"); col_add_str(pinfo->cinfo, COL_INFO, msg_type); } /* In the interest of speed, if "tree" is NULL, don't do any work not * necessary to generate protocol tree items. */ field_offset = 0; while(field_offset < pdu_len && (tag = fix_param(tvb, field_offset)) ) { int i, found; if (tag->tag_len < 1) { field_offset = tag->ctrla_offset + 1; continue; } tag_str = tvb_get_ephemeral_string(tvb, field_offset, tag->tag_len); tag_value = atoi(tag_str); if (tag->value_len < 1) { proto_tree *field_tree; /* XXX - put an error indication here. It's too late to return FALSE; we've already started dissecting, and if a heuristic dissector starts dissecting (either updating the columns or creating a protocol tree) and then gives up, it leaves crud behind that messes up other dissectors that might process the packet. */ ti = proto_tree_add_text(fix_tree, tvb, field_offset, tag->field_len, "%i: <missing value>", tag_value); field_tree = proto_item_add_subtree(ti, ett_badfield); proto_tree_add_uint(field_tree, hf_fix_field_tag, tvb, field_offset, tag->tag_len, tag_value); field_offset = tag->ctrla_offset + 1; continue; } /* fix_fields array is sorted by tag_value */ found = 0; if ((i = tag_search(tag_value)) >= 0) { found = 1; } value = tvb_get_ephemeral_string(tvb, tag->value_offset, tag->value_len); if (found) { if (fix_fields[i].table) { if (tree) { switch (fix_fields[i].type) { case 1: /* strings */ proto_tree_add_string_format_value(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value, "%s (%s)", value, str_to_str(value, fix_fields[i].table, "unknown %s")); break; case 2: /* char */ proto_tree_add_string_format_value(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value, "%s (%s)", value, val_to_str(*value, fix_fields[i].table, "unknown %d")); break; default: proto_tree_add_string_format_value(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value, "%s (%s)", value, val_to_str(atoi(value), fix_fields[i].table, "unknown %d")); break; } } } else { proto_item *item; /* checksum */ switch(tag_value) { case 10: { proto_tree *checksum_tree; guint8 sum = 0; const guint8 *data = tvb_get_ptr(tvb, 0, field_offset); gboolean sum_ok; int j; for (j = 0; j < field_offset; j++, data++) { sum += *data; } sum_ok = (atoi(value) == sum); if (sum_ok) { item = proto_tree_add_string_format_value(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value, "%s [correct]", value); } else { item = proto_tree_add_string_format_value(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value, "%s [incorrect should be %d]", value, sum); } checksum_tree = proto_item_add_subtree(item, ett_checksum); item = proto_tree_add_boolean(checksum_tree, hf_fix_checksum_good, tvb, field_offset, tag->field_len, sum_ok); PROTO_ITEM_SET_GENERATED(item); item = proto_tree_add_boolean(checksum_tree, hf_fix_checksum_bad, tvb, field_offset, tag->field_len, !sum_ok); PROTO_ITEM_SET_GENERATED(item); if (!sum_ok) expert_add_info_format(pinfo, item, PI_CHECKSUM, PI_ERROR, "Bad checksum"); } break; default: proto_tree_add_string(fix_tree, fix_fields[i].hf_id, tvb, field_offset, tag->field_len, value); break; } } } else if (tree) { proto_tree *field_tree; /* XXX - it could be -1 if the tag isn't a number */ ti = proto_tree_add_text(fix_tree, tvb, field_offset, tag->field_len, "%i: %s", tag_value, value); field_tree = proto_item_add_subtree(ti, ett_unknow); proto_tree_add_uint(field_tree, hf_fix_field_tag, tvb, field_offset, tag->tag_len, tag_value); proto_tree_add_item(field_tree, hf_fix_field_value, tvb, tag->value_offset, tag->value_len, ENC_ASCII|ENC_NA); } field_offset = tag->ctrla_offset + 1; tag_str = NULL; } return; }
/** * @param a The global parameter value vector. * We mark nu_F0 as fixed so that it floats only when * there are lines which are strong enough to float. */ void func_abs::init(ICOS_Float *a) { func_evaluator::init(a); fix_param(0); // nu_F0 }