Chameleon

Chameleon Commit Details

Date:2013-01-12 21:13:20 (6 years 10 months ago)
Author:Evan Lojewski
Commit:2161
Parents: 2160
Message:Add Base64 decoder. Call from XMLCastData
Changes:
A/trunk/i386/libsaio/base64-decode.c
M/trunk/i386/libsaio/Makefile
M/trunk/i386/libsaio/saio_internal.h
M/trunk/i386/libsaio/xml.c

File differences

trunk/i386/libsaio/xml.c
793793
794794
795795
796
796797
797798
798799
......
808809
809810
810811
811
812
812813
813814
814815
815
816
816817
817818
818819
static long
ParseTagData( char * buffer, TagPtr * tag )
{
int actuallen = 0;
long length;
TagPtr tmpTag;
// TODO: base64 decode
char* string = NewSymbol(buffer);
char* string = BASE64Decode(NewSymbol(buffer), length, &actuallen);
tmpTag->type = kTagTypeData;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->offset = length; // buffer_start ? buffer - buffer_start: 0;
tmpTag->offset = actuallen; // buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
trunk/i386/libsaio/Makefile
3838
3939
4040
41
41
4242
4343
4444
fake_efi.o ext2fs.o \
hpet.o dram_controllers.o spd.o usb.o pci_setup.o \
device_inject.o nvidia_helper.o nvidia.o ati.o gma.o pci_root.o \
convert.o aml_generator.o console.o exfat.o
convert.o aml_generator.o console.o exfat.o base64-decode.o
SAIO_OBJS := $(addprefix $(OBJROOT)/, $(SAIO_OBJS))
trunk/i386/libsaio/base64-decode.c
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
50
51
52
53
54
55
56
57
58
59
60
61
/*
* This code implements the BASE64 algorithm.
* This code is in the public domain; do with it what you wish.
*
* @file base64.c
* @brief This code implements the BASE64 algorithm
* @author Matthieu Speder
*/
#include <libsaio.h>
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,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 0, 0, -1, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 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)
{
char* dest;
char* result;
if (in_len % 4)
{
/* Wrong base64 string length */
return NULL;
}
result = dest = malloc(in_len / 4 * 3 + 1);
if (result == NULL)
return NULL; /* out of memory */
while (*src) {
char a = base64_digits[(unsigned char)*(src++)];
char b = base64_digits[(unsigned char)*(src++)];
char c = base64_digits[(unsigned char)*(src++)];
char d = base64_digits[(unsigned char)*(src++)];
*(dest++) = (a << 2) | ((b & 0x30) >> 4);
if (c == (char)-1)
break;
*(dest++) = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
if (d == (char)-1)
break;
*(dest++) = ((c & 0x03) << 6) | d;
}
*dest = 0;
*out_len = in_len / 4 * 3; // not including NULL terminator
return result;
}
/* end of base64.c */
trunk/i386/libsaio/saio_internal.h
218218
219219
220220
221
222
223
221224
unsigned int byteoff,
unsigned int byteCount, void * buffer );
// Base64-decode.c
char *BASE64Decode(const char* src, int in_len, int* out_len);
#endif /* !__LIBSAIO_SAIO_INTERNAL_H */

Archive Download the corresponding diff file

Revision: 2161