aboutsummaryrefslogtreecommitdiffstats
path: root/libical/src/libicalss
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@src.gnome.org>2000-12-12 06:07:15 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2000-12-12 06:07:15 +0800
commit5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb (patch)
tree9aef39b2615e0dcd55d15d18cc55a391a7f66161 /libical/src/libicalss
parent1a8645d8b85f46d34ff24f1f7bdc69bfd32282d4 (diff)
downloadgsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.tar
gsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.tar.gz
gsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.tar.bz2
gsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.tar.lz
gsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.tar.xz
gsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.tar.zst
gsoc2013-evolution-5ccacd6a5bbeb2d91aea706f37cc5f96ee3144fb.zip
This commit was generated by cvs2svn to compensate for changes in r6917,
which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=6918
Diffstat (limited to 'libical/src/libicalss')
-rw-r--r--libical/src/libicalss/icaldirset.c125
-rw-r--r--libical/src/libicalss/icaldirset.h20
-rw-r--r--libical/src/libicalss/icalfileset.c183
-rw-r--r--libical/src/libicalss/icalfileset.h21
-rw-r--r--libical/src/libicalss/icalfilesetimpl.h4
-rw-r--r--libical/src/libicalss/icalgauge.c55
-rw-r--r--libical/src/libicalss/icalgauge.h10
-rw-r--r--libical/src/libicalss/icalset.c337
-rw-r--r--libical/src/libicalss/icalset.h17
9 files changed, 639 insertions, 133 deletions
diff --git a/libical/src/libicalss/icaldirset.c b/libical/src/libicalss/icaldirset.c
index ff5357126c..b377d54571 100644
--- a/libical/src/libicalss/icaldirset.c
+++ b/libical/src/libicalss/icaldirset.c
@@ -31,11 +31,10 @@
icaldirset manages a database of ical components and offers
interfaces for reading, writting and searching for components.
- icaldirset groups components in to clusters based on their DTSTART
+ icaldirset groups components in to clusters based on their DTSTAMP
time -- all components that start in the same month are grouped
together in a single file. All files in a sotre are kept in a single
- directory. ( If a component does not have DTSTART, the store uses
- DTSTAMP or CREATE )
+ directory.
The primary interfaces are icaldirset_first and icaldirset_next. These
routine iterate through all of the components in the store, subject
@@ -76,32 +75,25 @@
#include <stdlib.h> /* for rand(), srand() */
#include <sys/utsname.h> /* for uname */
#include <string.h> /* for strdup */
+#include "icaldirsetimpl.h"
-struct icaldirset_impl
-{
- char* dir;
- icalcomponent* gauge;
- icaldirset* cluster;
- int first_component;
- pvl_list directory;
- pvl_elem directory_iterator;
-};
-
struct icaldirset_impl* icaldirset_new_impl()
{
- struct icaldirset_impl* comp;
+ struct icaldirset_impl* impl;
- if ( ( comp = (struct icaldirset_impl*)
+ if ( ( impl = (struct icaldirset_impl*)
malloc(sizeof(struct icaldirset_impl))) == 0) {
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
return 0;
}
- return comp;
+ strcpy(impl->id,ICALDIRSET_ID);
+
+ return impl;
}
-char* icaldirset_path(icaldirset* cluster)
+const char* icaldirset_path(icaldirset* cluster)
{
struct icaldirset_impl *impl = icaldirset_new_impl();
@@ -125,12 +117,12 @@ icalerrorenum icaldirset_commit(icaldirset* store)
}
-void icaldirset_lock(char* dir)
+void icaldirset_lock(const char* dir)
{
}
-void icaldirset_unlock(char* dir)
+void icaldirset_unlock(const char* dir)
{
}
@@ -172,7 +164,7 @@ icalerrorenum icaldirset_read_directory(struct icaldirset_impl* impl)
return ICAL_NO_ERROR;
}
-icaldirset* icaldirset_new(char* dir)
+icaldirset* icaldirset_new(const char* dir)
{
struct icaldirset_impl *impl = icaldirset_new_impl();
struct stat sbuf;
@@ -366,7 +358,7 @@ void icaldirset_add_uid(icaldirset* store, icaldirset* 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 DTSTART property */
+ component must have a DTAMP property */
icalerrorenum icaldirset_add_component(icaldirset* store, icaldirset* comp)
{
@@ -392,15 +384,32 @@ icalerrorenum icaldirset_add_component(icaldirset* store, icaldirset* comp)
inner != 0;
inner = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){
- dt = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY);
-
+ dt = icalcomponent_get_first_property(inner,ICAL_DTSTAMP_PROPERTY);
+
if (dt != 0){
break;
}
}
if (dt == 0){
- icalerror_warn("The component does not have a DTSTART property, so it cannot be added to the store");
+
+ 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;
}
@@ -488,7 +497,7 @@ icalerrorenum icaldirset_remove_component(icaldirset* store, icaldirset* comp)
icalerrorenum error = icaldirset_next_cluster(store);
if(impl->cluster != 0 && error == ICAL_NO_ERROR){
- icalfileset_get_first_component(impl->cluster,ICAL_ANY_COMPONENT);
+ icalfileset_get_first_component(impl->cluster);
} else {
/* HACK. Not strictly correct for impl->cluster==0 */
return error;
@@ -503,10 +512,24 @@ icalerrorenum icaldirset_remove_component(icaldirset* store, icaldirset* comp)
int icaldirset_count_components(icaldirset* store,
- icalcomponent_kind kind);
+ icalcomponent_kind kind)
+{
+ /* HACK, not implemented */
+
+ assert(0);
+
+ return 0;
+}
+
+
+icalcomponent* icaldirset_fetch_match(icaldirset* set, icalcomponent *c)
+{
+ fprintf(stderr," icaldirset_fetch_match is not implemented\n");
+ assert(0);
+}
-icalcomponent* icaldirset_fetch(icaldirset* store, char* uid)
+icalcomponent* icaldirset_fetch(icaldirset* store, const char* uid)
{
icalcomponent *gauge;
icalcomponent *old_gauge;
@@ -532,7 +555,7 @@ icalcomponent* icaldirset_fetch(icaldirset* store, char* uid)
old_gauge = impl->gauge;
impl->gauge = gauge;
- c= icaldirset_get_first_component(store,ICAL_ANY_COMPONENT);
+ c= icaldirset_get_first_component(store);
impl->gauge = old_gauge;
@@ -542,7 +565,7 @@ icalcomponent* icaldirset_fetch(icaldirset* store, char* uid)
}
-int icaldirset_has_uid(icaldirset* store, char* uid)
+int icaldirset_has_uid(icaldirset* store, const char* uid)
{
icalcomponent *c;
@@ -560,7 +583,7 @@ int icaldirset_has_uid(icaldirset* store, char* uid)
icalerrorenum icaldirset_select(icaldirset* store, icalcomponent* gauge)
-{
+ {
struct icaldirset_impl *impl = (struct icaldirset_impl*)store;
icalerror_check_arg_re( (store!=0), "store",ICAL_BADARG_ERROR);
@@ -575,16 +598,30 @@ icalerrorenum icaldirset_select(icaldirset* store, icalcomponent* gauge)
return ICAL_NO_ERROR;
}
-void icaldirset_clear(icaldirset* store);
-icalcomponent* icaldirset_fetch(icaldirset* store, char* uid);
-int icaldirset_has_uid(icaldirset* store, char* uid);
+
+icalerrorenum icaldirset_modify(icaldirset* store, icalcomponent *old,
+ icalcomponent *new)
+{
+ assert(0);
+ return ICAL_NO_ERROR; /* HACK, not implemented */
+
+}
+
+
+void icaldirset_clear(icaldirset* store)
+{
+
+ assert(0);
+ return;
+ /* HACK, not implemented */
+}
icalcomponent* icaldirset_get_current_component(icaldirset* store)
{
struct icaldirset_impl *impl = (struct icaldirset_impl*)store;
if(impl->cluster == 0){
- icaldirset_get_first_component(store,ICAL_ANY_COMPONENT);
+ icaldirset_get_first_component(store);
}
return icalfileset_get_current_component(impl->cluster);
@@ -592,8 +629,7 @@ icalcomponent* icaldirset_get_current_component(icaldirset* store)
}
-icalcomponent* icaldirset_get_first_component(icaldirset* store,
- icalcomponent_kind kind)
+icalcomponent* icaldirset_get_first_component(icaldirset* store)
{
struct icaldirset_impl *impl = (struct icaldirset_impl*)store;
icalerrorenum error;
@@ -638,11 +674,10 @@ icalcomponent* icaldirset_get_first_component(icaldirset* store,
impl->first_component = 1;
- return icaldirset_get_next_component(store, kind);
+ return icaldirset_get_next_component(store);
}
-icalcomponent* icaldirset_get_next_component(icaldirset* store,
- icalcomponent_kind kind)
+icalcomponent* icaldirset_get_next_component(icaldirset* store)
{
struct icaldirset_impl *impl;
icalcomponent *c;
@@ -662,10 +697,10 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store,
/* Set the component iterator for the following for loop */
if (impl->first_component == 1){
- icalfileset_get_first_component(impl->cluster,kind);
+ icalfileset_get_first_component(impl->cluster);
impl->first_component = 0;
} else {
- icalfileset_get_next_component(impl->cluster,kind);
+ icalfileset_get_next_component(impl->cluster);
}
@@ -673,9 +708,7 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store,
/* Iterate through all of the objects in the cluster*/
for( c = icalfileset_get_current_component(impl->cluster);
c != 0;
- c = icalfileset_get_next_component(
- impl->cluster,
- kind)){
+ c = icalfileset_get_next_component(impl->cluster)){
/* If there is a gauge defined and the component does not
pass the gauge, skip the rest of the loop */
@@ -698,9 +731,7 @@ icalcomponent* icaldirset_get_next_component(icaldirset* store,
/* No more clusters */
return 0;
} else {
- c = icalfileset_get_first_component(
- impl->cluster,
- kind);
+ c = icalfileset_get_first_component(impl->cluster);
return c;
}
diff --git a/libical/src/libicalss/icaldirset.h b/libical/src/libicalss/icaldirset.h
index e9d6240aeb..7d205ecf0a 100644
--- a/libical/src/libicalss/icaldirset.h
+++ b/libical/src/libicalss/icaldirset.h
@@ -30,7 +30,6 @@
#define ICALDIRSET_H
#include "ical.h"
-#include "icalerror.h"
/* icaldirset Routines for storing, fetching, and searching for ical
* objects in a database */
@@ -38,11 +37,11 @@
typedef void icaldirset;
-icaldirset* icaldirset_new(char* path);
+icaldirset* icaldirset_new(const char* path);
void icaldirset_free(icaldirset* store);
-char* icaldirset_path(icaldirset* store);
+const char* icaldirset_path(icaldirset* store);
/* Mark the cluster as changed, so it will be written to disk when it
is freed. Commit writes to disk immediately*/
@@ -61,22 +60,21 @@ icalerrorenum icaldirset_select(icaldirset* store, icalcomponent* gauge);
void icaldirset_clear(icaldirset* store);
/* Get a component by uid */
-icalcomponent* icaldirset_fetch(icaldirset* store, char* uid);
-int icaldirset_has_uid(icaldirset* store, char* uid);
+icalcomponent* icaldirset_fetch(icaldirset* store, const char* uid);
+int icaldirset_has_uid(icaldirset* store, const char* uid);
+icalcomponent* icaldirset_fetch_match(icaldirset* set, icalcomponent *c);
/* Modify components according to the MODIFY method of CAP. Works on
the currently selected components. */
-icalerrorenum icaldirset_modify(icaldirset* store, icalcomponent *old,
- icalcomponent *new);
+icalerrorenum icaldirset_modify(icaldirset* store, icalcomponent *oldc,
+ icalcomponent *newc);
/* Iterate through the components. If a guage has been defined, these
will skip over components that do not pass the gauge */
icalcomponent* icaldirset_get_current_component(icaldirset* store);
-icalcomponent* icaldirset_get_first_component(icaldirset* store,
- icalcomponent_kind kind);
-icalcomponent* icaldirset_get_next_component(icaldirset* store,
- icalcomponent_kind kind);
+icalcomponent* icaldirset_get_first_component(icaldirset* store);
+icalcomponent* icaldirset_get_next_component(icaldirset* store);
#endif /* !ICALDIRSET_H */
diff --git a/libical/src/libicalss/icalfileset.c b/libical/src/libicalss/icalfileset.c
index 46c5cd2586..a7527ff3e0 100644
--- a/libical/src/libicalss/icalfileset.c
+++ b/libical/src/libicalss/icalfileset.c
@@ -30,7 +30,6 @@
#include "config.h"
#endif
-
#include "icalfileset.h"
#include <errno.h>
#include <limits.h> /* For PATH_MAX */
@@ -46,21 +45,22 @@
int icalfileset_lock(icalfileset *cluster);
int icalfileset_unlock(icalfileset *cluster);
-
-icalerrorenum icalfileset_create_cluster(char *path);
+icalerrorenum icalfileset_create_cluster(const char *path);
icalfileset* icalfileset_new_impl()
{
- struct icalfileset_impl* comp;
+ struct icalfileset_impl* impl;
- if ( ( comp = (struct icalfileset_impl*)
+ if ( ( impl = (struct icalfileset_impl*)
malloc(sizeof(struct icalfileset_impl))) == 0) {
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
errno = ENOMEM;
return 0;
}
- return comp;
+ strcpy(impl->id,ICALFILESET_ID);
+
+ return impl;
}
char* read_from_file(char *s, size_t size, void *d)
@@ -69,7 +69,7 @@ char* read_from_file(char *s, size_t size, void *d)
return c;
}
-icalfileset* icalfileset_new(char* path)
+icalfileset* icalfileset_new(const char* path)
{
struct icalfileset_impl *impl = icalfileset_new_impl();
struct stat sbuf;
@@ -205,7 +205,7 @@ void icalfileset_free(icalfileset* cluster)
free(impl);
}
-char* icalfileset_path(icalfileset* cluster)
+const char* icalfileset_path(icalfileset* cluster)
{
struct icalfileset_impl *impl = (struct icalfileset_impl*)cluster;
icalerror_check_arg_rz((cluster!=0),"cluster");
@@ -250,7 +250,7 @@ int icalfileset_unlock(icalfileset *cluster)
}
-icalerrorenum icalfileset_create_cluster(char *path)
+icalerrorenum icalfileset_create_cluster(const char *path)
{
FILE* f;
@@ -387,11 +387,158 @@ int icalfileset_count_components(icalfileset *cluster,
return icalcomponent_count_components(impl->cluster,kind);
}
-icalerrorenum icalfileset_select(icalfileset* cluster, icalcomponent* gauge);
-void icalfileset_clear(icalfileset* cluster);
+icalerrorenum icalfileset_select(icalfileset* cluster, icalcomponent* gauge)
+{
+ assert(0); /* HACK, not implemented */
+ return ICAL_NO_ERROR;
+}
+
+void icalfileset_clear(icalfileset* cluster)
+{
+ assert(0); /* HACK, not implemented */
+}
+
+icalcomponent* icalfileset_fetch(icalfileset* store,const char* uid)
+{
+ icalcompiter i;
+ struct icalfileset_impl* impl = (struct icalfileset_impl*)store;
+
+ for(i = icalcomponent_begin_component(impl->cluster,ICAL_ANY_COMPONENT);
+ icalcompiter_deref(&i)!= 0; icalcompiter_next(&i)){
+
+ icalcomponent *this = icalcompiter_deref(&i);
+ icalcomponent *inner = icalcomponent_get_first_real_component(this);
+ icalcomponent *p;
+ const char *this_uid;
+
+ if(inner != 0){
+ p = icalcomponent_get_first_property(inner,ICAL_UID_PROPERTY);
+ 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;
+}
+
+int icalfileset_has_uid(icalfileset* store,const char* uid)
+{
+ assert(0); /* HACK, not implemented */
+ return 0;
+}
+
+/******* support routines for icalfileset_fetch_match *********/
+
+struct icalfileset_id{
+ char* uid;
+ char* recurrence_id;
+ int sequence;
+};
+
+void icalfileset_id_free(struct icalfileset_id *id)
+{
+ if(id->recurrence_id != 0){
+ free(id->recurrence_id);
+ }
+
+ if(id->uid != 0){
+ free(id->uid);
+ }
+
+}
+
+struct icalfileset_id icalfileset_get_id(icalcomponent* comp)
+{
+
+ icalcomponent *inner;
+ struct icalfileset_id id;
+ icalproperty *p;
+
+ inner = icalcomponent_get_first_real_component(comp);
+
+ p = icalcomponent_get_first_property(inner, ICAL_UID_PROPERTY);
+
+ assert(p!= 0);
+
+ id.uid = strdup(icalproperty_get_uid(p));
+
+ p = icalcomponent_get_first_property(inner, ICAL_SEQUENCE_PROPERTY);
+
+ if(p == 0) {
+ id.sequence = 0;
+ } else {
+ id.sequence = icalproperty_get_sequence(p);
+ }
+
+ p = icalcomponent_get_first_property(inner, ICAL_RECURRENCEID_PROPERTY);
+
+ if (p == 0){
+ id.recurrence_id = 0;
+ } else {
+ icalvalue *v;
+ v = icalproperty_get_value(p);
+ id.recurrence_id = strdup(icalvalue_as_ical_string(v));
+
+ assert(id.recurrence_id != 0);
+ }
+
+ return id;
+}
+
+/* Find the component that is related to the given
+ component. Currently, it just matches based on UID and
+ RECURRENCE-ID */
+icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *comp)
+{
+ struct icalfileset_impl* impl = (struct icalfileset_impl*)set;
+ icalcompiter i;
+
+ struct icalfileset_id comp_id, match_id;
+
+ comp_id = icalfileset_get_id(comp);
+
+ for(i = icalcomponent_begin_component(impl->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;
+
+}
+
-icalcomponent* icalfileset_fetch(icalfileset* store, char* uid);
-int icalfileset_has_uid(icalfileset* store, char* uid);
+icalerrorenum icalfileset_modify(icalfileset* store, icalcomponent *old,
+ icalcomponent *new)
+{
+ assert(0); /* HACK, not implemented */
+ return ICAL_NO_ERROR;
+}
/* Iterate through components */
@@ -405,23 +552,21 @@ icalcomponent* icalfileset_get_current_component (icalfileset* cluster)
}
-icalcomponent* icalfileset_get_first_component(icalfileset* cluster,
- icalcomponent_kind kind)
+icalcomponent* icalfileset_get_first_component(icalfileset* cluster)
{
struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster;
icalerror_check_arg_rz((cluster!=0),"cluster");
- return icalcomponent_get_first_component(impl->cluster,kind);
+ return icalcomponent_get_first_component(impl->cluster,ICAL_ANY_COMPONENT);
}
-icalcomponent* icalfileset_get_next_component(icalfileset* cluster,
- icalcomponent_kind kind)
+icalcomponent* icalfileset_get_next_component(icalfileset* cluster)
{
struct icalfileset_impl* impl = (struct icalfileset_impl*)cluster;
icalerror_check_arg_rz((cluster!=0),"cluster");
- return icalcomponent_get_next_component(impl->cluster,kind);
+ return icalcomponent_get_next_component(impl->cluster,ICAL_ANY_COMPONENT);
}
diff --git a/libical/src/libicalss/icalfileset.h b/libical/src/libicalss/icalfileset.h
index 8ceae632be..4430f1dc74 100644
--- a/libical/src/libicalss/icalfileset.h
+++ b/libical/src/libicalss/icalfileset.h
@@ -40,10 +40,10 @@ typedef void icalfileset;
*/
-icalfileset* icalfileset_new(char* path);
+icalfileset* icalfileset_new(const char* path);
void icalfileset_free(icalfileset* cluster);
-char* icalfileset_path(icalfileset* cluster);
+const char* icalfileset_path(icalfileset* cluster);
/* Mark the cluster as changed, so it will be written to disk when it
is freed. Commit writes to disk immediately. */
@@ -65,19 +65,22 @@ icalerrorenum icalfileset_select(icalfileset* store, icalcomponent* gauge);
void icalfileset_clear(icalfileset* store);
/* Get and search for a component by uid */
-icalcomponent* icalfileset_fetch(icalfileset* cluster, char* uid);
-int icalfileset_has_uid(icalfileset* cluster, char* uid);
+icalcomponent* icalfileset_fetch(icalfileset* cluster, const char* uid);
+int icalfileset_has_uid(icalfileset* cluster, const char* uid);
+icalcomponent* icalfileset_fetch_match(icalfileset* set, icalcomponent *c);
+/* Modify components according to the MODIFY method of CAP. Works on
+ the currently selected components. */
+icalerrorenum icalfileset_modify(icalfileset* store, icalcomponent *oldcomp,
+ icalcomponent *newcomp);
+
/* Iterate through components. If a guage has been defined, these
will skip over components that do not pass the gauge */
icalcomponent* icalfileset_get_current_component (icalfileset* cluster);
-icalcomponent* icalfileset_get_first_component(icalfileset* cluster,
- icalcomponent_kind kind);
-icalcomponent* icalfileset_get_next_component(icalfileset* cluster,
- icalcomponent_kind kind);
-
+icalcomponent* icalfileset_get_first_component(icalfileset* cluster);
+icalcomponent* icalfileset_get_next_component(icalfileset* cluster);
/* Return a reference to the internal component. You probably should
not be using this. */
diff --git a/libical/src/libicalss/icalfilesetimpl.h b/libical/src/libicalss/icalfilesetimpl.h
index de447c64eb..767dceeadd 100644
--- a/libical/src/libicalss/icalfilesetimpl.h
+++ b/libical/src/libicalss/icalfilesetimpl.h
@@ -33,7 +33,11 @@
/* This definition is in its own file so it can be kept out of the
main header file, but used by "friend classes" like icaldirset*/
+#define ICALFILESET_ID "fset"
+
struct icalfileset_impl {
+
+ char id[5]; /*fset*/
char *path;
icalcomponent* cluster;
int changed;
diff --git a/libical/src/libicalss/icalgauge.c b/libical/src/libicalss/icalgauge.c
index 60ce1587cd..0bbcd20bfc 100644
--- a/libical/src/libicalss/icalgauge.c
+++ b/libical/src/libicalss/icalgauge.c
@@ -27,6 +27,45 @@
======================================================================*/
#include "ical.h"
+#include "icalgauge.h"
+#include "icalgaugeimpl.h"
+#include <stdlib.h>
+
+
+extern char* input_buffer;
+extern char* input_buffer_p;
+int ssparse(void);
+
+struct icalgauge_impl *icalss_yy_gauge;
+
+icalgauge* icalgauge_new_from_sql(char* sql)
+{
+ 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 = icalcomponent_new(ICAL_XROOT_COMPONENT);
+ impl->from = icalcomponent_new(ICAL_XROOT_COMPONENT);
+ impl->where = icalcomponent_new(ICAL_XROOT_COMPONENT);
+
+ icalss_yy_gauge = impl;
+
+ input_buffer_p = input_buffer = sql;
+ r = ssparse();
+
+ return impl;
+}
+
+
+void icalgauge_free(icalgauge* gauge)
+{
+}
/* Convert a VQUERY component into a gauge */
icalcomponent* icalgauge_make_gauge(icalcomponent* query);
@@ -44,22 +83,18 @@ icalcomponent* icalgauge_make_gauge(icalcomponent* query);
When a gauge has several sub-components, the results of testing the
target against each of them is ORed together - the target
component will pass if it matches any of the sub-components in the
- gauge. However, the results of matching the proeprties in a
+ gauge. However, the results of matching the properties in a
sub-component are ANDed -- the target must match every property in
a gauge sub-component to match the sub-component.
Here is an example:
BEGIN:XROOT
- BEGIN:VCOMPONENT
- BEGIN:VEVENT
DTSTART;X-LIC-COMPARETYPE=LESS:19981025T020000
ORGANIZER;X-LIC-COMPARETYPE=EQUAL:mrbig@host.com
- END:VEVENT
- BEGIN:VEVENT
+ END:XROOT
+ BEGIN:XROOT
LOCATION;X-LIC-COMPARETYPE=EQUAL:McNary's Pub
- END:VEVENT
- END:VCALENDAR
END:XROOT
This gauge has two sub-components; one which will match a VEVENT
@@ -194,9 +229,11 @@ int icalgauge_test(icalcomponent* comp,
icalerror_check_arg_rz( (comp!=0), "comp");
icalerror_check_arg_rz( (gauge!=0), "gauge");
- for(gauge = icalcomponent_get_first_component(gaugecontainer,ICAL_ANY_COMPONENT);
+ for(gauge = icalcomponent_get_first_component(gaugecontainer,
+ ICAL_ANY_COMPONENT);
gauge != 0;
- gauge = icalcomponent_get_next_component(gaugecontainer,ICAL_ANY_COMPONENT)){
+ gauge = icalcomponent_get_next_component(gaugecontainer,
+ ICAL_ANY_COMPONENT)){
pass += icalgauge_test_recurse(comp, gauge);
}
diff --git a/libical/src/libicalss/icalgauge.h b/libical/src/libicalss/icalgauge.h
index 401d9b7347..2fbb3aab8c 100644
--- a/libical/src/libicalss/icalgauge.h
+++ b/libical/src/libicalss/icalgauge.h
@@ -29,8 +29,14 @@
#ifndef ICALGAUGE_H
#define ICALGAUGE_H
-icalcomponent* icalgauge_new_from_vquery(char* vquery);
-char* icalgauge_as_vquery(icalcomponent* gauge);
+typedef void icalgauge;
+
+icalgauge* icalgauge_new_from_sql(char* sql);
+
+void icalgauge_free(icalgauge* gauge);
+
+char* icalgauge_as_sql(icalcomponent* gauge);
+
int icalgauge_test(icalcomponent* comp, icalcomponent* gaugecontainer);
diff --git a/libical/src/libicalss/icalset.c b/libical/src/libicalss/icalset.c
index 01a36c0129..2ffe0deff2 100644
--- a/libical/src/libicalss/icalset.c
+++ b/libical/src/libicalss/icalset.c
@@ -5,9 +5,9 @@
Icalset is the "base class" for representations of a collection of
- iCal components. Derived classes (actually delegatees) include:
+ iCal components. Derived classes (actually delegates) include:
- icalfileset Store componetns in a single file
+ icalfileset Store components in a single file
icaldirset Store components in multiple files in a directory
icalheapset Store components on the heap
icalmysqlset Store components in a mysql database.
@@ -37,49 +37,330 @@
#include "ical.h"
#include "icalset.h"
#include "icalfileset.h"
+#include "icalfilesetimpl.h"
#include "icaldirset.h"
+#include "icaldirsetimpl.h"
+#include <stdlib.h>
/*#include "icalheapset.h"*/
/*#include "icalmysqlset.h"*/
-icalset* icalset_new_file(char* path);
+#define ICALSET_ID "set "
-icalset* icalset_new_dir(char* path);
-
-icalset* icalset_new_heap(void);
-
-icalset* icalset_new_mysql(char* path);
-
-void icalset_free(icalset* set);
+struct icalset_fp {
+ void (*free)(icalset* set);
+ const char* (*path)(icalset* set);
+ void (*mark)(icalset* set);
+ icalerrorenum (*commit)(icalset* set);
+ icalerrorenum (*add_component)(icalset* set, icalcomponent* comp);
+ icalerrorenum (*remove_component)(icalset* set, icalcomponent* comp);
+ int (*count_components)(icalset* set,
+ icalcomponent_kind kind);
+ icalerrorenum (*select)(icalset* set, icalcomponent* gauge);
+ void (*clear)(icalset* set);
+ icalcomponent* (*fetch)(icalset* set, const char* uid);
+ icalcomponent* (*fetch_match)(icalset* set, icalcomponent *comp);
+ int (*has_uid)(icalset* set, const char* uid);
+ icalerrorenum (*modify)(icalset* set, icalcomponent *old,
+ icalcomponent *new);
+ icalcomponent* (*get_current_component)(icalset* set);
+ icalcomponent* (*get_first_component)(icalset* set);
+ icalcomponent* (*get_next_component)(icalset* set);
+};
+
+struct icalset_fp icalset_dirset_fp = {
+ icaldirset_free,
+ icaldirset_path,
+ icaldirset_mark,
+ icaldirset_commit,
+ icaldirset_add_component,
+ icaldirset_remove_component,
+ icaldirset_count_components,
+ icaldirset_select,
+ icaldirset_clear,
+ icaldirset_fetch,
+ icaldirset_fetch_match,
+ icaldirset_has_uid,
+ icaldirset_modify,
+ icaldirset_get_current_component,
+ icaldirset_get_first_component,
+ icaldirset_get_next_component
+};
+
+
+struct icalset_fp icalset_fileset_fp = {
+ icalfileset_free,
+ icalfileset_path,
+ icalfileset_mark,
+ icalfileset_commit,
+ icalfileset_add_component,
+ icalfileset_remove_component,
+ icalfileset_count_components,
+ icalfileset_select,
+ icalfileset_clear,
+ icalfileset_fetch,
+ icalfileset_fetch_match,
+ icalfileset_has_uid,
+ icalfileset_modify,
+ icalfileset_get_current_component,
+ icalfileset_get_first_component,
+ icalfileset_get_next_component
+};
+
+struct icalset_impl {
+
+ char id[5]; /* "set " */
+
+ void *derived_impl;
+ struct icalset_fp *fp;
+};
+
+/* Figure out what was actually passed in as the set. This could be a
+ set or and of the derived types such as dirset or fileset. Note
+ this routine returns a value, not a reference, to avoid memory
+ leaks in the methods */
+struct icalset_impl icalset_get_impl(icalset* set)
+{
+ struct icalset_impl impl;
+
+ memset(&impl,0,sizeof(impl));
+ icalerror_check_arg_rv( (set!=0),"set");
+
+ if(strcmp((char*)set,ICALSET_ID)==0) {
+ /* It is actually a set, so just sent the reference back out. */
+ return *(struct icalset_impl*)set;
+ } else if(strcmp((char*)set,ICALFILESET_ID)==0) {
+ /* Make a new set from the fileset */
+ impl.fp = &icalset_fileset_fp;
+ impl.derived_impl = set;
+ strcpy(impl.id,ICALFILESET_ID);/* HACK. Is this necessary? */
+ return impl;
+ } else if(strcmp((char*)set,ICALDIRSET_ID)==0) {
+ /* Make a new set from the dirset */
+ impl.fp = &icalset_dirset_fp;
+ impl.derived_impl = set;
+ strcpy(impl.id,ICALDIRSET_ID);/* HACK. Is this necessary? */
+ return impl;
+ } else {
+ /* The type of set is unknown, so throw an error */
+ icalerror_assert((0),"Unknown set type");
+ return impl;
+ }
+}
+
+
+struct icalset_impl* icalset_new_impl()
+{
+
+ struct icalset_impl* impl;
+
+ if ( ( impl = (struct icalset_impl*)
+ malloc(sizeof(struct icalset_impl))) == 0) {
+ icalerror_set_errno(ICAL_NEWFAILED_ERROR);
+ return 0;
+ }
+
+ strcpy(impl->id,ICALSET_ID);
+
+ impl->derived_impl = 0;
+ impl->fp = 0;
+
+ return impl;
+}
+
+struct icalset_impl* icalset_new_file_from_ref(icalfileset *fset)
+{
+ struct icalset_impl *impl = icalset_new_impl();
+
+ icalerror_check_arg_rz( (fset!=0),"fset");
+
+ if(impl == 0){
+ free(impl);
+ return 0;
+ }
+
+ impl->derived_impl = fset;
+
+ if (impl->derived_impl == 0){
+ free(impl);
+ return 0;
+ }
+
+ impl->fp = &icalset_fileset_fp;
+
+ return (struct icalset_impl*)impl;
+}
+
+icalset* icalset_new_file(const char* path)
+{
+ icalfileset *fset = icalfileset_new(path);
+
+ if(fset == 0){
+ return 0;
+ }
+
+ return (icalset*)icalset_new_file_from_ref(fset);
+}
+
+icalset* icalset_new_dir_from_ref(icaldirset *dset)
+{
+
+ struct icalset_impl *impl = icalset_new_impl();
+
+ icalerror_check_arg_rz( (dset!=0),"dset");
+
+ if(impl == 0){
+ return 0;
+ }
+
+ impl->derived_impl = dset;
+
+ if (impl->derived_impl == 0){
+ free(impl);
+ return 0;
+ }
+
+ impl->fp = &icalset_dirset_fp;
+
+ return impl;
+}
+
+icalset* icalset_new_dir(const char* path)
+{
+ icaldirset *dset = icaldirset_new(path);
+
+ if(dset == 0){
+ return 0;
+ }
+
+ return icalset_new_dir_from_ref(dset);
+}
+
+icalset* icalset_new_heap(void)
+{
+ struct icalset_impl *impl = icalset_new_impl();
-char* icalset_path(icalset* set);
-void icalset_mark(icalset* set);
+ if(impl == 0){
+ free(impl);
+ return 0;
+ }
-icalerrorenum icalset_commit(icalset* set);
+ return 0;
+}
-icalerrorenum icalset_add_component(icalset* set, icalcomponent* comp);
+icalset* icalset_new_mysql(const char* path)
+{
+ struct icalset_impl *impl = icalset_new_impl();
-icalerrorenum icalset_remove_component(icalset* set, icalcomponent* comp);
+ if(impl == 0){
+ free(impl);
+ return 0;
+ }
-int icalset_count_components(icalset* set,
- icalcomponent_kind kind);
+ return 0;
+}
-icalerrorenum icalset_select(icalset* set, icalcomponent* gauge);
+void icalset_free(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->free))(impl.derived_impl);
-void icalset_clear_select(icalset* set);
+ if(strcmp((char*)set,ICALSET_ID)) {
+ free(set);
+ }
+}
-icalcomponent* icalset_fetch(icalset* set, char* uid);
+const char* icalset_path(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->path))(impl.derived_impl);
+}
-int icalset_has_uid(icalset* set, char* uid);
+void icalset_mark(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->mark))(impl.derived_impl);
+}
+
+icalerrorenum icalset_commit(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->commit))(impl.derived_impl);
+}
+
+icalerrorenum icalset_add_component(icalset* set, icalcomponent* comp)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->add_component))(impl.derived_impl,comp);
+}
+
+icalerrorenum icalset_remove_component(icalset* set, icalcomponent* comp)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->remove_component))(impl.derived_impl,comp);
+}
+
+int icalset_count_components(icalset* set,icalcomponent_kind kind)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->count_components))(impl.derived_impl,kind);
+}
+
+icalerrorenum icalset_select(icalset* set, icalcomponent* gauge)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->select))(impl.derived_impl,gauge);
+}
+
+void icalset_clear(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->clear))(impl.derived_impl);
+}
+
+icalcomponent* icalset_fetch(icalset* set, const char* uid)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->fetch))(impl.derived_impl,uid);
+}
+
+icalcomponent* icalset_fetch_match(icalset* set, icalcomponent *comp)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->fetch_match))(impl.derived_impl,comp);
+}
+
+
+int icalset_has_uid(icalset* set, const char* uid)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->has_uid))(impl.derived_impl,uid);
+}
icalerrorenum icalset_modify(icalset* set, icalcomponent *old,
- icalcomponent *new);
-
-icalcomponent* icalset_get_current_component(icalset* set);
-
-icalcomponent* icalset_get_first_component(icalset* set);
-
-icalcomponent* icalset_get_next_component(icalset* set);
+ icalcomponent *new)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->modify))(impl.derived_impl,old,new);
+}
+
+icalcomponent* icalset_get_current_component(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->get_current_component))(impl.derived_impl);
+}
+
+icalcomponent* icalset_get_first_component(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->get_first_component))(impl.derived_impl);
+}
+
+icalcomponent* icalset_get_next_component(icalset* set)
+{
+ struct icalset_impl impl = icalset_get_impl(set);
+ return (*(impl.fp->get_next_component))(impl.derived_impl);
+}
diff --git a/libical/src/libicalss/icalset.h b/libical/src/libicalss/icalset.h
index 15bb71f72e..d4678e3bed 100644
--- a/libical/src/libicalss/icalset.h
+++ b/libical/src/libicalss/icalset.h
@@ -52,15 +52,15 @@ typedef enum icalset_kind {
/* Create a specific derived type of set */
-icalset* icalset_new_file(char* path);
-icalset* icalset_new_dir(char* path);
+icalset* icalset_new_file(const char* path);
+icalset* icalset_new_dir(const char* path);
icalset* icalset_new_heap(void);
-icalset* icalset_new_mysql(char* path);
+icalset* icalset_new_mysql(const char* path);
/*icalset* icalset_new_cap(icalcstp* cstp);*/
void icalset_free(icalset* set);
-char* icalset_path(icalset* set);
+const char* icalset_path(icalset* set);
/* Mark the cluster as changed, so it will be written to disk when it
is freed. Commit writes to disk immediately*/
@@ -79,13 +79,14 @@ icalerrorenum icalset_select(icalset* set, icalcomponent* gauge);
void icalset_clear_select(icalset* set);
/* Get a component by uid */
-icalcomponent* icalset_fetch(icalset* set, char* uid);
-int icalset_has_uid(icalset* set, char* uid);
+icalcomponent* icalset_fetch(icalset* set, const char* uid);
+int icalset_has_uid(icalset* set, const char* uid);
+icalcomponent* icalset_fetch_match(icalset* set, icalcomponent *c);
/* Modify components according to the MODIFY method of CAP. Works on
the currently selected components. */
-icalerrorenum icalset_modify(icalset* set, icalcomponent *old,
- icalcomponent *new);
+icalerrorenum icalset_modify(icalset* set, icalcomponent *oldc,
+ icalcomponent *newc);
/* Iterate through the components. If a guage has been defined, these
will skip over components that do not pass the gauge */