xkaraman left a comment (kamailio/kamailio#4586)

This got a bit more than initially thought due to many considerations like 
multiple spaces before and after, no spaces, with/out display name etc. 

I used multiple messages to test which can be found here:

<details> test_message.sh

```
SIP_SERVER="kamailio.server.com"
SIP_PORT="5060"

send_invite() {
        printf "%b" "$1" | timeout 0.3 nc -u -4 "$SIP_SERVER" "$SIP_PORT"
}

# Valid case: From with display name and angle brackets, To with display name 
and angle brackets

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: Alice Smith <sip:[email protected]>;tag=1001\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf95\r\n\
Max-Forwards: 70\r\n\
To: Bob Jones <sip:[email protected]>\r\n\
Call-ID: test-case-001\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Valid case: From with angle brackets no display name, To with angle brackets 
no display name

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: <sip:[email protected]>;tag=1002\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf91\r\n\
Max-Forwards: 70\r\n\
To: <sip:[email protected]>\r\n\
Call-ID: test-case-002\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Valid case: From without angle brackets, To without angle brackets

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: sip:[email protected];tag=1003\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf92\r\n\
Max-Forwards: 70\r\n\
To: sip:[email protected]\r\n\
Call-ID: test-case-003\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Invalid case: From with display name no angle brackets, To with display name 
no angle brackets

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: Alice sip:[email protected];tag=1004\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf93\r\n\
Max-Forwards: 70\r\n\
To: Bob sip:[email protected]\r\n\
Call-ID: test-case-004\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Invalid case: From missing closing angle bracket

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: Alice <sip:[email protected];tag=1005\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf95\r\n\
Max-Forwards: 70\r\n\
To: <sip:[email protected]>\r\n\
Call-ID: test-case-005\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Valid case syntax: To with malformed URI

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: Alice <sip:[email protected]>;tag=1006\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf96\r\n\
Max-Forwards: 70\r\n\
To: <sip:bob@>\r\n\
Call-ID: test-case-006\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# valid case: From missing tag parameter

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: <sip:[email protected]>\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf97\r\n\
Max-Forwards: 70\r\n\
To: <sip:[email protected]>\r\n\
Call-ID: test-case-007\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Edge case: From with display name containing special characters, with angle 
brackets

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: \"Alice Smith, Support\" <sip:[email protected]>;tag=1008\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf98\r\n\
Max-Forwards: 70\r\n\
To: \"Bob Jones, Sales\" <sip:[email protected]>\r\n\
Call-ID: test-case-008\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Valid case: From and To with port numbers in URI

INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: Alice Smith <sip:[email protected];port=5050>;tag=1001\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf99\r\n\
Max-Forwards: 70\r\n\
To: Bob Jones <sip:[email protected]>\r\n\
Call-ID: test-case-009\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# valid case: no space between display name and URI in From header,
INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: Alice<sip:[email protected]>;tag=1001\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74b1239\r\n\
Max-Forwards: 70\r\n\
To: Bob Jones<sip:[email protected]>\r\n\
Call-ID: test-case-010\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# valid case: no space between header display name from,
INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From:Alice <sip:[email protected]>;tag=1001\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74b1231239\r\n\
Max-Forwards: 70\r\n\
To:Bob Jones <sip:[email protected]>\r\n\
Call-ID: test-case-011\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# valid case: no space between header display name and URI in From header,
INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From:Alice<sip:[email protected]>;tag=1001\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4b123K74b1239\r\n\
Max-Forwards: 70\r\n\
To:Bob Jones<sip:[email protected]>\r\n\
Call-ID: test-case-012\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# valid case: multiple space between header display name from,
INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From:     Alice    <sip:[email protected]>;tag=1001\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74b1231239\r\n\
Max-Forwards: 70\r\n\
To:    Bob Jones                 <sip:[email protected]>\r\n\
Call-ID: test-case-013\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"

# Invalid case: Empty angle brackets in From header
INVITE_MSG="INVITE sip:[email protected] SIP/2.0\r\n\
From: <>;tag=1009\r\n\
Via: SIP/2.0/UDP there.com:5060;rport;branch=z9hG4bK74bf9\r\n\
Max-Forwards: 70\r\n\
To: <sip:[email protected]>\r\n\
Call-ID: test-case-014\r\n\
CSeq: 1 INVITE\r\n\
Contact: <sip:[email protected]>;expires=3600\r\n\
Content-Length: 0\r\n\r\n"
send_invite "$INVITE_MSG"
```


-- 
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/4586#issuecomment-3884583822
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/pull/4586/[email protected]>
_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to