File: authsasltobase64.c

package info (click to toggle)
courier-authlib 0.72.6-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 17,844 kB
  • sloc: ansic: 25,772; cpp: 12,475; sh: 5,588; makefile: 938; perl: 761
file content (49 lines) | stat: -rw-r--r-- 831 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include	<stdlib.h>
#include	<string.h>
#include	"auth.h"
#include	"rfc2045/encode.h"

static int write_challenge(const char *p, size_t l, void *vp)
{
	char **cp=(char **)vp;

	while (l)
	{
		if (*p == '\r' || *p == '\n')
		{
			++p;
			--l;
			continue;
		}
		**cp = *p++;
		++*cp;

		--l;
	}

	return 0;
}

char *authsasl_tobase64(const char *p, int l)
{
	char *write_challenge_buf;
	char *write_challenge_ptr;

	struct libmail_encode_info encodeInfo;

	if (l < 0)	l=strlen(p);

	write_challenge_buf=malloc((l+3)/3*4+1);
	if (!write_challenge_buf)
		return (0);

	write_challenge_ptr=write_challenge_buf;

	libmail_encode_start(&encodeInfo, "base64", &write_challenge,
			     &write_challenge_ptr);

	libmail_encode(&encodeInfo, p, l);
	libmail_encode_end(&encodeInfo);
	*write_challenge_ptr=0;
	return (write_challenge_buf);
}