Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Ocsigen Server without configuration file (and with static linking) #238

Merged
merged 32 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ff96bd7
Remove the ability to switch to another user/group when launched as root
balat Apr 26, 2024
3258804
Ignoring command pipe creation failure
balat Apr 26, 2024
1cc3c8a
Removing commandpipe creation in Makefile
balat Apr 26, 2024
3d93a57
Static linking: making it possible for extensions' instructions to ha…
balat Apr 27, 2024
13b04a6
Static linking: using new instruction system for authbasic
balat Apr 27, 2024
0dcc26d
Static linking: fix order or instructions
balat Apr 27, 2024
c20b6fe
Static linking: using new instruction system for cors
balat Apr 27, 2024
d68e493
Static linking: using new instruction system for deflatemod
balat Apr 27, 2024
680e44b
Static linking: using new instruction system for outputfilter
balat Apr 27, 2024
14caae1
Static linking: using new instruction system for redirectmod
balat Apr 27, 2024
8375488
Static linking: using new instruction system for revproxy
balat Apr 27, 2024
2c8eb92
Static linking: using new instruction system for rewritemod
balat Apr 27, 2024
a64dfe8
Static linking: Simplify extension registration (remove Hmap for config)
balat May 4, 2024
62c3d73
Static linking: call register from run functions in extensions
balat May 4, 2024
9e01472
Add Ocsigen_loader.add_module_init_function
balat May 9, 2024
34b787b
Static linking: new interface in Ocsigen_server
balat May 10, 2024
4e0af2c
Static linking: fail if main loop is run twice
balat May 11, 2024
c74eb76
Static linking: add Ocsigen_config.has_configuration_file
balat May 11, 2024
32e511c
Adding main config options to Ocsigen_server.start
balat Jun 7, 2024
bbb045c
Ocamlformat 0.26.2
balat Jun 7, 2024
134d0d6
Doc: staticmod API
balat Jun 15, 2024
ab5c88c
Fix API doc generation
balat Jun 15, 2024
05c4550
Static linking: extendconfiguration
balat Aug 20, 2024
56c6f4e
Static linking: accesscontrol
balat Aug 21, 2024
3f9d5b1
Ocsigen_server: use ~regexp instead of ~re (uniformisation)
balat Aug 21, 2024
988a905
Static linking: improve API doc of extensions
balat Aug 21, 2024
0ceece5
Redirectmod: removing deprecated (and ambiguous) regexp option
balat Aug 21, 2024
be8b0fe
Accesscontrol: rephrase unclear debugging messages
balat Aug 21, 2024
61acd28
Revproxy: removing deprecated (and ambiguous) regexp option
balat Aug 23, 2024
98df03a
Outputfiler: use string fro regexp
balat Aug 23, 2024
731e32c
Extensions: API doc improvements
balat Aug 23, 2024
50bf9e4
6.0.0
balat May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.26.1
version=0.26.2
break-cases = fit
break-collection-expressions = fit-or-vertical
break-fun-decl = wrap
Expand Down
11 changes: 2 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include Makefile.options
include Makefile.config
include Makefile.options

### Building

.PHONY: default all
.PHONY: default all doc
default all: build

.PHONY: build
Expand Down Expand Up @@ -74,13 +74,6 @@ install.files:
@echo
@echo "## Run \"make doc\" and \"make install.doc\" to build and install the ocamldoc."
@echo INSTALL_CAN_PUT_PERMISSIONS: ${INSTALL_CAN_PUT_PERMISSIONS}
## Command pipe
$(INSTALL) -m ${INSTALL_MOD_755} -d $(dir $(TEMPROOT)$(COMMANDPIPE))
[ -p $(TEMPROOT)$(COMMANDPIPE) ] || \
{ mkfifo -m ${INSTALL_MOD_660} $(TEMPROOT)$(COMMANDPIPE); \
if [ "${INSTALL_CAN_PUT_PERMISSIONS}" = yes ]; \
then $(CHOWN) -R $(OCSIGENUSER):"$(OCSIGENGROUP)" $(TEMPROOT)$(COMMANDPIPE); \
fi; }
## Configuration files
$(INSTALL) -m ${INSTALL_MOD_755} -d $(TEMPROOT)$(CONFIGDIR)/conf.d
${INSTALL} -m ${INSTALL_MOD_644} ocsigenserver.conf.sample $(TEMPROOT)$(CONFIGDIR)/
Expand Down
2 changes: 1 addition & 1 deletion Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ INCS= -I ${BLD}/server/.ocsigenserver.objs/byte \
## ${SERVER_PACKAGE} is not only used to build the 'ocsigenserver' executable
## but also to generate src/baselib/ocsigen_config_static.ml

SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,lwt_log,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix,hmap
SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,lwt_log,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix

LIBS := -package ${SERVER_PACKAGE} ${INCS}

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.2
6.0.0
16 changes: 12 additions & 4 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DOC := baselib/ocsigen_cache.mli \
http/ocsigen_header.mli \
\
server/ocsigen_config.mli \
server/ocsigen_command.mli \
server/ocsigen_request.mli \
server/ocsigen_response.mli \
server/ocsigen_messages.mli \
Expand All @@ -26,10 +27,17 @@ DOC := baselib/ocsigen_cache.mli \
server/ocsigen_local_files.mli \
server/ocsigen_server.mli

PLUGINS_DOC := extensions/accesscontrol.mli extensions/authbasic.mli \
extensions/outputfilter.mli \
extensions/redirectmod.mli extensions/staticmod.mli \
extensions/deflatemod/deflatemod.mli
PLUGINS_DOC := extensions/accesscontrol.mli \
extensions/authbasic.mli \
extensions/outputfilter.mli \
extensions/extendconfiguration.mli \
extensions/redirectmod.mli \
extensions/rewritemod.mli \
extensions/userconf.mli \
extensions/revproxy.mli \
extensions/staticmod.mli \
extensions/deflatemod.mli \
extensions/cors.mli

all: doc wikidoc

Expand Down
21 changes: 18 additions & 3 deletions doc/indexdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
{1 Ocsigen server - API reference}
{!modules:
Ocsigen_server
}
{2 Extensions}
{!modules:
Staticmod
Extendconfiguration
Accesscontrol
Authbasic
Deflatemod
Redirectmod
Revproxy
Rewritemod
Outputfilter
Userconf
Cors
}

{2 Persistent data, writing in the logs, configuration file extension, polymorphic tables}
{!modules:
Expand All @@ -14,10 +31,8 @@ Ocsigen_config
{!modules:
Ocsigen_extensions
Ocsigen_local_files
Ocsigen_headers
Ocsigen_header
Ocsigen_stream
Ocsigen_comet
Authbasic
}

{2 Indexes}
Expand Down
3 changes: 1 addition & 2 deletions ocsigenserver.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "ocsigenserver"
version: "5.1.2"
version: "6.0.0"
maintainer: "[email protected]"
synopsis: "A full-featured and extensible Web server"
description: "Ocsigen Server implements most features of the HTTP protocol, and has a very powerful extension mechanism that makes it very easy to plug your own OCaml modules for generating pages. Many extensions are already implemented, like a reverse proxy, content compression, access control, authentication, etc."
Expand Down Expand Up @@ -59,7 +59,6 @@ depends: [
"ipaddr" {>= "2.1"}
"cohttp-lwt-unix" {>= "5.0.0" & < "6.0.0~"}
"conduit-lwt-unix" {>= "2.0.0"}
"hmap"
"xml-light"
"camlzip"
]
Expand Down
4 changes: 0 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ confs: ../ocsigenserver.conf.sample ../local/etc/ocsigenserver.conf
cat $< \
| sed s%_LOGDIR_%$(LOGDIR)%g \
| sed s%_DATADIR_%$(DATADIR)%g \
| sed s%_OCSIGENUSER_%$(OCSIGENUSER)%g \
| sed s%_OCSIGENGROUP_%"$(OCSIGENGROUP)"%g \
| sed s%_COMMANDPIPE_%$(COMMANDPIPE)%g \
| sed s%_MIMEFILE_%$(CONFIGDIR)/mime.types%g \
| sed s%_METADIR_%$(LIBDIR)%g \
Expand All @@ -30,8 +28,6 @@ confs: ../ocsigenserver.conf.sample ../local/etc/ocsigenserver.conf
| sed s%80\</port\>%8080\</port\>%g \
| sed s%_LOGDIR_%$(SRC)/local/var/log%g \
| sed s%_DATADIR_%$(SRC)/local/var/lib%g \
| sed s%\<user\>_OCSIGENUSER_\</user\>%%g \
| sed s%\<group\>_OCSIGENGROUP_\</group\>%%g \
| sed s%_COMMANDPIPE_%$(SRC)/local/var/run/ocsigenserver_command%g \
| sed s%_MIMEFILE_%$(SRC)/src/files/mime.types%g \
| sed s%_METADIR_%${LIBDIR}\"/\>\<findlib\ path=\"$(SRC)/src/files/\"/\>\<findlib\ path=\"$(SRC)/src/extensions/files/%g \
Expand Down
2 changes: 0 additions & 2 deletions src/baselib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ ocsigen_config_static.ml: ocsigen_config_static.ml.in ../../Makefile.config ../.
| sed s%_EXTDIR_%$(LIBDIR)/ocsigenserver/extensions%g \
| sed s%_STATICPAGESDIR_%$(STATICPAGESDIR)% \
| sed s%_UP_%$(UPLOADDIR)%g \
| sed s%_OCSIGENUSER_%$(OCSIGENUSER)%g \
| sed s%_OCSIGENGROUP_%"$(OCSIGENGROUP)"%g \
| sed s%_COMMANDPIPE_%$(COMMANDPIPE)%g \
| sed s%_CONFIGDIR_%$(CONFIGDIR)% \
| sed s%_ISNATIVE_%$(NATIVECODE_RUNTIME_DETECT)%g \
Expand Down
2 changes: 0 additions & 2 deletions src/baselib/ocsigen_config_static.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ let version_number = "_VERSION_"
let config_file = ref "_CONFIGDIR_/ocsigenserver.conf"
let is_native = Sys.backend_type = Sys.Native
let logdir = ref (Some "_LOGDIR_")
let default_user = ref "_OCSIGENUSER_"
let default_group = ref "_OCSIGENGROUP_"
let mimefile = ref "_CONFIGDIR_/mime.types"
let datadir = ref "_DATADIR_"
let bindir = ref "_BINDIR_"
Expand Down
2 changes: 0 additions & 2 deletions src/baselib/ocsigen_config_static.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ val version_number : string
val config_file : string ref
val is_native : bool
val logdir : string option ref
val default_user : string ref
val default_group : string ref
val mimefile : string ref
val datadir : string ref
val bindir : string ref
Expand Down
48 changes: 28 additions & 20 deletions src/baselib/ocsigen_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,39 @@ let loadfiles pre post force modules =
aux modules

let set_module_init_function name f =
init_functions := M.add name f !init_functions;
(* print_endline ("Added init_function for " ^ name); *)
(* print_endline ("get_init_on_load: " ^ string_of_bool (get_init_on_load ())); *)
init_functions := M.add name [f] !init_functions;
if get_init_on_load () then f ()

let add_module_init_function name f =
let update = function
| None (* no binding so far *) -> Some [f]
| Some old -> Some (f :: old)
in
init_functions := M.update name update !init_functions;
if get_init_on_load () then f ()

let init_module pre post force name =
let f =
try M.find name !init_functions
with Not_found as e -> raise (Dynlink_error ("named module " ^ name, e))
try
let l = List.rev @@ M.find name !init_functions in
fun () -> List.iter (fun f -> f ()) l
with Not_found ->
Lwt_log.ign_info_f ~section "No init function for named module %s." name;
fun () -> ()
in
try
if force
then (
pre ();
Lwt_log.ign_info_f ~section
"Initializing %s (will be initialized every time)" name;
try f (); post () with e -> post (); raise e)
else if not (isloaded name)
then (
pre ();
Lwt_log.ign_info_f ~section "Initializing module %s " name;
(try f (); post () with e -> post (); raise e);
addloaded name)
else Lwt_log.ign_info_f ~section "Module %s already initialized." name
with e -> raise (Dynlink_error (name, e))
if force
then (
pre ();
Lwt_log.ign_info_f ~section
"Initializing %s (will be initialized every time)" name;
try f (); post () with e -> post (); raise e)
else if not (isloaded name)
then (
pre ();
Lwt_log.ign_info_f ~section "Initializing module %s " name;
(try f (); post () with e -> post (); raise e);
addloaded name)
else Lwt_log.ign_info_f ~section "Module %s already initialized." name

(************************************************************************)
(* Manipulating Findlib's search path *)
Expand Down
8 changes: 7 additions & 1 deletion src/baselib/ocsigen_loader.mli
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ val loadfiles : (unit -> unit) -> (unit -> unit) -> bool -> string list -> unit
but the last one, and [loadfile pre post force] for the last one
(if any). *)

val add_module_init_function : string -> (unit -> unit) -> unit
(** [add_module_init_function name f] adds function [f]
to the initialisation functions to be run
when [init_module name] is called. *)

val set_module_init_function : string -> (unit -> unit) -> unit
(** [set_module_init_function name f] registers the function [f], which will
be used to initialize the module when [init_module name] is called. *)
be used to initialize the module when [init_module name] is called.
Will replace the prvious value. *)

val init_module : (unit -> unit) -> (unit -> unit) -> bool -> string -> unit
(** [init_module pre post force name] runs the init function for the module
Expand Down
Loading
Loading