move md5sum code into separate function that relay can copy

This commit is contained in:
Eric House 2013-06-28 20:33:12 -07:00
parent 6c756533e3
commit 17eda4e5e1
3 changed files with 27 additions and 7 deletions

View file

@ -32,6 +32,7 @@
#include "dictnryp.h" #include "dictnryp.h"
#include "linuxmain.h" #include "linuxmain.h"
#include "strutils.h" #include "strutils.h"
#include "linuxutl.h"
typedef struct DictStart { typedef struct DictStart {
XP_U32 numNodes; XP_U32 numNodes;
@ -374,16 +375,16 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const LaunchParams* params,
) { ) {
XP_U32 curPos = ptr - dctx->dictBase; XP_U32 curPos = ptr - dctx->dictBase;
gssize dictLength = dctx->dictLength - curPos; gssize dictLength = dctx->dictLength - curPos;
GChecksum* cksum = g_checksum_new( G_CHECKSUM_MD5 );
g_checksum_update( cksum, ptr, dictLength ); XP_UCHAR buf[128];
const gchar* sum = g_checksum_get_string( cksum ); XP_U16 buflen = VSIZE(buf);
XP_LOGF( "calculated sum on %d bytes: %s", dictLength, sum ); figureMD5Sum( ptr, dictLength, buf, &buflen );
assert( buflen < VSIZE(buf) );
if ( NULL == dctx->super.md5Sum ) { if ( NULL == dctx->super.md5Sum ) {
dctx->super.md5Sum = copyString( dctx->super.mpool, sum ); dctx->super.md5Sum = copyString( dctx->super.mpool, buf );
} else { } 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; dctx->super.nFaces = numFaces;

View file

@ -651,6 +651,21 @@ writeNoConnMsgs( CommonGlobals* cGlobals, int fd )
cGlobals->noConnMsgs = NULL; cGlobals->noConnMsgs = NULL;
} /* writeNoConnMsgs */ } /* 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 #ifdef TEXT_MODEL
/* This is broken for UTF-8, even Spanish */ /* This is broken for UTF-8, even Spanish */
void void

View file

@ -49,6 +49,10 @@ XP_Bool storeNoConnMsg( CommonGlobals* cGlobals, const XP_U8* msg, XP_U16 len,
const XP_UCHAR* relayID ); const XP_UCHAR* relayID );
void writeNoConnMsgs( CommonGlobals* cGlobals, int fd ); 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 #ifdef STREAM_VERS_BIGBOARD
void setSquareBonuses( const CommonGlobals* cGlobals ); void setSquareBonuses( const CommonGlobals* cGlobals );
#else #else