static BongoJsonObject * ConvertFile(const char *filename) { icalparser *parser; FILE *f; icalcomponent *component; BongoJsonObject *obj; parser = icalparser_new(); f = fopen(filename, "r"); if (!f) { printf("couldn't open input file %s\n", filename); return NULL; } icalparser_set_gen_data(parser, f); component = icalparser_parse(parser, ReadStream); icalcomponent_strip_errors(component); obj = BongoCalIcalToJson(component); return obj; }
GSList* EDSCalendarStorage::toICalComponentsList(const std::vector<std::string> & iCals, const OpenAB::PIMItem::IDs& ids, std::vector<icaltimezone*>& timezones) { GSList * events = NULL; currentEventTimeZones.clear(); for(unsigned int i = 0; i < iCals.size(); ++i) { std::stringstream ss(iCals[i]); //In case of recurring events one iCalendar can contain couple of VEVENT objects, get them all while (1) { std::string event = EDSCalendarStorageCommon::cutVObject(ss); if (event.empty()) { break; } icalcomponent* newEvent = icalcomponent_new_from_string(event.c_str()); if (!newEvent) { LOG_DEBUG() << "Cannot parse vevent" << std::endl; g_slist_free_full(events, (GDestroyNotify) icalcomponent_free); return NULL; } icalcomponent_foreach_tzid(newEvent, EDSCalendarStorage::findTimeZonesCb, newEvent); icalcomponent_strip_errors(newEvent); if (ids.size() > i) icalcomponent_set_uid(newEvent, ids[i].c_str()); events = g_slist_append(events, newEvent); } } std::set<std::string>::iterator it; for(it = currentEventTimeZones.begin(); it != currentEventTimeZones.end(); ++it) { icaltimezone* tz = icaltimezone_get_builtin_timezone((*it).c_str()); if (tz) { timezones.push_back(tz); } } return events; }