Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions
icaldirset.h File Reference
#include "ical.h"
#include "icalset.h"
#include "icalcluster.h"
#include "icalgauge.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  icaldirset_options

Typedefs

typedef struct icaldirset_impl
typedef struct icaldirset_options icaldirset_options

Functions

icalset * icaldirset_new (const char *path)
icalset * icaldirset_new_reader (const char *path)
icalset * icaldirset_new_writer (const char *path)
icalset * icaldirset_init (icalset *set, const char *dsn, void *options)
void icaldirset_free (icalset *set)
const char * icaldirset_path (icalset *set)
void icaldirset_mark (icalset *set)
icalerrorenum icaldirset_commit (icalset *set)
icalerrorenum icaldirset_add_component (icalset *store, icalcomponent *comp)
 This assumes that the top level component is a VCALENDAR, and there is an inner component of type VEVENT, VTODO or VJOURNAL.
icalerrorenum icaldirset_remove_component (icalset *store, icalcomponent *comp)
 Remove a component in the current cluster.
int icaldirset_count_components (icalset *store, icalcomponent_kind kind)
icalerrorenum icaldirset_select (icalset *store, icalgauge *gauge)
void icaldirset_clear (icalset *store)
icalcomponent * icaldirset_fetch (icalset *store, const char *uid)
int icaldirset_has_uid (icalset *store, const char *uid)
icalcomponent * icaldirset_fetch_match (icalset *set, icalcomponent *c)
icalerrorenum icaldirset_modify (icalset *store, icalcomponent *oldc, icalcomponent *newc)
icalcomponent * icaldirset_get_current_component (icalset *store)
icalcomponent * icaldirset_get_first_component (icalset *store)
icalcomponent * icaldirset_get_next_component (icalset *store)
icalsetiter icaldirset_begin_component (icalset *set, icalcomponent_kind kind, icalgauge *gauge)
icalcomponent * icaldirsetiter_to_next (icalset *set, icalsetiter *i)
icalcomponent * icaldirsetiter_to_prior (icalset *set, icalsetiter *i)

Class Documentation

struct icaldirset_options

Definition at line 91 of file icaldirset.h.

Collaboration diagram for icaldirset_options:
Class Members
int flags flags corresponding to the open() system call O_RDWR, etc.

Typedef Documentation

typedef struct icaldirset_impl

Definition at line 40 of file icaldirset.h.


Function Documentation

icalerrorenum icaldirset_add_component ( icalset *  set,
icalcomponent *  comp 
)

This assumes that the top level component is a VCALENDAR, and there is an inner component of type VEVENT, VTODO or VJOURNAL.

The inner component must have a DSTAMP property

Definition at line 421 of file icaldirset.c.

{
    char clustername[ICAL_PATH_MAX];
    icalproperty *dt = 0;
    icalvalue *v;
    struct icaltimetype tm;
    icalerrorenum error = ICAL_NO_ERROR;
    icalcomponent *inner;
    icaldirset *dset = (icaldirset*) set;

    icalerror_check_arg_rz( (dset!=0), "dset");
    icalerror_check_arg_rz( (comp!=0), "comp");

    icaldirset_add_uid(comp);

    /* Determine which cluster this object belongs in. This is a HACK */

    for(inner = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT);
       inner != 0;
       inner = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
  
       dt = icalcomponent_get_first_property(inner,ICAL_DTSTAMP_PROPERTY);
       
      if (dt != 0)
           break; 
       }      

    if (dt == 0) {
       for(inner = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT);
           inner != 0;
           inner = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
           
           dt = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY);
           
         if (dt != 0)
              break; 
           }  
       }

    if (dt == 0){
       icalerror_warn("The component does not have a DTSTAMP or DTSTART property, so it cannot be added to the store");
       icalerror_set_errno(ICAL_BADARG_ERROR);
       return ICAL_BADARG_ERROR;
    }

    v = icalproperty_get_value(dt);
    tm = icalvalue_get_datetime(v);

    snprintf(clustername,ICAL_PATH_MAX,"%s/%04d%02d",dset->dir, tm.year, tm.month);

    /* Load the cluster and insert the object */
    if(dset->cluster != 0 && 
       strcmp(clustername,icalcluster_key(dset->cluster)) != 0 ){
      icalcluster_free(dset->cluster);
      dset->cluster = 0;
    }

    if (dset->cluster == 0){
      dset->cluster = icalfileset_produce_icalcluster(clustername);

      if (dset->cluster == 0){
           error = icalerrno;
       }
    }
    
    if (error != ICAL_NO_ERROR){
       icalerror_set_errno(error);
       return error;
    }

    /* Add the component to the cluster */
    icalcluster_add_component(dset->cluster,comp);
    
    /* icalcluster_mark(impl->cluster); */

    return ICAL_NO_ERROR;    
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 781 of file icaldirset.c.

{
    icalsetiter itr = icalsetiter_null;
    icaldirset *fset = (icaldirset*) set;

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

    itr.iter.kind = kind;
    itr.gauge = gauge;

    /* TO BE IMPLEMENTED */
    return icalsetiter_null;
}
void icaldirset_clear ( icalset *  store)

Definition at line 644 of file icaldirset.c.

{

    assert(0);
    return;
    /* HACK, not implemented */
}
icalerrorenum icaldirset_commit ( icalset *  set)

Definition at line 116 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;
  icalset *fileset;
  icalfileset_options options = icalfileset_options_default;

  options.cluster = dset->cluster;

  fileset = icalset_new(ICAL_FILE_SET, icalcluster_key(dset->cluster), &options);

  fileset->commit(fileset);
  fileset->free(fileset);

  return ICAL_NO_ERROR;
}

Here is the call graph for this function:

int icaldirset_count_components ( icalset *  store,
icalcomponent_kind  kind 
)

Definition at line 558 of file icaldirset.c.

{
    /* HACK, not implemented */
    assert(0);

    return 0;
}
icalcomponent* icaldirset_fetch ( icalset *  store,
const char *  uid 
)

Definition at line 576 of file icaldirset.c.

{
    icaldirset *dset = (icaldirset*)set;
    icalgauge *gauge;
    icalgauge *old_gauge;
    icalcomponent *c;
    char sql[256];

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

    snprintf(sql, 256, "SELECT * FROM VEVENT WHERE UID = \"%s\"", uid);
    
    gauge = icalgauge_new_from_sql(sql, 0);

    old_gauge = dset->gauge;
    dset->gauge = gauge;

    c= icaldirset_get_first_component(set);

    dset->gauge = old_gauge;

    icalgauge_free(gauge);

    return c;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 568 of file icaldirset.c.

{
    fprintf(stderr," icaldirset_fetch_match is not implemented\n");
    assert(0);
    return 0;
}

Here is the call graph for this function:

void icaldirset_free ( icalset *  set)

Definition at line 269 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)s;
    char* str;

  icaldirset_unlock(dset->dir);

  if(dset->dir !=0){
    free(dset->dir);
    dset->dir = 0;
    }

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

  if(dset->cluster !=0){
    icalcluster_free(dset->cluster);
    }

  while(dset->directory !=0 &&  (str=pvl_pop(dset->directory)) != 0){
       free(str);
    }

  if(dset->directory != 0){
    pvl_free(dset->directory);
    dset->directory = 0;
    }

  dset->directory_iterator = 0;
  dset->first_component = 0;
}

Here is the call graph for this function:

icalcomponent* icaldirset_get_current_component ( icalset *  store)

Definition at line 652 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;

  if (dset->cluster == 0){
    icaldirset_get_first_component(set);
    }
  if(dset->cluster == 0){
       return 0;
    }

  return icalcluster_get_current_component(dset->cluster);
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalcomponent* icaldirset_get_first_component ( icalset *  store)

Definition at line 667 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;

    icalerrorenum error;
    char path[ICAL_PATH_MAX];

  error = icaldirset_read_directory(dset);

    if (error != ICAL_NO_ERROR){
       icalerror_set_errno(error);
       return 0;
    }

  dset->directory_iterator = pvl_head(dset->directory);
    
  if (dset->directory_iterator == 0){
       icalerror_set_errno(error);
       return 0;
    }
    
  snprintf(path,ICAL_PATH_MAX,"%s/%s",
          dset->dir,
          (char*)pvl_data(dset->directory_iterator));

    /* If the next cluster we need is different than the current cluster, 
       delete the current one and get a new one */

  if(dset->cluster != 0 && strcmp(path,icalcluster_key(dset->cluster)) != 0 ){
    icalcluster_free(dset->cluster);
    dset->cluster = 0;
    }
    
  if (dset->cluster == 0){
    dset->cluster = icalfileset_produce_icalcluster(path);

    if (dset->cluster == 0){
           error = icalerrno;
       }
    } 

    if (error != ICAL_NO_ERROR){
       icalerror_set_errno(error);
       return 0;
    }

  dset->first_component = 1;

  return icaldirset_get_next_component(set);
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalcomponent* icaldirset_get_next_component ( icalset *  store)

Definition at line 719 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;
    icalcomponent *c;
    icalerrorenum error;

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


  if(dset->cluster == 0){
       icalerror_warn("icaldirset_get_next_component called with a NULL cluster (Caller must call icaldirset_get_first_component first");
       icalerror_set_errno(ICAL_USAGE_ERROR);
       return 0;

    }

    /* Set the component iterator for the following for loop */
  if (dset->first_component == 1){
    icalcluster_get_first_component(dset->cluster);
    dset->first_component = 0;
    } else {
    icalcluster_get_next_component(dset->cluster);
    }

    while(1){
       /* Iterate through all of the objects in the cluster*/
    for( c = icalcluster_get_current_component(dset->cluster);
            c != 0;
        c = icalcluster_get_next_component(dset->cluster)){
           
           /* If there is a gauge defined and the component does not
              pass the gauge, skip the rest of the loop */

      if (dset->gauge != 0 && icalgauge_compare(dset->gauge,c) == 0){
              continue;
           }

           /* Either there is no gauge, or the component passed the
              gauge, so return it*/

           return c;
       }

       /* Fell through the loop, so the component we want is not
          in this cluster. Load a new cluster and try again.*/

    error = icaldirset_next_cluster(dset);

    if(dset->cluster == 0 || error != ICAL_NO_ERROR){
           /* No more clusters */
           return 0;
       } else {
      c = icalcluster_get_first_component(dset->cluster);

           return c;
       }
       
    }

    return 0; /* Should never get here */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int icaldirset_has_uid ( icalset *  store,
const char *  uid 
)

Definition at line 604 of file icaldirset.c.

{
    icalcomponent *c;

    icalerror_check_arg_rz( (set!=0), "set");
    icalerror_check_arg_rz( (uid!=0), "uid");
    
    /* HACK. This is a temporary implementation. _has_uid should use a
       database, and _fetch should use _has_uid, not the other way
       around */
    c = icaldirset_fetch(set,uid);

    return c!=0;

}

Here is the call graph for this function:

icalset* icaldirset_init ( icalset *  set,
const char *  dsn,
void options 
)

Definition at line 210 of file icaldirset.c.

{
  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;
}

Here is the call graph for this function:

void icaldirset_mark ( icalset *  set)

Definition at line 108 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;

  icalcluster_mark(dset->cluster);
}

Here is the call graph for this function:

icalerrorenum icaldirset_modify ( icalset *  store,
icalcomponent *  oldc,
icalcomponent *  newc 
)

Definition at line 634 of file icaldirset.c.

{
    assert(0);
    return ICAL_NO_ERROR; /* HACK, not implemented */

}
icalset* icaldirset_new ( const char *  path)

Definition at line 243 of file icaldirset.c.

Here is the call graph for this function:

Here is the caller graph for this function:

icalset* icaldirset_new_reader ( const char *  path)

Definition at line 249 of file icaldirset.c.

{
  icaldirset_options reader_options = icaldirset_options_default;

  reader_options.flags = O_RDONLY;

  return icalset_new(ICAL_DIR_SET, dir, &reader_options);
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalset* icaldirset_new_writer ( const char *  path)

Definition at line 259 of file icaldirset.c.

{
  icaldirset_options writer_options = icaldirset_options_default;

  writer_options.flags = O_RDWR|O_CREAT;

  return icalset_new(ICAL_DIR_SET, dir, &writer_options);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* icaldirset_path ( icalset *  set)

Definition at line 100 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;

  return dset->dir;
}
icalerrorenum icaldirset_remove_component ( icalset *  set,
icalcomponent *  comp 
)

Remove a component in the current cluster.

HACK. This routine is a "friend" of icalfileset, and breaks its encapsulation. It was either do it this way, or add several layers of interfaces that had no other use.

Definition at line 506 of file icaldirset.c.

{
    icaldirset *dset = (icaldirset*)set;
    icalcomponent *filecomp = icalcluster_get_component(dset->cluster);

    icalcompiter i;
    int found = 0;

    icalerror_check_arg_re((set!=0),"set",ICAL_BADARG_ERROR);
    icalerror_check_arg_re((comp!=0),"comp",ICAL_BADARG_ERROR);
    icalerror_check_arg_re((dset->cluster!=0),"Cluster pointer",ICAL_USAGE_ERROR);

    for(i = icalcomponent_begin_component(filecomp,ICAL_ANY_COMPONENT);
       icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){
       
       icalcomponent *this = icalcompiter_deref(&i);

       if (this == comp){
           found = 1;
           break;
       }
    }

    if (found != 1){
       icalerror_warn("icaldirset_remove_component: component is not part of current cluster");
       icalerror_set_errno(ICAL_USAGE_ERROR);
       return ICAL_USAGE_ERROR;
    }

    icalcluster_remove_component(dset->cluster,comp);

    /* icalcluster_mark(impl->cluster); */

    /* If the removal emptied the fileset, get the next fileset */
    if( icalcluster_count_components(dset->cluster,ICAL_ANY_COMPONENT)==0){
      icalerrorenum error = icaldirset_next_cluster(dset);

      if(dset->cluster != 0 && error == ICAL_NO_ERROR){
       icalcluster_get_first_component(dset->cluster);
       } else {
           /* HACK. Not strictly correct for impl->cluster==0 */
           return error;
       }
    } else {
       /* Do nothing */
    }

    return ICAL_NO_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

icalerrorenum icaldirset_select ( icalset *  store,
icalgauge *  gauge 
)

Definition at line 621 of file icaldirset.c.

{
  icaldirset *dset = (icaldirset*)set;

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

  dset->gauge = gauge;

    return ICAL_NO_ERROR;
}

Here is the caller graph for this function:

icalcomponent* icaldirsetiter_to_next ( icalset *  set,
icalsetiter i 
)

Definition at line 795 of file icaldirset.c.

{
    /* TO BE IMPLEMENTED */
    return NULL;
}
icalcomponent* icaldirsetiter_to_prior ( icalset *  set,
icalsetiter i 
)

Definition at line 801 of file icaldirset.c.

{
    /* TO BE IMPLEMENTED */
    return NULL;
}