From: Alan T. DeKok Date: Mon, 20 Sep 2010 14:49:13 +0000 (+0200) Subject: Added tolower function X-Git-Tag: release_3_0_0_beta0~1234 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=freeradius.git;a=commitdiff_plain;h=df2f776b9dcbf90e264634fa5aa7f65695cc4686 Added tolower function --- diff --git a/src/main/xlat.c b/src/main/xlat.c index 6bbf474..9c32288 100644 --- a/src/main/xlat.c +++ b/src/main/xlat.c @@ -499,6 +499,35 @@ static size_t xlat_md5(UNUSED void *instance, REQUEST *request, return strlen(out); } + +/* + * Convert a string to lowercase + */ +static size_t xlat_lc(UNUSED void *instance, REQUEST *request, + char *fmt, char *out, size_t outlen, + UNUSED RADIUS_ESCAPE_STRING func) +{ + char *p, *q; + char buffer[1024]; + + if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) { + *out = '\0'; + return 0; + } + + for (p = buffer, q = out; *p != '\0'; p++, outlen--) { + if (outlen <= 1) break; + + *(q++) = tolower((int) *p); + } + + *q = '\0'; + + return strlen(out); +} + + + /* * Compare two xlat_t structs, based ONLY on the module name. */ @@ -513,7 +542,6 @@ static int xlat_cmp(const void *a, const void *b) ((const xlat_t *)a)->length); } - /* * find the appropriate registered xlat function. */ @@ -610,6 +638,11 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance) c = xlat_find("md5"); rad_assert(c != NULL); c->internal = TRUE; + + xlat_register("tolower", xlat_lc, &xlat_inst[0]); + c = xlat_find("tolower"); + rad_assert(c != NULL); + c->internal = TRUE; } /*