Here is the code of the chat server:
chat_server_interactor(mes(From,Cs),Answer):-show_mes(From,Cs,Answer). chat_server_interactor(ping(T),R):-term_server_interactor(ping(T),R). chat_server_interactor(run(_),no). chat_server_interactor(run(_,_),no). chat_server:- server_interactor(chat_server_interactor)=>> run_server.
Basically, by overriding the default server_interactor with our chat_server_interactor we tell to chat_server that only commands matching known, secure operations has to be performed on behalf of remote users.
This might look very simple but some of BinProlog's key features (intuitionistic implication and higher-order call/N) are used inside the `generic' server code (see file extra.pl) to achieve this form of `configurability'.
Here is some interactor code (which might change in the future) for two other `secure' servers.
The first one (BinProlog's default) is a Linda+chat server (to be started with run_server/0). It offers an good combination of security and convenience: only allows modifying its dynamic database remotely through Linda operations and displaying messages. It can be shut down remotely (with password) and checked if alive and although it can be subject to resource attacks by malicious users it can do no harm to your files system or give away information about your computer.
term_server_interactor(cin(X),R):-serve_cin(X,R). term_server_interactor(out(X),R):-serve_out(X,R). term_server_interactor(cout(X),R):-serve_cout(X,R). term_server_interactor(rd(X),R):-serve_rd(X,R). term_server_interactor(all(X),Xs):-serve_facts(X,X,Xs). term_server_interactor(all(X,G),Xs):-serve_facts(X,G,Xs). term_server_interactor(id(R),R):-this_id(R). term_server_interactor(ping(T),T):-ctime(T). term_server_interactor(stop(W),yes):-assumel(server_done(W)). term_server_interactor(halt(X),R):-serve_halt(X,R). term_server_interactor(add_servant(X),R):-serve_add_servant(X,R). term_server_interactor(mes(From,Cs),Answer):- show_mes(From,Cs,Answer), forward_to_servants(mes(From,Cs)). term_server_interactor(proxy(H,P,Q),R):- ask_a_server(H,P,Q,A)->R=A;R=no. term_server_interactor(in(X),R):-serve_cin(X,R). % $$thish should block!!!
Note that this interactor even supports proxy forwarding to a give host/port as well as forwarding to passive pseudo-servers (called `servants', which work by watching for given patterns on real servers and reacting back) and in particular to the Java applets in related package LindaInteractor.tar.gz. Note that the secure execution of forwarded queries are the responsibility of the proxy target.