diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-01-14 00:23:31 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-01-14 00:23:31 +0100 |
commit | e15e7878a1e894b4e6928ab0417f5dfdc76b4968 (patch) | |
tree | 24beba4a5e7f8e9364f52fec8bddca328b2c3f54 /src/icalwrap | |
parent | eeee278ecefa4893d94f01e41093989a84630d55 (diff) |
icalvcalendar: refactor checking, add safe method
Diffstat (limited to 'src/icalwrap')
-rw-r--r-- | src/icalwrap/icalvcalendar.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs index 2336829..ec2aaf5 100644 --- a/src/icalwrap/icalvcalendar.rs +++ b/src/icalwrap/icalvcalendar.rs @@ -75,14 +75,6 @@ impl IcalVCalendar { return Err("could not read component".to_string()); } - if let Err(error) = IcalVCalendar::check_icalcomponent(parsed_cal) { - let path_string = match path { - Some(path_ref) => format!("{}", path_ref.display()), - None => "".to_string() - }; - warn!("{}: {}", path_string, error); - } - let kind = ical::icalcomponent_isa(parsed_cal); if kind != ical::icalcomponent_kind_ICAL_VCALENDAR_COMPONENT { let kind = CStr::from_ptr(ical::icalcomponent_kind_to_string(kind)).to_string_lossy(); @@ -91,6 +83,10 @@ impl IcalVCalendar { let mut cal = IcalVCalendar::from_ptr(parsed_cal); cal.path = path.map(|path| path.to_path_buf()); + + if let Err(error) = cal.check_for_errors() { + warn!("{}: {}", path.map_or_else(|| "", |path| path.to_str().unwrap()), error); + } Ok(cal) } } @@ -227,9 +223,16 @@ impl IcalVCalendar { event } - //to be used after parsing, parser adds X-LIC-ERROR properties for any error - //ical::icalrestriction_check() checks if the specification is violated and adds X-LIC-ERRORs accordingly - //ical::icalcomponent_count_errors() counts all X-LIC-ERROR properties + pub fn check_for_errors(&self) -> Result<(), String> { + let result = unsafe { + IcalVCalendar::check_icalcomponent(self.get_ptr()) + }; + result + } + + /// to be used after parsing, parser adds X-LIC-ERROR properties for any error + /// ical::icalrestriction_check() checks if the specification is violated and adds X-LIC-ERRORs accordingly + /// ical::icalcomponent_count_errors() counts all X-LIC-ERROR properties unsafe fn check_icalcomponent(comp: *mut ical::icalcomponent) -> Result<(), String> { ical::icalrestriction_check(comp); let error_count = ical::icalcomponent_count_errors(comp); @@ -486,10 +489,7 @@ mod tests { #[test] fn parse_checker_test() { - let c_str = CString::new(testdata::TEST_EVENT_MULTIDAY).unwrap(); - unsafe { - let parsed_cal = ical::icalparser_parse_string(c_str.as_ptr()); - assert!(IcalVCalendar::check_icalcomponent(parsed_cal).is_ok()) - } + let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap(); + assert!(cal.check_for_errors().is_ok()); } } |