diff options
author | David Robillard <d@drobilla.net> | 2011-01-29 23:03:54 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-29 23:03:54 +0000 |
commit | 1c040fd172230496d655ddce6033e8daa9ffa023 (patch) | |
tree | d936a92ef3faf61be6b074e42bbb2d5678151d27 | |
parent | 824a8c52a42300b1622fad16d7211984a2d518d6 (diff) | |
download | lilv-1c040fd172230496d655ddce6033e8daa9ffa023.tar.gz lilv-1c040fd172230496d655ddce6033e8daa9ffa023.tar.bz2 lilv-1c040fd172230496d655ddce6033e8daa9ffa023.zip |
Non-SPARQL versions of slv2_plugin_*_author functions.
10 queries left!
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2859 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/plugin.c | 106 |
1 files changed, 52 insertions, 54 deletions
diff --git a/src/plugin.c b/src/plugin.c index 7fb6e35..716e321 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -152,6 +152,19 @@ slv2_plugin_get_unique(SLV2Plugin p, librdf_node* subject, librdf_node* predicat slv2_values_free(values); return ret; } + + +static SLV2Value +slv2_plugin_get_one(SLV2Plugin p, librdf_node* subject, librdf_node* predicate) +{ + SLV2Values values = slv2_plugin_query_node(p, subject, predicate); + if (!values) { + return NULL; + } + SLV2Value ret = slv2_value_duplicate(slv2_values_get_at(values, 0)); + slv2_values_free(values); + return ret; +} /* private */ @@ -832,82 +845,67 @@ slv2_plugin_get_port_by_symbol(SLV2Plugin p, return NULL; } +#define NS_DOAP (const uint8_t*)"http://usefulinc.com/ns/doap#" +#define NS_FOAF (const uint8_t*)"http://xmlns.com/foaf/0.1/" -SLV2Value -slv2_plugin_get_author_name(SLV2Plugin plugin) +static librdf_node* +slv2_plugin_get_author(SLV2Plugin p) { - SLV2Value ret = NULL; - - const char* const query = - "SELECT ?name WHERE {\n" - " <> doap:maintainer ?maint . \n" - " ?maint foaf:name ?name . \n" - "}\n"; - SLV2Values results = slv2_plugin_query_variable(plugin, query, 0); + librdf_stream* maintainers = slv2_plugin_find_statements( + p, + librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val), + librdf_new_node_from_uri_string(p->world->world, NS_DOAP "maintainer"), + NULL); - if (results && slv2_values_size(results) > 0) { - SLV2Value val = slv2_values_get_at(results, 0); - if (slv2_value_is_string(val)) - ret = slv2_value_duplicate(val); + if (librdf_stream_end(maintainers)) { + return NULL; } - if (results) - slv2_values_free(results); + librdf_node* author = librdf_new_node_from_node( + librdf_statement_get_object(librdf_stream_get_object(maintainers))); - return ret; + librdf_free_stream(maintainers); + return author; } SLV2Value -slv2_plugin_get_author_email(SLV2Plugin plugin) +slv2_plugin_get_author_name(SLV2Plugin plugin) { - SLV2Value ret = NULL; - - const char* const query = - "SELECT ?email WHERE {\n" - " <> doap:maintainer ?maint . \n" - " ?maint foaf:mbox ?email . \n" - "}\n"; - - SLV2Values results = slv2_plugin_query_variable(plugin, query, 0); - - if (results && slv2_values_size(results) > 0) { - SLV2Value val = slv2_values_get_at(results, 0); - if (slv2_value_is_uri(val)) - ret = slv2_value_duplicate(val); + librdf_node* 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")); } + return NULL; +} - if (results) - slv2_values_free(results); - return ret; +SLV2Value +slv2_plugin_get_author_email(SLV2Plugin plugin) +{ + librdf_node* 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")); + } + return NULL; } SLV2Value slv2_plugin_get_author_homepage(SLV2Plugin plugin) { - SLV2Value ret = NULL; - - const char* const query = - "SELECT ?page WHERE {\n" - " <> doap:maintainer ?maint . \n" - " ?maint foaf:homepage ?page . \n" - "}\n"; - - SLV2Values results = slv2_plugin_query_variable(plugin, query, 0); - - if (results && slv2_values_size(results) > 0) { - SLV2Value val = slv2_values_get_at(results, 0); - if (slv2_value_is_uri(val)) - ret = slv2_value_duplicate(val); + librdf_node* 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")); } - - if (results) - slv2_values_free(results); - - return ret; + return NULL; } |