Re: [evolution-patches] patch for #70035 (calendar)



On Sun, 2005-04-03 at 12:37 +0200, Rodrigo Moya wrote:
> > Risky either way I suppose.  I see a couple of solutions:
> > 
> > 1) save this work for 2.2.3 and move it lower in the stack
> > 2) Use your current patch for 2.2.2 and fix it lower in 2.3
> > 
> I would opt for 2
> 
> > I think DnD/CCP might need to use the function as well.
> > 
> ok, attached patch adds that. Only sending the evo one, e-d-s is still
> the same as before.

attached updated e-d-s patch, which uses g_strstr_len to discard blank
lines at the beginning of the string to parse.
-- 
Rodrigo Moya <rodrigo novell com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.444
diff -u -p -r1.444 ChangeLog
--- ChangeLog	6 Apr 2005 18:17:37 -0000	1.444
+++ ChangeLog	6 Apr 2005 21:32:40 -0000
@@ -1,3 +1,13 @@
+2005-xx-xx  Rodrigo Moya <rodrigo novell com>
+
+	Fixes #70035
+
+	* libecal/e-cal-util.c (e_cal_util_parse_ics_string): new function that
+	supports strings with multiple VCALENDAR's.
+
+	* backends/http/e-cal-backend-http.c (retrieval_done): use the new
+	function instead of icalparser_parse_string.
+
 2005-04-06  Christian Kellner  <gicmo gnome org>
 	* libecal/e-cal.c (set_local_attachment_store): 
 	Add support for scalix provider. Also plug a 
Index: libecal/e-cal-util.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libecal/e-cal-util.c,v
retrieving revision 1.8
diff -u -p -r1.8 e-cal-util.c
--- libecal/e-cal-util.c	2 Feb 2005 18:44:32 -0000	1.8
+++ libecal/e-cal-util.c	6 Apr 2005 21:32:40 -0000
@@ -117,6 +117,73 @@ e_cal_util_new_component (icalcomponent_
 }
 
 static char *
+read_line (const char *string)
+{
+	char *line;
+	GString *line_str = NULL;
+
+	for (; *string; string++) {
+		if (!line_str)
+			line_str = g_string_new ("");
+
+		line_str = g_string_append_c (line_str, *string);
+		if (*string == '\n')
+			break;
+	}
+
+	line = line_str->str;
+	g_string_free (line_str, FALSE);
+
+	return line;
+}
+
+icalcomponent *
+e_cal_util_parse_ics_string (const char *string)
+{
+	char *s;
+	icalcomponent *icalcomp = NULL;
+
+	g_return_val_if_fail (string != NULL, NULL);
+
+	/* Split string into separated VCALENDAR's, if more than one */
+	if ((s = g_strstr_len (string, strlen (string), "BEGIN:VCALENDAR"))) {
+		GString *comp_str = NULL;
+
+		while (*s) {
+			char *line = read_line (s);
+			if (line) {
+				if (!comp_str)
+					comp_str = g_string_new (line);
+				else
+					comp_str = g_string_append (comp_str, line);
+
+				if (!strncmp (line, "END:VCALENDAR", 13)) {
+					icalcomponent *tmp;
+
+					tmp = icalparser_parse_string (comp_str->str);
+					if (tmp) {
+						if (icalcomp)
+							icalcomponent_merge_component (icalcomp, tmp);
+						else
+							icalcomp = tmp;
+					}
+
+					g_string_free (comp_str, TRUE);
+					comp_str = NULL;
+				}
+
+				s += strlen (line);
+
+				g_free (line);
+			}
+		}
+	} else
+		icalcomp = icalparser_parse_string (string);
+
+	return icalcomp;
+}
+
+static char *
 get_line_fn (char *buf, size_t size, void *file)
 {
 	return fgets (buf, size, file);
Index: backends/http/e-cal-backend-http.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/backends/http/e-cal-backend-http.c,v
retrieving revision 1.34
diff -u -p -r1.34 e-cal-backend-http.c
--- backends/http/e-cal-backend-http.c	6 Mar 2005 02:47:03 -0000	1.34
+++ backends/http/e-cal-backend-http.c	6 Apr 2005 21:32:40 -0000
@@ -256,7 +256,7 @@ retrieval_done (SoupMessage *msg, ECalBa
 	/* get the calendar from the response */
 	str = g_malloc0 (msg->response.length + 1);
 	strncpy (str, msg->response.body, msg->response.length);
-	icalcomp = icalparser_parse_string (str);
+	icalcomp = e_cal_util_parse_ics_string (str);
 	g_free (str);
 
 	if (!icalcomp) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]