~ubuntu-branches/ubuntu/trusty/ocamlnet/trusty

« back to all changes in this revision

Viewing changes to src/netcgi2-apache/netcgi_apache_mod.ml.in

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-09-02 14:12:33 UTC
  • mfrom: (18.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110902141233-zbj0ygxb92u6gy4z
Tags: 3.4-1
* New upstream release
  - add a new NetcgiRequire directive to ease dependency management
    (Closes: #637147)
  - remove patches that were applied upstream:
    + Added-missing-shebang-lines-in-example-shell-scripts
    + Try-also-ocamlc-for-POSIX-threads

Show diffs side-by-side

added added

removed removed

Lines of Context:
467
467
    with Dynlink.Error(e) ->
468
468
      log_error(Dynlink.error_message e)
469
469
 
 
470
  let skip_findlib = [ "unix"; "dynlink"; "findlib" ]
 
471
  let predicates = ref [ "byte" ]
 
472
  let loaded = ref []
 
473
  let init_findlib_var = ref false
 
474
 
 
475
  let init_findlib() =
 
476
    if not !init_findlib_var then (
 
477
      Findlib.init();
 
478
      init_findlib_var := true
 
479
    )
 
480
 
 
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
 
485
    let rec split i j =
 
486
      if j < l then
 
487
        match s.[j] with
 
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)
 
491
          | _ ->
 
492
              split i (j+1)
 
493
      else
 
494
        if i<j then [ String.sub s i (j-i) ] else []
 
495
    in
 
496
    split 0 0
 
497
 
 
498
  let cmd_require pkg =
 
499
    (* Findlib-supported package loading. Also see topfind.ml in findlib *)
 
500
    init_findlib();
 
501
    try
 
502
      let eff_pkglist =
 
503
        Findlib.package_deep_ancestors !predicates [pkg] in
 
504
      List.iter
 
505
        (fun pkg ->
 
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: *)
 
511
               let archive =
 
512
                 try Findlib.package_property !predicates pkg "archive"
 
513
                 with
 
514
                     Not_found -> ""
 
515
               in
 
516
               (* Split the 'archive' property and load the files: *)
 
517
               let archives = split_in_words archive in
 
518
               List.iter
 
519
                 (fun arch -> 
 
520
                    let arch' = Findlib.resolve_path ~base:d arch in
 
521
                    reg_module_name := 
 
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)
 
527
                 )
 
528
                 archives;
 
529
             end;
 
530
             (* The package is loaded: *)
 
531
             loaded := pkg :: !loaded
 
532
           end
 
533
        )
 
534
        eff_pkglist
 
535
    with
 
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)
 
540
      | Failure msg ->
 
541
          log_error ("Failure: " ^ msg)
 
542
 
 
543
  let cmd_thread _ =
 
544
    init_findlib();
 
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"
 
552
        )
 
553
        else (
 
554
          log_error "NetcgiThread: No support for threads"
 
555
        )
 
556
      )
 
557
 
 
558
  let cmd_predicates s =
 
559
    init_findlib();
 
560
    let preds = split_in_words s in
 
561
    predicates := preds @ !predicates
 
562
 
470
563
  let cmd_translate_handler sconfig name =
471
564
    { sconfig with translate_handler = Some (Hashtbl.find reg_table name) }
472
565
 
500
593
  let () =
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;