]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move escape sbuff sequences to utility library
authorAlan T. DeKok <aland@freeradius.org>
Wed, 4 Mar 2026 12:33:55 +0000 (07:33 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 4 Mar 2026 12:46:37 +0000 (07:46 -0500)
so that others can use them

src/lib/unlang/xlat_builtin.c
src/lib/util/file.c
src/lib/util/file.h

index 76dd746c0634cfebc3b3f33147fc2f8a961134bf..bd8c05f8ebc69dac51256cce8b78861a89b0e5d1 100644 (file)
@@ -316,37 +316,6 @@ static xlat_action_t xlat_func_pairs_debug(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcu
 #pragma clang diagnostic ignored "-Wgnu-designator"
 #endif
 
-static const fr_sbuff_escape_rules_t xlat_filename_escape = {
-       .name = "filename",
-       .chr = '_',
-       .do_utf8 = true,
-       .do_hex = true,
-
-       .esc = {
-               [ 0x00 ... 0x2d ] = true,               // special characters, but not '.'
-               [ 0x2f ] = true,                        // /
-               [ 0x3A ... 0x3f ] = true,               // :;<=>?, but not "@"
-               [ 0x5b ... 0x5e ] = true,               // [\]^
-               [ 0x60 ] = true,                        // back-tick
-               [ 0x7b ... 0xff ] = true,               // {|}, and all chars which have high bit set, but aren't UTF-8
-       },
-};
-
-static const fr_sbuff_escape_rules_t xlat_filename_escape_dots = {
-       .name = "filename",
-       .chr = '_',
-       .do_utf8 = true,
-       .do_hex = true,
-
-       .esc = {
-               [ 0x00 ... 0x2f ] = true,               // special characters, '.', '/', etc.
-               [ 0x3A ... 0x3f ] = true,               // :;<=>?, but not "@"
-               [ 0x5b ... 0x5e ] = true,               // [\]^
-               [ 0x60 ] = true,                        // back-tick
-               [ 0x7b ... 0xff ] = true,               // {|}, and all chars which have high bit set, but aren't UTF-8
-       },
-};
-
 #define FR_FILENAME_SAFE_FOR ((uintptr_t) filename_xlat_escape)
 
 static int CC_HINT(nonnull(2,3)) filename_xlat_escape(UNUSED request_t *request, fr_value_box_t *vb, UNUSED void *uctx)
@@ -400,7 +369,7 @@ static int CC_HINT(nonnull(2,3)) filename_xlat_escape(UNUSED request_t *request,
                 */
                if (fr_value_box_cast_in_place(vb, vb, FR_TYPE_STRING, NULL) < 0) return -1;
 
-               fr_value_box_print(out, vb, &xlat_filename_escape);
+               fr_value_box_print(out, vb, &fr_filename_escape);
                break;
 
        case FR_TYPE_STRING:
@@ -424,9 +393,9 @@ static int CC_HINT(nonnull(2,3)) filename_xlat_escape(UNUSED request_t *request,
                 *      "log/aland@freeradius.org".
                 */
                if (vb->vb_strvalue[0] == '.') {
-                       fr_value_box_print(out, vb, &xlat_filename_escape_dots);
+                       fr_value_box_print(out, vb, &fr_filename_escape_dots);
                } else {
-                       fr_value_box_print(out, vb, &xlat_filename_escape);
+                       fr_value_box_print(out, vb, &fr_filename_escape);
                }
 
                break;
index ddb53f1a0774de98feb663b78e25a143d1b4e8f9..033bc3b9438a75f6a85b14459fb36bef3ed44442 100644 (file)
@@ -913,3 +913,35 @@ int fr_globdir_iter_free(fr_globdir_iter_t *iter)
 
        return 0;
 }
+
+const fr_sbuff_escape_rules_t fr_filename_escape = {
+       .name = "filename",
+       .chr = '_',
+       .do_utf8 = true,
+       .do_hex = true,
+
+       .esc = {
+               [ 0x00 ... 0x2d ] = true,               // special characters, but not '.'
+               [ 0x2f ] = true,                        // /
+               [ 0x3A ... 0x3f ] = true,               // :;<=>?, but not "@"
+               [ 0x5b ... 0x5e ] = true,               // [\]^
+               [ 0x60 ] = true,                        // back-tick
+               [ 0x7b ... 0xff ] = true,               // {|}, and all chars which have high bit set, but aren't UTF-8
+       },
+};
+
+const fr_sbuff_escape_rules_t fr_filename_escape_dots = {
+       .name = "filename",
+       .chr = '_',
+       .do_utf8 = true,
+       .do_hex = true,
+
+       .esc = {
+               [ 0x00 ... 0x2f ] = true,               // special characters, '.', '/', etc.
+               [ 0x3A ... 0x3f ] = true,               // :;<=>?, but not "@"
+               [ 0x5b ... 0x5e ] = true,               // [\]^
+               [ 0x60 ] = true,                        // back-tick
+               [ 0x7b ... 0xff ] = true,               // {|}, and all chars which have high bit set, but aren't UTF-8
+       },
+};
+
index be731cab1fd4d0685b77bbadde5116bab48d117d..80f8bfbbb5c589161d2ec5e9d5cdffcc50a228f0 100644 (file)
@@ -104,6 +104,9 @@ int         fr_globdir_iter_init(char const **filename, char const *dir, char const *pa
 int            fr_globdir_iter_next(char const **filename, fr_globdir_iter_t *iter);
 int            fr_globdir_iter_free(fr_globdir_iter_t *iter);
 
+extern const fr_sbuff_escape_rules_t fr_filename_escape;
+extern const fr_sbuff_escape_rules_t fr_filename_escape_dots;
+
 #ifdef __cplusplus
 }
 #endif