From: Alan T. DeKok Date: Thu, 27 Jan 2011 14:33:32 +0000 (+0100) Subject: Add %{string:...} for printable data X-Git-Tag: release_2_1_11~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24b1b914aeff16dd8f3cf60a3422c19b6efcc949;p=thirdparty%2Ffreeradius-server.git Add %{string:...} for printable data --- diff --git a/src/main/xlat.c b/src/main/xlat.c index 0a0206484f3..6ac45b02dc7 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -410,7 +410,7 @@ static size_t xlat_packet(void *instance, REQUEST *request, } /* - * Dynamically translate for check:, request:, reply:, etc. + * Print data as integer, not as VALUE. */ static size_t xlat_integer(void *instance, REQUEST *request, char *fmt, char *out, size_t outlen, @@ -437,6 +437,36 @@ static size_t xlat_integer(void *instance, REQUEST *request, return snprintf(out, outlen, "%u", vp->vp_integer); } +/* + * Print data as string, if possible. + */ +static size_t xlat_string(void *instance, REQUEST *request, + char *fmt, char *out, size_t outlen, + RADIUS_ESCAPE_STRING func) +{ + int len; + VALUE_PAIR *vp; + + while (isspace((int) *fmt)) fmt++; + + if (outlen < 3) { + nothing: + *out = '\0'; + return 0; + } + + if (!radius_get_vp(request, fmt, &vp)) goto nothing; + + if (vp->type != PW_TYPE_OCTETS) goto nothing; + + *out++ = '"'; + len = fr_print_string(vp->vp_octets, vp->length, out + 1, outlen - 3); + out[len] = '"'; + out[len + 1] = '\0'; + + return len + 2; +} + #ifdef HAVE_REGEX_H /* * Pull %{0} to %{8} out of the packet. @@ -677,6 +707,11 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance) rad_assert(c != NULL); c->internal = TRUE; + xlat_register("string", xlat_string, ""); + c = xlat_find("string"); + rad_assert(c != NULL); + c->internal = TRUE; + #ifdef HAVE_REGEX_H /* * Register xlat's for regexes.