Source

ocaml-sip / tests / data / Testdata_messages.ml

Full commit
open Sip_types
open Batteries

(*********************************************************************************************************************
 *
 *)

module Util = struct

    let eol_sep = "\r\n"

    let prepare_invalid_message title msg = (title, String.concat eol_sep msg)

    let prepare_valid_message title msg descr = (title, String.concat eol_sep msg, descr)

    type message_description
        = DescrMimeField of string * string
        | DescrMimeFields of string * string list
        | DescrContentLength of int
        | DescrSipVersion of sip_version
        | DescrMaxForwards of int

    let descr_content_length i = DescrContentLength i
    let descr_sip_version i    = DescrSipVersion i
    let descr_max_forwards i   = DescrMaxForwards i
    let descr_mime_field a b   = DescrMimeField (a,b)
    let descr_mime_fields a b  = DescrMimeFields (a,b)
end

module Valid_messages = struct
    open Util

    let message_001 = prepare_valid_message "basic invite RFC3261.4"
        [ "INVITE sip:bob@biloxi.com SIP/2.0" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "Max-Forwards: 70" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
        ; "CSeq: 314159 INVITE"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ; String.repeat "a" 142
        ]

        [ descr_max_forwards 70
        ; descr_sip_version SIP_2_0
        ; descr_content_length 142

        ; descr_mime_fields "Via"
            [ "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
            ]
        ]


    let message_002 = prepare_valid_message "invite with multipart body RFC3261.23.4.2"
        [ "INVITE sip:bob@biloxi.com SIP/2.0"
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8"
        ; "To: Bob <sip:bob@biloxi.com>"
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774"
        ; "Call-ID: a84b4c76e66710"
        ; "CSeq: 314159 INVITE"
        ; "Max-Forwards: 70"
        ; "Date: Thu, 21 Feb 2002 13:02:03 GMT"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: multipart/signed;"
        ; "protocol=\"application/pkcs7-signature\";"
        ; "micalg=sha1; boundary=boundary42"
        ; "Content-Length: 568"
        ; ""
        ; "--boundary42"
        ; "Content-Type: message/sip"
        ; ""
        ; "INVITE sip:bob@biloxi.com SIP/2.0"
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKnashds8"
        ; "To: Bob <bob@biloxi.com>"
        ; "From: Alice <alice@atlanta.com>;tag=1928301774"
        ; "Call-ID: a84b4c76e66710"
        ; "CSeq: 314159 INVITE"
        ; "Max-Forwards: 70"
        ; "Date: Thu, 21 Feb 2002 13:02:03 GMT"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 147"
        ; ""
        ; "v=0"
        ; "o=UserA 2890844526 2890844526 IN IP4 here.com"
        ; "s=Session SDP"
        ; "c=IN IP4 pc33.atlanta.com"
        ; "t=0 0"
        ; "m=audio 49172 RTP/AVP 0"
        ; "a=rtpmap:0 PCMU/8000"
        ; ""
        ; "--boundary42"
        ; "Content-Type: application/pkcs7-signature; name=smime.p7s"
        ; "Content-Transfer-Encoding: base64"
        ; "Content-Disposition: attachment; filename=smime.p7s;"
        ; " handling=required"
        ; "ghyHhHUujhJhjH77n8HHGTrfvbnj756tbB9HG4VQpfyF467GhIGfHfYT6"
        ; "4VQpfyF467GhIGfHfYT6jH77n8HHGghyHhHUujhJh756tbB9HGTrfvbnj"
        ; "n8HHGTrfvhJhjH776tbB9HG4VQbnj7567GhIGfHfYT6ghyHhHUujpfyF4"
        ; "7GhIGfHfYT64VQbnj756"
        ; ""
        ; "--boundary42-"
        ]

        [ descr_max_forwards 70
        ; descr_sip_version SIP_2_0
        ; descr_content_length 568
        ]

    let message_003 = prepare_valid_message "basic invite RFC3261.4, but as SIP/1.0"
        [ "INVITE sip:bob@biloxi.com SIP/1.0" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "Max-Forwards: 70" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
        ; "CSeq: 314159 INVITE"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ; String.repeat "a" 142
        ]

        [ descr_max_forwards 70
        ; descr_sip_version SIP_1_0
        ; descr_content_length 142

        ; descr_mime_fields "Via"
            [ "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
            ]
        ]

    let message_004 = prepare_valid_message "basic invite RFC3261.4, but as SIP/1.5"
        [ "INVITE sip:bob@biloxi.com SIP/1.5" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "Max-Forwards: 70" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
        ; "CSeq: 314159 INVITE"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ; String.repeat "a" 142
        ]

        [ descr_max_forwards 70
        ; descr_sip_version (UnknownSipVersion "1.5")
        ; descr_content_length 142

        ; descr_mime_fields "Via"
            [ "SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
            ]
        ]

    let messages =
        [ message_001
        ; message_002
        ; message_003
        ; message_004
        ]
end


module Invalid_messages = struct
    open Util

    let message_001 = prepare_invalid_message "basic invite RFC3261.4, without the Contact header"
        [ "INVITE sip:bob@biloxi.com SIP/2.0" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "Max-Forwards: 70" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
        ; "CSeq: 314159 INVITE"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ]

    let message_002 = prepare_invalid_message "basic invite RFC3261.4, without the Call-ID header"
        [ "INVITE sip:bob@biloxi.com SIP/2.0" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "Max-Forwards: 70" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "CSeq: 314159 INVITE"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ; String.repeat "a" 142
        ]

    let message_003 = prepare_invalid_message "basic invite RFC3261.4, without the CSeq header"
        [ "INVITE sip:bob@biloxi.com SIP/2.0" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "Max-Forwards: 70" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ; String.repeat "a" 142
        ]

    let message_004 = prepare_invalid_message "basic invite RFC3261.4, without the Max-forwards header"
        [ "INVITE sip:bob@biloxi.com SIP/2.0" 
        ; "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds" 
        ; "To: Bob <sip:bob@biloxi.com>" 
        ; "From: Alice <sip:alice@atlanta.com>;tag=1928301774" 
        ; "Call-ID: a84b4c76e66710@pc33.atlanta.com" 
        ; "CSeq: 314159 INVITE"
        ; "Contact: <sip:alice@pc33.atlanta.com>"
        ; "Content-Type: application/sdp"
        ; "Content-Length: 142"
        ; ""
        ; String.repeat "a" 142
        ]

    let message_005 = prepare_invalid_message "basic invite RFC3261.4, without MIME"
        [ "INVITE sip:bob@biloxi.com SIP/2.0" 
        ; ""
        ]

    let messages =
        [ message_001
        ; message_002
        ; message_003
        ; message_004
        ; message_005
        ]

end