Commits

Anonymous committed 38d4034

commented out debugging prints

Comments (0)

Files changed (4)

dbg.ml

-(*
-value dbg fmt = Printf.printf fmt
-;
-*)
-
-value dbg fmt = Printf.ifprintf Pervasives.stdout fmt
-;
 open It_Ops
 ;
 
-open Dbg
-;
-
 open It_Types
 ;
 
       match i with
       [ IE_done x -> IO.return x
       | IE_cont opt_exn _ ->
+(*
 let () = dbg "run: exn=%s\n" &
   match opt_exn with
   [ None -> "none"
   | Some e -> Printexc.to_string e
   ]
 in
+*)
           IO.error & match opt_exn with
           [ None -> (Divergent_iteratee "run")
           | Some e -> e
 value (stream2list : iteratee 'el (list 'el)) =
   IE_cont None (fun s -> step [] s
     where rec step rev_acc s =
-      let () = dbg "s2l: step: acc=%i\n" & List.length rev_acc in
+      (* let () = dbg "s2l: step: acc=%i\n" & List.length rev_acc in *)
       match s with
       [ Chunk c ->
           if S.is_empty c
            then ie_contM (step acc)
            else
              let (matches, tail) = S.break cpred c in
+(*
 let () = dbg "S.break: %i -> %i+%i\n" (S.length c) (S.length matches) (S.length tail) in
+*)
              let new_acc = S.fold S.L func acc matches in
              if S.is_empty tail
              then ie_contM (step new_acc)
     match s with
     [ Chunk c ->
         let str = S.drop_while cpred c in
+(*
 let () = dbg "drop_while: %i -> %i\n" (S.length c) (S.length str) in
+*)
         if S.is_empty str
         then ie_contM step
         else ie_doneM () (Chunk str)
 ;
 
 
+(*
 value fdbg fmt = Printf.ksprintf (Printf.eprintf "forms: %s\n%!") fmt
 ;
+*)
 
 
 (* +
            check (Sl.append sl' sl_t) it
        ]
      and (loop : ! 'a . iteratee_cont 'el 'a -> enumpart_ret 'el 'a) k =
-       let () = fdbg "ep: loop" in
+       (* let () = fdbg "ep: loop" in *)
        mres (read_func inch buf_str 0 buffer_size) >>% fun read_res ->
        match read_res with
        [ `Error e ->
            k (EOF (some & ierr_of_merr e)) >>% fun (it, sl') ->
            IO.return (it, lazy sl', EP_None)
        | `Ok have_read ->
-           let () = fdbg "ep: Read buffer, size %i" have_read in
+           (* let () = fdbg "ep: Read buffer, size %i" have_read in *)
            let () = assert (have_read >= 0) in
            if have_read = 0
            then
      and (check : ! 'a . enumpart 'el 'a) sl it =
        match it with
        [ IE_cont None k ->
-           let () = fdbg "ep: check: cont" in
+           (* let () = fdbg "ep: check: cont" in *)
            feed sl k
        | IE_cont (Some _) _ | IE_done _ ->
-           let () = fdbg "ep: check: ready" in
+           (* let () = fdbg "ep: check: ready" in *)
            IO.return
              ( it
              , lazy (Sl.copy_my_buf buf_arr sl)
 
 
 value (enum_file : string -> enumerator char 'a) filepath iterv =
-  mprintf "opened file %S\n" filepath >>% fun () ->
+  (* mprintf "opened file %S\n" filepath >>% fun () -> *)
   IO.open_in filepath >>% fun inch ->
   enum_fd inch iterv >>% fun r ->
   IO.close_in inch >>% fun () ->
-  mprintf "closed file %S\n" filepath >>% fun () ->
+  (* mprintf "closed file %S\n" filepath >>% fun () -> *)
   IO.return r
 ;
 
 
 value (limit : int -> enumeratee 'el 'el 'a) lim = fun it ->
   let rec limit ~lim ~it =
-    let () = dbg "limit: lim=%i\n%!" lim in
+    (* let () = dbg "limit: lim=%i\n%!" lim in *)
     match (lim, it) with
     [ (_, (IE_done _ | IE_cont (Some _) _))
       | (0, IE_cont None _) -> return it
     [ EOF _ -> k s >>% fun (i, _) -> ie_doneM i s
     | Chunk c ->
         let len = S.length c in
-        let () = dbg "limit/step: len=%i\n%!" len in
+        (* let () = dbg "limit/step: len=%i\n%!" len in *)
         if len <= left
         then
           k s >>% fun (it, s) ->
     | `Error e -> IO.return (catchk (throw_err e), Sl.one s)
     ]
   in
-    let () = dbg "catchk: entered\n%!" in
+    (* let () = dbg "catchk: entered\n%!" in *)
     let it =
       try
         itf ()
 
 
 
+(*
 value printf fmt =
   Printf.ksprintf (fun s -> lift & IO.write IO.stdout s) fmt
 ;
+*)
 
 
 value gather_to_string : iteratee char string =
   match it_proc with
   [ IE_done _ | IE_cont (Some _) _ -> IO.return it_proc
   | IE_cont None k_proc ->
-      let () = fdbg "bs: feed_proc: %s" (dbgstream s) in
+      (* let () = fdbg "bs: feed_proc: %s" (dbgstream s) in *)
       k_proc s >>% fun (it_proc, _sl) ->
       IO.return it_proc
   ]
 and loop_q q it_proc =
   match Deque_stream.destr_head q with
   [ None ->
-      let () = fdbg "bs: loop_q: empty q" in
+      (* let () = fdbg "bs: loop_q: empty q" in *)
       ie_contM (step0 it_proc)
   | Some ((first_ofs, first_stream), qtail) ->
-      let () = fdbg "bs: loop_q: first_stream = %s, first_ofs = %i"
-        (dbgstream first_stream) first_ofs in
+      (* let () = fdbg "bs: loop_q: first_stream = %s, first_ofs = %i"
+        (dbgstream first_stream) first_ofs in *)
       match first_stream with
       [ EOF _ ->
           feed_proc it_proc first_stream >>% fun it_proc ->
   (* запрашиваем чанк, loop_index с первым чанком,
      смещением=0 и пустым хвостом.  вызывается из loop_q. *)
   fun s ->
-    let () = fdbg "bs: step0: stream = %s" (dbgstream s) in
+    (* let () = fdbg "bs: step0: stream = %s" (dbgstream s) in *)
     match s with
     [ Chunk c -> loop_index c 0 it_proc ~qtail:Deque_stream.empty
     | (EOF _ ) as s -> ie_doneM (None, it_proc) s
        смещения, имеющихся в значениях loop_index *)
     let len = cur_ofs - first_ofs in
     let () = assert (len >= 0) in
+    (*
     let () = fdbg "bs: feed_first_chunk: %i .. %i (len = %i) (chunk len = %i)"
       first_ofs cur_ofs len (S.length first_chunk) in
+     *)
     if len = 0
     then IO.return it_proc
     else
           (* let () = fdbg "bs: loop_ofs: None from subseq" in *)
           loop_ofs (ofs + 1)
       | Some io_sq_it_left ->
-          let () = fdbg "bs: loop_ofs: Some _ from subseq" in
+          (* let () = fdbg "bs: loop_ofs: Some _ from subseq" in *)
           io_sq_it_left >>% fun (sq_it, sq_left) ->
-          let () = fdbg "bs: loop_ofs: sq_left = %s"
+          (* let () = fdbg "bs: loop_ofs: sq_left = %s"
             (Sl.dbgsl sq_left)
-          in
+          in *)
           match sq_it with
           [ IE_done sub_res ->
-             let () = fdbg "bs: loop_ofs: sq_it done" in
+             (* let () = fdbg "bs: loop_ofs: sq_it done" in *)
              (* - когда результат от it_subseq_step -- *)
              (*   - Кормить *)
              feed_first_chunk ~cur_ofs:ofs it_proc >>% fun it_proc ->
               "break_sequence: it_subseq_step should return None on error")
               Sl.empty
           | IE_cont None k_sub ->
-              let () = fdbg "bs: loop_ofs: sq_it cont" in
+              (* let () = fdbg "bs: loop_ofs: sq_it cont" in *)
               (* - когда не ошибка, а "хочу ещё" от it_subseq_step -- *)
               (*   - Кормить *)
               feed_first_chunk ~cur_ofs:ofs it_proc >>% fun it_proc ->
-              let () = fdbg "substep/cont: head = %s at ofs %i"
-                (dbgstream (Chunk first_chunk)) ofs in
+              (* let () = fdbg "substep/cont: head = %s at ofs %i"
+                (dbgstream (Chunk first_chunk)) ofs in *)
               let qtail = Deque_stream.cons
                 0
                 (let c = S.drop ofs first_chunk in
 and step1 k_sub it_proc q =
   (* запрашиваем чанк *)
   ie_contM & fun s ->
-  let () = fdbg "step1: new chunk = %s" (dbgstream s) in
+  (* let () = fdbg "step1: new chunk = %s" (dbgstream s) in *)
   let q = Deque_stream.snoc q 0 s in
   (* дать s в k_sub, посмотреть на результат *)
   k_sub s >>% fun (it_sub, sl_sub) ->
   match it_sub with
   [ IE_done r ->
-      let () = fdbg "step1: it_sub done, sl_sub = %s" (Sl.dbgsl sl_sub) in
+      (* let () = fdbg "step1: it_sub done, sl_sub = %s" (Sl.dbgsl sl_sub) in *)
       break_subsequence_ret
         (Deque_stream.cons_sl sl_sub Deque_stream.empty)
         ~sub_res_opt:(Some r)
         it_proc
 
   | IE_cont (Some _) _ ->
-       let () = fdbg "step1: it_sub error" in
+       (* let () = fdbg "step1: it_sub error" in *)
        (* - если ошибка -- loop_index со следующего смещения в первом чанке
             очереди (может дать ofs=len) *)
        match Deque_stream.destr_head q with
        ]
 
   | IE_cont None k_sub ->
-      let () = fdbg "step1: it_sub cont" in
+      (* let () = fdbg "step1: it_sub cont" in *)
       step1 k_sub it_proc q
   ]
 in
   ie_cont & fun s ->
-    let () = fdbg "bs: init: stream = %s" (dbgstream s) in
+    (* let () = fdbg "bs: init: stream = %s" (dbgstream s) in *)
     break_subsequence Deque_stream.(cons 0 s empty) it_proc
 ;
 
            else `No
      in
      let ret ~arr ofs_after =
-       let () = fdbg "probe_string: len=%i, dropping %i"
-         (S.length arr) ofs_after in
+       (* let () = fdbg "probe_string: len=%i, dropping %i"
+         (S.length arr) ofs_after in *)
        ie_doneM () (Chunk (S.drop ofs_after arr))
      in
      let rec it_first_step arr ~ofs ~i
        [ `Yes ofs_after -> Some (ret ~arr ofs_after)
        | `No -> None
        | `Maybe i ->
-           let () = fdbg "probe: cont from first step" in
+           (* let () = fdbg "probe: cont from first step" in *)
            Some (ie_contM & it_step ~i)
        ]
      and it_step ~i s =

iteratees_http.ml

 open It_Types
 ;
 
-open Dbg
-;
-
 open It_Ops
 ;
 
     else return n
   in
     break_chars (fun c -> c == '\r' || c == '\n') >>= fun l ->
-let () = dbg "http_line: %S\n" l in
+(* let () = dbg "http_line: %S\n" l in *)
     terminators >>= fun ts ->
     check l ts
 ;
 value rec (enum_lines : enumeratee char string 'a) i =
   match i with
   [ IE_cont None k ->
-let () = dbg "enum_lines: IE_cont\n" in
+      (* let () = dbg "enum_lines: IE_cont\n" in *)
       line >>= fun term_line ->
         match term_line with
         [ (`Term, "") ->
-let () = dbg "enum_lines:   empty line\n" in
+            (* let () = dbg "enum_lines:   empty line\n" in *)
             return i  (* empty line, normal exit *)
         | (`Term, l) ->
-let () = dbg "enum_lines:   term: %S\n" l in
+            (* let () = dbg "enum_lines:   term: %S\n" l in *)
             liftI (
             k (chunk_of l) >>% fun (i, _s) ->
             IO.return (enum_lines i)
             )
         | (`No_term, l) ->
-let () = dbg "enum_lines:   non-term: %S\n" l in
+            (* let () = dbg "enum_lines:   non-term: %S\n" l in *)
             (lift : _)
             (k (if l="" then EOF (Some End_of_file) else chunk_of l)
              >>% fun (i, _s) ->
             )
         ]
   | IE_cont (Some _) _ ->
-let () = dbg "enum_lines: error\n" in
+      (* let () = dbg "enum_lines: error\n" in *)
       return i
   | IE_done _ ->
-let () = dbg "enum_lines: done\n" in
+      (* let () = dbg "enum_lines: done\n" in *)
       return i
   ]
 ;
         match read_hex str with
         [ None -> frame_err (exc ("Bad chunk size: " ^ str)) iter
         | Some size ->
-            let () = dbg
-              "enum_chunk_decoded: frame %i (%x) bytes\n" size size in
+            (* let () = dbg
+              "enum_chunk_decoded: frame %i (%x) bytes\n" size size in *)
             getCRLF iter (
             take size iter >>= fun r ->
             getCRLF r (
 ;
 
 
+(*
 value it_dbg it =
   match it with
   [ IE_cont None _ -> "IE_cont None _"
   | IE_done _ -> "IE_done _"
   ]
 ;
+*)
 
 
 exception Multipart_error of string;
                  multipart_max_header_size.val
            | IE_cont (Some _) _ | IE_done _ ->
                it_line >>= fun line ->
-                 let () = fdbg "read_part_headers: line = %S" line in
+                 (* let () = fdbg "read_part_headers: line = %S" line in *)
                  if line = ""
                  then return & List.rev acc
                  else inner (count + 1) [line :: acc]
        ]
      in
 
-     let fdbg_stream_char title =
+     (*
+     let fdbg_stream_char_ _title =
        ie_cont
          (fun s ->
-            let () =
-            fdbg "stream: %s: %s" title (dbgstream_char ~body:10 s)
-            in
+            (* let () =
+                 fdbg "stream: %s: %s" title (dbgstream_char ~body:10 s)
+            in *)
             ie_doneM () s
          )
      in
+     *)
 
      let rec loop_boundaries (it_fold : iteratee a r) =
-       let () = fdbg "loop" in
-       fdbg_stream_char "before loop" >>= fun () ->
+       (* let () = fdbg "loop" in *)
+       (* fdbg_stream_char_ "before loop" >>= fun () -> *)
        after_boundary >>= fun ab ->
        match ab with
        [ `Finished ->
-           let () = fdbg "  `Finished" in
+           (* let () = fdbg "  `Finished" in *)
            (* fdbg_stream_char "after finished" >>= fun () -> *)
            it_ignore (* must ignore, RFC 2046 *) >>= fun () ->
            let res = feed_it it_fold (EOF None) in
-           let () = fdbg "    loop_boundaries: res = %s" (it_dbg res) in
+           (* let () = fdbg "    loop_boundaries: res = %s" (it_dbg res) in *)
            map_ready res
        | `Next ->
-           let () = fdbg "  `Next" in
+           (* let () = fdbg "  `Next" in *)
            read_part_headers >>= fun part_headers ->
            let proc = proc_of_it_fold it_fold in
            break_subsequence
              (probe_string crlf_boundary)
              (match proc with
               [ `Proc ->
-                  let () = fdbg "will read this part with it_part" in
+                  (* let () = fdbg "will read this part with it_part" in *)
                   (it_part part_headers) >>= fun p ->
-                  let () = fdbg "it_part ok" in
+                  (* let () = fdbg "it_part ok" in *)
                   return & Some p
               | `Skip ->
-                  let () = fdbg "will skip this part" in
+                  (* let () = fdbg "will skip this part" in *)
                   it_ignore >>= fun () ->
-                  let () = fdbg "part was skipped" in
+                  (* let () = fdbg "part was skipped" in *)
                   return None
               ]
              )
            >>= fun (opt_boundary, opt_it_part) ->
-           fdbg_stream_char "after it_part" >>= fun () ->
+           (* fdbg_stream_char "after it_part" >>= fun () -> *)
            match opt_boundary with
            [ None ->
                (* если границу не нашли *)
        >>= fun (opt_boundary, it_last2) ->
        match opt_boundary with
        [ None ->
-           let () = fdbg "sfb: None" in
+           (* let () = fdbg "sfb: None" in *)
            map_ready & feed_it it_fold (EOF None)
        | Some () ->
-           let () = fdbg "sfb: Some" in
+           (* let () = fdbg "sfb: Some" in *)
            eof_to_res it_last2 None >>= fun res_last2 ->
            match res_last2 with
            [ `Ok ([] | ['\r'; '\n']) ->
-               let () = fdbg "sfb: found good prefix" in
+               (* let () = fdbg "sfb: found good prefix" in *)
                loop_boundaries it_fold
            | `Ok _ ->
-               let () = fdbg "sfb: found bad prefix" in
-               fdbg_stream_char "sfb/bad" >>= fun () ->
+               (* let () = fdbg "sfb: found bad prefix" in *)
+               (* fdbg_stream_char "sfb/bad" >>= fun () -> *)
                search_for_beginning ()
            | `Error _ ->
                throw_err (Failure "unexpected error from it_last 2")
 ;
 
 
+(*
 value dump_after title =
    get_stream_eof >>= fun opt_opt_err ->
    let () = fdbg "after %s: %s"
    in
      return ()
 ;
+*)
 
 
 value test_forms ~allsizes () =
     List.iter
       (fun (body, boundary, expected) ->
          let run_size sz =
-           let () = fdbg "test_forms/run_size %i" sz in
+           (* let () = fdbg "test_forms/run_size %i" sz in *)
            match IO.runIO
            ((enum_string ~chunk_size:sz
                body
                (     (H.it_multipart boundary
                         (fun headers ->
-                           let () = fdbg "getting part" in
+                           (* let () = fdbg "getting part" in *)
                            gather_to_string >>= fun part ->
-                           let () = fdbg "got part (%i bytes): %S"
-                             (String.length part) part in
-                           dump_after "part" >>= fun () ->
+                           (* let () = fdbg "got part (%i bytes): %S"
+                             (String.length part) part in *)
+                           (* dump_after "part" >>= fun () -> *)
                            return (headers, part)
                         )
                         (stream2list >>= fun lst ->
-                         dump_after "all parts" >>= fun () ->
+                         (* dump_after "all parts" >>= fun () -> *)
                          return lst
                         )
                      )