]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add %{string:...} for printable data
authorAlan T. DeKok <aland@freeradius.org>
Thu, 27 Jan 2011 14:33:32 +0000 (15:33 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 27 Jan 2011 14:33:32 +0000 (15:33 +0100)
src/main/xlat.c

index 0a0206484f39b3e64c4b2d339a2b35fa317b5fde..6ac45b02dc7c4f32cf6a0b0aea48c22d6a1b9aa9 100644 (file)
@@ -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.