Mercurial > pidgin
comparison src/util.c @ 4853:fbfdacf7c611
[gaim-migrate @ 5180]
This is better auto-getting of icons for oscar.
Ethan made me write a tobase16 fucntion and a from16 function (and he
done gave me some good advice for that, too) which convert to and
from arbitrary data and a null terminated string of hex. I use these
to get and store the md5 checksum for each icon sent to you. This way,
Gaim will request the icon when the md5sum differs. Er, so the md5sum
is stored in blist.xml.
Previously, Gaim would only request the icon if you did not have any
buddy icon for the other person. Now it will request it if the local
md5sum differs from the server md5sum.
To sum it up again, if their icon changes, gaim will request the new one.
I tried using the base64 functions, but they look like they want to
work with null terminated strings, rather than arbitrary data.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 22 Mar 2003 07:29:34 +0000 |
parents | 0ed37c803503 |
children | 912294585edf |
comparison
equal
deleted
inserted
replaced
4852:d1c17e81055e | 4853:fbfdacf7c611 |
---|---|
464 *data = out; | 464 *data = out; |
465 if (size) | 465 if (size) |
466 *size = len; | 466 *size = len; |
467 } | 467 } |
468 | 468 |
469 /* | |
470 * Converts raw data to a pretty, null-terminated base16 string. | |
471 */ | |
472 char *tobase16(const char *data, int length) | |
473 { | |
474 int i; | |
475 char *ascii = NULL; | |
476 | |
477 if (!data || !length) | |
478 return NULL; | |
479 | |
480 ascii = (char *)malloc(length*2 + 1); | |
481 | |
482 for (i=0; i<length; i++) | |
483 snprintf(&ascii[i*2], 3, "%02hhx", data[i]); | |
484 | |
485 return ascii; | |
486 } | |
487 | |
488 /* | |
489 * Converts a null-terminated string of hexidecimal to raw data. | |
490 */ | |
491 int frombase16(const char *ascii, char **raw) | |
492 { | |
493 int len, i, accumulator; | |
494 char *data; | |
495 | |
496 if (!ascii || !(len = strlen(ascii)) || (len % 2)) | |
497 return 0; | |
498 | |
499 data = (char *)malloc((len/2)*sizeof(char)); | |
500 for (i=0; i<len; i++) { | |
501 if (!(i % 2)) | |
502 accumulator = 0; | |
503 else | |
504 accumulator = accumulator << 4; | |
505 if (isdigit(ascii[i])) | |
506 accumulator |= ascii[i]-48; | |
507 else switch(ascii[i]) { | |
508 case 'a': case 'A': accumulator|=10; break; | |
509 case 'b': case 'B': accumulator|=11; break; | |
510 case 'c': case 'C': accumulator|=12; break; | |
511 case 'd': case 'D': accumulator|=13; break; | |
512 case 'e': case 'E': accumulator|=14; break; | |
513 case 'f': case 'F': accumulator|=15; break; | |
514 } | |
515 if (i % 2) | |
516 data[(i-1)/2] = accumulator; | |
517 } | |
518 | |
519 *raw = data; | |
520 return len/2; | |
521 } | |
469 | 522 |
470 char *normalize(const char *s) | 523 char *normalize(const char *s) |
471 { | 524 { |
472 static char buf[BUF_LEN]; | 525 static char buf[BUF_LEN]; |
473 char *tmp; | 526 char *tmp; |