Exemple #1
0
void component_errors(icalcomponent *comp)
{
    int errors;
    icalproperty *p;

    /* presume that we just got this component from the parser */

    errors = icalcomponent_count_errors(comp);

    printf("This component has %d parsing errors\n", errors);

    /* Print out all of the parsing errors. This is not strictly
       correct, because it does not descend into any sub-components,
       as icalcomponent_count_errors() does. */

    for(p = icalcomponent_get_first_property(comp,ICAL_XLICERROR_PROPERTY);
        p != 0;
        p = icalcomponent_get_next_property(comp,ICAL_XLICERROR_PROPERTY))
    {

        printf("-- The error is %s:\n",icalproperty_get_xlicerror(p));
    }



    /* Check the component for iTIP compilance, and add more
       X-LIC-ERROR properties if it is non-compilant. */
    icalrestriction_check(comp);


    /* Count the new errors.  */
    if(errors != icalcomponent_count_errors(comp)){
       printf(" -- The component also has iTIP restriction errors \n");
    }

    /* Since there are iTIP restriction errors, it may be impossible
       to process this component as an iTIP request. In this case, the
       X-LIC-ERROR proeprties should be expressed as REQUEST-STATUS
       properties in the reply. This following routine makes this
       conversion */


    icalcomponent_convert_errors(comp);

}
Exemple #2
0
void test_classify(void)
{
    icalcomponent *c, *match;
    int i = 0;
    int error_count = 0;

    /* Open up the two storage files, one for the incomming components,
       one for the calendar */
    icalfileset_options options = { O_RDONLY, 0644, 0, NULL };
    icalset *incoming = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/incoming.ics", &options);
    icalset *cal = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/calendar.ics", &options);
    icalset *f = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/classify.ics", &options);

    ok("opening file classify.ics", (f != 0));
    ok("opening file calendar.ics", (cal != 0));
    ok("opening file incoming.ics", (incoming != 0));

    /* some basic tests.. */
    if (f) {
        c = icalset_get_first_component(f);
        match = icalset_get_next_component(f);

        ok("test two vcalendars for SEQUENCE with icalclassify()",
           (icalclassify(c, match, "*****@*****.**") == ICAL_XLICCLASS_REQUESTRESCHEDULE));

        icalset_free(f);
    }

    assert(incoming != 0);
    assert(cal != 0);

    /* Iterate through all of the incoming components */
    for (c = icalset_get_first_component(incoming); c != 0;
         c = icalset_get_next_component(incoming)) {

        icalproperty_xlicclass class;
        icalcomponent *match = 0;
        const char *this_uid;
        const char *this_note = get_note(c);
        const char *expected_result = get_expect(c);
        const char *actual_result;
        char msg[128];

        i++;

        /* Check this component against the restrictions imposed by
           iTIP. An errors will be inserted as X-LIC-ERROR properties
           in the component. The Parser will also insert errors if it
           cannot parse the component */
        icalcomponent_check_restrictions(c);

        /* If there are any errors, print out the component */

        error_count = icalcomponent_count_errors(c);
        snprintf(msg, sizeof(msg), "%s - parsing", this_note);
        int_is(msg, error_count, 0);

        if (error_count != 0) {
            if (VERBOSE) {
                printf("----- Component has errors ------- \n%s-----------------\n",
                       icalcomponent_as_ical_string(c));
            }
        }

        /* Use one of the icalcomponent convenience routines to get
           the UID. This routine will save you from having to use
           icalcomponent_get_inner(),
           icalcomponent_get_first_property(), checking the return
           value, and then calling icalproperty_get_uid. There are
           several other convenience routines for DTSTART, DTEND,
           DURATION, SUMMARY, METHOD, and COMMENT */
        this_uid = icalcomponent_get_uid(c);

        if (this_uid != 0) {
            /* Look in the calendar for a component with the same UID
               as the incomming component. We should reall also be
               checking the RECURRENCE-ID. Another way to do this
               operation is to us icalset_find_match(), which does use
               the RECURRENCE-ID. */
            match = icalset_fetch(cal, this_uid);
        }

        /* Classify the incoming component. The third argument is the
           calid of the user who owns the calendar. In a real program,
           you would probably switch() on the class. */
        class = icalclassify(c, match, "*****@*****.**");
        /** eventually test this too.. **/
        (void)get_note(match);
        actual_result = icalproperty_enum_to_string(class);
        snprintf(msg, sizeof(msg), "expecting %s", expected_result);
        str_is(msg, expected_result, actual_result);

        if (VERBOSE) {
            printf("Test %d\n"
                   "Incoming:      %s\n"
                   "Matched:       %s\n"
                   "Classification: %s\n\n",
            i, this_note, get_note(match), icalproperty_enum_to_string(class));
        }
    }

    icalset_free(incoming);
    icalset_free(cal);
}