aboutsummaryrefslogtreecommitdiffstats
path: root/src/ical.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix out of bounds memory access (off by one)Max Kunzelmann2023-12-141-1/+1
| | | | | | | | | | | | If fgets reads a line that only contains a `\n`, then the pointer `eol` will point to the first byte in that buffer. The subsequent dereference of `*(eol -1 )` will access the byte before that buffer. This fix makes sure that that length of the current line read by fgets is at least 2 bytes long. Signed-off-by: Max Kunzelmann <max@mxzero.net> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix segmentation fault when exporting ical fileBenedikt Wildenhain2023-11-051-1/+2
| | | | | | | | | | | | If a note file gets accidently deleted this leads to ical_export_note trying to execute fclose(NULL) which leads to a segmentation fault on current Debian GNU/Linux using libc6 (according to fclose's manpage, the behaviour is undefined in this case). The fix tests whether fopen returned a non-NULL-pointer before trying to close it. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright ranges for 2023Lukas Fleischer2023-04-111-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix segfault when importing iCal filesMarian Buschsieweke2023-04-111-0/+8
| | | | | | | | Previously, events / appointments without a description resulted in a segfault. This provides a trivial fix by adding an `<emtpy>` as description in this case. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Allow newlines in SUMMARY by replacing them with blanksLars Henriksen2022-03-191-6/+3
| | | | | | Addresses Github issue #414 (Android calendar allows them). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright ranges for 2022Lukas Fleischer2022-03-111-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Introduce macro DAYLars Henriksen2020-12-191-2/+2
| | | | | | | DAY(t) is midnight (the day) of time_t t. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix parsing of UNTIL in iCal importLars Henriksen2020-12-191-3/+10
| | | | | Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not remove an empty note file after edit sessionLars Henriksen2020-11-151-1/+3
| | | | | Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Avoid double free on iCal import errorsLukas Fleischer2020-11-071-2/+13
| | | | | | | Set pointers to NULL after calling free() to prevent double free on cleanup. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Make iCal event import independent of property orderingLars Henriksen2020-11-071-122/+135
| | | | | | | | | | Refactoring of ical.c: properties DTSTART, DTEND, DURATION, RRULE and EXDATE are saved and only processed after encountering END:VEVENT. Adresses Github issue #323, follow-up question. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Replace 'ical_rpt_t' with 'struct rpt'Lars Henriksen2020-10-071-113/+71
| | | | | | | | Refactoring and simplification only, no functional change. All error checking and logging done before call of ical_store_event/apoint(). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Extend icalendar exportLars Henriksen2020-08-261-82/+219
| | | | | | | | Export now covers advanced recurrence rules and properties imported to a note file. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update use of note file for importLars Henriksen2020-08-261-62/+8
| | | | | | | | | | | Removes the parts of commit 'Extend use of note file for ical import' that relate to STATUS. The STATUS property is (partly) supported for todos already. Corrects insertion of a separator: always insert it before imported properties (also when there is no description). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Extend import of recurrence rulesLars Henriksen2020-06-131-23/+190
| | | | | | | | Support has been implemented for recurrence rule parts BYMONTH, BYMONTHDAY and BYDAY. A new test has been added. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update import of basic recurrence rulesLars Henriksen2020-06-131-122/+187
| | | | | | | | | | | | | | | | | | | Conversion of COUNT to UNTIL was a simple calculation which assumed one repetiton per period (day, week, month or year); it does not take exception days and invalid dates into account. Solved by a new function which returns the n'th occurrence of a recurrence rule. In calcurse UNTIL is interpreted as a day (DATE), in RFC 5545 as a time of day (DATE-TIME). This has implications when a recurrence rule has an occurrence on the UNTIL day, see comment in ical.c An "Import:" note is added when a multi-day event is imported and turned into a calcurse all-day event. Icalendar quotes in comments have been updated to RFC 5545. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support import of time zones (RFC 5545)Lars Henriksen2020-06-131-33/+85
| | | | | | | | | The property parameter time zone identifier (TZID) is recognized in DTSTART, DTEND and EXDATE and the DATE-TIME value converted to a local time. The time zone identifier is logged in the note file. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Take value data type of event start into account in iCal import/exportLars Henriksen2020-05-031-73/+159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The patch derives the item type (appointment or event) from the DTSTART value type. It is then used to perform an extended check of date/time values and reject non-conformant import files (like those reported in Github issues #81, (calcurse) events. The patch includes parsing and code corrections and minor refactoring. Background: Ical events are of two types, in calcurse called appointments and events. RFC 5545 has no distinguishing names for them, but describes them in section 3.6.1. The event type is derived from the value type of the DTSTART property. The value type may be either DATE-TIME (appointment) or DATE (event). If not specified by a VALUE property parameter in DTSTART, the default value type is DATE-TIME. The value type must be set explicitly to DATE to get an event. Other properties and rrule parts must agree with the DTSTART value type (DTEND, DURATION, EXDATE and UNTIL). Previously the type of an imported event was derived from the format of the DTSTART value. The DTSTART value type was not taken into account when importing, and not specified for recurring events when exporting (commit 0114289 solved it for events, see GitHub PR #97). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Recurrence rule extensionsLars Henriksen2020-04-281-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Terms and concepts are from RFC 5545 (the iCalendar specification). Overall design -------------- Calcurse is extended with full support for BYMONTH, BYDAY and BYMONTHDAY recurrence rule (rrule) parts. The three rule parts are lists of, respectively, months, weekdays and monthdays. The lists are added to 'struct rpt' as linked lists of integers, and the data file format is extended accordingly (details below). Load and save of the lists follow the pattern of the existing list of exception dates, also in 'struct rpt'. The function recur_item_find_occurence() is split into a front-end and a back-end. The back-end, called find_occurrence(), is the original function extended with rrule reductions; the front-end retains the original name and performs rrule expansions. Front-end plus back-end are backwards compatible and require no changes in calling functions. There is no user interface in this patch. Data file extensions -------------------- The BYMONTH, BYDAY and BYMONTHDAY lists are added to that part of an item line which describes the recurrence rule (the "{...}" part). Each list is - like the list of exception days - a space-separated string of values identified by the initial character. Each list is optional and, if present, must follow the until date and precede the exception day list. The lists must appear in order BYMONTHDAY list, BYDAY list and BYMONTH list. The possible list values are - BYMONTH: m1, m2, ..., m12 - BYDAY: w0, w1, ..., w6, w7, w-7, w8, w-8, ..., w377, w-377 - BYMONTHDAY: d1, d2, ..., d31, d-1, d-2, ..., d-31 which are interpreted as (cf. RFC 5545) - BYMONTH: January, February, ..., December. - BYDAY: SU, MO, ..., SA, +1SU, -1SU, +1MO, -1MO, ..., +53SA, -53SA - BYMONTHDAY: the first, the second, ..., the 31st, the last, the last but one, ..., the last but 30 day of the month Examples: Thursday, TH, is w4; Saturday, SA, is w6. The seventh Thursday, +7TH, is w53 (7 * 7 + 4 = 53); the last but second Saturday, -2SA, is w-20 (2 * 7 + 6 = 20); the last day of the month is d-1. Note that the values w-1, w-2, ..., w-6 are not used. A recurrent appointment with a BYDAY rule part: 06/23/2019 @ 12:00 -> 06/23/2019 @ 13:00 {1W w0 w6} |every week on Sunday and Saturday An event with a BYDAY and a BYMONTH rule part: 10/27/2019 [1] {1Y w-7 m10} every year on last Sunday in October An event with until date, a BYMONTH rule part and an exception day: 06/23/2019 [1] {1Y -> 08/31/2021 m5 m6 m7 !07/23/2020} every year on the 23rd in May, June and July for three years, starting on Sunday, 23 June 2019, but not on 23 July 2020. Recurrence set expansion and reduction --------------------------------------- In calcurse a recurrence rule is a quadruple (s, d, r, e) consisting of start, duration, repetition pattern and exception days and is implemented as: (time_t start, long dur, struct rpt *rpt, llist_t *exc) In RFC 5545 parlance, a recurrence rule defines a recurrence set consisting of all recurrence instances (occurrences) not earlier than start which match the rule pattern. With this concept in mind, recur_item_find_occurremce() may be thought of as a membership function for a recurrence set. The call recur_item_find_occurrence(s, d, r, e, day, occurrence) returns true if day belongs to the recurrence set of (s, d, r, e); if so occurrence points to the recurrence instance (the set member). For a recurrence rule with only the basic DAYLY, WEEKLY, MONTHLY or YEARLY type and frequency the recurrence set consists of periodically repeated instances. The BYxxx rule parts modify the recurrence set by reducing or expanding it as specified by RFC 5545. Expansion is implemented in the front-end by modifications of start and/or frequency of the rule (s, d, r, e), often several times, in such a way that the desired recurrence instances are included in the recurrence set. This is possible because the front-end as the very first thing checks for early days (day < s). When day is known not to be early, start (s) can safely be moved backwards. Likewise, if frequency must be changed, the front-end checks whether the frequency repetition applies to the week, month or year of day. Reduction is easier and is performed in the back-end along with the existing validity checks. It consists in checking whether month, day of month or weekday of a found occurrence is on the appropriate list. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Refactor function calls: recurrence parameters as a single argumentLars Henriksen2020-04-281-20/+26
| | | | | | | | | | | | | | | | | | | | | The recurrence parameters are type, frequency, until date and exception list (in RFC 5545 parlance FREQ, INTERVAL, UNTIL and EXDATE's). When these are passed in a function call, the argument list becomes long and not very readable. When support for extended recurrence rules is implemented, the number of recurrence parameters increases, and function signatures must be amended. Solution: The "struct rpt" is extended with the exception list; any future recurrence parameters are added here. A pointer to this structure replaces the recurrence parameters in function calls. Note: Each recurrent event and appoinment instance has (a pointer to) a "struct rpt" and in addition an exception list. The latter is retained to avoid the derived changes, and the exception list in the structure is initialized to an empty list when the recurrent instance is created. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Extend use of note file for iCal importLars Henriksen2020-04-281-61/+280
| | | | | | | | | | iCal import to an item note file is extended from DESCRIPTION to LOCATION, COMMENT and STATUS for both events and todos. Addresses GitHub issue #9. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Accept empty DESCRIPTION in ical importLars Henriksen2020-04-281-5/+0
| | | | | | | Adresses GitHub issue #274. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix formatting of DTSTART for recurrent eventsJerem-K2020-04-281-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix decoding of escaped characters in imported textLars Henriksen2020-03-221-11/+20
| | | | | | | | Stick strictly to RFC 5545, 3.3.11, Text, for SUMMARY and DESCRIPTION. Adresses Github issue #271. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix ical import loggingLars Henriksen2020-03-221-29/+59
| | | | | | | | | | | | | | | | | | | | | | | | The following issues have been fixed: Functions ical_read_event() and ical_read__todo() do not check the return value of functions which may fail, in which case an item is not skipped even though a problem may have been logged by the called function. Function ical_read_note() fails on empty DESCRIPTION, but does not log it. Function ical_read_exdate() may log a failure, but cannot fail itself. Function ical_read_summary() can fail, but not log a failure. Function ical_read_todo() do not skip a todo with an invalid priority. Additionally: A safety check has been added to ical_get_value(), and log messages resulting from failures have been made uniform. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Improve ical import loggingLars Henriksen2020-03-221-15/+22
| | | | | | | | | The log file is not deleted if items were skipped (adresses Github issue #269). The log file includes the import file name and time. The import line numbers have been corrected (and tests amended). Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Escape necessary characters in SUMMARY on exportKelvin Jackson2020-03-221-5/+26
| | | | | | | Escape semicolons, commas, and backslashes when exporting a calendar item to iCal format. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2020-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use ICALDATETIMEFMT for EXDATEHenrik Grimler2019-04-131-2/+2
| | | | | | Some servers (Radicale) cannot handle YYYYMM. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix priority parsing in iCal importsdott2018-11-241-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* ical: use the VALUE parameter in DTSTARTQuentin Hibon2018-05-101-1/+1
| | | | | | | | | According to RFC5545 3.3 (Property Value Data Types): "If the value type of a property is one of the alternate valid types, then it MUST be explicitly specified with the "VALUE" parameter." Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Fix spelling of "frequency"Lars Henriksen2017-10-231-2/+2
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Do not read past NUL character in ical_get_value()Lukas Fleischer2017-02-081-2/+2
| | | | | | | Make sure we never read beyond the end of the buffer, even if the terminating quote of a quoted string is missing. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Gracefully parse iCal parameters with colonsLukas Fleischer2017-02-071-12/+24
| | | | | | | | | | | | According to RFC 5545, iCalendar content lines can have optional parameters, which can be quoted strings containing colons (":"). Make sure that such colons are not interpreted as delimiters marking the start of the value string. Also, add a test case that covers this corner case. Reported-by: HÃ¥kan Jerning <jerning@home.se> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2017-01-121-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support format strings when dumping imported itemsLukas Fleischer2016-02-111-47/+36
| | | | | | | | | | | | | | In commit 3eae7ce (Add --list-imported command line option, 2016-01-12), we added an option to print the hashes of imported items to stdout. Extend this command line option such that it dumps the items using the specified formatting strings. With the new behavior it is, for example, easier to check items for import errors. Also, rename the option from --list-imported to --dump-imported (it is not part of any official release yet so we do not need to care about backwards compatibility). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Update copyright rangesLukas Fleischer2016-01-301-1/+1
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Support todo items with an undefined priorityLukas Fleischer2016-01-181-9/+4
| | | | | | | In addition to priorities 1-9, support todo items without any specific priority, internally represented by priority 0. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Use a separate field for the completed statusLukas Fleischer2016-01-181-11/+7
| | | | | | | Add a new field that indicates whether a todo item is completed or not instead of encoding completed todo items by negative priorities. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Export item UIDs upon requestLukas Fleischer2016-01-151-16/+51
| | | | | | | Add a new --export-uid command line option that adds each item's hash to the UID property when exporting. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* ical: Handle items without an end date gracefullyLukas Fleischer2016-01-131-16/+17
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* ical: Refactor item date/time parserLukas Fleischer2016-01-131-10/+8
| | | | Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Reimplement ical_unformat_line() using dynamic stringsLukas Fleischer2016-01-131-22/+10
| | | | | | | Use the new dynamic string utility functions instead of relying on a fixed-size buffer. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* ical: Export completed todo items properlyLukas Fleischer2016-01-131-3/+6
| | | | | | | Do not skip completed todo items when exporting to an iCal file. Instead, mark them as "STATUS:COMPLETED". Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* ical: Honor completed status of todo itemsLukas Fleischer2016-01-131-0/+5
| | | | | | | When importing todo items from an iCal file, mark completed items as completed. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* Add --list-imported command line optionLukas Fleischer2016-01-131-20/+54
| | | | | | | When this option is used together with -i/--import, the object identifiers of imported objects are printed to stdout. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
* ical.c: Small refactoringLukas Fleischer2015-02-251-15/+10
| | | | Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Use time_t instead of long in several placesLukas Fleischer2015-02-241-18/+12
| | | | | | | Start converting some variables and return values to store times from long to time_t. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* ical.c: Reduce nesting depthLukas Fleischer2015-02-241-318/+257
| | | | | | Refactor the iCal parser to reduce nesting depth. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
* Introduce starts_with() and starts_with_ci()Lukas Fleischer2015-02-241-84/+31
| | | | | | | | Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>