Fix bug receiving DeviceInfo after successful login
This commit is contained in:
1 parent
8e831fc045
commit
c2cc25e2a1
4 files changed
+65
-3
No files matched your search
+24
-2
@@ -102,7 +102,10 @@ fn bc_legacy_login_msg<'a, 'b>(buf: &'b [u8])
|
||||
fn bc_modern_msg<'a, 'b>(header: &'a BcHeader, buf: &'b [u8])
|
||||
-> IResult<&'b [u8], ModernMsg>
|
||||
{
|
||||
let end_of_xml = header.bin_offset.unwrap_or(header.body_len);
|
||||
let end_of_xml = match header.bin_offset {
|
||||
Some(off) if off > 0 => off,
|
||||
_ => header.body_len
|
||||
};
|
||||
|
||||
let (mut buf, body_buf) = take(end_of_xml)(buf)?;
|
||||
|
||||
@@ -215,7 +218,6 @@ fn test_bc_modern_login_failed() {
|
||||
assert_eq!(header.enc_offset, 0x0);
|
||||
assert_eq!(header.encrypted, true);
|
||||
assert_eq!(header.class, 0x0000);
|
||||
println!("{:?}", body);
|
||||
match body {
|
||||
BcBody::ModernMsg(ModernMsg{ xml: None, binary: None }) => {
|
||||
assert!(true);
|
||||
@@ -223,3 +225,23 @@ fn test_bc_modern_login_failed() {
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bc_modern_login_success() {
|
||||
let sample = include_bytes!("samples/modern_login_success.bin");
|
||||
|
||||
let (buf, header) = bc_header(&sample[..]).unwrap();
|
||||
let (_, body) = bc_body(&header, buf).unwrap();
|
||||
assert_eq!(header.msg_id, 1);
|
||||
assert_eq!(header.body_len, 2949);
|
||||
assert_eq!(header.enc_offset, 0x0);
|
||||
assert_eq!(header.encrypted, true);
|
||||
assert_eq!(header.class, 0x0000);
|
||||
|
||||
// Previously, we were not handling bin_offset == 0 (no bin offset) correctly.
|
||||
// Test that we decoded XML and no binary.
|
||||
match body {
|
||||
BcBody::ModernMsg(ModernMsg{ xml: Some(_), binary: None }) => assert!(true),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
+41
-1
@@ -76,7 +76,6 @@ impl Default for LoginNet {
|
||||
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct DeviceInfo {
|
||||
#[yaserde(rename="Resolution")]
|
||||
pub resolution: Resolution,
|
||||
}
|
||||
|
||||
@@ -178,3 +177,44 @@ fn test_login_ser() {
|
||||
assert_eq!(b, b3);
|
||||
assert_eq!(b2, b3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deviceinfo_partial_deser() {
|
||||
let sample = indoc!(r#"
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<DeviceInfo version="1.1">
|
||||
<ipChannel>0</ipChannel>
|
||||
<analogChnNum>1</analogChnNum>
|
||||
<resolution>
|
||||
<resolutionName>3840*2160</resolutionName>
|
||||
<width>3840</width>
|
||||
<height>2160</height>
|
||||
</resolution>
|
||||
<language>English</language>
|
||||
<sdCard>0</sdCard>
|
||||
<ptzMode>none</ptzMode>
|
||||
<typeInfo>IPC</typeInfo>
|
||||
<softVer>33554880</softVer>
|
||||
<B485>0</B485>
|
||||
<supportAutoUpdate>0</supportAutoUpdate>
|
||||
<userVer>1</userVer>
|
||||
</DeviceInfo>
|
||||
</body>"#);
|
||||
|
||||
// Needs to ignore all the other crap that we don't care about
|
||||
let b = Body::try_parse(sample.as_bytes()).unwrap();
|
||||
println!("{:?}", b);
|
||||
match b {
|
||||
Body {
|
||||
device_info: Some(DeviceInfo {
|
||||
resolution: Resolution {
|
||||
width: 3840,
|
||||
height: 2160,
|
||||
..
|
||||
}, ..
|
||||
}), ..
|
||||
} => assert!(true),
|
||||
_ => assert!(false)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user