More bug-fixes, GSASL DIGEST-MD5 now works.
[exim.git] / src / src / auths / xtextencode.c
CommitLineData
0756eb3c
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
0a49a7a4 5/* Copyright (c) University of Cambridge 1995 - 2009 */
0756eb3c
PH
6/* See the file NOTICE for conditions of use and distribution. */
7
8#include "../exim.h"
9
10
11/*************************************************
12* Encode byte-string in xtext *
13*************************************************/
14
15/* This function encodes a string of bytes, containing any values whatsoever,
16as "xtext", as defined in RFC 1891 and required by the SMTP AUTH extension (RFC
172554).
18
19Arguments:
20 clear points to the clear text bytes
21 len the number of bytes to encode
22
23Returns: a pointer to the zero-terminated xtext string, which
24 is in working store
25*/
26
27uschar *
28auth_xtextencode(uschar *clear, int len)
29{
30uschar *code;
31uschar *p = (uschar *)clear;
32uschar *pp;
33int c = len;
34int count = 1;
35register int x;
36
37/* We have to do a prepass to find out how many specials there are,
38in order to get the right amount of store. */
39
40while (c -- > 0)
41 count += ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')? 3 : 1;
42
43pp = code = store_get(count);
44
45p = (uschar *)clear;
46c = len;
47while (c-- > 0)
48 {
49 if ((x = *p++) < 33 || x > 127 || x == '+' || x == '=')
50 {
51 sprintf(CS pp, "+%.02x", x); /* There's always room */
52 pp += 3;
53 }
54 else *pp++ = x;
55 }
56
57*pp = 0;
58return code;
59}
60
61/* End of xtextencode.c */