return length + sublen;
}
-static void parse_condition(char const *input, char *output, size_t outlen)
+static void parse_condition(fr_dict_t const *dict, char const *input, char *output, size_t outlen)
{
ssize_t dec_len;
char const *error = NULL;
fr_cond_t *cond;
- dec_len = fr_cond_tokenize(NULL, NULL, input, &cond, &error, FR_COND_ONE_PASS);
+ dec_len = fr_cond_tokenize(NULL, &cond, &error, dict, NULL, input, FR_COND_ONE_PASS);
if (dec_len <= 0) {
snprintf(output, outlen, "ERROR offset %d %s", (int) -dec_len, error);
return;
p += 14;
}
- if (fr_pair_list_afrom_str(packet, proto_dict, p, &head) != T_EOL) {
+ if (fr_pair_list_afrom_str(packet, proto_dict ? proto_dict : dict, p, &head) != T_EOL) {
strerror_concat(output, sizeof(output));
talloc_free(packet);
if (strcmp(test_type, "attribute") == 0) {
p += 10;
- if (fr_pair_list_afrom_str(NULL, proto_dict, p, &head) != T_EOL) {
+ if (fr_pair_list_afrom_str(NULL, proto_dict ? proto_dict : dict, p, &head) != T_EOL) {
strerror_concat(output, sizeof(output));
continue;
}
if (strcmp(test_type, "condition") == 0) {
p += 10;
- parse_condition(p, output, sizeof(output));
+ parse_condition(proto_dict ? proto_dict : dict, p, output, sizeof(output));
continue;
}
/*
* Skip (...) to find the {
*/
- slen = fr_cond_tokenize(this, cf_section_to_item(this), ptr, &cond,
- &error, FR_COND_TWO_PASS);
+ slen = fr_cond_tokenize(this, &cond, &error,
+ NULL, cf_section_to_item(this), ptr, FR_COND_TWO_PASS);
memcpy(&p, &ptr, sizeof(p));
if (slen < 0) {
css->item.filename = filename;
css->item.lineno = *lineno;
- slen = fr_cond_tokenize(css, cf_section_to_item(css), ptr, &cond,
- &error, FR_COND_TWO_PASS);
+ slen = fr_cond_tokenize(css, &cond, &error,
+ NULL, cf_section_to_item(css), ptr, FR_COND_TWO_PASS);
*p = '{'; /* put it back */
cond_error:
/** Tokenize a conditional check
*
* @param[in] ctx for talloc
+ * @param[out] pcond pointer to the returned condition structure
+ * @param[out] error the parse error (if any)
* @param[in] ci for CONF_ITEM
* @param[in] start the start of the string to process. Should be "(..."
* @param[in] brace look for a closing brace
- * @param[out] pcond pointer to the returned condition structure
- * @param[out] error the parse error (if any)
* @param[in] flags do one/two pass
* @param[in] rules for attribute parsing
* @return
* - Length of the string skipped.
* - < 0 (the offset to the offending error) on error.
*/
-static ssize_t cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start, bool brace,
- fr_cond_t **pcond, char const **error, int flags, vp_tmpl_rules_t const *rules)
+static ssize_t cond_tokenize(TALLOC_CTX *ctx, fr_cond_t **pcond, char const **error,
+ CONF_ITEM *ci, char const *start, bool brace,
+ int flags, vp_tmpl_rules_t const *rules)
{
ssize_t slen, tlen;
char const *p = start;
*/
c->type = COND_TYPE_CHILD;
c->ci = ci;
- slen = cond_tokenize(c, ci, p, true, &c->data.child, error, flags, rules);
+ slen = cond_tokenize(c, &c->data.child, error, ci, p, true, flags, rules);
if (slen <= 0) return_SLEN;
if (!c->data.child) {
/*
* May still be looking for a closing brace.
*/
- slen = cond_tokenize(c, ci, p, brace, &c->next, error, flags, rules);
+ slen = cond_tokenize(c, &c->next, error, ci, p, brace, flags, rules);
if (slen <= 0) {
return_slen:
if (lhs) talloc_free(lhs);
/** Tokenize a conditional check
*
- * @param[in] ctx for talloc
- * @param[in] ci for CONF_ITEM
- * @param[in] start the start of the string to process. Should be "(..."
- * @param[out] head the parsed condition structure
- * @param[out] error the parse error (if any)
- * @param[in] flags do one/two pass
- * @return
+ * @param[in] ctx for talloc
+ * @param[out] head the parsed condition structure
+ * @param[out] error the parse error (if any)
+ * @param[in] dict dictionary to resolve attributes in.
+ * @param[in] ci for CONF_ITEM
+ * @param[in] start the start of the string to process. Should be "(..."
+ * @param[in] flags do one/two pass
+ * @return
* - Length of the string skipped.
* - < 0 (the offset to the offending error) on error.
*/
-ssize_t fr_cond_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *start,
- fr_cond_t **head, char const **error, int flags)
+ssize_t fr_cond_tokenize(TALLOC_CTX *ctx,
+ fr_cond_t **head, char const **error,
+ fr_dict_t const *dict,
+ CONF_ITEM *ci, char const *start, int flags)
{
- vp_tmpl_rules_t parse_rules;
-
- memset(&parse_rules, 0, sizeof(parse_rules));
+ vp_tmpl_rules_t parse_rules = {
+ .dict_def = dict
+ };
- return cond_tokenize(ctx, ci, start, false, head, error, flags, &parse_rules);
+ return cond_tokenize(ctx, head, error, ci, start, false, flags, &parse_rules);
}
/*