ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
decode_b64.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "uint_t.h"
3#include "errtxt.h"
4#include "idx.h"
5#include "logmsg.h"
6
7#define WHO "decode_b64"
8
16
17 /* Characters and translation as per rfc2047. */
18static const char char64table[128] = {
19 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
20 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
21 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
22 52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1,
23 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
24 15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
25 -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
26 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
27};
28
29#define char64enc(c) (((c) & 0x80) ? -1 : char64table[(c)])
30
31static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
32
33void decode_b64(const char *cpfrom,unsigned int n,stralloc *outdata)
34{
35 uint32 hold32;
36 char holdch[4] = "???";
37 int i,j;
38 char c; /* needs to be signed */
39 const unsigned char *cp;
40 const unsigned char *cpnext;
41
42 cp = cpfrom;
43 cpnext = cp + n;
44 i = 0;
45 hold32 = 0L;
46 if (!stralloc_readyplus(outdata,n)) die_nomem();
47 for (;;) {
48 if (i == 4) {
49 for (j = 2; j >= 0; --j) {
50 holdch[j] = hold32 & 0xff;
51 hold32 = hold32 >> 8;
52 }
53 if (!stralloc_cats(outdata,holdch)) die_nomem();
54 if (cp >= cpnext) break;
55 hold32 = 0L;
56 i = 0;
57 }
58 if (cp >= cpnext) { /* pad */
59 c = 0;
60 } else {
61 c = char64enc(*cp);
62 ++cp;
63 }
64 if (c < 0) continue;/* ignore illegal characters */
65 else {
66 hold32 = (hold32 << 6) | (c & 0x7f);
67 ++i;
68 }
69 }
70}
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
void decode_b64(const char *cpfrom, unsigned int n, stralloc *outdata)
Definition decode_b64.c:33
#define char64enc(c)
Definition decode_b64.c:29
#define outdata
Definition makehash.c:46
const char * cp
Definition ezmlm-cron.c:76
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32