Diff of /src/libdvdcss.c [688738] .. [d5e287] Maximize Restore

  Switch to unified view

a/src/libdvdcss.c b/src/libdvdcss.c
...
...
3
 * Authors: Stéphane Borel <stef@via.ecp.fr>
3
 * Authors: Stéphane Borel <stef@via.ecp.fr>
4
 *          Samuel Hocevar <sam@zoy.org>
4
 *          Samuel Hocevar <sam@zoy.org>
5
 *          Hĺkan Hjort <d95hjort@dtek.chalmers.se>
5
 *          Hĺkan Hjort <d95hjort@dtek.chalmers.se>
6
 *
6
 *
7
 * Copyright (C) 1998-2002 VideoLAN
7
 * Copyright (C) 1998-2002 VideoLAN
8
 * $Id: libdvdcss.c,v 1.35 2003/09/15 17:12:46 sam Exp $
8
 * $Id$
9
 *
9
 *
10
 * This program is free software; you can redistribute it and/or modify
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
13
 * (at your option) any later version.
...
...
317
        if( psz_cache[0] == '\0' || !strcmp( psz_cache, "off" ) )
317
        if( psz_cache[0] == '\0' || !strcmp( psz_cache, "off" ) )
318
        {
318
        {
319
            psz_cache = NULL;
319
            psz_cache = NULL;
320
        }
320
        }
321
        /* Check that we can add the ID directory and the block filename */
321
        /* Check that we can add the ID directory and the block filename */
322
        else if( strlen( psz_cache ) + 1 + 32 + 1 + 10 + 1 > PATH_MAX )
322
        else if( strlen( psz_cache ) + 1 + 32 + 1 + (KEY_SIZE * 2) + 10 + 1
323
                  > PATH_MAX )
323
        {
324
        {
324
            print_error( dvdcss, "cache directory name is too long" );
325
            print_error( dvdcss, "cache directory name is too long" );
325
            psz_cache = NULL;
326
            psz_cache = NULL;
326
        }
327
        }
327
    }
328
    }
...
...
375
    /* If the cache is enabled, extract a unique disc ID */
376
    /* If the cache is enabled, extract a unique disc ID */
376
    if( psz_cache )
377
    if( psz_cache )
377
    {
378
    {
378
        uint8_t p_sector[DVDCSS_BLOCK_SIZE];
379
        uint8_t p_sector[DVDCSS_BLOCK_SIZE];
379
        unsigned char   psz_debug[PATH_MAX+30];
380
        unsigned char   psz_debug[PATH_MAX+30];
381
        unsigned char   psz_key[1 + KEY_SIZE * 2 + 1];
380
        unsigned char * psz_title, * psz_serial;
382
        unsigned char * psz_title, * psz_serial;
381
        int i;
383
        int i;
382
384
383
        /* We read sector 0. If it starts with 0x000001ba (BE), we are
385
        /* We read sector 0. If it starts with 0x000001ba (BE), we are
384
         * reading a VOB file, and we should not cache anything. */
386
         * reading a VOB file, and we should not cache anything. */
...
...
441
        /* Check that all characters are digits, otherwise convert. */
443
        /* Check that all characters are digits, otherwise convert. */
442
        for( i = 0 ; i < 16 ; i++ )
444
        for( i = 0 ; i < 16 ; i++ )
443
        {
445
        {
444
            if( psz_serial[i] < '0' || psz_serial[i] > '9' )
446
            if( psz_serial[i] < '0' || psz_serial[i] > '9' )
445
            {
447
            {
448
                char psz_tmp[16 + 1];
446
                sprintf( psz_serial,
449
                sprintf( psz_tmp,
447
                         "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X",
450
                         "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
448
                         psz_serial[0], psz_serial[1], psz_serial[2],
451
                         psz_serial[0], psz_serial[1], psz_serial[2],
449
                         psz_serial[3], psz_serial[4], psz_serial[5],
452
                         psz_serial[3], psz_serial[4], psz_serial[5],
450
                         psz_serial[6], psz_serial[7] );
453
                         psz_serial[6], psz_serial[7] );
454
                memcpy( psz_serial, psz_tmp, 16 );
451
                break;
455
                break;
452
            }
456
            }
457
        }
458
459
        /* Get disk key, since some discs have got same title, manufacturing
460
         * date and serial number, but different keys */
461
        if( dvdcss->b_scrambled )
462
        {
463
             psz_key[0] = '-';
464
             for( i = 0; i < KEY_SIZE; i++ )
465
             {
466
                 sprintf( &psz_key[1+i*2], "%.2x", dvdcss->css.p_disc_key[i] );
467
             }
468
             psz_key[1 + KEY_SIZE * 2] = '\0';
469
        }
470
        else
471
        {
472
             psz_key[0] = 0;
453
        }
473
        }
454
474
455
        /* We have a disc name or ID, we can create the cache dir */
475
        /* We have a disc name or ID, we can create the cache dir */
456
        i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache );
476
        i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache );
457
#if !defined( WIN32 ) || defined( SYS_CYGWIN )
477
#if !defined( WIN32 ) || defined( SYS_CYGWIN )
...
...
464
            print_error( dvdcss, "failed creating cache directory" );
484
            print_error( dvdcss, "failed creating cache directory" );
465
            dvdcss->psz_cachefile[0] = '\0';
485
            dvdcss->psz_cachefile[0] = '\0';
466
            goto nocache;
486
            goto nocache;
467
        }
487
        }
468
488
469
        i += sprintf( dvdcss->psz_cachefile + i, "/%s#%s", psz_title,
489
        i += sprintf( dvdcss->psz_cachefile + i, "/%s-%s%s", psz_title,
470
                      psz_serial );
490
                      psz_serial, psz_key );
471
#if !defined( WIN32 ) || defined( SYS_CYGWIN )
491
#if !defined( WIN32 ) || defined( SYS_CYGWIN )
472
        i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
492
        i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
473
#else
493
#else
474
        i_ret = mkdir( dvdcss->psz_cachefile );
494
        i_ret = mkdir( dvdcss->psz_cachefile );
475
#endif
495
#endif