Mercurial > mplayer.hg
annotate libmpdvdkit2/libdvdcss.c @ 20488:f485fb548bf3
cosmetics: reformatted after previous commit
author | nicodvb |
---|---|
date | Sun, 29 Oct 2006 11:00:36 +0000 |
parents | f59726d0761e |
children |
rev | line source |
---|---|
7027 | 1 /* libdvdcss.c: DVD reading library. |
2 * | |
3 * Authors: Stéphane Borel <stef@via.ecp.fr> | |
4 * Samuel Hocevar <sam@zoy.org> | |
5 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
6 * | |
7 * Copyright (C) 1998-2002 VideoLAN | |
8 * $Id$ | |
9 * | |
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 | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
14 * |
7027 | 15 * This program is distributed in the hope that it will be useful, |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. | |
23 */ | |
24 | |
16630 | 25 /** |
7027 | 26 * \mainpage libdvdcss developer documentation |
27 * | |
28 * \section intro Introduction | |
29 * | |
30 * \e libdvdcss is a simple library designed for accessing DVDs like a block | |
31 * device without having to bother about the decryption. The important features | |
32 * are: | |
33 * \li portability: currently supported platforms are GNU/Linux, FreeBSD, | |
34 * NetBSD, OpenBSD, BSD/OS, BeOS, Windows 95/98, Windows NT/2000, MacOS X, | |
35 * Solaris, HP-UX and OS/2. | |
36 * \li adaptability: unlike most similar projects, libdvdcss doesn't require | |
37 * the region of your drive to be set and will try its best to read from | |
38 * the disc even in the case of a region mismatch. | |
39 * \li simplicity: a DVD player can be built around the \e libdvdcss API using | |
40 * no more than 4 or 5 library calls. | |
41 * | |
42 * \e libdvdcss is free software, released under the General Public License. | |
43 * This ensures that \e libdvdcss remains free and used only with free | |
44 * software. | |
45 * | |
46 * \section api The libdvdcss API | |
47 * | |
48 * The complete \e libdvdcss programming interface is documented in the | |
49 * dvdcss.h file. | |
50 * | |
51 * \section env Environment variables | |
52 * | |
53 * Some environment variables can be used to change the behaviour of | |
54 * \e libdvdcss without having to modify the program which uses it. These | |
55 * variables are: | |
56 * | |
57 * \li \b DVDCSS_VERBOSE: sets the verbosity level. | |
58 * - \c 0 outputs no messages at all. | |
59 * - \c 1 outputs error messages to stderr. | |
60 * - \c 2 outputs error messages and debug messages to stderr. | |
61 * | |
62 * \li \b DVDCSS_METHOD: sets the authentication and decryption method | |
63 * that \e libdvdcss will use to read scrambled discs. Can be one | |
64 * of \c title, \c key or \c disc. | |
65 * - \c key is the default method. \e libdvdcss will use a set of | |
66 * calculated player keys to try and get the disc key. This can fail | |
67 * if the drive does not recognize any of the player keys. | |
68 * - \c disc is a fallback method when \c key has failed. Instead of | |
69 * using player keys, \e libdvdcss will crack the disc key using | |
70 * a brute force algorithm. This process is CPU intensive and requires | |
71 * 64 MB of memory to store temporary data. | |
72 * - \c title is the fallback when all other methods have failed. It does | |
73 * not rely on a key exchange with the DVD drive, but rather uses a | |
74 * crypto attack to guess the title key. On rare cases this may fail | |
75 * because there is not enough encrypted data on the disc to perform | |
76 * a statistical attack, but in the other hand it is the only way to | |
77 * decrypt a DVD stored on a hard disc, or a DVD with the wrong region | |
78 * on an RPC2 drive. | |
79 * | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
80 * \li \b DVDCSS_RAW_DEVICE: specify the raw device to use. Exact usage will |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
81 * depend on your operating system, the Linux utility to set up raw devices |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
82 * is \c raw(8) for instance. Please note that on most operating systems, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
83 * using a raw device requires highly aligned buffers: Linux requires a |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
84 * 2048 bytes alignment (which is the size of a DVD sector). |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
85 * |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
86 * \li \b DVDCSS_CACHE: specify a directory in which to store title key |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
87 * values. This will speed up descrambling of DVDs which are in the |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
88 * cache. The DVDCSS_CACHE directory is created if it does not exist, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
89 * and a subdirectory is created named after the DVD's title or |
16848
279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
diego
parents:
16714
diff
changeset
|
90 * manufacturing date. If DVDCSS_CACHE is not set or is empty, \e libdvdcss |
279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
diego
parents:
16714
diff
changeset
|
91 * will use the default value which is "${HOME}/.dvdcss/" under Unix and |
279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
diego
parents:
16714
diff
changeset
|
92 * "C:\Documents and Settings\$USER\Application Data\dvdcss\" under Win32. |
279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
diego
parents:
16714
diff
changeset
|
93 * The special value "off" disables caching. |
7027 | 94 */ |
95 | |
96 /* | |
97 * Preamble | |
98 */ | |
99 #include "config.h" | |
100 | |
101 #include <stdio.h> | |
102 #include <stdlib.h> | |
103 #include <string.h> | |
104 #include <sys/types.h> | |
105 #include <sys/stat.h> | |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
106 #ifdef HAVE_SYS_PARAM_H |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
107 # include <sys/param.h> |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
108 #endif |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
109 #ifdef HAVE_PWD_H |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
110 # include <pwd.h> |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
111 #endif |
7027 | 112 #include <fcntl.h> |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
113 #include <errno.h> |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
114 |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
115 #ifdef HAVE_UNISTD_H |
16630 | 116 # include <unistd.h> |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
117 #endif |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
118 |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
119 #ifdef HAVE_LIMITS_H |
16630 | 120 # include <limits.h> |
16714
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
121 #endif |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
122 |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
123 #ifdef HAVE_DIRECT_H |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
124 # include <direct.h> |
2ab52c9b72b9
Replace unconditional #defines by build system trickery.
diego
parents:
16631
diff
changeset
|
125 #endif |
7027 | 126 |
19820
e5d97c5f3c32
Move dvdcss.h to a dvdcss subdirectory, just like upstream libdvdcss does.
diego
parents:
18783
diff
changeset
|
127 #include "dvdcss/dvdcss.h" |
7027 | 128 |
129 #include "common.h" | |
130 #include "css.h" | |
131 #include "libdvdcss.h" | |
132 #include "ioctl.h" | |
133 #include "device.h" | |
134 | |
135 /** | |
136 * \brief Symbol for version checks. | |
137 * | |
138 * The name of this symbol contains the library major number, which makes it | |
139 * easy to check which \e libdvdcss development headers are installed on the | |
140 * system with tools such as autoconf. | |
141 * | |
142 * The variable itself contains the exact version number of the library, | |
143 * which can be useful for specific feature needs. | |
144 */ | |
20425 | 145 LIBDVDCSS_EXPORT char * dvdcss_interface_2; |
7027 | 146 char * dvdcss_interface_2 = VERSION; |
147 | |
148 /** | |
149 * \brief Open a DVD device or directory and return a dvdcss instance. | |
150 * | |
151 * \param psz_target a string containing the target name, for instance | |
152 * "/dev/hdc" or "E:". | |
153 * \return a handle to a dvdcss instance or NULL on error. | |
154 * | |
155 * Initialize the \e libdvdcss library and open the requested DVD device or | |
156 * directory. \e libdvdcss checks whether ioctls can be performed on the disc, | |
157 * and when possible, the disc key is retrieved. | |
158 * | |
159 * dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss | |
20415 | 160 * calls. If an error occurred, NULL is returned. |
7027 | 161 */ |
20425 | 162 LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( char *psz_target ) |
7027 | 163 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
164 char psz_buffer[PATH_MAX]; |
7027 | 165 int i_ret; |
166 | |
167 char *psz_method = getenv( "DVDCSS_METHOD" ); | |
168 char *psz_verbose = getenv( "DVDCSS_VERBOSE" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
169 char *psz_cache = getenv( "DVDCSS_CACHE" ); |
7027 | 170 #ifndef WIN32 |
171 char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" ); | |
172 #endif | |
173 | |
174 dvdcss_t dvdcss; | |
175 | |
176 /* | |
177 * Allocate the library structure | |
178 */ | |
179 dvdcss = malloc( sizeof( struct dvdcss_s ) ); | |
180 if( dvdcss == NULL ) | |
181 { | |
182 return NULL; | |
183 } | |
184 | |
185 /* | |
186 * Initialize structure with default values | |
187 */ | |
188 #ifndef WIN32 | |
189 dvdcss->i_raw_fd = -1; | |
190 #endif | |
191 dvdcss->p_titles = NULL; | |
192 dvdcss->psz_device = (char *)strdup( psz_target ); | |
193 dvdcss->psz_error = "no error"; | |
194 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
195 dvdcss->psz_cachefile[0] = '\0'; |
7027 | 196 dvdcss->b_debug = 0; |
197 dvdcss->b_errors = 0; | |
198 | |
199 /* | |
200 * Find verbosity from DVDCSS_VERBOSE environment variable | |
201 */ | |
202 if( psz_verbose != NULL ) | |
203 { | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
204 int i = atoi( psz_verbose ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
205 |
16630 | 206 if( i >= 2 ) dvdcss->b_debug = i; |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
207 if( i >= 1 ) dvdcss->b_errors = 1; |
7027 | 208 } |
209 | |
210 /* | |
211 * Find method from DVDCSS_METHOD environment variable | |
212 */ | |
213 if( psz_method != NULL ) | |
214 { | |
215 if( !strncmp( psz_method, "key", 4 ) ) | |
216 { | |
217 dvdcss->i_method = DVDCSS_METHOD_KEY; | |
218 } | |
219 else if( !strncmp( psz_method, "disc", 5 ) ) | |
220 { | |
221 dvdcss->i_method = DVDCSS_METHOD_DISC; | |
222 } | |
223 else if( !strncmp( psz_method, "title", 5 ) ) | |
224 { | |
225 dvdcss->i_method = DVDCSS_METHOD_TITLE; | |
226 } | |
227 else | |
228 { | |
16630 | 229 print_error( dvdcss, "unknown decrypt method, please choose " |
230 "from 'title', 'key' or 'disc'" ); | |
7027 | 231 free( dvdcss->psz_device ); |
232 free( dvdcss ); | |
233 return NULL; | |
234 } | |
235 } | |
236 | |
16630 | 237 /* |
238 * If DVDCSS_CACHE was not set, try to guess a default value | |
239 */ | |
240 if( psz_cache == NULL || psz_cache[0] == '\0' ) | |
241 { | |
242 #ifdef HAVE_DIRECT_H | |
243 typedef HRESULT( WINAPI *SHGETFOLDERPATH ) | |
244 ( HWND, int, HANDLE, DWORD, LPTSTR ); | |
245 | |
246 # define CSIDL_FLAG_CREATE 0x8000 | |
247 # define CSIDL_APPDATA 0x1A | |
248 # define SHGFP_TYPE_CURRENT 0 | |
249 | |
250 char psz_home[MAX_PATH]; | |
251 HINSTANCE p_dll; | |
252 SHGETFOLDERPATH p_getpath; | |
253 | |
254 *psz_home = '\0'; | |
255 | |
256 /* Load the shfolder dll to retrieve SHGetFolderPath */ | |
257 p_dll = LoadLibrary( "shfolder.dll" ); | |
258 if( p_dll ) | |
259 { | |
260 p_getpath = (void*)GetProcAddress( p_dll, "SHGetFolderPathA" ); | |
261 if( p_getpath ) | |
262 { | |
263 /* Get the "Application Data" folder for the current user */ | |
264 if( p_getpath( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, | |
265 NULL, SHGFP_TYPE_CURRENT, psz_home ) == S_OK ) | |
266 { | |
267 FreeLibrary( p_dll ); | |
268 } | |
269 else | |
270 { | |
271 *psz_home = '\0'; | |
272 } | |
273 } | |
274 FreeLibrary( p_dll ); | |
275 } | |
276 | |
277 /* Cache our keys in | |
278 * C:\Documents and Settings\$USER\Application Data\dvdcss\ */ | |
279 if( *psz_home ) | |
280 { | |
281 snprintf( psz_buffer, PATH_MAX, "%s/dvdcss", psz_home ); | |
282 psz_buffer[PATH_MAX-1] = '\0'; | |
283 psz_cache = psz_buffer; | |
284 } | |
285 #else | |
286 char *psz_home = NULL; | |
287 # ifdef HAVE_PWD_H | |
288 struct passwd *p_pwd; | |
289 | |
290 /* Try looking in password file for home dir. */ | |
291 p_pwd = getpwuid(getuid()); | |
292 if( p_pwd ) | |
293 { | |
294 psz_home = p_pwd->pw_dir; | |
295 } | |
296 # endif | |
297 | |
298 if( psz_home == NULL ) | |
299 { | |
300 psz_home = getenv( "HOME" ); | |
301 } | |
18109
68145aae7349
fallback to USERPROFILE environment variable for caching CSS keys when
reimar
parents:
16848
diff
changeset
|
302 if( psz_home == NULL ) |
68145aae7349
fallback to USERPROFILE environment variable for caching CSS keys when
reimar
parents:
16848
diff
changeset
|
303 { |
68145aae7349
fallback to USERPROFILE environment variable for caching CSS keys when
reimar
parents:
16848
diff
changeset
|
304 psz_home = getenv( "USERPROFILE" ); |
68145aae7349
fallback to USERPROFILE environment variable for caching CSS keys when
reimar
parents:
16848
diff
changeset
|
305 } |
16630 | 306 |
307 /* Cache our keys in ${HOME}/.dvdcss/ */ | |
308 if( psz_home ) | |
309 { | |
310 snprintf( psz_buffer, PATH_MAX, "%s/.dvdcss", psz_home ); | |
311 psz_buffer[PATH_MAX-1] = '\0'; | |
312 psz_cache = psz_buffer; | |
313 } | |
314 #endif | |
315 } | |
316 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
317 /* |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
318 * Find cache dir from the DVDCSS_CACHE environment variable |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
319 */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
320 if( psz_cache != NULL ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
321 { |
16630 | 322 if( psz_cache[0] == '\0' || !strcmp( psz_cache, "off" ) ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
323 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
324 psz_cache = NULL; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
325 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
326 /* Check that we can add the ID directory and the block filename */ |
16630 | 327 else if( strlen( psz_cache ) + 1 + 32 + 1 + (KEY_SIZE * 2) + 10 + 1 |
328 > PATH_MAX ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
329 { |
16630 | 330 print_error( dvdcss, "cache directory name is too long" ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
331 psz_cache = NULL; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
332 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
333 } |
7032 | 334 |
7027 | 335 /* |
336 * Open device | |
337 */ | |
20425 | 338 _dvdcss_check( dvdcss ); |
7027 | 339 i_ret = _dvdcss_open( dvdcss ); |
340 if( i_ret < 0 ) | |
341 { | |
342 free( dvdcss->psz_device ); | |
343 free( dvdcss ); | |
344 return NULL; | |
345 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
346 |
7027 | 347 dvdcss->b_scrambled = 1; /* Assume the worst */ |
348 dvdcss->b_ioctls = _dvdcss_use_ioctls( dvdcss ); | |
349 | |
350 if( dvdcss->b_ioctls ) | |
351 { | |
352 i_ret = _dvdcss_test( dvdcss ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
353 if( i_ret < 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
354 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
355 /* Disable the CSS ioctls and hope that it works? */ |
16630 | 356 print_debug( dvdcss, |
357 "could not check whether the disc was scrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
358 dvdcss->b_ioctls = 0; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
359 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
360 else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
361 { |
16630 | 362 print_debug( dvdcss, i_ret ? "disc is scrambled" |
363 : "disc is unscrambled" ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
364 dvdcss->b_scrambled = i_ret; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
365 } |
7027 | 366 } |
367 | |
368 /* If disc is CSS protected and the ioctls work, authenticate the drive */ | |
369 if( dvdcss->b_scrambled && dvdcss->b_ioctls ) | |
370 { | |
371 i_ret = _dvdcss_disckey( dvdcss ); | |
372 | |
373 if( i_ret < 0 ) | |
374 { | |
375 _dvdcss_close( dvdcss ); | |
376 free( dvdcss->psz_device ); | |
377 free( dvdcss ); | |
378 return NULL; | |
379 } | |
380 } | |
381 | |
16630 | 382 /* If the cache is enabled, write the cache directory tag */ |
383 if( psz_cache ) | |
384 { | |
385 char *psz_tag = "Signature: 8a477f597d28d172789f06886806bc55\r\n" | |
386 "# This file is a cache directory tag created by libdvdcss.\r\n" | |
387 "# For information about cache directory tags, see:\r\n" | |
388 "# http://www.brynosaurus.com/cachedir/\r\n"; | |
20417 | 389 char psz_tagfile[PATH_MAX + 1 + 12 + 1]; |
16630 | 390 int i_fd; |
391 | |
392 sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache ); | |
393 i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 ); | |
394 if( i_fd >= 0 ) | |
395 { | |
396 write( i_fd, psz_tag, strlen(psz_tag) ); | |
397 close( i_fd ); | |
398 } | |
399 } | |
400 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
401 /* If the cache is enabled, extract a unique disc ID */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
402 if( psz_cache ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
403 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
404 uint8_t p_sector[DVDCSS_BLOCK_SIZE]; |
20417 | 405 char psz_debug[PATH_MAX + 30]; |
406 char psz_key[1 + KEY_SIZE * 2 + 1]; | |
407 char *psz_title, *psz_serial; | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
408 int i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
409 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
410 /* We read sector 0. If it starts with 0x000001ba (BE), we are |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
411 * reading a VOB file, and we should not cache anything. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
412 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
413 i_ret = dvdcss->pf_seek( dvdcss, 0 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
414 if( i_ret != 0 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
415 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
416 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
417 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
418 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
419 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
420 if( i_ret != 1 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
421 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
422 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
423 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
424 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
425 if( p_sector[0] == 0x00 && p_sector[1] == 0x00 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
426 && p_sector[2] == 0x01 && p_sector[3] == 0xba ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
427 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
428 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
429 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
430 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
431 /* The data we are looking for is at sector 16 (32768 bytes): |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
432 * - offset 40: disc title (32 uppercase chars) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
433 * - offset 813: manufacturing date + serial no (16 digits) */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
434 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
435 i_ret = dvdcss->pf_seek( dvdcss, 16 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
436 if( i_ret != 16 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
437 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
438 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
439 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
440 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
441 i_ret = dvdcss->pf_read( dvdcss, p_sector, 1 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
442 if( i_ret != 1 ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
443 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
444 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
445 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
446 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
447 /* Get the disc title */ |
20417 | 448 psz_title = (char *)p_sector + 40; |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
449 psz_title[32] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
450 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
451 for( i = 0 ; i < 32 ; i++ ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
452 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
453 if( psz_title[i] <= ' ' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
454 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
455 psz_title[i] = '\0'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
456 break; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
457 } |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
458 else if( psz_title[i] == '/' || psz_title[i] == '\\' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
459 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
460 psz_title[i] = '-'; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
461 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
462 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
463 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
464 /* Get the date + serial */ |
20417 | 465 psz_serial = (char *)p_sector + 813; |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
466 psz_serial[16] = '\0'; |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
467 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
468 /* Check that all characters are digits, otherwise convert. */ |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
469 for( i = 0 ; i < 16 ; i++ ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
470 { |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
471 if( psz_serial[i] < '0' || psz_serial[i] > '9' ) |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
472 { |
20418 | 473 char psz_tmp[16 + 1]; |
16630 | 474 sprintf( psz_tmp, |
475 "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", | |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
476 psz_serial[0], psz_serial[1], psz_serial[2], |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
477 psz_serial[3], psz_serial[4], psz_serial[5], |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
478 psz_serial[6], psz_serial[7] ); |
16630 | 479 memcpy( psz_serial, psz_tmp, 16 ); |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
480 break; |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
481 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
482 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
483 |
16630 | 484 /* Get disk key, since some discs have got same title, manufacturing |
485 * date and serial number, but different keys */ | |
486 if( dvdcss->b_scrambled ) | |
487 { | |
488 psz_key[0] = '-'; | |
489 for( i = 0; i < KEY_SIZE; i++ ) | |
490 { | |
491 sprintf( &psz_key[1+i*2], "%.2x", dvdcss->css.p_disc_key[i] ); | |
492 } | |
493 psz_key[1 + KEY_SIZE * 2] = '\0'; | |
494 } | |
495 else | |
496 { | |
497 psz_key[0] = 0; | |
498 } | |
499 | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
500 /* We have a disc name or ID, we can create the cache dir */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
501 i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
502 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
503 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
504 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
505 i_ret = mkdir( dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
506 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
507 if( i_ret < 0 && errno != EEXIST ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
508 { |
16630 | 509 print_error( dvdcss, "failed creating cache directory" ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
510 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
511 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
512 } |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
513 |
16848
279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
diego
parents:
16714
diff
changeset
|
514 i += sprintf( dvdcss->psz_cachefile + i, "/%s-%s%s", psz_title, |
279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
diego
parents:
16714
diff
changeset
|
515 psz_serial, psz_key ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
516 #if !defined( WIN32 ) || defined( SYS_CYGWIN ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
517 i_ret = mkdir( dvdcss->psz_cachefile, 0755 ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
518 #else |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
519 i_ret = mkdir( dvdcss->psz_cachefile ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
520 #endif |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
521 if( i_ret < 0 && errno != EEXIST ) |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
522 { |
16630 | 523 print_error( dvdcss, "failed creating cache subdirectory" ); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
524 dvdcss->psz_cachefile[0] = '\0'; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
525 goto nocache; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
526 } |
9882 | 527 i += sprintf( dvdcss->psz_cachefile + i, "/"); |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
528 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
529 /* Pointer to the filename we will use. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
530 dvdcss->psz_block = dvdcss->psz_cachefile + i; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
531 |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
532 sprintf( psz_debug, "using CSS key cache dir: %s", |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
533 dvdcss->psz_cachefile ); |
16630 | 534 print_debug( dvdcss, psz_debug ); |
7032 | 535 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
536 nocache: |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
537 |
10720
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
538 #ifndef WIN32 |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
539 if( psz_raw_device != NULL ) |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
540 { |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
541 _dvdcss_raw_open( dvdcss, psz_raw_device ); |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
542 } |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
543 #endif |
f23c35ce0d16
synced to libdvdcss 1.2.8 (except the DVDCSS_PATH guessing, we use our
arpi
parents:
9882
diff
changeset
|
544 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
545 /* Seek at the beginning, just for safety. */ |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
546 dvdcss->pf_seek( dvdcss, 0 ); |
7032 | 547 |
7027 | 548 return dvdcss; |
549 } | |
550 | |
551 /** | |
20415 | 552 * \brief Return a string containing the latest error that occurred in the |
7027 | 553 * given \e libdvdcss instance. |
554 * | |
555 * \param dvdcss a \e libdvdcss instance. | |
556 * \return a null-terminated string containing the latest error message. | |
557 * | |
558 * This function returns a constant string containing the latest error that | |
20415 | 559 * occurred in \e libdvdcss. It can be used to format error messages at your |
7027 | 560 * convenience in your application. |
561 */ | |
20425 | 562 LIBDVDCSS_EXPORT char * dvdcss_error ( dvdcss_t dvdcss ) |
7027 | 563 { |
564 return dvdcss->psz_error; | |
565 } | |
566 | |
567 /** | |
568 * \brief Seek in the disc and change the current key if requested. | |
569 * | |
570 * \param dvdcss a \e libdvdcss instance. | |
571 * \param i_blocks an absolute block offset to seek to. | |
572 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with one of #DVDCSS_SEEK_KEY | |
573 * or #DVDCSS_SEEK_MPEG. | |
574 * \return the new position in blocks, or a negative value in case an error | |
575 * happened. | |
576 * | |
577 * This function seeks to the requested position, in logical blocks. | |
578 * | |
579 * You typically set \p i_flags to #DVDCSS_NOFLAGS when seeking in a .IFO. | |
580 * | |
581 * If #DVDCSS_SEEK_MPEG is specified in \p i_flags and if \e libdvdcss finds it | |
582 * reasonable to do so (ie, if the dvdcss method is not "title"), the current | |
583 * title key will be checked and a new one will be calculated if necessary. | |
584 * This flag is typically used when reading data from a VOB. | |
585 * | |
586 * If #DVDCSS_SEEK_KEY is specified, the title key will be always checked, | |
587 * even with the "title" method. This is equivalent to using the now | |
588 * deprecated dvdcss_title() call. This flag is typically used when seeking | |
589 * in a new title. | |
590 */ | |
20425 | 591 LIBDVDCSS_EXPORT int dvdcss_seek ( dvdcss_t dvdcss, int i_blocks, int i_flags ) |
7027 | 592 { |
593 /* title cracking method is too slow to be used at each seek */ | |
594 if( ( ( i_flags & DVDCSS_SEEK_MPEG ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
595 && ( dvdcss->i_method != DVDCSS_METHOD_TITLE ) ) |
7027 | 596 || ( i_flags & DVDCSS_SEEK_KEY ) ) |
597 { | |
598 /* check the title key */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
599 if( _dvdcss_title( dvdcss, i_blocks ) ) |
7027 | 600 { |
601 return -1; | |
602 } | |
603 } | |
604 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
605 return dvdcss->pf_seek( dvdcss, i_blocks ); |
7027 | 606 } |
607 | |
608 /** | |
609 * \brief Read from the disc and decrypt data if requested. | |
610 * | |
611 * \param dvdcss a \e libdvdcss instance. | |
612 * \param p_buffer a buffer that will contain the data read from the disc. | |
613 * \param i_blocks the amount of blocks to read. | |
614 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
615 * \return the amount of blocks read, or a negative value in case an | |
616 * error happened. | |
617 * | |
618 * This function reads \p i_blocks logical blocks from the DVD. | |
619 * | |
620 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
621 * .IFO file on the DVD. | |
622 * | |
623 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_read() will | |
624 * automatically decrypt scrambled sectors. This flag is typically used when | |
625 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
626 * discs or unscrambled sectors, and can be safely used on those. | |
627 * | |
628 * \warning dvdcss_read() expects to be able to write \p i_blocks * | |
629 * #DVDCSS_BLOCK_SIZE bytes in \p p_buffer. | |
630 */ | |
20425 | 631 LIBDVDCSS_EXPORT int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, |
7027 | 632 int i_blocks, |
633 int i_flags ) | |
634 { | |
635 int i_ret, i_index; | |
636 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
637 i_ret = dvdcss->pf_read( dvdcss, p_buffer, i_blocks ); |
7027 | 638 |
639 if( i_ret <= 0 | |
640 || !dvdcss->b_scrambled | |
641 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
642 { | |
643 return i_ret; | |
644 } | |
645 | |
646 if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) ) | |
647 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
648 /* For what we believe is an unencrypted title, |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
649 * check that there are no encrypted blocks */ |
7027 | 650 for( i_index = i_ret; i_index; i_index-- ) |
651 { | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
652 if( ((uint8_t*)p_buffer)[0x14] & 0x30 ) |
7027 | 653 { |
16630 | 654 print_error( dvdcss, "no key but found encrypted block" ); |
7027 | 655 /* Only return the initial range of unscrambled blocks? */ |
656 /* or fail completely? return 0; */ | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
657 break; |
7027 | 658 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
659 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
7027 | 660 } |
661 } | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
662 else |
7027 | 663 { |
664 /* Decrypt the blocks we managed to read */ | |
665 for( i_index = i_ret; i_index; i_index-- ) | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
666 { |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
667 _dvdcss_unscramble( dvdcss->css.p_title_key, p_buffer ); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
668 ((uint8_t*)p_buffer)[0x14] &= 0x8f; |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
669 p_buffer = (void *) ((uint8_t *)p_buffer + DVDCSS_BLOCK_SIZE); |
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
670 } |
7027 | 671 } |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
672 |
7027 | 673 return i_ret; |
674 } | |
675 | |
676 /** | |
677 * \brief Read from the disc into multiple buffers and decrypt data if | |
678 * requested. | |
679 * | |
680 * \param dvdcss a \e libdvdcss instance. | |
681 * \param p_iovec a pointer to an array of iovec structures that will contain | |
682 * the data read from the disc. | |
683 * \param i_blocks the amount of blocks to read. | |
684 * \param i_flags #DVDCSS_NOFLAGS, optionally ored with #DVDCSS_READ_DECRYPT. | |
685 * \return the amount of blocks read, or a negative value in case an | |
686 * error happened. | |
687 * | |
688 * This function reads \p i_blocks logical blocks from the DVD and writes them | |
689 * to an array of iovec structures. | |
690 * | |
691 * You typically set \p i_flags to #DVDCSS_NOFLAGS when reading data from a | |
692 * .IFO file on the DVD. | |
693 * | |
694 * If #DVDCSS_READ_DECRYPT is specified in \p i_flags, dvdcss_readv() will | |
695 * automatically decrypt scrambled sectors. This flag is typically used when | |
696 * reading data from a .VOB file on the DVD. It has no effect on unscrambled | |
697 * discs or unscrambled sectors, and can be safely used on those. | |
698 * | |
699 * \warning dvdcss_readv() expects to be able to write \p i_blocks * | |
700 * #DVDCSS_BLOCK_SIZE bytes in the buffers pointed by \p p_iovec. | |
701 * Moreover, all iov_len members of the iovec structures should be | |
702 * multiples of #DVDCSS_BLOCK_SIZE. | |
703 */ | |
20425 | 704 LIBDVDCSS_EXPORT int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec, |
7027 | 705 int i_blocks, |
706 int i_flags ) | |
707 { | |
708 struct iovec *_p_iovec = (struct iovec *)p_iovec; | |
709 int i_ret, i_index; | |
710 void *iov_base; | |
711 size_t iov_len; | |
712 | |
8637
0211de3039eb
update libdvdcss in libmpdvdkit to latest version (1.2.4)
arpi
parents:
8123
diff
changeset
|
713 i_ret = dvdcss->pf_readv( dvdcss, _p_iovec, i_blocks ); |
7027 | 714 |
715 if( i_ret <= 0 | |
716 || !dvdcss->b_scrambled | |
717 || !(i_flags & DVDCSS_READ_DECRYPT) ) | |
718 { | |
719 return i_ret; | |
720 } | |
721 | |
722 /* Initialize loop for decryption */ | |
723 iov_base = _p_iovec->iov_base; | |
724 iov_len = _p_iovec->iov_len; | |
725 | |
726 /* Decrypt the blocks we managed to read */ | |
727 for( i_index = i_ret; i_index; i_index-- ) | |
728 { | |
729 /* Check that iov_len is a multiple of 2048 */ | |
730 if( iov_len & 0x7ff ) | |
731 { | |
732 return -1; | |
733 } | |
734 | |
735 while( iov_len == 0 ) | |
736 { | |
737 _p_iovec++; | |
738 iov_base = _p_iovec->iov_base; | |
739 iov_len = _p_iovec->iov_len; | |
740 } | |
741 | |
742 _dvdcss_unscramble( dvdcss->css.p_title_key, iov_base ); | |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
743 ((uint8_t*)iov_base)[0x14] &= 0x8f; |
7027 | 744 |
9333
f0f0f176d298
sync with libdvdcss 1.2.5 (including u8->uint8_t and whitespace cosmetics...)
arpi
parents:
8841
diff
changeset
|
745 iov_base = (void *) ((uint8_t*)iov_base + DVDCSS_BLOCK_SIZE); |
7027 | 746 iov_len -= DVDCSS_BLOCK_SIZE; |
747 } | |
748 | |
749 return i_ret; | |
750 } | |
751 | |
752 /** | |
753 * \brief Close the DVD and clean up the library. | |
754 * | |
755 * \param dvdcss a \e libdvdcss instance. | |
756 * \return zero in case of success, a negative value otherwise. | |
757 * | |
758 * This function closes the DVD device and frees all the memory allocated | |
759 * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be | |
760 * used again. | |
761 */ | |
20425 | 762 LIBDVDCSS_EXPORT int dvdcss_close ( dvdcss_t dvdcss ) |
7027 | 763 { |
764 dvd_title_t *p_title; | |
765 int i_ret; | |
766 | |
767 /* Free our list of keys */ | |
768 p_title = dvdcss->p_titles; | |
769 while( p_title ) | |
770 { | |
771 dvd_title_t *p_tmptitle = p_title->p_next; | |
772 free( p_title ); | |
773 p_title = p_tmptitle; | |
774 } | |
775 | |
776 i_ret = _dvdcss_close( dvdcss ); | |
777 | |
778 if( i_ret < 0 ) | |
779 { | |
780 return i_ret; | |
781 } | |
782 | |
783 free( dvdcss->psz_device ); | |
784 free( dvdcss ); | |
785 | |
786 return 0; | |
787 } | |
788 | |
789 /* | |
790 * Deprecated. See dvdcss_seek(). | |
791 */ | |
792 #undef dvdcss_title | |
20425 | 793 LIBDVDCSS_EXPORT int dvdcss_title ( dvdcss_t dvdcss, int i_block ) |
7027 | 794 { |
795 return _dvdcss_title( dvdcss, i_block ); | |
796 } | |
797 |