Skip to content

Commit 809391c

Browse files
authored
Merge pull request #229 from glondu/fix-obsolete-libraries
Fix obsolete libraries
2 parents 6da7c7f + 5ac6399 commit 809391c

21 files changed

+57
-66
lines changed

Makefile.options

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ INCS= -I ${BLD}/server/.ocsigenserver.objs/byte \
2323
## ${SERVER_PACKAGE} is not only used to build the 'ocsigenserver' executable
2424
## but also to generate src/baselib/ocsigen_config_static.ml
2525

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

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

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ check_library lwt_react "See: http://ocsigen.org/lwt"
401401
check_library lwt_ssl "See: http://ocsigen.org/lwt"
402402
check_library lwt_log "See: http://ocsigen.org/lwt"
403403

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

407407
check_library xml-light "See: https://github.com/ncannasse/xml-light"

ocsigenserver.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ depends: [
5454
"lwt_ssl"
5555
"lwt_react"
5656
"lwt_log"
57-
"pcre"
57+
"re" {>= "1.11.0"}
5858
"cryptokit"
5959
"ipaddr" {>= "2.1"}
60-
"cohttp-lwt-unix" {< "5.0.0"}
60+
"cohttp-lwt-unix" {>= "5.0.0"}
6161
"conduit-lwt-unix" {>= "2.0.0"}
6262
"hmap"
6363
"xml-light"

src/baselib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
ocsigen_loader
1919
ocsigen_stream)
2020
(libraries
21-
str findlib lwt_log lwt.unix cryptokit pcre ocsigen_lib_base
21+
str findlib lwt_log lwt.unix cryptokit re ocsigen_lib_base
2222
(select dynlink_wrapper.ml from
2323
(dynlink -> dynlink_wrapper.natdynlink.ml)
2424
(_ -> dynlink_wrapper.nonatdynlink.ml))))

src/baselib/ocsigen_lib.ml

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -100,47 +100,44 @@ let make_cryptographic_safe_string =
100100
*)
101101

102102
module Netstring_pcre = struct
103+
module Pcre = Re.Pcre
104+
103105
let regexp s = Pcre.regexp ~flags:[`MULTILINE] s
104106
let templ_re = Pcre.regexp "(?:\\\\\\d)|[\\$\\\\]"
105107

106-
let tr_templ s =
107-
(* Convert \n to $n etc. *)
108-
(* Unfortunately we cannot just replace \ by $. *)
108+
let tr_templ s g =
109+
(* Instantiate backreferences in s based on match g *)
110+
let b = Buffer.create (String.length s) in
109111
let rec tr l =
110112
match l with
111-
| Pcre.Delim "$" :: l' -> "$$" :: tr l'
112-
| Pcre.Delim "\\" :: Pcre.Delim "$" :: l' -> "$$" :: tr l'
113-
| Pcre.Delim "\\" :: Pcre.Delim s :: l' -> s :: tr l'
114-
| Pcre.Delim "\\" :: Pcre.Text s :: l' -> s :: tr l'
113+
| Pcre.Delim "$" :: l' -> Buffer.add_char b '$'; tr l'
114+
| Pcre.Delim "\\" :: Pcre.Delim s :: l' -> Buffer.add_string b s; tr l'
115+
| Pcre.Delim "\\" :: Pcre.Text s :: l' -> Buffer.add_string b s; tr l'
115116
| [Pcre.Delim "\\"] -> failwith "trailing backslash"
116117
| Pcre.Delim d :: l' ->
117118
assert (d.[0] = '\\');
118119
let n = Char.code d.[1] - Char.code '0' in
119-
if n = 0
120-
then "$&" :: tr l'
121-
else ("$" ^ string_of_int n ^ "$!") :: tr l'
122-
| Pcre.Text t :: l' -> t :: tr l'
120+
Buffer.add_string b (Re.Group.get g n);
121+
tr l'
122+
| Pcre.Text t :: l' -> Buffer.add_string b t; tr l'
123123
| Pcre.Group (_, _) :: _ -> assert false
124124
| Pcre.NoGroup :: _ -> assert false
125-
| [] -> []
125+
| [] -> ()
126126
in
127127
let l = Pcre.full_split ~rex:templ_re ~max:(-1) s in
128-
String.concat "" (tr l)
128+
tr l; Buffer.contents b
129129

130130
let matched_group result n _ =
131-
if n < 0 || n >= Pcre.num_of_subs result then raise Not_found;
131+
if n < 0 || n >= Re.Group.nb_groups result then raise Not_found;
132132
ignore (Pcre.get_substring_ofs result n);
133133
Pcre.get_substring result n
134134

135135
let matched_string result _ =
136136
ignore (Pcre.get_substring_ofs result 0);
137137
Pcre.get_substring result 0
138138

139-
let global_replace pat templ s =
140-
Pcre.replace ~rex:pat ~itempl:(Pcre.subst (tr_templ templ)) s
141-
142-
let global_substitute pat subst s =
143-
Pcre.substitute_substrings ~rex:pat ~subst:(fun r -> subst r s) s
139+
let global_replace pat templ s = Re.replace pat ~f:(tr_templ templ) s
140+
let global_substitute pat subst s = Re.replace pat ~f:(fun r -> subst r s) s
144141

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

151148
let bounded_split expr text num =
152-
let start =
153-
try
154-
let start_substrs = Pcre.exec ~rex:expr ~flags:[`ANCHORED] text in
155-
(* or Not_found *)
156-
let _, match_end = Pcre.get_substring_ofs start_substrs 0 in
157-
match_end
158-
with Not_found -> 0
159-
in
160149
let rec split start n =
161150
if start >= String.length text
162151
then []
@@ -167,21 +156,24 @@ module Netstring_pcre = struct
167156
let next_substrs = Pcre.exec ~rex:expr ~pos:start text in
168157
(* or Not_found *)
169158
let pos, match_end = Pcre.get_substring_ofs next_substrs 0 in
170-
String.sub text start (pos - start) :: split match_end (n - 1)
159+
if pos = 0
160+
then split match_end n (* a leading match is ignored *)
161+
else String.sub text start (pos - start) :: split match_end (n - 1)
171162
with Not_found -> [string_after text start]
172163
in
173-
split start num
164+
split 0 num
174165

175166
let split sep s = bounded_split sep s 0
176167

177168
let string_match pat s pos =
178169
try
179-
let result = Pcre.exec ~rex:pat ~flags:[`ANCHORED] ~pos s in
180-
Some result
170+
let result = Pcre.exec ~rex:pat ~pos s in
171+
if Re.Group.start result 0 = pos then Some result else None
181172
with Not_found -> None
182173
end
183174

184175
module Url = struct
176+
module Pcre = Re.Pcre
185177
include Url_base
186178

187179
(* Taken from Neturl version 1.1.2 *)

src/baselib/ocsigen_lib.mli

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ end
9595
(* This exists to facilitate transition away from Ocamlnet. Do not use
9696
for new code! *)
9797
module Netstring_pcre : sig
98+
open Re
99+
98100
val regexp : string -> Pcre.regexp
99-
val matched_group : Pcre.substrings -> int -> string -> string
100-
val matched_string : Pcre.substrings -> string -> string
101+
val matched_group : Pcre.groups -> int -> string -> string
102+
val matched_string : Pcre.groups -> string -> string
101103
val global_replace : Pcre.regexp -> string -> string -> string
102-
val search_forward : Pcre.regexp -> string -> int -> int * Pcre.substrings
104+
val search_forward : Pcre.regexp -> string -> int -> int * Pcre.groups
103105
val split : Pcre.regexp -> string -> string list
104-
val string_match : Pcre.regexp -> string -> int -> Pcre.substrings option
106+
val string_match : Pcre.regexp -> string -> int -> Pcre.groups option
105107
end
106108

107109
module Date : sig

src/baselib/ocsigen_loader.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let add_ocamlpath p =
147147
(* Using Findlib to locate files *)
148148

149149
let findfiles =
150-
let cmx = Pcre.regexp ~flags:[`MULTILINE; `CASELESS] "\\.cmx($| |a)" in
150+
let cmx = Re.Pcre.regexp ~flags:[`MULTILINE; `CASELESS] "\\.cmx($| |a)" in
151151
fun package ->
152152
try
153153
let preds =

src/baselib/ocsigen_stream.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ let substream delim s =
180180
if ldelim = 0
181181
then Lwt.fail (Stream_error "Empty delimiter")
182182
else
183-
let rdelim = Pcre.(regexp (quote delim)) in
183+
let rdelim = Re.Pcre.(regexp (quote delim)) in
184184
let rec aux = function
185185
| Finished _ -> Lwt.fail Stream_too_small
186186
| Cont (s, f) as stre -> (

src/extensions/outputfilter.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(* This module enables rewritting the server output *)
2222

2323
type header_filter =
24-
[ `Rewrite of Ocsigen_header.Name.t * Pcre.regexp * string
24+
[ `Rewrite of Ocsigen_header.Name.t * Re.Pcre.regexp * string
2525
| `Add of Ocsigen_header.Name.t * string * bool option ]
2626

2727
let gen filter = function

src/extensions/outputfilter.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
val mode
2-
: [ `Rewrite of Ocsigen_header.Name.t * Pcre.regexp * string
2+
: [ `Rewrite of Ocsigen_header.Name.t * Re.Pcre.regexp * string
33
| `Add of Ocsigen_header.Name.t * string * bool option
44
| `Code of Cohttp.Code.status ]
55
Ocsigen_server.Site.Config.key

0 commit comments

Comments
 (0)