Skip to content

Commit

Permalink
Merge pull request #229 from glondu/fix-obsolete-libraries
Browse files Browse the repository at this point in the history
Fix obsolete libraries
  • Loading branch information
balat authored Sep 20, 2023
2 parents 6da7c7f + 5ac6399 commit 809391c
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 66 deletions.
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,pcre,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,hmap

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

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ check_library lwt_react "See: http://ocsigen.org/lwt"
check_library lwt_ssl "See: http://ocsigen.org/lwt"
check_library lwt_log "See: http://ocsigen.org/lwt"

check_library pcre "See: http://ocaml.info/home/ocaml_sources.html"
check_library re "See: https://github.com/ocaml/ocaml-re/"
check_library cryptokit "See: http://pauillac.inria.fr/~xleroy/software.html#cryptokit"

check_library xml-light "See: https://github.com/ncannasse/xml-light"
Expand Down
4 changes: 2 additions & 2 deletions ocsigenserver.opam
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ depends: [
"lwt_ssl"
"lwt_react"
"lwt_log"
"pcre"
"re" {>= "1.11.0"}
"cryptokit"
"ipaddr" {>= "2.1"}
"cohttp-lwt-unix" {< "5.0.0"}
"cohttp-lwt-unix" {>= "5.0.0"}
"conduit-lwt-unix" {>= "2.0.0"}
"hmap"
"xml-light"
Expand Down
2 changes: 1 addition & 1 deletion src/baselib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ocsigen_loader
ocsigen_stream)
(libraries
str findlib lwt_log lwt.unix cryptokit pcre ocsigen_lib_base
str findlib lwt_log lwt.unix cryptokit re ocsigen_lib_base
(select dynlink_wrapper.ml from
(dynlink -> dynlink_wrapper.natdynlink.ml)
(_ -> dynlink_wrapper.nonatdynlink.ml))))
54 changes: 23 additions & 31 deletions src/baselib/ocsigen_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,47 +100,44 @@ let make_cryptographic_safe_string =
*)

module Netstring_pcre = struct
module Pcre = Re.Pcre

let regexp s = Pcre.regexp ~flags:[`MULTILINE] s
let templ_re = Pcre.regexp "(?:\\\\\\d)|[\\$\\\\]"

let tr_templ s =
(* Convert \n to $n etc. *)
(* Unfortunately we cannot just replace \ by $. *)
let tr_templ s g =
(* Instantiate backreferences in s based on match g *)
let b = Buffer.create (String.length s) in
let rec tr l =
match l with
| Pcre.Delim "$" :: l' -> "$$" :: tr l'
| Pcre.Delim "\\" :: Pcre.Delim "$" :: l' -> "$$" :: tr l'
| Pcre.Delim "\\" :: Pcre.Delim s :: l' -> s :: tr l'
| Pcre.Delim "\\" :: Pcre.Text s :: l' -> s :: tr l'
| Pcre.Delim "$" :: l' -> Buffer.add_char b '$'; tr l'
| Pcre.Delim "\\" :: Pcre.Delim s :: l' -> Buffer.add_string b s; tr l'
| Pcre.Delim "\\" :: Pcre.Text s :: l' -> Buffer.add_string b s; tr l'
| [Pcre.Delim "\\"] -> failwith "trailing backslash"
| Pcre.Delim d :: l' ->
assert (d.[0] = '\\');
let n = Char.code d.[1] - Char.code '0' in
if n = 0
then "$&" :: tr l'
else ("$" ^ string_of_int n ^ "$!") :: tr l'
| Pcre.Text t :: l' -> t :: tr l'
Buffer.add_string b (Re.Group.get g n);
tr l'
| Pcre.Text t :: l' -> Buffer.add_string b t; tr l'
| Pcre.Group (_, _) :: _ -> assert false
| Pcre.NoGroup :: _ -> assert false
| [] -> []
| [] -> ()
in
let l = Pcre.full_split ~rex:templ_re ~max:(-1) s in
String.concat "" (tr l)
tr l; Buffer.contents b

let matched_group result n _ =
if n < 0 || n >= Pcre.num_of_subs result then raise Not_found;
if n < 0 || n >= Re.Group.nb_groups result then raise Not_found;
ignore (Pcre.get_substring_ofs result n);
Pcre.get_substring result n

let matched_string result _ =
ignore (Pcre.get_substring_ofs result 0);
Pcre.get_substring result 0

let global_replace pat templ s =
Pcre.replace ~rex:pat ~itempl:(Pcre.subst (tr_templ templ)) s

let global_substitute pat subst s =
Pcre.substitute_substrings ~rex:pat ~subst:(fun r -> subst r s) s
let global_replace pat templ s = Re.replace pat ~f:(tr_templ templ) s
let global_substitute pat subst s = Re.replace pat ~f:(fun r -> subst r s) s

let search_forward pat s pos =
let result = Pcre.exec ~rex:pat ~pos s in
Expand All @@ -149,14 +146,6 @@ module Netstring_pcre = struct
let string_after s n = String.sub s n (String.length s - n)

let bounded_split expr text num =
let start =
try
let start_substrs = Pcre.exec ~rex:expr ~flags:[`ANCHORED] text in
(* or Not_found *)
let _, match_end = Pcre.get_substring_ofs start_substrs 0 in
match_end
with Not_found -> 0
in
let rec split start n =
if start >= String.length text
then []
Expand All @@ -167,21 +156,24 @@ module Netstring_pcre = struct
let next_substrs = Pcre.exec ~rex:expr ~pos:start text in
(* or Not_found *)
let pos, match_end = Pcre.get_substring_ofs next_substrs 0 in
String.sub text start (pos - start) :: split match_end (n - 1)
if pos = 0
then split match_end n (* a leading match is ignored *)
else String.sub text start (pos - start) :: split match_end (n - 1)
with Not_found -> [string_after text start]
in
split start num
split 0 num

let split sep s = bounded_split sep s 0

let string_match pat s pos =
try
let result = Pcre.exec ~rex:pat ~flags:[`ANCHORED] ~pos s in
Some result
let result = Pcre.exec ~rex:pat ~pos s in
if Re.Group.start result 0 = pos then Some result else None
with Not_found -> None
end

module Url = struct
module Pcre = Re.Pcre
include Url_base

(* Taken from Neturl version 1.1.2 *)
Expand Down
10 changes: 6 additions & 4 deletions src/baselib/ocsigen_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ end
(* This exists to facilitate transition away from Ocamlnet. Do not use
for new code! *)
module Netstring_pcre : sig
open Re

val regexp : string -> Pcre.regexp
val matched_group : Pcre.substrings -> int -> string -> string
val matched_string : Pcre.substrings -> string -> string
val matched_group : Pcre.groups -> int -> string -> string
val matched_string : Pcre.groups -> string -> string
val global_replace : Pcre.regexp -> string -> string -> string
val search_forward : Pcre.regexp -> string -> int -> int * Pcre.substrings
val search_forward : Pcre.regexp -> string -> int -> int * Pcre.groups
val split : Pcre.regexp -> string -> string list
val string_match : Pcre.regexp -> string -> int -> Pcre.substrings option
val string_match : Pcre.regexp -> string -> int -> Pcre.groups option
end

module Date : sig
Expand Down
2 changes: 1 addition & 1 deletion src/baselib/ocsigen_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ let add_ocamlpath p =
(* Using Findlib to locate files *)

let findfiles =
let cmx = Pcre.regexp ~flags:[`MULTILINE; `CASELESS] "\\.cmx($| |a)" in
let cmx = Re.Pcre.regexp ~flags:[`MULTILINE; `CASELESS] "\\.cmx($| |a)" in
fun package ->
try
let preds =
Expand Down
2 changes: 1 addition & 1 deletion src/baselib/ocsigen_stream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ let substream delim s =
if ldelim = 0
then Lwt.fail (Stream_error "Empty delimiter")
else
let rdelim = Pcre.(regexp (quote delim)) in
let rdelim = Re.Pcre.(regexp (quote delim)) in
let rec aux = function
| Finished _ -> Lwt.fail Stream_too_small
| Cont (s, f) as stre -> (
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/outputfilter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(* This module enables rewritting the server output *)

type header_filter =
[ `Rewrite of Ocsigen_header.Name.t * Pcre.regexp * string
[ `Rewrite of Ocsigen_header.Name.t * Re.Pcre.regexp * string
| `Add of Ocsigen_header.Name.t * string * bool option ]

let gen filter = function
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/outputfilter.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val mode
: [ `Rewrite of Ocsigen_header.Name.t * Pcre.regexp * string
: [ `Rewrite of Ocsigen_header.Name.t * Re.Pcre.regexp * string
| `Add of Ocsigen_header.Name.t * string * bool option
| `Code of Cohttp.Code.status ]
Ocsigen_server.Site.Config.key
Expand Down
2 changes: 2 additions & 0 deletions src/extensions/redirectmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

(* Define page redirections in the configuration file *)

module Pcre = Re.Pcre

let section = Lwt_log.Section.make "ocsigen:ext:redirectmod"

(* The table of redirections for each virtual server *)
Expand Down
1 change: 1 addition & 0 deletions src/extensions/revproxy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
The reverse proxy is still experimental. *)

open Lwt.Infix
module Pcre = Re.Pcre

let section = Lwt_log.Section.make "ocsigen:ext:revproxy"

Expand Down
2 changes: 2 additions & 0 deletions src/extensions/rewritemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

(* Rewrite URLs in the configuration file *)

module Pcre = Re.Pcre

(* IMPORTANT WARNING
It is really basic for now:
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/staticmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*)

open Lwt.Infix
module Pcre = Re.Pcre

let name = "staticmod"
let section = Lwt_log.Section.make "ocsigen:ext:staticmod"
Expand Down Expand Up @@ -233,15 +234,15 @@ let parse_config userconf _ : Ocsigen_extensions.parse_config_aux =
; Configuration.attribute ~name:"regexp" (fun s ->
let s =
try Ocsigen_lib.Netstring_pcre.regexp ("^" ^ s ^ "$")
with Pcre.Error (Pcre.BadPattern _) ->
with Re.Pcre.Parse_error | Re.Pcre.Not_supported ->
badconfig
"Bad regexp \"%s\" in <static regexp=\"...\" />" s
in
opt := {!opt with opt_regexp = Some s})
; Configuration.attribute ~name:"code" (fun s ->
let c =
try Ocsigen_lib.Netstring_pcre.regexp ("^" ^ s ^ "$")
with Pcre.Error (Pcre.BadPattern _) ->
with Re.Pcre.Parse_error | Re.Pcre.Not_supported ->
badconfig "Bad regexp \"%s\" in <static code=\"...\" />"
s
in
Expand Down
2 changes: 1 addition & 1 deletion src/http/ocsigen_charset_mime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let section = Lwt_log.Section.make "ocsigen:mimetype"
type 'a assoc_item =
| Extension of extension * 'a
| File of filename * 'a
| Regexp of Pcre.regexp * 'a
| Regexp of Re.Pcre.regexp * 'a
| Map of 'a MapString.t

type 'a assoc = {assoc_list : 'a assoc_item list; assoc_default : 'a}
Expand Down
4 changes: 2 additions & 2 deletions src/http/ocsigen_charset_mime.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ val update_charset_file : charset_assoc -> filename -> charset -> charset_assoc

val update_charset_regexp
: charset_assoc
-> Pcre.regexp
-> Re.Pcre.regexp
-> charset
-> charset_assoc

Expand All @@ -81,4 +81,4 @@ val default_mime : mime_assoc -> mime_type
val set_default_mime : mime_assoc -> mime_type -> mime_assoc
val update_mime_ext : mime_assoc -> extension -> mime_type -> mime_assoc
val update_mime_file : mime_assoc -> filename -> mime_type -> mime_assoc
val update_mime_regexp : mime_assoc -> Pcre.regexp -> mime_type -> mime_assoc
val update_mime_regexp : mime_assoc -> Re.Pcre.regexp -> mime_type -> mime_assoc
13 changes: 1 addition & 12 deletions src/server/ocsigen_cohttp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,12 @@ exception
@param request Cohttp request *)

let _print_request fmt request =
let print_list print_data out_ch lst =
let rec aux = function
| [] -> ()
| [x] -> print_data out_ch x
| x :: r -> print_data out_ch x; aux r
in
aux lst
in
Format.fprintf fmt "%s [%s/%s]:\n"
(Uri.to_string (Cohttp.Request.uri request))
Cohttp.(Code.string_of_version (Request.version request))
Cohttp.(Code.string_of_method (Request.meth request));
Cohttp.Header.iter
(fun key values ->
print_list
(fun fmt value -> Format.fprintf fmt "\t%s = %s\n" key value)
fmt values)
(fun key value -> Format.fprintf fmt "\t%s = %s\n" key value)
(Cohttp.Request.headers request)

let connections = Hashtbl.create 256
Expand Down
1 change: 1 addition & 0 deletions src/server/ocsigen_extensions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
let section = Lwt_log.Section.make "ocsigen:ext"

open Lwt.Infix
module Pcre = Re.Pcre
module Url = Ocsigen_lib.Url
include Ocsigen_command

Expand Down
8 changes: 4 additions & 4 deletions src/server/ocsigen_extensions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ val badconfig : ('a, unit, string, 'b) format4 -> 'a

(*****************************************************************************)

type virtual_hosts = (string * Pcre.regexp * int option) list
type virtual_hosts = (string * Re.Pcre.regexp * int option) list
(** Type of the result of parsing the field [hostfiler] in the configuration
file. Inside the list, the first argument is the host itself
(which is a glob-like pattern that can contains [*]), a regexp
Expand Down Expand Up @@ -76,7 +76,7 @@ val serve_everything : do_not_serve

exception IncorrectRegexpes of do_not_serve

val do_not_serve_to_regexp : do_not_serve -> Pcre.regexp
val do_not_serve_to_regexp : do_not_serve -> Re.Pcre.regexp
(** Compile a do_not_serve structure into a regexp. Raises
[IncorrectRegexpes] if the compilation fails. The result is
memoized for subsequent calls with the same argument *)
Expand Down Expand Up @@ -380,14 +380,14 @@ type ud_string

val parse_user_dir : string -> ud_string

val replace_user_dir : Pcre.regexp -> ud_string -> string -> string
val replace_user_dir : Re.Pcre.regexp -> ud_string -> string -> string
(** raises [Not_found] is the directory does not exist *)

exception Not_concerned
(** {3 Regular expressions for redirections} *)

val find_redirection
: Pcre.regexp
: Re.Pcre.regexp
-> bool
-> string
-> Ocsigen_request.t
Expand Down
1 change: 1 addition & 0 deletions src/server/ocsigen_multipart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

open Lwt.Infix
module S = Ocsigen_lib.Netstring_pcre
module Pcre = Re.Pcre

let section = Lwt_log.Section.make "ocsigen:server:multipart"

Expand Down
2 changes: 1 addition & 1 deletion src/server/ocsigen_parseconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ let parse_host_field =
in
let split_host = function
| Str.Delim _ -> ".*"
| Str.Text t -> Pcre.quote t
| Str.Text t -> Re.Pcre.quote t
in
( host
, Netstring_pcre.regexp
Expand Down

0 comments on commit 809391c

Please sign in to comment.