# HG changeset patch # User Stu Tomlinson # Date 1180185095 0 # Node ID b462ef222d28e74fd34a02f7209585b02a2c964b # Parent 85d131a53fa27a581e9762a8762c635574b210ca Use glib functions for endian conversion. If someone has a big endian system and can test that this works for me, that would be great! diff -r 85d131a53fa2 -r b462ef222d28 libpurple/protocols/msn/msnutils.c --- a/libpurple/protocols/msn/msnutils.c Sat May 26 12:49:57 2007 +0000 +++ b/libpurple/protocols/msn/msnutils.c Sat May 26 13:11:35 2007 +0000 @@ -498,27 +498,6 @@ /*************************************************************************** * MSN Challenge Computing Function ***************************************************************************/ -/*check the edian of system*/ -int -isBigEndian(void) -{ - short int word = 0x0100; - char *byte = (char *)&word; - - return(byte[0]); -} - -/*swap utility*/ -unsigned int -swapInt(unsigned int dw) -{ - unsigned int tmp; - tmp = (dw & 0x000000FF); - tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08); - tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08); - tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08); - return(tmp); -} /* * Handle MSN Chanllege computation @@ -539,10 +518,7 @@ long long nHigh=0, nLow=0; - int i, bigEndian; - - /* Determine our endianess */ - bigEndian = isBigEndian(); + int i; /* Create the MD5 hash by using Purple MD5 algorithm*/ cipher = purple_ciphers_find_cipher("md5"); @@ -558,9 +534,8 @@ /* Split it into four integers */ md5Parts = (unsigned int *)md5Hash; for(i=0; i<4; i++){ - /* check for endianess */ - if(bigEndian) - md5Parts[i] = swapInt(md5Parts[i]); + /* adjust endianess */ + md5Parts[i] = GUINT_TO_LE(md5Parts[i]); /* & each integer with 0x7FFFFFFF */ /* and save one unmodified array for later */ @@ -581,10 +556,8 @@ for (i=0; i<(strlen(buf)/4)-1; i+=2){ long long temp; - if(bigEndian){ - chlStringParts[i] = swapInt(chlStringParts[i]); - chlStringParts[i+1] = swapInt(chlStringParts[i+1]); - } + chlStringParts[i] = GUINT_TO_LE(chlStringParts[i]); + chlStringParts[i+1] = GUINT_TO_LE(chlStringParts[i+1]); temp=(md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; nHigh=(md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; @@ -598,9 +571,9 @@ newHashParts[2]^=nHigh; newHashParts[3]^=nLow; - /* swap more bytes if big endian */ - for(i=0; i<4 && bigEndian; i++) - newHashParts[i] = swapInt(newHashParts[i]); + /* adjust endianness */ + for(i=0; i<4; i++) + newHashParts[i] = GUINT_TO_LE(newHashParts[i]); /* make a string of the parts */ newHash = (unsigned char *)newHashParts; diff -r 85d131a53fa2 -r b462ef222d28 libpurple/protocols/msn/msnutils.h --- a/libpurple/protocols/msn/msnutils.h Sat May 26 12:49:57 2007 +0000 +++ b/libpurple/protocols/msn/msnutils.h Sat May 26 13:11:35 2007 +0000 @@ -56,7 +56,5 @@ void msn_parse_socket(const char *str, char **ret_host, int *ret_port); void msn_handle_chl(char *input, char *output); -int isBigEndian(void); -unsigned int swapInt(unsigned int dw); #endif /* _MSN_UTILS_H_ */