shithub: libdvdcss

Download patch

ref: ddfe2c316e0fd6819721f5e5ddb861f5df5e6ecf
parent: 0104be9ede298780483f95736a7be2c619b766bb
author: Sam Hocevar <sam@videolan.org>
date: Tue Sep 9 06:03:48 EDT 2003

* Changed _dvdcss_error and _dvdcss_debug to print_error and print_debug
    because they aren't libdvdcss functions.


--- a/src/css.c
+++ b/src/css.c
@@ -2,7 +2,7 @@
  * css.c: Functions for DVD authentication and descrambling
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: css.c,v 1.26 2003/07/16 21:40:01 sam Exp $
+ * $Id: css.c,v 1.27 2003/09/09 10:03:48 sam Exp $
  *
  * Author: St�phane Borel <stef@via.ecp.fr>
  *         H�kan Hjort <d95hjort@dtek.chalmers.se>
@@ -111,9 +111,9 @@
     if( i_ret < 0 )
     {
         /* Since it's the first ioctl we try to issue, we add a notice */
-        _dvdcss_error( dvdcss, "css error: ioctl_ReadCopyright failed, "
-                       "make sure there is a DVD in the drive, and that "
-                       "you have used the correct device node." );
+        print_error( dvdcss, "css error: ioctl_ReadCopyright failed, "
+                     "make sure there is a DVD in the drive, and that "
+                     "you have used the correct device node." );
 
         return i_ret;
     }
@@ -143,7 +143,7 @@
     int       i_ret = -1;
     int       i;
 
-    _dvdcss_debug( dvdcss, "requesting AGID" );
+    print_debug( dvdcss, "requesting AGID" );
     i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
 
     /* We might have to reset hung authentication processes in the drive
@@ -153,7 +153,7 @@
     {
         sprintf( psz_warning,
                  "ioctl ReportAgid failed, invalidating AGID %d", i );
-        _dvdcss_debug( dvdcss, psz_warning );
+        print_debug( dvdcss, psz_warning );
 
         /* This is really _not good_, should be handled by the OS.
            Invalidating an AGID could make another process fail some
@@ -161,7 +161,7 @@
         dvdcss->css.i_agid = i;
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
 
-        _dvdcss_debug( dvdcss, "requesting AGID" );
+        print_debug( dvdcss, "requesting AGID" );
         i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
     }
 
@@ -168,7 +168,7 @@
     /* Unable to authenticate without AGID */
     if( i_ret == -1 )
     {
-        _dvdcss_error( dvdcss, "ioctl ReportAgid failed, fatal" );
+        print_error( dvdcss, "ioctl ReportAgid failed, fatal" );
         return -1;
     }
 
@@ -188,7 +188,7 @@
     if( ioctl_SendChallenge( dvdcss->i_fd,
                              &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl SendChallenge failed" );
+        print_error( dvdcss, "ioctl SendChallenge failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -196,7 +196,7 @@
     /* Get key1 from LU */
     if( ioctl_ReportKey1( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0)
     {
-        _dvdcss_error( dvdcss, "ioctl ReportKey1 failed" );
+        print_error( dvdcss, "ioctl ReportKey1 failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -215,7 +215,7 @@
         {
             snprintf( psz_warning, sizeof(psz_warning),
                       "drive authenticated, using variant %d", i );
-            _dvdcss_debug( dvdcss, psz_warning );
+            print_debug( dvdcss, psz_warning );
             i_variant = i;
             break;
         }
@@ -223,7 +223,7 @@
 
     if( i == 32 )
     {
-        _dvdcss_error( dvdcss, "drive would not authenticate" );
+        print_error( dvdcss, "drive would not authenticate" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -232,7 +232,7 @@
     if( ioctl_ReportChallenge( dvdcss->i_fd,
                                &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl ReportKeyChallenge failed" );
+        print_error( dvdcss, "ioctl ReportKeyChallenge failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -254,13 +254,13 @@
     /* Send key2 to LU */
     if( ioctl_SendKey2( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl SendKey2 failed" );
+        print_error( dvdcss, "ioctl SendKey2 failed" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
 
     /* The drive has accepted us as authentic. */
-    _dvdcss_debug( dvdcss, "authentication established" );
+    print_debug( dvdcss, "authentication established" );
 
     memcpy( p_challenge, p_key1, KEY_SIZE );
     memcpy( p_challenge + KEY_SIZE, p_key2, KEY_SIZE );
@@ -279,7 +279,7 @@
 
     sprintf( psz_output, "%s%02x:%02x:%02x:%02x:%02x", prefix,
              data[0], data[1], data[2], data[3], data[4] );
-    _dvdcss_debug( dvdcss, psz_output );
+    print_debug( dvdcss, psz_output );
 }
 
 /*****************************************************************************
@@ -329,7 +329,7 @@
         {
             if( read( i_fd, p_title_key, 5 ) == 5 )
             {
-                _dvdcss_debug( dvdcss, "key found in cache" );
+                print_debug( dvdcss, "key found in cache" );
                 /* Don't try to save it again */
                 b_cache = 0;
                 i_ret = 1;
@@ -345,13 +345,13 @@
 
         if( i_ret < 0 )
         {
-            _dvdcss_error( dvdcss, "fatal error in vts css key" );
+            print_error( dvdcss, "fatal error in vts css key" );
             return i_ret;
         }
 
         if( i_ret == 0 )
         {
-            _dvdcss_debug( dvdcss, "unencrypted title" );
+            print_debug( dvdcss, "unencrypted title" );
             /* We cache this anyway, so we don't need to check again. */
         }
     }
@@ -425,7 +425,7 @@
     /* Get encrypted disc key */
     if( ioctl_ReadDiscKey( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
     {
-        _dvdcss_error( dvdcss, "ioctl ReadDiscKey failed" );
+        print_error( dvdcss, "ioctl ReadDiscKey failed" );
         return -1;
     }
 
@@ -433,8 +433,8 @@
     if( GetASF( dvdcss ) != 1 )
     {
         /* Region mismatch (or region not set) is the most likely source. */
-        _dvdcss_error( dvdcss,
-                       "ASF not 1 after reading disc key (region mismatch?)" );
+        print_error( dvdcss,
+                     "ASF not 1 after reading disc key (region mismatch?)" );
         ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
         return -1;
     }
@@ -450,15 +450,15 @@
         case DVDCSS_METHOD_KEY:
 
             /* Decrypt disc key with player key. */
-            _dvdcss_debug( dvdcss, "decrypting disc key with player keys" );
+            print_debug( dvdcss, "decrypting disc key with player keys" );
             if( ! DecryptDiscKey( p_buffer, p_disc_key ) )
             {
                 PrintKey( dvdcss, "decrypted disc key is ", p_disc_key );
                 break;
             }
-            _dvdcss_debug( dvdcss, "failed to decrypt the disc key, "
-                                   "faulty drive/kernel? "
-                                   "cracking title keys instead" );
+            print_debug( dvdcss, "failed to decrypt the disc key, "
+                                 "faulty drive/kernel? "
+                                 "cracking title keys instead" );
 
             /* Fallback, but not to DISC as the disc key might be faulty */
             dvdcss->i_method = DVDCSS_METHOD_TITLE;
@@ -467,8 +467,8 @@
         case DVDCSS_METHOD_DISC:
 
             /* Crack Disc key to be able to use it */
-            _dvdcss_debug( dvdcss, "cracking disc key from key hash ..."
-                                   " this will take some time" );
+            print_debug( dvdcss, "cracking disc key from key hash ..."
+                                 " this will take some time" );
             memcpy( p_disc_key, p_buffer, KEY_SIZE );
             if( ! CrackDiscKey( dvdcss, p_disc_key ) )
             {
@@ -475,7 +475,7 @@
                 PrintKey( dvdcss, "cracked disc key is ", p_disc_key );
                 break;
             }
-            _dvdcss_debug( dvdcss, "failed to crack the disc key" );
+            print_debug( dvdcss, "failed to crack the disc key" );
             memset( p_disc_key, 0, KEY_SIZE );
             dvdcss->i_method = DVDCSS_METHOD_TITLE;
             break;
@@ -482,7 +482,7 @@
 
         default:
 
-            _dvdcss_debug( dvdcss, "disc key needs not be decrypted" );
+            print_debug( dvdcss, "disc key needs not be decrypted" );
             memset( p_disc_key, 0, KEY_SIZE );
             break;
     }
@@ -509,7 +509,7 @@
          * read the title key and decrypt it.
          */
 
-        _dvdcss_debug( dvdcss, "getting title key the classic way" );
+        print_debug( dvdcss, "getting title key the classic way" );
 
         /* We need to authenticate again every time to get a new session key */
         if( GetBusKey( dvdcss ) < 0 )
@@ -521,8 +521,8 @@
         if( ioctl_ReadTitleKey( dvdcss->i_fd, &dvdcss->css.i_agid,
                                 i_pos, p_key ) < 0 )
         {
-            _dvdcss_debug( dvdcss,
-                           "ioctl ReadTitleKey failed (region mismatch?)" );
+            print_debug( dvdcss,
+                         "ioctl ReadTitleKey failed (region mismatch?)" );
             i_ret = -1;
         }
 
@@ -531,7 +531,7 @@
         {
             case -1:
                 /* An error getting the ASF status, something must be wrong. */
-                _dvdcss_debug( dvdcss, "lost ASF requesting title key" );
+                print_debug( dvdcss, "lost ASF requesting title key" );
                 ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
                 i_ret = -1;
                 break;
@@ -539,7 +539,7 @@
             case 0:
                 /* This might either be a title that has no key,
                  * or we encountered a region error. */
-                _dvdcss_debug( dvdcss, "lost ASF requesting title key" );
+                print_debug( dvdcss, "lost ASF requesting title key" );
                 break;
 
             case 1:
@@ -582,7 +582,7 @@
         }
 
         /* The title key request failed */
-        _dvdcss_debug( dvdcss, "resetting drive and cracking title key" );
+        print_debug( dvdcss, "resetting drive and cracking title key" );
 
         /* Read an unscrambled sector and reset the drive */
         dvdcss->pf_seek( dvdcss, 0 );
@@ -666,17 +666,17 @@
     if( ioctl_ReportASF( dvdcss->i_fd, NULL, &i_asf ) != 0 )
     {
         /* The ioctl process has failed */
-        _dvdcss_error( dvdcss, "GetASF fatal error" );
+        print_error( dvdcss, "GetASF fatal error" );
         return -1;
     }
 
     if( i_asf )
     {
-        _dvdcss_debug( dvdcss, "GetASF authenticated, ASF=1" );
+        print_debug( dvdcss, "GetASF authenticated, ASF=1" );
     }
     else
     {
-        _dvdcss_debug( dvdcss, "GetASF not authenticated, ASF=0" );
+        print_debug( dvdcss, "GetASF not authenticated, ASF=0" );
     }
 
     return i_asf;
@@ -1081,7 +1081,7 @@
     unsigned int*  BigTable;    /* LFSR2 startstate indexed by
                                  * 1,2,5 output byte */
 
-    _dvdcss_debug( dvdcss, "cracking disc key" );
+    print_debug( dvdcss, "cracking disc key" );
 
     /*
      * Prepare tables for hash reversal
@@ -1109,7 +1109,7 @@
 /*
             if( tmp4 == K1TABLEWIDTH )
             {
-                _dvdcss_debug( dvdcss, "Table disaster %d", tmp4 );
+                print_debug( dvdcss, "Table disaster %d", tmp4 );
             }
 */
             if( tmp4 < K1TABLEWIDTH )
@@ -1130,7 +1130,7 @@
 
     tmp3 = 0;
 
-    _dvdcss_debug( dvdcss, "initializing the big table" );
+    print_debug( dvdcss, "initializing the big table" );
 
     for( i = 0 ; i < 16777216 ; i++ )
     {
@@ -1413,7 +1413,7 @@
     int b_read_error = 0;
     int i_ret;
 
-    _dvdcss_debug( dvdcss, "cracking title key" );
+    print_debug( dvdcss, "cracking title key" );
 
     i_tries = 0;
     i_success = 0;
@@ -1424,7 +1424,7 @@
 
         if( i_ret != i_pos )
         {
-            _dvdcss_error( dvdcss, "seek failed" );
+            print_error( dvdcss, "seek failed" );
         }
 
         i_ret = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
@@ -1435,12 +1435,12 @@
         {
             if( i_ret == 0 )
             {
-                _dvdcss_debug( dvdcss, "read returned 0 (end of device?)" );
+                print_debug( dvdcss, "read returned 0 (end of device?)" );
             }
             else if( !b_read_error )
             {
-                _dvdcss_debug( dvdcss, "read error, resorting to secret "
-                                       "arcanes to recover" );
+                print_debug( dvdcss, "read error, resorting to secret "
+                                     "arcanes to recover" );
 
                 /* Reset the drive before trying to continue */
                 _dvdcss_close( dvdcss );
@@ -1457,12 +1457,12 @@
          * For now, allow all blocks that begin with a start code. */
         if( memcmp( p_buf, p_packstart, 3 ) )
         {
-            _dvdcss_debug( dvdcss, "non MPEG block found (end of title)" );
+            print_debug( dvdcss, "non MPEG block found (end of title)" );
             break;
         }
 
         if( p_buf[0x0d] & 0x07 )
-            _dvdcss_debug( dvdcss, "stuffing in pack header" );
+            print_debug( dvdcss, "stuffing in pack header" );
 
         /* PES_scrambling_control does not exist in a system_header,
          * a padding_stream or a private_stream2 (and others?). */
@@ -1491,7 +1491,7 @@
         /* Emit a progress indication now and then. */
         if( !( i_reads & 0xfff ) )
         {
-            _dvdcss_debug( dvdcss, "still cracking..." );
+            print_debug( dvdcss, "still cracking..." );
         }
 
         /* Stop after 2000 blocks if we haven't seen any encrypted blocks. */
@@ -1501,7 +1501,7 @@
 
     if( !b_stop_scanning )
     {
-        _dvdcss_debug( dvdcss, "end of title reached" );
+        print_debug( dvdcss, "end of title reached" );
     }
 
     { /* Print some statistics. */
@@ -1509,12 +1509,12 @@
         snprintf( psz_info, sizeof(psz_info),
                   "%d of %d attempts successful, %d of %d blocks scrambled",
                   i_success, i_tries, i_encrypted, i_reads );
-        _dvdcss_debug( dvdcss, psz_info );
+        print_debug( dvdcss, psz_info );
     }
 
     if( i_success > 0 /* b_stop_scanning */ )
     {
-        _dvdcss_debug( dvdcss, "vts key initialized" );
+        print_debug( dvdcss, "vts key initialized" );
         return 1;
     }
 
@@ -1521,7 +1521,7 @@
     if( i_encrypted == 0 && i_reads > 0 )
     {
         memset( p_titlekey, 0, KEY_SIZE );
-        _dvdcss_debug( dvdcss, "file was unscrambled" );
+        print_debug( dvdcss, "file was unscrambled" );
         return 0;
     }
 
--- a/src/device.c
+++ b/src/device.c
@@ -2,7 +2,7 @@
  * device.h: DVD device access
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: device.c,v 1.16 2003/07/08 18:00:54 gbazin Exp $
+ * $Id: device.c,v 1.17 2003/09/09 10:03:48 sam Exp $
  *
  * Authors: St�phane Borel <stef@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -140,7 +140,7 @@
 
     snprintf( psz_debug, 199, "opening target `%s'", psz_device );
     psz_debug[199] = '\0';
-    _dvdcss_debug( dvdcss, psz_debug );
+    print_debug( dvdcss, psz_debug );
 
 #if defined( WIN32 )
     /* If device is not "X:", we are actually opening a file. */
@@ -152,7 +152,7 @@
 
     if( !dvdcss->b_file && WIN2K )
     {
-        _dvdcss_debug( dvdcss, "using Win2K API for access" );
+        print_debug( dvdcss, "using Win2K API for access" );
         dvdcss->pf_seek  = win2k_seek;
         dvdcss->pf_read  = win2k_read;
         dvdcss->pf_readv = win_readv;
@@ -160,7 +160,7 @@
     }
     else if( !dvdcss->b_file )
     {
-        _dvdcss_debug( dvdcss, "using ASPI for access" );
+        print_debug( dvdcss, "using ASPI for access" );
         dvdcss->pf_seek  = aspi_seek;
         dvdcss->pf_read  = aspi_read;
         dvdcss->pf_readv = win_readv;
@@ -169,7 +169,7 @@
     else
 #endif
     {
-        _dvdcss_debug( dvdcss, "using libc for access" );
+        print_debug( dvdcss, "using libc for access" );
         dvdcss->pf_seek  = libc_seek;
         dvdcss->pf_read  = libc_read;
         dvdcss->pf_readv = libc_readv;
@@ -184,7 +184,7 @@
 
     if( dvdcss->i_raw_fd == -1 )
     {
-        _dvdcss_error( dvdcss, "failed opening raw device, continuing" );
+        print_error( dvdcss, "failed opening raw device, continuing" );
         return -1;
     }
     else
@@ -253,7 +253,7 @@
 
     if( dvdcss->i_fd == -1 )
     {
-        _dvdcss_error( dvdcss, "failed opening device" );
+        print_error( dvdcss, "failed opening device" );
         return -1;
     }
 
@@ -290,7 +290,7 @@
 
     if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
     {
-        _dvdcss_error( dvdcss, "failed opening device" );
+        print_error( dvdcss, "failed opening device" );
         return -1;
     }
 
@@ -313,7 +313,7 @@
     hASPI = LoadLibrary( "wnaspi32.dll" );
     if( hASPI == NULL )
     {
-        _dvdcss_error( dvdcss, "unable to load wnaspi32.dll" );
+        print_error( dvdcss, "unable to load wnaspi32.dll" );
         return -1;
     }
 
@@ -322,7 +322,7 @@
 
     if(lpGetSupport == NULL || lpSendCommand == NULL )
     {
-        _dvdcss_error( dvdcss, "unable to get aspi function pointers" );
+        print_error( dvdcss, "unable to get aspi function pointers" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -331,7 +331,7 @@
 
     if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
     {
-        _dvdcss_error( dvdcss, "no ASPI adapters found" );
+        print_error( dvdcss, "no ASPI adapters found" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -338,7 +338,7 @@
 
     if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
     {
-        _dvdcss_error( dvdcss, "unable to initalize aspi layer" );
+        print_error( dvdcss, "unable to initalize aspi layer" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -346,7 +346,7 @@
     i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
     if( i_hostadapters == 0 )
     {
-        _dvdcss_error( dvdcss, "no ASPI adapters ready" );
+        print_error( dvdcss, "no ASPI adapters ready" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -354,7 +354,7 @@
     fd = malloc( sizeof( struct w32_aspidev ) );
     if( fd == NULL )
     {
-        _dvdcss_error( dvdcss, "not enough memory" );
+        print_error( dvdcss, "not enough memory" );
         FreeLibrary( hASPI );
         return -1;
     }
@@ -405,7 +405,7 @@
                 {
                     free( (void*) fd );
                     FreeLibrary( hASPI );
-                    _dvdcss_error( dvdcss,"this is not a cdrom drive" );
+                    print_error( dvdcss,"this is not a cdrom drive" );
                     return -1;
                 }
             }
@@ -414,7 +414,7 @@
 
     free( (void*) fd );
     FreeLibrary( hASPI );
-    _dvdcss_error( dvdcss, "unable to get haid and target (aspi)" );
+    print_error( dvdcss, "unable to get haid and target (aspi)" );
     return -1;
 }
 #endif
@@ -437,7 +437,7 @@
 
     if( i_seek < 0 )
     {
-        _dvdcss_error( dvdcss, "seek error" );
+        print_error( dvdcss, "seek error" );
         dvdcss->i_pos = -1;
         return i_seek;
     }
@@ -521,7 +521,7 @@
 
     if( i_ret < 0 )
     {
-        _dvdcss_error( dvdcss, "read error" );
+        print_error( dvdcss, "read error" );
         dvdcss->i_pos = -1;
         return i_ret;
     }
@@ -670,7 +670,7 @@
         dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
         if( !dvdcss->p_readv_buffer )
         {
-            _dvdcss_error( dvdcss, " failed (readv)" );
+            print_error( dvdcss, " failed (readv)" );
             dvdcss->i_pos = -1;
             return -1;
         }
--- a/src/error.c
+++ b/src/error.c
@@ -2,7 +2,7 @@
  * error.c: error management functions
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: error.c,v 1.7 2003/03/09 23:34:18 gbazin Exp $
+ * $Id: error.c,v 1.8 2003/09/09 10:03:48 sam Exp $
  *
  * Author: Samuel Hocevar <sam@zoy.org>
  *
@@ -43,7 +43,7 @@
 /*****************************************************************************
  * Error messages
  *****************************************************************************/
-void _dvdcss_error( dvdcss_t dvdcss, char *psz_string )
+void _print_error( dvdcss_t dvdcss, char *psz_string )
 {
     if( dvdcss->b_errors )
     {
@@ -56,7 +56,8 @@
 /*****************************************************************************
  * Debug messages
  *****************************************************************************/
-void _dvdcss_debug( dvdcss_t dvdcss, char *psz_string )
+#if 0
+void _print_debug( dvdcss_t dvdcss, char *psz_string )
 {
     if( dvdcss->b_debug )
     {
@@ -63,4 +64,5 @@
         fprintf( stderr, "libdvdcss debug: %s\n", psz_string );
     }
 }
+#endif
 
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -5,7 +5,7 @@
  *          H�kan Hjort <d95hjort@dtek.chalmers.se>
  *
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: libdvdcss.c,v 1.33 2003/06/18 17:23:55 sam Exp $
+ * $Id: libdvdcss.c,v 1.34 2003/09/09 10:03:48 sam Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -225,8 +225,8 @@
         }
         else
         {
-            _dvdcss_error( dvdcss, "unknown decrypt method, please choose "
-                                   "from 'title', 'key' or 'disc'" );
+            print_error( dvdcss, "unknown decrypt method, please choose "
+                                 "from 'title', 'key' or 'disc'" );
             free( dvdcss->psz_device );
             free( dvdcss );
             return NULL;
@@ -321,7 +321,7 @@
         /* Check that we can add the ID directory and the block filename */
         else if( strlen( psz_cache ) + 1 + 32 + 1 + 10 + 1 > PATH_MAX )
         {
-            _dvdcss_error( dvdcss, "cache directory name is too long" );
+            print_error( dvdcss, "cache directory name is too long" );
             psz_cache = NULL;
         }
     }
@@ -346,14 +346,14 @@
         if( i_ret < 0 )
         {
             /* Disable the CSS ioctls and hope that it works? */
-            _dvdcss_debug( dvdcss,
-                           "could not check whether the disc was scrambled" );
+            print_debug( dvdcss,
+                         "could not check whether the disc was scrambled" );
             dvdcss->b_ioctls = 0;
         }
         else
         {
-            _dvdcss_debug( dvdcss, i_ret ? "disc is scrambled"
-                                         : "disc is unscrambled" );
+            print_debug( dvdcss, i_ret ? "disc is scrambled"
+                                       : "disc is unscrambled" );
             dvdcss->b_scrambled = i_ret;
         }
     }
@@ -461,7 +461,7 @@
 #endif
         if( i_ret < 0 && errno != EEXIST )
         {
-            _dvdcss_error( dvdcss, "failed creating cache directory" );
+            print_error( dvdcss, "failed creating cache directory" );
             dvdcss->psz_cachefile[0] = '\0';
             goto nocache;
         }
@@ -475,7 +475,7 @@
 #endif
         if( i_ret < 0 && errno != EEXIST )
         {
-            _dvdcss_error( dvdcss, "failed creating cache subdirectory" );
+            print_error( dvdcss, "failed creating cache subdirectory" );
             dvdcss->psz_cachefile[0] = '\0';
             goto nocache;
         }
@@ -486,7 +486,7 @@
 
         sprintf( psz_debug, "using CSS key cache dir: %s",
                             dvdcss->psz_cachefile );
-        _dvdcss_debug( dvdcss, psz_debug );
+        print_debug( dvdcss, psz_debug );
     }
     nocache:
 
@@ -606,7 +606,7 @@
         {
             if( ((uint8_t*)p_buffer)[0x14] & 0x30 )
             {
-                _dvdcss_error( dvdcss, "no key but found encrypted block" );
+                print_error( dvdcss, "no key but found encrypted block" );
                 /* Only return the initial range of unscrambled blocks? */
                 /* or fail completely? return 0; */
                 break;
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -2,7 +2,7 @@
  * libdvdcss.h: private DVD reading library data
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.h,v 1.9 2002/12/19 15:36:04 sam Exp $
+ * $Id: libdvdcss.h,v 1.10 2003/09/09 10:03:48 sam Exp $
  *
  * Authors: St�phane Borel <stef@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -77,6 +77,14 @@
 /*****************************************************************************
  * Functions used across the library
  *****************************************************************************/
-void _dvdcss_error ( dvdcss_t, char * );
-void _dvdcss_debug ( dvdcss_t, char * );
+#define print_error(dvdcss,msg) _print_error(dvdcss,msg)
+#define print_debug(dvdcss,msg,args...) \
+    if( dvdcss->b_debug ) \
+    { \
+        fprintf( stderr, "libdvdcss debug: " ); \
+        fprintf( stderr, msg, ##args ); \
+        fprintf( stderr, "\n" ); \
+    }
+
+void _print_error ( dvdcss_t, char * );