View source with formatted 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, []).   36
   37/** <module> Declare RDF API sandbox-safe
   38
   39This   module   provides   clauses   for     the   multifile   predicate
   40sandbox:safe_primitive/1  defined  in  library(sandbox)  that  make  all
   41predicates of the RDF API that have   no permanent side effects safe. To
   42have an affect, this  module  must  be   *loaded  after  the  modules it
   43declares safe*. Thus, when using the   sequence  below, `rdf11` is safe,
   44while `sparql_client` is not (unless   sparql_client  was already loaded
   45before this sequence).
   46
   47  ```
   48  :- use_module(library(semweb/rdf11)).         % safe
   49  :- use_module(library(semweb/rdf_sandbox)).
   50  :- use_module(library(semweb/sparql_client)). % Not safe
   51  ```
   52
   53Normally, sandbox declarations live in  the   module  in  which the safe
   54predicates are defined, so we are sure  we are making declarations about
   55this specific version of a predicate. For   RDF we decoupled the sandbox
   56declarations  from  the  implementation  because    although   rdf/3  is
   57technically safe to use (calling it has   no side effects), it may _make
   58information accessible_ that is not supposed to be.
   59
   60Loading this library makes all   side-effect-free  predicates considered
   61safe. If some of your RDF needs to  remain hidden, you should *not* load
   62this file and instead use your own   version that project your data. The
   63example below defines a wrapper around   rdf/4 that provides safe access
   64to certain graphs.
   65
   66``` :- module(rdf_api,
   67          [ rdf/4
   68          ]).
   69:- use_module(library(semweb/rdf11)).
   70
   71:- rdf_meta rdf(r,r,o,r).
   72
   73rdf(S,P,O,G) :-
   74        public_graph(G), !,
   75        rdf11:rdf(S,P,O,G).
   76rdf(S,P,O,G) :-
   77        permission_error(access, graph, G).
   78
   79:- multifile sandbox:safe_primitive/1.
   80
   81sandbox:safe_primitive(rdf_api:rdf(_,_,_,_)).
   82*/
   83
   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_db:rdf_current_prefix/2).
  121sandbox:safe_meta_predicate(rdf_db: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(_,_)).
  133:- endif.  134
  135
  136                 /*******************************
  137                 *         RDF-LITINDEX         *
  138                 *******************************/
  139
  140:- if(current_predicate(rdf_litindex:rdf_find_literals/2)).  141sandbox:safe_primitive(rdf_litindex:rdf_find_literals(_,_)).
  142sandbox:safe_primitive(rdf_litindex:rdf_tokenize_literal(_,_)).
  143sandbox:safe_primitive(rdf_litindex:rdf_literal_index(_,_)).
  144:- endif.  145
  146                 /*******************************
  147                 *         SPARQL-CLIENT        *
  148                 *******************************/
  149
  150:- if(current_predicate(sparql_client:sparql_query/3)).  151sandbox:safe_primitive(sparql_client:sparql_query(_,_,_)).
  152:- endif.