-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust/sip: register parser for tcp v9 #9893
Changes from all commits
5451fdb
961a62d
add724d
a4f7db1
c49e208
96b34a7
fbb6c7a
769de02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* 02110-1301, USA. | ||
*/ | ||
|
||
// written by Giuseppe Longo <giuseppe@glono.it> | ||
// written by Giuseppe Longo <giuseppe@glongo.it> | ||
|
||
use nom7::bytes::streaming::{take, take_while, take_while1}; | ||
use nom7::character::streaming::{char, crlf}; | ||
|
@@ -57,9 +57,13 @@ pub struct Response { | |
pub body_len: u16, | ||
} | ||
|
||
/** | ||
* Valid tokens and chars are defined in RFC3261: | ||
* https://www.rfc-editor.org/rfc/rfc3261#section-25.1 | ||
*/ | ||
#[inline] | ||
fn is_token_char(b: u8) -> bool { | ||
is_alphanumeric(b) || b"!%'*+-._`".contains(&b) | ||
is_alphanumeric(b) || b"!%'*+-._`~".contains(&b) | ||
} | ||
|
||
#[inline] | ||
|
@@ -69,12 +73,12 @@ fn is_method_char(b: u8) -> bool { | |
|
||
#[inline] | ||
fn is_request_uri_char(b: u8) -> bool { | ||
is_alphanumeric(b) || is_token_char(b) || b"~#@:".contains(&b) | ||
is_alphanumeric(b) || is_token_char(b) || b"~#@:;=?+&$,/".contains(&b) | ||
} | ||
|
||
#[inline] | ||
fn is_version_char(b: u8) -> bool { | ||
is_alphanumeric(b) || b"./".contains(&b) | ||
b"SIP/2.0".contains(&b) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we rather want the caller of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will also match There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you, it's much better tagging |
||
} | ||
|
||
#[inline] | ||
|
@@ -322,4 +326,33 @@ mod tests { | |
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_parse_invalid_version() { | ||
let buf: &[u8] = "HTTP/1.1\r\n".as_bytes(); | ||
|
||
// This test must fail if 'HTTP/1.1' is accepted | ||
match parse_version(buf) { | ||
Ok((_, _)) => { | ||
assert!(false); | ||
} | ||
Err(_) => { | ||
assert!(true); | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_parse_valid_version() { | ||
let buf: &[u8] = "SIP/2.0\r\n".as_bytes(); | ||
|
||
match parse_version(buf) { | ||
Ok((_, version)) => { | ||
assert_eq!(version, "SIP/2.0"); | ||
} | ||
Err(_) => { | ||
assert!(false); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should mention that this is for the
stats
events.cc @jufajardini
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!