Discussion:
[libdvdcss-devel] some cache directory cleanup
Diego Biurrun
2014-11-01 16:56:28 UTC
Permalink
Some of the later patches in my large set still lack the "it actually
works" feature that everybody is raving about nowadays. Here is some
(related) intermediary cleanup while I restructure the patches not to
break the cache.
Diego Biurrun
2014-11-01 16:56:29 UTC
Permalink
---
src/libdvdcss.h | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/libdvdcss.h b/src/libdvdcss.h
index 4f1f4af..399a1a3 100644
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -35,6 +35,14 @@
#include "device.h"

/*****************************************************************************
+ * libdvdcss method: used like init flags
+ *****************************************************************************/
+enum dvdcss_method {
+ DVDCSS_METHOD_KEY,
+ DVDCSS_METHOD_DISC,
+ DVDCSS_METHOD_TITLE,
+};
+/*****************************************************************************
* The libdvdcss structure
*****************************************************************************/
struct dvdcss_s
@@ -51,7 +59,7 @@ struct dvdcss_s
int ( * pf_readv ) ( dvdcss_t, struct iovec *, int );

/* Decryption stuff */
- int i_method;
+ enum dvdcss_method i_method;
css_t css;
int b_ioctls;
int b_scrambled;
@@ -78,13 +86,6 @@ struct dvdcss_s
};

/*****************************************************************************
- * libdvdcss method: used like init flags
- *****************************************************************************/
-#define DVDCSS_METHOD_KEY 0
-#define DVDCSS_METHOD_DISC 1
-#define DVDCSS_METHOD_TITLE 2
-
-/*****************************************************************************
* Functions used across the library
*****************************************************************************/
#define print_debug( dvdcss, ... ) \
--
1.9.1
Jean-Baptiste Kempf
2014-11-01 17:04:05 UTC
Permalink
LGTM.
Post by Diego Biurrun
---
src/libdvdcss.h | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/libdvdcss.h b/src/libdvdcss.h
index 4f1f4af..399a1a3 100644
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -35,6 +35,14 @@
#include "device.h"
/*****************************************************************************
+ * libdvdcss method: used like init flags
+ *****************************************************************************/
+enum dvdcss_method {
+ DVDCSS_METHOD_KEY,
+ DVDCSS_METHOD_DISC,
+ DVDCSS_METHOD_TITLE,
+};
+/*****************************************************************************
* The libdvdcss structure
*****************************************************************************/
struct dvdcss_s
@@ -51,7 +59,7 @@ struct dvdcss_s
int ( * pf_readv ) ( dvdcss_t, struct iovec *, int );
/* Decryption stuff */
- int i_method;
+ enum dvdcss_method i_method;
css_t css;
int b_ioctls;
int b_scrambled;
@@ -78,13 +86,6 @@ struct dvdcss_s
};
/*****************************************************************************
- * libdvdcss method: used like init flags
- *****************************************************************************/
-#define DVDCSS_METHOD_KEY 0
-#define DVDCSS_METHOD_DISC 1
-#define DVDCSS_METHOD_TITLE 2
-
-/*****************************************************************************
* Functions used across the library
*****************************************************************************/
#define print_debug( dvdcss, ... ) \
--
1.9.1
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Fabian Greffrath
2014-11-03 08:50:06 UTC
Permalink
Post by Diego Biurrun
+enum dvdcss_method {
+ DVDCSS_METHOD_KEY,
+ DVDCSS_METHOD_DISC,
+ DVDCSS_METHOD_TITLE,
+};
[...]
Post by Diego Biurrun
+ enum dvdcss_method i_method;
Why don't you use typedef enum?

- Fabian
Diego Biurrun
2014-11-03 08:53:03 UTC
Permalink
Post by Fabian Greffrath
Post by Diego Biurrun
+enum dvdcss_method {
+ DVDCSS_METHOD_KEY,
+ DVDCSS_METHOD_DISC,
+ DVDCSS_METHOD_TITLE,
+};
[...]
Post by Diego Biurrun
+ enum dvdcss_method i_method;
Why don't you use typedef enum?
I'll turn this around - why should I typedef?

Diego
Fabian Greffrath
2014-11-03 09:05:23 UTC
Permalink
Post by Diego Biurrun
Post by Fabian Greffrath
Post by Diego Biurrun
+enum dvdcss_method {
+ DVDCSS_METHOD_KEY,
+ DVDCSS_METHOD_DISC,
+ DVDCSS_METHOD_TITLE,
+};
[...]
Post by Diego Biurrun
+ enum dvdcss_method i_method;
Why don't you use typedef enum?
I'll turn this around - why should I typedef?
Because then you could declare the variable without having to duplicate
its enum type:

typedef enum dvdcss_method {
...
} dvdcss_method_t;
[...]
dvdcss_method_t i_method;

- Fabian
Diego Biurrun
2014-11-03 09:11:51 UTC
Permalink
Post by Fabian Greffrath
Post by Diego Biurrun
Post by Fabian Greffrath
Post by Diego Biurrun
+enum dvdcss_method {
+ DVDCSS_METHOD_KEY,
+ DVDCSS_METHOD_DISC,
+ DVDCSS_METHOD_TITLE,
+};
[...]
Post by Diego Biurrun
+ enum dvdcss_method i_method;
Why don't you use typedef enum?
I'll turn this around - why should I typedef?
Because then you could declare the variable without having to duplicate
typedef enum dvdcss_method {
...
} dvdcss_method_t;
[...]
dvdcss_method_t i_method;
And what would I have gained apart from typing 3 characters less?
Suddenly I have to lookup the real type in another header instead of being
told that it is an enum. I see absolutely no gain from this procedure.
I'm not alone with my opinion; cf. the Linux style guide wrt typedeffing
struct names.

Also, the _t namespace is reserved by POSIX, this particular name would
invade it even more.

Diego
Fabian Greffrath
2014-11-03 09:19:52 UTC
Permalink
Post by Diego Biurrun
And what would I have gained apart from typing 3 characters less?
Suddenly I have to lookup the real type in another header instead of being
told that it is an enum. I see absolutely no gain from this procedure.
I'm not alone with my opinion; cf. the Linux style guide wrt typedeffing
struct names.
I see it quite the other way round: As long as I know my variable is of
type "dvdcss_method", I don't need to care if it is actually an enum or
whatever. I got myself used to typedef enums as soon as I use them as
actual variable types and not just for enumerating, I consider that
"cleaner". But it was just a suggestion.

- Fabian

Diego Biurrun
2014-11-01 16:56:30 UTC
Permalink
Otherwise creating the tag would fail on first invocation of libdvdcss and
the tag would only be created upon the second invocation.
---
src/libdvdcss.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index af7857e..31df8d7 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -370,6 +370,13 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
char psz_tagfile[PATH_MAX + 1 + 12 + 1];
int i_fd;

+ i_ret = mkdir( psz_cache, 0755 );
+ if( i_ret < 0 && errno != EEXIST )
+ {
+ print_error( dvdcss, "failed creating cache directory" );
+ goto nocache;
+ }
+
sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache );
i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 );
if( i_fd >= 0 )
@@ -483,18 +490,9 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
psz_key[0] = 0;
}

- /* We have a disc name or ID, we can create the cache dir */
- i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache );
- i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
- if( i_ret < 0 && errno != EEXIST )
- {
- print_error( dvdcss, "failed creating cache directory" );
- dvdcss->psz_cachefile[0] = '\0';
- goto nocache;
- }
-
- i += sprintf( dvdcss->psz_cachefile + i, "/%s-%s%s", psz_title,
- psz_serial, psz_key );
+ /* We have a disc name or ID, we can create the cache subdirectory. */
+ i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s%s",
+ psz_cache, psz_title, psz_serial, psz_key );
i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
if( i_ret < 0 && errno != EEXIST )
{
--
1.9.1
Jean-Baptiste Kempf
2014-11-01 17:04:42 UTC
Permalink
LGTM. I hope it's enough tested
Post by Diego Biurrun
Otherwise creating the tag would fail on first invocation of libdvdcss and
the tag would only be created upon the second invocation.
---
src/libdvdcss.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index af7857e..31df8d7 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -370,6 +370,13 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
char psz_tagfile[PATH_MAX + 1 + 12 + 1];
int i_fd;
+ i_ret = mkdir( psz_cache, 0755 );
+ if( i_ret < 0 && errno != EEXIST )
+ {
+ print_error( dvdcss, "failed creating cache directory" );
+ goto nocache;
+ }
+
sprintf( psz_tagfile, "%s/CACHEDIR.TAG", psz_cache );
i_fd = open( psz_tagfile, O_RDWR|O_CREAT, 0644 );
if( i_fd >= 0 )
@@ -483,18 +490,9 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
psz_key[0] = 0;
}
- /* We have a disc name or ID, we can create the cache dir */
- i = sprintf( dvdcss->psz_cachefile, "%s", psz_cache );
- i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
- if( i_ret < 0 && errno != EEXIST )
- {
- print_error( dvdcss, "failed creating cache directory" );
- dvdcss->psz_cachefile[0] = '\0';
- goto nocache;
- }
-
- i += sprintf( dvdcss->psz_cachefile + i, "/%s-%s%s", psz_title,
- psz_serial, psz_key );
+ /* We have a disc name or ID, we can create the cache subdirectory. */
+ i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s%s",
+ psz_cache, psz_title, psz_serial, psz_key );
i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
if( i_ret < 0 && errno != EEXIST )
{
--
1.9.1
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Diego Biurrun
2014-11-01 16:56:31 UTC
Permalink
---
src/libdvdcss.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 31df8d7..c6ef8be 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -478,12 +478,11 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
* date and serial number, but different keys. */
if( dvdcss->b_scrambled )
{
- psz_key[0] = '-';
for( i = 0; i < KEY_SIZE; i++ )
{
- sprintf( &psz_key[1+i*2], "%.2x", dvdcss->css.p_disc_key[i] );
+ sprintf( &psz_key[i * 2], "%.2x", dvdcss->css.p_disc_key[i] );
}
- psz_key[1 + KEY_SIZE * 2] = '\0';
+ psz_key[KEY_SIZE * 2] = '\0';
}
else
{
@@ -491,7 +490,7 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
}

/* We have a disc name or ID, we can create the cache subdirectory. */
- i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s%s",
+ i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s-%s",
psz_cache, psz_title, psz_serial, psz_key );
i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
if( i_ret < 0 && errno != EEXIST )
--
1.9.1
Jean-Baptiste Kempf
2014-11-01 17:05:24 UTC
Permalink
lol. LGTM.
Post by Diego Biurrun
---
src/libdvdcss.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index 31df8d7..c6ef8be 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -478,12 +478,11 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
* date and serial number, but different keys. */
if( dvdcss->b_scrambled )
{
- psz_key[0] = '-';
for( i = 0; i < KEY_SIZE; i++ )
{
- sprintf( &psz_key[1+i*2], "%.2x", dvdcss->css.p_disc_key[i] );
+ sprintf( &psz_key[i * 2], "%.2x", dvdcss->css.p_disc_key[i] );
}
- psz_key[1 + KEY_SIZE * 2] = '\0';
+ psz_key[KEY_SIZE * 2] = '\0';
}
else
{
@@ -491,7 +490,7 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
}
/* We have a disc name or ID, we can create the cache subdirectory. */
- i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s%s",
+ i = sprintf( dvdcss->psz_cachefile, "%s/%s-%s-%s",
psz_cache, psz_title, psz_serial, psz_key );
i_ret = mkdir( dvdcss->psz_cachefile, 0755 );
if( i_ret < 0 && errno != EEXIST )
--
1.9.1
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Diego Biurrun
2014-11-01 16:56:32 UTC
Permalink
There is a buffer in the global dvdcss struct that can be used instead.
---
src/libdvdcss.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index c6ef8be..826e599 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -196,7 +196,6 @@ static int set_access_method( dvdcss_t dvdcss )
*/
LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
{
- char psz_buffer[PATH_MAX];
int i_ret;

const char *psz_cache = getenv( "DVDCSS_CACHE" );
@@ -241,9 +240,9 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
if (SHGetFolderPathA (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, psz_home ) == S_OK)
{
- snprintf( psz_buffer, PATH_MAX, "%s\\dvdcss", psz_home );
- psz_buffer[PATH_MAX-1] = '\0';
- psz_cache = psz_buffer;
+ snprintf( dvdcss->psz_cachefile, PATH_MAX, "%s\\dvdcss", psz_home );
+ dvdcss->psz_cachefile[PATH_MAX - 1] = '\0';
+ psz_cache = dvdcss->psz_cachefile;
}
#else
char *psz_home = NULL;
@@ -282,15 +281,15 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
psz_unixroot[1] == ':' &&
psz_unixroot[2] == '\0')
{
- strcpy( psz_buffer, psz_unixroot );
+ strcpy( dvdcss->psz_cachefile, psz_unixroot );
home_pos = 2;
}
}
#endif /* __OS2__ */
- snprintf( psz_buffer + home_pos, PATH_MAX - home_pos,
+ snprintf( dvdcss->psz_cachefile + home_pos, PATH_MAX - home_pos,
"%s/.dvdcss", psz_home );
- psz_buffer[PATH_MAX-1] = '\0';
- psz_cache = psz_buffer;
+ dvdcss->psz_cachefile[PATH_MAX - 1] = '\0';
+ psz_cache = dvdcss->psz_cachefile;
}
#endif /* ! defined(_WIN32_IE) && _WIN32_IE >= 0x500 */
}
--
1.9.1
Jean-Baptiste Kempf
2014-11-01 17:07:48 UTC
Permalink
OK.
Post by Diego Biurrun
There is a buffer in the global dvdcss struct that can be used instead.
---
src/libdvdcss.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index c6ef8be..826e599 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -196,7 +196,6 @@ static int set_access_method( dvdcss_t dvdcss )
*/
LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
{
- char psz_buffer[PATH_MAX];
int i_ret;
const char *psz_cache = getenv( "DVDCSS_CACHE" );
@@ -241,9 +240,9 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
if (SHGetFolderPathA (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, psz_home ) == S_OK)
{
- snprintf( psz_buffer, PATH_MAX, "%s\\dvdcss", psz_home );
- psz_buffer[PATH_MAX-1] = '\0';
- psz_cache = psz_buffer;
+ snprintf( dvdcss->psz_cachefile, PATH_MAX, "%s\\dvdcss", psz_home );
+ dvdcss->psz_cachefile[PATH_MAX - 1] = '\0';
+ psz_cache = dvdcss->psz_cachefile;
}
#else
char *psz_home = NULL;
@@ -282,15 +281,15 @@ LIBDVDCSS_EXPORT dvdcss_t dvdcss_open ( const char *psz_target )
psz_unixroot[1] == ':' &&
psz_unixroot[2] == '\0')
{
- strcpy( psz_buffer, psz_unixroot );
+ strcpy( dvdcss->psz_cachefile, psz_unixroot );
home_pos = 2;
}
}
#endif /* __OS2__ */
- snprintf( psz_buffer + home_pos, PATH_MAX - home_pos,
+ snprintf( dvdcss->psz_cachefile + home_pos, PATH_MAX - home_pos,
"%s/.dvdcss", psz_home );
- psz_buffer[PATH_MAX-1] = '\0';
- psz_cache = psz_buffer;
+ dvdcss->psz_cachefile[PATH_MAX - 1] = '\0';
+ psz_cache = dvdcss->psz_cachefile;
}
#endif /* ! defined(_WIN32_IE) && _WIN32_IE >= 0x500 */
}
--
1.9.1
_______________________________________________
libdvdcss-devel mailing list
https://mailman.videolan.org/listinfo/libdvdcss-devel
--
With my kindest regards,
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
Loading...