View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2016, VU University Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(rdf_sandbox, []).

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, while sparql_client is not (unless sparql_client was already loaded before this sequence).

:- use_module(library(semweb/rdf11)).         % safe
:- use_module(library(semweb/rdf_sandbox)).
:- use_module(library(semweb/sparql_client)). % Not safe

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(_,_,_,_)). */

   84:- multifile
   85    sandbox:safe_primitive/1,
   86    sandbox:safe_meta_predicate/1.   87
   88
   89                 /*******************************
   90                 *             RDF_DB           *
   91                 *******************************/
   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                 /*******************************
  126                 *            RDF11             *
  127                 *******************************/
  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                 /*******************************
  138                 *         RDF-LITINDEX         *
  139                 *******************************/
  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                 /*******************************
  148                 *         SPARQL-CLIENT        *
  149                 *******************************/
  150
  151:- if(current_predicate(sparql_client:sparql_query/3)).  152sandbox:safe_primitive(sparql_client:sparql_query(_,_,_)).
  153:- endif.