xlat lower/upper
Alexander Clouter
alex at digriz.org.uk
Mon Sep 20 18:57:47 CEST 2010
Hi,
Another patch that Alan will no doubt neglect, others might find it
useful though.
This patch adds lower/uppercase xlat support so you can now do things
like:
----
update request {
Calling-Station-Id := "%{lower:%{Calling-Station-Id}}"
}
update request {
Calling-Station-Id := "%{upper:%{Calling-Station-Id}}"
}
----
Cheers
--
Alexander Clouter
.sigmonster says: Girls are better looking in snowstorms.
-- Archie Goodwin
--- src/main/xlat.c.orig 2010-09-20 16:10:54.000000000 +0000
+++ src/main/xlat.c 2010-09-20 16:23:41.000000000 +0000
@@ -465,6 +465,61 @@
return strlen(out);
}
+/*
+ * Lowercase a string
+ */
+static size_t xlat_lower(UNUSED void *instance, REQUEST *request,
+ char *fmt, char *out, size_t outlen,
+ UNUSED RADIUS_ESCAPE_STRING func)
+{
+ int i;
+ char buffer[1024];
+
+ if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+ *out = '\0';
+ return 0;
+ }
+
+ if (outlen < strlen(buffer)) {
+ snprintf(out, outlen, "lower_overflow");
+ return strlen(out);
+ }
+
+ for (i = 0; buffer[i] != '\0'; i++)
+ out[i] = tolower(buffer[i]);
+
+ out[i] = '\0';
+
+ return strlen(out);
+}
+
+/*
+ * Uppercase a string
+ */
+static size_t xlat_upper(UNUSED void *instance, REQUEST *request,
+ char *fmt, char *out, size_t outlen,
+ UNUSED RADIUS_ESCAPE_STRING func)
+{
+ int i;
+ char buffer[1024];
+
+ if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+ *out = '\0';
+ return 0;
+ }
+
+ if (outlen < strlen(buffer)) {
+ snprintf(out, outlen, "upper_overflow");
+ return strlen(out);
+ }
+
+ for (i = 0; buffer[i] != '\0'; i++)
+ out[i] = toupper(buffer[i]);
+
+ out[i] = '\0';
+
+ return strlen(out);
+}
/*
* Calculate the MD5 hash of a string.
@@ -610,6 +665,16 @@
c = xlat_find("md5");
rad_assert(c != NULL);
c->internal = TRUE;
+
+ xlat_register("lower", xlat_lower, &xlat_inst[0]);
+ c = xlat_find("lower");
+ rad_assert(c != NULL);
+ c->internal = TRUE;
+
+ xlat_register("upper", xlat_upper, &xlat_inst[0]);
+ c = xlat_find("upper");
+ rad_assert(c != NULL);
+ c->internal = TRUE;
}
/*
More information about the Freeradius-Devel
mailing list