$OpenBSD: patch-dvdread_dvd_input_c,v 1.8 2008/07/24 09:37:26 jakemsr Exp $
--- dvdread/dvd_input.c.orig	Mon Sep 19 06:43:08 2005
+++ dvdread/dvd_input.c	Thu Jul 17 23:43:16 2008
@@ -45,30 +45,30 @@ int         (*dvdinput_read)  (dvd_input_t, void *, in
 char *      (*dvdinput_error) (dvd_input_t);
 
 #ifdef HAVE_DVDCSS_DVDCSS_H
-/* linking to libdvdcss */
-#include <dvdcss/dvdcss.h>
-#define DVDcss_open(a) dvdcss_open((char*)(a))
-#define DVDcss_close   dvdcss_close
-#define DVDcss_seek    dvdcss_seek
-#define DVDcss_title   dvdcss_title
-#define DVDcss_read    dvdcss_read
-#define DVDcss_error   dvdcss_error
+/* linking to dvdcss */
+#include <libdvd/libdvd.h>
+#define DVD_open(a) libdvd_open((char*)(a))
+#define DVD_close   libdvd_close
+#define DVD_seek    libdvd_seek
+#define DVD_title   libdvd_title
+#define DVD_read    libdvd_read
+#define DVD_error   libdvd_error
 #else
-/* dlopening libdvdcss */
+/* dlopening dvdcss */
 #include <dlfcn.h>
-typedef struct dvdcss_s *dvdcss_handle;
-static dvdcss_handle (*DVDcss_open)  (const char *);
-static int           (*DVDcss_close) (dvdcss_handle);
-static int           (*DVDcss_seek)  (dvdcss_handle, int, int);
-static int           (*DVDcss_title) (dvdcss_handle, int); 
-static int           (*DVDcss_read)  (dvdcss_handle, void *, int, int);
-static char *        (*DVDcss_error) (dvdcss_handle);
+typedef struct libdvd_s *libdvd_handle;
+static libdvd_handle (*DVD_open)  (const char *);
+static int           (*DVD_close) (libdvd_handle);
+static int           (*DVD_seek)  (libdvd_handle, int, int);
+static int           (*DVD_title) (libdvd_handle, int); 
+static int           (*DVD_read)  (libdvd_handle, void *, int, int);
+static char *        (*DVD_error) (libdvd_handle);
 #endif
 
 /* The DVDinput handle, add stuff here for new input methods. */
 struct dvd_input_s {
-  /* libdvdcss handle */
-  dvdcss_handle dvdcss;
+  /* dvdcss handle */
+  libdvd_handle libdvd;
   
   /* dummy file input */
   int fd;
@@ -78,7 +78,7 @@ struct dvd_input_s {
 /**
  * initialize and open a DVD device or file.
  */
-static dvd_input_t css_open(const char *target)
+static dvd_input_t libdvd_open(const char *target)
 {
   dvd_input_t dev;
     
@@ -89,9 +89,9 @@ static dvd_input_t css_open(const char *target)
     return NULL;
   }
   
-  /* Really open it with libdvdcss */
-  dev->dvdcss = DVDcss_open(target);
-  if(dev->dvdcss == 0) {
+  /* Really open it with dvdcss */
+  dev->libdvd = DVD_open(target);
+  if(dev->libdvd == 0) {
     free(dev);
     dev = NULL;
   }
@@ -102,44 +102,44 @@ static dvd_input_t css_open(const char *target)
 /**
  * return the last error message
  */
-static char *css_error(dvd_input_t dev)
+static char *libdvd_error(dvd_input_t dev)
 {
-  return DVDcss_error(dev->dvdcss);
+  return DVD_error(dev->libdvd);
 }
 
 /**
  * seek into the device.
  */
-static int css_seek(dvd_input_t dev, int blocks)
+static int libdvd_seek(dvd_input_t dev, int blocks)
 {
   /* DVDINPUT_NOFLAGS should match the DVDCSS_NOFLAGS value. */
-  return DVDcss_seek(dev->dvdcss, blocks, DVDINPUT_NOFLAGS);
+  return DVD_seek(dev->libdvd, blocks, DVDINPUT_NOFLAGS);
 }
 
 /**
  * set the block for the begining of a new title (key).
  */
-static int css_title(dvd_input_t dev, int block)
+static int libdvd_title(dvd_input_t dev, int block)
 {
-  return DVDcss_title(dev->dvdcss, block);
+  return DVD_title(dev->libdvd, block);
 }
 
 /**
  * read data from the device.
  */
-static int css_read(dvd_input_t dev, void *buffer, int blocks, int flags)
+static int libdvd_read(dvd_input_t dev, void *buffer, int blocks, int flags)
 {
-  return DVDcss_read(dev->dvdcss, buffer, blocks, flags);
+  return DVD_read(dev->libdvd, buffer, blocks, flags);
 }
 
 /**
  * close the DVD device and clean up the library.
  */
-static int css_close(dvd_input_t dev)
+static int libdvd_close(dvd_input_t dev)
 {
   int ret;
 
-  ret = DVDcss_close(dev->dvdcss);
+  ret = DVD_close(dev->libdvd);
 
   if(ret < 0)
     return ret;
@@ -280,8 +280,8 @@ static int file_close(dvd_input_t dev)
 }
 
 
-static void *dvdcss_library = NULL;
-static int dvdcss_library_init = 0;
+static void *libdvd_library = NULL;
+static int libdvd_library_init = 0;
 
 /**
  * Free any objects allocated by dvdinput_setup.
@@ -294,28 +294,36 @@ void dvdinput_free(void)
   /* linked statically, nothing to free */
   return;
 #else
-  if(dvdcss_library) {
-    dlclose(dvdcss_library);
-    dvdcss_library = NULL;
+  if(libdvd_library) {
+    dlclose(libdvd_library);
+    libdvd_library = NULL;
   }
-  dvdcss_library_init = 0;
+  libdvd_library_init = 0;
   return;
 #endif
 }
 
 
+#if defined(DEBUG_CSS)
+#define LIBDVDNAME	"libdvdcss.so.2"
+#define LIBDVD_		"dvdcss_"
+#else
+#define LIBDVDNAME	"libdvd.so.0"
+#define LIBDVD_		"libdvd_"
+#endif
+
 /**
- * Setup read functions with either libdvdcss or minimal DVD access.
+ * Setup read functions with either libdvd or minimal DVD access.
  */
 int dvdinput_setup(void)
 {
-  char **dvdcss_version = NULL;
+  char **libdvd_version = NULL;
   int verbose;
 
   /* dlopening libdvdcss */
-  if(dvdcss_library_init) {
+  if(libdvd_library_init) {
     /* libdvdcss is already dlopened, function ptrs set */
-    if(dvdcss_library) {
+    if(libdvd_library) {
       return 1; /* css available */
     } else {
       return 0; /* css not available */
@@ -326,59 +334,57 @@ int dvdinput_setup(void)
   
 #ifdef HAVE_DVDCSS_DVDCSS_H
   /* linking to libdvdcss */
-  dvdcss_library = &dvdcss_library;  /* Give it some value != NULL */
+  libdvd_library = &libdvd_library;  /* Give it some value != NULL */
   /* the DVDcss_* functions have been #defined at the top */
-  dvdcss_version = &dvdcss_interface_2;
+  libdvd_version = &libdvd_interface_2;
 
 #else
 
-  dvdcss_library = dlopen("libdvdcss.so.2", RTLD_LAZY);
+  libdvd_library = dlopen(LIBDVDNAME, RTLD_LAZY);
 
-  if(dvdcss_library != NULL) {
+  if(libdvd_library != NULL) {
 #if defined(__OpenBSD__) && !defined(__ELF__)
 #define U_S "_"
 #else
 #define U_S
 #endif
-    DVDcss_open = (dvdcss_handle (*)(const char*))
-      dlsym(dvdcss_library, U_S "dvdcss_open");
-    DVDcss_close = (int (*)(dvdcss_handle))
-      dlsym(dvdcss_library, U_S "dvdcss_close");
-    DVDcss_title = (int (*)(dvdcss_handle, int))
-      dlsym(dvdcss_library, U_S "dvdcss_title");
-    DVDcss_seek = (int (*)(dvdcss_handle, int, int))
-      dlsym(dvdcss_library, U_S "dvdcss_seek");
-    DVDcss_read = (int (*)(dvdcss_handle, void*, int, int))
-      dlsym(dvdcss_library, U_S "dvdcss_read");
-    DVDcss_error = (char* (*)(dvdcss_handle))
-      dlsym(dvdcss_library, U_S "dvdcss_error");
+    DVD_open = (libdvd_handle (*)(const char*))
+      dlsym(libdvd_library, U_S LIBDVD_"open");
+    DVD_close = (int (*)(libdvd_handle))
+      dlsym(libdvd_library, U_S LIBDVD_"close");
+    DVD_title = (int (*)(libdvd_handle, int))
+      dlsym(libdvd_library, U_S LIBDVD_"title");
+    DVD_seek = (int (*)(libdvd_handle, int, int))
+      dlsym(libdvd_library, U_S LIBDVD_"seek");
+    DVD_read = (int (*)(libdvd_handle, void*, int, int))
+      dlsym(libdvd_library, U_S LIBDVD_"read");
+    DVD_error = (char* (*)(libdvd_handle))
+      dlsym(libdvd_library, U_S LIBDVD_"error");
     
-    dvdcss_version = (char **)dlsym(dvdcss_library, U_S "dvdcss_interface_2");
+    libdvd_version = (char **)dlsym(libdvd_library, U_S LIBDVD_"interface_2");
 
-    if(dlsym(dvdcss_library, U_S "dvdcss_crack")) {
+    if(dlsym(libdvd_library, U_S "dvdcss_crack")) {
       if(verbose >= 0) {
         fprintf(stderr, 
-                "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n"
-                "libdvdread: You should get the latest version from "
-                "http://www.videolan.org/\n" );
+                "libdvdread: Old (pre-0.0.2) version of libdvdcss found.\n");
       }
-      dlclose(dvdcss_library);
-      dvdcss_library = NULL;
-    } else if(!DVDcss_open  || !DVDcss_close || !DVDcss_title || !DVDcss_seek
-              || !DVDcss_read || !DVDcss_error || !dvdcss_version) {
+      dlclose(libdvd_library);
+      libdvd_library = NULL;
+    } else if(!DVD_open  || !DVD_close || !DVD_title || !DVD_seek
+              || !DVD_read || !DVD_error || !libdvd_version) {
       if(verbose >= 0) {
-        fprintf(stderr,  "libdvdread: Missing symbols in libdvdcss.so.2, "
-                "this shouldn't happen !\n");
+        fprintf(stderr,  "libdvdread: Missing symbols in %s, "
+                "this shouldn't happen !\n", LIBDVDNAME);
       }
-      dlclose(dvdcss_library);
-      dvdcss_library = NULL;
+      dlclose(libdvd_library);
+      libdvd_library = NULL;
     }
   }
 #endif /* HAVE_DVDCSS_DVDCSS_H */
 
-  dvdcss_library_init = 1;
+  libdvd_library_init = 1;
   
-  if(dvdcss_library) {
+  if(libdvd_library) {
     /*
       char *psz_method = getenv( "DVDCSS_METHOD" );
       char *psz_verbose = getenv( "DVDCSS_VERBOSE" );
@@ -386,16 +392,16 @@ int dvdinput_setup(void)
       fprintf(stderr, "DVDCSS_VERBOSE %s\n", psz_verbose);
     */
     if(verbose >= 1) {
-      fprintf(stderr, "libdvdread: Using libdvdcss version %s for DVD access\n",
-              *dvdcss_version);
+      fprintf(stderr, "libdvdread: Using %s version %s for DVD access\n",
+              LIBDVDNAME, *libdvd_version);
     }
     /* libdvdcss wrapper functions */
-    dvdinput_open  = css_open;
-    dvdinput_close = css_close;
-    dvdinput_seek  = css_seek;
-    dvdinput_title = css_title;
-    dvdinput_read  = css_read;
-    dvdinput_error = css_error;
+    dvdinput_open  = libdvd_open;
+    dvdinput_close = libdvd_close;
+    dvdinput_seek  = libdvd_seek;
+    dvdinput_title = libdvd_title;
+    dvdinput_read  = libdvd_read;
+    dvdinput_error = libdvd_error;
     return 1;
     
   } else {
