debian release
[hcoop/debian/courier-authlib.git] / authsasltobase64.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include "rfc822/encode.h"
4
5 static int write_challenge(const char *p, size_t l, void *vp)
6 {
7 char **cp=(char **)vp;
8
9 while (l)
10 {
11 if (*p == '\r' || *p == '\n')
12 {
13 ++p;
14 --l;
15 continue;
16 }
17 **cp = *p++;
18 ++*cp;
19
20 --l;
21 }
22
23 return 0;
24 }
25
26 char *authsasl_tobase64(const char *p, int l)
27 {
28 char *write_challenge_buf;
29 char *write_challenge_ptr;
30
31 struct libmail_encode_info encodeInfo;
32
33 if (l < 0) l=strlen(p);
34
35 write_challenge_buf=malloc((l+3)/3*4+1);
36 if (!write_challenge_buf)
37 return (0);
38
39 write_challenge_ptr=write_challenge_buf;
40
41 libmail_encode_start(&encodeInfo, "base64", &write_challenge,
42 &write_challenge_ptr);
43
44 libmail_encode(&encodeInfo, p, l);
45 libmail_encode_end(&encodeInfo);
46 *write_challenge_ptr=0;
47 return (write_challenge_buf);
48 }