-
Notifications
You must be signed in to change notification settings - Fork 86
Fix SDP session ID length limitation #438
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
Changes from 4 commits
1d2f0be
88a6c35
eab1c10
fd1fd2f
4fcb7ac
f4ae108
b17a399
0f60e6d
d57fd4b
1a0970e
55bad47
f1526b9
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#include "sdp/sdp.h" | ||
|
||
#include <stdexcept> | ||
#include <boost/lexical_cast.hpp> | ||
#include "bst/regex.h" | ||
#include "cpprest/basic_utils.h" | ||
#include "cpprest/json_visit.h" | ||
|
@@ -68,6 +69,22 @@ namespace sdp | |
return web::json::value(v); | ||
} | ||
|
||
inline std::string jns2s(const web::json::value& v) | ||
{ | ||
if (v.is_number()) return jn2s(v); | ||
else return js2s(v); | ||
} | ||
inline web::json::value digits2jns(const std::string& s) | ||
{ | ||
if (!std::all_of(s.begin(), s.end(), ::isdigit)) throw sdp_parse_error("expected a sequence of digits"); | ||
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.
|
||
|
||
uint64_t v; | ||
std::istringstream is(s); | ||
is >> v; | ||
lo-simon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (is.fail() || !is.eof()) return s2js(s); | ||
return web::json::value(boost::lexical_cast<utility::string_t>(v)); | ||
} | ||
|
||
// find the first delimiter in str, beginning at pos, and return the substring from pos to the delimiter (or end) | ||
// set pos to the end of the delimiter | ||
inline std::string substr_find(const std::string& str, std::string::size_type& pos, const std::string& delimiter = {}) | ||
|
@@ -96,6 +113,8 @@ namespace sdp | |
|
||
const converter digits_converter{ jn2s, digits2jn }; | ||
|
||
const converter long_digits_converter{ jns2s, digits2jns }; | ||
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. Very minor quibble... Long is often understood to refer to the |
||
|
||
// <key>[<separator><value>] | ||
converter key_value_converter(char separator, const std::pair<utility::string_t, converter>& key_converter, const std::pair<utility::string_t, converter>& value_converter) | ||
{ | ||
|
@@ -290,8 +309,8 @@ namespace sdp | |
'o', | ||
object_converter({ | ||
{ sdp::fields::user_name, string_converter }, | ||
{ sdp::fields::session_id, digits_converter }, | ||
{ sdp::fields::session_version, digits_converter }, | ||
{ sdp::fields::session_id, long_digits_converter }, | ||
{ sdp::fields::session_version, long_digits_converter }, | ||
{ sdp::fields::network_type, string_converter }, | ||
{ sdp::fields::address_type, string_converter }, | ||
{ sdp::fields::unicast_address, string_converter } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,8 @@ a=mid:SECONDARY | |
{ sdp::fields::protocol_version, 0 }, | ||
{ sdp::fields::origin, web::json::value_of({ | ||
{ sdp::fields::user_name, U("-") }, | ||
{ sdp::fields::session_id, 3745911798u }, | ||
{ sdp::fields::session_version, 3745911798u }, | ||
{ sdp::fields::session_id, U("3745911798") }, | ||
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. Does the conversion from JSON data model to textual SDP file now handle both strings and numbers? Do we test both? 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. They are covered in the 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. No, I don't think so, those check only parsing from textual SDP to JSON. My concern was whether an application developer who assumes the value in the JSON is a number as before will now get an exception either when they process the parsed JSON or when they construct the JSON with a number and generate SDP text. You can't make a value be both a number and a string of course! The generation could handle both (does it? this is the original question I was asking) but the parser can't. I guess given the type of the accessor object has changed they will get a compile error if they use that? Maybe that's good enough if so... 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. Thanks @garethsb, a new test |
||
{ sdp::fields::session_version, U("3745911798") }, | ||
{ sdp::fields::network_type, sdp::network_types::internet.name }, | ||
{ sdp::fields::address_type, sdp::address_types::IP4.name }, | ||
{ sdp::fields::unicast_address, U("192.168.9.142") } | ||
|
@@ -346,8 +346,8 @@ a=framerate:59.94 | |
{ sdp::fields::protocol_version, 0 }, | ||
{ sdp::fields::origin, web::json::value_of({ | ||
{ sdp::fields::user_name, U("-") }, | ||
{ sdp::fields::session_id, 0 }, | ||
{ sdp::fields::session_version, 0 }, | ||
{ sdp::fields::session_id, U("0") }, | ||
{ sdp::fields::session_version, U("0") }, | ||
{ sdp::fields::network_type, sdp::network_types::internet.name }, | ||
{ sdp::fields::address_type, sdp::address_types::IP4.name }, | ||
{ sdp::fields::unicast_address, U("192.0.2.0") } | ||
|
@@ -571,3 +571,35 @@ a=fmtp:96)"; | |
BST_REQUIRE_THROW(sdp::parse_session_description(test_sdp + bp), std::runtime_error); | ||
} | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////// | ||
BST_TEST_CASE(testSdpSessionId) | ||
{ | ||
const std::string before = "v=0\r\no=- "; | ||
const std::string after = " 42 IN IP4 10.0.0.1\r\ns= \r\nt=0 0\r\n"; | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "0" + after)); | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "007" + after)); | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "18446744073709551615" + after)); // session id to UINT64_MAX | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "184467440737095516150" + after)); // session id greater than UINT64_MAX | ||
// an invalid session id results in "sdp parse error - expected a sequence of digits at line 2" | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "foo" + after), std::runtime_error); | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "0foo" + after), std::runtime_error); | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "0.0" + after), std::runtime_error); | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "0x0" + after), std::runtime_error); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////// | ||
BST_TEST_CASE(testSdpSessionVersion) | ||
{ | ||
const std::string before = "v=0\r\no=- 42 "; | ||
const std::string after = " IN IP4 10.0.0.1\r\ns= \r\nt=0 0\r\n"; | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "0" + after)); | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "007" + after)); | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "18446744073709551615" + after)); // session version to UINT64_MAX | ||
BST_REQUIRE_NO_THROW(sdp::parse_session_description(before + "184467440737095516150" + after)); // session version greater than UINT64_MAX | ||
// an invalid session version results in "sdp parse error - expected a sequence of digits at line 2" | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "foo" + after), std::runtime_error); | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "0foo" + after), std::runtime_error); | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "0.0" + after), std::runtime_error); | ||
BST_REQUIRE_THROW(sdp::parse_session_description(before + "0x0" + after), std::runtime_error); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.