summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@novell.com>2005-04-08 15:41:21 +0000
committerRodrigo Moya <rodrigo@src.gnome.org>2005-04-08 15:41:21 +0000
commit46ee952f315060306935e22440b9e7b6f480871a (patch)
tree33463c68ae4a11756854357e6a234a0a6f6cf33d
parent992d8b29e162a7b1afa38414a5bde863526347bd (diff)
downloadevolution-data-server-46ee952f315060306935e22440b9e7b6f480871a.tar.gz
Fixes #70035
2005-04-08 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.
-rw-r--r--calendar/ChangeLog10
-rw-r--r--calendar/backends/http/e-cal-backend-http.c2
-rw-r--r--calendar/libecal/e-cal-util.c67
3 files changed, 78 insertions, 1 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 8e5cb472e..f681f7362 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,13 @@
+2005-04-08 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.
+
2004-04-06 Rodrigo Moya <rodrigo@novell.com>
* libecal/e-cal.c (e_cal_open_async): check load state and if in
diff --git a/calendar/backends/http/e-cal-backend-http.c b/calendar/backends/http/e-cal-backend-http.c
index 07b0f265b..99b5a5f90 100644
--- a/calendar/backends/http/e-cal-backend-http.c
+++ b/calendar/backends/http/e-cal-backend-http.c
@@ -256,7 +256,7 @@ retrieval_done (SoupMessage *msg, ECalBackendHttp *cbhttp)
/* 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) {
diff --git a/calendar/libecal/e-cal-util.c b/calendar/libecal/e-cal-util.c
index b253f4c9c..9065576ee 100644
--- a/calendar/libecal/e-cal-util.c
+++ b/calendar/libecal/e-cal-util.c
@@ -117,6 +117,73 @@ e_cal_util_new_component (icalcomponent_kind kind)
}
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);