20#include "icalerror_p.h"
36static int compare_span(
void *a,
void *b)
38 const struct icaltime_span *span_a = (
struct icaltime_span *)a;
39 const struct icaltime_span *span_b = (
struct icaltime_span *)b;
41 if (span_a->start == span_b->start) {
43 }
else if (span_a->start < span_b->start) {
61static void icalspanlist_new_callback(icalcomponent *comp,
const struct icaltime_span *span,
void *data)
64 icalspanlist *sl = (icalspanlist *)data;
68 if (span->is_busy == 0) {
72 if ((s = (icaltime_span *)malloc(
sizeof(icaltime_span))) == 0) {
79 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)s);
84 struct icaltime_span range;
88 struct icaltime_span *freetime;
90 if ((sl = (
struct icalspanlist_impl *)malloc(
sizeof(
struct icalspanlist_impl))) == 0) {
95 sl->spans = icalpvl_newlist();
131 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
132 const struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
138 if ((freetime = (
struct icaltime_span *)malloc(
sizeof(
struct icaltime_span))) == 0) {
144 if (range.start < s->start) {
145 freetime->start = range.start;
146 freetime->end = s->start;
148 freetime->is_busy = 0;
150 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)freetime);
155 range.start = s->end;
163 const struct icaltime_span *last_span;
165 last_span = (
struct icaltime_span *)icalpvl_data(icalpvl_tail(sl->spans));
167 if (last_span != 0) {
168 if ((freetime = (
struct icaltime_span *)malloc(
sizeof(
struct icaltime_span))) == 0) {
174 freetime->is_busy = 0;
175 freetime->start = last_span->end;
176 freetime->end = freetime->start;
177 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)freetime);
186 struct icaltime_span *span;
192 while ((span = icalpvl_pop(sl->spans)) != 0) {
196 icalpvl_free(sl->spans);
208 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
209 struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
211 printf(
"#%02d %d start: %s", ++i, s->is_busy, icalctime(&s->start));
212 printf(
" end : %s", icalctime(&s->end));
221 struct icaltime_span *s;
229 itr = icalpvl_head(sl->spans);
230 s = (
struct icaltime_span *)icalpvl_data(itr);
239 if (rangett < s->start) {
244 if (s->is_busy == 1) {
255 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
256 s = (
struct icaltime_span *)icalpvl_data(itr);
262 if (s->is_busy == 0 && s->start >= rangett && (rangett < s->end || s->end == s->start)) {
263 if (rangett < s->start) {
284 icaltime_t spanduration_secs;
286 icaltime_t matrix_slots;
287 icaltime_t sl_start, sl_end;
289 icalerror_check_arg_rz((spanlist != 0),
"spanlist");
290 icalerror_check_arg_rz((delta_t >= 0),
"delta_t");
310 if (sl_end < sl_start) {
314 spanduration_secs = sl_end - sl_start;
317 matrix_slots = spanduration_secs / delta_t + 1;
318 if ((uint64_t)matrix_slots > SIZE_MAX /
sizeof(
int)) {
323 matrix = (
int *)malloc(
sizeof(
int) * (
size_t)matrix_slots);
324 if (matrix == NULL) {
328 memset(matrix, 0,
sizeof(
int) * (
size_t)matrix_slots);
329 matrix[matrix_slots - 1] = -1;
333 for (itr = icalpvl_head(spanlist->spans); itr != 0; itr = icalpvl_next(itr)) {
334 const struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
336 if (s && s->is_busy == 1) {
338 const icaltime_t span_start = s->start > sl_start ? s->start : sl_start;
339 const icaltime_t span_end = s->end < sl_end ? s->end : sl_end;
340 icaltime_t offset_start, offset_end, i;
342 if (span_end <= span_start) {
345 offset_start = (span_start - sl_start) / delta_t;
346 offset_end = (span_end - 1 - sl_start) / delta_t + 1;
348 for (i = offset_start; i < offset_end; i++) {
357 const char *organizer,
const char *attendee)
384 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
385 struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
387 if (s && s->is_busy == 1) {
404 icalcomponent *inner;
408 icalerror_check_arg_rz((comp != NULL),
"comp");
415 if ((sl = (icalspanlist *)malloc(
sizeof(icalspanlist))) == 0) {
419 sl->spans = icalpvl_newlist();
427 icaltime_span *s = (icaltime_span *)malloc(
sizeof(icaltime_span));
448 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)s);
struct icaltimetype icalcomponent_get_dtend(icalcomponent *comp)
struct icaltimetype icalcomponent_get_dtstart(icalcomponent *comp)
icalproperty * icalcomponent_get_first_property(icalcomponent *c, icalproperty_kind kind)
icalcomponent * icalcomponent_new_vfreebusy(void)
icalcomponent * icalcomponent_get_inner(icalcomponent *comp)
void icalcomponent_add_property(icalcomponent *component, icalproperty *property)
icalcomponent_kind icalcomponent_isa(const icalcomponent *component)
void icalcomponent_foreach_recurrence(icalcomponent *comp, struct icaltimetype start, struct icaltimetype end, void(*callback)(icalcomponent *comp, const struct icaltime_span *span, void *data), void *callback_data)
icalproperty * icalcomponent_get_next_property(icalcomponent *c, icalproperty_kind kind)
icalparameter_fbtype icalparameter_get_fbtype(const icalparameter *value)
icalparameter * icalparameter_new_fbtype(icalparameter_fbtype v)
struct icalparameter_impl icalparameter
icalproperty * icalproperty_new_organizer(const char *v)
icalproperty * icalproperty_new_dtend(struct icaltimetype v)
icalproperty * icalproperty_new_dtstamp(struct icaltimetype v)
icalproperty * icalproperty_new_freebusy(struct icalperiodtype v)
struct icalperiodtype icalproperty_get_freebusy(const icalproperty *prop)
icalproperty * icalproperty_new_dtstart(struct icaltimetype v)
icalproperty * icalproperty_new_attendee(const char *v)
struct icaldurationtype icaldurationtype_null_duration(void)
Creates a duration with zero length.
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
icalparameter * icalproperty_get_first_parameter(icalproperty *p, icalparameter_kind kind)
void icalproperty_add_parameter(icalproperty *p, icalparameter *parameter)
icalcomponent * icalset_get_first_component(icalset *set)
icalcomponent * icalset_get_next_component(icalset *set)
void icalspanlist_dump(icalspanlist *sl)
icalspanlist * icalspanlist_from_vfreebusy(icalcomponent *comp)
int * icalspanlist_as_freebusy_matrix(icalspanlist *spanlist, int delta_t)
void icalspanlist_free(icalspanlist *sl)
icalspanlist * icalspanlist_new(icalset *set, struct icaltimetype start, struct icaltimetype end)
icalcomponent * icalspanlist_as_vfreebusy(icalspanlist *sl, const char *organizer, const char *attendee)
struct icalperiodtype icalspanlist_next_free_time(icalspanlist *sl, struct icaltimetype t)
Code that supports collections of free/busy spans of time.
struct icaltimetype icaltime_from_timet_with_zone(const icaltime_t tm, const bool is_date, const icaltimezone *zone)
Constructor.
bool icaltime_is_null_time(const struct icaltimetype t)
icaltime_t icaltime_as_timet_with_zone(const struct icaltimetype tt, const icaltimezone *zone)
icaltime_t icaltime_as_timet(const struct icaltimetype tt)
struct icaltimetype icaltime_null_time(void)
icaltimezone * icaltimezone_get_utc_timezone(void)
Timezone handling routines.
struct _icaltimezone icaltimezone
struct icaldurationtype duration
struct icaltimetype start