Example #1
0
META_ROOT *meta_parse(BD_DISC *disc)
{
#ifdef HAVE_LIBXML2
    META_ROOT *root = calloc(1, sizeof(META_ROOT));
    if (!root) {
        BD_DEBUG(DBG_CRIT, "out of memory\n");
        return NULL;
    }
    root->dl_count = 0;

    xmlDocPtr doc;
    _findMetaXMLfiles(root, disc);

    uint8_t i;
    for (i = 0; i < root->dl_count; i++) {
        uint8_t *data = NULL;
        size_t size;
        size = disc_read_file(disc, "BDMV" DIR_SEP "META" DIR_SEP "DL",
                              root->dl_entries[i].filename,
                              &data);
        if (!data || size == 0) {
            BD_DEBUG(DBG_DIR, "Failed to read BDMV/META/DL/%s\n", root->dl_entries[i].filename);
        } else {
                doc = xmlReadMemory((char*)data, (int)size, NULL, NULL, 0);
                if (doc == NULL) {
                    BD_DEBUG(DBG_DIR, "Failed to parse BDMV/META/DL/%s\n", root->dl_entries[i].filename);
                } else {
                    xmlNode *root_element = NULL;
                    root_element = xmlDocGetRootElement(doc);
                    root->dl_entries[i].di_name = root->dl_entries[i].di_alternative = NULL;
                    root->dl_entries[i].di_num_sets = root->dl_entries[i].di_set_number = -1;
                    root->dl_entries[i].toc_count = root->dl_entries[i].thumb_count = 0;
                    root->dl_entries[i].toc_entries = NULL;
                    root->dl_entries[i].thumbnails = NULL;
                    _parseManifestNode(root_element, &root->dl_entries[i]);
                    xmlFreeDoc(doc);
                }
            X_FREE(data);
        }
    }
    xmlCleanupParser();
    return root;
#else
    (void)disc;
    BD_DEBUG(DBG_DIR, "configured without libxml2 - can't parse meta info\n");
    return NULL;
#endif
}
Example #2
0
META_ROOT *meta_parse(const char *device_path)
{
#ifdef HAVE_LIBXML2
    META_ROOT *root = calloc(1, sizeof(META_ROOT));
    root->dl_count = 0;

    xmlDocPtr doc;
    _findMetaXMLfiles(root, device_path);

    uint8_t i;
    for (i = 0; i < root->dl_count; i++) {
        char *base = NULL;
        base = str_printf("%s" DIR_SEP "BDMV" DIR_SEP "META" DIR_SEP "DL" , device_path);
        char *path = NULL;
        path = str_printf("%s" DIR_SEP "%s", base, root->dl_entries[i].filename);

        BD_FILE_H *handle = file_open(path, "rb");
        if (handle == NULL) {
            BD_DEBUG(DBG_DIR, "Failed to open meta file (%s)\n", path);
            X_FREE(path);
            X_FREE(base);
            continue;
        }

        file_seek(handle, 0, SEEK_END);
        int64_t length = file_tell(handle);

        if (length > 0 && length < MAX_META_FILE_SIZE) {
            file_seek(handle, 0, SEEK_SET);
            size_t size = (size_t)length;
            uint8_t *data = malloc(size);
            size_t size_read = file_read(handle, data, size);
            if (size != size_read) {
                BD_DEBUG(DBG_DIR, "Failed to read %s\n", path);
            } else {
                doc = xmlReadMemory((char*)data, (int)size, base, NULL, 0);
                if (doc == NULL) {
                    BD_DEBUG(DBG_DIR, "Failed to parse %s\n", path);
                } else {
                    xmlNode *root_element = NULL;
                    root_element = xmlDocGetRootElement(doc);
                    root->dl_entries[i].di_name = root->dl_entries[i].di_alternative = NULL;
                    root->dl_entries[i].di_num_sets = root->dl_entries[i].di_set_number = -1;
                    root->dl_entries[i].toc_count = root->dl_entries[i].thumb_count = 0;
                    root->dl_entries[i].toc_entries = NULL;
                    root->dl_entries[i].thumbnails = NULL;
                    _parseManifestNode(root_element, &root->dl_entries[i]);
                    xmlFreeDoc(doc);
                }
            }
            X_FREE(data);
        }
        file_close(handle);
        X_FREE(path);
        X_FREE(base);
    }
    xmlCleanupParser();
    return root;
#else
    BD_DEBUG(DBG_DIR, "configured without libxml2 - can't parse meta info\n");
    return NULL;
#endif
}