12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485(*********************************************************************************)(* Stog *)(* *)(* Copyright (C) 2012-2015 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as *)(* published by the Free Software Foundation, version 3 of the License. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(** *)openRunopenStog.UrlopenStog.TypesmoduleS=Cohttp_lwt_unix.Serverlet(>>=)=Lwt.bindletnew_stog_sessionstog~http_urlbase_path=letstog_base_url=Http.preview_urlhttp_urlbase_pathinPreview.new_stog_sessionstogstog_base_urlletstart_servercurrent_state~http_url~ws_urlbase_path=lethost=Stog.Url.hosthttp_url.privinletport=Stog.Url.porthttp_url.privinLwt_io.writeLwt_io.stdout(Printf.sprintf"Listening for HTTP request on: %s:%d\n\
Open http://%s:%d/preview"hostporthostport)>>=fun_->letconn_closed(_,id)=ignore(Lwt_io.writeLwt_io.stdout(Printf.sprintf"connection %s closed\n%!"(Cohttp.Connection.to_stringid)))inletconfig=S.make~callback:(funsockreqbody->Http.handlercurrent_state~http_url~ws_urlbase_pathreq)~conn_closed()inConduit_lwt_unix.init~src:host()>>=functx->letctx=Cohttp_lwt_unix.Net.init~ctx()inletmode=`TCP(`Portport)inS.create~ctx~modeconfigletlaunchread_stogstog~http_url~ws_urlbase_path=letread_stog()=letstog=read_stog()inletstog={stogwithStog.Types.stog_outdir="stog-output"}instoginlet(current_state,active_cons)=new_stog_sessionstog~http_urlbase_pathinlet_ws_server=Ws.run_serverread_stogcurrent_stateactive_consws_urlbase_pathinstart_servercurrent_state~http_url~ws_urlbase_pathlet()=letrunread_stogstog~http_url~ws_url=Lwt_main.run(launchread_stogstog~http_url~ws_url[])inStog.Server_mode.set_singlerun