123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(*********************************************************************************)(* Stog *)(* *)(* Copyright (C) 2012-2024 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 *)(* *)(*********************************************************************************)(** *)openStog.UrlopenConfigopenSessionopenGslet(>>=)=Lwt.bindlethandle_congsbase_pathclient=prerr_endline"new connection";letrecv()=Websocket_lwt_unix.Connected_client.recvclientinletpush=Websocket_lwt_unix.Connected_client.sendclientinletreq=Websocket_lwt_unix.Connected_client.http_requestclientinletstream=Websocket_lwt_unix.mk_frame_streamrecvinleturi=Cohttp.Request.urireqinletpath=Stog_base.Misc.split_string(Uri.pathuri)['/']inmatchpathwith|"sessions"::id::p->beginmatchStog.Types.Str_map.findid!(gs.sessions)with|exceptionNot_found->failwith(Printf.sprintf"Invalid session %S"id)|session->matchpwith|"editor"::_->session.session_editor.editor_ws_cons#add_connectionstreampush|_->session.session_stog.stog_ws_cons:=(stream,push)::!(session.session_stog.stog_ws_cons);letread_stog()=Session.read_stogsession.session_stog.stog_dirinStog_server.Ws.handle_messagesread_stogsession.session_stog.stog_statesession.session_stog.stog_ws_cons(base_path@[id])streampushend|_->failwith"Invalid path";;letservercfggssockaddr=Websocket_lwt_unix.establish_standard_server~check_request:(fun_->true);;letrun_servercfggs=lethost=Stog.Url.hostcfg.ws_url.privinletport=Stog.Url.portcfg.ws_url.privinprerr_endline("Setting up websocket server on host="^host^", port="^(string_of_intport));(* set scheme to http to be resolved correctly *)leturi=letu=Uri.of_string(Stog.Url.to_stringcfg.ws_url.priv)inUri.with_schemeu(Some"http")inResolver_lwt.resolve_uri~uriResolver_lwt_unix.system>>=funendp->letctx=Lazy.forceConduit_lwt_unix.default_ctxinConduit_lwt_unix.endp_to_server~ctxendp>>=funserver->lethandler=handle_congs(Stog.Url.pathcfg.ws_url.pub)inWebsocket_lwt_unix.establish_standard_server~ctx~check_request:(fun_->true)~mode:serverhandler;;