Mercurial > pidgin
comparison src/util.c @ 6872:dd0eecfbe413
[gaim-migrate @ 7418]
ok, these are some tweaks i've made to core code working on the new jabber
plugin.
- add gaim_find_buddy_in_group() that searches a specific group instead
of the entire list. kinda handy.
- re-did the base64 encoding function. i think it may have been broken,
i'm not sure, but this i know works.
- fix the formatted notify dialog to be more to my liking, and to have
a working Close button.
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Wed, 17 Sep 2003 03:45:04 +0000 |
| parents | 4ae5d9c3d9ec |
| children | 083d1e4a9c78 |
comparison
equal
deleted
inserted
replaced
| 6871:714fc8f45cf2 | 6872:dd0eecfbe413 |
|---|---|
| 317 | 317 |
| 318 static const char alphabet[] = | 318 static const char alphabet[] = |
| 319 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | 319 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
| 320 "0123456789+/"; | 320 "0123456789+/"; |
| 321 | 321 |
| 322 /* This was borrowed from the Kame source, and then tweaked to our needs */ | 322 char *tobase64(const unsigned char *in, size_t inlen) |
| 323 char *tobase64(const unsigned char *buf, size_t len) | 323 { |
| 324 { | 324 char *out, *rv; |
| 325 char *s = NULL, *rv = NULL; | 325 |
| 326 unsigned long tmp; | 326 rv = out = g_malloc((4 * (inlen + 1)) / 3 + 1); |
| 327 | 327 |
| 328 s = g_malloc((4 * (len + 1)) / 3 + 1); | 328 for (; inlen >= 3; inlen -= 3) |
| 329 | 329 { |
| 330 rv = s; | 330 *out++ = alphabet[in[0] >> 2]; |
| 331 while (len >= 3) { | 331 *out++ = alphabet[((in[0] << 4) & 0x30) | (in[1] >> 4)]; |
| 332 tmp = buf[0] << 16 | buf[1] << 8 | buf[2]; | 332 *out++ = alphabet[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; |
| 333 s[0] = alphabet[tmp >> 18]; | 333 *out++ = alphabet[in[2] & 0x3f]; |
| 334 s[1] = alphabet[(tmp >> 12) & 077]; | 334 in += 3; |
| 335 s[2] = alphabet[(tmp >> 6) & 077]; | 335 } |
| 336 s[3] = alphabet[tmp & 077]; | 336 if (inlen > 0) |
| 337 len -= 3; | 337 { |
| 338 buf += 3; | 338 unsigned char fragment; |
| 339 s += 4; | 339 |
| 340 } | 340 *out++ = alphabet[in[0] >> 2]; |
| 341 | 341 fragment = (in[0] << 4) & 0x30; |
| 342 /* RFC 1521 enumerates these three possibilities... */ | 342 if (inlen > 1) |
| 343 switch(len) { | 343 fragment |= in[1] >> 4; |
| 344 case 2: | 344 *out++ = alphabet[fragment]; |
| 345 tmp = buf[0] << 16 | buf[1] << 8; | 345 *out++ = (inlen < 2) ? '=' : alphabet[(in[1] << 2) & 0x3c]; |
| 346 s[0] = alphabet[(tmp >> 18) & 077]; | 346 *out++ = '='; |
| 347 s[1] = alphabet[(tmp >> 12) & 077]; | 347 } |
| 348 s[2] = alphabet[(tmp >> 6) & 077]; | 348 *out = '\0'; |
| 349 s[3] = '='; | |
| 350 s[4] = '\0'; | |
| 351 break; | |
| 352 case 1: | |
| 353 tmp = buf[0] << 16; | |
| 354 s[0] = alphabet[(tmp >> 18) & 077]; | |
| 355 s[1] = alphabet[(tmp >> 12) & 077]; | |
| 356 s[2] = s[3] = '='; | |
| 357 s[4] = '\0'; | |
| 358 break; | |
| 359 case 0: | |
| 360 s[0] = '\0'; | |
| 361 break; | |
| 362 } | |
| 363 | 349 |
| 364 return rv; | 350 return rv; |
| 365 } | 351 } |
| 366 | 352 |
| 367 | 353 |
