467
467
with Dynlink.Error(e) ->
468
468
log_error(Dynlink.error_message e)
470
let skip_findlib = [ "unix"; "dynlink"; "findlib" ]
471
let predicates = ref [ "byte" ]
473
let init_findlib_var = ref false
476
if not !init_findlib_var then (
478
init_findlib_var := true
481
let split_in_words s =
482
(* Copy of Fl_split.in_words.
483
splits s in words separated by commas and/or whitespace *)
484
let l = String.length s in
488
(' '|'\t'|'\n'|'\r'|',') ->
489
if i<j then (String.sub s i (j-i)) :: (split (j+1) (j+1))
490
else split (j+1) (j+1)
494
if i<j then [ String.sub s i (j-i) ] else []
498
let cmd_require pkg =
499
(* Findlib-supported package loading. Also see topfind.ml in findlib *)
503
Findlib.package_deep_ancestors !predicates [pkg] in
506
if not (List.mem pkg !loaded) then begin
507
(* Determine the package directory: *)
508
let d = Findlib.package_directory pkg in
509
if not (List.mem pkg skip_findlib) then begin
510
(* Determine the 'archive' property: *)
512
try Findlib.package_property !predicates pkg "archive"
516
(* Split the 'archive' property and load the files: *)
517
let archives = split_in_words archive in
520
let arch' = Findlib.resolve_path ~base:d arch in
522
Some(String.capitalize(Filename.chop_extension
523
(Filename.basename arch')));
524
try Dynlink.loadfile arch';
525
with Dynlink.Error(e) ->
526
log_error(Dynlink.error_message e)
530
(* The package is loaded: *)
531
loaded := pkg :: !loaded
536
| Findlib.No_such_package(name,_) ->
537
log_error ("No such ocaml package: " ^ name)
538
| Findlib.Package_loop name ->
539
log_error ("Ocaml package loop: " ^ name)
541
log_error ("Failure: " ^ msg)
545
let have_mt_support() =
546
Findlib.package_property [] "threads" "type_of_threads" = "posix" in
547
if not(List.mem "threads" !loaded) then (
548
(* This works only for POSIX threads. *)
549
if have_mt_support() then (
550
predicates := ["mt"; "mt_posix"] @ !predicates;
551
cmd_require "threads"
554
log_error "NetcgiThread: No support for threads"
558
let cmd_predicates s =
560
let preds = split_in_words s in
561
predicates := preds @ !predicates
470
563
let cmd_translate_handler sconfig name =
471
564
{ sconfig with translate_handler = Some (Hashtbl.find reg_table name) }
501
594
let cb = Callback.register in
502
595
cb "netcgi2_apache_cmd_load" cmd_load;
596
cb "netcgi2_apache_cmd_require" cmd_require;
597
cb "netcgi2_apache_cmd_thread" cmd_thread;
598
cb "netcgi2_apache_cmd_predicates" cmd_predicates;
503
599
cb "netcgi2_apache_cmd_translate_handler" cmd_translate_handler;
504
600
cb "netcgi2_apache_cmd_check_user_id_handler" cmd_check_user_id_handler;
505
601
cb "netcgi2_apache_cmd_auth_checker_handler" cmd_auth_checker_handler;