next_inactive up previous







LP/CLP, the Internet, and the WWW

LP/CLP, the Internet, and the WWW

Global Outline

Writing Basic CGI-bin Applications


  1. A standard URL is selected in a browser (client), which is the address of the CGI application, e.g.: http://www.xxx.yyy/cgi_bin/hello_world
  2. The browser sends it to the corresponding HTTP server.
  3. The executable ``hello_world'' (in directory cgi_bin) is started by HTTP server.
  4. Executable output (stdout) (which has to be in HTML -or MIME- format) is taken by the HTTP server, and passed on to the client Browser, which displays it.

\psfig{figure=/home/logalg/public_html/slides/Figs/cgiC80.eps,height=0.55\textheight}

An example: UNIX csh

See http://www.clip.dia.fi.upm.es/demo/pillow/hw_csh.cgi
#!/bin/tcsh

echo "Content-type: text/html"
echo ""
echo "<HTML>"
echo "Hello <B>world</B>."
echo "</HTML>"
echo ""
\psfig{figure=/home/logalg/public_html/slides/Figs/cgiC80.eps,width=\textwidth}

Writing Basic CGI-bin Applications in LP/CLP

See http://www.clip.dia.fi.upm.es/demo/pillow/hw_prolog.cgi

main(_) :- 
  write('Content-type: text/html'), 
  nl, nl,
  write('<HTML>'),
  write('Hello <B>world</B>.'),
  write('</HTML>').
\psfig{figure=/home/logalg/public_html/slides/Figs/cgiC80.eps,width=\textwidth}

Scripting Languages

Effective LP/CLP scripts

See http://www.clip.dia.fi.upm.es/demo/pillow/hw_pshell.cgi

Effective LP/CLP scripts (Contd.)

Relating HTML code and Prolog Terms

Relating HTML code and Prolog Terms

See http://www.clip.dia.fi.upm.es/demo/pillow/hw_pillow.cgi

Relating HTML code and Prolog Terms

Responding to Input: Forms


\psfig{figure=/home/logalg/public_html/slides/Figs/formsC80.eps}


Responding to Input: Forms


\psfig{figure=/home/logalg/public_html/slides/Figs/formsC80.eps,height=0.5\textheight}


Writing Form Handlers in LP/CLP


E.g., predicates provided in PiLLoW:

A browser can be used as a graphical interface!

Writing Form Handlers in LP/CLP: Example

See http://www.clip.dia.fi.upm.es/demo/pillow/simple_form.html

Writing Form Handlers in LP/CLP: Example

See http://www.clip.dia.fi.upm.es/demo/pillow/simple_handler.cgi

Producing Forms from Programs: Example

See http://www.clip.dia.fi.upm.es/demo/pillow/simple_form_pillow.cgi

Producing Forms from Programs: Example

See http://www.clip.dia.fi.upm.es/demo/pillow/simple_form_pillow_sugar.cgi

Combining the Form Producer and Handler

See http://www.clip.dia.fi.upm.es/demo/pillow/combined_form.cgi

#!/bin/sh 
exec /home/clip/bin/ciao-shell $0 $* # -*- mode: ciao; -*-

:- include(library(pillow)).
main(_) :-
    get_form_input(Input),
    get_form_value(Input,person_name,Name),
    output_html([ cgi_reply, html( [ 
              --, h2('You submitted the name: '), em(Name),
              --, h2('Please enter input (person_name):'),
              start_form, %% Refers to self!
              input(text,[name=person_name,size=40]),
              input(submit,[value='Submit']),
              end_form,
              -- ] ) ] ).

A Phones Database

See http://www.clip.dia.fi.upm.es/demo/pillow/phone_db.cgi


response(Name, []) :- form_empty_value(Name), !.
response(Name, ['Phone number for ',bf(Name),' is ',Info, --]) :-
        phone(Name,Info), !.
response(Name, ['No phone number available for ',bf(Name), '.', --]).

%% Database
phone('CLIP',   '336-7448').
phone('Paco',   '554-5225').
phone('Daniel', '460-0569').

A Phones Database (Contd.)

main(_) :-
        get_form_input(Input),
        get_form_value(Input,person_name,Name),
        response(Name,Response),
        output_html([
          cgi_reply,
          begin(html),
          title('Simple CLIP telephone database'),
          begin(body,[background='/demo/images/Clip_bg.gif']),
          center( [ 
            image('/demo/images/clip.gif'),
            heading(2,'Simple CLIP telephone database'),
            --, Response,
            start_form,
            'Click here, enter name of clip member, 
             and press return:',  \\,
            input(text,[name=person_name,size=20]), --,
            end_form,
            image('/demo/images/pillow_d.gif') ]),
          end(body), end(html)]).

HTML/XML Templates

Example of template for phones db

See http://www.clip.dia.fi.upm.es/demo/pillow/html_template.html

<HTML><HEAD><TITLE>Simple CLIP telephone database</TITLE></HEAD>
<BODY background="/demo/images/Clip_bg.gif">
<CENTER>
<IMG src="/demo/images/clip.gif">
<H2>Simple CLIP telephone database</H2>
<HR>
<V>response</V>
<FORM method="POST">
Click here, enter name of clip member, and press return:<BR>
<INPUT type="text" name="person_name" size="20">
<HR>
</FORM>
<IMG src="/demo/images/pillow_d.gif">
</CENTER></BODY></HTML>

Phones db with template

See http://www.clip.dia.fi.upm.es/demo/pillow/phone_db_template.cgi

#! /bin/sh 
exec /home/clip/bin/ciao-shell $0 $* # -*- mode: ciao; -*-

:- include(library(pillow)).
:- use_module(library(file_utils),[file_to_string/2]).

main(_) :-
    get_form_input(Input),
    get_form_value(Input,person_name,Name),
    response(Name,Response),
    file_to_string('html_template.html', Contents),
    html_template(Contents, HTML_terms, [response = Response]),
    output_html([cgi_reply|HTML_terms]).

% response/2 and phone/2 as before.

Accessing WWW/Internet documents from LP/CLP

Accessing WWW/Internet documents from LP/CLP

Accessing WWW/Internet Example: Link Checker

See http://www.clip.dia.fi.upm.es/demo/pillow/check_links.cgi

check_links(URL,BadLinks) :-
        url_info(URL,URLInfo),
        fetch_url(URLInfo,[],Response),
        member(content_type(text,html,_),Response),
        member(content(Content),Response),
        html2terms(Content,Terms),
        check_source_links(Terms,URLInfo,[],BadLinks).

check_source_links([],_,BL,BL).
check_source_links([E|Es],BaseURL,BL0,BL) :-
        check_source_links1(E,BaseURL,BL0,BL1),
        check_source_links(Es,BaseURL,BL1,BL).
check_source_links1(env(a,AnchorAtts,_),BaseURL,BL0,BL) :-
        member((href=URL),AnchorAtts), !,
        check_link(URL,BaseURL,BL0,BL).
check_source_links1(env(_Name,_Atts,Env_html),BaseURL,BL0,BL) :- !,
        check_source_links(Env_html,BaseURL,BL0,BL).
check_source_links1(_,_,BL,BL).

Accessing WWW/Internet Example: Link Checker (Contd.)

check_link(URL,BaseURL,BL0,BL) :-
        url_info_relative(URL,BaseURL,URLInfo), !,
        fetch_url_status(URLInfo,Status,Phrase),
        ( Status \== success ->
          name(P,Phrase),
          name(U,URL),
          BL = [badlink(U,P)|BL0]
        ; BL = BL0
        ).
check_link(_,_,BL,BL).

fetch_url_status(URL,Status,Phrase) :-
        fetch_url(URL,[head,timeout(20)],Response), !,
        member(status(Status,_,Phrase),Response).
fetch_url_status(_,timeout,timeout).

Limitations of CGI

\psfig{figure=/home/logalg/public_html/slides/Figs/cgiC80.eps,height=0.5\textheight}

Solving the Limitations of CGI

\psfig{figure=/home/logalg/public_html/slides/Figs/auxiliaryC80.eps}

Solving the Limitations of CGI

\psfig{figure=/home/logalg/public_html/slides/Figs/formactive75.eps,height=0.35\textheight}

Active Modules / Active Objects

Using Active Modules: An Example

Using Active Modules: An Example

Application: Active Modules as Form Servers

\psfig{figure=/home/logalg/public_html/slides/Figs/formactive75.eps,width=0.95\textwidth}

Phone DB Using Active Modules: Server

:- module(_,[process_form/2],[pillow]).
:- use_module(library(file_utils),[file_to_string/2]).

process_form(Input,Output) :-
    get_form_value(Input,person_name,Name),
    response(Name,Response),
    file_to_string('html_template.html', Contents),
    html_template(Contents, HTML_terms, [response = Response]),
    Output = [cgi_reply|HTML_terms].

response(Name, []) :- form_empty_value(Name), !.
response(Name, ['Phone number for ',bf(Name),' is ',Info, --]) :-
        phone(Name,Info), !.
response(Name, ['No phone number available for ',bf(Name), '.', --]).

%% Database
phone('CLIP',   '336-7448').
phone('Paco',   '554-5225').
phone('Daniel', '460-0569').

Phone DB Using Active Modules: Client

See http://www.clip.dia.fi.upm.es/demo/pillow/phone_db_client.cgi

:- module(_,[main/1],[actmods,pillow]).

:- use_active_module(phone_db_server, [process_form/2]).
:- use_module(library('actmods/filebased_locate')).

main(_) :-
    get_form_input(Input),
    process_form(Input,Output),
    output_html(Output).

Phone DB Using Active Modules: Adding Phones


See http://www.clip.dia.fi.upm.es/demo/pillow/phone_db_client2.cgi


:- module(_,[process_form/2],[pillow]).
:- use_module(library(file_utils),[file_to_string/2]).
:- use_module(library(dynamic)).

process_form(Input,[cgi_reply|HTML_terms]) :-
    (  get_form_value(Input,input_name,IName),  \+ form_empty_value(IName)
    -> get_form_value(Input,phone_name,PName),  assert(phone(IName,PName)),
       Response = [ 'Added ', b(IName), ' / ',  b(PName), -- ]
    ;  get_form_value(Input,person_name,Name),  response(Name,Response) ),
    file_to_string('html_template2.html', Contents),
    html_template(Contents, HTML_terms, [response = Response]).

response(Name, []) :- form_empty_value(Name), !.
response(Name, ['Phone number for ',b(Name),' is ',Info, --]) :- phone(Name,Info), !.
response(Name, ['No phone number available for ',b(Name), '.', --]).

:- dynamic phone/2.
phone('CLIP',   '336-7448'). phone('Paco',   '554-5225'). phone('Daniel', '460-0569').

Phone DB Using Active Modules: Adding Phones w/Persistence


See http://www.clip.dia.fi.upm.es/demo/pillow/phone_db_client2pers.cgi


:- module(_,[process_form/2],[pillow,persdb]).
:- use_module(library(file_utils),[file_to_string/2]).
:- use_module(library(dynamic)).

process_form(Input,[cgi_reply|HTML_terms]) :-
    (  get_form_value(Input,input_name,IName), \+ form_empty_value(IName)
    -> get_form_value(Input,phone_name,PName),
        passertz_fact(phone(IName,PName)),
       Response = [ 'Added ', b(IName), ' / ', b(PName), hr$[] ]
    ;  get_form_value(Input,person_name,Name), response(Name,Response) ),
    file_to_string('html_template2.html', Contents),
    html_template(Contents, HTML_terms, [response = Response]).

response(Name, []) :- form_empty_value(Name), !.
response(Name, ['Phone number for ',b(Name),' is ',Info, --]) :- phone(Name,Info), !.
response(Name, ['No phone number available for ',b(Name), '.', --]).

Phone DB Using Active Modules: Adding Phones w/Pers (Cont.)

:- initialization(init_persdb).

:- multifile persistent_dir/2.
:- data persistent_dir/2.
persistent_dir(db,'./').

:- persistent(phone/2,db).
%% Database
phone('CLIP',   '336-7448').
phone('Paco',   '554-5225').
phone('Daniel', '460-0569').

Achieving Client-side (``Java-like'') Functionality

Automatic Code Downloading for Local Execution

Automatic Code Downloading Procedure



Automatic Code Downloading Procedure - Figure

\psfig{figure=/home/logalg/public_html/slides/Figs/formcodeC75_por.eps,height=0.9\textheight}

Higher-Level Models

Several models can be defined which provide a higher level of abstraction (e.g., higher level than PiLLoW):

Some Other Work on LP/CLP + WWW

Some Conclusions / Other Issues

Some Conclusions / Other Issues (Contd.)


next_inactive up previous
Last modification: Thu Nov 23 00:03:59 CET 2006 <webmaster@clip.dia.fi.upm.es>[CLIP] [FIM] [UNM]