Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions | Variables
icalfileset.h File Reference
#include "ical.h"
#include "icalset.h"
#include "icalcluster.h"
#include "icalgauge.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  icalfileset_options
 options for opening an icalfileset. More...

Typedefs

typedef struct icalfileset_impl
typedef struct icalfileset_options icalfileset_options
 options for opening an icalfileset.

Functions

icalset * icalfileset_new (const char *path)
icalset * icalfileset_new_reader (const char *path)
icalset * icalfileset_new_writer (const char *path)
icalset * icalfileset_init (icalset *set, const char *dsn, void *options)
icalfileset * icalfileset_new_from_cluster (const char *path, icalcluster *cluster)
icalcluster * icalfileset_produce_icalcluster (const char *path)
void icalfileset_free (icalset *cluster)
const char * icalfileset_path (icalset *cluster)
void icalfileset_mark (icalset *set)
icalerrorenum icalfileset_commit (icalset *set)
icalerrorenum icalfileset_add_component (icalset *set, icalcomponent *child)
icalerrorenum icalfileset_remove_component (icalset *set, icalcomponent *child)
int icalfileset_count_components (icalset *set, icalcomponent_kind kind)
icalerrorenum icalfileset_select (icalset *set, icalgauge *gauge)
 Restrict the component returned by icalfileset_first, _next to those that pass the gauge.
void icalfileset_clear (icalset *set)
 clear the gauge
icalcomponent * icalfileset_fetch (icalset *set, const char *uid)
 Get and search for a component by uid.
int icalfileset_has_uid (icalset *set, const char *uid)
icalcomponent * icalfileset_fetch_match (icalset *set, icalcomponent *c)
icalerrorenum icalfileset_modify (icalset *set, icalcomponent *oldcomp, icalcomponent *newcomp)
 Modify components according to the MODIFY method of CAP.
icalcomponent * icalfileset_get_current_component (icalset *cluster)
icalcomponent * icalfileset_get_first_component (icalset *cluster)
icalcomponent * icalfileset_get_next_component (icalset *cluster)
icalsetiter icalfileset_begin_component (icalset *set, icalcomponent_kind kind, icalgauge *gauge)
icalcomponent * icalfilesetiter_to_next (icalset *set, icalsetiter *iter)
icalcomponent * icalfileset_form_a_matched_recurrence_component (icalsetiter *itr)
icalcomponent * icalfileset_get_component (icalset *cluster)
 Return a reference to the internal component.

Variables

icalfileset_options icalfileset_options_default
 Default options used when NULL is passed to icalset_new()

Class Documentation

struct icalfileset_options

options for opening an icalfileset.

These options should be passed to the icalset_new() function

Definition at line 120 of file icalfileset.h.

Collaboration diagram for icalfileset_options:
Class Members
icalcluster * cluster use this cluster to initialize data
int flags flags for open() O_RDONLY, etc
mode_t mode file mode

Typedef Documentation

typedef struct icalfileset_impl

Definition at line 44 of file icalfileset.h.

options for opening an icalfileset.

These options should be passed to the icalset_new() function


Function Documentation

icalerrorenum icalfileset_add_component ( icalset *  set,
icalcomponent *  child 
)

Definition at line 409 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_re((set!=0),"set", ICAL_BADARG_ERROR);
    icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR);

    icalcomponent_add_component(fset->cluster,child);

    icalfileset_mark(set);

    return ICAL_NO_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalsetiter icalfileset_begin_component ( icalset *  set,
icalcomponent_kind  kind,
icalgauge *  gauge 
)

Definition at line 712 of file icalfileset.c.

{
    icalsetiter itr = icalsetiter_null;
    icalcomponent* comp = NULL;
    icalcompiter citr;
    icalfileset *fset = (icalfileset*) set;
    struct icaltimetype start, next;
    icalproperty *dtstart, *rrule, *prop, *due;
    struct icalrecurrencetype recur;
    int g = 0;

    icalerror_check_arg_re((set!=0), "set", icalsetiter_null);

    itr.gauge = gauge;

    citr = icalcomponent_begin_component(fset->cluster, kind);
    comp = icalcompiter_deref(&citr);

    if (gauge == 0) {
        itr.iter = citr;
        return itr;
    }

    while (comp != 0) {

        /* check if it is a recurring component and with guage expand, if so
           we need to add recurrence-id property to the given component */
        rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY);
        g = icalgauge_get_expand(gauge);

        if (rrule != 0
            && g == 1) {

            recur = icalproperty_get_rrule(rrule);
            if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) {
                dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY);
                if (dtstart)
                    start = icalproperty_get_dtstart(dtstart);
            } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) {
                    due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY);
                    if (due)
                        start = icalproperty_get_due(due);
            }

            if (itr.last_component == NULL) {
                itr.ritr = icalrecur_iterator_new(recur, start);
                next = icalrecur_iterator_next(itr.ritr);
                itr.last_component = comp;
            }
            else {
                next = icalrecur_iterator_next(itr.ritr);
                if (icaltime_is_null_time(next)){
                    itr.last_component = NULL;
                    icalrecur_iterator_free(itr.ritr);
                    itr.ritr = NULL;
                    return icalsetiter_null;
                } else {
                    itr.last_component = comp;
                }
            }

            /* add recurrence-id to the component
               if there is a recurrence-id already, remove it, then add the new one */
            if (prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY))
                icalcomponent_remove_property(comp, prop);
            icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next));

        }

        if (gauge == 0 || icalgauge_compare(itr.gauge, comp) == 1) {
            /* matches and returns */
            itr.iter = citr;
            return itr;
        }

        /* if there is no previous component pending, then get the next component */
        if (itr.last_component == NULL)
            comp =  icalcompiter_next(&citr);
    }

    return icalsetiter_null;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void icalfileset_clear ( icalset *  set)

clear the gauge

Definition at line 463 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_rv(set!=0,"set");

    fset->gauge = 0;
}
icalerrorenum icalfileset_commit ( icalset *  set)

Definition at line 340 of file icalfileset.c.

{
    char tmp[ICAL_PATH_MAX]; 
    char *str;
    icalcomponent *c;
    off_t write_size=0;
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_re((fset!=0),"set",ICAL_BADARG_ERROR);  
    
    icalerror_check_arg_re((fset->fd>0),"set->fd is invalid",
                        ICAL_INTERNAL_ERROR) ;

    if (fset->changed == 0 ){
       return ICAL_NO_ERROR;
    }
    
    if(lseek(fset->fd, 0, SEEK_SET) < 0){
       icalerror_set_errno(ICAL_FILE_ERROR);
       return ICAL_FILE_ERROR;
    }
    
    for(c = icalcomponent_get_first_component(fset->cluster,ICAL_ANY_COMPONENT);
       c != 0;
       c = icalcomponent_get_next_component(fset->cluster,ICAL_ANY_COMPONENT)){
       int sz;

       str = icalcomponent_as_ical_string(c);
    
       sz=write(fset->fd,str,strlen(str));

       if ( sz != strlen(str)){
           perror("write");
           icalerror_set_errno(ICAL_FILE_ERROR);
           return ICAL_FILE_ERROR;
       }

       write_size += sz;
    }
    
    fset->changed = 0;    

#ifndef WIN32
    if(ftruncate(fset->fd,write_size) < 0){
       return ICAL_FILE_ERROR;
    }
#else
       chsize( fset->fd, tell( fset->fd ) );
#endif
    
    return ICAL_NO_ERROR;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

int icalfileset_count_components ( icalset *  set,
icalcomponent_kind  kind 
)

Definition at line 439 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    if (set == 0){
       icalerror_set_errno(ICAL_BADARG_ERROR);
       return -1;
    }

    return icalcomponent_count_components(fset->cluster,kind);
}

Here is the call graph for this function:

icalcomponent* icalfileset_fetch ( icalset *  set,
const char *  uid 
)

Get and search for a component by uid.

Definition at line 472 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;
    icalcompiter i;    

    icalerror_check_arg_rz(set!=0,"set");
    
    for(i = icalcomponent_begin_component(fset->cluster,ICAL_ANY_COMPONENT);
       icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){
       
              icalcomponent *this = icalcompiter_deref(&i);
              icalcomponent *inner;
              icalproperty *p;
              const char *this_uid;

              for(inner = icalcomponent_get_first_component(this,ICAL_ANY_COMPONENT);
                     inner != 0;
                     inner = icalcomponent_get_next_component(this,ICAL_ANY_COMPONENT)){

                     p = icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY);
                     if ( p )
                     {
                            this_uid = icalproperty_get_uid(p);

                            if(this_uid==0){
                            icalerror_warn("icalfileset_fetch found a component with no UID");
                            continue;
                            }

                            if (strcmp(uid,this_uid)==0){
                                   return this;
                            }
                     }
              }
       }

    return 0;
}

Here is the call graph for this function:

icalcomponent* icalfileset_fetch_match ( icalset *  set,
icalcomponent *  c 
)

Definition at line 578 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;
    icalcompiter i;    

    struct icalfileset_id comp_id, match_id;
    
    comp_id = icalfileset_get_id(comp);

    for(i = icalcomponent_begin_component(fset->cluster,ICAL_ANY_COMPONENT);
       icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){
       
       icalcomponent *match = icalcompiter_deref(&i);

       match_id = icalfileset_get_id(match);

       if(strcmp(comp_id.uid, match_id.uid) == 0 &&
          ( comp_id.recurrence_id ==0 || 
            strcmp(comp_id.recurrence_id, match_id.recurrence_id) ==0 )){

           /* HACK. What to do with SEQUENCE? */

           icalfileset_id_free(&match_id);
           icalfileset_id_free(&comp_id);
           return match;
           
       }
       
       icalfileset_id_free(&match_id);
    }

    icalfileset_id_free(&comp_id);
    return 0;

}

Here is the call graph for this function:

Definition at line 794 of file icalfileset.c.

{
    icalcomponent* comp = NULL;
    struct icaltimetype start, next;
    icalproperty *dtstart, *rrule, *prop, *due;
    struct icalrecurrencetype recur;

    comp = itr->last_component;

    if (comp == NULL || itr->gauge == NULL) {
        return NULL;
    }

    rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY);

    recur = icalproperty_get_rrule(rrule);

    if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT) {
        dtstart = icalcomponent_get_first_property(comp, ICAL_DTSTART_PROPERTY);
        if (dtstart)
            start = icalproperty_get_dtstart(dtstart);
    } else if (icalcomponent_isa(comp) == ICAL_VTODO_COMPONENT) {
        due = icalcomponent_get_first_property(comp, ICAL_DUE_PROPERTY);
        if (due)
            start = icalproperty_get_due(due);
    }

    if (itr->ritr == NULL) {
        itr->ritr = icalrecur_iterator_new(recur, start);
        next = icalrecur_iterator_next(itr->ritr);
        itr->last_component = comp;
    } else {
        next = icalrecur_iterator_next(itr->ritr);
        if (icaltime_is_null_time(next)){
            /* no more recurrence, returns */
            itr->last_component = NULL;
            icalrecur_iterator_free(itr->ritr);
            itr->ritr = NULL;
            return NULL;
        } else {
            itr->last_component = comp;
        }
    }

    /* add recurrence-id to the component
     * if there is a recurrence-id already, remove it, then add the new one */
    if (prop = icalcomponent_get_first_property(comp, ICAL_RECURRENCEID_PROPERTY))
        icalcomponent_remove_property(comp, prop);
        icalcomponent_add_property(comp, icalproperty_new_recurrenceid(next));

     if (itr->gauge == 0 || icalgauge_compare(itr->gauge, comp) == 1) {
         /* matches and returns */
         return comp;
     }
     /* not matched */
     return NULL;

}

Here is the call graph for this function:

void icalfileset_free ( icalset *  cluster)

Definition at line 266 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_rv((set!=0),"set");

    if (fset->cluster != 0){
       icalfileset_commit(set);
       icalcomponent_free(fset->cluster);
       fset->cluster=0;
    }

    if (fset->gauge != 0){
       icalgauge_free(fset->gauge);
       fset->gauge=0;
    }

    if(fset->fd > 0){
       icalfileset_unlock(fset);
       close(fset->fd);
       fset->fd = -1;
    }

    if(fset->path != 0){
       free(fset->path);
       fset->path = 0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalcomponent* icalfileset_get_component ( icalset *  cluster)

Return a reference to the internal component.

You probably should not be using this.

Definition at line 399 of file icalfileset.c.

                                                      {
    icalfileset *fset = (icalfileset*) set;
    icalerror_check_arg_rz((set!=0),"set");

    return fset->cluster;
}
icalcomponent* icalfileset_get_current_component ( icalset *  cluster)

Definition at line 626 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_rz((set!=0),"set");

    return icalcomponent_get_current_component(fset->cluster);
}

Here is the call graph for this function:

icalcomponent* icalfileset_get_first_component ( icalset *  cluster)

Definition at line 636 of file icalfileset.c.

{
    icalcomponent *c=0;
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_rz((set!=0),"set");

    do {
       if (c == 0){
           c = icalcomponent_get_first_component(fset->cluster,
                                            ICAL_ANY_COMPONENT);
       } else {
           c = icalcomponent_get_next_component(fset->cluster,
                                           ICAL_ANY_COMPONENT);
       }

       if(c != 0 && (fset->gauge == 0 ||
                    icalgauge_compare(fset->gauge, c) == 1)){
           return c;
       }

    } while(c != 0);


    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalcomponent* icalfileset_get_next_component ( icalset *  cluster)

Definition at line 663 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;
    icalcomponent *c;

    icalerror_check_arg_rz((set!=0),"set");
    
    do {
       c = icalcomponent_get_next_component(fset->cluster,
                                        ICAL_ANY_COMPONENT);

       if(c != 0 && (fset->gauge == 0 ||
                    icalgauge_compare(fset->gauge,c) == 1)){
           return c;
       }
       
    } while(c != 0);
    
    
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int icalfileset_has_uid ( icalset *  set,
const char *  uid 
)

Definition at line 511 of file icalfileset.c.

{
    assert(0); /* HACK, not implemented */
    return 0;
}
icalset* icalfileset_init ( icalset *  set,
const char *  dsn,
void options 
)

Definition at line 92 of file icalfileset.c.

{
  icalfileset_options *options = (options_in) ? options_in : &icalfileset_options_default;
  icalfileset *fset = (icalfileset*) set;
  int flags;
  mode_t mode;
  off_t cluster_file_size;

  icalerror_clear_errno();
  icalerror_check_arg_rz( (path!=0), "path");
  icalerror_check_arg_rz( (fset!=0), "fset");

  fset->path = strdup(path);
  fset->options = *options;

  flags = options->flags;
  mode  = options->mode;

  cluster_file_size = icalfileset_filesize(fset);
  
  if(cluster_file_size < 0){
    icalfileset_free(set);
    return 0;
  }

#ifndef WIN32
  fset->fd = open(fset->path, flags, mode);
#else
  fset->fd = open(fset->path, flags | O_BINARY, mode);
  /* fset->fd = sopen(fset->path,flags, _SH_DENYWR, _S_IREAD | _S_IWRITE); */
#endif
    
  if (fset->fd < 0){
    icalerror_set_errno(ICAL_FILE_ERROR);
    icalfileset_free(set);
    return 0;
  }

#ifndef WIN32
    icalfileset_lock(fset);
#endif
    
    if(cluster_file_size > 0 ){
       icalerrorenum error;
       if((error = icalfileset_read_file(fset,mode))!= ICAL_NO_ERROR){
         icalfileset_free(set);
         return 0;
       }
    }
 
    if (options->cluster) {
       fset->cluster = icalcomponent_new_clone(icalcluster_get_component(options->cluster));
       fset->changed = 1;
    }

    if (fset->cluster == 0) {
      fset->cluster = icalcomponent_new(ICAL_XROOT_COMPONENT);
    }

    return set;
}

Here is the call graph for this function:

void icalfileset_mark ( icalset *  set)

Definition at line 393 of file icalfileset.c.

                                    {
    icalerror_check_arg_rv((set!=0),"set");

    ((icalfileset*)set)->changed = 1;
}

Here is the caller graph for this function:

icalerrorenum icalfileset_modify ( icalset *  set,
icalcomponent *  oldcomp,
icalcomponent *  newcomp 
)

Modify components according to the MODIFY method of CAP.

Works on the currently selected components.

Definition at line 615 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    assert(0); /* HACK, not implemented */
    return ICAL_NO_ERROR;
}
icalset* icalfileset_new ( const char *  path)

Definition at line 71 of file icalfileset.c.

Here is the call graph for this function:

Here is the caller graph for this function:

icalfileset* icalfileset_new_from_cluster ( const char *  path,
icalcluster *  cluster 
)
icalset* icalfileset_new_reader ( const char *  path)

Definition at line 76 of file icalfileset.c.

{
  icalfileset_options reader_options = icalfileset_options_default;
  reader_options.flags = O_RDONLY;

  return icalset_new(ICAL_FILE_SET, path, &reader_options);
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalset* icalfileset_new_writer ( const char *  path)

Definition at line 84 of file icalfileset.c.

{
  icalfileset_options writer_options = icalfileset_options_default;
  writer_options.flags = O_RDONLY;

  return icalset_new(ICAL_FILE_SET, path, &writer_options);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* icalfileset_path ( icalset *  cluster)

Definition at line 295 of file icalfileset.c.

                                           {
    icalerror_check_arg_rz((set!=0),"set");

    return ((icalfileset*)set)->path;
}
icalcluster* icalfileset_produce_icalcluster ( const char *  path)

Definition at line 155 of file icalfileset.c.

                                                               {
  icalset *fileset;
  icalcluster *ret;

  int errstate = icalerror_errors_are_fatal;
  icalerror_errors_are_fatal = 0;
    
  fileset = icalfileset_new_reader(path);
  

  if (fileset == 0 && icalerrno == ICAL_FILE_ERROR) {
    /* file does not exist */
    ret = icalcluster_new(path, NULL);
  } else {
    ret = icalcluster_new(path, ((icalfileset*)fileset)->cluster);
    icalfileset_free(fileset);
  }
  
  icalerror_errors_are_fatal = errstate;
  icalerror_set_errno(ICAL_NO_ERROR);
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalerrorenum icalfileset_remove_component ( icalset *  set,
icalcomponent *  child 
)

Definition at line 424 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_re((set!=0),"set",ICAL_BADARG_ERROR);
    icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR);

    icalcomponent_remove_component(fset->cluster,child);

    icalfileset_mark(set);

    return ICAL_NO_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalerrorenum icalfileset_select ( icalset *  set,
icalgauge *  gauge 
)

Restrict the component returned by icalfileset_first, _next to those that pass the gauge.

_clear removes the gauge

Definition at line 452 of file icalfileset.c.

{
    icalfileset *fset = (icalfileset*) set;

    icalerror_check_arg_re(gauge!=0,"gauge",ICAL_BADARG_ERROR);

    fset->gauge = gauge;

    return ICAL_NO_ERROR;
}

Here is the caller graph for this function:

icalcomponent* icalfilesetiter_to_next ( icalset *  set,
icalsetiter iter 
)

Definition at line 852 of file icalfileset.c.

{

    icalcomponent* c = NULL;
    icalfileset *fset = (icalfileset*) set;
    struct icaltimetype start, next;
    icalproperty *dtstart, *rrule, *prop, *due;
    struct icalrecurrencetype recur;
    int g = 0;


    do {
        c = icalcompiter_next(&(i->iter));

        if (c == 0) continue;
        if (i->gauge == 0) return c;


        rrule = icalcomponent_get_first_property(c, ICAL_RRULE_PROPERTY);
        g = icalgauge_get_expand(i->gauge);

        /* a recurring component with expand query */
        if (rrule != 0
            && g == 1) {

            recur = icalproperty_get_rrule(rrule);

            if (icalcomponent_isa(c) == ICAL_VEVENT_COMPONENT) {
                dtstart = icalcomponent_get_first_property(c, ICAL_DTSTART_PROPERTY);
                if (dtstart)
                    start = icalproperty_get_dtstart(dtstart);
            } else if (icalcomponent_isa(c) == ICAL_VTODO_COMPONENT) {
                due = icalcomponent_get_first_property(c, ICAL_DUE_PROPERTY);
                if (due)
                    start = icalproperty_get_due(due);
            }

            if (i->ritr == NULL) {
                i->ritr = icalrecur_iterator_new(recur, start);
                next = icalrecur_iterator_next(i->ritr);
                i->last_component = c;
            } else {
                next = icalrecur_iterator_next(i->ritr);
                if (icaltime_is_null_time(next)) {
                    /* no more recurrence, returns */
                    i->last_component = NULL;
                    icalrecur_iterator_free(i->ritr);
                    i->ritr = NULL;
                    return NULL;
                } else {
                    i->last_component = c;
                }
            }
        }

        /* add recurrence-id to the component
         * if there is a recurrence-id already, remove it, then add the new one */
        if (prop = icalcomponent_get_first_property(c, ICAL_RECURRENCEID_PROPERTY))
            icalcomponent_remove_property(c, prop);
        icalcomponent_add_property(c, icalproperty_new_recurrenceid(next));

        if(c != 0 && (i->gauge == 0 ||
                        icalgauge_compare(i->gauge, c) == 1)){
            return c;
        }
    } while (c != 0);

    return 0;

}

Here is the call graph for this function:


Variable Documentation

Default options used when NULL is passed to icalset_new()

Definition at line 62 of file icalfileset.c.