]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_calendar: Fix build with libical 4.X
authormikhail_grishak <m.grishak@yandex.ru>
Tue, 26 May 2026 18:04:06 +0000 (21:04 +0300)
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Mon, 1 Jun 2026 16:41:12 +0000 (16:41 +0000)
libical 4.0 removed the icaltime_add() function in favor of icaltime_adjust(). Additionally, the callback signature for icalcomponent_foreach_recurrence() was updated to use a const pointer for the icaltime_span argument.

This commit adds conditional compilation using ICAL_MAJOR_VERSION to support both libical 3.X and the new 4.X API, ensuring backward compatibility.

Fixes: #1957
res/res_calendar_caldav.c
res/res_calendar_icalendar.c

index d531f98063934e5269f7fe7393dd1f0157bb2be2..d2cefa0f0cacf7bb4a329121bab58b05c020a806 100644 (file)
 #include "asterisk.h"
 
 #include <libical/ical.h>
+
+#if ICAL_MAJOR_VERSION >= 4
+#define ICAL_SPAN_CONST const
+#else
+#define ICAL_SPAN_CONST
+#endif
 #include <ne_session.h>
 #include <ne_uri.h>
 #include <ne_request.h>
@@ -349,7 +355,7 @@ static time_t icalfloat_to_timet(icaltimetype time)
  * span here, and instead will grab the start and end from the component, which will
  * allow us to test for floating times or dates.
  */
-static void caldav_add_event(icalcomponent *comp, struct icaltime_span *span, void *data)
+static void caldav_add_event(icalcomponent *comp, ICAL_SPAN_CONST struct icaltime_span *span, void *data)
 {
        struct caldav_pvt *pvt = data;
        struct ast_calendar_event *event;
@@ -464,7 +470,17 @@ static void caldav_add_event(icalcomponent *comp, struct icaltime_span *span, vo
        } else { /* Offset from either dtstart or dtend */
                /* XXX Technically you can check RELATED to see if the event fires from the END of the event
                 * But, I'm not sure I've ever seen anyone implement it in calendaring software, so I'm ignoring for now */
+#if ICAL_MAJOR_VERSION >= 4
+               tmp = start;
+               int sign = trigger.duration.is_neg ? -1 : 1;
+               icaltime_adjust(&tmp,
+                       sign * (trigger.duration.days + trigger.duration.weeks * 7),
+                       sign * trigger.duration.hours,
+                       sign * trigger.duration.minutes,
+                       sign * trigger.duration.seconds);
+#else
                tmp = icaltime_add(start, trigger.duration);
+#endif
                event->alarm = icaltime_as_timet_with_zone(tmp, icaltime_get_timezone(start));
        }
 
index 95790e5d0843d85c675683a2dfdb9b6a8cb6d8f4..0776a3bdd5fc86e8f384211d5d93a5f31707ac0e 100644 (file)
 #include "asterisk.h"
 
 #include <libical/ical.h>
+
+#if ICAL_MAJOR_VERSION >= 4
+#define ICAL_SPAN_CONST const
+#else
+#define ICAL_SPAN_CONST
+#endif
 #include <ne_session.h>
 #include <ne_uri.h>
 #include <ne_request.h>
@@ -191,7 +197,7 @@ static time_t icalfloat_to_timet(icaltimetype time)
  * allow us to test for floating times or dates.
  */
 
-static void icalendar_add_event(icalcomponent *comp, struct icaltime_span *span, void *data)
+static void icalendar_add_event(icalcomponent *comp, ICAL_SPAN_CONST struct icaltime_span *span, void *data)
 {
        struct icalendar_pvt *pvt = data;
        struct ast_calendar_event *event;
@@ -341,7 +347,17 @@ static void icalendar_add_event(icalcomponent *comp, struct icaltime_span *span,
        } else { /* Offset from either dtstart or dtend */
                /* XXX Technically you can check RELATED to see if the event fires from the END of the event
                 * But, I'm not sure I've ever seen anyone implement it in calendaring software, so I'm ignoring for now */
+#if ICAL_MAJOR_VERSION >= 4
+               tmp = start;
+               int sign = trigger.duration.is_neg ? -1 : 1;
+               icaltime_adjust(&tmp,
+                       sign * (trigger.duration.days + trigger.duration.weeks * 7),
+                       sign * trigger.duration.hours,
+                       sign * trigger.duration.minutes,
+                       sign * trigger.duration.seconds);
+#else
                tmp = icaltime_add(start, trigger.duration);
+#endif
                event->alarm = icaltime_as_timet_with_zone(tmp, icaltime_get_timezone(start));
        }