Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
* Do not longer expect ICS file to be well-formed (FIX #614244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Gräfe committed Sep 19, 2010
1 parent e3ceb7a commit 810c5c0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/icsexport.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ void icsexport(const gchar *path) {
/* key is part of ICSBirthday so it will not be freed two times */
birthdays = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, ics_birthday_destroy);

/* TODO: this hopes the .ics to be well-formed */
if((fd = fopen(path, "r")) != NULL) {
birthday = NULL;
while(fgets(line, sizeof(line), fd)) {
if(purple_utf8_strcasecmp(line, "END:VEVENT\n") == 0) {
if(birthday && purple_utf8_strcasecmp(line, "END:VEVENT\n") == 0) {
if(birthday->summary && birthday->description && birthday->date && birthday->uid) {
g_hash_table_insert(birthdays, birthday->uid, birthday);
} else {
Expand All @@ -130,25 +130,33 @@ void icsexport(const gchar *path) {
if(birthday->uid) g_free(birthday->uid);
g_free(birthday);
}
birthday = NULL;
}
if(purple_utf8_strcasecmp(line, "BEGIN:VEVENT\n") == 0) {
if(birthday) {
if(birthday->summary) g_free(birthday->summary);
if(birthday->description) g_free(birthday->description);
if(birthday->date) g_free(birthday->date);
if(birthday->uid) g_free(birthday->uid);
g_free(birthday);
}
birthday = g_malloc(sizeof(ICSBirthday));
birthday->summary = NULL;
birthday->description = NULL;
birthday->date = NULL;
birthday->uid = NULL;
}

if(sscanf(line, "DTSTART;VALUE=DATE:%256[^\n]\n", buf)==1) {
if(birthday && sscanf(line, "DTSTART;VALUE=DATE:%256[^\n]\n", buf)==1) {
birthday->date = g_strdup(buf);
}
if(sscanf(line, "SUMMARY:%256[^\n]\n", buf)==1) {
if(birthday && sscanf(line, "SUMMARY:%256[^\n]\n", buf)==1) {
birthday->summary = g_strdup(buf);
}
if(sscanf(line, "DESCRIPTION:%256[^\n]\n", buf)==1) {
if(birthday && sscanf(line, "DESCRIPTION:%256[^\n]\n", buf)==1) {
birthday->description = g_strdup(buf);
}
if(sscanf(line, "UID:%256[^\n]\n", buf)==1) {
if(birthday && sscanf(line, "UID:%256[^\n]\n", buf)==1) {
birthday->uid = g_strdup(buf);
}
}
Expand Down

0 comments on commit 810c5c0

Please sign in to comment.