Skip to content

Commit 8cabbf0

Browse files
committed
move escape sbuff sequences to utility library
so that others can use them
1 parent c6f969e commit 8cabbf0

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

src/lib/unlang/xlat_builtin.c

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -316,37 +316,6 @@ static xlat_action_t xlat_func_pairs_debug(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcu
316316
#pragma clang diagnostic ignored "-Wgnu-designator"
317317
#endif
318318

319-
static const fr_sbuff_escape_rules_t xlat_filename_escape = {
320-
.name = "filename",
321-
.chr = '_',
322-
.do_utf8 = true,
323-
.do_hex = true,
324-
325-
.esc = {
326-
[ 0x00 ... 0x2d ] = true, // special characters, but not '.'
327-
[ 0x2f ] = true, // /
328-
[ 0x3A ... 0x3f ] = true, // :;<=>?, but not "@"
329-
[ 0x5b ... 0x5e ] = true, // [\]^
330-
[ 0x60 ] = true, // back-tick
331-
[ 0x7b ... 0xff ] = true, // {|}, and all chars which have high bit set, but aren't UTF-8
332-
},
333-
};
334-
335-
static const fr_sbuff_escape_rules_t xlat_filename_escape_dots = {
336-
.name = "filename",
337-
.chr = '_',
338-
.do_utf8 = true,
339-
.do_hex = true,
340-
341-
.esc = {
342-
[ 0x00 ... 0x2f ] = true, // special characters, '.', '/', etc.
343-
[ 0x3A ... 0x3f ] = true, // :;<=>?, but not "@"
344-
[ 0x5b ... 0x5e ] = true, // [\]^
345-
[ 0x60 ] = true, // back-tick
346-
[ 0x7b ... 0xff ] = true, // {|}, and all chars which have high bit set, but aren't UTF-8
347-
},
348-
};
349-
350319
#define FR_FILENAME_SAFE_FOR ((uintptr_t) filename_xlat_escape)
351320

352321
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,
400369
*/
401370
if (fr_value_box_cast_in_place(vb, vb, FR_TYPE_STRING, NULL) < 0) return -1;
402371

403-
fr_value_box_print(out, vb, &xlat_filename_escape);
372+
fr_value_box_print(out, vb, &fr_filename_escape);
404373
break;
405374

406375
case FR_TYPE_STRING:
@@ -424,9 +393,9 @@ static int CC_HINT(nonnull(2,3)) filename_xlat_escape(UNUSED request_t *request,
424393
* "log/aland@freeradius.org".
425394
*/
426395
if (vb->vb_strvalue[0] == '.') {
427-
fr_value_box_print(out, vb, &xlat_filename_escape_dots);
396+
fr_value_box_print(out, vb, &fr_filename_escape_dots);
428397
} else {
429-
fr_value_box_print(out, vb, &xlat_filename_escape);
398+
fr_value_box_print(out, vb, &fr_filename_escape);
430399
}
431400

432401
break;

src/lib/util/file.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,35 @@ int fr_globdir_iter_free(fr_globdir_iter_t *iter)
913913

914914
return 0;
915915
}
916+
917+
const fr_sbuff_escape_rules_t fr_filename_escape = {
918+
.name = "filename",
919+
.chr = '_',
920+
.do_utf8 = true,
921+
.do_hex = true,
922+
923+
.esc = {
924+
[ 0x00 ... 0x2d ] = true, // special characters, but not '.'
925+
[ 0x2f ] = true, // /
926+
[ 0x3A ... 0x3f ] = true, // :;<=>?, but not "@"
927+
[ 0x5b ... 0x5e ] = true, // [\]^
928+
[ 0x60 ] = true, // back-tick
929+
[ 0x7b ... 0xff ] = true, // {|}, and all chars which have high bit set, but aren't UTF-8
930+
},
931+
};
932+
933+
const fr_sbuff_escape_rules_t fr_filename_escape_dots = {
934+
.name = "filename",
935+
.chr = '_',
936+
.do_utf8 = true,
937+
.do_hex = true,
938+
939+
.esc = {
940+
[ 0x00 ... 0x2f ] = true, // special characters, '.', '/', etc.
941+
[ 0x3A ... 0x3f ] = true, // :;<=>?, but not "@"
942+
[ 0x5b ... 0x5e ] = true, // [\]^
943+
[ 0x60 ] = true, // back-tick
944+
[ 0x7b ... 0xff ] = true, // {|}, and all chars which have high bit set, but aren't UTF-8
945+
},
946+
};
947+

src/lib/util/file.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ int fr_globdir_iter_init(char const **filename, char const *dir, char const *pa
104104
int fr_globdir_iter_next(char const **filename, fr_globdir_iter_t *iter);
105105
int fr_globdir_iter_free(fr_globdir_iter_t *iter);
106106

107+
extern const fr_sbuff_escape_rules_t fr_filename_escape;
108+
extern const fr_sbuff_escape_rules_t fr_filename_escape_dots;
109+
107110
#ifdef __cplusplus
108111
}
109112
#endif

0 commit comments

Comments
 (0)