You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
247 lines
8.0 KiB
247 lines
8.0 KiB
#include <util/calendar_parsing.h>
|
|
|
|
#include <memory>
|
|
|
|
namespace util {
|
|
std::vector<ical::ical_object*> parse_cal_dir(std::string directory) {
|
|
std::vector<ical::ical_object*> objects;
|
|
std::vector<icalcomponent*> components;
|
|
uint counter = 0;
|
|
for (boost::filesystem::directory_entry& entry : boost::filesystem::directory_iterator(directory)) {
|
|
DEBUG << "Parsing: " + entry.path().generic_string();
|
|
ical::ical_object* object = new ical::ical_object();
|
|
parse_main_component(object, parse_ics_file(entry.path().generic_string()));
|
|
counter++;
|
|
}
|
|
DEBUG << "files parsed: " << counter;
|
|
return objects;
|
|
}
|
|
|
|
icalcomponent* parse_main_component(ical::ical_object* object, icalcomponent* component) {
|
|
icalcomponent* c = icalcomponent_get_first_component(component, ICAL_ANY_COMPONENT);
|
|
while(c != 0) {
|
|
if(c != 0) {
|
|
parse_component(object, c);
|
|
}
|
|
c = parse_main_component(object, c);
|
|
if(c == 0) {
|
|
c = icalcomponent_get_next_component(component, ICAL_ANY_COMPONENT);
|
|
}
|
|
}
|
|
return c;
|
|
}
|
|
|
|
void parse_component(ical::ical_object* object, icalcomponent* component) {
|
|
switch(icalcomponent_isa(component)) {
|
|
case ICAL_VALARM_COMPONENT: break;
|
|
case ICAL_NO_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_NO_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_ANY_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_ANY_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XROOT_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XROOT_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XATTACH_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XATTACH_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VEVENT_COMPONENT:
|
|
{
|
|
//DEBUG << "parsed component: ICAL_VEVENT_COMPONENT";
|
|
//DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
ical::Event(object, component);
|
|
break;
|
|
}
|
|
case ICAL_VTODO_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VTODO_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VJOURNAL_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VJOURNAL_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VCALENDAR_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VCALENDAR_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VAGENDA_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VAGENDA_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VFREEBUSY_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VFREEBUSY_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XAUDIOALARM_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XAUDIOALARM_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XDISPLAYALARM_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XDISPLAYALARM_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XEMAILALARM_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XEMAILALARM_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XPROCEDUREALARM_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XPROCEDUREALARM_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VTIMEZONE_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VTIMEZONE_COMPONENT";
|
|
break;
|
|
}
|
|
case ICAL_XSTANDARD_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XSTANDARD_COMPONENT";
|
|
break;
|
|
}
|
|
case ICAL_XDAYLIGHT_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XDAYLIGHT_COMPONENT";
|
|
break;
|
|
}
|
|
case ICAL_X_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_X_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VSCHEDULE_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VSCHEDULE_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VQUERY_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VQUERY_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VREPLY_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VREPLY_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VCAR_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VCAR_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VCOMMAND_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VCOMMAND_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XLICINVALID_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XLICINVALID_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XLICMIMEPART_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XLICMIMEPART_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VAVAILABILITY_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VAVAILABILITY_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XAVAILABLE_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XAVAILABLE_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VPOLL_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VPOLL_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VVOTER_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VVOTER_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XVOTE_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XVOTE_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_VPATCH_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_VPATCH_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
case ICAL_XPATCH_COMPONENT:
|
|
{
|
|
DEBUG << "parsed component: ICAL_XPATCH_COMPONENT";
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
break;
|
|
}
|
|
default:
|
|
DEBUG << "parse_component: something else found";
|
|
break;
|
|
}
|
|
}
|
|
|
|
std::string slurp(std::ifstream& in) {
|
|
std::ostringstream sstr;
|
|
sstr << in.rdbuf();
|
|
return sstr.str();
|
|
}
|
|
|
|
icalcomponent* parse_ics_file(std::string filename) {
|
|
std::ifstream ifs (filename, std::ifstream::in);
|
|
return icalparser_parse_string(slurp(ifs).c_str());
|
|
}
|
|
|
|
void debug(icalcomponent* component) {
|
|
DEBUG << "\n" << icalcomponent_as_ical_string_r(component);
|
|
}
|
|
}
|