Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*.o
*.a
*.annot
*.cmt
*.cmti
*~
Makefile.config
src/baselib/ocsigen_config.ml
Expand Down
8 changes: 4 additions & 4 deletions Makefile.options
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

BYTEDBG :=
OPTDBG :=
THREAD :=
Expand All @@ -9,8 +8,8 @@ OPTDBG += -g
endif

ifeq "$(ANNOT)" "YES"
BYTEDBG += -dtypes
OPTDBG += -dtypes
BYTEDBG += -bin-annot
OPTDBG += -bin-annot
endif

ifeq "$(PROFILING)" "YES"
Expand All @@ -29,9 +28,10 @@ ifeq "$(PREEMPTIVE)" "YES"
LWT_PREEMPTIVE_PACKAGE:=lwt.preemptive
endif

BASE_PACKAGE := lwt ipaddr
BASE_PACKAGE := lwt ipaddr bytes

SERVER_PACKAGE := lwt.ssl \
bytes \
${LWT_PREEMPTIVE_PACKAGE} \
ipaddr \
netstring \
Expand Down
6 changes: 3 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ set_defaults () {
name="ocsigenserver"
enable_natdynlink=1
enable_debug=1
enable_annot=0
enable_annot=1
with_sqlite=1
with_camlzip=1
with_dbm=1
Expand Down Expand Up @@ -180,7 +180,7 @@ usage () {
usage: ./configure [ options ]

--enable-debug, --disable-debug Enable/disable debug output
--enable-annot, --disable-annot Enable/disable .annot files generation
--enable-annot, --disable-annot Enable/disable .cmt{,i} files generation
--enable-natdynlink, --disable-natdynlink Enable/disable nativecode dynamic linking

--with-sqlite, --without-sqlite Compile ocsipersist with SQLite for persistent storage
Expand Down Expand Up @@ -578,7 +578,7 @@ PREEMPTIVE:=$with_preempt
# Do you want debugging information (-g) ? YES/NO
DEBUG:=$enable_debug

# Do you want annot files (-dtypes) ? YES/NO
# Do you want annot files (-bin-annot) ? YES/NO
ANNOT:=$enable_annot

# Profiling (always put NO here - but if you want to debug ocsigen):
Expand Down
2 changes: 1 addition & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include ../src/Makefile.filelist
OCAMLDOC := ${OCAMLFIND} ocamldoc
ODOC_WIKI := odoc_wiki.cma

LIBS := -package lwt,tyxml,ssl,netstring-pcre,ipaddr \
LIBS := -package lwt,tyxml,ssl,netstring,netstring-pcre,ipaddr \
${addprefix -I ../src/, baselib http server extensions }

doc: api-html/index.html
Expand Down
73 changes: 35 additions & 38 deletions src/baselib/.depend
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
ocsigen_cache.cmi:
ocsigen_config.cmi: ocsigen_lib.cmi
ocsigen_getcommandline.cmi:
ocsigen_loader.cmi:
ocsigen_messages.cmi:
ocsigen_stream.cmi:
ocsigen_utils.cmi:
polytables.cmi:
dynlink_wrapper.cmo:
dynlink_wrapper.cmx:
dynlink_wrapper.natdynlink.cmo:
dynlink_wrapper.natdynlink.cmx:
dynlink_wrapper.nonatdynlink.cmo:
dynlink_wrapper.nonatdynlink.cmx:
ocsigen_cache.cmo: ocsigen_cache.cmi
ocsigen_cache.cmx: ocsigen_cache.cmi
ocsigen_commandline.cmo: ocsigen_getcommandline.cmi ocsigen_config.cmi
ocsigen_commandline.cmx: ocsigen_getcommandline.cmi ocsigen_config.cmx
ocsigen_config.cmo: ocsigen_lib.cmi ocsigen_config.cmi
ocsigen_config.cmx: ocsigen_lib.cmx ocsigen_config.cmi
ocsigen_lib.cmo: ocsigen_lib_base.cmi ocsigen_lib.cmi
ocsigen_lib.cmx: ocsigen_lib_base.cmx ocsigen_lib.cmi
ocsigen_lib_base.cmo: ocsigen_lib_base.cmi
ocsigen_lib_base.cmx: ocsigen_lib_base.cmi
ocsigen_loader.cmo: ocsigen_messages.cmi ocsigen_lib.cmi ocsigen_config.cmi \
dynlink_wrapper.cmo ocsigen_loader.cmi
ocsigen_loader.cmx: ocsigen_messages.cmx ocsigen_lib.cmx ocsigen_config.cmx \
dynlink_wrapper.cmx ocsigen_loader.cmi
ocsigen_messages.cmo: ocsigen_config.cmi ocsigen_messages.cmi
ocsigen_messages.cmx: ocsigen_config.cmx ocsigen_messages.cmi
ocsigen_stream.cmo: ocsigen_lib.cmi ocsigen_config.cmi ocsigen_stream.cmi
ocsigen_stream.cmx: ocsigen_lib.cmx ocsigen_config.cmx ocsigen_stream.cmi
ocsigen_utils.cmo: ocsigen_utils.cmi
ocsigen_utils.cmx: ocsigen_utils.cmi
polytables.cmo: polytables.cmi
polytables.cmx: polytables.cmi
ocsigen_lib_base.cmi:
ocsigen_lib.cmi: ocsigen_lib_base.cmi
ocsigen_loader.cmi :
ocsigen_cache.cmi :
ocsigen_stream.cmi :
ocsigen_config.cmi : ocsigen_lib.cmi
ocsigen_messages.cmi :
ocsigen_getcommandline.cmi :
polytables.cmi :
dynlink_wrapper.cmo :
dynlink_wrapper.cmx :
dynlink_wrapper.natdynlink.cmo :
dynlink_wrapper.natdynlink.cmx :
dynlink_wrapper.nonatdynlink.cmo :
dynlink_wrapper.nonatdynlink.cmx :
ocsigen_cache.cmo : ocsigen_cache.cmi
ocsigen_cache.cmx : ocsigen_cache.cmi
ocsigen_commandline.cmo : ocsigen_getcommandline.cmi ocsigen_config.cmi
ocsigen_commandline.cmx : ocsigen_getcommandline.cmi ocsigen_config.cmx
ocsigen_config.cmo : ocsigen_lib.cmi ocsigen_config.cmi
ocsigen_config.cmx : ocsigen_lib.cmx ocsigen_config.cmi
ocsigen_lib_base.cmo : ocsigen_lib_base.cmi
ocsigen_lib_base.cmx : ocsigen_lib_base.cmi
ocsigen_lib.cmo : ocsigen_lib_base.cmi ocsigen_lib.cmi
ocsigen_lib.cmx : ocsigen_lib_base.cmx ocsigen_lib.cmi
ocsigen_loader.cmo : ocsigen_lib.cmi ocsigen_config.cmi dynlink_wrapper.cmo \
ocsigen_loader.cmi
ocsigen_loader.cmx : ocsigen_lib.cmx ocsigen_config.cmx dynlink_wrapper.cmx \
ocsigen_loader.cmi
ocsigen_messages.cmo : ocsigen_config.cmi ocsigen_messages.cmi
ocsigen_messages.cmx : ocsigen_config.cmx ocsigen_messages.cmi
ocsigen_stream.cmo : ocsigen_lib.cmi ocsigen_config.cmi ocsigen_stream.cmi
ocsigen_stream.cmx : ocsigen_lib.cmx ocsigen_config.cmx ocsigen_stream.cmi
polytables.cmo : polytables.cmi
polytables.cmx : polytables.cmi
ocsigen_lib_base.cmi :
ocsigen_lib.cmi : ocsigen_lib_base.cmi
7 changes: 4 additions & 3 deletions src/baselib/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include ../../Makefile.config

PACKAGE := \
bytes \
lwt.unix \
netstring \
netstring-pcre \
Expand Down Expand Up @@ -144,10 +145,10 @@ ${INTF_NOP4:.mli=.cmi}: \
## Clean up

clean:
-rm -f *.cm[ioax] *.cmxa *.cmxs *.o *.a *.annot
-rm -f *.cm* *.o *.a *.annot
-rm -f ${PREDEP}
-cd commandline; rm -f *.cm[iox]* *.annot *.o
-cd nocommandline; rm -f *.cm[iox]* *.annot *.o
-cd commandline; rm -f *.cm* *.annot *.o
-cd nocommandline; rm -f *.cm* *.annot *.o

distclean: clean
-rm -f *~ \#* .\#*
Expand Down
6 changes: 3 additions & 3 deletions src/baselib/ocsigen_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ module Url = struct

let to_hex2 k =
(* Converts k to a 2-digit hex string *)
let s = String.create 2 in
s.[0] <- hex_digits.( (k lsr 4) land 15 );
s.[1] <- hex_digits.( k land 15 );
let s = Bytes.create 2 in
Bytes.set s 0 hex_digits.( (k lsr 4) land 15 );
Bytes.set s 1 hex_digits.( k land 15 );
s

let url_encoding_re =
Expand Down
12 changes: 12 additions & 0 deletions src/baselib/ocsigen_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ module Url : sig
val decode : ?plus:bool -> string -> string
val make_encoded_parameters : (string * string) list -> string
val string_of_url_path : encode:bool -> path -> uri

(** [parse url] returns a tuple containing information about [url]
{ul
{- If url contains scheme 'https'}
{- host of url (ex: http://www.ocsigen.org/ -> www.ocsigen.org)}
{- port of url}
{- path as [string] without first '/'}
{- path as [string list]}
{- GET query of url}
{- lazy value to decode GET query }
}
*)
val parse : t ->
bool option * string option * int option *
string (** the path, as a string, without the first / *) *
Expand Down
19 changes: 17 additions & 2 deletions src/baselib/ocsigen_lib_base.mli
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ('a, 'b) leftright = Left of 'a | Right of 'b

val advert: string

(** Module Option to compute type ['a option] *)
module Option : sig
type 'a t = 'a option
val map : ('a -> 'b) -> 'a t -> 'b t
Expand All @@ -71,6 +72,7 @@ module Option : sig
end
end

(** Improvement of module List *)
module List : sig
include module type of List

Expand Down Expand Up @@ -116,6 +118,7 @@ module Int : sig
module Table : Map.S with type key = int
end

(** Improvement of module String *)
module String_base : sig

include module type of String
Expand All @@ -124,7 +127,7 @@ module String_base : sig
removing spaces at the beginning and at the end *)
val remove_spaces : string -> int -> int -> string

(* Cuts a string to the next separator *)
(** Cuts a string to the next separator *)
val basic_sep : char -> string -> string * string

(** Cuts a string to the next separator, removing spaces.
Expand All @@ -139,7 +142,7 @@ module String_base : sig
val may_append : string -> sep:string -> string -> string (* WAS add_to_string *)
val may_concat : string -> sep:string -> string -> string (* WAS concat_strings *)

(* [first_diff s1 s2 n last] returns the index of the first difference
(** [first_diff s1 s2 n last] returns the index of the first difference
between s1 and s2, starting from n and ending at last.
returns (last + 1) if no difference is found. *)
val first_diff : string -> string -> int -> int -> int
Expand All @@ -155,21 +158,33 @@ module Url_base : sig
type t = string
type uri = string

(** [make_absolute_url https host port path] generates a new absolute url *)
val make_absolute_url :
https:bool -> host:string -> port:int -> uri -> t

type path = string list

(** [remove_dotdot path] cleans the path of [..] *)
val remove_dotdot : path -> path

(** [remove_end_slash str] removes last [/] *)
val remove_end_slash : string -> string

(** [remove_internal_slash path] cleans the path of empty string *)
val remove_internal_slash : path -> path

val change_empty_list : path -> path
val add_end_slash_if_missing : path -> path
val remove_slash_at_end : path -> path
val remove_slash_at_beginning : path -> path

(* val recursively_remove_slash_at_beginning : path -> path *)

(** [is_prefix_skip_end_slash path1 path2] returns [true] if [path1] is the same
as [path2] before a first slash *)
val is_prefix_skip_end_slash : string list -> string list -> bool

(** [split_fragment str] splits [str] at first '#' *)
val split_fragment : string -> string * string option

end
Expand Down
30 changes: 25 additions & 5 deletions src/baselib/ocsigen_stream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ type 'a t =
let empty follow =
match follow with
None -> Lwt.return (Finished None)
| Some st -> Lwt.return (Finished (Some (Lazy.lazy_from_fun st)))
| Some st -> Lwt.return (Finished (Some (Lazy.from_fun st)))

let cont stri f =
Lwt.return (Cont (stri, Lazy.lazy_from_fun f))
Lwt.return (Cont (stri, Lazy.from_fun f))

let make ?finalize:(g = fun _ -> Lwt.return ()) f =
{ stream = Lazy.lazy_from_fun f; in_use = false; finalizer = g }
{ stream = Lazy.from_fun f; in_use = false; finalizer = g }

let next = Lazy.force

Expand Down Expand Up @@ -230,19 +230,39 @@ let of_file filename =
(Unix.openfile filename [Unix.O_RDONLY;Unix.O_NONBLOCK] 0o666)
in
let ch = Lwt_chan.in_channel_of_descr fd in
let buf = String.create 1024 in
let buf = Bytes.create 1024 in
let rec aux () =
Lwt_chan.input ch buf 0 1024 >>= fun n ->
if n = 0 then empty None else
(* Streams should be immutable, thus we always make a copy
of the buffer *)
cont (String.sub buf 0 n) aux
cont (Bytes.sub buf 0 n) aux
in make ~finalize:(fun _ -> Lwt_unix.close fd) aux

let of_string s =
make (fun () -> cont s (fun () -> empty None))

(** Convert a {!Lwt_stream.t} to an {!Ocsigen_stream.t}. *)
let of_lwt_stream stream =
let rec aux () =
Lwt_stream.get stream >>= function
| Some e -> cont e aux
| None -> empty None
in make aux

(** Convert an {!Ocsigen_stream.t} into a {!Lwt_stream.t}.
@param is_empty function to skip empty chunk.
*)
let to_lwt_stream o_stream =
let stream = ref (get o_stream) in
let rec wrap () =
next !stream >>= function
| Finished None -> o_stream.finalizer `Success >>= fun () -> Lwt.return None
| Finished (Some next) -> stream := next; wrap ()
| Cont (value, next) ->
stream := next;
Lwt.return (Some value)
in Lwt_stream.from wrap

module StringStream = struct

Expand Down
8 changes: 8 additions & 0 deletions src/baselib/ocsigen_stream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ val of_file : string -> string t
(** returns a stream containing a string. *)
val of_string : string -> string t

(** Convert a {!Lwt_stream.t} to an {!Ocsigen_stream.t}. *)
val of_lwt_stream : 'a Lwt_stream.t -> 'a t


(** Convert an {!Ocsigen_stream.t} into a {!Lwt_stream.t}.
@param is_empty function to skip empty chunk.
*)
val to_lwt_stream : 'a t -> 'a Lwt_stream.t

module StringStream : sig

Expand Down
2 changes: 1 addition & 1 deletion src/baselib/polytables.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
(**
Polymorphic tables (using Map)
Polymorphic tables (using Map)
@author Vincent Balat
@author Jérôme Vouillon
*)
Expand Down
Loading