Back to index

lightning-sunbird  0.9+nobinonly
storage.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: storage.c
00004   CREATOR: eric 03 April 1999
00005   
00006   DESCRIPTION:
00007   
00008   $Id: storage.c,v 1.5 2002/07/16 10:04:08 acampi Exp $
00009   $Locker:  $
00010 
00011   (C) COPYRIGHT 1999 Eric Busboom 
00012   http://www.softwarestudio.org
00013 
00014   The contents of this file are subject to the Mozilla Public License
00015   Version 1.0 (the "License"); you may not use this file except in
00016   compliance with the License. You may obtain a copy of the License at
00017   http://www.mozilla.org/MPL/
00018  
00019   Software distributed under the License is distributed on an "AS IS"
00020   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00021   the License for the specific language governing rights and
00022   limitations under the License.
00023 
00024   The original author is Eric Busboom
00025   The original code is usecases.c
00026 
00027     
00028   ======================================================================*/
00029 
00030 #include "ical.h"
00031 #include <assert.h>
00032 #include <string.h> /* for strdup */
00033 #include <stdlib.h> /* for malloc */
00034 #include <stdio.h> /* for printf */
00035 #include <time.h> /* for time() */
00036 #include "icalmemory.h"
00037 #include "icaldirset.h"
00038 #include "icalfileset.h"
00039 #ifdef WITH_BDB4
00040 #include "icalbdbset.h"
00041 #endif
00042 #include "icalerror.h"
00043 #include "icalrestriction.h"
00044 #include "icalcalendar.h"
00045 
00046 #define OUTPUT_FILE "filesetout.ics"
00047 #define DATABASE "calendar.db"
00048 
00049 /* define sample calendar struct */
00050 struct calendar {
00051   int ID;
00052   int total_size;
00053 
00054   /* offsets */
00055   int total_size_offset;
00056   int vcalendar_size_offset;
00057   int vcalendar_offset;
00058   int title_size_offset;
00059   int title_offset;
00060 
00061   /* data */
00062   int vcalendar_size;
00063   char *vcalendar;
00064 
00065   int title_size;
00066   char *title;
00067 
00068 };
00069 
00070 int vcalendar_init(struct calendar **cal, char *vcalendar, char *title);
00071 
00072 #ifdef WITH_BDB4
00073 int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey);
00074 char * parse_vcalendar(const DBT *dbt) ;
00075 #endif
00076 
00077 char * pack_calendar(struct calendar *cal, int size);
00078 struct calendar * unpack_calendar(char *str, int size);
00079 
00080 char str[] = "BEGIN:VCALENDAR\n\
00081 PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\
00082 VERSION:2.0\n\
00083 BEGIN:VTIMEZONE\n\
00084 TZID:US-Eastern\n\
00085 BEGIN:STANDARD\n\
00086 DTSTART:19981025T020000\n\
00087 RDATE:19981025T020000\n\
00088 TZOFFSETFROM:-0400\n\
00089 TZOFFSETTO:-0500\n\
00090 TZNAME:EST\n\
00091 END:STANDARD\n\
00092 BEGIN:DAYLIGHT\n\
00093 DTSTART:19990404T020000\n\
00094 RDATE:19990404T020000\n\
00095 TZOFFSETFROM:-0500\n\
00096 TZOFFSETTO:-0400\n\
00097 TZNAME:EDT\n\
00098 END:DAYLIGHT\n\
00099 END:VTIMEZONE\n\
00100 BEGIN:VEVENT\n\
00101 DTSTAMP:19980309T231000Z\n\
00102 UID:guid-1.host1.com\n\
00103 ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\
00104 ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\
00105 DESCRIPTION:Project XYZ Review Meeting\n\
00106 CATEGORIES:MEETING\n\
00107 CLASS:PUBLIC\n\
00108 CREATED:19980309T130000Z\n\
00109 SUMMARY:XYZ Project Review\n\
00110 DTSTART;TZID=US-Eastern:19980312T083000\n\
00111 DTEND;TZID=US-Eastern:19980312T093000\n\
00112 LOCATION:1CP Conference Room 4350\n\
00113 END:VEVENT\n\
00114 BEGIN:BOOGA\n\
00115 DTSTAMP:19980309T231000Z\n\
00116 X-LIC-FOO:Booga\n\
00117 DTSTOMP:19980309T231000Z\n\
00118 UID:guid-1.host1.com\n\
00119 END:BOOGA\n\
00120 END:VCALENDAR";
00121 
00122 char str2[] = "BEGIN:VCALENDAR\n\
00123 PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\n\
00124 VERSION:2.0\n\
00125 BEGIN:VEVENT\n\
00126 DTSTAMP:19980309T231000Z\n\
00127 UID:guid-1.host1.com\n\
00128 ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\n\
00129 ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\n\
00130 DESCRIPTION:Project XYZ Review Meeting\n\
00131 CATEGORIES:MEETING\n\
00132 CLASS:PUBLIC\n\
00133 CREATED:19980309T130000Z\n\
00134 SUMMARY:XYZ Project Review\n\
00135 DTSTART;TZID=US-Eastern:19980312T083000\n\
00136 DTEND;TZID=US-Eastern:19980312T093000\n\
00137 LOCATION:1CP Conference Room 4350\n\
00138 END:VEVENT\n\
00139 END:VCALENDAR\n\
00140 ";
00141 
00142 void test_fileset()
00143 {
00144     icalfileset *cout;
00145     int month = 0;
00146     int count=0;
00147     struct icaltimetype start, end;
00148     icalcomponent *c,*clone, *itr;
00149 
00150     start = icaltime_from_timet( time(0),0);
00151     end = start;
00152     end.hour++;
00153 
00154     cout = icalfileset_new(OUTPUT_FILE);
00155     assert(cout != 0);
00156 
00157     c = icalparser_parse_string(str2);
00158     assert(c != 0);
00159 
00160     /* Add data to the file */
00161 
00162     for(month = 1; month < 10; month++){
00163        icalcomponent *event;
00164        icalproperty *dtstart, *dtend;
00165 
00166         cout = icalfileset_new(OUTPUT_FILE);
00167         assert(cout != 0);
00168 
00169        start.month = month; 
00170        end.month = month;
00171        
00172        clone = icalcomponent_new_clone(c);
00173        assert(clone !=0);
00174        event = icalcomponent_get_first_component(clone,ICAL_VEVENT_COMPONENT);
00175        assert(event != 0);
00176 
00177        dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00178        assert(dtstart!=0);
00179        icalproperty_set_dtstart(dtstart,start);
00180         
00181        dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00182        assert(dtend!=0);
00183        icalproperty_set_dtend(dtend,end);
00184        
00185        icalfileset_add_component(cout,clone);
00186        icalfileset_commit(cout);
00187 
00188         icalset_free(cout);
00189 
00190     }
00191 
00192     /* Print them out */
00193 
00194     cout = icalfileset_new(OUTPUT_FILE);
00195     assert(cout != 0);
00196     
00197     for (itr = icalfileset_get_first_component(cout);
00198          itr != 0;
00199          itr = icalfileset_get_next_component(cout)){
00200 
00201       icalcomponent *event;
00202       icalproperty *dtstart, *dtend;
00203 
00204       count++;
00205 
00206       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00207 
00208       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00209       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00210       
00211       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00212              icalproperty_as_ical_string(dtend));
00213 
00214     }
00215 
00216     /* Remove all of them */
00217 
00218     icalset_free(cout);
00219 
00220     cout = icalfileset_new(OUTPUT_FILE);
00221     assert(cout != 0);
00222     
00223     for (itr = icalfileset_get_first_component(cout);
00224          itr != 0;
00225          itr = icalfileset_get_next_component(cout)){
00226 
00227 
00228       icalfileset_remove_component(cout, itr);
00229     }
00230 
00231     icalset_free(cout);
00232 
00233 
00234     /* Print them out again */
00235 
00236     cout = icalfileset_new(OUTPUT_FILE);
00237     assert(cout != 0);
00238     count =0;
00239     
00240     for (itr = icalfileset_get_first_component(cout);
00241          itr != 0;
00242          itr = icalfileset_get_next_component(cout)){
00243 
00244       icalcomponent *event;
00245       icalproperty *dtstart, *dtend;
00246 
00247       count++;
00248 
00249       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00250 
00251       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00252       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00253       
00254       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00255              icalproperty_as_ical_string(dtend));
00256 
00257     }
00258 
00259     icalset_free(cout);
00260 
00261 
00262 }
00263 
00264 /*
00265    In this example, we're storing a calendar with several components
00266    under the reference id "calendar_7286" and retrieving records based
00267    on title, "month_1" through "month_10".  We use a number of the 
00268    "optional" arguments to specify secondary indices, sub-databases
00269    (i.e. having multiple databases residing within a single Berkeley
00270    DB file), and keys for storage and retrieval.
00271 */
00272 
00273 #ifdef WITH_BDB4
00274 void test_bdbset()
00275 {
00276     icalbdbset *cout;
00277     int month = 0;
00278     int count=0;
00279     int num_components=0;
00280     int szdata_len=0;
00281     int ret=0;
00282     char *subdb, *szdata, *szpacked_data;
00283     char uid[255];
00284     struct icaltimetype start, end;
00285     icalcomponent *c,*clone, *itr;
00286     DB *dbp, *sdbp;
00287     DBT key, data;
00288     DBC *dbcp;
00289 
00290     struct calendar *cal;
00291     int cal_size;
00292 
00293     start = icaltime_from_timet( time(0),0);
00294     end = start;
00295     end.hour++;
00296 
00297     /* Note: as per the Berkeley DB ref pages: 
00298      *
00299      * The database argument is optional, and allows applications to
00300      * have multiple databases in a single file. Although no database
00301      * argument needs to be specified, it is an error to attempt to
00302      * open a second database in a file that was not initially created
00303      * using a database name. 
00304      *
00305      */
00306 
00307     subdb = "calendar_id";
00308     sdbp = 0;
00309 
00310     /* open database, using subdb */
00311     dbp = icalbdbset_database_open(DATABASE, subdb, DB_HASH);
00312     sdbp = icalbdbset_secondary_open(dbp, 
00313                                  DATABASE, 
00314                                  "title", 
00315                                  get_title, 
00316                                  DB_HASH); 
00317 
00318     c = icalparser_parse_string(str2);
00319     assert(c != 0);
00320 
00321     /* Add data to the file */
00322 
00323     for(month = 1; month < 10; month++){
00324       icalcomponent *event;
00325       icalproperty *dtstart, *dtend, *location;
00326 
00327       /* retrieve data */
00328       cout = icalbdbset_new(dbp, sdbp, NULL);  
00329       assert(cout != 0);
00330 
00331       start.month = month; 
00332       end.month = month;
00333               
00334       clone = icalcomponent_new_clone(c);
00335       assert(clone !=0);
00336       event = icalcomponent_get_first_component(clone,
00337                                           ICAL_VEVENT_COMPONENT);
00338       assert(event != 0);
00339 
00340       dtstart = icalcomponent_get_first_property(event,
00341                                            ICAL_DTSTART_PROPERTY);
00342       assert(dtstart!=0);
00343       icalproperty_set_dtstart(dtstart,start);
00344         
00345       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00346       assert(dtend!=0);
00347       icalproperty_set_dtend(dtend,end);
00348 
00349       location = icalcomponent_get_first_property(event, ICAL_LOCATION_PROPERTY);
00350       assert(location!=0);
00351 
00352 #if 0
00353       /* change the uid to include the month */
00354       sprintf(uid, "%s_%d", icalcomponent_get_uid(clone), month);
00355       icalcomponent_set_uid(clone, uid);
00356 #endif
00357 
00358       icalbdbset_add_component(cout,clone);
00359 
00360       /* commit changes */
00361       icalbdbset_commit(cout);
00362 
00363       num_components = icalcomponent_count_components(clone, ICAL_ANY_COMPONENT);
00364 
00365       icalset_free(cout); 
00366 
00367     }
00368 
00369     /* try out the cursor operations */
00370     memset(&key, 0, sizeof(DBT));
00371     memset(&data, 0, sizeof(DBT));
00372     
00373     ret = icalbdbset_acquire_cursor(dbp, &dbcp);
00374     ret = icalbdbset_get_first(dbcp, &key, &data);
00375     ret = icalbdbset_get_next(dbcp, &key, &data);
00376     ret = icalbdbset_get_last(dbcp, &key, &data);
00377 
00378     /* Print them out */
00379 
00380     for(month = 1, count=0; month < 10; month++){
00381       char *title;
00382 
00383       icalcomponent *event;
00384       icalproperty *dtstart, *dtend;
00385 
00386       cout = icalbdbset_new(dbp, sdbp, NULL);
00387       assert(cout != 0);
00388     
00389       for (itr = icalbdbset_get_first_component(cout);
00390           itr != 0;
00391           itr = icalbdbset_get_next_component(cout)){
00392 
00393        icalcomponent *event;
00394        icalproperty *dtstart, *dtend;
00395 
00396        count++;
00397 
00398       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00399 
00400       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00401       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00402       
00403       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00404              icalproperty_as_ical_string(dtend));
00405 
00406       }
00407       icalset_free(cout);
00408     }
00409 
00410     /* close database */
00411     icalbdbset_database_close(dbp);
00412     icalbdbset_database_close(sdbp); 
00413 
00414     /* open database */
00415     dbp = icalbdbset_database_open(DATABASE, subdb, DB_HASH);
00416     sdbp = icalbdbset_secondary_open(dbp, 
00417                                  DATABASE, 
00418                                  "title", 
00419                                  get_title, 
00420                                  DB_HASH); 
00421 
00422     /* Remove all of them */
00423     for(month = 1; month < 10; month++){
00424 
00425       cout = icalbdbset_new(dbp, sdbp, NULL);
00426       assert(cout != 0);
00427     
00428       for (itr = icalbdbset_get_first_component(cout);
00429           itr != 0;
00430           itr = icalbdbset_get_next_component(cout)){
00431        
00432        icalbdbset_remove_component(cout, itr);
00433       }
00434 
00435       icalbdbset_commit(cout);
00436       icalset_free(cout);
00437 
00438     }
00439 
00440     /* Print them out again */
00441 
00442     for(month = 1, count=0; month < 10; month++){
00443       char *title;
00444 
00445       icalcomponent *event;
00446       icalproperty *dtstart, *dtend;
00447 
00448       cout = icalbdbset_new(dbp, sdbp, NULL);
00449       assert(cout != 0);
00450     
00451       for (itr = icalbdbset_get_first_component(cout);
00452           itr != 0;
00453           itr = icalbdbset_get_next_component(cout)){
00454 
00455        icalcomponent *event;
00456        icalproperty *dtstart, *dtend;
00457 
00458        count++;
00459 
00460       event = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00461 
00462       dtstart = icalcomponent_get_first_property(event,ICAL_DTSTART_PROPERTY);
00463       dtend = icalcomponent_get_first_property(event,ICAL_DTEND_PROPERTY);
00464       
00465       printf("%d %s %s\n",count, icalproperty_as_ical_string(dtstart),
00466              icalproperty_as_ical_string(dtend));
00467 
00468       }
00469       icalset_free(cout);
00470     }
00471 }
00472 
00473 /* get_title -- extracts a secondary key (the vcalendar)
00474  * from a primary key/data pair */
00475 
00476 /* just create a random title for now */
00477 
00478 int get_title(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey)
00479 {
00480   icalcomponent *cl;
00481   char title[255];
00482 
00483   memset(skey, 0, sizeof(DBT)); 
00484 
00485   cl = icalparser_parse_string((char *)pdata->data);
00486   sprintf(title, "title_%s", icalcomponent_get_uid(cl));
00487 
00488   skey->data = strdup(title);
00489   skey->size = strlen(skey->data);
00490   return (0); 
00491 }
00492 
00493 char * parse_vcalendar(const DBT *dbt) 
00494 {
00495   char *str;
00496   struct calendar *cal;
00497 
00498   str = (char *)dbt->data;
00499   cal = unpack_calendar(str, dbt->size);
00500 
00501   return cal->vcalendar;
00502 }
00503 
00504 #endif
00505 
00506 
00507 int vcalendar_init(struct calendar **rcal, char *vcalendar, char *title) 
00508 {
00509   int vcalendar_size, title_size, total_size;
00510   struct calendar *cal;
00511 
00512   if(vcalendar) 
00513     vcalendar_size = strlen(vcalendar);
00514   else {
00515     vcalendar = "";
00516     vcalendar_size = strlen(vcalendar);
00517   }
00518 
00519   if(title) 
00520     title_size = strlen(title);
00521   else {
00522     title = "";
00523     title_size = strlen(title);
00524   }
00525 
00526   total_size = sizeof(struct calendar) + vcalendar_size + title_size;
00527 
00528   if((cal = (struct calendar *)malloc(total_size))==NULL)
00529     return 0;
00530   memset(cal, 0, total_size);
00531 
00532   /* offsets */
00533   cal->total_size_offset     = sizeof(int);
00534   cal->vcalendar_size_offset = (sizeof(int) * 7);
00535   cal->vcalendar_offset      = cal->vcalendar_size_offset + sizeof(int);
00536   cal->title_size_offset     = cal->vcalendar_offset + vcalendar_size;
00537   cal->title_offset          = cal->title_size_offset + sizeof(int);
00538 
00539   /* sizes */
00540   cal->total_size            = total_size;
00541   cal->vcalendar_size        = vcalendar_size;
00542   cal->title_size            = title_size;
00543 
00544   if (vcalendar && *vcalendar) 
00545     cal->vcalendar = strdup(vcalendar);
00546 
00547   if (title && *title)
00548     cal->title     = strdup(title);
00549 
00550   *rcal = cal;
00551 
00552   return 0;
00553 }
00554 
00555 char * pack_calendar(struct calendar *cal, int size) 
00556 {
00557   char *str;
00558 
00559   if((str = (char *)malloc(sizeof(char) * size))==NULL)
00560     return 0;
00561 
00562   /* ID */
00563   memcpy(str, &cal->ID, sizeof(cal->ID));
00564 
00565   /* total_size */
00566   memcpy(str + cal->total_size_offset,
00567         &cal->total_size,
00568         sizeof(cal->total_size));
00569 
00570   /* vcalendar_size */
00571   memcpy(str + cal->vcalendar_size_offset, 
00572          &cal->vcalendar_size, 
00573          sizeof(cal->vcalendar_size));
00574 
00575   /* vcalendar */
00576   memcpy(str + cal->vcalendar_offset, 
00577          cal->vcalendar, 
00578          cal->vcalendar_size);
00579 
00580   /* title_size */
00581   memcpy(str + cal->title_size_offset,
00582         &cal->title_size,
00583         sizeof(cal->title_size));
00584 
00585   /* title */
00586   memcpy(str + cal->title_offset,
00587         cal->title,
00588         cal->title_size);
00589 
00590   return str;
00591 }
00592 
00593 struct calendar * unpack_calendar(char *str, int size)
00594 {
00595   struct calendar *cal;
00596   if((cal = (struct calendar *) malloc(size))==NULL)
00597     return 0;
00598   memset(cal, 0, size);
00599 
00600   /* offsets */
00601   cal->total_size_offset     = sizeof(int);
00602   cal->vcalendar_size_offset = (sizeof(int) * 7);
00603   cal->vcalendar_offset      = cal->vcalendar_size_offset + sizeof(int);
00604 
00605   /* ID */
00606   memcpy(&cal->ID, str, sizeof(cal->ID));
00607 
00608   /* total_size */
00609   memcpy(&cal->total_size,
00610         str + cal->total_size_offset,
00611         sizeof(cal->total_size));
00612 
00613   /* vcalendar_size */
00614   memcpy(&cal->vcalendar_size, 
00615         str + cal->vcalendar_size_offset, 
00616         sizeof(cal->vcalendar_size));
00617 
00618   if((cal->vcalendar = (char *)malloc(sizeof(char) * 
00619                                   cal->vcalendar_size))==NULL)
00620     return 0;
00621 
00622   /* vcalendar */
00623   memcpy(cal->vcalendar, 
00624         (char *)(str + cal->vcalendar_offset), 
00625         cal->vcalendar_size);
00626 
00627   cal->title_size_offset     = cal->vcalendar_offset + cal->vcalendar_size;
00628   cal->title_offset          = cal->title_size_offset + sizeof(int);
00629 
00630   /* title_size */
00631   memcpy(&cal->title_size,
00632         str + cal->title_size_offset,
00633         sizeof(cal->title_size));
00634 
00635   if((cal->title = (char *)malloc(sizeof(char) *
00636                               cal->title_size))==NULL)
00637     return 0;
00638 
00639   /* title*/
00640   memcpy(cal->title,
00641         (char *)(str + cal->title_offset),
00642         cal->title_size);
00643 
00644   return cal;
00645 }
00646 
00647 int test_dirset()
00648 {
00649 
00650     icalcomponent *c, *gauge;
00651     icalerrorenum error;
00652     icalcomponent *itr;
00653     icalfileset* cluster;
00654     struct icalperiodtype rtime;
00655     icaldirset *s = icaldirset_new("store");
00656     int i;
00657 
00658     assert(s != 0);
00659 
00660     rtime.start = icaltime_from_timet( time(0),0);
00661 
00662     cluster = icalfileset_new(OUTPUT_FILE);
00663 
00664     assert(cluster != 0);
00665 
00666 #define NUMCOMP 4
00667 
00668     /* Duplicate every component in the cluster NUMCOMP times */
00669 
00670     icalerror_clear_errno();
00671 
00672     for (i = 1; i<NUMCOMP+1; i++){
00673 
00674        /*rtime.start.month = i%12;*/
00675        rtime.start.month = i;
00676        rtime.end = rtime.start;
00677        rtime.end.hour++;
00678        
00679        for (itr = icalfileset_get_first_component(cluster);
00680             itr != 0;
00681             itr = icalfileset_get_next_component(cluster)){
00682            icalcomponent *clone, *inner;
00683            icalproperty *p;
00684 
00685            inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00686             if (inner == 0){
00687               continue;
00688             }
00689 
00690            /* Change the dtstart and dtend times in the component
00691                pointed to by Itr*/
00692 
00693            clone = icalcomponent_new_clone(itr);
00694            inner = icalcomponent_get_first_component(itr,ICAL_VEVENT_COMPONENT);
00695 
00696            assert(icalerrno == ICAL_NO_ERROR);
00697            assert(inner !=0);
00698 
00699            /* DTSTART*/
00700            p = icalcomponent_get_first_property(inner,ICAL_DTSTART_PROPERTY);
00701            assert(icalerrno  == ICAL_NO_ERROR);
00702 
00703            if (p == 0){
00704               p = icalproperty_new_dtstart(rtime.start);
00705               icalcomponent_add_property(inner,p);
00706            } else {
00707               icalproperty_set_dtstart(p,rtime.start);
00708            }
00709            assert(icalerrno  == ICAL_NO_ERROR);
00710 
00711            /* DTEND*/
00712            p = icalcomponent_get_first_property(inner,ICAL_DTEND_PROPERTY);
00713            assert(icalerrno  == ICAL_NO_ERROR);
00714 
00715            if (p == 0){
00716               p = icalproperty_new_dtstart(rtime.end);
00717               icalcomponent_add_property(inner,p);
00718            } else {
00719               icalproperty_set_dtstart(p,rtime.end);
00720            }
00721            assert(icalerrno  == ICAL_NO_ERROR);
00722            
00723            printf("\n----------\n%s\n---------\n",icalcomponent_as_ical_string(inner));
00724 
00725            error = icaldirset_add_component(s,
00726                                         icalcomponent_new_clone(itr));
00727            
00728            assert(icalerrno  == ICAL_NO_ERROR);
00729 
00730        }
00731 
00732     }
00733     
00734     gauge = 
00735        icalcomponent_vanew(
00736            ICAL_VCALENDAR_COMPONENT,
00737            icalcomponent_vanew(
00738               ICAL_VEVENT_COMPONENT,  
00739               icalproperty_vanew_summary(
00740                   "Submit Income Taxes",
00741                   icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL),
00742                   0),
00743               0),
00744            icalcomponent_vanew(
00745               ICAL_VEVENT_COMPONENT,  
00746               icalproperty_vanew_summary(
00747                   "Bastille Day Party",
00748                   icalparameter_new_xliccomparetype(ICAL_XLICCOMPARETYPE_EQUAL),
00749                   0),
00750               0),
00751            0);
00752 
00753 #if 0
00754 
00755 
00756     icaldirset_select(s,gauge);
00757 
00758     for(c = icaldirset_first(s); c != 0; c = icaldirset_next(s)){
00759        
00760        printf("Got one! (%d)\n", count++);
00761        
00762        if (c != 0){
00763            printf("%s", icalcomponent_as_ical_string(c));;
00764            if (icaldirset_store(s2,c) == 0){
00765               printf("Failed to write!\n");
00766            }
00767            icalcomponent_free(c);
00768        } else {
00769            printf("Failed to get component\n");
00770        }
00771     }
00772 
00773 
00774     icalset_free(s2);
00775 #endif
00776 
00777 
00778     for(c = icaldirset_get_first_component(s); 
00779        c != 0; 
00780        c = icaldirset_get_next_component(s)){
00781 
00782        if (c != 0){
00783            printf("%s", icalcomponent_as_ical_string(c));;
00784        } else {
00785            printf("Failed to get component\n");
00786        }
00787 
00788     }
00789 
00790     /* Remove all of the components */
00791     i=0;
00792     while((c=icaldirset_get_current_component(s)) != 0 ){
00793        i++;
00794 
00795        icaldirset_remove_component(s,c);
00796     }
00797        
00798 
00799     icalset_free(s);
00800     return 0;
00801 }
00802 
00803 #if 0
00804 void test_calendar()
00805 {
00806     icalcomponent *comp;
00807     icalfileset *c;
00808     icaldirset *s;
00809     icalcalendar* calendar = icalcalendar_new("calendar");
00810     icalerrorenum error;
00811     struct icaltimetype atime = icaltime_null_time();
00812 
00813     comp = icalcomponent_vanew(
00814        ICAL_VEVENT_COMPONENT,
00815        icalproperty_new_version("2.0"),
00816        icalproperty_new_description("This is an event"),
00817        icalproperty_new_dtstart(atime),
00818        icalproperty_vanew_comment(
00819            "Another Comment",
00820            icalparameter_new_cn("A Common Name 1"),
00821            icalparameter_new_cn("A Common Name 2"),
00822            icalparameter_new_cn("A Common Name 3"),
00823               icalparameter_new_cn("A Common Name 4"),
00824            0),
00825        icalproperty_vanew_xlicerror(
00826            "This is only a test",
00827            icalparameter_new_xlicerrortype(ICAL_XLICERRORTYPE_COMPONENTPARSEERROR),
00828            0),
00829        
00830        0);
00831        
00832        
00833     s = icalcalendar_get_booked(calendar);
00834 
00835     error = icaldirset_add_component(s,comp);
00836     
00837     assert(error == ICAL_NO_ERROR);
00838 
00839     c = icalcalendar_get_properties(calendar);
00840 
00841     error = icalfileset_add_component(c,icalcomponent_new_clone(comp));
00842 
00843     assert(error == ICAL_NO_ERROR);
00844 
00845     icalcalendar_free(calendar);
00846 
00847 }
00848 #endif
00849 
00850 int main(int argc, char *argv[])
00851 {
00852 
00853     printf("\n------------Test File Set---------------\n");
00854     test_fileset(); 
00855 
00856     printf("\n------------Test Dir Set---------------\n");
00857     test_dirset();
00858 
00859 #ifdef WITH_BDB4
00860     printf("\n------------Test BerkeleyDB Set---------------\n");
00861     test_bdbset();
00862 #endif
00863 
00864 #if 0
00865     printf("\n------------Test Calendar---------------\n");
00866     test_calendar();
00867 #endif
00868 
00869     return 0;
00870 }
00871 
00872 
00873