Commits

Paweł Wieczorek committed 91b1f2f Draft

cleaning

  • Participants
  • Parent commits 85d8baf

Comments (0)

Files changed (4)

File src/Sip_parser.ml

 
         let uri            = sip_uri_of_string _uri in
 
-(*
-        let sip_contact    = SipContact (Hashtbl.find mime "contact") in
-*)
+        let sip_contact    = Option.map sip_address_of_string (Hashtbl.find_option mime "contact") in
 
         let max_forwards   = int_of_string (Hashtbl.find mime "max-forwards") in
 
 
         method max_forwards     = max_forwards
 
-(*
         method contact          = sip_contact
-*)
 
         method header name      = Hashtbl.find mime name
 
+        method header_option name = Hashtbl.find_option mime name
+
         method header_all name  = Hashtbl.find_all mime name
 
     end

File src/Sip_types.ml

 type sip_cseq =
     SipCseq of string
 
-type sip_contact =
-    SipContact of string
-
 type sip_version =
     | SIP_1_0
     | SIP_2_0
 
         method max_forwards     : int
 
-(*
-        method contact          : sip_contact
-*)
+        method contact          : sip_address option
 
         method header           : string -> string
 
+        method header_option    : string -> string option
+
         method header_all       : string -> string list
 
+
     end
 
 (*********************************************************************************************************************

File tests/Test_parser.ml

 let assert_strs_equal msg a b =
     assert_equal ~msg:msg ~printer:(fun x -> "[" ^ String.concat "," (List.map String.quote x) ^ "]") a b
 
-let validate_extracted_field request conv revconv field extracted expected =
-    let actual_mime      = request#header (String.lowercase field) in
-    let printer = String.quote -| revconv in
-    assert_equal ~msg:("mime field " ^ field) ~printer:printer expected (conv actual_mime);
+let _validate_field printer actual request revconv field extracted expected =
+    assert_equal ~msg:("mime field " ^ field) ~printer:printer expected actual;
     assert_equal ~msg:("extracted field " ^ field) ~printer:printer expected extracted
 
+let validate_extracted_field request conv revconv field extracted expected =
+    let actual_mime      = conv (request#header (String.lowercase field)) in
+    let printer = String.quote -| revconv in
+    _validate_field printer actual_mime request revconv field extracted expected
+
+let validate_extracted_field_option request conv revconv field extracted expected =
+    let actual_mime      = Option.map conv (request#header_option (String.lowercase field)) in
+    let printer          = Option.map_default (String.quote -| revconv) "None" in
+    _validate_field printer actual_mime request revconv field extracted expected
+
 let validate_extracted_field_all request conv revconv field extracted expected =
-    let actual_mime      = request#header_all (String.lowercase field) in
+    let actual_mime      = List.map conv (request#header_all (String.lowercase field)) in
     let printer          = String.concat "," -| List.map (String.quote -| revconv) in
     assert_equal ~msg:("length " ^ field) ~printer:string_of_int (List.length expected) (List.length extracted);
-    assert_equal ~msg:("mime field " ^ field) ~printer:printer expected (List.map conv actual_mime);
-    assert_equal ~msg:("extracted field " ^ field) ~printer:printer expected extracted
+    _validate_field printer actual_mime request revconv field extracted expected
 
 let validate_message request = function
     | DescrMimeField (field, expected) ->
             sip_via_of_string string_of_sip_via
             "via" extracted expected
 
+    | DescrContact expected ->
+        let extracted = request#contact in
+        validate_extracted_field_option request
+            sip_address_of_string string_of_sip_address
+            "contact" extracted expected
 
 let valid_message_parse_test (title, buffer, descr) = 
     "valid message -- " ^ title >::

File tests/data/Testdata_messages.ml

         | DescrTo of sip_address
         | DescrFrom of sip_address
         | DescrVia of sip_via list
+        | DescrContact of sip_address option
 
     let descr_content_length i = DescrContentLength i
     let descr_sip_version i    = DescrSipVersion i
     let descr_to c             = DescrTo c
     let descr_from c           = DescrFrom c
     let descr_via c            = DescrVia (List.rev c)
+
+    let descr_no_contact       = DescrContact None
+    let descr_contact c        = DescrContact (Some c)
 end
 
 module Valid_messages = struct
             ; descr_sip_version
                 SIP_2_0
 
+            ; descr_contact
+                (sip_address_of_string "<sip:alice@pc33.atlanta.com>")
+
             ; descr_cseq
                 (sip_cseq_of_string "314159 INVITE")