summaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c627
1 files changed, 286 insertions, 341 deletions
diff --git a/src/world.c b/src/world.c
index 47dc147..31fa906 100644
--- a/src/world.c
+++ b/src/world.c
@@ -19,14 +19,13 @@
#include "lilv_internal.h"
#include "lilv/lilv.h"
+#include "lv2/core/lv2.h"
+#include "lv2/presets/presets.h"
+#include "lv2/state/state.h"
#include "serd/serd.h"
-#include "sord/sord.h"
#include "zix/common.h"
#include "zix/tree.h"
-#include "lv2/core/lv2.h"
-#include "lv2/presets/presets.h"
-
#ifdef LILV_DYN_MANIFEST
# include "lv2/dynmanifest/dynmanifest.h"
# include <dlfcn.h>
@@ -34,25 +33,25 @@
#include <assert.h>
#include <stdbool.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int
-lilv_world_drop_graph(LilvWorld* world, const SordNode* graph);
+lilv_world_drop_graph(LilvWorld* world, const SerdNode* graph);
LilvWorld*
lilv_world_new(void)
{
LilvWorld* world = (LilvWorld*)calloc(1, sizeof(LilvWorld));
- world->world = sord_world_new();
+ world->world = serd_world_new();
if (!world->world) {
goto fail;
}
- world->model = sord_new(world->world, SORD_SPO | SORD_OPS, true);
+ world->model = serd_model_new(
+ world->world, SERD_INDEX_SPO | SERD_INDEX_OPS | SERD_INDEX_GRAPHS);
if (!world->model) {
goto fail;
}
@@ -70,7 +69,7 @@ lilv_world_new(void)
#define NS_DYNMAN "http://lv2plug.in/ns/ext/dynmanifest#"
#define NS_OWL "http://www.w3.org/2002/07/owl#"
-#define NEW_URI(uri) sord_new_uri(world->world, (const uint8_t*)(uri))
+#define NEW_URI(uri) serd_new_uri(SERD_STATIC_STRING(uri))
world->uris.dc_replaces = NEW_URI(NS_DCTERMS "replaces");
world->uris.dman_DynManifest = NEW_URI(NS_DYNMAN "DynManifest");
@@ -94,9 +93,11 @@ lilv_world_new(void)
world->uris.lv2_portProperty = NEW_URI(LV2_CORE__portProperty);
world->uris.lv2_reportsLatency = NEW_URI(LV2_CORE__reportsLatency);
world->uris.lv2_requiredFeature = NEW_URI(LV2_CORE__requiredFeature);
- world->uris.lv2_symbol = NEW_URI(LV2_CORE__symbol);
+ world->uris.lv2_project = NEW_URI(LV2_CORE__project);
world->uris.lv2_prototype = NEW_URI(LV2_CORE__prototype);
+ world->uris.lv2_symbol = NEW_URI(LV2_CORE__symbol);
world->uris.owl_Ontology = NEW_URI(NS_OWL "Ontology");
+ world->uris.pset_Preset = NEW_URI(LV2_PRESETS__Preset);
world->uris.pset_value = NEW_URI(LV2_PRESETS__value);
world->uris.rdf_a = NEW_URI(LILV_NS_RDF "type");
world->uris.rdf_value = NEW_URI(LILV_NS_RDF "value");
@@ -104,10 +105,12 @@ lilv_world_new(void)
world->uris.rdfs_label = NEW_URI(LILV_NS_RDFS "label");
world->uris.rdfs_seeAlso = NEW_URI(LILV_NS_RDFS "seeAlso");
world->uris.rdfs_subClassOf = NEW_URI(LILV_NS_RDFS "subClassOf");
+ world->uris.state_state = NEW_URI(LV2_STATE__state);
world->uris.xsd_base64Binary = NEW_URI(LILV_NS_XSD "base64Binary");
world->uris.xsd_boolean = NEW_URI(LILV_NS_XSD "boolean");
world->uris.xsd_decimal = NEW_URI(LILV_NS_XSD "decimal");
world->uris.xsd_double = NEW_URI(LILV_NS_XSD "double");
+ world->uris.xsd_int = NEW_URI(LILV_NS_XSD "int");
world->uris.xsd_integer = NEW_URI(LILV_NS_XSD "integer");
world->uris.null_uri = NULL;
@@ -136,14 +139,14 @@ lilv_world_free(LilvWorld* world)
lilv_plugin_class_free(world->lv2_plugin_class);
world->lv2_plugin_class = NULL;
- for (SordNode** n = (SordNode**)&world->uris; *n; ++n) {
- sord_node_free(world->world, *n);
+ for (SerdNode** n = (SerdNode**)&world->uris; *n; ++n) {
+ serd_node_free(*n);
}
for (LilvSpec* spec = world->specs; spec;) {
LilvSpec* next = spec->next;
- sord_node_free(world->world, spec->spec);
- sord_node_free(world->world, spec->bundle);
+ serd_node_free(spec->spec);
+ serd_node_free(spec->bundle);
lilv_nodes_free(spec->data_uris);
free(spec);
spec = next;
@@ -173,10 +176,10 @@ lilv_world_free(LilvWorld* world)
zix_tree_free((ZixTree*)world->plugin_classes);
world->plugin_classes = NULL;
- sord_free(world->model);
+ serd_model_free(world->model);
world->model = NULL;
- sord_world_free(world->world);
+ serd_world_free(world->world);
world->world = NULL;
free(world->opt.lv2_path);
@@ -212,31 +215,20 @@ lilv_world_find_nodes(LilvWorld* world,
const LilvNode* object)
{
if (subject && !lilv_node_is_uri(subject) && !lilv_node_is_blank(subject)) {
- LILV_ERRORF("Subject `%s' is not a resource\n",
- sord_node_get_string(subject->node));
+ LILV_ERRORF("Subject `%s' is not a resource\n", serd_node_string(subject));
return NULL;
- }
-
- if (!predicate) {
+ } else if (!predicate) {
LILV_ERROR("Missing required predicate\n");
return NULL;
- }
-
- if (!lilv_node_is_uri(predicate)) {
- LILV_ERRORF("Predicate `%s' is not a URI\n",
- sord_node_get_string(predicate->node));
+ } else if (!lilv_node_is_uri(predicate)) {
+ LILV_ERRORF("Predicate `%s' is not a URI\n", serd_node_string(predicate));
return NULL;
- }
-
- if (!subject && !object) {
+ } else if (!subject && !object) {
LILV_ERROR("Both subject and object are NULL\n");
return NULL;
}
- return lilv_world_find_nodes_internal(world,
- subject ? subject->node : NULL,
- predicate->node,
- object ? object->node : NULL);
+ return lilv_world_find_nodes_internal(world, subject, predicate, object);
}
LilvNode*
@@ -245,52 +237,8 @@ lilv_world_get(LilvWorld* world,
const LilvNode* predicate,
const LilvNode* object)
{
- if (!object) {
- // TODO: Improve performance (see lilv_plugin_get_one)
- SordIter* stream = sord_search(world->model,
- subject ? subject->node : NULL,
- predicate ? predicate->node : NULL,
- NULL,
- NULL);
-
- LilvNodes* nodes =
- lilv_nodes_from_stream_objects(world, stream, SORD_OBJECT);
-
- if (nodes) {
- LilvNode* value = lilv_node_duplicate(lilv_nodes_get_first(nodes));
- lilv_nodes_free(nodes);
- return value;
- }
-
- return NULL;
- }
-
- SordNode* snode = sord_get(world->model,
- subject ? subject->node : NULL,
- predicate ? predicate->node : NULL,
- object ? object->node : NULL,
- NULL);
- LilvNode* lnode = lilv_node_new_from_node(world, snode);
- sord_node_free(world->world, snode);
- return lnode;
-}
-
-SordIter*
-lilv_world_query_internal(LilvWorld* world,
- const SordNode* subject,
- const SordNode* predicate,
- const SordNode* object)
-{
- return sord_search(world->model, subject, predicate, object, NULL);
-}
-
-bool
-lilv_world_ask_internal(LilvWorld* world,
- const SordNode* subject,
- const SordNode* predicate,
- const SordNode* object)
-{
- return sord_ask(world->model, subject, predicate, object, NULL);
+ return serd_node_copy(
+ serd_model_get(world->model, subject, predicate, object, NULL));
}
bool
@@ -299,59 +247,44 @@ lilv_world_ask(LilvWorld* world,
const LilvNode* predicate,
const LilvNode* object)
{
- return sord_ask(world->model,
- subject ? subject->node : NULL,
- predicate ? predicate->node : NULL,
- object ? object->node : NULL,
- NULL);
+ return serd_model_ask(world->model, subject, predicate, object, NULL);
}
-SordModel*
+SerdModel*
lilv_world_filter_model(LilvWorld* world,
- SordModel* model,
- const SordNode* subject,
- const SordNode* predicate,
- const SordNode* object,
- const SordNode* graph)
+ SerdModel* model,
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const SerdNode* object,
+ const SerdNode* graph)
{
- SordModel* results = sord_new(world->world, SORD_SPO, false);
- SordIter* i = sord_search(model, subject, predicate, object, graph);
- for (; !sord_iter_end(i); sord_iter_next(i)) {
- SordQuad quad;
- sord_iter_get(i, quad);
- sord_add(results, quad);
+ SerdModel* results = serd_model_new(world->world, SERD_INDEX_SPO);
+ SerdRange* r = serd_model_range(model, subject, predicate, object, graph);
+ for (; !serd_range_empty(r); serd_range_next(r)) {
+ serd_model_insert(results, serd_range_front(r));
}
- sord_iter_free(i);
+ serd_range_free(r);
return results;
}
LilvNodes*
lilv_world_find_nodes_internal(LilvWorld* world,
- const SordNode* subject,
- const SordNode* predicate,
- const SordNode* object)
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const SerdNode* object)
{
- return lilv_nodes_from_stream_objects(
+ return lilv_nodes_from_range(
world,
- lilv_world_query_internal(world, subject, predicate, object),
- (object == NULL) ? SORD_OBJECT : SORD_SUBJECT);
-}
-
-static SerdNode
-lilv_new_uri_relative_to_base(const uint8_t* uri_str,
- const uint8_t* base_uri_str)
-{
- SerdURI base_uri;
- serd_uri_parse(base_uri_str, &base_uri);
- return serd_node_new_uri_from_string(uri_str, &base_uri, NULL);
+ serd_model_range(world->model, subject, predicate, object, NULL),
+ (object == NULL) ? SERD_OBJECT : SERD_SUBJECT);
}
-const uint8_t*
+const char*
lilv_world_blank_node_prefix(LilvWorld* world)
{
static char str[32];
snprintf(str, sizeof(str), "%u", world->n_read_files++);
- return (const uint8_t*)str;
+ return str;
}
/** Comparator for sequences (e.g. world->plugins). */
@@ -411,24 +344,21 @@ lilv_collection_get_by_uri(const ZixTree* seq, const LilvNode* uri)
static void
lilv_world_add_spec(LilvWorld* world,
- const SordNode* specification_node,
- const SordNode* bundle_node)
+ const SerdNode* specification_node,
+ const SerdNode* bundle_node)
{
LilvSpec* spec = (LilvSpec*)malloc(sizeof(LilvSpec));
- spec->spec = sord_node_copy(specification_node);
- spec->bundle = sord_node_copy(bundle_node);
+ spec->spec = serd_node_copy(specification_node);
+ spec->bundle = serd_node_copy(bundle_node);
spec->data_uris = lilv_nodes_new();
// Add all data files (rdfs:seeAlso)
- SordIter* files = sord_search(
- world->model, specification_node, world->uris.rdfs_seeAlso, NULL, NULL);
- FOREACH_MATCH (files) {
- const SordNode* file_node = sord_iter_get_node(files, SORD_OBJECT);
- zix_tree_insert((ZixTree*)spec->data_uris,
- lilv_node_new_from_node(world, file_node),
- NULL);
+ FOREACH_PAT(
+ s, world->model, specification_node, world->uris.rdfs_seeAlso, NULL, NULL)
+ {
+ const SerdNode* file_node = serd_statement_object(s);
+ zix_tree_insert((ZixTree*)spec->data_uris, serd_node_copy(file_node), NULL);
}
- sord_iter_free(files);
// Add specification to world specification list
spec->next = world->specs;
@@ -437,15 +367,12 @@ lilv_world_add_spec(LilvWorld* world,
static void
lilv_world_add_plugin(LilvWorld* world,
- const SordNode* plugin_node,
+ const SerdNode* plugin_uri,
const LilvNode* manifest_uri,
void* dynmanifest,
- const SordNode* bundle)
+ const SerdNode* bundle)
{
- (void)dynmanifest;
-
- LilvNode* plugin_uri = lilv_node_new_from_node(world, plugin_node);
- ZixTreeIter* z = NULL;
+ ZixTreeIter* z = NULL;
LilvPlugin* plugin =
(LilvPlugin*)lilv_plugins_get_by_uri(world->plugins, plugin_uri);
@@ -454,15 +381,13 @@ lilv_world_add_plugin(LilvWorld* world,
// (use the first plugin found in LV2_PATH)
const LilvNode* last_bundle = lilv_plugin_get_bundle_uri(plugin);
const char* plugin_uri_str = lilv_node_as_uri(plugin_uri);
- if (sord_node_equals(bundle, last_bundle->node)) {
+ if (serd_node_equals(bundle, last_bundle)) {
LILV_WARNF("Reloading plugin <%s>\n", plugin_uri_str);
plugin->loaded = false;
- lilv_node_free(plugin_uri);
} else {
LILV_WARNF("Duplicate plugin <%s>\n", plugin_uri_str);
LILV_WARNF("... found in %s\n", lilv_node_as_string(last_bundle));
- LILV_WARNF("... and %s (ignored)\n", sord_node_get_string(bundle));
- lilv_node_free(plugin_uri);
+ LILV_WARNF("... and %s (ignored)\n", serd_node_string(bundle));
return;
}
} else if ((z = lilv_collection_find_by_uri((const ZixTree*)world->zombies,
@@ -471,12 +396,10 @@ lilv_world_add_plugin(LilvWorld* world,
plugin = (LilvPlugin*)zix_tree_get(z);
zix_tree_remove((ZixTree*)world->zombies, z);
zix_tree_insert((ZixTree*)world->plugins, plugin, NULL);
- lilv_node_free(plugin_uri);
- lilv_plugin_clear(plugin, lilv_node_new_from_node(world, bundle));
+ lilv_plugin_clear(plugin, bundle);
} else {
// Add new plugin to the world
- plugin = lilv_plugin_new(
- world, plugin_uri, lilv_node_new_from_node(world, bundle));
+ plugin = lilv_plugin_new(world, plugin_uri, bundle);
// Add manifest as plugin data file (as if it were rdfs:seeAlso)
zix_tree_insert(
@@ -492,37 +415,40 @@ lilv_world_add_plugin(LilvWorld* world,
plugin->dynmanifest = (LilvDynManifest*)dynmanifest;
++((LilvDynManifest*)dynmanifest)->refs;
}
+#else
+ (void)dynmanifest;
#endif
// Add all plugin data files (rdfs:seeAlso)
- SordIter* files = sord_search(
- world->model, plugin_node, world->uris.rdfs_seeAlso, NULL, NULL);
- FOREACH_MATCH (files) {
- const SordNode* file_node = sord_iter_get_node(files, SORD_OBJECT);
- zix_tree_insert((ZixTree*)plugin->data_uris,
- lilv_node_new_from_node(world, file_node),
- NULL);
+ FOREACH_PAT(s, world->model, plugin_uri, world->uris.rdfs_seeAlso, NULL, NULL)
+ {
+ const SerdNode* file_node = serd_statement_object(s);
+ zix_tree_insert(
+ (ZixTree*)plugin->data_uris, serd_node_copy(file_node), NULL);
}
- sord_iter_free(files);
}
SerdStatus
-lilv_world_load_graph(LilvWorld* world, SordNode* graph, const LilvNode* uri)
+lilv_world_load_graph(LilvWorld* world,
+ const SerdNode* graph,
+ const LilvNode* uri)
{
- const SerdNode* base = sord_node_to_serd_node(uri->node);
- SerdEnv* env = serd_env_new(base);
- SerdReader* reader = sord_new_reader(world->model, env, SERD_TURTLE, graph);
+ SerdEnv* env = serd_env_new(serd_node_string_view(uri));
+ SerdSink* inserter = serd_inserter_new(world->model, graph);
+ SerdReader* reader = serd_reader_new(
+ world->world, SERD_TURTLE, 0, env, inserter, LILV_READER_STACK_SIZE);
const SerdStatus st = lilv_world_load_file(world, reader, uri);
- serd_env_free(env);
serd_reader_free(reader);
+ serd_sink_free(inserter);
+ serd_env_free(env);
return st;
}
static void
lilv_world_load_dyn_manifest(LilvWorld* world,
- SordNode* bundle_node,
+ const SerdNode* bundle_node,
const LilvNode* manifest)
{
#ifdef LILV_DYN_MANIFEST
@@ -533,33 +459,33 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
LV2_Dyn_Manifest_Handle handle = NULL;
// ?dman a dynman:DynManifest bundle_node
- SordModel* model = lilv_world_filter_model(world,
+ SerdModel* model = lilv_world_filter_model(world,
world->model,
NULL,
world->uris.rdf_a,
world->uris.dman_DynManifest,
bundle_node);
- SordIter* iter = sord_begin(model);
- for (; !sord_iter_end(iter); sord_iter_next(iter)) {
- const SordNode* dmanifest = sord_iter_get_node(iter, SORD_SUBJECT);
+ SerdIter* iter = serd_begin(model);
+ for (; !serd_iter_end(iter); serd_iter_next(iter)) {
+ const SerdNode* dmanifest = serd_iter_get_node(iter, SERD_SUBJECT);
// ?dman lv2:binary ?binary
- SordIter* binaries = sord_search(
+ SerdIter* binaries = serd_model_find(
world->model, dmanifest, world->uris.lv2_binary, NULL, bundle_node);
- if (sord_iter_end(binaries)) {
- sord_iter_free(binaries);
+ if (serd_iter_end(binaries)) {
+ serd_iter_free(binaries);
LILV_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n",
- sord_node_get_string(bundle_node));
+ serd_node_string(bundle_node));
continue;
}
// Get binary path
- const SordNode* binary = sord_iter_get_node(binaries, SORD_OBJECT);
- const uint8_t* lib_uri = sord_node_get_string(binary);
- char* lib_path = lilv_file_uri_parse((const char*)lib_uri, 0);
+ const SerdNode* const binary = serd_iter_get_node(binaries, SERD_OBJECT);
+ const char* const lib_uri = serd_node_string(binary);
+ char* const lib_path = serd_file_uri_parse(lib_uri, 0);
if (!lib_path) {
LILV_ERROR("No dynamic manifest library path\n");
- sord_iter_free(binaries);
+ serd_iter_free(binaries);
continue;
}
@@ -569,7 +495,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
if (!lib) {
LILV_ERRORF(
"Failed to open dynmanifest library `%s' (%s)\n", lib_path, dlerror());
- sord_iter_free(binaries);
+ serd_iter_free(binaries);
lilv_free(lib_path);
continue;
}
@@ -580,7 +506,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
OpenFunc dmopen = (OpenFunc)lilv_dlfunc(lib, "lv2_dyn_manifest_open");
if (!dmopen || dmopen(&handle, &dman_features)) {
LILV_ERRORF("No `lv2_dyn_manifest_open' in `%s'\n", lib_path);
- sord_iter_free(binaries);
+ serd_iter_free(binaries);
dlclose(lib);
lilv_free(lib_path);
continue;
@@ -592,19 +518,19 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
(GetSubjectsFunc)lilv_dlfunc(lib, "lv2_dyn_manifest_get_subjects");
if (!get_subjects_func) {
LILV_ERRORF("No `lv2_dyn_manifest_get_subjects' in `%s'\n", lib_path);
- sord_iter_free(binaries);
+ serd_iter_free(binaries);
dlclose(lib);
lilv_free(lib_path);
continue;
}
LilvDynManifest* desc = (LilvDynManifest*)malloc(sizeof(LilvDynManifest));
- desc->bundle = lilv_node_new_from_node(world, bundle_node);
+ desc->bundle = serd_node_copy(bundle_node);
desc->lib = lib;
desc->handle = handle;
desc->refs = 0;
- sord_iter_free(binaries);
+ serd_iter_free(binaries);
// Generate data file
FILE* fd = tmpfile();
@@ -613,12 +539,12 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
// Parse generated data file into temporary model
// FIXME
- const SerdNode* base = sord_node_to_serd_node(dmanifest);
+ const SerdNode* base = dmanifest;
SerdEnv* env = serd_env_new(base);
- SerdReader* reader = sord_new_reader(
- world->model, env, SERD_TURTLE, sord_node_copy(dmanifest));
+ SerdReader* reader = serd_model_new_reader(
+ world->model, env, SERD_TURTLE, serd_node_copy(dmanifest));
serd_reader_add_blank_prefix(reader, lilv_world_blank_node_prefix(world));
- serd_reader_read_file_handle(reader, fd, (const uint8_t*)"(dyn-manifest)");
+ serd_reader_read_file_handle(reader, fd, "(dyn-manifest)");
serd_reader_free(reader);
serd_env_free(env);
@@ -626,32 +552,32 @@ lilv_world_load_dyn_manifest(LilvWorld* world,
fclose(fd);
// ?plugin a lv2:Plugin
- SordModel* plugins = lilv_world_filter_model(world,
+ SerdModel* plugins = lilv_world_filter_model(world,
world->model,
NULL,
world->uris.rdf_a,
world->uris.lv2_Plugin,
dmanifest);
- SordIter* p = sord_begin(plugins);
- FOREACH_MATCH (p) {
- const SordNode* plug = sord_iter_get_node(p, SORD_SUBJECT);
+ SerdIter* p = serd_begin(plugins);
+ FOREACH_MATCH (s, p) {
+ const SerdNode* plug = serd_statement_subject(s);
lilv_world_add_plugin(world, plug, manifest, desc, bundle_node);
}
if (desc->refs == 0) {
- lilv_dynmanifest_free(desc);
+ free(desc);
}
- sord_iter_free(p);
- sord_free(plugins);
+ serd_iter_free(p);
+ serd_free(plugins);
lilv_free(lib_path);
}
- sord_iter_free(iter);
- sord_free(model);
+ serd_iter_free(iter);
+ serd_free(model);
-#else // LILV_DYN_MANIFEST
+#else
(void)world;
(void)bundle_node;
(void)manifest;
-#endif
+#endif // LILV_DYN_MANIFEST
}
#ifdef LILV_DYN_MANIFEST
@@ -672,67 +598,88 @@ lilv_dynmanifest_free(LilvDynManifest* dynmanifest)
#endif // LILV_DYN_MANIFEST
LilvNode*
-lilv_world_get_manifest_uri(LilvWorld* world, const LilvNode* bundle_uri)
+lilv_world_get_manifest_node(LilvWorld* world, const LilvNode* bundle_node)
{
- SerdNode manifest_uri = lilv_new_uri_relative_to_base(
- (const uint8_t*)"manifest.ttl", sord_node_get_string(bundle_uri->node));
- LilvNode* manifest = lilv_new_uri(world, (const char*)manifest_uri.buf);
- serd_node_free(&manifest_uri);
- return manifest;
+ (void)world;
+
+ const SerdURIView bundle_uri = serd_node_uri_view(bundle_node);
+ const SerdURIView manifest_ref = serd_parse_uri("manifest.ttl");
+ const SerdURIView manifest_uri = serd_resolve_uri(manifest_ref, bundle_uri);
+
+ return serd_new_parsed_uri(manifest_uri);
+}
+
+char*
+lilv_world_get_manifest_path(LilvWorld* world, const LilvNode* bundle_node)
+{
+ const SerdNode* const node = lilv_world_get_manifest_node(world, bundle_node);
+
+ return serd_parse_file_uri(serd_node_string(node), NULL);
}
-static SordModel*
+static SerdModel*
load_plugin_model(LilvWorld* world,
const LilvNode* bundle_uri,
const LilvNode* plugin_uri)
{
// Create model and reader for loading into it
- SordNode* bundle_node = bundle_uri->node;
- SordModel* model = sord_new(world->world, SORD_SPO | SORD_OPS, false);
- SerdEnv* env = serd_env_new(sord_node_to_serd_node(bundle_node));
- SerdReader* reader = sord_new_reader(model, env, SERD_TURTLE, NULL);
+ SerdModel* model =
+ serd_model_new(world->world, SERD_INDEX_SPO | SERD_INDEX_OPS);
+ SerdEnv* env = serd_env_new(serd_node_string_view(bundle_uri));
+ SerdSink* inserter = serd_inserter_new(model, NULL);
+ SerdReader* reader = serd_reader_new(
+ world->world, SERD_TURTLE, 0, env, inserter, LILV_READER_STACK_SIZE);
// Load manifest
- LilvNode* manifest_uri = lilv_world_get_manifest_uri(world, bundle_uri);
+ char* manifest_path = lilv_world_get_manifest_path(world, bundle_uri);
+ SerdByteSource* manifest_source =
+ serd_byte_source_new_filename(manifest_path, 4096);
serd_reader_add_blank_prefix(reader, lilv_world_blank_node_prefix(world));
- serd_reader_read_file(reader,
- (const uint8_t*)lilv_node_as_string(manifest_uri));
+ serd_reader_start(reader, manifest_source);
+ serd_reader_read_document(reader);
+ serd_reader_finish(reader);
// Load any seeAlso files
- SordModel* files = lilv_world_filter_model(
- world, model, plugin_uri->node, world->uris.rdfs_seeAlso, NULL, NULL);
-
- SordIter* f = sord_begin(files);
- FOREACH_MATCH (f) {
- const SordNode* file = sord_iter_get_node(f, SORD_OBJECT);
- const uint8_t* file_str = sord_node_get_string(file);
- if (sord_node_get_type(file) == SORD_URI) {
+ SerdModel* files = lilv_world_filter_model(
+ world, model, plugin_uri, world->uris.rdfs_seeAlso, NULL, NULL);
+
+ SerdIter* f = serd_model_begin(files);
+ for (; !serd_iter_equals(f, serd_model_end(files)); serd_iter_next(f)) {
+ const SerdNode* file = serd_statement_object(serd_iter_get(f));
+ const char* uri_str = serd_node_string(file);
+ if (serd_node_type(file) == SERD_URI) {
+ char* path_str = serd_parse_file_uri(uri_str, NULL);
+ SerdByteSource* source = serd_byte_source_new_filename(path_str, 4096);
+
serd_reader_add_blank_prefix(reader, lilv_world_blank_node_prefix(world));
- serd_reader_read_file(reader, file_str);
+ serd_reader_start(reader, source);
+ serd_reader_read_document(reader);
+ serd_reader_finish(reader);
+
+ serd_byte_source_free(source);
}
}
- sord_iter_free(f);
- sord_free(files);
+ serd_iter_free(f);
+ serd_model_free(files);
serd_reader_free(reader);
serd_env_free(env);
- lilv_node_free(manifest_uri);
return model;
}
static LilvVersion
-get_version(LilvWorld* world, SordModel* model, const LilvNode* subject)
+get_version(LilvWorld* world, SerdModel* model, const LilvNode* subject)
{
- const SordNode* minor_node =
- sord_get(model, subject->node, world->uris.lv2_minorVersion, NULL, NULL);
- const SordNode* micro_node =
- sord_get(model, subject->node, world->uris.lv2_microVersion, NULL, NULL);
+ const SerdNode* minor_node =
+ serd_model_get(model, subject, world->uris.lv2_minorVersion, NULL, NULL);
+ const SerdNode* micro_node =
+ serd_model_get(model, subject, world->uris.lv2_microVersion, NULL, NULL);
LilvVersion version = {0, 0};
if (minor_node && micro_node) {
- version.minor = atoi((const char*)sord_node_get_string(minor_node));
- version.micro = atoi((const char*)sord_node_get_string(micro_node));
+ version.minor = atoi(serd_node_string(minor_node));
+ version.micro = atoi(serd_node_string(micro_node));
}
return version;
@@ -742,16 +689,14 @@ void
lilv_world_load_bundle(LilvWorld* world, const LilvNode* bundle_uri)
{
if (!lilv_node_is_uri(bundle_uri)) {
- LILV_ERRORF("Bundle URI `%s' is not a URI\n",
- sord_node_get_string(bundle_uri->node));
+ LILV_ERRORF("Bundle URI `%s' is not a URI\n", serd_node_string(bundle_uri));
return;
}
- SordNode* bundle_node = bundle_uri->node;
- LilvNode* manifest = lilv_world_get_manifest_uri(world, bundle_uri);
+ LilvNode* manifest = lilv_world_get_manifest_node(world, bundle_uri);
- // Read manifest into model with graph = bundle_node
- SerdStatus st = lilv_world_load_graph(world, bundle_node, manifest);
+ // Read manifest into model with graph = bundle_uri
+ SerdStatus st = lilv_world_load_graph(world, bundle_uri, manifest);
if (st > SERD_FAILURE) {
LILV_ERRORF("Error reading %s\n", lilv_node_as_string(manifest));
lilv_node_free(manifest);
@@ -759,32 +704,32 @@ lilv_world_load_bundle(LilvWorld* world, const LilvNode* bundle_uri)
}
// ?plugin a lv2:Plugin
- SordIter* plug_results = sord_search(
- world->model, NULL, world->uris.rdf_a, world->uris.lv2_Plugin, bundle_node);
+ SerdRange* plug_results = serd_model_range(
+ world->model, NULL, world->uris.rdf_a, world->uris.lv2_Plugin, bundle_uri);
// Find any loaded plugins that will be replaced with a newer version
LilvNodes* unload_uris = lilv_nodes_new();
- FOREACH_MATCH (plug_results) {
- const SordNode* plug = sord_iter_get_node(plug_results, SORD_SUBJECT);
+ FOREACH_MATCH (s, plug_results) {
+ const SerdNode* plug = serd_statement_subject(s);
- LilvNode* plugin_uri = lilv_node_new_from_node(world, plug);
+ LilvNode* plugin_uri = serd_node_copy(plug);
const LilvPlugin* plugin =
lilv_plugins_get_by_uri(world->plugins, plugin_uri);
const LilvNode* last_bundle =
plugin ? lilv_plugin_get_bundle_uri(plugin) : NULL;
- if (!plugin || sord_node_equals(bundle_node, last_bundle->node)) {
+ if (!plugin || serd_node_equals(bundle_uri, last_bundle)) {
// No previously loaded version, or it's from the same bundle
lilv_node_free(plugin_uri);
continue;
}
// Compare versions
- SordModel* this_model = load_plugin_model(world, bundle_uri, plugin_uri);
+ SerdModel* this_model = load_plugin_model(world, bundle_uri, plugin_uri);
LilvVersion this_version = get_version(world, this_model, plugin_uri);
- SordModel* last_model = load_plugin_model(world, last_bundle, plugin_uri);
+ SerdModel* last_model = load_plugin_model(world, last_bundle, plugin_uri);
LilvVersion last_version = get_version(world, last_model, plugin_uri);
- sord_free(this_model);
- sord_free(last_model);
+ serd_model_free(this_model);
+ serd_model_free(last_model);
const int cmp = lilv_version_cmp(&this_version, &last_version);
if (cmp > 0) {
zix_tree_insert(
@@ -792,20 +737,20 @@ lilv_world_load_bundle(LilvWorld* world, const LilvNode* bundle_uri)
LILV_WARNF("Replacing version %d.%d of <%s> from <%s>\n",
last_version.minor,
last_version.micro,
- sord_node_get_string(plug),
- sord_node_get_string(last_bundle->node));
+ serd_node_string(plug),
+ serd_node_string(last_bundle));
LILV_NOTEF("New version %d.%d found in <%s>\n",
this_version.minor,
this_version.micro,
- sord_node_get_string(bundle_node));
+ serd_node_string(bundle_uri));
} else if (cmp < 0) {
- LILV_WARNF("Ignoring bundle <%s>\n", sord_node_get_string(bundle_node));
+ LILV_WARNF("Ignoring bundle <%s>\n", serd_node_string(bundle_uri));
LILV_NOTEF("Newer version of <%s> loaded from <%s>\n",
- sord_node_get_string(plug),
- sord_node_get_string(last_bundle->node));
+ serd_node_string(plug),
+ serd_node_string(last_bundle));
lilv_node_free(plugin_uri);
- sord_iter_free(plug_results);
- lilv_world_drop_graph(world, bundle_node);
+ serd_range_free(plug_results);
+ lilv_world_drop_graph(world, bundle_uri);
lilv_node_free(manifest);
lilv_nodes_free(unload_uris);
return;
@@ -813,7 +758,7 @@ lilv_world_load_bundle(LilvWorld* world, const LilvNode* bundle_uri)
lilv_node_free(plugin_uri);
}
- sord_iter_free(plug_results);
+ serd_range_free(plug_results);
// Unload any old conflicting plugins
LilvNodes* unload_bundles = lilv_nodes_new();
@@ -837,49 +782,46 @@ lilv_world_load_bundle(LilvWorld* world, const LilvNode* bundle_uri)
lilv_nodes_free(unload_bundles);
// Re-search for plugin results now that old plugins are gone
- plug_results = sord_search(
- world->model, NULL, world->uris.rdf_a, world->uris.lv2_Plugin, bundle_node);
+ plug_results = serd_model_range(
+ world->model, NULL, world->uris.rdf_a, world->uris.lv2_Plugin, bundle_uri);
- FOREACH_MATCH (plug_results) {
- const SordNode* plug = sord_iter_get_node(plug_results, SORD_SUBJECT);
- lilv_world_add_plugin(world, plug, manifest, NULL, bundle_node);
+ FOREACH_MATCH (s, plug_results) {
+ const SerdNode* plug = serd_statement_subject(s);
+ lilv_world_add_plugin(world, plug, manifest, NULL, bundle_uri);
}
- sord_iter_free(plug_results);
+ serd_range_free(plug_results);
- lilv_world_load_dyn_manifest(world, bundle_node, manifest);
+ lilv_world_load_dyn_manifest(world, bundle_uri, manifest);
// ?spec a lv2:Specification
// ?spec a owl:Ontology
- const SordNode* spec_preds[] = {
+ const SerdNode* spec_preds[] = {
world->uris.lv2_Specification, world->uris.owl_Ontology, NULL};
- for (const SordNode** p = spec_preds; *p; ++p) {
- SordIter* i =
- sord_search(world->model, NULL, world->uris.rdf_a, *p, bundle_node);
- FOREACH_MATCH (i) {
- const SordNode* spec = sord_iter_get_node(i, SORD_SUBJECT);
- lilv_world_add_spec(world, spec, bundle_node);
+ for (const SerdNode** p = spec_preds; *p; ++p) {
+ FOREACH_PAT(s, world->model, NULL, world->uris.rdf_a, *p, bundle_uri)
+ {
+ const SerdNode* spec = serd_statement_subject(s);
+ lilv_world_add_spec(world, spec, bundle_uri);
}
- sord_iter_free(i);
}
lilv_node_free(manifest);
}
static int
-lilv_world_drop_graph(LilvWorld* world, const SordNode* graph)
+lilv_world_drop_graph(LilvWorld* world, const SerdNode* graph)
{
- SordIter* i = sord_search(world->model, NULL, NULL, NULL, graph);
- while (!sord_iter_end(i)) {
- const SerdStatus st = sord_erase(world->model, i);
- if (st) {
- LILV_ERRORF("Error removing statement from <%s> (%s)\n",
- sord_node_get_string(graph),
- serd_strerror(st));
- return st;
- }
+ SerdRange* r = serd_model_range(world->model, NULL, NULL, NULL, graph);
+ const SerdStatus st = serd_model_erase_range(world->model, r);
+
+ if (st) {
+ LILV_ERRORF("Error dropping graph <%s> (%s)\n",
+ serd_node_string(graph),
+ serd_strerror(st));
+ return st;
}
- sord_iter_free(i);
+ serd_range_free(r);
return 0;
}
@@ -941,20 +883,25 @@ lilv_world_unload_bundle(LilvWorld* world, const LilvNode* bundle_uri)
}
// Drop everything in bundle graph
- return lilv_world_drop_graph(world, bundle_uri->node);
+ return lilv_world_drop_graph(world, bundle_uri);
}
static void
load_dir_entry(const char* dir, const char* name, void* data)
{
LilvWorld* world = (LilvWorld*)data;
- char* path = lilv_strjoin(dir, "/", name, "/", NULL);
- SerdNode suri = serd_node_new_file_uri((const uint8_t*)path, 0, 0, true);
- LilvNode* node = lilv_new_uri(world, (const char*)suri.buf);
+ if (!strcmp(name, ".") || !strcmp(name, "..")) {
+ return;
+ }
+
+ char* path = lilv_strjoin(dir, "/", name, "/", NULL);
+ SerdNode* suri =
+ serd_new_file_uri(SERD_MEASURE_STRING(path), SERD_EMPTY_STRING());
+ LilvNode* node = lilv_new_uri(world, serd_node_string(suri));
lilv_world_load_bundle(world, node);
lilv_node_free(node);
- serd_node_free(&suri);
+ serd_node_free(suri);
free(path);
}
@@ -1025,34 +972,29 @@ lilv_world_load_plugin_classes(LilvWorld* world)
is e.g. how a host would build a menu), they won't be seen anyway...
*/
- SordIter* classes = sord_search(
- world->model, NULL, world->uris.rdf_a, world->uris.rdfs_Class, NULL);
- FOREACH_MATCH (classes) {
- const SordNode* class_node = sord_iter_get_node(classes, SORD_SUBJECT);
+ FOREACH_PAT(
+ s, world->model, NULL, world->uris.rdf_a, world->uris.rdfs_Class, NULL)
+ {
+ const SerdNode* class_node = serd_statement_subject(s);
- SordNode* parent = sord_get(
+ const SerdNode* parent = serd_model_get(
world->model, class_node, world->uris.rdfs_subClassOf, NULL, NULL);
- if (!parent || sord_node_get_type(parent) != SORD_URI) {
+ if (!parent || serd_node_type(parent) != SERD_URI) {
continue;
}
- SordNode* label =
- sord_get(world->model, class_node, world->uris.rdfs_label, NULL, NULL);
+ const SerdNode* label = serd_model_get(
+ world->model, class_node, world->uris.rdfs_label, NULL, NULL);
if (!label) {
- sord_node_free(world->world, parent);
continue;
}
- LilvPluginClass* pclass = lilv_plugin_class_new(
- world, parent, class_node, (const char*)sord_node_get_string(label));
+ LilvPluginClass* pclass =
+ lilv_plugin_class_new(world, parent, class_node, serd_node_string(label));
if (pclass) {
zix_tree_insert((ZixTree*)world->plugin_classes, pclass, NULL);
}
-
- sord_node_free(world->world, label);
- sord_node_free(world->world, parent);
}
- sord_iter_free(classes);
}
void
@@ -1074,11 +1016,11 @@ lilv_world_load_all(LilvWorld* world)
(const LilvPlugin*)lilv_collection_get((ZixTree*)world->plugins, p);
// ?new dc:replaces plugin
- if (sord_ask(world->model,
- NULL,
- world->uris.dc_replaces,
- lilv_plugin_get_uri(plugin)->node,
- NULL)) {
+ if (serd_model_ask(world->model,
+ NULL,
+ world->uris.dc_replaces,
+ lilv_plugin_get_uri(plugin),
+ NULL)) {
// TODO: Check if replacement is a known plugin? (expensive)
((LilvPlugin*)plugin)->replaced = true;
}
@@ -1092,25 +1034,33 @@ lilv_world_load_all(LilvWorld* world)
SerdStatus
lilv_world_load_file(LilvWorld* world, SerdReader* reader, const LilvNode* uri)
{
- ZixTreeIter* iter = NULL;
+ ZixTreeIter* iter;
if (!zix_tree_find((ZixTree*)world->loaded_files, uri, &iter)) {
return SERD_FAILURE; // File has already been loaded
}
- size_t uri_len = 0;
- const uint8_t* const uri_str =
- sord_node_get_string_counted(uri->node, &uri_len);
- if (strncmp((const char*)uri_str, "file:", 5)) {
+ const char* const uri_str = serd_node_string(uri);
+ const size_t uri_len = serd_node_length(uri);
+ if (strncmp(uri_str, "file:", 5)) {
return SERD_FAILURE; // Not a local file
+ } else if (strcmp(uri_str + uri_len - 4, ".ttl")) {
+ return SERD_FAILURE; // Not a Turtle file
}
- if (strcmp((const char*)uri_str + uri_len - 4, ".ttl")) {
- return SERD_FAILURE; // Not a Turtle file
+ SerdStatus st = SERD_SUCCESS;
+ char* hostname = NULL;
+ char* filename = serd_parse_file_uri(serd_node_string(uri), &hostname);
+ if (!filename || hostname) {
+ return SERD_ERR_BAD_ARG;
}
+ SerdByteSource* const source =
+ serd_byte_source_new_filename(filename, PAGE_SIZE);
+
serd_reader_add_blank_prefix(reader, lilv_world_blank_node_prefix(world));
- const SerdStatus st = serd_reader_read_file(reader, uri_str);
- if (st) {
+ if ((st = serd_reader_start(reader, source)) ||
+ (st = serd_reader_read_document(reader)) ||
+ (st = serd_reader_finish(reader))) {
LILV_ERRORF("Error loading file `%s'\n", lilv_node_as_string(uri));
return st;
}
@@ -1124,30 +1074,29 @@ int
lilv_world_load_resource(LilvWorld* world, const LilvNode* resource)
{
if (!lilv_node_is_uri(resource) && !lilv_node_is_blank(resource)) {
- LILV_ERRORF("Node `%s' is not a resource\n",
- sord_node_get_string(resource->node));
+ LILV_ERRORF("Node `%s' is not a resource\n", serd_node_string(resource));
return -1;
}
- SordModel* files = lilv_world_filter_model(
- world, world->model, resource->node, world->uris.rdfs_seeAlso, NULL, NULL);
+ SerdModel* files = lilv_world_filter_model(
+ world, world->model, resource, world->uris.rdfs_seeAlso, NULL, NULL);
- SordIter* f = sord_begin(files);
+ SerdIter* f = serd_model_begin(files);
int n_read = 0;
- FOREACH_MATCH (f) {
- const SordNode* file = sord_iter_get_node(f, SORD_OBJECT);
- const uint8_t* file_str = sord_node_get_string(file);
- LilvNode* file_node = lilv_node_new_from_node(world, file);
- if (sord_node_get_type(file) != SORD_URI) {
+ for (; !serd_iter_equals(f, serd_model_end(files)); serd_iter_next(f)) {
+ const SerdNode* file = serd_statement_object(serd_iter_get(f));
+ const char* file_str = serd_node_string(file);
+ LilvNode* file_node = serd_node_copy(file);
+ if (serd_node_type(file) != SERD_URI) {
LILV_ERRORF("rdfs:seeAlso node `%s' is not a URI\n", file_str);
- } else if (!lilv_world_load_graph(world, (SordNode*)file, file_node)) {
+ } else if (!lilv_world_load_graph(world, (SerdNode*)file, file_node)) {
++n_read;
}
lilv_node_free(file_node);
}
- sord_iter_free(f);
+ serd_iter_free(f);
- sord_free(files);
+ serd_model_free(files);
return n_read;
}
@@ -1155,31 +1104,30 @@ int
lilv_world_unload_resource(LilvWorld* world, const LilvNode* resource)
{
if (!lilv_node_is_uri(resource) && !lilv_node_is_blank(resource)) {
- LILV_ERRORF("Node `%s' is not a resource\n",
- sord_node_get_string(resource->node));
+ LILV_ERRORF("Node `%s' is not a resource\n", serd_node_string(resource));
return -1;
}
- SordModel* files = lilv_world_filter_model(
- world, world->model, resource->node, world->uris.rdfs_seeAlso, NULL, NULL);
+ SerdModel* files = lilv_world_filter_model(
+ world, world->model, resource, world->uris.rdfs_seeAlso, NULL, NULL);
- SordIter* f = sord_begin(files);
+ SerdIter* f = serd_model_begin(files);
int n_dropped = 0;
- FOREACH_MATCH (f) {
- const SordNode* file = sord_iter_get_node(f, SORD_OBJECT);
- LilvNode* file_node = lilv_node_new_from_node(world, file);
- if (sord_node_get_type(file) != SORD_URI) {
+ for (; !serd_iter_equals(f, serd_model_end(files)); serd_iter_next(f)) {
+ const SerdNode* file = serd_statement_object(serd_iter_get(f));
+ LilvNode* file_node = serd_node_copy(file);
+ if (serd_node_type(file) != SERD_URI) {
LILV_ERRORF("rdfs:seeAlso node `%s' is not a URI\n",
- sord_node_get_string(file));
- } else if (!lilv_world_drop_graph(world, file_node->node)) {
+ serd_node_string(file));
+ } else if (!lilv_world_drop_graph(world, file_node)) {
lilv_world_unload_file(world, file_node);
++n_dropped;
}
lilv_node_free(file_node);
}
- sord_iter_free(f);
+ serd_iter_free(f);
- sord_free(files);
+ serd_model_free(files);
return n_dropped;
}
@@ -1205,13 +1153,11 @@ LilvNode*
lilv_world_get_symbol(LilvWorld* world, const LilvNode* subject)
{
// Check for explicitly given symbol
- SordNode* snode =
- sord_get(world->model, subject->node, world->uris.lv2_symbol, NULL, NULL);
+ const SerdNode* snode =
+ serd_model_get(world->model, subject, world->uris.lv2_symbol, NULL, NULL);
if (snode) {
- LilvNode* ret = lilv_node_new_from_node(world, snode);
- sord_node_free(world->world, snode);
- return ret;
+ return serd_node_copy(snode);
}
if (!lilv_node_is_uri(subject)) {
@@ -1219,16 +1165,15 @@ lilv_world_get_symbol(LilvWorld* world, const LilvNode* subject)
}
// Find rightmost segment of URI
- SerdURI uri;
- serd_uri_parse((const uint8_t*)lilv_node_as_uri(subject), &uri);
+ SerdURIView uri = serd_parse_uri(lilv_node_as_uri(subject));
const char* str = "_";
if (uri.fragment.buf) {
- str = (const char*)uri.fragment.buf + 1;
+ str = uri.fragment.buf + 1;
} else if (uri.query.buf) {
- str = (const char*)uri.query.buf;
+ str = uri.query.buf;
} else if (uri.path.buf) {
- const char* last_slash = strrchr((const char*)uri.path.buf, '/');
- str = last_slash ? (last_slash + 1) : (const char*)uri.path.buf;
+ const char* last_slash = strrchr(uri.path.buf, '/');
+ str = last_slash ? (last_slash + 1) : uri.path.buf;
}
// Replace invalid characters