~ubuntu-branches/ubuntu/oneiric/ocsigen/oneiric

« back to all changes in this revision

Viewing changes to extensions/outputfilter.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stephane Glondu
  • Date: 2009-07-02 10:02:08 UTC
  • mfrom: (1.1.9 upstream) (4.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090702100208-n158b1sqwzn0asil
Tags: 1.2.0-2
Fix build on non-native architectures

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
open Ocsigen_headers
30
30
 
31
31
 
32
 
let gen (header, regexp, dest) charset = function
 
32
let gen (header, regexp, dest) = function
33
33
  | Req_not_found (code,_) -> return (Ext_next code)
34
 
  | Req_found (ri, result) ->
35
 
      result () >>= fun res ->
 
34
  | Req_found (ri, res) ->
36
35
      try
37
36
        let header_values =
38
37
          Http_headers.find_all header res.Ocsigen_http_frame.res_headers
60
59
      with Not_found ->
61
60
        Lwt.return (Ocsigen_extensions.Ext_found (fun () -> Lwt.return res))
62
61
 
63
 
(*****************************************************************************)
64
 
(** Function to be called at the beginning of the initialisation phase
65
 
    of the server (actually each time the config file is reloaded) *)
66
 
let start_init () =
67
 
  ()
68
 
 
69
 
(** Function to be called at the end of the initialisation phase *)
70
 
let end_init () =
71
 
  ()
72
 
 
73
 
 
74
 
 
75
 
(*****************************************************************************)
76
 
(** A function that will create an error message from the exceptions
77
 
    that may be raised during the initialisation phase, and raise again
78
 
    all other exceptions. That function has type exn -> string. Use the
79
 
   raise function if you don't need any. *)
80
 
let exn_handler = raise
81
 
 
82
 
 
83
 
 
84
 
(*****************************************************************************)
85
 
(** Extensions may define new tags for configuring each site.
86
 
    These tags are inside <site ...>...</site> in the config file.
87
 
 
88
 
   For example:
89
 
   <site dir="">
90
 
     <extensiontemplate module=".../mymodule.cmo" />
91
 
   </site>
92
 
 
93
 
   Each extension will set its own configuration options, for example:
94
 
   <site dir="">
95
 
     <extensiontemplate module=".../mymodule.cmo" />
96
 
     <eliom module=".../myeliommodule.cmo" />
97
 
     <static dir="/var/www/plop" />
98
 
   </site>
99
 
 
100
 
 *)
101
 
 
102
 
let parse_config path charset _ _ = function
 
62
 
 
63
 
 
64
(*****************************************************************************)
 
65
 
 
66
let parse_config = function
103
67
  | Element ("outputfilter", atts, []) ->
104
68
      let rec parse_attrs ((h, r, d) as res) = function
105
69
        | [] -> res
113
77
      in
114
78
      (match parse_attrs (None, None, None) atts with
115
79
      | (Some h, Some r, Some d) ->
116
 
          gen (Http_headers.name h, r, d) charset
 
80
          gen (Http_headers.name h, r, d)
117
81
      | _ ->
118
82
          raise
119
83
            (Error_in_config_file
120
84
               "Missing attributes for <outputfilter header=... regexp=... dest=... />"))
 
85
  | Element ("outputfilter" as s, _, _) -> badconfig "Bad syntax for tag %s" s
 
86
 
121
87
  | Element (t, _, _) -> raise (Bad_config_tag_for_extension t)
122
88
  | _ ->
123
89
      raise (Error_in_config_file "Unexpected data in config file")
125
91
 
126
92
 
127
93
 
128
 
(*****************************************************************************)
129
 
let site_creator hostpattern = parse_config
130
 
   (* hostpattern has type Ocsigen_extensions.virtual_hosts
131
 
      and represents the name of the virtual host *)
132
 
 
133
94
 
134
95
(*****************************************************************************)
135
96
(** Registration of the extension *)
136
 
let _ = Ocsigen_extensions.register_extension
137
 
  site_creator
138
 
  site_creator
139
 
  start_init
140
 
  end_init
141
 
  exn_handler
142
 
 
 
97
let () = register_extension
 
98
  ~name:"outputfilter"
 
99
  ~fun_site:(fun _ _ _ _ -> parse_config)
 
100
  ~user_fun_site:(fun _ _ _ _ _ -> parse_config)
 
101
  ()