GNOKII_API int gn_ical2todo(FILE *f, gn_todo *ctodo, int id) { #ifdef HAVE_LIBICAL icalparser *parser = NULL; icalcomponent *comp = NULL; gn_error error; parser = icalparser_new(); if (!parser) { return GN_ERR_FAILED; } icalparser_set_gen_data(parser, f); comp = icalparser_parse(parser, ical_fgets); if (!comp) { icalparser_free(parser); return GN_ERR_FAILED; } error = gn_ical2todo_real(comp, ctodo, id); icalcomponent_free(comp); icalparser_free(parser); return error; #else return GN_ERR_NOTIMPLEMENTED; #endif /* HAVE_LIBICAL */ }
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; }
/* read a vcalendar event given by id from file f and store the data in calnote */ GNOKII_API gn_error gn_ical2calnote(FILE *f, gn_calnote *calnote, int id) { #ifdef HAVE_LIBICAL icalparser *parser = NULL; icalcomponent *comp = NULL; gn_error retval; parser = icalparser_new(); if (!parser) { return GN_ERR_FAILED; } icalparser_set_gen_data(parser, f); comp = icalparser_parse(parser, ical_fgets); if (!comp) { icalparser_free(parser); return GN_ERR_FAILED; } retval = gn_ical2calnote_real(comp, calnote, id); icalcomponent_free(comp); icalparser_free(parser); return retval; #else return GN_ERR_NOTIMPLEMENTED; #endif /* HAVE_LIBICAL */ }
icalcomponent* icalparser_parse_string(const char* str) { icalcomponent *c; struct slg_data d; icalparser *p; icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR); d.pos = 0; d.str = str; p = icalparser_new(); icalparser_set_gen_data(p,&d); icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL); c = icalparser_parse(p,icalparser_string_line_generator); icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es); icalparser_free(p); return c; }
/** Loads the builtin VTIMEZONE data for the given timezone. */ static void icaltimezone_load_builtin_timezone (icaltimezone *zone) { char *filename; unsigned int filename_len; FILE *fp; icalparser *parser; icalcomponent *comp, *subcomp; /* If the location isn't set, it isn't a builtin timezone. */ if (!zone->location || !zone->location[0]) return; filename_len = strlen (get_zone_directory()) + strlen (zone->location) + 6; filename = (char*) malloc (filename_len); if (!filename) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return; } snprintf (filename, filename_len, "%s/%s.ics", get_zone_directory(), zone->location); fp = fopen (filename, "r"); free (filename); if (!fp) { icalerror_set_errno(ICAL_FILE_ERROR); return; } /* ##### B.# Sun, 11 Nov 2001 04:04:29 +1100 this is where the MALFORMEDDATA error is being set, after the call to 'icalparser_parse' fprintf(stderr, "** WARNING ** %s: %d %s\n", __FILE__, __LINE__, icalerror_strerror(icalerrno)); */ parser = icalparser_new (); icalparser_set_gen_data (parser, fp); comp = icalparser_parse (parser, icaltimezone_load_get_line_fn); icalparser_free (parser); fclose (fp); /* Find the VTIMEZONE component inside the VCALENDAR. There should be 1. */ subcomp = icalcomponent_get_first_component (comp, ICAL_VTIMEZONE_COMPONENT); if (!subcomp) { icalerror_set_errno(ICAL_PARSE_ERROR); return; } icaltimezone_get_vtimezone_properties (zone, subcomp); icalcomponent_remove_component(comp,subcomp); icalcomponent_free(comp); }
/** * e_cal_util_parse_ics_file: * @filename: Name of the file to be parsed. * * Parses the given file, and, if it contains a valid iCalendar object, * parse it and return a new #icalcomponent. * * Returns: a newly created #icalcomponent or NULL if the file doesn't * contain a valid iCalendar object. */ icalcomponent * e_cal_util_parse_ics_file (const gchar *filename) { icalparser *parser; icalcomponent *icalcomp; FILE *file; file = g_fopen (filename, "rb"); if (!file) return NULL; parser = icalparser_new (); icalparser_set_gen_data (parser, file); icalcomp = icalparser_parse (parser, get_line_fn); icalparser_free (parser); fclose (file); return icalcomp; }
gint ics_parse_file (struct ics_file *file_entry, gchar *name, gchar *filename, gboolean desc_flag, gboolean count_only, GUI *appGUI) { FILE *ics_stream; icalparser *ics_parser; icalcomponent *ics_component; icalcomponent *h, *l; icalproperty *p, *r; struct icaltimetype tt; struct ics_entry *item; gint n = 0; ics_parser = icalparser_new (); g_return_val_if_fail (ics_parser != NULL, n); ics_stream = fopen (filename, "r"); if (ics_stream == NULL) { icalparser_free (ics_parser); return n; } icalparser_set_gen_data (ics_parser, ics_stream); ics_component = icalparser_parse (ics_parser, ics_read_stream); if (ics_component == NULL) { fclose (ics_stream); icalparser_free (ics_parser); return n; } /* FIXME */ if (icalcomponent_get_first_component (ics_component, ICAL_VEVENT_COMPONENT) != NULL) { for (h = icalcomponent_get_first_component (ics_component, ICAL_VEVENT_COMPONENT); h; h = icalcomponent_get_next_component (ics_component, ICAL_VEVENT_COMPONENT)) { p = icalcomponent_get_first_property (h, ICAL_DTSTART_PROPERTY); tt = icaltime_from_string (icalproperty_get_value_as_string (p)); p = icalcomponent_get_first_property (h, ICAL_SUMMARY_PROPERTY); if (p != NULL && count_only == FALSE) { r = icalcomponent_get_first_property (h, ICAL_DESCRIPTION_PROPERTY); item = g_malloc (sizeof (struct ics_entry)); if (item != NULL) { item->date.day = tt.day; item->date.month = tt.month; item->date.year = tt.year; item->summary = g_strdup (icalproperty_get_value_as_string (p)); if (r != NULL) { item->description = g_strdup (icalproperty_get_value_as_string (r)); } else { item->description = NULL; } file_entry->entries_list = g_slist_append (file_entry->entries_list, item); } } n++; } } else if (icalcomponent_get_first_component (ics_component, ICAL_VCALENDAR_COMPONENT) != NULL) { for (l = icalcomponent_get_first_component (ics_component, ICAL_VCALENDAR_COMPONENT); l; l = icalcomponent_get_next_component (ics_component, ICAL_VCALENDAR_COMPONENT)) { h = icalcomponent_get_first_component (l, ICAL_VEVENT_COMPONENT); p = icalcomponent_get_first_property (h, ICAL_DTSTART_PROPERTY); tt = icaltime_from_string (icalproperty_get_value_as_string (p)); p = icalcomponent_get_first_property (h, ICAL_SUMMARY_PROPERTY); if (p != NULL && count_only == FALSE) { r = icalcomponent_get_first_property (h, ICAL_DESCRIPTION_PROPERTY); item = g_malloc (sizeof (struct ics_entry)); if (item != NULL) { item->date.day = tt.day; item->date.month = tt.month; item->date.year = tt.year; item->summary = g_strdup (icalproperty_get_value_as_string(p)); if (r != NULL) { item->description = g_strdup (icalproperty_get_value_as_string (r)); } else { item->description = NULL; } file_entry->entries_list = g_slist_append (file_entry->entries_list, item); } } n++; } } icalcomponent_free (ics_component); fclose (ics_stream); icalparser_free (ics_parser); return n; }