From: Alan T. DeKok Date: Tue, 21 Dec 2010 09:01:16 +0000 (+0100) Subject: Added %{integer:...} X-Git-Tag: release_2_1_11~180 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b74612c710d3d7e9fdfa4ebf8763877d25a0d3a9;p=thirdparty%2Ffreeradius-server.git Added %{integer:...} Which takes an argument like %{integer:Event-Timestamp}, and prints it as an integer, bypassing all of the named enumeration and date/time expansion --- diff --git a/src/main/xlat.c b/src/main/xlat.c index 023b2dc3ff8..1331df30f65 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -409,6 +409,34 @@ static size_t xlat_packet(void *instance, REQUEST *request, return valuepair2str(out, outlen, vp, da->type, func); } +/* + * Dynamically translate for check:, request:, reply:, etc. + */ +static size_t xlat_integer(void *instance, REQUEST *request, + char *fmt, char *out, size_t outlen, + RADIUS_ESCAPE_STRING func) +{ + VALUE_PAIR *vp; + + while (isspace((int) *fmt) *fmt++; + + if (!radius_get_vp(request, fmt, &vp)) { + *out = '\0'; + return 0; + } + + if ((vp->type != PW_TYPE_IPADDR) && + (vp->type != PW_TYPE_INTEGER) && + (vp->type != PW_TYPE_SHORT) && + (vp->type != PW_TYPE_BYTE) && + (vp->type != PW_TYPE_DATE)) { + *out = '\0'; + return 0; + } + + return snprintf(out, outlen, "%u", vp->vp_integer); +} + #ifdef HAVE_REGEX_H /* * Pull %{0} to %{8} out of the packet. @@ -644,6 +672,11 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance) rad_assert(c != NULL); c->internal = TRUE; + xlat_register("integer", xlat_integer, ""); + c = xlat_find("integer"); + rad_assert(c != NULL); + c->internal = TRUE; + #ifdef HAVE_REGEX_H /* * Register xlat's for regexes.