:- use_module(library('http/xpce_httpd')). :- use_module(plht). :- dynamic published_dir/2. :- dynamic published_pred/2. :- dynamic index_file/1. :- dynamic simple_mime/2. :- dynamic processed_file/2. published_dir('/doc','/usr/local/httpd/htdocs'). published_dir('/','/home/yannick/proj/LUSE/web/'). index_file('index.html'). index_file('index.plht'). simple_mime('.html','text/html'). simple_mime('.htm','text/html'). simple_mime('.txt','text/plain'). simple_mime('.gif','image/gif'). simple_mime('.jpg','image/jpeg'). simple_mime('.png','image/png'). processed_file('.plht',process_plht). join_path(Dir,Fname,Path):- atom_concat(Dir,'/',Dir2), atom_concat(Dir2,Fname,Path). %%% TODO: %%% doesn't allow things like /blah/foo.plht/mumble/schnuck %%% loop could have a "cycle" attribute %%% as in reply(Query):- member(path(Path),Query), published_dir(Path_Prefix,Real_Dir), atom_concat(Path_Prefix,Path_Suffix,Path), atom_concat(Real_Dir,Path_Suffix,Path1), absolute_file_name(Path1,Real_Path), atom_concat(Real_Dir,_,Real_Path), ( exists_file(Real_Path), publish_file(Real_Path,Query); exists_directory(Real_Path), index_file(I), join_path(Real_Path,I,Path2), exists_file(Path2), publish_file(Path2,Query)). reply(Query):- member(path(Path),Query), published_pred(Path_Prefix,Pred), atom_concat(Path_Prefix,Path_Suffix,Path), call(Pred,[path_suffix(Path_Suffix)|Query]). publish_file(Real_Path,_):- simple_mime(Ext,Mimetype), atom_concat(_,Ext,Real_Path), format('Content-type: ~a\r\n\r\n',[Mimetype]), open(Real_Path,read,In), current_output(Out), copy_stream_data(In,Out), close(In). publish_file(Real_Path,Query):- processed_file(Ext,Pred), atom_concat(_,Ext,Real_Path), call(Pred,Real_Path,Query). %publish_file(Real_Path,Query):- % write('Content-type: text/plain\r\n\r\n'), % format('filename: ~q\n',[Real_Path]). process_plht(Real_Path,Query):- hash_term(Real_Path,Hash), atom_concat(plht_,Hash,PredName), atom_concat(PredName,'.pl',FileName), ( current_predicate(PredName/1), time_file(FileName,TimePL), time_file(Real_Path,TimePLHT), TimePLHT