| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::fsshttpb::data::cell_id::CellId; |
| 3 |
use crate::fsshttpb::data::exguid::ExGuid; |
| 4 |
use crate::fsshttpb::data::object_types::ObjectType; |
| 5 |
use crate::fsshttpb::data::serial_number::SerialNumber; |
| 6 |
use crate::fsshttpb::data::stream_object::ObjectHeader; |
| 7 |
use crate::fsshttpb::data_element::DataElement; |
| 8 |
use crate::Reader; |
| 9 |
use std::collections::HashMap; |
| 10 |
|
| 11 |
/// A storage index. |
| 12 |
/// |
| 13 |
/// See [\[MS-FSSHTTPB\] 2.2.1.12.2] |
| 14 |
/// |
| 15 |
/// [\[MS-FSSHTTPB\] 2.2.1.12.2]: https://docs.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-fsshttpb/f5724986-bd0f-488d-9b85-7d5f954d8e9a |
| 16 |
#[derive(Debug)] |
| 17 |
pub(crate) struct StorageIndex { |
| 18 |
pub(crate) manifest_mappings: Vec<StorageIndexManifestMapping>, |
| 19 |
pub(crate) cell_mappings: HashMap<CellId, StorageIndexCellMapping>, |
| 20 |
pub(crate) revision_mappings: HashMap<ExGuid, StorageIndexRevisionMapping>, |
| 21 |
} |
| 22 |
|
| 23 |
impl StorageIndex { |
| 24 |
pub(crate) fn find_cell_mapping_id(&self, cell_id: CellId) -> Option<ExGuid> { |
| 25 |
self.cell_mappings.get(&cell_id).map(|mapping| mapping.id) |
| 26 |
} |
| 27 |
|
| 28 |
pub(crate) fn find_revision_mapping_id(&self, id: ExGuid) -> Option<ExGuid> { |
| 29 |
self.revision_mappings |
| 30 |
.get(&id) |
| 31 |
.map(|mapping| mapping.revision_mapping) |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
/// A storage indexes manifest mapping. |
| 36 |
#[derive(Debug)] |
| 37 |
pub(crate) struct StorageIndexManifestMapping { |
| 38 |
pub(crate) mapping_id: ExGuid, |
| 39 |
pub(crate) serial: SerialNumber, |
| 40 |
} |
| 41 |
|
| 42 |
/// A storage indexes cell mapping. |
| 43 |
#[derive(Debug)] |
| 44 |
pub(crate) struct StorageIndexCellMapping { |
| 45 |
pub(crate) cell_id: CellId, |
| 46 |
pub(crate) id: ExGuid, |
| 47 |
pub(crate) serial: SerialNumber, |
| 48 |
} |
| 49 |
|
| 50 |
/// A storage indexes revision mapping. |
| 51 |
#[derive(Debug)] |
| 52 |
pub(crate) struct StorageIndexRevisionMapping { |
| 53 |
pub(crate) revision_mapping: ExGuid, |
| 54 |
pub(crate) serial: SerialNumber, |
| 55 |
} |
| 56 |
|
| 57 |
impl DataElement { |
| 58 |
pub(crate) fn parse_storage_index(reader: Reader) -> Result<StorageIndex> { |
| 59 |
let mut manifest_mappings = vec![]; |
| 60 |
let mut cell_mappings = HashMap::new(); |
| 61 |
let mut revision_mappings = HashMap::new(); |
| 62 |
|
| 63 |
loop { |
| 64 |
if ObjectHeader::has_end_8(reader, ObjectType::DataElement)? { |
| 65 |
break; |
| 66 |
} |
| 67 |
|
| 68 |
let object_header = ObjectHeader::parse_16(reader)?; |
| 69 |
match object_header.object_type { |
| 70 |
ObjectType::StorageIndexManifestMapping => { |
| 71 |
manifest_mappings.push(Self::parse_storage_index_manifest_mapping(reader)?) |
| 72 |
} |
| 73 |
ObjectType::StorageIndexCellMapping => { |
| 74 |
let (id, mapping) = Self::parse_storage_index_cell_mapping(reader)?; |
| 75 |
|
| 76 |
cell_mappings.insert(id, mapping); |
| 77 |
} |
| 78 |
ObjectType::StorageIndexRevisionMapping => { |
| 79 |
let (id, mapping) = Self::parse_storage_index_revision_mapping(reader)?; |
| 80 |
|
| 81 |
revision_mappings.insert(id, mapping); |
| 82 |
} |
| 83 |
_ => { |
| 84 |
return Err(ErrorKind::MalformedFssHttpBData( |
| 85 |
format!("unexpected object type: {:x}", object_header.object_type).into(), |
| 86 |
) |
| 87 |
.into()) |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
ObjectHeader::try_parse_end_8(reader, ObjectType::DataElement)?; |
| 93 |
|
| 94 |
Ok(StorageIndex { |
| 95 |
manifest_mappings, |
| 96 |
cell_mappings, |
| 97 |
revision_mappings, |
| 98 |
}) |
| 99 |
} |
| 100 |
|
| 101 |
fn parse_storage_index_manifest_mapping(reader: Reader) -> Result<StorageIndexManifestMapping> { |
| 102 |
let mapping_id = ExGuid::parse(reader)?; |
| 103 |
let serial = SerialNumber::parse(reader)?; |
| 104 |
|
| 105 |
Ok(StorageIndexManifestMapping { mapping_id, serial }) |
| 106 |
} |
| 107 |
|
| 108 |
fn parse_storage_index_cell_mapping( |
| 109 |
reader: Reader, |
| 110 |
) -> Result<(CellId, StorageIndexCellMapping)> { |
| 111 |
let cell_id = CellId::parse(reader)?; |
| 112 |
let id = ExGuid::parse(reader)?; |
| 113 |
let serial = SerialNumber::parse(reader)?; |
| 114 |
|
| 115 |
let mapping = StorageIndexCellMapping { |
| 116 |
cell_id, |
| 117 |
id, |
| 118 |
serial, |
| 119 |
}; |
| 120 |
|
| 121 |
Ok((cell_id, mapping)) |
| 122 |
} |
| 123 |
|
| 124 |
fn parse_storage_index_revision_mapping( |
| 125 |
reader: Reader, |
| 126 |
) -> Result<(ExGuid, StorageIndexRevisionMapping)> { |
| 127 |
let id = ExGuid::parse(reader)?; |
| 128 |
let revision_mapping = ExGuid::parse(reader)?; |
| 129 |
let serial = SerialNumber::parse(reader)?; |
| 130 |
|
| 131 |
let mapping = StorageIndexRevisionMapping { |
| 132 |
revision_mapping, |
| 133 |
serial, |
| 134 |
}; |
| 135 |
|
| 136 |
Ok((id, mapping)) |
| 137 |
} |
| 138 |
} |