X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/c86f62585c172e92377d4a5d58b754ed72094cc3..0756eb3cb50d73a77b486e47528f7cb1bffdb299:/src/src/auths/xtextencode.c diff --git a/src/src/auths/xtextencode.c b/src/src/auths/xtextencode.c new file mode 100644 index 000000000..424453dc0 --- /dev/null +++ b/src/src/auths/xtextencode.c @@ -0,0 +1,63 @@ +/* $Cambridge: exim/src/src/auths/xtextencode.c,v 1.1 2004/10/07 13:10:01 ph10 Exp $ */ + +/************************************************* +* Exim - an Internet mail transport agent * +*************************************************/ + +/* Copyright (c) University of Cambridge 1995 - 2004 */ +/* See the file NOTICE for conditions of use and distribution. */ + +#include "../exim.h" + + +/************************************************* +* Encode byte-string in xtext * +*************************************************/ + +/* This function encodes a string of bytes, containing any values whatsoever, +as "xtext", as defined in RFC 1891 and required by the SMTP AUTH extension (RFC +2554). + +Arguments: + clear points to the clear text bytes + len the number of bytes to encode + +Returns: a pointer to the zero-terminated xtext string, which + is in working store +*/ + +uschar * +auth_xtextencode(uschar *clear, int len) +{ +uschar *code; +uschar *p = (uschar *)clear; +uschar *pp; +int c = len; +int count = 1; +register int x; + +/* We have to do a prepass to find out how many specials there are, +in order to get the right amount of store. */ + +while (c -- > 0) + count += ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')? 3 : 1; + +pp = code = store_get(count); + +p = (uschar *)clear; +c = len; +while (c-- > 0) + { + if ((x = *p++) < 33 || x > 127 || x == '+' || x == '=') + { + sprintf(CS pp, "+%.02x", x); /* There's always room */ + pp += 3; + } + else *pp++ = x; + } + +*pp = 0; +return code; +} + +/* End of xtextencode.c */