icalgauge *icalgauge_new_from_sql(char *sql, int expand) { struct icalgauge_impl *impl; int r; if ((impl = (struct icalgauge_impl *)malloc(sizeof(struct icalgauge_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } impl->select = pvl_newlist(); impl->from = pvl_newlist(); impl->where = pvl_newlist(); impl->expand = expand; icalss_yy_gauge = impl; input_buffer = input_buffer_p = sql; r = ssparse(); if (r == 0) { return impl; } else { icalgauge_free(impl); return NULL; } }
icalgauge* icalgauge_new_from_sql(char* sql, int expand) { struct icalgauge_impl *impl; yyscan_t yy_globals = NULL; int r; if ( ( impl = (struct icalgauge_impl*) malloc(sizeof(struct icalgauge_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } impl->select = pvl_newlist(); impl->from = pvl_newlist(); impl->where = pvl_newlist(); impl->expand = expand; sslex_init(&yy_globals); ssset_extra(impl, yy_globals); ss_scan_string(sql, yy_globals); r = ssparse(yy_globals); sslex_destroy(yy_globals); if (r == 0) { return impl; } else { icalgauge_free(impl); return NULL; } }
icalset* icaldirset_init(icalset* set, const char* dir, void* options_in) { icaldirset *dset = (icaldirset*)set; icaldirset_options *options = options_in; struct stat sbuf; icalerror_check_arg_rz( (dir!=0), "dir"); icalerror_check_arg_rz( (set!=0), "set"); if (stat(dir,&sbuf) != 0){ icalerror_set_errno(ICAL_FILE_ERROR); return 0; } /* dir is not the name of a direectory*/ if (!S_ISDIR(sbuf.st_mode)){ icalerror_set_errno(ICAL_USAGE_ERROR); return 0; } icaldirset_lock(dir); dset->dir = (char*)strdup(dir); dset->options = *options; dset->directory = pvl_newlist(); dset->directory_iterator = 0; dset->gauge = 0; dset->first_component = 0; dset->cluster = 0; return set; }
icalspanlist *icalspanlist_from_vfreebusy(icalcomponent *comp) { icalcomponent *inner; icalproperty *prop; icalspanlist *sl; icalerror_check_arg_rz((comp != NULL), "comp"); inner = icalcomponent_get_inner(comp); if (!inner) return NULL; if ((sl = (icalspanlist *) malloc(sizeof(icalspanlist))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } sl->spans = pvl_newlist(); /* cycle through each FREEBUSY property, adding to the spanlist */ for (prop = icalcomponent_get_first_property(inner, ICAL_FREEBUSY_PROPERTY); prop != NULL; prop = icalcomponent_get_next_property(inner, ICAL_FREEBUSY_PROPERTY)) { icaltime_span *s = (icaltime_span *) malloc(sizeof(icaltime_span)); icalparameter *param; struct icalperiodtype period; icalparameter_fbtype fbtype; if (s == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); icalspanlist_free(sl); return 0; } param = icalproperty_get_first_parameter(prop, ICAL_FBTYPE_PARAMETER); fbtype = (param) ? icalparameter_get_fbtype(param) : ICAL_FBTYPE_BUSY; switch (fbtype) { case ICAL_FBTYPE_FREE: case ICAL_FBTYPE_NONE: case ICAL_FBTYPE_X: s->is_busy = 1; break; default: s->is_busy = 0; } period = icalproperty_get_freebusy(prop); s->start = icaltime_as_timet_with_zone(period.start, icaltimezone_get_utc_timezone()); s->end = icaltime_as_timet_with_zone(period.end, icaltimezone_get_utc_timezone()); ; pvl_insert_ordered(sl->spans, compare_span, (void *)s); } /** @todo calculate start/end limits.. fill in holes? **/ return sl; }
static void icalset_init(void) { assert(icalset_kinds == 0); icalset_kinds = pvl_newlist(); pvl_push(icalset_kinds, &icalset_fileset_init); pvl_push(icalset_kinds, &icalset_dirset_init); #ifdef WITH_BDB4 pvl_push(icalset_kinds, &icalset_bdb4set_init); #endif #ifdef EXT_PATH icalset_loaddir(EXT_PATH); #endif icalset_init_done++; }
icalparser *icalparser_new(void) { struct icalparser_impl *impl = 0; if ((impl = (struct icalparser_impl *)malloc(sizeof(struct icalparser_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } impl->root_component = 0; impl->components = pvl_newlist(); impl->level = 0; impl->state = ICALPARSER_SUCCESS; impl->tmp_buf_size = TMP_BUF_SIZE; impl->buffer_full = 0; impl->continuation_line = 0; impl->lineno = 0; memset(impl->temp, 0, TMP_BUF_SIZE); return (icalparser *) impl; }
icalspanlist* icalspanlist_new(icalset *set, struct icaltimetype start, struct icaltimetype end) { struct icaltime_span range; pvl_elem itr; icalcomponent *c,*inner; icalcomponent_kind kind, inner_kind; icalspanlist *sl; struct icaltime_span *freetime; if ( ( sl = (struct icalspanlist_impl*) malloc(sizeof(struct icalspanlist_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } sl->spans = pvl_newlist(); sl->start = start; sl->end = end; range.start = icaltime_as_timet(start); range.end = icaltime_as_timet(end); /* Get a list of spans of busy time from the events in the set and order the spans based on the start time */ for(c = icalset_get_first_component(set); c != 0; c = icalset_get_next_component(set)){ kind = icalcomponent_isa(c); inner = icalcomponent_get_inner(c); if(!inner){ continue; } inner_kind = icalcomponent_isa(inner); if( kind != ICAL_VEVENT_COMPONENT && inner_kind != ICAL_VEVENT_COMPONENT){ continue; } icalerror_clear_errno(); icalcomponent_foreach_recurrence(c, start, end, icalspanlist_new_callback, (void*)sl); } /* Now Fill in the free time spans. loop through the spans. if the start of the range is not within the span, create a free entry that runs from the start of the range to the start of the span. */ for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); if ((freetime=(struct icaltime_span *) malloc(sizeof(struct icaltime_span))) == 0){ icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } if(range.start < s->start){ freetime->start = range.start; freetime->end = s->start; freetime->is_busy = 0; pvl_insert_ordered(sl->spans,compare_span,(void*)freetime); } else { free(freetime); } range.start = s->end; } /* If the end of the range is null, then assume that everything after the last item in the calendar is open and add a span that indicates this */ if( icaltime_is_null_time(end)){ struct icaltime_span* last_span; last_span = (struct icaltime_span*)pvl_data(pvl_tail(sl->spans)); if (last_span != 0){ if ((freetime=(struct icaltime_span *) malloc(sizeof(struct icaltime_span))) == 0){ icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } freetime->is_busy = 0; freetime->start = last_span->end; freetime->end = freetime->start; pvl_insert_ordered(sl->spans,compare_span,(void*)freetime); } } return sl; }