34
35:- module(rdf_sandbox, []).
84:- multifile
85 sandbox:safe_primitive/1,
86 sandbox:safe_meta_predicate/1. 87
88
89 92
93:- if(current_predicate(rdf_db:rdf/3)). 94sandbox:safe_primitive(rdf_db:rdf(_,_,_)).
95sandbox:safe_primitive(rdf_db:rdf(_,_,_,_)).
96sandbox:safe_primitive(rdf_db:rdf_has(_,_,_)).
97sandbox:safe_primitive(rdf_db:rdf_has(_,_,_,_)).
98sandbox:safe_primitive(rdf_db:rdf_reachable(_,_,_)).
99sandbox:safe_primitive(rdf_db:rdf_reachable(_,_,_,_,_)).
100sandbox:safe_primitive(rdf_db:rdf_resource(_)).
101sandbox:safe_primitive(rdf_db:rdf_subject(_)).
102sandbox:safe_primitive(rdf_db:rdf_predicate_property(_,_)).
103sandbox:safe_primitive(rdf_db:rdf_current_predicate(_)).
104sandbox:safe_primitive(rdf_db:rdf_current_literal(_)).
105sandbox:safe_primitive(rdf_db:rdf_graph(_)).
106sandbox:safe_primitive(rdf_db:rdf_generation(_)).
107sandbox:safe_primitive(rdf_db:rdf_estimate_complexity(_,_,_,_)).
108sandbox:safe_primitive(rdf_db:rdf_statistics(_)).
109sandbox:safe_primitive(rdf_db:lang_matches(_,_)).
110sandbox:safe_primitive(rdf_db:lang_equal(_,_)).
111sandbox:safe_primitive(rdf_db:rdf_version(_)).
112sandbox:safe_primitive(rdf_db:rdf_md5(_,_)).
113sandbox:safe_primitive(rdf_db:rdf_graph_modified_(_,_,_)).
114sandbox:safe_primitive(rdf_db:rdf_graph_source_(_,_,_)).
115sandbox:safe_primitive(rdf_db:rdf_graph_(_,_)).
116sandbox:safe_primitive(rdf_db:rdf_find_literal_map(_,_,_)).
117sandbox:safe_primitive(rdf_db:rdf_keys_in_literal_map(_,_,_)).
118sandbox:safe_primitive(rdf_db:rdf_statistics_literal_map(_,_)).
119
120sandbox:safe_meta_predicate(rdf_prefixes:rdf_current_prefix/2).
121sandbox:safe_meta_predicate(rdf_prefixes:rdf_global_id/2).
122:- endif. 123
124
125 128
129:- if(current_predicate(rdf11:in_xml_literal/3)). 130sandbox:safe_primitive(rdf11:in_xml_literal(_,_,_)).
131sandbox:safe_primitive(rdf11:pre_object(_,_,_,_)).
132sandbox:safe_primitive(rdf11:post_object(_,_)).
133sandbox:safe_primitive(rdf11:rdf_where(_)).
134:- endif. 135
136
137 140
141:- if(current_predicate(rdf_litindex:rdf_find_literals/2)). 142sandbox:safe_primitive(rdf_litindex:rdf_find_literals(_,_)).
143sandbox:safe_primitive(rdf_litindex:rdf_tokenize_literal(_,_)).
144sandbox:safe_primitive(rdf_litindex:rdf_literal_index(_,_)).
145:- endif. 146
147 150
151:- if(current_predicate(sparql_client:sparql_query/3)). 152sandbox:safe_primitive(sparql_client:sparql_query(_,_,_)).
153:- endif.
Declare RDF API sandbox-safe
This module provides clauses for the multifile predicate sandbox:safe_primitive/1 defined in library(sandbox) that make all predicates of the RDF API that have no permanent side effects safe. To have an affect, this module must be loaded after the modules it declares safe. Thus, when using the sequence below,
rdf11
is safe, whilesparql_client
is not (unless sparql_client was already loaded before this sequence).Normally, sandbox declarations live in the module in which the safe predicates are defined, so we are sure we are making declarations about this specific version of a predicate. For RDF we decoupled the sandbox declarations from the implementation because although rdf/3 is technically safe to use (calling it has no side effects), it may make information accessible that is not supposed to be.
Loading this library makes all side-effect-free predicates considered safe. If some of your RDF needs to remain hidden, you should not load this file and instead use your own version that project your data. The example below defines a wrapper around rdf/4 that provides safe access to certain graphs.
` :-
module(rdf_api, [ rdf/4 ])
. :-use_module(library(semweb/rdf11))
.:- rdf_meta
rdf(r,r,o,r)
.rdf(S,P,O,G)
:-public_graph(G)
, !, rdf11:rdf(S,P,O,G)
.rdf(S,P,O,G)
:-permission_error(access, graph, G)
.:- multifile sandbox:safe_primitive/1.
sandbox:
safe_primitive(rdf_api:rdf(_,_,_,_))
. */