Revision: 14360 Author: adrian.chadd Date: Wed Nov 4 15:59:48 2009 Log: recommit the work to break out the hex generation code
http://code.google.com/p/lusca-cache/source/detail?r=14360 Added: /branches/LUSCA_HEAD/include/hex.h /branches/LUSCA_HEAD/lib/hex.c Modified: /branches/LUSCA_HEAD/src/store_key_md5.c ======================================= --- /dev/null +++ /branches/LUSCA_HEAD/include/hex.h Wed Nov 4 15:59:48 2009 @@ -0,0 +1,6 @@ +#ifndef __INCLUDE_HEX_H__ +#define __INCLUDE_HEX_H__ + +extern void hex_from_byte_array(char *dst, const char *src, int srclen); + +#endif ======================================= --- /dev/null +++ /branches/LUSCA_HEAD/lib/hex.c Wed Nov 4 15:59:48 2009 @@ -0,0 +1,20 @@ +#include "../include/config.h" + +/* XXX this should be uhm, a library function! [ahc] */ +static char tohex[] = { '0','1','2','3','4','5','6','7','8','9', 'A', 'B', 'C', 'D', 'E', 'F' }; + +/* + * Create a hex string from the given byte array. + * + * It is up to the caller to ensure that there is at least 2x "srclen" bytes + * available in dst. + */ +void +hex_from_byte_array(char *dst, const char *src, int srclen) +{ + int i; + for (i = 0; i < srclen; i++) { + *(dst++) = tohex[(*src >> 4) & 0x0f]; + *(dst++) = tohex[*(src++) & 0x0f]; + } +} ======================================= --- /branches/LUSCA_HEAD/src/store_key_md5.c Wed Nov 4 15:54:09 2009 +++ /branches/LUSCA_HEAD/src/store_key_md5.c Wed Nov 4 15:59:48 2009 @@ -35,24 +35,18 @@ #include "squid.h" +#include "../include/hex.h" + static cache_key null_key[SQUID_MD5_DIGEST_LENGTH]; static MemPool * pool_md5_key = NULL; -/* XXX this should be uhm, a library function! [ahc] */ -static char tohex[] = { '0','1','2','3','4','5','6','7','8','9', 'A', 'B', 'C', 'D', 'E', 'F' }; - const char * storeKeyText(const unsigned char *key) { static char buf[SQUID_MD5_DIGEST_LENGTH*2+1]; - char *b = buf; - int i; - - for (i = 0; i < SQUID_MD5_DIGEST_LENGTH; i++) { - *(b++) = tohex[(key[i] >> 4) & 0x0f]; - *(b++) = tohex[key[i] & 0x0f]; - } - *b = '\0'; + + hex_from_byte_array(buf, (char *) key, SQUID_MD5_DIGEST_LENGTH); + buf[SQUID_MD5_DIGEST_LENGTH*2] = '\0'; return buf; } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "lusca-commit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/lusca-commit?hl=en -~----------~----~----~----~------~----~------~--~---
