Chameleon

Chameleon Commit Details

Date:2013-01-31 07:23:49 (7 years 3 months ago)
Author:Evan Lojewski
Commit:2176
Parents: 2175
Message:Fix base64 decode, fixes Issue #320
Changes:
M/trunk/i386/libsaio/base64-decode.c
M/trunk/i386/libsaio/xml.c

File differences

trunk/i386/libsaio/xml.c
806806
807807
808808
809
810
811
809
812810
813811
814812
//printf("ParseTagData unimplimented\n");
//printf("Data: %s\n", buffer);
//getchar();
// TODO: base64 decode
char* string = BASE64Decode(buffer, strlen(buffer), &actuallen);
tmpTag->type = kTagTypeData;
tmpTag->string = string;
trunk/i386/libsaio/base64-decode.c
88
99
1010
11
12
11
12
1313
1414
1515
......
2828
2929
3030
31
3132
3233
3334
......
3536
3637
3738
38
39
40
3941
4042
4143
......
4648
4749
4850
51
52
53
4954
55
5056
5157
58
59
60
5261
62
5363
5464
5565
56
66
5767
5868
5969
*/
#include <libsaio.h>
static const char base64_chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//static const char base64_chars[] =
//"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char base64_digits[] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
char *BASE64Decode(const char* src, int in_len, int* out_len)
{
int endpad = 0;
char* dest;
char* result;
{
/* Wrong base64 string length */
return NULL;
}
}
result = dest = malloc(in_len / 4 * 3 + 1);
if (result == NULL)
return NULL; /* out of memory */
char d = base64_digits[(unsigned char)*(src++)];
*(dest++) = (a << 2) | ((b & 0x30) >> 4);
if (c == (char)-1)
{
// padding char.
endpad += 2;
break;
}
*(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
if (d == (char)-1)
{
// padding char.
endpad += 1;
break;
}
*(dest++) = ((c & 0x03) << 6) | d;
}
*dest = 0;
*out_len = in_len / 4 * 3; // not including NULL terminator
*out_len = in_len / 4 * 3 - endpad; // not including NULL terminator
return result;
}

Archive Download the corresponding diff file

Revision: 2176