Skip to content

Commit

Permalink
Merge pull request #4 from ocsigen/static
Browse files Browse the repository at this point in the history
Configuration without config file
  • Loading branch information
balat authored Jun 11, 2024
2 parents cbf8728 + 65880fb commit 04246ee
Show file tree
Hide file tree
Showing 34 changed files with 704 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.19.0
version=0.26.2
break-cases = fit
break-collection-expressions = fit-or-vertical
break-fun-decl = wrap
Expand Down
20 changes: 20 additions & 0 deletions ocsipersist-dbm-config.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
opam-version: "2.0"
name: "ocsipersist-dbm-config"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Ocsigen Server configuration file extension for ocsipersist-dbm"
description: "Load this package from Ocsigen Server's configuration file if you want to use the DBM storage backend."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
dev-repo: "git+https://github.com/ocsigen/ocsipersist.git"
build: [ "dune" "build" "-p" name "-j" jobs ]

depends: [
"dune" {>= "2.9"}
"xml-light"
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-dbm" {>= "2.0.0" & < "2.1.0"}
]
10 changes: 4 additions & 6 deletions ocsipersist-dbm.opam
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
opam-version: "2.0"
name: "ocsipersist-dbm"
version: "1.1.0"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Persistent key/value storage (for Ocsigen) using DBM"
description: "This library provides a DBM backend for the unified key/value storage frontend as defined in the ocsipersist package. Ocsipersist is used pervasively in Eliom/Ocsigen to handle sessions and references. It can be used as an extension for ocsigenserver or as a library."
synopsis: "Persistent key/value storage for OCaml using DBM"
description: "This library provides a DBM backend for the unified key/value storage frontend as defined in the ocsipersist package."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
Expand All @@ -16,8 +16,6 @@ depends: [
"dune" {>= "2.9"}
"lwt" {>= "4.2.0"}
"lwt_log"
"xml-light"
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-lib" {>= "1.1.0" & < "1.2.0"}
"ocsipersist" {>= "2.0.0" & < "2.1.0"}
"dbm"
]
4 changes: 2 additions & 2 deletions ocsipersist-lib.opam
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
opam-version: "2.0"
name: "ocsipersist-lib"
version: "1.1.0"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Persistent key/value storage (for Ocsigen) - support library"
synopsis: "Persistent key/value storage for OCaml - support library"
description: "This library defines signatures and auxiliary tools for defining backends for the Ocsipersist frontent. Ocsipersist is used pervasively in Eliom/Ocsigen to handle sessions and references. It can be used as an extension for ocsigenserver or as a library. Implementations of the following backends currently exist: DBM, PostgreSQL, SQLite."

homepage: "https://github.com/ocsigen/ocsipersist"
Expand Down
20 changes: 20 additions & 0 deletions ocsipersist-pgsql-config.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
opam-version: "2.0"
name: "ocsipersist-pgsql-config"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Ocsigen Server configuration file extension for ocsipersist-pgsql"
description: "Load this package from Ocsigen Server's configuration file if you want to use the PostgreSQL storage backend."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
dev-repo: "git+https://github.com/ocsigen/ocsipersist.git"
build: [ "dune" "build" "-p" name "-j" jobs ]

depends: [
"dune" {>= "2.9"}
"xml-light"
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-pgsql" {>= "2.0.0" & < "2.1.0"}
]
10 changes: 4 additions & 6 deletions ocsipersist-pgsql.opam
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
opam-version: "2.0"
name: "ocsipersist-pgsql"
version: "1.1.0"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Persistent key/value storage (for Ocsigen) using PostgreSQL"
description: "This library provides a PostgreSQL backend for the unified key/value storage frontend as defined in the ocsipersist package. Ocsipersist is used pervasively in Eliom/Ocsigen to handle sessions and references. It can be used as an extension for ocsigenserver or as a library."
synopsis: "Persistent key/value storage for OCaml using PostgreSQL"
description: "This library provides a PostgreSQL backend for the unified key/value storage frontend as defined in the ocsipersist package."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
Expand All @@ -16,8 +16,6 @@ depends: [
"dune" {>= "2.9"}
"lwt" {>= "4.2.0"}
"lwt_log"
"xml-light"
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-lib" {>= "1.1.0" & < "1.2.0"}
"ocsipersist" {>= "2.0.0" & < "2.1.0"}
"pgocaml"
]
20 changes: 20 additions & 0 deletions ocsipersist-sqlite-config.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
opam-version: "2.0"
name: "ocsipersist-sqlite-config"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Ocsigen Server configuration file extension for ocsipersist-sqlite"
description: "Load this package from Ocsigen Server's configuration file if you want to use the SQLite storage backend."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
dev-repo: "git+https://github.com/ocsigen/ocsipersist.git"
build: [ "dune" "build" "-p" name "-j" jobs ]

depends: [
"dune" {>= "2.9"}
"xml-light"
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-sqlite" {>= "2.0.0" & < "2.1.0"}
]
10 changes: 4 additions & 6 deletions ocsipersist-sqlite.opam
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
opam-version: "2.0"
name: "ocsipersist-sqlite"
version: "1.1.0"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Persistent key/value storage (for Ocsigen) using SQLite"
description: "This library provides a SQLite backend for the unified key/value storage frontend as defined in the ocsipersist package. Ocsipersist is used pervasively in Eliom/Ocsigen to handle sessions and references. It can be used as an extension for ocsigenserver or as a library."
synopsis: "Persistent key/value storage for OCaml using SQLite"
description: "This library provides a SQLite backend for the unified key/value storage frontend as defined in the ocsipersist package."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
Expand All @@ -16,8 +16,6 @@ depends: [
"dune" {>= "2.9"}
"lwt" {>= "4.2.0"}
"lwt_log"
"xml-light"
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-lib" {>= "1.1.0" & < "1.2.0"}
"ocsipersist" {>= "2.0.0" & < "2.1.0"}
"sqlite3"
]
22 changes: 7 additions & 15 deletions ocsipersist.opam
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
opam-version: "2.0"
name: "ocsipersist"
version: "1.1.0"
version: "2.0.0"
authors: "The Ocsigen team <dev@ocsigen.org>"
maintainer: "Jan Rochel <jan@besport.com>"
license: "LGPL-2.1-only with OCaml-LGPL-linking-exception"
synopsis: "Persistent key/value storage (for Ocsigen) using multiple backends"
description: "This is an virtual library defining a unified frontend for a number of key/value storage implementations. Ocsipersist is used pervasively in Eliom/Ocsigen to handle sessions and references. It can be used as an extension for ocsigenserver or as a library. Implementations of the following backends currently exist: DBM, PostgreSQL, SQLite."
synopsis: "Persistent key-value storage for OCaml using multiple backends"
description: "This is an virtual library defining a unified frontend for a number of key-value storage implementations. Implementations of the following backends currently exist: DBM, PostgreSQL, SQLite."

homepage: "https://github.com/ocsigen/ocsipersist"
bug-reports: "https://github.com/ocsigen/ocsipersist/issues"
Expand All @@ -15,18 +15,10 @@ build: [ "dune" "build" "-p" name "-j" jobs ]
depends: [
"dune" {>= "2.9"}
"lwt" {>= "4.2.0"}
"ocsigenserver" {>= "3.0.0"}
"ocsipersist-lib" {>= "1.1.0" & < "1.2.0"}
"ocsipersist-lib" {>= "2.0.0" & < "3.0.0"}
]

depopts: [
"ocsipersist-dbm"
"ocsipersist-pgsql"
"ocsipersist-sqlite"
]

conflicts: [
"ocsipersist-dbm" {< "1.1.0" | >= "1.2.0"}
"ocsipersist-pgsql" {< "1.1.0" | >= "1.2.0"}
"ocsipersist-sqlite" {< "1.1.0" | >= "1.2.0"}
"ocsipersist-dbm" {< "2.0.0" | >= "2.1.0"}
"ocsipersist-pgsql" {< "2.0.0" | >= "2.1.0"}
"ocsipersist-sqlite" {< "2.0.0" | >= "2.1.0"}
]
36 changes: 30 additions & 6 deletions src/dbm/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,41 @@

(library
(name ocsipersist_dbm)
(public_name ocsipersist.dbm)
(public_name ocsipersist-dbm)
(implements ocsipersist)
(modules ocsipersist)
(modules
:standard
\
ocsipersist_config
ocsidbm
ocsidbmtypes
ocsipersist_settings)
(libraries
dbm
lwt_log
xml-light
ocsipersist_dbmtypes
ocsigenserver
ocsipersist_lib)
(optional))
ocsipersist_lib
ocsipersist_dbm_settings))

; Configuration functions (part of ocsipersist-dbm package):

(library
(name ocsipersist_dbm_settings)
(public_name ocsipersist-dbm.settings)
(wrapped false)
(modules ocsipersist_settings)
(libraries lwt lwt.unix))

; Configuration through Ocsigen Server config file:

(library
(name ocsipersist_dbm_config)
(public_name ocsipersist-dbm-config)
(modules ocsipersist_config)
(wrapped false)
(libraries xml-light ocsipersist_dbm ocsigenserver))

; DBM server:

(executable
(public_name ocsidbm)
Expand Down
29 changes: 17 additions & 12 deletions src/dbm/index.mld
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{0 ocsipersist-dbm}

For the API documentation see OPAM package [ocsipersist].

Here we document the configuration options of the ocsigenserver extension.
All sub-tags of the [extension] tag are optional.

{[
<extension findlib-package="ocsipersist.dbm">
<delayloading val="false"/>
<store dir="store"/>
<ocsidbm name="ocsidbm"/>
</extension>
]}
DBM backend for Ocsipersist.
For the API documentation see OPAM package {{:../ocsipersist/Ocsipersist/index.html}ocsipersist}.
This page describes how to configure the DBM backend.
The DBM backend uses a server process [ocsidbm].

{1 Using as a library}

If you are not using Ocsigen Server's configuration file,
add library [ocsipersist-dbm.settings] in your Dune file, and
use module {!Ocsipersist_settings}
to configure the storage file.

{1 Using with Ocsigen Server: ocsipersist-dbm-config}

If you want to configure Ocsipersist-dbm from Ocsigen Server's
configuration file, use package
{{:../ocsipersist-dbm-config/Ocsipersist_config/index.html}ocsipersist-dbm-config}.
55 changes: 26 additions & 29 deletions src/dbm/ocsidbm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ let errlog s =
(** Internal functions: storage in files using DBM *)

module Tableoftables = Map.Make (struct
type t = string
type t = string

let compare = compare
end)
let compare = compare
end)

let tableoftables = ref Tableoftables.empty

Expand Down Expand Up @@ -138,8 +138,8 @@ let db_length t =
let rec aux f n =
Lwt.catch
(fun () ->
ignore (f table);
Lwt.pause () >>= fun () -> aux Dbm.nextkey (n + 1))
ignore (f table);
Lwt.pause () >>= fun () -> aux Dbm.nextkey (n + 1))
(function Not_found -> Lwt.return n | e -> Lwt.fail e)
in
aux Dbm.firstkey 0
Expand Down Expand Up @@ -189,34 +189,32 @@ let execute outch =
function
| Get (t, k) ->
handle_errors (fun () ->
try send outch (Value (db_get t k))
with Not_found -> send outch Dbm_not_found)
try send outch (Value (db_get t k))
with Not_found -> send outch Dbm_not_found)
| Remove (t, k) -> handle_errors (fun () -> db_remove t k; send outch Ok)
| Replace (t, k, v) ->
handle_errors (fun () -> db_replace t k v; send outch Ok)
| Replace_if_exists (t, k, v) ->
handle_errors (fun () ->
try
ignore (db_get t k);
db_replace t k v;
send outch Ok
with Not_found -> send outch Dbm_not_found)
try
ignore (db_get t k);
db_replace t k v;
send outch Ok
with Not_found -> send outch Dbm_not_found)
| Firstkey t ->
handle_errors (fun () ->
try send outch (Key (db_firstkey t))
with Not_found -> send outch End)
try send outch (Key (db_firstkey t)) with Not_found -> send outch End)
| Nextkey t ->
handle_errors (fun () ->
try send outch (Key (db_nextkey t)) with Not_found -> send outch End)
try send outch (Key (db_nextkey t)) with Not_found -> send outch End)
| Length t ->
handle_errors (fun () ->
Lwt.catch
(fun () ->
db_length t >>= fun i ->
send outch (Value (Marshal.to_string i [])))
(function
| Not_found -> send outch Dbm_not_found
| e -> send outch (Error e)))
Lwt.catch
(fun () ->
db_length t >>= fun i ->
send outch (Value (Marshal.to_string i [])))
(function
| Not_found -> send outch Dbm_not_found | e -> send outch (Error e)))

let nb_clients = ref 0

Expand Down Expand Up @@ -246,13 +244,13 @@ let _ =
(let socket = Lwt_unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
Lwt.catch
(fun () ->
Lwt_unix.bind socket (Unix.ADDR_UNIX (directory ^ "/" ^ socketname)))
Lwt_unix.bind socket (Unix.ADDR_UNIX (directory ^ "/" ^ socketname)))
(fun _exn ->
errlog
("Please make sure that the directory " ^ directory
^ " exists, writable for ocsidbm, and no other ocsidbm process is running on the same directory. If not, remove the file "
^ directory ^ "/" ^ socketname);
the_end 1)
errlog
("Please make sure that the directory " ^ directory
^ " exists, writable for ocsidbm, and no other ocsidbm process is running on the same directory. If not, remove the file "
^ directory ^ "/" ^ socketname);
the_end 1)
>>= fun () ->
Lwt_unix.listen socket 20;
(* Done in ocsipersist.ml
Expand Down Expand Up @@ -316,5 +314,4 @@ let _ =
) >>=
f
in ignore (f ())
*)
Loading

0 comments on commit 04246ee

Please sign in to comment.