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

« back to all changes in this revision

Viewing changes to eliom/eliommod_services.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:
27
27
(*****************************************************************************)
28
28
 
29
29
open Lwt
 
30
open Ocsigen_extensions
30
31
 
31
32
 
32
33
(*****************************************************************************)
90
91
  in
91
92
  (catch
92
93
     (fun () -> return (List.assoc k !pagetableref))
93
 
     (function Not_found ->
94
 
       fail Eliom_common.Eliom_404 | e -> fail e)) >>=
 
94
     (function
 
95
        | Not_found -> fail Eliom_common.Eliom_404
 
96
        | e -> fail e)) >>=
95
97
  aux [] >>=
96
98
  (fun (r, toremove) ->
97
99
    let list, newptr = Ocsigen_lib.list_assoc_remove k !pagetableref in
122
124
  try
123
125
    let l, newt = Ocsigen_lib.list_assoc_remove key t in
124
126
    try
125
 
      if key.Eliom_common.key_state = (None, None)
 
127
      if key.Eliom_common.key_state = (Eliom_common.Att_no, Eliom_common.Att_no)
126
128
      then begin
127
129
(********* V�rifier ici qu'il n'y a pas qqchose similaire d�j� enregistr� ?! *)
128
130
        let (oldgen, n), oldl = Ocsigen_lib.list_assoc_remove id l in
129
131
        if not duringsession && (generation = oldgen)
130
132
        then
131
133
          raise (Eliom_common.Eliom_duplicate_registration
132
 
                   (Ocsigen_lib.string_of_url_path url_act))
 
134
                   (Ocsigen_lib.string_of_url_path ~encode:false url_act))
133
135
        else (key, (insert_as_last_of_generation generation v oldl))::newt
134
136
      end
135
137
      else (key, (insert_as_last_of_generation generation v l))::newt
162
164
    (page_table_key,
163
165
     ((unique_id1, unique_id2), max_use, expdate, action)) =
164
166
 
165
 
  let aux search dircontentref a l =
 
167
  let rec aux dircontentref a l =
166
168
    try
167
169
      let direltref = find_dircontent !dircontentref a in
168
170
      match !direltref with
169
 
      | Eliom_common.Dir dcr -> search dcr l
 
171
      | Eliom_common.Dir dcr -> search_page_table_ref dcr l
170
172
      | Eliom_common.File ptr ->
171
173
          raise (Eliom_common.Eliom_page_erasing a)
172
174
            (* Ocsigen_messages.warning ("Eliom page registration: Page "^
173
175
               a^" has been replaced by a directory");
174
176
               let newdcr = ref (Eliom_common.empty_dircontent ()) in
175
177
               (direltref := Eliom_common.Dir newdcr;
176
 
               search newdcr l) *)
 
178
               search_page_table_ref newdcr l) *)
177
179
    with
178
180
    | Not_found ->
179
181
        let newdcr = ref (Eliom_common.empty_dircontent ()) in
180
182
        (dircontentref :=
181
183
          add_dircontent !dircontentref (a, ref (Eliom_common.Dir newdcr));
182
 
         search newdcr l)
183
 
  in
184
 
 
185
 
  let rec search_page_table_ref dircontentref = function
 
184
         search_page_table_ref newdcr l)
 
185
 
 
186
 
 
187
  and search_page_table_ref dircontentref = function
186
188
    | [] | [""] ->
187
189
        search_page_table_ref dircontentref [Eliom_common.defaultpagename]
188
190
    | [a] ->
205
207
                (a, ref (Eliom_common.File newpagetableref));
206
208
             newpagetableref))
207
209
    | ""::l -> search_page_table_ref dircontentref l
208
 
    | a::l -> aux search_page_table_ref dircontentref a l
209
 
          (* and search_dircontentref dircontentref = function
210
 
             [] -> dircontentref
211
 
             | ""::l -> search_dircontentref dircontentref l
212
 
             | a::l -> aux search_dircontentref a l *)
 
210
    | a::l -> aux dircontentref a l
213
211
  in
214
212
 
215
213
  (match expdate with
254
252
            search_page_table !dircontentref2 l
255
253
        | Eliom_common.File page_table_ref -> page_table_ref, l)
256
254
      with Exn1 ->
257
 
        (match !(find_dircontent dircontent
258
 
                   Eliom_common.eliom_suffix_internal_name) with
 
255
        (match !(try 
 
256
                   find_dircontent dircontent
 
257
                     Eliom_common.eliom_suffix_internal_name
 
258
                 with Not_found -> raise Exn1)
 
259
         with
259
260
        | Eliom_common.Dir _ -> raise Not_found
260
261
        | Eliom_common.File page_table_ref ->
261
262
            (page_table_ref, (if a = None then [""] else aa::l)))
262
263
    in function
263
 
      | [] -> raise Ocsigen_extensions.Ocsigen_Is_a_directory
 
264
      | [] -> raise (Ocsigen_extensions.Ocsigen_Is_a_directory ri)
264
265
      | [""] -> aux None []
265
266
      | ""::l -> search_page_table dircontent l
266
267
      | a::l -> aux (Some a) l
268
269
  let page_table_ref, suffix =
269
270
    try
270
271
      search_page_table !dircontentref
271
 
        (Ocsigen_lib.change_empty_list ri.Ocsigen_extensions.ri_sub_path)
272
 
    with Not_found -> raise Eliom_common.Eliom_404
 
272
        (Ocsigen_lib.change_empty_list ri.request_info.ri_sub_path)
 
273
    with Exn1 | Not_found -> raise Eliom_common.Eliom_404
273
274
  in
274
275
  find_page_table
275
276
    now
280
281
    ri
281
282
    suffix
282
283
    {Eliom_common.key_state = si.Eliom_common.si_state_info;
283
 
     Eliom_common.key_kind = ri.Ocsigen_extensions.ri_method}
 
284
     Eliom_common.key_kind = ri.request_info.ri_method}
284
285
    si
285
286
 
 
287
 
286
288
(******************************************************************)
287
289
(* attached services                                              *)
288
290
let get_page
329
331
                    Ocsigen_messages.debug
330
332
                      (fun () ->
331
333
                         "--Eliom: I'm looking for "^
332
 
                           (Ocsigen_lib.string_of_url_path ri.Ocsigen_extensions.ri_sub_path)^
 
334
                           (Ocsigen_lib.string_of_url_path
 
335
                              ~encode:true
 
336
                              ri.request_info.ri_sub_path)^
333
337
                           " in the secure session table:");
334
338
                    find_aux Eliom_common.Eliom_404 !service_cookies_info
335
339
                | _ -> Lwt.fail Eliom_common.Eliom_404
340
344
                  Ocsigen_messages.debug
341
345
                    (fun () ->
342
346
                       "--Eliom: I'm looking for "^
343
 
                         (Ocsigen_lib.string_of_url_path ri.Ocsigen_extensions.ri_sub_path)^
 
347
                         (Ocsigen_lib.string_of_url_path
 
348
                            ~encode:true
 
349
                            ri.request_info.ri_sub_path)^
344
350
                         " in the session table:");
345
351
                  find_aux Eliom_common.Eliom_404 !service_cookies_info
346
352
              | e -> fail e)
365
371
                | Eliom_common.Eliom_Wrong_parameter as exn ->
366
372
                    (* si pas trouv� avec, on essaie sans l'�tat *)
367
373
                    (match si.Eliom_common.si_state_info with
368
 
                    | (None, None) -> fail exn
369
 
                    | (g, Some _) ->
 
374
                    | (Eliom_common.Att_no, Eliom_common.Att_no) -> fail exn
 
375
                    | (g, Eliom_common.Att_anon _)
 
376
                    | (g, Eliom_common.Att_named _) ->
370
377
                        (* There was a POST state.
371
378
                           We remove it, and remove POST parameters.
372
379
                         *)
373
380
                        Ocsigen_messages.debug2
374
381
                          "--Eliom: Link to old. I will try without POST parameters:";
375
382
                        fail (Eliom_common.Eliom_retry_with
376
 
                                ({ri with
377
 
                                  Ocsigen_extensions.ri_post_params =
378
 
                                     lazy (return []);
379
 
                                  Ocsigen_extensions.ri_method =
380
 
                                  Ocsigen_http_frame.Http_header.GET;
381
 
                                  Ocsigen_extensions.ri_extension_info=
382
 
                                  Eliom_common.Eliom_Link_too_old::
383
 
                                  ri.Ocsigen_extensions.ri_extension_info
384
 
                                },
 
383
                                ({ri with request_info =
 
384
                                     { ri.request_info with
 
385
                                         ri_post_params = lazy (return []);
 
386
                                         ri_method =
 
387
                                           Ocsigen_http_frame.Http_header.GET;
 
388
                                         ri_extension_info =
 
389
                                           Eliom_common.Eliom_Link_too_old ::
 
390
                                             ri.request_info.ri_extension_info
 
391
                                }},
385
392
                                 {si with
386
393
                                  Eliom_common.si_nonatt_info=
387
394
                                  Eliom_common.Na_no;
388
 
                                  Eliom_common.si_state_info= (g, None);
 
395
                                  Eliom_common.si_state_info= 
 
396
                                     (g, Eliom_common.Att_no);
389
397
                                },
390
398
                                 cookies_to_set,
391
399
                                 all_cookie_info
392
400
                                ))
393
 
                    | (Some _, None) ->
 
401
                    | (Eliom_common.Att_named _, Eliom_common.Att_no)
 
402
                    | (Eliom_common.Att_anon _, Eliom_common.Att_no) ->
394
403
                        (* There was a GET state, but no POST state.
395
404
                           We remove it with its parameters,
396
405
                           and remove POST parameters.
398
407
                        Ocsigen_messages.debug2
399
408
                          "--Eliom: Link to old. I will try without GET state parameters and POST parameters:";
400
409
                        fail (Eliom_common.Eliom_retry_with
401
 
                                ({ri with
402
 
                                  ri_get_params =
403
 
                                  lazy si.Eliom_common.si_other_get_params;
404
 
                                  Ocsigen_extensions.ri_post_params = lazy (return []);
405
 
                                  Ocsigen_extensions.ri_method =
406
 
                                  Ocsigen_http_frame.Http_header.GET;
407
 
                                  Ocsigen_extensions.ri_extension_info=
408
 
                                  Eliom_common.Eliom_Link_too_old::
409
 
                                  ri.Ocsigen_extensions.ri_extension_info
 
410
                                ({ri with request_info =
 
411
                                     { ri.request_info with
 
412
                                         ri_get_params =
 
413
                                           lazy si.Eliom_common.si_other_get_params;
 
414
                                         ri_post_params = lazy (return []);
 
415
                                         ri_method =
 
416
                                           Ocsigen_http_frame.Http_header.GET;
 
417
                                         ri_extension_info=
 
418
                                           Eliom_common.Eliom_Link_too_old::
 
419
                                             ri.request_info.ri_extension_info
 
420
                                     }
410
421
                                },
411
422
                                 {si with
412
423
                                  Eliom_common.si_nonatt_info=
413
424
                                  Eliom_common.Na_no;
414
 
                                  Eliom_common.si_state_info=(None, None);
 
425
                                  Eliom_common.si_state_info=
 
426
                                     (Eliom_common.Att_no, Eliom_common.Att_no);
415
427
                                  Eliom_common.si_other_get_params=[];
416
428
                                },
417
429
                                 cookies_to_set,