Back to index

lightning-sunbird  0.9+nobinonly
icalcluster.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: icalcluster.c
00004   CREATOR: acampi 13 March 2002
00005   
00006   $Id: icalcluster.c,v 1.3 2002/06/28 10:15:39 acampi Exp $
00007   $Locker:  $
00008     
00009  (C) COPYRIGHT 2002, Eric Busboom, http://www.softwarestudio.org
00010 
00011  This program is free software; you can redistribute it and/or modify
00012  it under the terms of either: 
00013 
00014     The LGPL as published by the Free Software Foundation, version
00015     2.1, available at: http://www.fsf.org/copyleft/lesser.html
00016 
00017   Or:
00018 
00019     The Mozilla Public License Version 1.0. You may obtain a copy of
00020     the License at http://www.mozilla.org/MPL/
00021 
00022  The Original Code is eric. The Initial Developer of the Original
00023  Code is Eric Busboom
00024 
00025 
00026  ======================================================================*/
00027 
00028 
00041 #ifdef HAVE_CONFIG_H
00042 #include "config.h"
00043 #endif
00044 
00045 #include <stdlib.h>
00046 #include <string.h>
00047 
00048 #if 0
00049 #include <errno.h>
00050 #include <sys/stat.h> /* for stat */
00051 #ifndef WIN32
00052 #include <unistd.h> /* for stat, getpid */
00053 #else
00054 #include <io.h>
00055 #include <share.h>
00056 #endif
00057 #include <fcntl.h> /* for fcntl */
00058 #endif
00059 
00060 #include "icalcluster.h"
00061 #include "icalclusterimpl.h"
00062 #include "icalgauge.h"
00063 
00064 #ifdef WIN32
00065 #define snprintf     _snprintf
00066 #define strcasecmp   stricmp
00067 #endif
00068 
00069 
00070 icalcluster * icalcluster_new_impl(void) {
00071 
00072        struct icalcluster_impl* impl;
00073   
00074        if ((impl = (struct icalcluster_impl*)malloc(
00075                             sizeof(struct icalcluster_impl))) == 0) {
00076               icalerror_set_errno(ICAL_NEWFAILED_ERROR);
00077               return 0;
00078        }
00079   
00080        memset(impl, 0, sizeof(struct icalcluster_impl));
00081        strcpy(impl->id,ICALCLUSTER_ID);
00082 
00083        return impl;
00084 }
00085 
00092 icalcluster * icalcluster_new(const char* key, icalcomponent *data) {
00093        struct icalcluster_impl *impl = icalcluster_new_impl();
00094        assert(impl->data == 0);
00095 
00096        impl->key     = strdup(key);
00097        impl->changed = 0;
00098        impl->data    = 0;
00099 
00100        if (data != NULL) {
00101               if (icalcomponent_isa(data) != ICAL_XROOT_COMPONENT) {
00102                      impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT);
00103                      icalcomponent_add_component(impl->data, data);
00104               } else {
00105                      impl->data = icalcomponent_new_clone(data);
00106               }
00107        } else {
00108               impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT);
00109        }
00110 
00111        return impl;
00112 }
00113 
00118 icalcluster *icalcluster_new_clone(const icalcluster *data) {
00119        struct icalcluster_impl *old = (struct icalcluster_impl *)data;
00120        struct icalcluster_impl *impl = icalcluster_new_impl();
00121 
00122        impl->key     = strdup(old->key);
00123        impl->data    = icalcomponent_new_clone(old->data);
00124        impl->changed = 0;
00125 
00126        return impl;
00127 }
00128 
00129 
00130 void icalcluster_free(icalcluster *impl) {
00131        icalerror_check_arg_rv((impl!=0),"cluster");
00132 
00133        if (impl->key != 0){
00134               free(impl->key);
00135               impl->key = 0;
00136        }
00137 
00138        if (impl->data != 0){
00139               icalcomponent_free(impl->data);
00140               impl->data = 0;
00141        }
00142 
00143        free(impl);
00144 }
00145 
00146 
00147 const char *icalcluster_key(icalcluster *impl) {
00148        icalerror_check_arg_rz((impl!=0),"cluster");
00149 
00150        return impl->key;
00151 }
00152 
00153 
00154 int icalcluster_is_changed(icalcluster *impl) {
00155        icalerror_check_arg_rz((impl!=0),"cluster");
00156 
00157        return impl->changed;
00158 }
00159 
00160 
00161 void icalcluster_mark(icalcluster *impl) {
00162        icalerror_check_arg_rv((impl!=0),"cluster");
00163 
00164        impl->changed = 1;
00165 }
00166 
00167 
00168 void icalcluster_commit(icalcluster *impl) {
00169        icalerror_check_arg_rv((impl!=0),"cluster");
00170 
00171        impl->changed = 0;
00172 }
00173 
00174 
00175 icalcomponent *icalcluster_get_component(icalcluster *impl) {
00176 
00177        icalerror_check_arg_rz((impl!=0),"cluster");
00178 
00179        if (icalcomponent_isa(impl->data) != ICAL_XROOT_COMPONENT) {
00180               icalerror_warn("The top component is not an XROOT");
00181               fprintf(stderr, "%s\n", icalcomponent_as_ical_string(impl->data));
00182               abort();
00183        }
00184 
00185        return impl->data;
00186 }
00187 
00188 
00189 icalerrorenum icalcluster_add_component(icalcluster *impl, icalcomponent* child) {
00190 
00191        icalerror_check_arg_re((impl!=0),"cluster", ICAL_BADARG_ERROR);
00192        icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR);
00193 
00194        icalcomponent_add_component(impl->data, child);
00195        icalcluster_mark(impl);
00196 
00197        return ICAL_NO_ERROR;
00198 }
00199 
00200 
00201 icalerrorenum icalcluster_remove_component(icalcluster *impl, icalcomponent* child) {
00202 
00203        icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR);
00204        icalerror_check_arg_re((child!=0),"child",ICAL_BADARG_ERROR);
00205 
00206        icalcomponent_remove_component(impl->data,child);
00207        icalcluster_mark(impl);
00208 
00209        return ICAL_NO_ERROR;
00210 }
00211 
00212 
00213 int icalcluster_count_components(icalcluster *impl, icalcomponent_kind kind) {
00214 
00215        icalerror_check_arg_re((impl!=0),"cluster",ICAL_BADARG_ERROR);
00216 
00217        return icalcomponent_count_components(impl->data, kind);
00218 }
00219 
00220 
00222 icalcomponent *icalcluster_get_current_component(icalcluster* impl) {
00223 
00224        icalerror_check_arg_rz((impl!=0),"cluster");
00225 
00226        return icalcomponent_get_current_component(impl->data);
00227 }
00228 
00229 
00230 icalcomponent *icalcluster_get_first_component(icalcluster* impl) {
00231 
00232        icalerror_check_arg_rz((impl!=0),"cluster");
00233 
00234        return icalcomponent_get_first_component(impl->data,
00235                                             ICAL_ANY_COMPONENT);
00236 }
00237 
00238 
00239 icalcomponent *icalcluster_get_next_component(icalcluster* impl) {
00240 
00241        icalerror_check_arg_rz((impl!=0),"cluster");
00242     
00243        return icalcomponent_get_next_component(impl->data,
00244                                         ICAL_ANY_COMPONENT);
00245 }