53 |
53 |
54 #include "../daemon/netsite.h" |
54 #include "../daemon/netsite.h" |
55 #include "../public/nsapi.h" |
55 #include "../public/nsapi.h" |
56 |
56 |
57 #include "util.h" |
57 #include "util.h" |
|
58 |
|
59 |
|
60 |
|
61 /* ------------------------------ _uudecode ------------------------------- */ |
|
62 |
|
63 static const unsigned char pr2six[256] = { |
|
64 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
|
65 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63, |
|
66 52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9, |
|
67 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27, |
|
68 28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, |
|
69 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
|
70 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
|
71 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
|
72 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
|
73 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
|
74 64,64,64,64,64,64,64,64,64,64,64,64,64 |
|
75 }; |
|
76 |
|
77 /** you MUST reserve at least 2 additional bytes for bufout */ |
|
78 size_t util_base64decode(char *bufcoded, size_t codedbytes, char *bufout) { |
|
79 register char *bufin = bufcoded; |
|
80 register int nprbytes; |
|
81 size_t nbytesdecoded; |
|
82 |
|
83 /* Find the length */ |
|
84 nprbytes = (int) codedbytes; |
|
85 while(pr2six[(int)(bufin[nprbytes-1])] >= 64) { |
|
86 nprbytes--; |
|
87 } |
|
88 nbytesdecoded = ((nprbytes+3)/4) * 3; |
|
89 |
|
90 while (nprbytes > 0) { |
|
91 *(bufout++) = (unsigned char) |
|
92 (pr2six[(int)(*bufin)] << 2 | pr2six[(int)bufin[1]] >> 4); |
|
93 *(bufout++) = (unsigned char) |
|
94 (pr2six[(int)bufin[1]] << 4 | pr2six[(int)bufin[2]] >> 2); |
|
95 *(bufout++) = (unsigned char) |
|
96 (pr2six[(int)bufin[2]] << 6 | pr2six[(int)bufin[3]]); |
|
97 bufin += 4; |
|
98 nprbytes -= 4; |
|
99 } |
|
100 |
|
101 if(nprbytes & 03) { |
|
102 if(pr2six[(int)bufin[-2]] > 63) |
|
103 nbytesdecoded -= 2; |
|
104 else |
|
105 nbytesdecoded -= 1; |
|
106 } |
|
107 |
|
108 return nbytesdecoded; |
|
109 } |
58 |
110 |
59 /* |
111 /* |
60 NSAPI_PUBLIC int util_getboolean(const char *v, int def) { |
112 NSAPI_PUBLIC int util_getboolean(const char *v, int def) { |
61 if(v[0] == 'T' || v[0] == 't') { |
113 if(v[0] == 'T' || v[0] == 't') { |
62 return 1; |
114 return 1; |