summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-04 01:37:51 +0000
committerDavid Robillard <d@drobilla.net>2011-02-04 01:37:51 +0000
commit5b8c788cc4a42f9424d5cca7ca46ceb3cb427af7 (patch)
tree1c7f67590c255d27ae587ed27e026cae1d2958bf /src
parentcded478d952f14fee667e5ba9407923b17daaa65 (diff)
downloadlilv-5b8c788cc4a42f9424d5cca7ca46ceb3cb427af7.tar.gz
lilv-5b8c788cc4a42f9424d5cca7ca46ceb3cb427af7.tar.bz2
lilv-5b8c788cc4a42f9424d5cca7ca46ceb3cb427af7.zip
Drop librdf in favour of serd/sord.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2895 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/collections.c1
-rw-r--r--src/plugin.c104
-rw-r--r--src/pluginclass.c4
-rw-r--r--src/plugininstance.c36
-rw-r--r--src/plugins.c1
-rw-r--r--src/port.c16
-rw-r--r--src/query.c19
-rw-r--r--src/slv2_internal.h73
-rw-r--r--src/util.c41
-rw-r--r--src/value.c53
-rw-r--r--src/world.c446
11 files changed, 353 insertions, 441 deletions
diff --git a/src/collections.c b/src/collections.c
index 0c21a42..4730e1b 100644
--- a/src/collections.c
+++ b/src/collections.c
@@ -20,7 +20,6 @@
#include <string.h>
#include <limits.h>
-#include <redland.h>
#include "slv2/collections.h"
#include "slv2/pluginclass.h"
#include "slv2/pluginui.h"
diff --git a/src/plugin.c b/src/plugin.c
index fd58ab3..049a7ec 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -25,7 +25,6 @@
#ifdef SLV2_DYN_MANIFEST
#include <dlfcn.h>
#endif
-#include <redland.h>
#include "slv2/types.h"
#include "slv2/collections.h"
#include "slv2/plugin.h"
@@ -41,19 +40,18 @@ slv2_plugin_new(SLV2World world, SLV2Value uri, SLV2Value bundle_uri)
{
assert(bundle_uri);
struct _SLV2Plugin* plugin = malloc(sizeof(struct _SLV2Plugin));
- plugin->world = world;
- plugin->plugin_uri = uri;
- plugin->bundle_uri = bundle_uri;
- plugin->binary_uri = NULL;
+ plugin->world = world;
+ plugin->plugin_uri = uri;
+ plugin->bundle_uri = bundle_uri;
+ plugin->binary_uri = NULL;
#ifdef SLV2_DYN_MANIFEST
- plugin->dynman_uri = NULL;
+ plugin->dynman_uri = NULL;
#endif
plugin->plugin_class = NULL;
- plugin->data_uris = slv2_values_new();
- plugin->ports = NULL;
- plugin->storage = NULL;
- plugin->rdf = NULL;
- plugin->num_ports = 0;
+ plugin->data_uris = slv2_values_new();
+ plugin->ports = NULL;
+ plugin->num_ports = 0;
+ plugin->loaded = false;
return plugin;
}
@@ -84,16 +82,6 @@ slv2_plugin_free(SLV2Plugin p)
p->ports = NULL;
}
- if (p->rdf) {
- librdf_free_model(p->rdf);
- p->rdf = NULL;
- }
-
- if (p->storage) {
- librdf_free_storage(p->storage);
- p->storage = NULL;
- }
-
slv2_values_free(p->data_uris);
p->data_uris = NULL;
@@ -105,7 +93,7 @@ slv2_plugin_free(SLV2Plugin p)
void
slv2_plugin_load_if_necessary(SLV2Plugin p)
{
- if (!p->rdf)
+ if (!p->loaded)
slv2_plugin_load(p);
}
@@ -113,6 +101,7 @@ slv2_plugin_load_if_necessary(SLV2Plugin p)
static SLV2Values
slv2_plugin_query_node(SLV2Plugin p, SLV2Node subject, SLV2Node predicate)
{
+ slv2_plugin_load_if_necessary(p);
// <subject> <predicate> ?value
SLV2Matches results = slv2_plugin_find_statements(
p, subject, predicate, NULL);
@@ -141,7 +130,7 @@ slv2_plugin_get_unique(SLV2Plugin p, SLV2Node subject, SLV2Node predicate)
SLV2Values values = slv2_plugin_query_node(p, subject, predicate);
if (!values || slv2_values_size(values) != 1) {
SLV2_ERRORF("Port does not have exactly one `%s' property\n",
- librdf_uri_as_string(librdf_node_get_uri(predicate)));
+ sord_node_get_string(predicate));
return NULL;
}
SLV2Value ret = slv2_value_duplicate(slv2_values_get_at(values, 0));
@@ -167,7 +156,7 @@ slv2_plugin_get_one(SLV2Plugin p, SLV2Node subject, SLV2Node predicate)
void
slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
{
- if (!p->rdf)
+ if (!p->loaded)
slv2_plugin_load(p);
if (!p->ports) {
@@ -223,7 +212,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
p, port, p->world->rdf_a_node, NULL);
FOREACH_MATCH(types) {
SLV2Node type = slv2_match_object(types);
- if (librdf_node_is_resource(type)) {
+ if (sord_node_get_type(type) == SORD_URI) {
raptor_sequence_push(
this_port->classes,
slv2_value_new_from_node(p->world, type));
@@ -254,18 +243,13 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
void
slv2_plugin_load(SLV2Plugin p)
{
- if (!p->storage) {
- assert(!p->rdf);
- p->storage = slv2_world_new_storage(p->world);
- p->rdf = librdf_new_model(p->world->world, p->storage, NULL);
- }
-
// Parse all the plugin's data files into RDF model
for (unsigned i=0; i < slv2_values_size(p->data_uris); ++i) {
- SLV2Value data_uri_val = slv2_values_get_at(p->data_uris, i);
- librdf_uri* data_uri = librdf_node_get_uri(
- slv2_value_as_node(data_uri_val));
- librdf_parser_parse_into_model(p->world->parser, data_uri, data_uri, p->rdf);
+ SLV2Value data_uri_val = slv2_values_get_at(p->data_uris, i);
+ sord_read_file(p->world->model,
+ sord_node_get_string(data_uri_val->val.uri_val),
+ p->bundle_uri->val.uri_val,
+ slv2_world_blank_node_prefix(p->world));
}
#ifdef SLV2_DYN_MANIFEST
@@ -293,10 +277,7 @@ slv2_plugin_load(SLV2Plugin p)
FILE* fd = tmpfile();
get_data_func(handle, fd, slv2_value_as_string(p->plugin_uri));
rewind(fd);
- librdf_parser_parse_file_handle_into_model(
- p->world->parser, fd, 0,
- librdf_node_get_value(slv2_value_as_node(p->bundle_uri)),
- p->rdf);
+ sord_read_file_handle(p->world->model, fd, p->bundle_uri);
fclose(fd);
}
@@ -306,7 +287,7 @@ slv2_plugin_load(SLV2Plugin p)
close_func(handle);
}
#endif
- assert(p->rdf);
+ p->loaded = true;
}
@@ -341,7 +322,7 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
NULL);
FOREACH_MATCH(results) {
SLV2Node binary_node = slv2_match_object(results);
- if (librdf_node_is_resource(binary_node)) {
+ if (sord_node_get_type(binary_node) == SORD_URI) {
p->binary_uri = slv2_value_new_from_node(p->world, binary_node);
break;
}
@@ -372,7 +353,7 @@ slv2_plugin_get_class(SLV2Plugin p)
NULL);
FOREACH_MATCH(results) {
SLV2Node class_node = slv2_node_copy(slv2_match_object(results));
- if (!librdf_node_is_resource(class_node)) {
+ if (sord_node_get_type(class_node) != SORD_URI) {
continue;
}
@@ -494,8 +475,8 @@ slv2_plugin_get_value_by_qname_i18n(SLV2Plugin p,
return NULL;
}
- SLV2Node pred_node = librdf_new_node_from_uri_string(
- p->world->world, (const uint8_t*)pred_uri);
+ SLV2Node pred_node = sord_get_uri(
+ p->world->model, true, (const uint8_t*)pred_uri);
SLV2Matches results = slv2_plugin_find_statements(
p,
@@ -525,8 +506,13 @@ slv2_plugin_get_value_for_subject(SLV2Plugin p,
SLV2Node subject_node = (slv2_value_is_uri(subject))
? slv2_node_copy(subject->val.uri_val)
- : librdf_new_node_from_blank_identifier(
- p->world->world, (const uint8_t*)slv2_value_as_blank(subject));
+ : sord_get_blank(p->world->model, false,
+ (const uint8_t*)slv2_value_as_blank(subject));
+
+ if (!subject_node) {
+ fprintf(stderr, "No such subject\n");
+ return NULL;
+ }
return slv2_plugin_query_node(p,
subject_node,
@@ -750,8 +736,8 @@ slv2_plugin_get_port_by_symbol(SLV2Plugin p,
static SLV2Node
slv2_plugin_get_author(SLV2Plugin p)
{
- SLV2Node doap_maintainer = librdf_new_node_from_uri_string(
- p->world->world, NS_DOAP "maintainer");
+ SLV2Node doap_maintainer = sord_get_uri(
+ p->world->model, true, NS_DOAP "maintainer");
SLV2Matches maintainers = slv2_plugin_find_statements(
p,
@@ -778,8 +764,8 @@ slv2_plugin_get_author_name(SLV2Plugin plugin)
SLV2Node author = slv2_plugin_get_author(plugin);
if (author) {
return slv2_plugin_get_one(
- plugin, author, librdf_new_node_from_uri_string(
- plugin->world->world, NS_FOAF "name"));
+ plugin, author, sord_get_uri(
+ plugin->world->model, true, NS_FOAF "name"));
}
return NULL;
}
@@ -791,8 +777,8 @@ slv2_plugin_get_author_email(SLV2Plugin plugin)
SLV2Node author = slv2_plugin_get_author(plugin);
if (author) {
return slv2_plugin_get_one(
- plugin, author, librdf_new_node_from_uri_string(
- plugin->world->world, NS_FOAF "mbox"));
+ plugin, author, sord_get_uri(
+ plugin->world->model, true, NS_FOAF "mbox"));
}
return NULL;
}
@@ -804,8 +790,8 @@ slv2_plugin_get_author_homepage(SLV2Plugin plugin)
SLV2Node author = slv2_plugin_get_author(plugin);
if (author) {
return slv2_plugin_get_one(
- plugin, author, librdf_new_node_from_uri_string(
- plugin->world->world, NS_FOAF "homepage"));
+ plugin, author, sord_get_uri(
+ plugin->world->model, true, NS_FOAF "homepage"));
}
return NULL;
}
@@ -816,8 +802,8 @@ slv2_plugin_get_uis(SLV2Plugin p)
{
#define NS_UI (const uint8_t*)"http://lv2plug.in/ns/extensions/ui#"
- SLV2Node ui_ui = librdf_new_node_from_uri_string(
- p->world->world, NS_UI "ui");
+ SLV2Node ui_ui = sord_get_uri(
+ p->world->model, true, NS_UI "ui");
SLV2UIs result = slv2_uis_new();
SLV2Matches uis = slv2_plugin_find_statements(
@@ -832,15 +818,15 @@ slv2_plugin_get_uis(SLV2Plugin p)
SLV2Value type = slv2_plugin_get_unique(
p, ui, p->world->rdf_a_node);
- SLV2Node ui_binary_node = librdf_new_node_from_uri_string(
- p->world->world, NS_UI "binary");
+ SLV2Node ui_binary_node = sord_get_uri(
+ p->world->model, true, NS_UI "binary");
SLV2Value binary = slv2_plugin_get_unique(
p, ui, ui_binary_node);
slv2_node_free(ui_binary_node);
- if (!librdf_node_is_resource(ui)
+ if (sord_node_get_type(ui) != SORD_URI
|| !slv2_value_is_uri(type)
|| !slv2_value_is_uri(binary)) {
slv2_value_free(binary);
diff --git a/src/pluginclass.c b/src/pluginclass.c
index 9997253..9125eed 100644
--- a/src/pluginclass.c
+++ b/src/pluginclass.c
@@ -34,7 +34,9 @@ slv2_plugin_class_new(SLV2World world,
SLV2Node uri,
const char* label)
{
- assert(!parent_node || librdf_node_is_resource(parent_node));
+ if (parent_node && sord_node_get_type(parent_node) != SORD_URI) {
+ return NULL; // Not an LV2 plugin superclass (FIXME: discover properly)
+ }
SLV2PluginClass pc = (SLV2PluginClass)malloc(sizeof(struct _SLV2PluginClass));
pc->world = world;
pc->uri = slv2_value_new_from_node(world, uri);
diff --git a/src/plugininstance.c b/src/plugininstance.c
index 7a0fa6e..2229424 100644
--- a/src/plugininstance.c
+++ b/src/plugininstance.c
@@ -44,7 +44,7 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
local_features[0] = NULL;
}
- const char* const lib_uri = slv2_value_as_uri(slv2_plugin_get_library_uri(plugin));
+ const char* const lib_uri = slv2_value_as_uri(slv2_plugin_get_library_uri(plugin));
const char* const lib_path = slv2_uri_to_path(lib_uri);
if (!lib_path)
@@ -80,11 +80,31 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
dlclose(lib);
break; // return NULL
} else {
- librdf_uri* absolute_uri = librdf_new_uri_relative_to_base(
- librdf_node_get_uri(slv2_value_as_node(
- slv2_plugin_get_bundle_uri(plugin))),
- (const uint8_t*)ld->URI);
- if (!strcmp((const char*)librdf_uri_as_string(absolute_uri),
+ // FIXME: duplicated/common code, put this in serd
+ SerdURI uri;
+ if (!serd_uri_parse((const uint8_t*)ld->URI, &uri)) {
+ SLV2_ERROR("Failed to parse library URI\n");
+ dlclose(lib);
+ break;
+ }
+
+ SerdURI base_uri;
+ if (!serd_uri_parse(
+ (const uint8_t*)slv2_value_as_uri(slv2_plugin_get_bundle_uri(plugin)),
+ &base_uri)) {
+ dlclose(lib);
+ break;
+ }
+
+ SerdURI abs_uri;
+ if (!serd_uri_resolve(&uri, &base_uri, &abs_uri)) {
+ fprintf(stderr, "error: failed to resolve new base URI\n");
+ return false;
+ }
+
+ SerdNode abs_uri_node = serd_node_new_uri(&abs_uri, &base_uri);
+
+ if (!strcmp((const char*)abs_uri_node.buf,
slv2_value_as_uri(slv2_plugin_get_uri(plugin)))) {
assert(plugin->plugin_uri);
assert(ld->instantiate);
@@ -98,10 +118,10 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
impl->lib_handle = lib;
result->pimpl = impl;
- librdf_free_uri(absolute_uri);
+ serd_node_free(&abs_uri_node);
break;
} else {
- librdf_free_uri(absolute_uri);
+ serd_node_free(&abs_uri_node);
}
}
}
diff --git a/src/plugins.c b/src/plugins.c
index 2d47ffb..71fd265 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
-#include <redland.h>
#include "slv2/types.h"
#include "slv2/plugin.h"
#include "slv2/collections.h"
diff --git a/src/port.c b/src/port.c
index 21c5c55..f48c30f 100644
--- a/src/port.c
+++ b/src/port.c
@@ -127,7 +127,7 @@ slv2_port_supports_event(SLV2Plugin p,
SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
- librdf_new_node_from_uri_string(p->world->world, NS_EV "supportsEvent"),
+ sord_get_uri(p->world->model, true, NS_EV "supportsEvent"),
slv2_value_as_node(event));
const bool ret = !slv2_matches_end(results);
@@ -172,7 +172,7 @@ slv2_port_get_value_by_qname(SLV2Plugin p,
SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
- librdf_new_node_from_uri_string(p->world->world, (const uint8_t*)pred_uri),
+ sord_get_uri(p->world->model, true, (const uint8_t*)pred_uri),
NULL);
free(pred_uri);
@@ -181,11 +181,11 @@ slv2_port_get_value_by_qname(SLV2Plugin p,
static SLV2Values
-slv2_port_get_value_by_node(SLV2Plugin p,
- SLV2Port port,
- SLV2Node predicate)
+slv2_port_get_value_by_node(SLV2Plugin p,
+ SLV2Port port,
+ SLV2Node predicate)
{
- assert(librdf_node_is_resource(predicate));
+ assert(sord_node_get_type(predicate) == SORD_URI);
SLV2Node port_node = slv2_port_get_node(p, port);
SLV2Matches results = slv2_plugin_find_statements(
@@ -229,7 +229,7 @@ slv2_port_get_value_by_qname_i18n(SLV2Plugin p,
SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
- librdf_new_node_from_uri_string(p->world->world, (const uint8_t*)pred_uri),
+ sord_get_uri(p->world->model, true, pred_uri),
NULL);
free(pred_uri);
@@ -316,7 +316,7 @@ slv2_port_get_scale_points(SLV2Plugin p,
SLV2Matches points = slv2_plugin_find_statements(
p,
port_node,
- librdf_new_node_from_uri_string(p->world->world, SLV2_NS_LV2 "scalePoint"),
+ sord_get_uri(p->world->model, true, SLV2_NS_LV2 "scalePoint"),
NULL);
SLV2ScalePoints ret = NULL;
diff --git a/src/query.c b/src/query.c
index 5709ffd..3ad5ef8 100644
--- a/src/query.c
+++ b/src/query.c
@@ -18,7 +18,6 @@
#define _XOPEN_SOURCE 500
#include <assert.h>
-#include <redland.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -36,14 +35,8 @@ slv2_plugin_find_statements(SLV2Plugin plugin,
SLV2Node object)
{
slv2_plugin_load_if_necessary(plugin);
- librdf_statement* q = librdf_new_statement_from_nodes(
- plugin->world->world,
- subject ? slv2_node_copy(subject) : NULL,
- predicate ? slv2_node_copy(predicate) : NULL,
- object ? slv2_node_copy(object) : NULL);
- librdf_stream* results = librdf_model_find_statements(plugin->rdf, q);
- librdf_free_statement(q);
- return results;
+ SordTuple pat = { subject, predicate, object, NULL };
+ return sord_find(plugin->world->model, pat);
}
@@ -55,13 +48,13 @@ slv2_values_from_stream_i18n(SLV2Plugin p,
SLV2Node nolang = NULL;
FOREACH_MATCH(stream) {
SLV2Node value = slv2_match_object(stream);
- if (librdf_node_is_literal(value)) {
- const char* lang = librdf_node_get_literal_value_language(value);
+ if (sord_node_get_type(value) == SORD_LITERAL) {
+ const char* lang = sord_literal_get_lang(value);
if (lang) {
if (!strcmp(lang, slv2_get_lang())) {
raptor_sequence_push(
values, slv2_value_new_string(
- p->world, (const char*)librdf_node_get_literal_value(value)));
+ p->world, sord_node_get_string(value)));
}
} else {
nolang = value;
@@ -76,7 +69,7 @@ slv2_values_from_stream_i18n(SLV2Plugin p,
if (nolang) {
raptor_sequence_push(
values, slv2_value_new_string(
- p->world, (const char*)librdf_node_get_literal_value(nolang)));
+ p->world, sord_node_get_string(nolang)));
} else {
slv2_values_free(values);
values = NULL;
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index e9847fe..2d1bed9 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -30,7 +30,9 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
-#include <redland.h>
+#include <raptor.h>
+#include "serd/serd.h"
+#include "sord/sord.h"
#include "slv2/types.h"
#include "slv2/lv2_ui.h"
#ifdef SLV2_DYN_MANIFEST
@@ -43,26 +45,29 @@ extern "C" {
#define SLV2_NS_XSD (const uint8_t*)"http://www.w3.org/2001/XMLSchema#"
#define SLV2_NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-typedef librdf_stream* SLV2Matches;
-typedef librdf_node* SLV2Node; ///< RDF node
+typedef SordIter SLV2Matches;
+typedef SordNode SLV2Node;
-#define FOREACH_MATCH(stream) \
- for (; !librdf_stream_end(stream); librdf_stream_next(stream))
+#define FOREACH_MATCH(iter) \
+ for (; !sord_iter_end(iter); sord_iter_next(iter))
static inline SLV2Node
-slv2_match_subject(SLV2Matches stream) {
- return librdf_statement_get_subject(librdf_stream_get_object(stream));
+slv2_match_subject(SLV2Matches iter) {
+ SordTuple tup;
+ sord_iter_get(iter, tup);
+ return tup[SORD_SUBJECT];
}
static inline SLV2Node
-slv2_match_object(SLV2Matches stream) {
- return librdf_statement_get_object(librdf_stream_get_object(stream));
+slv2_match_object(SLV2Matches iter) {
+ SordTuple tup;
+ sord_iter_get(iter, tup);
+ return tup[SORD_OBJECT];
}
static inline void
-slv2_match_end(SLV2Matches stream)
+slv2_match_end(SLV2Matches iter)
{
- librdf_free_stream(stream);
}
@@ -89,17 +94,16 @@ void slv2_port_free(SLV2Port port);
* paths of relevant files, the actual data therein isn't loaded into memory.
*/
struct _SLV2Plugin {
- struct _SLV2World* world;
- SLV2Value plugin_uri;
- SLV2Value bundle_uri; ///< Bundle directory plugin was loaded from
- SLV2Value binary_uri; ///< lv2:binary
- SLV2Value dynman_uri; ///< dynamic manifest binary
- SLV2PluginClass plugin_class;
- raptor_sequence* data_uris; ///< rdfs::seeAlso
- SLV2Port* ports;
- librdf_storage* storage;
- librdf_model* rdf;
- uint32_t num_ports;
+ struct _SLV2World* world;
+ SLV2Value plugin_uri;
+ SLV2Value bundle_uri; ///< Bundle directory plugin was loaded from
+ SLV2Value binary_uri; ///< lv2:binary
+ SLV2Value dynman_uri; ///< dynamic manifest binary
+ SLV2PluginClass plugin_class;
+ raptor_sequence* data_uris; ///< rdfs::seeAlso
+ SLV2Port* ports;
+ uint32_t num_ports;
+ bool loaded;
};
SLV2Plugin slv2_plugin_new(SLV2World world, SLV2Value uri, SLV2Value bundle_uri);
@@ -169,12 +173,10 @@ void slv2_plugin_classes_free();
/** Model of LV2 (RDF) data loaded from bundles.
*/
struct _SLV2World {
- bool local_world;
- librdf_world* world;
- librdf_storage* storage;
- librdf_model* model;
- librdf_parser* parser;
- librdf_hash* namespaces;
+ Sord model;
+ SerdReader reader;
+ SerdEnv namespaces;
+ unsigned n_read_files;
SLV2PluginClass lv2_plugin_class;
SLV2PluginClasses plugin_classes;
SLV2Plugins plugins;
@@ -202,6 +204,9 @@ struct _SLV2World {
SLV2Node xsd_decimal_node;
};
+const uint8_t*
+slv2_world_blank_node_prefix(SLV2World world);
+
/** Load all bundles found in \a search_path.
*
* \param search_path A colon-delimited list of directories. These directories
@@ -220,10 +225,7 @@ void
slv2_world_load_specifications(SLV2World world);
void
-slv2_world_load_file(SLV2World world, librdf_uri* file_uri);
-
-librdf_storage*
-slv2_world_new_storage(SLV2World world);
+slv2_world_load_file(SLV2World world, const char* file_uri);
/* ********* Plugin UI ********* */
@@ -272,11 +274,10 @@ SLV2Value slv2_value_new_from_node(SLV2World world, SLV2Node node);
SLV2Node slv2_value_as_node(SLV2Value value);
static inline SLV2Node slv2_node_copy(SLV2Node node) {
- return librdf_new_node_from_node(node);
+ return node;
}
static inline void slv2_node_free(SLV2Node node) {
- librdf_free_node(node);
}
/* ********* Values ********* */
@@ -303,11 +304,11 @@ SLV2Matches slv2_plugin_find_statements(SLV2Plugin plugin,
SLV2Node object);
static inline bool slv2_matches_next(SLV2Matches matches) {
- return librdf_stream_next(matches);
+ return sord_iter_next(matches);
}
static inline bool slv2_matches_end(SLV2Matches matches) {
- return librdf_stream_end(matches);
+ return sord_iter_end(matches);
}
SLV2Values slv2_values_from_stream_i18n(SLV2Plugin p,
diff --git a/src/util.c b/src/util.c
index 9fee529..b6b7d85 100644
--- a/src/util.c
+++ b/src/util.c
@@ -92,32 +92,21 @@ slv2_get_lang()
char*
slv2_qname_expand(SLV2Plugin p, const char* qname)
{
- char* colon = strchr(qname, ':');
- if (!colon || colon == qname) {
- SLV2_ERRORF("Invalid QName `%s'\n", qname);
- return NULL;
- }
-
- const size_t prefix_len = colon - qname;
- char* prefix = malloc(prefix_len + 1);
- memcpy(prefix, qname, prefix_len);
- prefix[prefix_len] = '\0';
-
- char* namespace = librdf_hash_get(p->world->namespaces, prefix);
- free(prefix);
- if (!namespace) {
- SLV2_ERRORF("QName `%s' has Undefined prefix\n", qname);
+ const size_t qname_len = strlen(qname);
+ SerdNode qname_node = { SERD_CURIE, qname_len + 1, qname_len,
+ (const uint8_t*)qname };
+
+ SerdChunk uri_prefix;
+ SerdChunk uri_suffix;
+ if (serd_env_expand(p->world->namespaces, &qname_node, &uri_prefix, &uri_suffix)) {
+ const size_t uri_len = uri_prefix.len + uri_suffix.len;
+ char* uri = malloc(uri_len + 1);
+ memcpy(uri, uri_prefix.buf, uri_prefix.len);
+ memcpy(uri + uri_prefix.len, uri_suffix.buf, uri_suffix.len);
+ uri[uri_len] = '\0';
+ return uri;
+ } else {
+ SLV2_ERRORF("Failed to expand QName `%s'\n", qname);
return NULL;
}
-
- const size_t qname_len = strlen(qname);
- const size_t suffix_len = qname_len - prefix_len - 1;
- const size_t namespace_len = strlen(namespace);
- char* uri = malloc(namespace_len + suffix_len + 1);
- memcpy(uri, namespace, namespace_len);
- memcpy(uri + namespace_len, colon + 1, qname_len - prefix_len - 1);
- uri[namespace_len + suffix_len] = '\0';
-
- free(namespace);
- return uri;
}
diff --git a/src/value.c b/src/value.c
index 6714ff9..9e9f8d5 100644
--- a/src/value.c
+++ b/src/value.c
@@ -75,11 +75,9 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str)
switch (type) {
case SLV2_VALUE_URI:
- val->val.uri_val = librdf_new_node_from_uri_string(
- world->world, (const uint8_t*)str);
+ val->val.uri_val = sord_get_uri(world->model, true, str);
assert(val->val.uri_val);
- val->str_val = (char*)librdf_uri_as_string(
- librdf_node_get_uri(val->val.uri_val));
+ val->str_val = (char*)sord_node_get_string(val->val.uri_val);
break;
case SLV2_VALUE_QNAME_UNUSED:
case SLV2_VALUE_BLANK:
@@ -96,51 +94,45 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str)
/** Create a new SLV2Value from @a node, or return NULL if impossible */
SLV2Value
-slv2_value_new_from_node(SLV2World world, librdf_node* node)
+slv2_value_new_from_node(SLV2World world, SordNode node)
{
SLV2Value result = NULL;
- librdf_uri* datatype_uri = NULL;
+ SordNode datatype_uri = NULL;
SLV2ValueType type = SLV2_VALUE_STRING;
- switch (librdf_node_get_type(node)) {
- case LIBRDF_NODE_TYPE_RESOURCE:
+ switch (sord_node_get_type(node)) {
+ case SORD_URI:
type = SLV2_VALUE_URI;
result = (SLV2Value)malloc(sizeof(struct _SLV2Value));
result->type = SLV2_VALUE_URI;
result->val.uri_val = slv2_node_copy(node);
- result->str_val = (char*)librdf_uri_as_string(
- librdf_node_get_uri(result->val.uri_val));
+ result->str_val = (char*)sord_node_get_string(result->val.uri_val);
break;
- case LIBRDF_NODE_TYPE_LITERAL:
- datatype_uri = librdf_node_get_literal_value_datatype_uri(node);
+ case SORD_LITERAL:
+ datatype_uri = sord_literal_get_datatype(node);
if (datatype_uri) {
- if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_integer_node)))
+ if (sord_node_equals(datatype_uri, world->xsd_integer_node))
type = SLV2_VALUE_INT;
- else if (librdf_uri_equals(datatype_uri, librdf_node_get_uri(world->xsd_decimal_node)))
+ else if (sord_node_equals(datatype_uri, world->xsd_decimal_node))
type = SLV2_VALUE_FLOAT;
else
- SLV2_ERRORF("Unknown datatype %s\n", librdf_uri_as_string(datatype_uri));
+ SLV2_ERRORF("Unknown datatype %s\n", sord_node_get_string(datatype_uri));
}
- result = slv2_value_new(world, type, (const char*)librdf_node_get_literal_value(node));
+ result = slv2_value_new(world, type, (const char*)sord_node_get_string(node));
switch (result->type) {
- case SLV2_VALUE_URI:
- case SLV2_VALUE_BLANK:
- case SLV2_VALUE_STRING:
- case SLV2_VALUE_QNAME_UNUSED:
- break;
case SLV2_VALUE_INT:
case SLV2_VALUE_FLOAT:
slv2_value_set_numerics_from_string(result);
+ default:
+ break;
}
break;
- case LIBRDF_NODE_TYPE_BLANK:
- type = SLV2_VALUE_BLANK;
- result = slv2_value_new(world, type, (const char*)librdf_node_get_blank_identifier(node));
+ case SORD_BLANK:
+ type = SLV2_VALUE_BLANK;
+ result = slv2_value_new(world, type, (const char*)sord_node_get_string(node));
break;
- case LIBRDF_NODE_TYPE_UNKNOWN:
default:
- SLV2_ERRORF("Unknown RDF node type %d\n", librdf_node_get_type(node));
- break;
+ assert(false);
}
return result;
@@ -194,8 +186,7 @@ slv2_value_duplicate(SLV2Value val)
if (val->type == SLV2_VALUE_URI) {
result->val.uri_val = slv2_node_copy(val->val.uri_val);
- result->str_val = (char*)librdf_uri_as_string(
- librdf_node_get_uri(val->val.uri_val));
+ result->str_val = (char*)sord_node_get_string(result->val.uri_val);
} else {
result->str_val = strdup(val->str_val);
result->val = val->val;
@@ -231,11 +222,11 @@ slv2_value_equals(SLV2Value value, SLV2Value other)
switch (value->type) {
case SLV2_VALUE_URI:
- return (librdf_node_equals(value->val.uri_val, other->val.uri_val) != 0);
+ return sord_node_equals(value->val.uri_val, other->val.uri_val);
case SLV2_VALUE_BLANK:
case SLV2_VALUE_STRING:
case SLV2_VALUE_QNAME_UNUSED:
- return ! strcmp(value->str_val, other->str_val);
+ return !strcmp(value->str_val, other->str_val);
case SLV2_VALUE_INT:
return (value->val.int_val == other->val.int_val);
case SLV2_VALUE_FLOAT:
diff --git a/src/world.c b/src/world.c
index f32dfaa..9657805 100644
--- a/src/world.c
+++ b/src/world.c
@@ -24,7 +24,6 @@
#ifdef SLV2_DYN_MANIFEST
#include <dlfcn.h>
#endif
-#include <redland.h>
#include "slv2/types.h"
#include "slv2/world.h"
#include "slv2/slv2.h"
@@ -32,32 +31,36 @@
#include "slv2-config.h"
#include "slv2_internal.h"
+static void
+slv2_world_set_prefix(SLV2World world, const char* name, const char* uri)
+{
+ const SerdNode name_node = serd_node_from_string(SERD_LITERAL,
+ (const uint8_t*)name);
+ const SerdNode uri_node = serd_node_from_string(SERD_URI,
+ (const uint8_t*)uri);
+ serd_env_add(world->namespaces, &name_node, &uri_node);
+}
+
/* private */
static SLV2World
slv2_world_new_internal(SLV2World world)
{
assert(world);
- assert(world->world);
-
- world->storage = slv2_world_new_storage(world);
- if (!world->storage)
- goto fail;
- world->model = librdf_new_model(world->world, world->storage, NULL);
+ world->model = sord_new();
if (!world->model)
goto fail;
- world->parser = librdf_new_parser(world->world, "turtle", NULL, NULL);
- if (!world->parser)
+ if (!sord_open(world->model))
goto fail;
-
+
world->plugin_classes = slv2_plugin_classes_new();
world->plugins = slv2_plugins_new();
#define NS_DYNMAN (const uint8_t*)"http://lv2plug.in/ns/ext/dynmanifest#"
-#define NEW_URI(uri) librdf_new_node_from_uri_string(world->world, uri);
+#define NEW_URI(uri) sord_get_uri(world->model, true, (const char*)uri)
world->dyn_manifest_node = NEW_URI(NS_DYNMAN "DynManifest");
world->lv2_specification_node = NEW_URI(SLV2_NS_LV2 "Specification");
@@ -84,15 +87,17 @@ slv2_world_new_internal(SLV2World world)
world->lv2_plugin_class = slv2_plugin_class_new(
world, NULL, world->lv2_plugin_node, "Plugin");
+ assert(world->lv2_plugin_class);
+
+ world->namespaces = serd_env_new();
+ slv2_world_set_prefix(world, "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
+ slv2_world_set_prefix(world, "rdfs", "http://www.w3.org/2000/01/rdf-schema#");
+ slv2_world_set_prefix(world, "doap", "http://usefulinc.com/ns/doap#");
+ slv2_world_set_prefix(world, "foaf", "http://xmlns.com/foaf/0.1/");
+ slv2_world_set_prefix(world, "lv2", "http://lv2plug.in/ns/lv2core#");
+ slv2_world_set_prefix(world, "lv2ev", "http://lv2plug.in/ns/ext/event#");
- world->namespaces = librdf_new_hash_from_string(
- world->world, NULL,
- "rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#',"
- "rdfs='http://www.w3.org/2000/01/rdf-schema#',"
- "doap='http://usefulinc.com/ns/doap#',"
- "foaf='http://xmlns.com/foaf/0.1/',"
- "lv2='http://lv2plug.in/ns/lv2core#',"
- "lv2ev='http://lv2plug.in/ns/ext/event#'");
+ world->n_read_files = 0;
return world;
@@ -102,57 +107,10 @@ fail:
}
-/* private */
-librdf_storage*
-slv2_world_new_storage(SLV2World world)
-{
- static bool warned = false;
- librdf_hash* options = librdf_new_hash_from_string(world->world, NULL,
- "index-spo='yes',index-ops='yes'");
- librdf_storage* ret = librdf_new_storage_with_options(
- world->world, "trees", NULL, options);
- if (!ret) {
- warned = true;
- SLV2_WARN("Unable to create \"trees\" RDF storage, you should upgrade librdf.\n");
- ret = librdf_new_storage(world->world, "hashes", NULL,
- "hash-type='memory'");
- }
-
- librdf_free_hash(options);
- return ret;
-}
-
-
SLV2World
slv2_world_new()
{
SLV2World world = (SLV2World)malloc(sizeof(struct _SLV2World));
-
- world->world = librdf_new_world();
- if (!world->world) {
- free(world);
- return NULL;
- }
-
- world->local_world = true;
-
- librdf_world_open(world->world);
-
- return slv2_world_new_internal(world);
-}
-
-
-SLV2World
-slv2_world_new_using_rdf_world(librdf_world* rdf_world)
-{
- if (rdf_world == NULL)
- return slv2_world_new();
-
- SLV2World world = (SLV2World)malloc(sizeof(struct _SLV2World));
-
- world->world = rdf_world;
- world->local_world = false;
-
return slv2_world_new_internal(world);
}
@@ -194,51 +152,82 @@ slv2_world_free(SLV2World world)
raptor_free_sequence(world->plugin_classes);
world->plugin_classes = NULL;
- librdf_free_parser(world->parser);
- world->parser = NULL;
-
- librdf_free_model(world->model);
+ sord_free(world->model);
world->model = NULL;
- librdf_free_storage(world->storage);
- world->storage = NULL;
+ serd_env_free(world->namespaces);
- librdf_free_hash(world->namespaces);
+ free(world);
+}
- if (world->local_world)
- librdf_free_world(world->world);
- world->world = NULL;
+static SLV2Matches
+slv2_world_find_statements(SLV2World world,
+ Sord model,
+ SLV2Node subject,
+ SLV2Node predicate,
+ SLV2Node object,
+ SLV2Node graph)
+{
+ SordTuple pat = { subject, predicate, object, graph };
+ return sord_find(model, pat);
+}
- free(world);
+static SerdNode
+slv2_new_uri_relative_to_base(const uint8_t* uri_str, const uint8_t* base_uri_str)
+{
+ SerdURI uri;
+ if (!serd_uri_parse(uri_str, &uri)) {
+ return SERD_NODE_NULL;
+ }
+
+ SerdURI base_uri;
+ if (!serd_uri_parse(base_uri_str, &base_uri)) {
+ return SERD_NODE_NULL;
+ }
+
+ SerdURI abs_uri;
+ if (!serd_uri_resolve(&uri, &base_uri, &abs_uri)) {
+ return SERD_NODE_NULL;
+ }
+
+ SerdURI ignored;
+ return serd_node_new_uri(&abs_uri, &ignored);
+}
+
+const uint8_t*
+slv2_world_blank_node_prefix(SLV2World world)
+{
+ static char str[32];
+ snprintf(str, sizeof(str), "%d", world->n_read_files++);
+ return (const uint8_t*)str;
}
-/** Load the entire contents of a file into the world model.
- */
-void
-slv2_world_load_file(SLV2World world, librdf_uri* file_uri)
+/** Comparator for sorting SLV2Plugins */
+int
+slv2_plugin_compare_by_uri(const void* a, const void* b)
{
- librdf_parser_parse_into_model(world->parser, file_uri, file_uri, world->model);
+ SLV2Plugin plugin_a = *(SLV2Plugin*)a;
+ SLV2Plugin plugin_b = *(SLV2Plugin*)b;
+
+ return strcmp(slv2_value_as_uri(plugin_a->plugin_uri),
+ slv2_value_as_uri(plugin_b->plugin_uri));
}
-static SLV2Matches
-slv2_world_find_statements(SLV2World world,
- librdf_model* model,
- SLV2Node subject,
- SLV2Node predicate,
- SLV2Node object)
+
+/** Comparator for sorting SLV2PluginClasses */
+int
+slv2_plugin_class_compare_by_uri(const void* a, const void* b)
{
- librdf_statement* q = librdf_new_statement_from_nodes(
- world->world,
- subject ? slv2_node_copy(subject) : NULL,
- predicate ? slv2_node_copy(predicate) : NULL,
- object ? slv2_node_copy(object) : NULL);
- SLV2Matches results = librdf_model_find_statements(model, q);
- librdf_free_statement(q);
- return results;
+ SLV2PluginClass class_a = *(SLV2PluginClass*)a;
+ SLV2PluginClass class_b = *(SLV2PluginClass*)b;
+
+ return strcmp(slv2_value_as_uri(class_a->uri),
+ slv2_value_as_uri(class_b->uri));
}
+
void
slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
{
@@ -247,17 +236,14 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
return;
}
- librdf_uri* manifest_uri = librdf_new_uri_relative_to_base(
- librdf_node_get_uri(bundle_uri->val.uri_val),
- (const uint8_t*)"manifest.ttl");
+ const SordNode bundle_node = bundle_uri->val.uri_val;
- /* Parse the manifest into a temporary model */
- librdf_storage* manifest_storage = slv2_world_new_storage(world);
+ SerdNode manifest_uri = slv2_new_uri_relative_to_base(
+ (const uint8_t*)"manifest.ttl",
+ (const uint8_t*)sord_node_get_string(bundle_node));
- librdf_model* manifest_model = librdf_new_model(world->world,
- manifest_storage, NULL);
- librdf_parser_parse_into_model(world->parser, manifest_uri,
- manifest_uri, manifest_model);
+ sord_read_file(world->model, manifest_uri.buf, bundle_node,
+ slv2_world_blank_node_prefix(world));
#ifdef SLV2_DYN_MANIFEST
typedef void* LV2_Dyn_Manifest_Handle;
@@ -267,14 +253,15 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world, world->model,
NULL,
world->rdf_a_node,
- world->dyn_manifest_node);
+ world->dyn_manifest_node,
+ bundle_node);
FOREACH_MATCH(dmanifests) {
SLV2Node dmanifest = slv2_match_subject(dmanifests);
SLV2Matches binaries = slv2_world_find_statements(
world, world->model,
dmanifest,
world->lv2_binary_node,
- NULL);
+ bundle_node);
if (slv2_matches_end(binaries)) {
slv2_match_end(binaries);
SLV2_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n",
@@ -283,7 +270,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
}
SLV2Node binary = slv2_node_copy(slv2_match_object(binaries));
- const uint8_t* lib_uri = librdf_uri_as_string(librdf_node_get_uri(binary));
+ const uint8_t* lib_uri = sord_node_get_string(binary);
const char* lib_path = slv2_uri_to_path((const char*)lib_uri);
if (!lib_path)
continue;
@@ -323,14 +310,15 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
world, dyn_manifest_model,
NULL,
world->rdf_a_node,
- world->lv2_plugin_node);
+ world->lv2_plugin_node,
+ bundle_node);
FOREACH_MATCH(dyn_plugins) {
SLV2Node plugin = slv2_match_subject(dyn_plugins);
// Add ?plugin slv2:dynamic-manifest ?binary to dynamic model
librdf_model_add(
manifest_model, plugin,
- librdf_new_node_from_uri_string(world->world, SLV2_NS_RDFS "seeAlso"),
+ world->slv2_dmanifest_node,
slv2_node_copy(binary));
}
slv2_match_end(dyn_plugins);
@@ -346,63 +334,85 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
#endif // SLV2_DYN_MANIFEST
// ?plugin a lv2:Plugin
- SLV2Matches results = slv2_world_find_statements(
- world, manifest_model,
+ SLV2Matches plug_results = slv2_world_find_statements(
+ world, world->model,
NULL,
world->rdf_a_node,
- world->lv2_plugin_node);
- FOREACH_MATCH(results) {
- SLV2Node plugin = slv2_match_subject(results);
-
- // Add ?plugin rdfs:seeAlso <manifest.ttl>
- librdf_model_add(
- world->model,
- slv2_node_copy(plugin),
- librdf_new_node_from_uri_string(world->world, SLV2_NS_RDFS "seeAlso"),
- librdf_new_node_from_uri(world->world, manifest_uri));
-
- // Add ?plugin slv2:bundleURI <file://some/path>
- librdf_model_add(
- world->model,
- slv2_node_copy(plugin),
- librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
- slv2_node_copy(bundle_uri->val.uri_val));
+ world->lv2_plugin_node,
+ bundle_node);
+ FOREACH_MATCH(plug_results) {
+ SLV2Node plugin_node = slv2_match_subject(plug_results);
+ SLV2Value plugin_uri = slv2_value_new_from_node(world, plugin_node);
+
+ //fprintf(stderr, "Add <%s> in %s\n", sord_node_get_string(plugin_node),
+ // sord_node_get_string(bundle_uri->val.uri_val));
+
+ SLV2Plugin existing = slv2_plugins_get_by_uri(world->plugins, plugin_uri);
+ if (existing) {
+ SLV2_ERRORF("Duplicate plugin <%s>\n", slv2_value_as_uri(plugin_uri));
+ SLV2_ERRORF("... found in %s\n", slv2_value_as_string(
+ slv2_plugin_get_bundle_uri(existing)));
+ SLV2_ERRORF("... and %s\n", sord_node_get_string(bundle_node));
+ slv2_value_free(plugin_uri);
+ continue;
+ }
+
+ // Create SLV2Plugin
+ SLV2Value bundle_uri = slv2_value_new_from_node(world, bundle_node);
+ SLV2Plugin plugin = slv2_plugin_new(world, plugin_uri, bundle_uri);
+
+ // Add manifest as plugin data file (as if it were rdfs:seeAlso)
+ raptor_sequence_push(plugin->data_uris,
+ slv2_value_new_uri(world, (const char*)manifest_uri.buf));
+
+ // Add all plugin data files (rdfs:seeAlso)
+ SLV2Matches files = slv2_world_find_statements(
+ world, world->model,
+ plugin_node,
+ world->rdfs_seealso_node,
+ NULL,
+ NULL);
+ FOREACH_MATCH(files) {
+ SLV2Node file_node = slv2_match_object(files);
+ raptor_sequence_push(plugin->data_uris,
+ slv2_value_new_from_node(world, file_node));
+ }
+
+ // Add plugin to world plugin list
+ raptor_sequence_push(world->plugins, plugin);
+ raptor_sequence_sort(world->plugins, slv2_plugin_compare_by_uri);
}
- slv2_match_end(results);
+ slv2_match_end(plug_results);
// ?specification a lv2:Specification
- results = slv2_world_find_statements(
- world, manifest_model,
+ SLV2Matches spec_results = slv2_world_find_statements(
+ world, world->model,
NULL,
world->rdf_a_node,
- world->lv2_specification_node);
- FOREACH_MATCH(results) {
- SLV2Node spec = slv2_match_subject(results);
+ world->lv2_specification_node,
+ bundle_node);
+ FOREACH_MATCH(spec_results) {
+ SLV2Node spec = slv2_match_subject(spec_results);
// Add ?specification rdfs:seeAlso <manifest.ttl>
- librdf_model_add(
- world->model,
+ SordTuple see_also_tup = {
slv2_node_copy(spec),
- librdf_new_node_from_uri_string(world->world, SLV2_NS_RDFS "seeAlso"),
- librdf_new_node_from_uri(world->world, manifest_uri));
+ world->rdfs_seealso_node,
+ sord_get_uri(world->model, true, (const char*)manifest_uri.buf),
+ NULL
+ };
+ sord_add(world->model, see_also_tup);
// Add ?specification slv2:bundleURI <file://some/path>
- librdf_model_add(
- world->model,
+ SordTuple bundle_uri_tup = {
slv2_node_copy(spec),
- librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
- slv2_node_copy(bundle_uri->val.uri_val));
+ slv2_node_copy(world->slv2_bundleuri_node),
+ slv2_node_copy(bundle_uri->val.uri_val),
+ NULL
+ };
+ sord_add(world->model, bundle_uri_tup);
}
- slv2_match_end(results);
-
- // Join the temporary model to the main model
- librdf_stream* manifest_stream = librdf_model_as_stream(manifest_model);
- librdf_model_add_statements(world->model, manifest_stream);
- librdf_free_stream(manifest_stream);
-
- librdf_free_model(manifest_model);
- librdf_free_storage(manifest_storage);
- librdf_free_uri(manifest_uri);
+ slv2_match_end(spec_results);
}
@@ -463,30 +473,6 @@ slv2_world_load_path(SLV2World world,
}
-/** Comparator for sorting SLV2Plugins */
-int
-slv2_plugin_compare_by_uri(const void* a, const void* b)
-{
- SLV2Plugin plugin_a = *(SLV2Plugin*)a;
- SLV2Plugin plugin_b = *(SLV2Plugin*)b;
-
- return strcmp(slv2_value_as_uri(plugin_a->plugin_uri),
- slv2_value_as_uri(plugin_b->plugin_uri));
-}
-
-
-/** Comparator for sorting SLV2PluginClasses */
-int
-slv2_plugin_class_compare_by_uri(const void* a, const void* b)
-{
- SLV2PluginClass class_a = *(SLV2PluginClass*)a;
- SLV2PluginClass class_b = *(SLV2PluginClass*)b;
-
- return strcmp(slv2_value_as_uri(class_a->uri),
- slv2_value_as_uri(class_b->uri));
-}
-
-
void
slv2_world_load_specifications(SLV2World world)
{
@@ -494,17 +480,22 @@ slv2_world_load_specifications(SLV2World world)
world, world->model,
NULL,
world->rdf_a_node,
- world->lv2_specification_node);
+ world->lv2_specification_node,
+ NULL);
FOREACH_MATCH(specs) {
SLV2Node spec_node = slv2_match_subject(specs);
SLV2Matches files = slv2_world_find_statements(
world, world->model,
spec_node,
world->rdfs_seealso_node,
+ NULL,
NULL);
FOREACH_MATCH(files) {
SLV2Node file_node = slv2_match_object(files);
- slv2_world_load_file(world, librdf_node_get_uri(file_node));
+ sord_read_file(world->model,
+ (const uint8_t*)sord_node_get_string(file_node),
+ NULL,
+ slv2_world_blank_node_prefix(world));
}
slv2_match_end(files);
}
@@ -525,7 +516,8 @@ slv2_world_load_plugin_classes(SLV2World world)
world, world->model,
NULL,
world->rdf_a_node,
- world->rdfs_class_node);
+ world->rdfs_class_node,
+ NULL);
FOREACH_MATCH(classes) {
SLV2Node class_node = slv2_match_subject(classes);
@@ -534,6 +526,7 @@ slv2_world_load_plugin_classes(SLV2World world)
world, world->model,
class_node,
world->rdfs_subclassof_node,
+ NULL,
NULL);
if (slv2_matches_end(parents)) {
@@ -544,7 +537,7 @@ slv2_world_load_plugin_classes(SLV2World world)
SLV2Node parent_node = slv2_node_copy(slv2_match_object(parents));
slv2_match_end(parents);
- if (!librdf_node_is_resource(parent_node)) {
+ if (!sord_node_get_type(parent_node) == SORD_URI) {
// Class parent is not a resource, ignore (e.g. owl restriction)
continue;
}
@@ -554,6 +547,7 @@ slv2_world_load_plugin_classes(SLV2World world)
world, world->model,
class_node,
world->rdfs_label_node,
+ NULL,
NULL);
if (slv2_matches_end(labels)) {
@@ -562,7 +556,7 @@ slv2_world_load_plugin_classes(SLV2World world)
}
SLV2Node label_node = slv2_node_copy(slv2_match_object(labels));
- const uint8_t* label = librdf_node_get_literal_value(label_node);
+ const uint8_t* label = (const uint8_t*)sord_node_get_string(label_node);
slv2_match_end(labels);
SLV2PluginClasses classes = world->plugin_classes;
@@ -573,15 +567,17 @@ slv2_world_load_plugin_classes(SLV2World world)
SLV2PluginClass prev = raptor_sequence_get_at(classes, n_classes - 1);
assert(strcmp(
slv2_value_as_string(slv2_plugin_class_get_uri(prev)),
- (const char*)librdf_uri_as_string(
- librdf_node_get_uri(class_node))) < 0);
+ (const char*)sord_node_get_string(class_node)) < 0);
}
#endif
- raptor_sequence_push(classes,
- slv2_plugin_class_new(world,
- parent_node,
- class_node,
- (const char*)label));
+ SLV2PluginClass pclass = slv2_plugin_class_new(world,
+ parent_node,
+ class_node,
+ (const char*)label);
+
+ if (pclass) {
+ raptor_sequence_push(classes, pclass);
+ }
slv2_node_free(parent_node);
slv2_node_free(label_node);
@@ -641,68 +637,18 @@ slv2_world_load_all(SLV2World world)
slv2_world_load_plugin_classes(world);
- SLV2Matches plugins = slv2_world_find_statements(
- world, world->model,
- NULL,
- world->rdf_a_node,
- world->lv2_plugin_node);
- FOREACH_MATCH(plugins) {
- SLV2Node plugin_node = slv2_match_subject(plugins);
- const char* plugin_uri = (const char*)librdf_uri_as_string(
- librdf_node_get_uri(plugin_node));
-
- SLV2Matches bundles = slv2_world_find_statements(
- world, world->model,
- plugin_node,
- world->slv2_bundleuri_node,
- NULL);
-
- if (slv2_matches_end(bundles)) {
- slv2_match_end(bundles);
- SLV2_ERRORF("Plugin <%s> has no bundle, ignored\n", plugin_uri);
- continue;
- }
-
- SLV2Node bundle_node = slv2_node_copy(slv2_match_object(bundles));
-
- slv2_matches_next(bundles);
- if (!slv2_matches_end(bundles)) {
- slv2_match_end(bundles);
- SLV2_ERRORF("Plugin <%s> found in several bundles, ignored\n",
- plugin_uri);
- continue;
- }
-
- slv2_match_end(bundles);
-
- // Add a new plugin to the world
- SLV2Value uri = slv2_value_new_from_node(world, plugin_node);
- const unsigned n_plugins = raptor_sequence_size(world->plugins);
-#ifndef NDEBUG
- if (n_plugins > 0) {
- // Plugin results are in increasing sorted order
- SLV2Plugin prev = raptor_sequence_get_at(world->plugins, n_plugins - 1);
- assert(strcmp(slv2_value_as_string(slv2_plugin_get_uri(prev)),
- plugin_uri) < 0);
- }
-#endif
-
- SLV2Plugin plugin = slv2_plugin_new(
- world, uri, slv2_value_new_from_node(world, bundle_node));
-
- raptor_sequence_push(world->plugins, plugin);
-
+/* FIXME: move this to slv2_world_load_bundle
#ifdef SLV2_DYN_MANIFEST
{
SLV2Matches dmanifests = slv2_world_find_statements(
world, world->model,
plugin_node,
world->slv2_dmanifest_node,
+ NULL,
NULL);
FOREACH_MATCH(dmanifests) {
SLV2Node lib_node = slv2_match_object(dmanifests);
- const char* lib_uri = (const char*)librdf_uri_as_string(
- librdf_node_get_uri(lib_node));
+ const char* lib_uri = (const char*)sord_node_get_string(lib_node);
if (dlopen(slv2_uri_to_path(lib_uri, RTLD_LAZY))) {
plugin->dynman_uri = slv2_value_new_from_node(world, lib_node);
@@ -711,21 +657,7 @@ slv2_world_load_all(SLV2World world)
slv2_match_end(dmanifests);
}
#endif
- SLV2Matches files = slv2_world_find_statements(
- world, world->model,
- plugin_node,
- world->rdfs_seealso_node,
- NULL);
- FOREACH_MATCH(files) {
- SLV2Node file_node = slv2_match_object(files);
- raptor_sequence_push(plugin->data_uris,
- slv2_value_new_from_node(world, file_node));
- }
- slv2_match_end(files);
-
- slv2_node_free(bundle_node);
- }
- slv2_match_end(plugins);
+*/
}