diff options
-rw-r--r-- | calendar/ChangeLog | 15 | ||||
-rw-r--r-- | calendar/cal-util/cal-util.c | 27 | ||||
-rw-r--r-- | calendar/cal-util/cal-util.h | 2 | ||||
-rw-r--r-- | calendar/cal-util/test-recur.c | 42 | ||||
-rw-r--r-- | calendar/gui/comp-editor-factory.c | 4 | ||||
-rw-r--r-- | calendar/pcs/cal-backend-file.c | 49 |
6 files changed, 54 insertions, 85 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 7f18449320..4d767bf9ec 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,18 @@ +2003-03-25 Dan Winship <danw@ximian.com> + + * cal-util/cal-util.c (cal_util_parse_ics_file): Utility wrapper + around icalparser. + + * cal-util/test-recur.c (main): Use it + + * pcs/cal-backend-file.c (open_cal): Likewise + + * gui/comp-editor-factory.c (open_client): Add the OpenClient to + the hash before calling cal_client_open_calendar, since in some + failure cases, that will call cal_opened_cb (which will free the + oc) with a failure immediately, causing a crash if we then try to + deref it. + 2003-03-21 JP Rosevear <jpr@ximian.com> Fixes #32248 diff --git a/calendar/cal-util/cal-util.c b/calendar/cal-util/cal-util.c index 040e322cce..ad495bca77 100644 --- a/calendar/cal-util/cal-util.c +++ b/calendar/cal-util/cal-util.c @@ -102,6 +102,33 @@ cal_util_new_top_level (void) return icalcomp; } +static char * +get_line_fn (char *buf, size_t size, void *file) +{ + return fgets (buf, size, file); +} + +icalcomponent * +cal_util_parse_ics_file (const char *filename) +{ + icalparser *parser; + icalcomponent *icalcomp; + FILE *file; + + file = fopen (filename, "r"); + 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; +} + /* Computes the range of time in which recurrences should be generated for a * component in order to compute alarm trigger times. */ diff --git a/calendar/cal-util/cal-util.h b/calendar/cal-util/cal-util.h index bf43493f82..7b4f6c051e 100644 --- a/calendar/cal-util/cal-util.h +++ b/calendar/cal-util/cal-util.h @@ -71,6 +71,8 @@ void cal_obj_uid_list_free (GList *list); icalcomponent *cal_util_new_top_level (void); +icalcomponent *cal_util_parse_ics_file (const char *filename); + CalComponentAlarms *cal_util_generate_alarms_for_comp (CalComponent *comp, time_t start, time_t end, diff --git a/calendar/cal-util/test-recur.c b/calendar/cal-util/test-recur.c index 5078a1db94..03f19b52bd 100644 --- a/calendar/cal-util/test-recur.c +++ b/calendar/cal-util/test-recur.c @@ -37,6 +37,7 @@ #include <string.h> #include <gtk/gtkmain.h> #include <cal-util/cal-recur.h> +#include <cal-util/cal-util.h> /* Since events can recur infinitely, we set a limit to the number of @@ -44,10 +45,6 @@ #define MAX_OCCURRENCES 1000 static void usage (void); -static icalcomponent* scan_ics_file (char *filename); -static char* get_line (char *s, - size_t size, - void *data); static void generate_occurrences (icalcomponent *comp); static gboolean occurrence_cb (CalComponent *comp, time_t instance_start, @@ -69,7 +66,7 @@ main (int argc, filename = argv[1]; - icalcomp = scan_ics_file (filename); + icalcomp = cal_util_parse_ics_file (filename); if (icalcomp) generate_occurrences (icalcomp); @@ -85,41 +82,6 @@ usage (void) } -static icalcomponent* -scan_ics_file (char *filename) -{ - FILE *fp; - icalcomponent *icalcomp; - icalparser *parser; - - g_print ("Opening file: %s\n", filename); - fp = fopen (filename, "r"); - - if (!fp) { - g_print ("Can't open file: %s\n", filename); - return NULL; - } - - parser = icalparser_new (); - icalparser_set_gen_data (parser, fp); - - icalcomp = icalparser_parse (parser, get_line); - icalparser_free (parser); - - return icalcomp; -} - - -/* Callback used from icalparser_parse() */ -static char * -get_line (char *s, - size_t size, - void *data) -{ - return fgets (s, size, (FILE*) data); -} - - /* This resolves any TZIDs in the components. The VTIMEZONEs must be in the file we are reading. */ static icaltimezone* diff --git a/calendar/gui/comp-editor-factory.c b/calendar/gui/comp-editor-factory.c index 404b0ab5a6..6c40a0d644 100644 --- a/calendar/gui/comp-editor-factory.c +++ b/calendar/gui/comp-editor-factory.c @@ -514,6 +514,8 @@ open_client (CompEditorFactory *factory, const char *uristr) g_signal_connect (oc->client, "cal_opened", G_CALLBACK (cal_opened_cb), oc); + g_hash_table_insert (priv->uri_client_hash, oc->uri, oc); + if (!cal_client_open_calendar (oc->client, uristr, FALSE)) { g_free (oc->uri); g_object_unref (oc->client); @@ -522,8 +524,6 @@ open_client (CompEditorFactory *factory, const char *uristr) return NULL; } - g_hash_table_insert (priv->uri_client_hash, oc->uri, oc); - return oc; } diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c index 7ab6506aa9..d11df6d076 100644 --- a/calendar/pcs/cal-backend-file.c +++ b/calendar/pcs/cal-backend-file.c @@ -22,6 +22,7 @@ #include <config.h> #include <string.h> +#include <unistd.h> #include <bonobo/bonobo-exception.h> #include <bonobo/bonobo-moniker-util.h> #include <libgnome/gnome-i18n.h> @@ -679,53 +680,19 @@ scan_vcalendar (CalBackendFile *cbfile) } } -/* Callback used from icalparser_parse() */ -static char * -get_line_fn (char *s, size_t size, void *data) -{ - FILE *file; - - file = data; - return fgets (s, size, file); -} - -/* Parses an open iCalendar file and returns a toplevel component with the contents */ -static icalcomponent * -parse_file (FILE *file) -{ - icalparser *parser; - icalcomponent *icalcomp; - - parser = icalparser_new (); - icalparser_set_gen_data (parser, file); - - icalcomp = icalparser_parse (parser, get_line_fn); - icalparser_free (parser); - - return icalcomp; -} - /* Parses an open iCalendar file and loads it into the backend */ static CalBackendOpenStatus -open_cal (CalBackendFile *cbfile, const char *uristr, FILE *file) +open_cal (CalBackendFile *cbfile, const char *uristr) { CalBackendFilePrivate *priv; icalcomponent *icalcomp; priv = cbfile->priv; - icalcomp = parse_file (file); - - if (fclose (file) != 0) { - if (icalcomp) - icalcomponent_free (icalcomp); - - return CAL_BACKEND_OPEN_ERROR; - } - + icalcomp = cal_util_parse_ics_file (uristr); if (!icalcomp) return CAL_BACKEND_OPEN_ERROR; - + /* FIXME: should we try to demangle XROOT components and * individual components as well? */ @@ -771,7 +738,6 @@ cal_backend_file_open (CalBackend *backend, const char *uristr, gboolean only_if { CalBackendFile *cbfile; CalBackendFilePrivate *priv; - FILE *file; char *str_uri; GnomeVFSURI *uri; CalBackendOpenStatus status; @@ -806,11 +772,8 @@ cal_backend_file_open (CalBackend *backend, const char *uristr, gboolean only_if return CAL_BACKEND_OPEN_ERROR; } - /* Load! */ - file = fopen (str_uri, "r"); - - if (file) - status = open_cal (cbfile, str_uri, file); + if (access (str_uri, R_OK) == 0) + status = open_cal (cbfile, str_uri); else { if (only_if_exists) status = CAL_BACKEND_OPEN_NOT_FOUND; |