regex_t *preg; //!< Compiled pattern.
#endif
fr_regmatch_t *regmatch; //!< Match vectors.
+
+ fr_value_box_safe_for_t safe_for;
+ bool secret;
} fr_regcapture_t;
/** Adds subcapture values to request data
* reparented to the regcapture struct.
* @param[in,out] regmatch Pointers into value. May be set to NULL if
* reparented to the regcapture struct.
+ * @param[in] in value-box which we matched against
*/
-void regex_sub_to_request(request_t *request, regex_t **preg, fr_regmatch_t **regmatch)
+void regex_sub_to_request(request_t *request, regex_t **preg, fr_regmatch_t **regmatch, fr_value_box_t const *in)
{
fr_regcapture_t *old_rc, *new_rc; /* lldb doesn't like bare new *sigh* */
fr_assert(preg && *preg);
fr_assert(regmatch);
+ fr_assert(in);
DEBUG4("Adding %zu matches", (*regmatch)->used);
* Steal match data
*/
new_rc->regmatch = talloc_steal(new_rc, *regmatch);
+ new_rc->safe_for = in->safe_for;
+ new_rc->secret = in->secret;
*regmatch = NULL;
request_data_talloc_add(request, request, REQUEST_DATA_REGEX, fr_regcapture_t, new_rc, true, false, false);
* - 0 on success.
* - -1 on notfound.
*/
-int regex_request_to_sub(TALLOC_CTX *ctx, char **out, request_t *request, uint32_t num)
+int regex_request_to_sub(TALLOC_CTX *ctx, fr_value_box_t *out, request_t *request, uint32_t num)
{
fr_regcapture_t *rc;
char *buff;
rc = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rc) {
RDEBUG4("No subcapture data found");
- *out = NULL;
return -1;
}
match_data = talloc_get_type_abort(rc->regmatch->match_data, pcre2_match_data);
*/
case PCRE2_ERROR_NOSUBSTRING:
RDEBUG4("%i/%zu Not found", num + 1, rc->regmatch->used);
- *out = NULL;
return -1;
default:
if (ret < 0) {
- *out = NULL;
return -1;
}
MEM(buff = talloc_array(ctx, char, ++len)); /* +1 for \0, it'll get reset by pcre2_substring */
pcre2_substring_copy_bynumber(match_data, num, (PCRE2_UCHAR *)buff, &len); /* can't error */
- RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used,
- fr_box_strvalue_buffer(buff), talloc_array_length(buff) - 1);
+ fr_value_box_init(out, FR_TYPE_STRING, NULL, false);
+ fr_value_box_bstrndup_shallow(out, NULL, buff, len, false);
+ fr_value_box_mark_safe_for(out, rc->safe_for);
+ fr_value_box_set_secret(out, rc->secret);
- *out = buff;
+ RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used, out, out->vb_length);
break;
}
* - 0 on success.
* - -1 on notfound.
*/
-int regex_request_to_sub_named(TALLOC_CTX *ctx, char **out, request_t *request, char const *name)
+int regex_request_to_sub_named(TALLOC_CTX *ctx, fr_value_box_t *out, request_t *request, char const *name)
{
fr_regcapture_t *rc;
char *buff;
rc = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rc) {
RDEBUG4("No subcapture data found");
- *out = NULL;
return -1;
}
match_data = rc->regmatch->match_data;
*/
case PCRE2_ERROR_NOSUBSTRING:
RDEBUG4("No named capture group \"%s\"", name);
- *out = NULL;
return -1;
default:
- if (ret < 0) {
- *out = NULL;
- return -1;
- }
+ if (ret < 0) return -1;
MEM(buff = talloc_array(ctx, char, ++len)); /* +1 for \0, it'll get reset by pcre2_substring */
pcre2_substring_copy_byname(match_data, (PCRE2_UCHAR const *)name, (PCRE2_UCHAR *)buff, &len); /* can't error */
- RDEBUG4("Found \"%s\": %pV (%zu)", name,
- fr_box_strvalue_buffer(buff), talloc_array_length(buff) - 1);
+ fr_value_box_init(out, FR_TYPE_STRING, NULL, false);
+ fr_value_box_bstrndup_shallow(out, NULL, buff, len, false);
+ fr_value_box_mark_safe_for(out, rc->safe_for);
+ fr_value_box_set_secret(out, rc->secret);
- *out = buff;
+ RDEBUG4("Found \"%s\": %pV (%zu)", name, out, out->vb_length);
break;
}
* - 0 on success.
* - -1 on notfound.
*/
-int regex_request_to_sub(TALLOC_CTX *ctx, char **out, request_t *request, uint32_t num)
+int regex_request_to_sub(TALLOC_CTX *ctx, fr_value_box_t *out, request_t *request, uint32_t num)
{
fr_regcapture_t *rc;
char const *p;
rc = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rc) {
RDEBUG4("No subcapture data found");
- *out = NULL;
return -1;
}
*/
case PCRE_ERROR_NOSUBSTRING:
RDEBUG4("%i/%zu Not found", num + 1, rc->regmatch->used);
- *out = NULL;
return -1;
default:
- if (ret < 0) {
- *out = NULL;
- return -1;
- }
+ if (ret < 0) return -1;
talloc_set_type(p, char);
- p = talloc_steal(ctx, p);
+ talloc_steal(ctx, p);
- RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used,
- fr_box_strvalue_buffer(p), talloc_array_length(p) - 1);
+ fr_value_box_init(out, FR_TYPE_STRING, NULL, false);
+ fr_value_box_bstrndup_shallow(out, NULL, p, talloc_array_length(p) - 1, false);
+ fr_value_box_mark_safe_for(out, rc->safe_for);
+ fr_value_box_set_secret(out, rc->secret);
- memcpy(out, &p, sizeof(*out));
+ RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used, out, out->vb_length);
break;
}
* - 0 on success.
* - -1 on notfound.
*/
-int regex_request_to_sub_named(TALLOC_CTX *ctx, char **out, request_t *request, char const *name)
+int regex_request_to_sub_named(TALLOC_CTX *ctx, fr_value_box_t *out, request_t *request, char const *name)
{
fr_regcapture_t *rc;
void *rd;
rd = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rd) {
RDEBUG4("No subcapture data found");
- *out = NULL;
return -1;
}
*/
case PCRE_ERROR_NOSUBSTRING:
RDEBUG4("No named capture group \"%s\"", name);
- *out = NULL;
return -1;
default:
- if (ret < 0) {
- *out = NULL;
- return -1;
- }
+ if (ret < 0) return -1;
- /*
- * Check libpcre really is using our overloaded
- * memory allocation and freeing talloc wrappers.
- */
talloc_set_type(p, char);
talloc_steal(ctx, p);
- RDEBUG4("Found \"%s\": %pV (%zu)", name,
- fr_box_strvalue_buffer(p), talloc_array_length(p) - 1);
+ fr_value_box_init(out, FR_TYPE_STRING, NULL, false);
+ fr_value_box_bstrndup_shallow(out, NULL, p, talloc_array_length(p) - 1, false);
+ fr_value_box_mark_safe_for(out, rc->safe_for);
+ fr_value_box_set_secret(out, rc->secret);
- memcpy(out, &p, sizeof(*out));
+ RDEBUG4("Found \"%s\": %pV (%zu)", name, out, out->vb_length);
break;
}
* - 0 on success.
* - -1 on notfound.
*/
-int regex_request_to_sub(TALLOC_CTX *ctx, char **out, request_t *request, uint32_t num)
+int regex_request_to_sub(TALLOC_CTX *ctx, fr_value_box_t *out, request_t *request, uint32_t num)
{
fr_regcapture_t *rc;
char *buff;
rc = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rc) {
RDEBUG4("No subcapture data found");
- *out = NULL;
return -1;
}
match_data = rc->regmatch->match_data;
*/
if ((num >= rc->regmatch->used) || (match_data[num].rm_eo == -1) || (match_data[num].rm_so == -1)) {
RDEBUG4("%i/%zu Not found", num + 1, rc->regmatch->used);
- *out = NULL;
return -1;
}
len = match_data[num].rm_eo - match_data[num].rm_so;
MEM(buff = talloc_bstrndup(ctx, start, len));
- RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used, fr_box_strvalue_buffer(buff), len);
- *out = buff;
+ fr_value_box_init(out, FR_TYPE_STRING, NULL, false);
+ fr_value_box_bstrndup_shallow(out, NULL, buff, len, false);
+ fr_value_box_mark_safe_for(out, rc->safe_for);
+ fr_value_box_set_secret(out, rc->secret);
+
+ RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used, out, out->vb_length);
return 0;
}
*/
if (!arg) {
fr_value_box_t *vb;
- char *p;
MEM(vb = fr_value_box_alloc_null(ctx));
- if (regex_request_to_sub(vb, &p, request, 0) < 0) {
+ if (regex_request_to_sub(vb, vb, request, 0) < 0) {
REDEBUG2("No previous regex capture");
talloc_free(vb);
return XLAT_ACTION_FAIL;
}
- fr_assert(p);
- fr_value_box_bstrdup_buffer_shallow(NULL, vb, NULL, p, false);
fr_dcursor_append(out, vb);
return XLAT_ACTION_DONE;
{
fr_value_box_t idx;
fr_value_box_t *vb;
- char *p;
if (fr_value_box_list_next(in, in_head)) {
REDEBUG("Only one subcapture argument allowed");
}
MEM(vb = fr_value_box_alloc_null(ctx));
- if (regex_request_to_sub(vb, &p, request, idx.vb_uint32) < 0) {
+ if (regex_request_to_sub(vb, vb, request, idx.vb_uint32) < 0) {
REDEBUG2("No previous numbered regex capture group");
talloc_free(vb);
return XLAT_ACTION_FAIL;
}
- fr_assert(p);
- fr_value_box_bstrdup_buffer_shallow(NULL, vb, NULL, p, false);
fr_dcursor_append(out, vb);
return XLAT_ACTION_DONE;
default:
{
fr_value_box_t *vb;
- char *p;
/*
* Concatenate all input
}
MEM(vb = fr_value_box_alloc_null(ctx));
- if (regex_request_to_sub_named(vb, &p, request, arg->vb_strvalue) < 0) {
+ if (regex_request_to_sub_named(vb, vb, request, arg->vb_strvalue) < 0) {
REDEBUG2("No previous named regex capture group");
talloc_free(vb);
return XLAT_ACTION_FAIL;
}
-
- fr_assert(p);
- fr_value_box_bstrdup_buffer_shallow(NULL, vb, NULL, p, false);
fr_dcursor_append(out, vb);
return XLAT_ACTION_DONE;