comparison src/util.c @ 8929:54eba3833e34

[gaim-migrate @ 9699] Ambrose Li fixed up our quoted-printable decoding committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Fri, 14 May 2004 05:51:38 +0000
parents c34e4e6128f3
children 60a47725df97
comparison
equal deleted inserted replaced
8928:755d7f8907c6 8929:54eba3833e34
134 * Base64 Functions 134 * Base64 Functions
135 **************************************************************************/ 135 **************************************************************************/
136 static const char alphabet[] = 136 static const char alphabet[] =
137 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 137 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
138 "0123456789+/"; 138 "0123456789+/";
139
140 static const char xdigits[] =
141 "0123456789abcdef";
139 142
140 unsigned char * 143 unsigned char *
141 gaim_base64_encode(const unsigned char *in, size_t inlen) 144 gaim_base64_encode(const unsigned char *in, size_t inlen)
142 { 145 {
143 char *out, *rv; 146 char *out, *rv;
242 if (size) 245 if (size)
243 *size = len; 246 *size = len;
244 } 247 }
245 248
246 /************************************************************************** 249 /**************************************************************************
247 * Quoted Printable Functions 250 * Quoted Printable Functions (see RFC 1341)
248 **************************************************************************/ 251 **************************************************************************/
249 void 252 void
250 gaim_quotedp_decode(const char *str, char **ret_str, int *ret_len) 253 gaim_quotedp_decode(const char *str, char **ret_str, int *ret_len)
251 { 254 {
252 char *n, *new; 255 char *n, *new;
253 const char *end, *p; 256 const char *end, *p;
254 int i;
255 257
256 n = new = g_malloc(strlen (str) + 1); 258 n = new = g_malloc(strlen (str) + 1);
257 end = str + strlen(str); 259 end = str + strlen(str);
258 260
259 for (p = str; p < end; p++, n++) { 261 for (p = str; p < end; p++, n++) {
260 if (*p == '=') { 262 if (*p == '=') {
261 sscanf(p + 1, "%2x\n", &i); 263 if (p[1] == '\r' && p[2] == '\n') { /* 5.1 #5 */
262 *n = i; 264 n -= 1;
263 p += 2; 265 p += 2;
266 } else if (p[1] == '\n') { /* fuzzy case for 5.1 #5 */
267 n -= 1;
268 p += 1;
269 } else if (p[1] && p[2]) {
270 char *nibble1 = strchr(xdigits, tolower(p[1]));
271 char *nibble2 = strchr(xdigits, tolower(p[2]));
272 if (nibble1 && nibble2) { /* 5.1 #1 */
273 *n = ((nibble1 - xdigits) << 4) | (nibble2 - xdigits);
274 p += 2;
275 } else { /* This should never happen */
276 *n = *p;
277 }
278 } else { /* This should never happen */
279 *n = *p;
280 }
264 } 281 }
265 else if (*p == '_') 282 else if (*p == '_')
266 *n = ' '; 283 *n = ' ';
267 else 284 else
268 *n = *p; 285 *n = *p;