From: Robert K. <may...@us...> - 2001-07-23 22:32:14
|
Update of /cvsroot/bitcollider/bitcollider/lib In directory usw-pr-cvs1:/tmp/cvs-serv8755/lib Modified Files: Makefile.am main.c Added Files: bitprint.c Log Message: Added the new bitprint.[ch] to the bitcollider. The bitprints and audioSha1 values are now in base32 --- NEW FILE: bitprint.c --- /* (PD) 2001 The Bitzi Corporation * Please see file COPYING or http://bitzi.com/publicdomain * for more info. * * $Id: bitprint.c,v 1.1 2001/07/23 22:32:10 mayhemchaos Exp $ */ #include <string.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> #include <ctype.h> #include "bitprint.h" /* =================================================================== */ /* Main code */ /* =================================================================== */ #define BASE32_LOOKUP_MAX 43 static unsigned char *base32Chars = "ABCDEFGHIJKMNPQRSTUVWXYZ23456789"; static unsigned char base32Lookup[BASE32_LOOKUP_MAX][2] = { { '0', 0xFF }, { '1', 0xFF }, { '2', 0x18 }, { '3', 0x19 }, { '4', 0x1A }, { '5', 0x1B }, { '6', 0x1C }, { '7', 0x1D }, { '8', 0x1E }, { '9', 0x1F }, { ':', 0xFF }, { ';', 0xFF }, { '<', 0xFF }, { '=', 0xFF }, { '>', 0xFF }, { '?', 0xFF }, { '@', 0xFF }, { 'A', 0x00 }, { 'B', 0x01 }, { 'C', 0x02 }, { 'D', 0x03 }, { 'E', 0x04 }, { 'F', 0x05 }, { 'G', 0x06 }, { 'H', 0x07 }, { 'I', 0x08 }, { 'J', 0x09 }, { 'K', 0x0A }, { 'L', 0xFF }, { 'M', 0x0B }, { 'N', 0x0C }, { 'O', 0xFF }, { 'P', 0x0D }, { 'Q', 0x0E }, { 'R', 0x0F }, { 'S', 0x10 }, { 'T', 0x11 }, { 'U', 0x12 }, { 'V', 0x13 }, { 'W', 0x14 }, { 'X', 0x15 }, { 'Y', 0x16 }, { 'Z', 0x17 } }; #define BUFFER_LEN 4096 #define ONEK_SIZE 1025 #define EMPTY_SHA "5I64H5U8PPFS4NUXZ9Z3K2A2UCZ7SB2J" #define ONE_SHA "GXXBUK53CQ2E2XCZJWNNFDKG626XIKFM" #define ONEK_SHA "CAE76MZYDA77PYGAT6RPTZ4II9VT88YM" #define EMPTY_TIGER "GKJ4222NCR2CIZ6UZQ2ZN5SYC37E6YCJFZRHH62" #define ONE_TIGER "DXMVDFFAK5XVEAH34NBJADEEHS8WDK4Q4BYAHZ2" #define ONEK_TIGER "4FNVCKHVA5QT2KBTIYJAM6KN3QCD6349AIRU7IS" static int check_sha1_hash(const char *result, unsigned char *data, int len); static int check_tigertree_hash(const char *result, unsigned char *data, int len); static int hash_sanity_check(void); int bitziBitprintFile(const char *fileName, unsigned char *bitprint) { FILE *file; int ret; file = fopen(fileName, "rb"); if (file == NULL) return 0; ret = bitziBitprintStream(file, bitprint); fclose(file); return ret; } int bitziBitprintStream(FILE *source, unsigned char *bitprint) { BP_CONTEXT context; unsigned char *buffer; int bytes; int ret = 1; if (bitziBitprintInit(&context) == -1) return -1; buffer = (unsigned char*)malloc(BUFFER_LEN); if (buffer == NULL) { return 0; } fseek(source, 0, SEEK_SET); for(;;) { bytes = fread(buffer, 1, BUFFER_LEN, source); if (bytes <= 0) { ret = feof(source) != 0; break; } bitziBitprintUpdate(&context, buffer, bytes); } free(buffer); bitziBitprintFinal(&context, bitprint); return ret; } int bitziBitprintBuffer(unsigned char *buffer, unsigned int bufLen, unsigned char *bitprint) { BP_CONTEXT context; if (bitziBitprintInit(&context) == -1) return -1; bitziBitprintUpdate(&context, buffer, bufLen); bitziBitprintFinal(&context, bitprint); return 1; } int bitziBitprintInit(BP_CONTEXT *context) { if (hash_sanity_check() > 0) return -1; tt_init(&context->tcontext); sha_init(&context->scontext); return 1; } void bitziBitprintUpdate(BP_CONTEXT *context, unsigned char *buffer, unsigned bytes) { tt_update(&context->tcontext, buffer, bytes); sha_update(&context->scontext, buffer, bytes); } void bitziBitprintFinal(BP_CONTEXT *context, unsigned char *bitprint) { sha_final(bitprint, &context->scontext); tt_digest(&context->tcontext, bitprint + SHA_DIGESTSIZE); } void bitziBitprintToBase32(const unsigned char *bitprint, char *base32Bitprint) { bitziEncodeBase32(bitprint, BITPRINT_RAW_LEN, base32Bitprint); } void bitziBitprintFromBase32(const char *base32Bitprint, unsigned char *bitprint) { bitziDecodeBase32(base32Bitprint, BITPRINT_BASE32_LEN, bitprint); } int bitziGetBase32EncodeLength(int rawLength) { return ((rawLength * 8) / 5) + ((rawLength % 5) != 0) + 1; } int bitziGetBase32DecodeLength(int base32Length) { return ((base32Length * 5) / 8); } void bitziEncodeBase32(const unsigned char *buffer, unsigned int bufLen, char *base32Buffer) { unsigned int i, index; unsigned char word; for(i = 0, index = 0; i < bufLen;) { /* Is the current word going to span a byte boundary? */ if (index > 3) { word = (buffer[i] & (0xFF >> index)); index = (index + 5) % 8; word <<= index; if (i < bufLen - 1) word |= buffer[i + 1] >> (8 - index); i++; } else { word = (buffer[i] >> (8 - (index + 5))) & 0x1F; index = (index + 5) % 8; if (index == 0) i++; } assert(word < 32); *(base32Buffer++) = (char)base32Chars[word]; } *base32Buffer = 0; } void bitziDecodeBase32(const char *base32Buffer, unsigned int base32BufLen, unsigned char *buffer) { int i, index, max, lookup, offset; unsigned char word; memset(buffer, 0, bitziGetBase32DecodeLength(base32BufLen)); max = strlen(base32Buffer); for(i = 0, index = 0, offset = 0; i < max; i++) { lookup = toupper(base32Buffer[i]) - '0'; /* Check to make sure that the given word falls inside a valid range */ if ( lookup < 0 && lookup >= BASE32_LOOKUP_MAX) word = 0xFF; else word = base32Lookup[lookup][1]; /* If this word is not in the table, ignore it */ if (word == 0xFF) continue; if (index <= 3) { index = (index + 5) % 8; if (index == 0) { buffer[offset] |= word; offset++; } else buffer[offset] |= word << (8 - index); } else { index = (index + 5) % 8; buffer[offset] |= (word >> index); offset++; buffer[offset] |= word << (8 - index); } } } static int hash_sanity_check(void) { int ret; unsigned char *data; ret = check_tigertree_hash(EMPTY_TIGER, "", 0); ret += check_sha1_hash(EMPTY_SHA, "", 0); ret += check_tigertree_hash(ONE_TIGER, "1", 1); ret += check_sha1_hash(ONE_SHA, "1", 1); data = malloc(ONEK_SIZE); memset(data, 'a', ONEK_SIZE); ret += check_tigertree_hash(ONEK_TIGER, data, ONEK_SIZE); ret += check_sha1_hash(ONEK_SHA, data, ONEK_SIZE); free(data); return ret; } /* NOTE: This function returns true if it failed the check! */ static int check_tigertree_hash(const char *result, unsigned char *data, int len) { TT_CONTEXT tcontext; unsigned char tigerTreeHash[TIGERSIZE]; char tigerTreeDigest[TIGER_BASE32SIZE + 1]; tt_init(&tcontext); tt_update(&tcontext, data, len); tt_digest(&tcontext, tigerTreeHash); bitziEncodeBase32(tigerTreeHash, TIGERSIZE, tigerTreeDigest); if (strcmp(tigerTreeDigest, result)) { fprintf(stderr, " tigertree: '%s' [%d]\n", tigerTreeDigest, len); fprintf(stderr, "correct tigertree: '%s' [%d]\n", result, len); return 1; } return 0; } /* NOTE: This function returns true if it failed the check! */ static int check_sha1_hash(const char *result, unsigned char *data, int len) { SHA_INFO scontext; unsigned char shaHash[SHA_DIGESTSIZE]; char shaDigest[SHA_BASE32SIZE + 1]; sha_init(&scontext); sha_update(&scontext, data, len); sha_final(shaHash, &scontext); bitziEncodeBase32(shaHash, SHA_DIGESTSIZE, shaDigest); if (strcmp(shaDigest, result)) { fprintf(stderr, " sha: '%s' [%d]\n", shaDigest, len); fprintf(stderr, " correct sha: '%s' [%d]\n", result, len); return 1; } return 0; } Index: Makefile.am =================================================================== RCS file: /cvsroot/bitcollider/bitcollider/lib/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** Makefile.am 2001/07/09 21:19:52 1.10 --- Makefile.am 2001/07/23 22:32:10 1.11 *************** *** 9,13 **** INCLUDES = $(INCLTDL) -I$(top_srcdir)/.. -I$(top_srcdir)/ver -I$(top_srcdir)/include lib_LTLIBRARIES = libbitcollider.la ! libbitcollider_la_SOURCES = main.c sha1.c tiger.c tigertree.c sboxes.c browser.c mp3.c id3.c plugin_man.c plugin_man.h dirsearch.c dir.h libbitcollider_la_LDFLAGS = -version-info 1:0:0 libbitcollider_la_LIBADD = $(LIBLTDL) --- 9,13 ---- INCLUDES = $(INCLTDL) -I$(top_srcdir)/.. -I$(top_srcdir)/ver -I$(top_srcdir)/include lib_LTLIBRARIES = libbitcollider.la ! libbitcollider_la_SOURCES = main.c sha1.c tiger.c tigertree.c sboxes.c browser.c mp3.c id3.c plugin_man.c plugin_man.h dirsearch.c dir.h bitprint.c bitprint.h libbitcollider_la_LDFLAGS = -version-info 1:0:0 libbitcollider_la_LIBADD = $(LIBLTDL) Index: main.c =================================================================== RCS file: /cvsroot/bitcollider/bitcollider/lib/main.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -r1.24 -r1.25 *** main.c 2001/07/23 21:22:34 1.24 --- main.c 2001/07/23 22:32:11 1.25 *************** *** 13,18 **** #include "bc_version.h" #include "bitcollider.h" ! #include "tigertree.h" ! #include "sha1.h" #include "mp3.h" #include "id3.h" --- 13,17 ---- #include "bc_version.h" #include "bitcollider.h" ! #include "bitprint.h" #include "mp3.h" #include "id3.h" *************** *** 26,33 **** /*------------------------------------------------------------------------- */ - b_bool hashCheckPassed = false; - /*------------------------------------------------------------------------- */ - #define BUFFER_LEN 4096 #define FIRST_N_HEX 20 --- 25,29 ---- *************** *** 36,48 **** #define DEFAULT_NUM_ATTRS 16 #define GROW_NUM_ATTRS 16 - #define SHA_HEXSIZE ((SHA_DIGESTSIZE * 2 * sizeof(char)) + 1) - #define TIGER_HEXSIZE ((TIGERSIZE * 2 * sizeof(char)) + 1) - #define ONEK_SIZE 1025 - #define EMPTY_SHA "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" - #define ONE_SHA "356A192B7913B04C54574D18C28D46E6395428AB" - #define ONEK_SHA "1009DE2EF6183BD6D8C08F1ED8DF4847E71F7ACB" - #define EMPTY_TIGER "3293AC630C13F0245F92BBB1766E16167A4E58492DDE73F3" - #define ONE_TIGER "1D573194A056EB3200F9D302900C843C3D41AB4ED06C03DF" - #define ONEK_TIGER "D1593128F306DD1C2831459205F14CCB843E675F021F2EA2" #ifdef _WIN32 --- 32,35 ---- *************** *** 68,73 **** b_bool calculate_hashes(BitcolliderSubmission *submission, FILE *source, ! unsigned char *sha1, ! unsigned char *tigerTree, mp3_info *mp3Info, PluginMethods *methods, --- 55,59 ---- b_bool calculate_hashes(BitcolliderSubmission *submission, FILE *source, ! char *bitprint, mp3_info *mp3Info, PluginMethods *methods, *************** *** 79,84 **** b_bool get_bitprint_data(BitcolliderSubmission *submission, const char *fileName, ! unsigned char *sha1, ! unsigned char *tigerTree, unsigned char *firstHex, mp3_info *mp3Info, --- 65,69 ---- b_bool get_bitprint_data(BitcolliderSubmission *submission, const char *fileName, ! char *bitprint, unsigned char *firstHex, mp3_info *mp3Info, *************** *** 86,92 **** Attribute **attrList); void convert_to_multiple_submission(BitcolliderSubmission *submission); - b_bool hash_sanity_check(void); - b_bool check_tigertree_hash(const char *result, unsigned char *data, int len); - b_bool check_sha1_hash(const char *result, unsigned char *data, int len); void set_error(BitcolliderSubmission *sub, const char *newError); void set_warning(BitcolliderSubmission *sub, const char *newError); --- 71,74 ---- *************** *** 147,152 **** if (ret != ERROR_SUCCESS) return bc; - - /*printf("Reg key set. Using path: '%s'\n", path); */ } ptr = path; --- 129,132 ---- *************** *** 171,260 **** } - BitcolliderSubmission *read_submission_from_file(Bitcollider *bc, FILE *infile) - { - BitcolliderSubmission *submission; - char buf[BUFFER_LEN], last[BUFFER_LEN], temp[BUFFER_LEN]; - char *c, *t; - int line, empty = 1; - - submission = (BitcolliderSubmission *)malloc(sizeof(BitcolliderSubmission)); - if (submission == NULL) - return NULL; - - memset(submission, 0, sizeof(BitcolliderSubmission)); - submission->bc = bc; - - last[0] = 0; - - for( line = 1; fgets( buf, BUFFER_LEN, infile ) != NULL; ++line ) - { - if( ! ( ( t = strchr( buf, '\r' ) ) || ( t = strchr( buf, '\n' ) ) ) ) - { - if( strlen( buf ) == BUFFER_LEN - 1 ) - { - fprintf( stderr, "Line %d exceeds length limit\n", line ); - exit(1); - } - else - { - fprintf( stderr, "Line %d is truncated\n", line ); - exit(1); - } - } - *t = 0; - - for( c = buf; *c == ' ' && *c == '\t'; ++c ) - ; /* <-- Empty for loop */ - - if( ! *c || *c == '#' ) - continue; - - if( ! ( t = strchr( c, '=' ) ) ) - { - fprintf( stderr, "Line %d does not appear to contain a tag\n", - line ); - exit(1); - } - *t = 0; - if( ! strncmp( c, "head.", 5 ) ) - continue; - if( isdigit( *c ) ) - { - if( ! ( t = strchr( c, '.' ) ) ) - { - fprintf(stderr, "Line %d does not appear to contain a tag\n", - line ); - exit(1); - } - *t = 0; - - strcpy( last, c ); - c = t + 1; - } - if (empty) - { - empty = 0; - get_agent_string(temp); - add_attribute(submission, "head.agent", temp); - - sprintf(temp, "S%s", BC_SUBMITSPECVER); - add_attribute(submission, "head.version", temp); - } - - if(strncmp(c, "bitprint", 8) == 0) - { - if (submission->numBitprints == 1) - convert_to_multiple_submission(submission); - - submission->numBitprints++; - } - submission->numBitprints--; - add_attribute( submission, c, c + strlen( c ) + 1 ); - submission->numBitprints++; - } - - return submission; - } - BitcolliderSubmission *create_submission(Bitcollider *bc) { --- 151,154 ---- *************** *** 268,278 **** submission->bc = bc; - if (!hashCheckPassed && hash_sanity_check()) - { - set_error(submission, ERROR_HASHCHECK); - } - else - hashCheckPassed = true; - return submission; } --- 162,165 ---- *************** *** 282,287 **** b_bool matchingExtsOnly) { ! char shaDigest[SHA_HEXSIZE]; ! char tigerTreeDigest[TIGER_HEXSIZE]; char firstNHex[FIRST_N_HEX_SIZE + 1]; char temp[MAX_ATTR_STRING_LEN], *ext; --- 169,173 ---- b_bool matchingExtsOnly) { ! char bitprint[BITPRINT_BASE32_LEN + 1]; char firstNHex[FIRST_N_HEX_SIZE + 1]; char temp[MAX_ATTR_STRING_LEN], *ext; *************** *** 304,313 **** } - if (!hashCheckPassed) - { - set_error(submission, ERROR_HASHCHECK); - return false; - } - if (submission->fileName) { --- 190,193 ---- *************** *** 356,361 **** mp3Info = malloc(sizeof(mp3_info)); ! if (!get_bitprint_data(submission, fileName, shaDigest, tigerTreeDigest, ! firstNHex, mp3Info, methods, &attrList)) { if (mp3Info) --- 236,241 ---- mp3Info = malloc(sizeof(mp3_info)); ! if (!get_bitprint_data(submission, fileName, bitprint, firstNHex, ! mp3Info, methods, &attrList)) { if (mp3Info) *************** *** 380,385 **** convert_to_multiple_submission(submission); ! sprintf(temp, "%s%s", shaDigest, tigerTreeDigest); ! add_attribute(submission, "bitprint", temp); sprintf(temp, "%lu", submission->fileSize); --- 260,264 ---- convert_to_multiple_submission(submission); ! add_attribute(submission, "bitprint", bitprint); sprintf(temp, "%lu", submission->fileSize); *************** *** 400,407 **** if (mp3Check) { ! char audioShaDigest[SHA_HEXSIZE]; ID3Info *info; ! convert_to_hex(mp3Info->audioSha, SHA_DIGESTSIZE, audioShaDigest); sprintf(temp, "%d", mp3Info->duration); add_attribute(submission, "tag.mp3.duration", temp); --- 279,286 ---- if (mp3Check) { ! char audioShaDigest[SHA_BASE32SIZE + 1]; ID3Info *info; ! bitziEncodeBase32(mp3Info->audioSha, SHA_DIGESTSIZE, audioShaDigest); sprintf(temp, "%d", mp3Info->duration); add_attribute(submission, "tag.mp3.duration", temp); *************** *** 581,584 **** --- 460,476 ---- } + static void convert_to_hex(const unsigned char *buffer, + int size, + char *hexBuffer) + { + int i; + + for(i = 0; i < size; i++) + { + sprintf(hexBuffer + (i * sizeof(char) * 2), "%02X", buffer[i] & 0xFF); + } + } + + void add_attribute(BitcolliderSubmission *submission, const char *key, *************** *** 651,656 **** b_bool get_bitprint_data(BitcolliderSubmission *submission, const char *fileName, ! unsigned char *sha1, ! unsigned char *tigerTree, unsigned char *firstHex, mp3_info *mp3Info, --- 543,547 ---- b_bool get_bitprint_data(BitcolliderSubmission *submission, const char *fileName, ! char *bitprint, unsigned char *firstHex, mp3_info *mp3Info, *************** *** 672,676 **** fseek(source, 0, SEEK_SET); ! ret = calculate_hashes(submission, source, sha1, tigerTree, mp3Info, methods, attrList); if (ret) --- 563,567 ---- fseek(source, 0, SEEK_SET); ! ret = calculate_hashes(submission, source, bitprint, mp3Info, methods, attrList); if (ret) *************** *** 683,703 **** b_bool calculate_hashes(BitcolliderSubmission *submission, FILE *source, ! unsigned char *sha1, ! unsigned char *tigerTree, mp3_info *mcontext, PluginMethods *methods, Attribute **attrList) { ! TT_CONTEXT tcontext; ! SHA_INFO scontext; ! unsigned char *buffer; int bytes; - unsigned char tigerHash[TIGERSIZE]; - unsigned char shaHash[SHA_DIGESTSIZE]; b_bool ret = true; Context *context = NULL; - tt_init(&tcontext); - sha_init(&scontext); if (mcontext) mp3_init(mcontext); --- 574,594 ---- b_bool calculate_hashes(BitcolliderSubmission *submission, FILE *source, ! char *bitprint, mp3_info *mcontext, PluginMethods *methods, Attribute **attrList) { ! BP_CONTEXT bcontext; ! unsigned char *buffer, bitprintRaw[BITPRINT_RAW_LEN]; int bytes; b_bool ret = true; Context *context = NULL; + + if (bitziBitprintInit(&bcontext) == -1) + { + set_error(submission, ERROR_HASHCHECK); + return false; + } if (mcontext) mp3_init(mcontext); *************** *** 729,734 **** } ! tt_update(&tcontext, buffer, bytes); ! sha_update(&scontext, buffer, bytes); if (mcontext) mp3_update(mcontext, buffer, bytes); --- 620,624 ---- } ! bitziBitprintUpdate(&bcontext, buffer, bytes); if (mcontext) mp3_update(mcontext, buffer, bytes); *************** *** 752,757 **** free(buffer); ! tt_digest(&tcontext, tigerHash); ! sha_final(shaHash, &scontext); if (mcontext) mp3_final(mcontext); --- 642,648 ---- free(buffer); ! bitziBitprintFinal(&bcontext, bitprintRaw); ! bitziBitprintToBase32(bitprintRaw, bitprint); ! if (mcontext) mp3_final(mcontext); *************** *** 759,765 **** *attrList = methods->mem_analyze_final(context); - convert_to_hex(tigerHash, TIGERSIZE, tigerTree); - convert_to_hex(shaHash, SHA_DIGESTSIZE, sha1); - return ret; } --- 650,653 ---- *************** *** 795,808 **** } - void convert_to_hex(const unsigned char *buffer, int size, char *hexBuffer) - { - int i; - - for(i = 0; i < size; i++) - { - sprintf(hexBuffer + (i * sizeof(char) * 2), "%02X", buffer[i] & 0xFF); - } - } - b_bool submit_submission(BitcolliderSubmission *submission, const char *url, --- 683,686 ---- *************** *** 909,986 **** } ! void print_submission(BitcolliderSubmission *submission) { ! int i; ! for(i = 0; i < submission->numItems; i++) ! { ! printf("%s=%s\n", ! submission->attrList[i]->key, ! submission->attrList[i]->value); ! } ! } ! b_bool hash_sanity_check(void) ! { ! b_bool ret; ! unsigned char *data; ! ret = check_tigertree_hash(EMPTY_TIGER, "", 0); ! ret += check_sha1_hash(EMPTY_SHA, "", 0); ! ret += check_tigertree_hash(ONE_TIGER, "1", 1); ! ret += check_sha1_hash(ONE_SHA, "1", 1); ! ! data = malloc(ONEK_SIZE); ! memset(data, 'a', ONEK_SIZE); ! ret += check_tigertree_hash(ONEK_TIGER, data, ONEK_SIZE); ! ret += check_sha1_hash(ONEK_SHA, data, ONEK_SIZE); ! free(data); ! return ret; ! } ! /* NOTE: This function returns true if it failed the check! */ ! b_bool check_tigertree_hash(const char *result, unsigned char *data, int len) ! { ! TT_CONTEXT tcontext; ! unsigned char tigerTreeHash[TIGERSIZE]; ! char tigerTreeDigest[TIGER_HEXSIZE]; ! tt_init(&tcontext); ! tt_update(&tcontext, data, len); ! tt_digest(&tcontext, tigerTreeHash); ! convert_to_hex(tigerTreeHash, TIGERSIZE, tigerTreeDigest); ! if (strcmp(tigerTreeDigest, result)) ! { ! fprintf(stderr, " tigertree: '%s' [%d]\n", ! tigerTreeDigest, len); ! fprintf(stderr, "correct tigertree: '%s' [%d]\n", ! result, len); ! return true; } ! return false; } ! /* NOTE: This function returns true if it failed the check! */ ! b_bool check_sha1_hash(const char *result, unsigned char *data, int len) { ! SHA_INFO scontext; ! unsigned char shaHash[SHA_DIGESTSIZE]; ! char shaDigest[SHA_HEXSIZE]; ! ! sha_init(&scontext); ! sha_update(&scontext, data, len); ! sha_final(shaHash, &scontext); ! convert_to_hex(shaHash, SHA_DIGESTSIZE, shaDigest); ! if (strcmp(shaDigest, result)) { ! fprintf(stderr, " sha: '%s' [%d]\n", shaDigest, len); ! fprintf(stderr, " correct sha: '%s' [%d]\n", result, len); ! return true; } - return false; } --- 787,886 ---- } ! BitcolliderSubmission *read_submission_from_file(Bitcollider *bc, FILE *infile) { ! BitcolliderSubmission *submission; ! char buf[BUFFER_LEN], last[BUFFER_LEN], temp[BUFFER_LEN]; ! char *c, *t; ! int line, empty = 1; ! submission = (BitcolliderSubmission *)malloc(sizeof(BitcolliderSubmission)); ! if (submission == NULL) ! return NULL; ! memset(submission, 0, sizeof(BitcolliderSubmission)); ! submission->bc = bc; + last[0] = 0; ! for( line = 1; fgets( buf, BUFFER_LEN, infile ) != NULL; ++line ) ! { ! if( ! ( ( t = strchr( buf, '\r' ) ) || ( t = strchr( buf, '\n' ) ) ) ) ! { ! if( strlen( buf ) == BUFFER_LEN - 1 ) ! { ! fprintf( stderr, "Line %d exceeds length limit\n", line ); ! exit(1); ! } ! else ! { ! fprintf( stderr, "Line %d is truncated\n", line ); ! exit(1); ! } ! } ! *t = 0; ! for( c = buf; *c == ' ' && *c == '\t'; ++c ) ! ; /* <-- Empty for loop */ ! if( ! *c || *c == '#' ) ! continue; ! if( ! ( t = strchr( c, '=' ) ) ) ! { ! fprintf( stderr, "Line %d does not appear to contain a tag\n", ! line ); ! exit(1); ! } ! *t = 0; ! if( ! strncmp( c, "head.", 5 ) ) ! continue; ! if( isdigit( *c ) ) ! { ! if( ! ( t = strchr( c, '.' ) ) ) ! { ! fprintf(stderr, "Line %d does not appear to contain a tag\n", ! line ); ! exit(1); ! } ! *t = 0; ! strcpy( last, c ); ! c = t + 1; ! } ! if (empty) ! { ! empty = 0; ! get_agent_string(temp); ! add_attribute(submission, "head.agent", temp); ! ! sprintf(temp, "S%s", BC_SUBMITSPECVER); ! add_attribute(submission, "head.version", temp); ! } ! ! if(strncmp(c, "bitprint", 8) == 0) ! { ! if (submission->numBitprints == 1) ! convert_to_multiple_submission(submission); ! ! submission->numBitprints++; ! } ! submission->numBitprints--; ! add_attribute( submission, c, c + strlen( c ) + 1 ); ! submission->numBitprints++; } ! ! return submission; } ! void print_submission(BitcolliderSubmission *submission) { ! int i; ! for(i = 0; i < submission->numItems; i++) { ! printf("%s=%s\n", ! submission->attrList[i]->key, ! submission->attrList[i]->value); } } |