Back to index

lightning-sunbird  0.9+nobinonly
icalcalendar.c
Go to the documentation of this file.
00001 /*======================================================================
00002   FILE: icalcalendar.c
00003   CREATOR: eric 23 December 1999
00004   
00005   $Id: icalcalendar.c,v 1.6 2002/08/07 17:09:06 acampi Exp $
00006   $Locker:  $
00007     
00008  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
00009 
00010  This program is free software; you can redistribute it and/or modify
00011  it under the terms of either: 
00012 
00013     The LGPL as published by the Free Software Foundation, version
00014     2.1, available at: http://www.fsf.org/copyleft/lesser.html
00015 
00016   Or:
00017 
00018     The Mozilla Public License Version 1.0. You may obtain a copy of
00019     the License at http://www.mozilla.org/MPL/
00020 
00021  ======================================================================*/
00022 
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include "config.h"
00026 #endif
00027 
00028 
00029 #include "icalcalendar.h"
00030 #include "icalset.h"
00031 #include "icalfileset.h"
00032 #include "icaldirset.h"
00033 #include <limits.h> 
00034 #include <sys/stat.h> /* For mkdir, stat */
00035 #include <sys/types.h> /* For mkdir */
00036 #include <fcntl.h> /* For mkdir */
00037 
00038 #ifndef WIN32
00039 #include <unistd.h>  /* For mkdir, stat */    
00040 #endif
00041 
00042 #ifndef PATH_MAX
00043 #define PATH_MAX 512
00044 #endif
00045 
00046 
00047 #include <stdlib.h> /* for malloc */
00048 #include <string.h> /* for strcat */
00049 #include <errno.h>
00050 
00051 #define BOOKED_DIR "booked"
00052 #define INCOMING_FILE "incoming.ics"
00053 #define PROP_FILE "properties.ics"
00054 #define FBLIST_FILE "freebusy.ics"
00055 
00056 struct icalcalendar_impl 
00057 {
00058        char* dir;
00059        icalset* freebusy;
00060        icalset* properties;
00061        icalset* booked;
00062        icalset* incoming;
00063 };
00064 
00065 struct icalcalendar_impl* icalcalendar_new_impl(void)
00066 {
00067     struct icalcalendar_impl* impl;
00068 
00069     if ( ( impl = (struct icalcalendar_impl*)
00070           malloc(sizeof(struct icalcalendar_impl))) == 0) {
00071        icalerror_set_errno(ICAL_NEWFAILED_ERROR);
00072        return 0;
00073     }
00074 
00075     return impl;
00076 }
00077 
00078 
00079 icalerrorenum icalcalendar_create(struct icalcalendar_impl* impl)
00080 {
00081     char path[PATH_MAX];
00082     struct stat sbuf;
00083     int r;
00084     
00085     icalerror_check_arg_re((impl != 0),"impl",ICAL_BADARG_ERROR);
00086 
00087     path[0] = '\0';
00088     strcpy(path,impl->dir);
00089     strcat(path,"/");
00090     strcat(path,BOOKED_DIR);
00091 
00092     r = stat(path,&sbuf);
00093 
00094     if( r != 0 && errno == ENOENT){
00095 
00096        if(mkdir(path,0777)!=0){
00097            icalerror_set_errno(ICAL_FILE_ERROR);
00098            return ICAL_FILE_ERROR;
00099        }
00100     }
00101 
00102     return ICAL_NO_ERROR;
00103 }
00104 
00105 icalcalendar* icalcalendar_new(char* dir)
00106 {
00107     struct icalcalendar_impl* impl;
00108 
00109     icalerror_check_arg_rz((dir != 0),"dir");
00110     
00111     impl = icalcalendar_new_impl();
00112 
00113     if (impl == 0){
00114        return 0;
00115     }
00116 
00117     impl->dir = (char*)strdup(dir);
00118     impl->freebusy = 0;
00119     impl->properties = 0;
00120     impl->booked = 0;
00121     impl->incoming = 0;
00122 
00123     if (icalcalendar_create(impl) != ICAL_NO_ERROR){
00124        free(impl);
00125        return 0;
00126     }
00127 
00128     return impl;
00129 }
00130 
00131 void icalcalendar_free(icalcalendar* impl)
00132 {
00133     if (impl->dir !=0){
00134        free(impl->dir);
00135     }
00136 
00137     if (impl->freebusy !=0){
00138        icalset_free(impl->booked);
00139     }
00140 
00141     if (impl->properties !=0){
00142        icalset_free(impl->properties);
00143     }
00144 
00145     if (impl->booked !=0){
00146        icalset_free(impl->booked);
00147     }
00148 
00149     if (impl->incoming !=0){
00150        icalset_free(impl->incoming);
00151     }
00152 
00153     impl->dir = 0;
00154     impl->freebusy = 0;
00155     impl->properties = 0;
00156     impl->booked = 0;
00157     impl->incoming = 0;
00158 
00159 
00160     free(impl);
00161 }
00162 
00163 
00164 int icalcalendar_lock(icalcalendar* impl)
00165 {
00166     icalerror_check_arg_rz((impl != 0),"impl");
00167     return 0;
00168 }
00169 
00170 int icalcalendar_unlock(icalcalendar* impl)
00171 {
00172     icalerror_check_arg_rz((impl != 0),"impl");
00173     return 0;
00174 }
00175 
00176 int icalcalendar_islocked(icalcalendar* impl)
00177 {
00178     icalerror_check_arg_rz((impl != 0),"impl");
00179     return 0;
00180 }
00181 
00182 int icalcalendar_ownlock(icalcalendar* impl)
00183 {
00184     icalerror_check_arg_rz((impl != 0),"impl");
00185     return 0;
00186 }
00187 
00188 icalset* icalcalendar_get_booked(icalcalendar* impl)
00189 {
00190     char dir[PATH_MAX];
00191 
00192     icalerror_check_arg_rz((impl != 0),"impl");
00193     
00194     dir[0] = '\0';
00195     strcpy(dir,impl->dir);
00196     strcat(dir,"/");
00197     strcat(dir,BOOKED_DIR);
00198 
00199     if (impl->booked == 0){
00200        icalerror_clear_errno();
00201        impl->booked = icaldirset_new(dir);
00202        assert(icalerrno == ICAL_NO_ERROR);
00203     }
00204 
00205     return impl->booked;
00206 
00207 }
00208 
00209 icalset* icalcalendar_get_incoming(icalcalendar* impl)
00210 {
00211     char path[PATH_MAX];
00212     icalerror_check_arg_rz((impl != 0),"impl");
00213 
00214     path[0] = '\0';
00215     strcpy(path,impl->dir);
00216     strcat(path,"/");
00217     strcat(path,INCOMING_FILE);
00218 
00219     if (impl->properties == 0){
00220        impl->properties = icalfileset_new(path);
00221     }
00222 
00223     return impl->properties;
00224 }
00225 
00226 icalset* icalcalendar_get_properties(icalcalendar* impl)
00227 {
00228     char path[PATH_MAX];
00229     icalerror_check_arg_rz((impl != 0),"impl");
00230 
00231     path[0] = '\0';
00232     strcpy(path,impl->dir);
00233     strcat(path,"/");
00234     strcat(path,PROP_FILE);
00235 
00236     if (impl->properties == 0){
00237        impl->properties = icalfileset_new(path);
00238     }
00239 
00240     return impl->properties;
00241 }
00242 
00243 icalset* icalcalendar_get_freebusy(icalcalendar* impl)
00244 {
00245     char path[PATH_MAX];
00246     icalerror_check_arg_rz((impl != 0),"impl");
00247 
00248     path[0] = '\0';
00249     strcpy(path,impl->dir);
00250     strcat(path,"/");
00251     strcat(path,FBLIST_FILE);
00252 
00253 
00254     if (impl->freebusy == 0){
00255        impl->freebusy = icalfileset_new(path);
00256     }
00257 
00258     return impl->freebusy;
00259 }
00260 
00261 
00262 
00263