From 17eda4e5e111ef3eb62b0d802c39eeec2ade174e Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 28 Jun 2013 20:33:12 -0700 Subject: [PATCH] move md5sum code into separate function that relay can copy --- xwords4/linux/linuxdict.c | 15 ++++++++------- xwords4/linux/linuxutl.c | 15 +++++++++++++++ xwords4/linux/linuxutl.h | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/xwords4/linux/linuxdict.c b/xwords4/linux/linuxdict.c index b6e207768..653c19fb5 100644 --- a/xwords4/linux/linuxdict.c +++ b/xwords4/linux/linuxdict.c @@ -32,6 +32,7 @@ #include "dictnryp.h" #include "linuxmain.h" #include "strutils.h" +#include "linuxutl.h" typedef struct DictStart { XP_U32 numNodes; @@ -374,16 +375,16 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const LaunchParams* params, ) { XP_U32 curPos = ptr - dctx->dictBase; gssize dictLength = dctx->dictLength - curPos; - GChecksum* cksum = g_checksum_new( G_CHECKSUM_MD5 ); - g_checksum_update( cksum, ptr, dictLength ); - const gchar* sum = g_checksum_get_string( cksum ); - XP_LOGF( "calculated sum on %d bytes: %s", dictLength, sum ); + + XP_UCHAR buf[128]; + XP_U16 buflen = VSIZE(buf); + figureMD5Sum( ptr, dictLength, buf, &buflen ); + assert( buflen < VSIZE(buf) ); if ( NULL == dctx->super.md5Sum ) { - dctx->super.md5Sum = copyString( dctx->super.mpool, sum ); + dctx->super.md5Sum = copyString( dctx->super.mpool, buf ); } else { - XP_ASSERT( 0 == XP_STRCMP( dctx->super.md5Sum, sum ) ); + XP_ASSERT( 0 == XP_STRCMP( dctx->super.md5Sum, buf ) ); } - g_checksum_free( cksum ); } dctx->super.nFaces = numFaces; diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index 650c0c892..db67e3c4f 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -651,6 +651,21 @@ writeNoConnMsgs( CommonGlobals* cGlobals, int fd ) cGlobals->noConnMsgs = NULL; } /* writeNoConnMsgs */ +void +figureMD5Sum( const XP_U8* data, XP_U16 datalen, XP_UCHAR* buf, XP_U16* buflen ) +{ + GChecksum* cksum = g_checksum_new( G_CHECKSUM_MD5 ); + g_checksum_update( cksum, data, datalen ); + const gchar* sum = g_checksum_get_string( cksum ); + XP_LOGF( "%s calculated sum on %d bytes: %s", __func__, datalen, sum ); + int sumlen = strlen( sum ); + if ( sumlen < *buflen ) { + (void)snprintf( buf, *buflen, "%s", sum ); + } + *buflen = sumlen; + g_checksum_free( cksum ); +} + #ifdef TEXT_MODEL /* This is broken for UTF-8, even Spanish */ void diff --git a/xwords4/linux/linuxutl.h b/xwords4/linux/linuxutl.h index 781031a32..967bd03fd 100644 --- a/xwords4/linux/linuxutl.h +++ b/xwords4/linux/linuxutl.h @@ -49,6 +49,10 @@ XP_Bool storeNoConnMsg( CommonGlobals* cGlobals, const XP_U8* msg, XP_U16 len, const XP_UCHAR* relayID ); void writeNoConnMsgs( CommonGlobals* cGlobals, int fd ); +void figureMD5Sum( const XP_U8* data, XP_U16 datalen, + XP_UCHAR* buf, XP_U16* buflen ); + + #ifdef STREAM_VERS_BIGBOARD void setSquareBonuses( const CommonGlobals* cGlobals ); #else