summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lilv_internal.h5
-rw-r--r--src/plugin.c12
-rw-r--r--src/world.c82
3 files changed, 56 insertions, 43 deletions
diff --git a/src/lilv_internal.h b/src/lilv_internal.h
index 567fcea..f8fcec6 100644
--- a/src/lilv_internal.h
+++ b/src/lilv_internal.h
@@ -275,7 +275,10 @@ LilvPluginClasses* lilv_plugin_classes_new(void);
LilvUIs* lilv_uis_new(void);
const uint8_t* lilv_world_blank_node_prefix(LilvWorld* world);
-void lilv_world_load_file(LilvWorld* world, const char* file_uri);
+
+SerdStatus lilv_world_load_file(LilvWorld* world,
+ SerdReader* reader,
+ const LilvNode* uri);
LilvUI* lilv_ui_new(LilvWorld* world,
LilvNode* uri,
diff --git a/src/plugin.c b/src/plugin.c
index b0a726e..cc1bdba 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -166,14 +166,10 @@ lilv_plugin_load(LilvPlugin* p)
// Parse all the plugin's data files into RDF model
LILV_FOREACH(nodes, i, p->data_uris) {
- const LilvNode* data_uri_val = lilv_nodes_get(p->data_uris, i);
- const SordNode* data_uri_node = data_uri_val->node;
- const char* data_uri_str = lilv_node_as_uri(data_uri_val);
-
- serd_env_set_base_uri(env, sord_node_to_serd_node(data_uri_node));
- serd_reader_add_blank_prefix(reader,
- lilv_world_blank_node_prefix(p->world));
- serd_reader_read_file(reader, (const uint8_t*)data_uri_str);
+ const LilvNode* data_uri = lilv_nodes_get(p->data_uris, i);
+
+ serd_env_set_base_uri(env, sord_node_to_serd_node(data_uri->node));
+ lilv_world_load_file(p->world, reader, data_uri);
}
#ifdef LILV_DYN_MANIFEST
diff --git a/src/world.c b/src/world.c
index 5e1142a..e89a23f 100644
--- a/src/world.c
+++ b/src/world.c
@@ -533,18 +533,18 @@ lilv_world_load_bundle(LilvWorld* world, LilvNode* bundle_uri)
return;
}
- SordNode* bundle_node = bundle_uri->node;
-
- SerdNode manifest_uri = lilv_new_uri_relative_to_base(
+ SordNode* bundle_node = bundle_uri->node;
+ SerdNode manifest_uri = lilv_new_uri_relative_to_base(
(const uint8_t*)"manifest.ttl",
(const uint8_t*)sord_node_get_string(bundle_node));
- SerdEnv* env = serd_env_new(&manifest_uri);
- SerdReader* reader = sord_new_reader(world->model, env, SERD_TURTLE,
- bundle_node);
- serd_reader_add_blank_prefix(reader, lilv_world_blank_node_prefix(world));
+ LilvNode* manifest = lilv_new_uri(world, (const char*)manifest_uri.buf);
+ SerdEnv* env = serd_env_new(&manifest_uri);
+ SerdReader* reader = sord_new_reader(
+ world->model, env, SERD_TURTLE, bundle_node);
- SerdStatus st = serd_reader_read_file(reader, manifest_uri.buf);
+ SerdStatus st = lilv_world_load_file(world, reader, manifest);
+ lilv_node_free(manifest);
serd_reader_free(reader);
serd_env_free(env);
if (st) {
@@ -752,6 +752,28 @@ lilv_world_load_all(LilvWorld* world)
lilv_world_load_plugin_classes(world);
}
+SerdStatus
+lilv_world_load_file(LilvWorld* world, SerdReader* reader, const LilvNode* uri)
+{
+ ZixTreeIter* iter;
+ if (!zix_tree_find((ZixTree*)world->loaded_files, uri, &iter)) {
+ return SERD_FAILURE; // File has already been loaded
+ }
+
+ serd_reader_add_blank_prefix(reader, lilv_world_blank_node_prefix(world));
+ const uint8_t* uri_str = sord_node_get_string(uri->node);
+ SerdStatus st = serd_reader_read_file(reader, uri_str);
+ if (st) {
+ LILV_ERRORF("Error loading file `%s'\n", lilv_node_as_string(uri));
+ return st;
+ }
+
+ zix_tree_insert((ZixTree*)world->loaded_files,
+ lilv_node_duplicate(uri),
+ NULL);
+ return SERD_SUCCESS;
+}
+
LILV_API
int
lilv_world_load_resource(LilvWorld* world,
@@ -769,33 +791,25 @@ lilv_world_load_resource(LilvWorld* world,
world->uris.rdfs_seeAlso,
NULL, NULL);
FOREACH_MATCH(files) {
- const SordNode* file = sord_iter_get_node(files, SORD_OBJECT);
- const uint8_t* str = sord_node_get_string(file);
- LilvNode* file_node = lilv_node_new_from_node(world, file);
- ZixTreeIter* iter;
- if (zix_tree_find((ZixTree*)world->loaded_files, file_node, &iter)) {
- if (sord_node_get_type(file) == SORD_URI) {
- const SerdNode* base = sord_node_to_serd_node(file);
- SerdEnv* env = serd_env_new(base);
- SerdReader* reader = sord_new_reader(
- world->model, env, SERD_TURTLE, (SordNode*)file);
- serd_reader_add_blank_prefix(
- reader, lilv_world_blank_node_prefix(world));
- if (!serd_reader_read_file(reader, str)) {
- ++n_read;
- zix_tree_insert(
- (ZixTree*)world->loaded_files, file_node, NULL);
- file_node = NULL; // prevent deletion...
- } else {
- LILV_ERRORF("Error loading resource `%s'\n", str);
- }
- serd_reader_free(reader);
- serd_env_free(env);
- } else {
- LILV_ERRORF("rdfs:seeAlso node `%s' is not a URI\n", str);
- }
+ const SordNode* file = sord_iter_get_node(files, SORD_OBJECT);
+ const uint8_t* str = sord_node_get_string(file);
+ if (sord_node_get_type(file) != SORD_URI) {
+ LILV_ERRORF("rdfs:seeAlso node `%s' is not a URI\n", str);
+ continue;
}
- lilv_node_free(file_node); // ...here
+
+ LilvNode* file_node = lilv_node_new_from_node(world, file);
+ SerdEnv* env = serd_env_new(sord_node_to_serd_node(file));
+ SerdReader* reader = sord_new_reader(
+ world->model, env, SERD_TURTLE, (SordNode*)file);
+
+ if (!lilv_world_load_file(world, reader, file_node)) {
+ ++n_read;
+ }
+
+ lilv_node_free(file_node);
+ serd_reader_free(reader);
+ serd_env_free(env);
}
sord_iter_free(files);