Mercurial > hg > xmms-sid
comparison src/xs_length.c @ 87:94497283affa
Various fixes and improvements
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 05 Oct 2003 10:38:03 +0000 |
parents | 9533b78f1a7d |
children | 2607683bc9eb |
comparison
equal
deleted
inserted
replaced
86:9533b78f1a7d | 87:94497283affa |
---|---|
196 iResult = -2; | 196 iResult = -2; |
197 } else | 197 } else |
198 iResult = -1; | 198 iResult = -1; |
199 | 199 |
200 /* Ignore and skip the possible attributes */ | 200 /* Ignore and skip the possible attributes */ |
201 while (!isspace(pcStr[*piPos])) (*piPos)++; | 201 while (pcStr[*piPos] && !isspace(pcStr[*piPos])) (*piPos)++; |
202 | 202 |
203 return iResult; | 203 return iResult; |
204 } | 204 } |
205 | 205 |
206 | 206 |
262 (guint *) &(tmpNode->md5Hash[10]), (guint *) &(tmpNode->md5Hash[11]), | 262 (guint *) &(tmpNode->md5Hash[10]), (guint *) &(tmpNode->md5Hash[11]), |
263 (guint *) &(tmpNode->md5Hash[12]), (guint *) &(tmpNode->md5Hash[13]), | 263 (guint *) &(tmpNode->md5Hash[12]), (guint *) &(tmpNode->md5Hash[13]), |
264 (guint *) &(tmpNode->md5Hash[14]), (guint *) &(tmpNode->md5Hash[15])); | 264 (guint *) &(tmpNode->md5Hash[14]), (guint *) &(tmpNode->md5Hash[15])); |
265 | 265 |
266 /* Get playtimes */ | 266 /* Get playtimes */ |
267 if (inLine[linePos] != 0) | |
268 { | |
267 if (inLine[linePos] != '=') | 269 if (inLine[linePos] != '=') |
268 { | 270 { |
269 XSERR("'=' expected in SongLengthDB file '%s' line #%d, column #%d\n", | 271 XSERR("'=' expected in SongLengthDB file '%s' line #%d, column #%d\n", |
270 dbFilename, lineNum, linePos); | 272 dbFilename, lineNum, linePos); |
271 | 273 |
292 if (iOK) | 294 if (iOK) |
293 xs_db_node_insert(tmpNode); | 295 xs_db_node_insert(tmpNode); |
294 else | 296 else |
295 xs_db_node_free(tmpNode); | 297 xs_db_node_free(tmpNode); |
296 } | 298 } |
299 } | |
297 } | 300 } |
298 } else | 301 } else |
299 if ((inLine[0] != ';') && (inLine[0] != '[')) | 302 if ((inLine[0] != ';') && (inLine[0] != '[')) |
300 { | 303 { |
301 XSERR("Invalid line in SongLengthDB file '%s' line #%d\n", | 304 XSERR("Invalid line in SongLengthDB file '%s' line #%d\n", |
450 gint rd_str(FILE *f, gchar *s, gint l) | 453 gint rd_str(FILE *f, gchar *s, gint l) |
451 { | 454 { |
452 return fread(s, sizeof(gchar), l, f); | 455 return fread(s, sizeof(gchar), l, f); |
453 } | 456 } |
454 | 457 |
458 #define MAX_MEMBUF (80*1024) | |
455 | 459 |
456 gint xs_get_sid_hash(gchar *pcFilename, t_xs_md5hash hash) | 460 gint xs_get_sid_hash(gchar *pcFilename, t_xs_md5hash hash) |
457 { | 461 { |
458 FILE *inFile; | 462 FILE *inFile; |
459 t_xs_md5state inState; | 463 t_xs_md5state inState; |
460 t_xs_psidv1_header psidH; | 464 t_xs_psidv1_header psidH; |
461 t_xs_psidv2_header psidH2; | 465 t_xs_psidv2_header psidH2; |
462 guint8 *songData, ib8[2], i8; | 466 guint8 songData[MAX_MEMBUF+1], ib8[2], i8; |
463 gint iIndex, iRes, songDataLen; | 467 gint iIndex, iRes; |
468 | |
464 | 469 |
465 /* Try to open the file */ | 470 /* Try to open the file */ |
466 if ((inFile = fopen(pcFilename, "rb")) == NULL) | 471 if ((inFile = fopen(pcFilename, "rb")) == NULL) |
467 return -1; | 472 return -1; |
468 | 473 |
493 psidH2.startPage = fgetc(inFile); | 498 psidH2.startPage = fgetc(inFile); |
494 psidH2.pageLength = fgetc(inFile); | 499 psidH2.pageLength = fgetc(inFile); |
495 psidH2.reserved = rd_be16(inFile); | 500 psidH2.reserved = rd_be16(inFile); |
496 } | 501 } |
497 | 502 |
498 /* Get data length and seek to data offset */ | |
499 fseek(inFile, 0L, SEEK_END); | |
500 songDataLen = ftell(inFile) - psidH.dataOffset; | |
501 fseek(inFile, psidH.dataOffset, SEEK_SET); | |
502 | |
503 /* Allocate memory */ | |
504 songData = (guint8 *) g_malloc(sizeof(guint8) * songDataLen); | |
505 if (songData == NULL) | |
506 { | |
507 fclose(inFile); | |
508 return -7; | |
509 } | |
510 | |
511 /* Read data to buffer */ | 503 /* Read data to buffer */ |
512 iRes = fread(songData, sizeof(guint8), songDataLen, inFile); | 504 iRes = fread(songData, sizeof(guint8), MAX_MEMBUF, inFile); |
513 fclose(inFile); | 505 fclose(inFile); |
514 | 506 |
515 if (iRes != songDataLen) | |
516 { | |
517 g_free(songData); | |
518 return -9; | |
519 } | |
520 | |
521 /* Initialize and start MD5-hash calculation */ | 507 /* Initialize and start MD5-hash calculation */ |
522 xs_md5_init(&inState); | 508 xs_md5_init(&inState); |
523 if (psidH.loadAddress == 0) | 509 if (psidH.loadAddress == 0) |
524 /* COULD SOMEONE EXPLAIN WHY DO WE NEED THIS +2 STRIP???? */ | 510 /* COULD SOMEONE EXPLAIN WHY DO WE NEED THIS +2 STRIP???? */ |
525 xs_md5_append(&inState, songData+2, iRes-2); | 511 xs_md5_append(&inState, &songData[2], iRes-2); |
526 else | 512 else |
527 xs_md5_append(&inState, songData, iRes); | 513 xs_md5_append(&inState, &songData, iRes); |
528 | 514 |
529 g_free(songData); | |
530 | |
531 /* Append header data to hash */ | 515 /* Append header data to hash */ |
532 #define XSADDHASH(QDATAB) { ib8[0] = (QDATAB & 0xff); ib8[1] = (QDATAB >> 8); xs_md5_append(&inState, (guint8 *) &ib8, sizeof(ib8)); } | 516 #define XSADDHASH(QDATAB) { ib8[0] = (QDATAB & 0xff); ib8[1] = (QDATAB >> 8); xs_md5_append(&inState, (guint8 *) &ib8, sizeof(ib8)); } |
533 | 517 |
534 XSADDHASH(psidH.initAddress) | 518 XSADDHASH(psidH.initAddress) |
535 XSADDHASH(psidH.playAddress) | 519 XSADDHASH(psidH.playAddress) |