libaacs | branch: master | npzacs <npz...@gmail.com> | Mon Jan 5 16:09:56 2015 +0200| [71ab9e6a08a52845bcd56cf729f78dc0c585c273] | committer: npzacs
add aacs_set_fopen() Old filesystem handler was global and did not have any application-specific callback handle. > http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=71ab9e6a08a52845bcd56cf729f78dc0c585c273 --- src/file/filesystem.h | 23 +++++++++++++++++++++ src/libaacs/aacs.c | 53 ++++++++++++++++++++++++++++++++++++++----------- src/libaacs/aacs.h | 4 ++++ 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/file/filesystem.h b/src/file/filesystem.h index c0c060b..d038a70 100644 --- a/src/file/filesystem.h +++ b/src/file/filesystem.h @@ -45,5 +45,28 @@ typedef AACS_FILE_H* (*AACS_FILE_OPEN)(const char* filename, const char *mode); */ AACS_FILE_OPEN aacs_register_file(AACS_FILE_OPEN p); +/** + * + * Function that will be used to open a file + * + * NOTE: file name is relative to disc root directory ! + * + * @param handle application-specific handle + * @param filename file to open + * @return pointer to AACS_FILE_H, NULL if error + */ +typedef AACS_FILE_H* (*AACS_FILE_OPEN2)(void *handle, const char* filename); + +/** + * + * Register function pointer that will be used to open a file + * + * @param aacs aacs instance + * @param handle handle that will be passed to file open function + * @param p function pointer + */ +struct aacs; +void aacs_set_fopen(struct aacs *aacs, void *handle, AACS_FILE_OPEN2 p); + #endif /* AACS_FILESYSTEM_H_ */ diff --git a/src/libaacs/aacs.c b/src/libaacs/aacs.c index 729250f..02eb409 100644 --- a/src/libaacs/aacs.c +++ b/src/libaacs/aacs.c @@ -49,6 +49,9 @@ struct aacs { + void *fopen_handle; + AACS_FILE_OPEN2 fopen; + /* current disc */ char *path; int mkb_version; @@ -375,6 +378,10 @@ static AACS_FILE_H *_file_open(AACS *aacs, const char *file) AACS_FILE_H *fp; char *f_name; + if (aacs->fopen) { + return aacs->fopen(aacs->fopen_handle, file); + } + f_name = str_printf("%s/%s", aacs->path, file); fp = file_open(f_name, "rb"); X_FREE(f_name); @@ -957,8 +964,18 @@ AACS *aacs_open(const char *path, const char *configfile_path) return NULL; } +/* aacs_open_device() wrapper for backward compability */ AACS *aacs_open2(const char *path, const char *configfile_path, int *error_code) { + AACS *aacs = aacs_init(); + if (aacs) { + *error_code = aacs_open_device(aacs, path, configfile_path); + } + return aacs; +} + +AACS *aacs_init() +{ DEBUG(DBG_AACS, "libaacs "AACS_VERSION_STRING" [%u]\n", (unsigned)sizeof(AACS)); DEBUG(DBG_AACS, "Initializing libgcrypt...\n"); @@ -967,37 +984,49 @@ AACS *aacs_open2(const char *path, const char *configfile_path, int *error_code) return NULL; } - AACS *aacs = calloc(1, sizeof(AACS)); + return calloc(1, sizeof(AACS)); +} + +void aacs_set_fopen(AACS *aacs, void *handle, AACS_FILE_OPEN2 p) +{ + if (aacs) { + aacs->fopen = p; + aacs->fopen_handle = handle; + } +} + +int aacs_open_device(AACS *aacs, const char *path, const char *configfile_path) +{ config_file *cf; + int error_code; aacs->path = str_printf("%s", path); - *error_code = _calc_title_hash(aacs); - if (*error_code != AACS_SUCCESS) { + error_code = _calc_title_hash(aacs); + if (error_code != AACS_SUCCESS) { aacs_close(aacs); - return NULL; + return error_code; } cf = keydbcfg_config_load(configfile_path); DEBUG(DBG_AACS, "Starting AACS waterfall...\n"); - *error_code = _calc_uks(aacs, cf); - if (*error_code != AACS_SUCCESS) { + error_code = _calc_uks(aacs, cf); + if (error_code != AACS_SUCCESS) { DEBUG(DBG_AACS, "Failed to initialize AACS!\n"); } aacs->bee = _get_bus_encryption_enabled(aacs); aacs->bec = _get_bus_encryption_capable(path); - if (*error_code == AACS_SUCCESS && aacs->bee && aacs->bec) { + if (error_code == AACS_SUCCESS && aacs->bee && aacs->bec) { if (!cf) { - *error_code = AACS_ERROR_NO_CONFIG; - return aacs; + return AACS_ERROR_NO_CONFIG; } - *error_code = _read_read_data_key(aacs, cf->host_cert_list); - if (*error_code != AACS_SUCCESS) { + error_code = _read_read_data_key(aacs, cf->host_cert_list); + if (error_code != AACS_SUCCESS) { DEBUG(DBG_AACS | DBG_CRIT, "Unable to initialize bus encryption required by drive and disc\n"); } } @@ -1006,7 +1035,7 @@ AACS *aacs_open2(const char *path, const char *configfile_path, int *error_code) DEBUG(DBG_AACS, "AACS initialized!\n"); - return aacs; + return error_code; } void aacs_close(AACS *aacs) diff --git a/src/libaacs/aacs.h b/src/libaacs/aacs.h index fe64bc8..0d306ef 100644 --- a/src/libaacs/aacs.h +++ b/src/libaacs/aacs.h @@ -42,8 +42,12 @@ typedef struct aacs AACS; AACS_PUBLIC void aacs_get_version(int *major, int *minor, int *micro); +AACS_PUBLIC AACS *aacs_init (void); +AACS_PUBLIC int aacs_open_device(AACS *, const char *path, const char *keyfile_path); + AACS_PUBLIC AACS *aacs_open(const char *path, const char *keyfile_path); AACS_PUBLIC AACS *aacs_open2(const char *path, const char *keyfile_path, int *error_code); + AACS_PUBLIC void aacs_close(AACS *aacs); AACS_PUBLIC void aacs_select_title(AACS *aacs, uint32_t title); /* 0 - top menu, 0xffff - first play */ AACS_PUBLIC int aacs_decrypt_unit(AACS *aacs, uint8_t *buf); _______________________________________________ libaacs-devel mailing list libaacs-devel@videolan.org https://mailman.videolan.org/listinfo/libaacs-devel