Back to index

lightning-sunbird  0.9+nobinonly
testclassify.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: testclassify.c
00004   CREATOR: eric 11 February 2000
00005   
00006   $Id: testclassify.c,v 1.5 2001/04/16 21:04:20 ebusboom Exp $
00007   $Locker:  $
00008     
00009  (C) COPYRIGHT 2000 Eric Busboom
00010  http://www.softwarestudio.org
00011 
00012  The contents of this file are subject to the Mozilla Public License
00013  Version 1.0 (the "License"); you may not use this file except in
00014  compliance with the License. You may obtain a copy of the License at
00015  http://www.mozilla.org/MPL/
00016  
00017  Software distributed under the License is distributed on an "AS IS"
00018  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00019  the License for the specific language governing rights and
00020  limitations under the License.
00021  
00022  The Original Code is eric. The Initial Developer of the Original
00023  Code is Eric Busboom
00024 
00025 
00026  ======================================================================*/
00027 
00028 #include <stdio.h> /* for printf */
00029 #include "ical.h"
00030 #include <errno.h>
00031 #include <string.h> /* For strerror */
00032 #include "icalss.h"
00033 
00034 /* Get a note about the purpose of the property*/
00035 const char* get_note(icalcomponent *c)
00036 {
00037     icalproperty *p;
00038     const char* note = 0;
00039 
00040     if(c != 0){
00041         for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY);
00042             p!= 0;
00043             p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){
00044             if(strcmp(icalproperty_get_x_name(p),"X-LIC-NOTE")==0){
00045             note = icalproperty_get_x(p);
00046             }
00047         }
00048     } 
00049     
00050     if(note == 0){
00051         note = "None";
00052     }
00053     
00054     return note;
00055 }
00056 
00057 
00058 int main(int argc, char* argv[])
00059 {
00060     icalcomponent *c;
00061     int i=0;
00062 
00063     /* Open up the two storage files, one for the incomming components, 
00064        one for the calendar */
00065     icalset* incoming = icalset_new_file("../../test-data/incoming.ics");
00066     icalset* cal = icalset_new_file("../../test-data/calendar.ics");
00067 
00068     assert(incoming!= 0);
00069     assert(cal!=0);
00070 
00071     /* Iterate through all of the incoming components */
00072     for(c=icalset_get_first_component(incoming);c!=0;
00073        c=icalset_get_next_component(incoming)){
00074        
00075        icalproperty_xlicclass class;
00076        icalcomponent *match = 0;
00077         const char* this_uid;
00078 
00079        i++;
00080 
00081         /* Check this component against the restrictions imposed by
00082            iTIP. An errors will be inserted as X-LIC-ERROR properties
00083            in the component. The Parser will also insert errors if it
00084            cannot parse the component */
00085         icalcomponent_check_restrictions(c);
00086 
00087         /* If there are any errors, print out the component */
00088         if(icalcomponent_count_errors(c) != 0){
00089             printf("----- Component has errors ------- \n%s-----------------\n",
00090                    icalcomponent_as_ical_string(c));
00091         }
00092 
00093         /* Use one of the icalcomponent convenience routines to get
00094            the UID. This routine will save you from having to use
00095            icalcomponent_get_inner(),
00096            icalcomponent_get_first_property(), checking the return
00097            value, and then calling icalproperty_get_uid. There are
00098            several other convenience routines for DTSTART, DTEND,
00099            DURATION, SUMMARY, METHOD, and COMMENT */
00100        this_uid = icalcomponent_get_uid(c);
00101 
00102         if(this_uid != 0){
00103             /* Look in the calendar for a component with the same UID
00104                as the incomming component. We should reall also be
00105                checking the RECURRENCE-ID. Another way to do this
00106                operation is to us icalset_find_match(), which does use
00107                the RECURRENCE-ID. */
00108             match = icalset_fetch(cal,this_uid);
00109         }
00110 
00111         
00112         /* Classify the incoming component. The third argument is the
00113            calid of the user who owns the calendar. In a real program,
00114            you would probably switch() on the class.*/
00115        class = icalclassify(c,match,"A@example.com");
00116 
00117        printf("Test %d\n\
00118 Incoming:      %s\n\
00119 Matched:       %s\n\
00120 Classification: %s\n\n",
00121                i,get_note(c),get_note(match),
00122                icalproperty_enum_to_string(class));     
00123     }
00124 
00125     return 0;
00126 }
00127 
00128