20#include "icalerror_p.h"
35static int compare_span(
void *a,
void *b)
37 const struct icaltime_span *span_a = (
struct icaltime_span *)a;
38 const struct icaltime_span *span_b = (
struct icaltime_span *)b;
40 if (span_a->start == span_b->start) {
42 }
else if (span_a->start < span_b->start) {
60static void icalspanlist_new_callback(icalcomponent *comp,
const struct icaltime_span *span,
void *data)
63 icalspanlist *sl = (icalspanlist *)data;
67 if (span->is_busy == 0) {
71 if ((s = (icaltime_span *)malloc(
sizeof(icaltime_span))) == 0) {
78 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)s);
83 struct icaltime_span range;
87 struct icaltime_span *freetime;
89 if ((sl = (
struct icalspanlist_impl *)malloc(
sizeof(
struct icalspanlist_impl))) == 0) {
94 sl->spans = icalpvl_newlist();
130 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
131 const struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
137 if ((freetime = (
struct icaltime_span *)malloc(
sizeof(
struct icaltime_span))) == 0) {
143 if (range.start < s->start) {
144 freetime->start = range.start;
145 freetime->end = s->start;
147 freetime->is_busy = 0;
149 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)freetime);
154 range.start = s->end;
162 const struct icaltime_span *last_span;
164 last_span = (
struct icaltime_span *)icalpvl_data(icalpvl_tail(sl->spans));
166 if (last_span != 0) {
167 if ((freetime = (
struct icaltime_span *)malloc(
sizeof(
struct icaltime_span))) == 0) {
173 freetime->is_busy = 0;
174 freetime->start = last_span->end;
175 freetime->end = freetime->start;
176 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)freetime);
185 struct icaltime_span *span;
191 while ((span = icalpvl_pop(sl->spans)) != 0) {
195 icalpvl_free(sl->spans);
207 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
208 struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
210 printf(
"#%02d %d start: %s", ++i, s->is_busy, icalctime(&s->start));
211 printf(
" end : %s", icalctime(&s->end));
220 struct icaltime_span *s;
228 itr = icalpvl_head(sl->spans);
229 s = (
struct icaltime_span *)icalpvl_data(itr);
238 if (rangett < s->start) {
243 if (s->is_busy == 1) {
254 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
255 s = (
struct icaltime_span *)icalpvl_data(itr);
261 if (s->is_busy == 0 && s->start >= rangett && (rangett < s->end || s->end == s->start)) {
262 if (rangett < s->start) {
283 icaltime_t spanduration_secs;
285 icaltime_t matrix_slots;
286 icaltime_t sl_start, sl_end;
288 icalerror_check_arg_rz((spanlist != 0),
"spanlist");
308 spanduration_secs = sl_end - sl_start;
311 matrix_slots = spanduration_secs / delta_t + 1;
313 matrix = (
int *)malloc(
sizeof(
int) * (
size_t)matrix_slots);
314 if (matrix == NULL) {
318 memset(matrix, 0,
sizeof(
int) * (
size_t)matrix_slots);
319 matrix[matrix_slots - 1] = -1;
323 for (itr = icalpvl_head(spanlist->spans); itr != 0; itr = icalpvl_next(itr)) {
324 const struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
326 if (s && s->is_busy == 1) {
327 icaltime_t offset_start = s->start / delta_t - sl_start / delta_t;
328 icaltime_t offset_end = (s->end - 1) / delta_t - sl_start / delta_t + 1;
331 if (offset_end >= matrix_slots) {
332 offset_end = matrix_slots - 1;
335 for (i = offset_start; i < offset_end; i++) {
344 const char *organizer,
const char *attendee)
371 for (itr = icalpvl_head(sl->spans); itr != 0; itr = icalpvl_next(itr)) {
372 struct icaltime_span *s = (
struct icaltime_span *)icalpvl_data(itr);
374 if (s && s->is_busy == 1) {
380 icalproperty *p = icalproperty_new_freebusy(period);
391 icalcomponent *inner;
395 icalerror_check_arg_rz((comp != NULL),
"comp");
402 if ((sl = (icalspanlist *)malloc(
sizeof(icalspanlist))) == 0) {
406 sl->spans = icalpvl_newlist();
412 icaltime_span *s = (icaltime_span *)malloc(
sizeof(icaltime_span));
413 icalparameter *param;
415 icalparameter_fbtype fbtype;
424 fbtype = (param) ? icalparameter_get_fbtype(param) : ICAL_FBTYPE_BUSY;
427 case ICAL_FBTYPE_FREE:
428 case ICAL_FBTYPE_NONE:
436 period = icalproperty_get_freebusy(prop);
440 icalpvl_insert_ordered(sl->spans, compare_span, (
void *)s);
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)
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_from_timet_with_zone(const icaltime_t tm, const bool is_date, const icaltimezone *zone)
Constructor.
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