# HG changeset patch # User reimar # Date 1282382309 0 # Node ID 0a895a0ce15a7bbb94ef2d9ec3907ef40e8791d8 # Parent 4a605046d5e076aa5ed12f4730b982327bcd202c Extract reading KEDB.cfg into a separate function. diff -r 4a605046d5e0 -r 0a895a0ce15a stream/stream_bd.c --- a/stream/stream_bd.c Fri Aug 20 18:19:11 2010 +0000 +++ b/stream/stream_bd.c Sat Aug 21 09:18:29 2010 +0000 @@ -131,43 +131,12 @@ return 1; } -static int bd_get_uks(struct bd_priv *bd) +static int find_vuk(struct bd_priv *bd, uint8_t discid[20]) { - unsigned char *buf; - size_t file_size; - int pos; - int i, j; - struct AVAES *a; - struct AVSHA *asha; - stream_t *file; char filename[PATH_MAX]; - uint8_t discid[20]; - char *home; + const char *home; int vukfound = 0; - - snprintf(filename, sizeof(filename), BD_UKF_PATH, bd->device); - file = open_stream(filename, NULL, NULL); - if (!file) { - mp_msg(MSGT_OPEN, MSGL_ERR, - "Cannot open file %s to get UK and DiscID\n", filename); - return 0; - } - file_size = file->end_pos; - if (file_size <= 0 || file_size > 10 * 1024* 1024) { - mp_msg(MSGT_OPEN, MSGL_ERR, "File %s too large\n", filename); - free_stream(file); - return 0; - } - buf = av_malloc(file_size); - stream_read(file, buf, file_size); - free_stream(file); - - // get discid from file - asha = av_malloc(av_sha_size); - av_sha_init(asha, 160); - av_sha_update(asha, buf, file_size); - av_sha_final(asha, discid); - av_free(asha); + stream_t *file; // look up discid in KEYDB.cfg to get VUK home = getenv("HOME"); @@ -176,10 +145,10 @@ if (!file) { mp_msg(MSGT_OPEN,MSGL_ERR, "Cannot open VUK database file %s\n", filename); - av_free(buf); return 0; } while (!stream_eof(file)) { + int i; char line[1024]; uint8_t id[20]; char d[200]; @@ -220,7 +189,46 @@ vukfound = 1; } free_stream(file); - if (!vukfound) { + return vukfound; +} + +static int bd_get_uks(struct bd_priv *bd) +{ + unsigned char *buf; + size_t file_size; + int pos; + int i, j; + struct AVAES *a; + struct AVSHA *asha; + stream_t *file; + char filename[PATH_MAX]; + uint8_t discid[20]; + + snprintf(filename, sizeof(filename), BD_UKF_PATH, bd->device); + file = open_stream(filename, NULL, NULL); + if (!file) { + mp_msg(MSGT_OPEN, MSGL_ERR, + "Cannot open file %s to get UK and DiscID\n", filename); + return 0; + } + file_size = file->end_pos; + if (file_size <= 0 || file_size > 10 * 1024* 1024) { + mp_msg(MSGT_OPEN, MSGL_ERR, "File %s too large\n", filename); + free_stream(file); + return 0; + } + buf = av_malloc(file_size); + stream_read(file, buf, file_size); + free_stream(file); + + // get discid from file + asha = av_malloc(av_sha_size); + av_sha_init(asha, 160); + av_sha_update(asha, buf, file_size); + av_sha_final(asha, discid); + av_free(asha); + + if (!find_vuk(bd, discid)) { mp_msg(MSGT_OPEN, MSGL_ERR, "No Volume Unique Key (VUK) found for this Disc: "); for (j = 0; j < 20; j++) mp_msg(MSGT_OPEN, MSGL_ERR, "%02x", discid[j]);