diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/.svnignore | 7 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 23 | ||||
-rw-r--r-- | examples/access-usecases.txt | 60 | ||||
-rw-r--r-- | examples/access_components.c | 318 | ||||
-rw-r--r-- | examples/access_properties_and_parameters.c | 151 | ||||
-rw-r--r-- | examples/access_store.c | 210 | ||||
-rw-r--r-- | examples/changenames.pl | 4 | ||||
-rw-r--r-- | examples/errors.c | 70 | ||||
-rw-r--r-- | examples/main.c | 12 | ||||
-rw-r--r-- | examples/parse_text.c | 70 | ||||
-rw-r--r-- | examples/usecases.c | 97 |
11 files changed, 1022 insertions, 0 deletions
diff --git a/examples/.svnignore b/examples/.svnignore new file mode 100644 index 00000000..b15541d8 --- /dev/null +++ b/examples/.svnignore @@ -0,0 +1,7 @@ +Makefile +.deps +.libs +*.lo +*.la +doesnothing +Makefile.in diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..3379ffd8 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src + ${CMAKE_SOURCE_DIR}/src/libical ${CMAKE_BINARY_DIR}/src/libical + ${CMAKE_SOURCE_DIR}/src/libicalss ${CMAKE_BINARY_DIR}/src/libicalss +) + +########### next target ############### + +set(doesnothing_SRCS + access_components.c + access_properties_and_parameters.c + errors.c + main.c + parse_text.c +) + +add_executable(doesnothing ${doesnothing_SRCS}) + +target_link_libraries(doesnothing ical icalss icalvcal ical icalss icalvcal) + +########### install files ############### + diff --git a/examples/access-usecases.txt b/examples/access-usecases.txt new file mode 100644 index 00000000..9bcb7544 --- /dev/null +++ b/examples/access-usecases.txt @@ -0,0 +1,60 @@ + + +Usecases +--------- + +1) iMIP based CUA uses a local, file-based store + +2) CAP based CUA uses one or more remote CAP servers + +3) CAP based CUA uses a local cache that synchronizes with one or more +CAP servers. + +4) CUA imports and exports from a file + +Scenarios. +--------- + +1 Open a connection to a store. + +2 Create a new calendar for which user Bob can read and user Alice can +read an write. + +3 Create several new calendars + +4 Delete a calendar + +5 Change the calid of a calendar + +6 Delete all calendars belonging to user bob + +7 Get three new UIDs from the store + +8 Store a new VEVENT in the store. + +9 Find all components for which the LOCATION is "West Conference Room" +and change them to "East Conference Room" + +10 Find the component with UID X and add a GEO property to it. + +11 Delete all VEVENTS which have a METHOD that is not CREATED + +12 Retrieve all VEVENTS which have a METHOD that is not CREATED + +13 Retrieve the capabilities of the store + +14 Retrieve/Modify/Add/Delete properties of a store + +15 Retrieve/Modify/Add/Delete VCARs of a store + +16 Retrieve/Modify/Add/Delete VTIMEZONEs of a store + +17 Retrieve/Modify/Add/Delete properties of a calendar + +18 Retrieve/Modify/Add/Delete VCARs of a calendar + +19 Retrieve/Modify/Add/Delete VTIMEZONEs of a calendar + +20 Translate a CALID into one or more UPNs + +21 Expand a group UPN into all of the members of the group
\ No newline at end of file diff --git a/examples/access_components.c b/examples/access_components.c new file mode 100644 index 00000000..796ce475 --- /dev/null +++ b/examples/access_components.c @@ -0,0 +1,318 @@ +/* Access_component.c */ + +#include <libical/ical.h> + +#include <assert.h> +#include <string.h> /* for strdup */ +#include <stdlib.h> /* for malloc */ +#include <stdio.h> /* for printf */ +#include <time.h> /* for time() */ + +void do_something(icalcomponent *c); + +/* Creating iCal Components + + There are two ways to create new component in libical. You can + build the component from primitive parts, or you can create it + from a string. + + There are two variations of the API for building the component from + primitive parts. In the first variation, you add each parameter and + value to a property, and then add each property to a + component. This results in a long series of function calls. This + style is show in create_new_component() + + The second variation uses vargs lists to nest many primitive part + constructors, resulting in a compact, neatly formated way to create + components. This style is shown in create_new_component_with_va_args() + + + +*/ + +icalcomponent* create_new_component() +{ + + /* variable definitions */ + icalcomponent* calendar; + icalcomponent* event; + struct icaltimetype atime = icaltime_from_timet( time(0),0); + struct icalperiodtype rtime; + icalproperty* property; + + /* Define a time type that will use as data later. */ + rtime.start = icaltime_from_timet( time(0),0); + rtime.end = icaltime_from_timet( time(0),0); + rtime.end.hour++; + + /* Create calendar and add properties */ + + calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); + + /* Nearly every libical function call has the same general + form. The first part of the name defines the 'class' for the + function, and the first argument will be a pointer to a struct + of that class. So, icalcomponent_ functions will all take + icalcomponent* as their first argument. */ + + /* The next call creates a new proeprty and immediately adds it to the + 'calendar' component. */ + + icalcomponent_add_property( + calendar, + icalproperty_new_version("2.0") + ); + + + /* Here is the short version of the memory rules: + + If the routine name has "new" in it: + Caller owns the returned memory. + If you pass in a string, the routine takes the memory. + + If the routine name has "add" in it: + The routine takes control of the component, property, + parameter or value memory. + + If the routine returns a string ( "get" and "as_ical_string" ) + The library owns the returned memory. + + There are more rules, so refer to the documentation for more + details. + + */ + + icalcomponent_add_property( + calendar, + icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN") + ); + + /* Add an event */ + + event = icalcomponent_new(ICAL_VEVENT_COMPONENT); + + icalcomponent_add_property( + event, + icalproperty_new_dtstamp(atime) + ); + + /* In the previous call, atime is a struct, and it is passed in by value. + This is how all compound types of values are handled. */ + + icalcomponent_add_property( + event, + icalproperty_new_uid("guid-1.host1.com") + ); + + /* add a property that has parameters */ + property = icalproperty_new_organizer("mailto:mrbig@host.com"); + + icalproperty_add_parameter( + property, + icalparameter_new_role(ICAL_ROLE_CHAIR) + ); + + icalcomponent_add_property(event,property); + + /* In this style of component creation, you need to use an extra + call to add parameters to properties, but the form of this + operation is the same as adding a property to a component */ + + /* add another property that has parameters */ + property = icalproperty_new_attendee("mailto:employee-A@host.com"); + + icalproperty_add_parameter( + property, + icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT) + ); + + icalproperty_add_parameter( + property, + icalparameter_new_rsvp(1) + ); + + icalproperty_add_parameter( + property, + icalparameter_new_cutype(ICAL_CUTYPE_GROUP) + ); + + icalcomponent_add_property(event,property); + + + /* more properties */ + + icalcomponent_add_property( + event, + icalproperty_new_description("Project XYZ Review Meeting") + ); + + icalcomponent_add_property( + event, + icalproperty_new_categories("MEETING") + ); + + icalcomponent_add_property( + event, + icalproperty_new_class(ICAL_CLASS_PUBLIC) + ); + + icalcomponent_add_property( + event, + icalproperty_new_created(atime) + ); + + icalcomponent_add_property( + event, + icalproperty_new_summary("XYZ Project Review") + ); + + property = icalproperty_new_dtstart(atime); + + icalproperty_add_parameter( + property, + icalparameter_new_tzid("US-Eastern") + ); + + icalcomponent_add_property(event,property); + + + property = icalproperty_new_dtend(atime); + + icalproperty_add_parameter( + property, + icalparameter_new_tzid("US-Eastern") + ); + + icalcomponent_add_property(event,property); + + icalcomponent_add_property( + event, + icalproperty_new_location("1CP Conference Room 4350") + ); + + icalcomponent_add_component(calendar,event); + + return calendar; +} + + +/* Now, create the same component as in the previous routine, but use +the constructor style. */ + +icalcomponent* create_new_component_with_va_args() +{ + + /* This is a similar set up to the last routine */ + icalcomponent* calendar; + struct icaltimetype atime = icaltime_from_timet( time(0),0); + struct icalperiodtype rtime; + + rtime.start = icaltime_from_timet( time(0),0); + rtime.end = icaltime_from_timet( time(0),0); + rtime.end.hour++; + + /* Some of these routines are the same as those in the previous + routine, but we've also added several 'vanew' routines. These + 'vanew' routines take a list of properties, parameters or + values and add each of them to the parent property or + component. */ + + calendar = + icalcomponent_vanew( + ICAL_VCALENDAR_COMPONENT, + icalproperty_new_version("2.0"), + icalproperty_new_prodid("-//RDU Software//NONSGML HandCal//EN"), + icalcomponent_vanew( + ICAL_VEVENT_COMPONENT, + icalproperty_new_dtstamp(atime), + icalproperty_new_uid("guid-1.host1.com"), + icalproperty_vanew_organizer( + "mailto:mrbig@host.com", + icalparameter_new_role(ICAL_ROLE_CHAIR), + 0 + ), + icalproperty_vanew_attendee( + "mailto:employee-A@host.com", + icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), + icalparameter_new_rsvp(1), + icalparameter_new_cutype(ICAL_CUTYPE_GROUP), + 0 + ), + icalproperty_new_description("Project XYZ Review Meeting"), + + icalproperty_new_categories("MEETING"), + icalproperty_new_class(ICAL_CLASS_PUBLIC), + icalproperty_new_created(atime), + icalproperty_new_summary("XYZ Project Review"), + icalproperty_vanew_dtstart( + atime, + icalparameter_new_tzid("US-Eastern"), + 0 + ), + icalproperty_vanew_dtend( + atime, + icalparameter_new_tzid("US-Eastern"), + 0 + ), + icalproperty_new_location("1CP Conference Room 4350"), + 0 + ), + 0 + ); + + + /* Note that properties with no parameters can use the regular + 'new' constructor, while those with parameters use the 'vanew' + constructor. And, be sure that the last argument in the 'vanew' + call is a zero. Without, your program will probably crash. */ + + return calendar; +} + + +void find_sub_components(icalcomponent* comp) +{ + icalcomponent *c; + + /* The second parameter to icalcomponent_get_first_component + indicates the type of component to search for. This will + iterate through all sub-components */ + for(c = icalcomponent_get_first_component(comp,ICAL_ANY_COMPONENT); + c != 0; + c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)){ + + do_something(c); + } + + /* This will iterate only though VEVENT sub-components */ + + for(c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT); + c != 0; + c = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT)){ + + do_something(c); + } + +} + +/* Ical components only have one internal iterator, so removing the + object that the iterator points to can cause problems. Here is the + right way to remove components */ + +void remove_vevent_sub_components(icalcomponent* comp){ + + icalcomponent *c, *next; + + for( c = icalcomponent_get_first_component(comp,ICAL_VEVENT_COMPONENT); + c != 0; + c = next) + { + next = icalcomponent_get_next_component(comp,ICAL_VEVENT_COMPONENT); + + icalcomponent_remove_component(comp,c); + + do_something(c); + } + +} + diff --git a/examples/access_properties_and_parameters.c b/examples/access_properties_and_parameters.c new file mode 100644 index 00000000..0c0f2ae0 --- /dev/null +++ b/examples/access_properties_and_parameters.c @@ -0,0 +1,151 @@ +/* access_properties_and_parameters.c */ + +#include <libical/ical.h> +#include <string.h> +#include <stdlib.h> + +/* Get a particular parameter out of a component. This routine will + return a list of strings of all attendees who are required. Note + that this routine assumes that the component that we pass in is a + VEVENT. */ + +void get_required_attendees(icalcomponent* event) +{ + icalproperty* p; + icalparameter* parameter; + + assert(event != 0); + assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT); + + /* This loop iterates over all of the ATTENDEE properties in the + event */ + + /* The iteration routines save their state in the event + struct, so the are not thread safe unless you lock the whole + component. */ + + for( + p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY); + p != 0; + p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY) + ) { + + /* Get the first ROLE parameter in the property. There should + only be one, so we won't bother to iterate over them. But, + you can iterate over parameters just like with properties */ + + parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER); + + /* If the parameter indicates the participant is required, get + the attendees name and stick a copy of it into the output + array */ + + if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT) + { + /* Remember, the caller does not own this string, so you + should strdup it if you want to change it. */ + const char *attendee = icalproperty_get_attendee(p); + printf("%s",attendee); + } + } + +} + +/* Here is a similar example. If an attendee has a PARTSTAT of + NEEDSACTION or has no PARTSTAT parameter, change it to + TENTATIVE. */ + +void update_attendees(icalcomponent* event) +{ + icalproperty* p; + icalparameter* parameter; + + assert(event != 0); + assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT); + + for( + p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY); + p != 0; + p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY) + ) { + + parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER); + + if (parameter == 0) { + + /* There was no PARTSTAT parameter, so add one. */ + icalproperty_add_parameter( + p, + icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE) + ); + + } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) { + /* Remove the NEEDSACTION parameter and replace it with + TENTATIVE */ + + icalproperty_remove_parameter(p,ICAL_PARTSTAT_PARAMETER); + + /* Don't forget to free it */ + icalparameter_free(parameter); + + /* Add a new one */ + icalproperty_add_parameter( + p, + icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE) + ); + } + + } +} + +/* Here are some examples of manipulating properties */ + +void test_properties() +{ + icalproperty *prop; + icalparameter *param; + icalvalue *value; + char *str; + + icalproperty *clone; + + /* Create a new property */ + prop = icalproperty_vanew_comment( + "Another Comment", + icalparameter_new_cn("A Common Name 1"), + icalparameter_new_cn("A Common Name 2"), + icalparameter_new_cn("A Common Name 3"), + icalparameter_new_cn("A Common Name 4"), + 0); + + /* Iterate through all of the parameters in the property */ + for(param = icalproperty_get_first_parameter(prop,ICAL_ANY_PARAMETER); + param != 0; + param = icalproperty_get_next_parameter(prop,ICAL_ANY_PARAMETER)) { + + printf("Prop parameter: %s\n",icalparameter_get_cn(param)); + } + + /* Get a string representation of the property's value */ + printf("Prop value: %s\n",icalproperty_get_comment(prop)); + + /* Spit out the property in its RFC 2445 representation */ + str = icalproperty_as_ical_string_r(prop); + printf("As iCAL string:\n %s\n", str); + free(str); + + /* Make a copy of the property. Caller owns the memory */ + clone = icalproperty_new_clone(prop); + + /* Get a reference to the value within the clone property */ + value = icalproperty_get_value(clone); + + str = icalvalue_as_ical_string_r(value); + printf("Value: %s", str); + free(str); + + /* Free the original and the clone */ + icalproperty_free(clone); + icalproperty_free(prop); + +} diff --git a/examples/access_store.c b/examples/access_store.c new file mode 100644 index 00000000..fc2f5b01 --- /dev/null +++ b/examples/access_store.c @@ -0,0 +1,210 @@ + + +void acess_cap(void) { + + /* Note, all routines that are prefixed with "caller_" are + implemented by the caller of libical */ + +/* 1 Open a connection to a store. */ + + /* The caller is responsible for getting a socket to the server + and negotiating the first stages of the CAP exchange. These can + be fairly complex and varied for different operating systems, + local vs remote usage, and for different authentication + schemes, so the API does not try to simplify them. */ + + int sock = caller_create_socket_to_server(); + icalcstp *cstp = icalcstp_new(0,sock,sock); + + caller_authenticate(cstp); + + icalcsdb *csdb = icalcsdb_new(cstp); + +/* 2 Create a new calendar for which user Bill can read and user Mary can +read and write. See CAP draft 7.2.1.1.1. for the text of this example*/ + + /* This case requires setting up a TARGET, multiple OWNERs and + multiple VCARs, so it creates a component and uses CSTP that + than the CSDB interface. + + icalcomponent *create = icalcaputil_new_create(); + + icalcomponent_add_property(create, + icalproperty_new_target( + strdup("cap://cal.example.com/relcal8") + )); + + icalcomponent *cal = + icalcomponent_vanew_vcalendar( + icalproperty_new_relcalid(strdup("relcalid")), + icalproperty_new_name(strdup("Bill & Mary's cal")), + icalproperty_new_owner(strdup("bill")), + icalproperty_new_owner(strdup("mary")), + icalproperty_new_calmaster(strdup("mailto:bill@example.com")), + icalcomponent_vanew_vcar( + icalproperty_new_grant(strdup("UPN=bill;ACTION=*;OBJECT=*")), + icalproperty_new_grant(strdup("UPN=bill;ACTION=*;OBJECT=*")) + 0) + 0); + + error = icalcomponent_add_component(create,cal); + + /* Send the data */ + error = icalcstp_senddata(cstp,10,create); + + + /* Get the response */ + icalcstp_response response = icalcstp_get_first_response(cstp); + + /* Do something with the response*/ + + if(icalenum_reqstat_major(response.code) != 2){ + /* do something with the error */ + } + + icalcomponent_free(create); + + +/* 3 Create several new calendars */ + + /* Same as #2, but insert more TARGET properties and read more responses*/ + +/* 4 Delete a calendar */ + + error = icalcsdb_delete(csdb,"uid12345-example.com"); + +/* 5 Change the calid of a calendar */ + + erorr = icalcsdb_move(csdb,"uid12345-old-example.com", + "uid12345-new-example.com"); + + +/* 6 Delete all calendars belonging to user bob */ + + icalproperty *p; + /* First expand bob's UPN into a set of CALIDs */ + icalcomponent *calids = icalcsdb_expand_upn("bob@example.com"); + + /* Then, create a message to delete all of them */ + icalcomponent *delete = icalcaputil_new_create(); + + + for(p = icalcomponent_get_first_property(calids,ICAL_CALID_PROPERTY); + p != 0; + p = icalcomponent_get_next_property(calids,ICAL_CALID_PROPERTY)){ + + char* = icalproperty_get_calid(p); + + icalcomponent_add_target(delete,p); + + } + + /* Send the message */ + + error = icalcstp_senddata(cstp,10,delete); + + /* Finally, read the responses */ + + for(response = icalcstp_get_first_response(cstp); + response.code != ICAL_UNKNOWN_STATUS; + response = icalcstp_get_next_response(cstp)){ + + if(icalenum_reqstat_major(response.code) != 2){ + /* do something with the error */ + } + } + + +/* 7 Get three new UIDs from the store */ + + /* libical owns the returned memory. Copy before using */ + char* uid1 = icalcsdb_generateuid(csdb); + char* uid2 = icalcsdb_generateuid(csdb); + char* uid3 = icalcsdb_generateuid(csdb); + +/* 8 Store a new VEVENT in the store. */ + + /* Very similar to case #2 */ + +/* 9 Find all components for which the LOCATION is "West Conference +Room" and change them to "East Conference Room" */ + + icalcomponent *modify = icalcaputil_new_modify(); + + icalcaputil_modify_add_old_prop(modify, + icalproperty_new_location( + strdup("West Conference Room"))); + + icalcaputil_modify_add_new_prop(modify, + icalproperty_new_location( + strdup("East Conference Room"))); + + icalcaputil_add_target(modify,"relcal2"); + + /* Send the component */ + error = icalcstp_senddata(cstp,10,delete); + + /* Get the response */ + icalcstp_response response = icalcstp_get_first_response(cstp); + + /* Do something with the response*/ + + if(icalenum_reqstat_major(response.code) != 2){ + /* do something with the error */ + } + + icalcomponent_free(modify); + +/* 10 Find the component with UID X and add a GEO property to it. */ + + + icalcomponent *modify = icalcaputil_new_modify(); + + icalcaputil_modify_add_query(modify, + "SELECT UID FROM VEVENT WHERE UID = 'X'"); + + icalcaputil_modify_add_new_prop(modify, + icalproperty_new_geo( + strdup("-117;32"))); + + icalcaputil_add_target(modify,"relcal2"); + + /* Send the component */ + error = icalcstp_senddata(cstp,10,delete); + + /* Get the response */ + icalcstp_response response = icalcstp_get_first_response(cstp); + + /* Do something with the response*/ + + if(icalenum_reqstat_major(response.code) != 2){ + /* do something with the error */ + } + + icalcomponent_free(modify); + + +/* 11 Delete all VEVENTS which have a METHOD that is not CREATED */ + + +/* 12 Retrieve all VEVENTS which have a METHOD that is not CREATED */ + + /* Nearly the same at #11 */ + +/* 13 Retrieve the capabilities of the store */ + +/* 14 Retrieve/Modify/Add/Delete properties of a store */ + +/* 15 Retrieve/Modify/Add/Delete VCARs of a store */ + +/* 16 Retrieve/Modify/Add/Delete VTIMEZONEs of a store */ + +/* 17 Retrieve/Modify/Add/Delete properties of a calendar */ + +/* 18 Retrieve/Modify/Add/Delete VCARs of a calendar */ + +/* 19 Retrieve/Modify/Add/Delete VTIMEZONEs of a calendar */ + +/* 20 Translate a CALID into one or more UPNs */ + +/* 21 Expand a group UPN into all of the members of the group */ diff --git a/examples/changenames.pl b/examples/changenames.pl new file mode 100644 index 00000000..4adf84b9 --- /dev/null +++ b/examples/changenames.pl @@ -0,0 +1,4 @@ +s/icalcluster/icalfileset/g; +s/ICALCLUSTER/ICALFILESET/g; +s/icalstore/icaldirset/g; +s/ICALSTORE/ICALDIRSET/g; diff --git a/examples/errors.c b/examples/errors.c new file mode 100644 index 00000000..2ff316dd --- /dev/null +++ b/examples/errors.c @@ -0,0 +1,70 @@ +/* errors.c */ + +#include <libical/ical.h> +#include <stdio.h> + +void program_errors() +{ + /*Most routines will set icalerrno on errors. This is an + enumeration defined in icalerror.h */ + + icalcomponent *c; + + icalerror_clear_errno(); + + c = icalcomponent_new(ICAL_VEVENT_COMPONENT); + + if (icalerrno != ICAL_NO_ERROR){ + + fprintf(stderr,"Horrible libical error: %s\n", + icalerror_strerror(icalerrno)); + + } + +} + +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); + +} diff --git a/examples/main.c b/examples/main.c new file mode 100644 index 00000000..3d8d7777 --- /dev/null +++ b/examples/main.c @@ -0,0 +1,12 @@ +/* This is just to make the code in the example directory link properly. */ +#include <libical/ical.h> + +int main() +{ + + return 1; +} + + +void do_something(icalcomponent* comp){ +} diff --git a/examples/parse_text.c b/examples/parse_text.c new file mode 100644 index 00000000..2fc9051b --- /dev/null +++ b/examples/parse_text.c @@ -0,0 +1,70 @@ +/* parse_text.c + + */ +#include <stdio.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <libical/ical.h> + +#include <stdlib.h> + +/* The icalparser_get_line routine will create a single *content* line +out of one or more input lines. The content line is all of the +properties and values for a single property, and it can span several +input lines. So, icalparser_get_line will need to be able to get more +data on its own. Read_string is a routine that does this. You can +write your own version of read stream to get data from other types of +files, sockets, etc. */ + +char* read_stream(char *s, size_t size, void *d) +{ + char *c = fgets(s,size, (FILE*)d); + + return c; + +} + +void parse_text(int argc, char* argv[]) +{ + + char* line; + FILE* stream; + icalcomponent *c; + + /* Create a new parser object */ + icalparser *parser = icalparser_new(); + + stream = fopen(argv[1],"r"); + + assert(stream != 0); + + /* Tell the parser what input routie it should use. */ + icalparser_set_gen_data(parser,stream); + + do{ + + /* Get a single content line by making one or more calls to + read_stream()*/ + line = icalparser_get_line(parser,read_stream); + + /* Now, add that line into the parser object. If that line + completes a component, c will be non-zero */ + c = icalparser_add_line(parser,line); + + + if (c != 0){ + char *temp = icalcomponent_as_ical_string_r(c); + printf("%s", temp); + free(temp); + + printf("\n---------------\n"); + + icalcomponent_free(c); + } + + } while ( line != 0); + + + icalparser_free(parser); +} diff --git a/examples/usecases.c b/examples/usecases.c new file mode 100644 index 00000000..713d1a48 --- /dev/null +++ b/examples/usecases.c @@ -0,0 +1,97 @@ +/* -*- Mode: C -*- + ====================================================================== + FILE: usecases.c + CREATOR: eric 03 April 1999 + + DESCRIPTION: + + $Id: usecases.c,v 1.3 2008-01-02 20:07:29 dothebart Exp $ + $Locker: $ + + (C) COPYRIGHT 1999 Eric Busboom + http://www.softwarestudio.org + + The contents of this file are subject to the Mozilla Public License + Version 1.0 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and + limitations under the License. + + The original author is Eric Busboom + The original code is usecases.c + + + ======================================================================*/ + +#include <libical/ical.h> +#include <assert.h> +#include <string.h> /* for strdup */ +#include <stdlib.h> /* for malloc */ +#include <stdio.h> /* for printf */ +#include <time.h> /* for time() */ + +char str[] = "BEGIN:VCALENDAR\ +PRODID:\"-//RDU Software//NONSGML HandCal//EN\"\ +VERSION:2.0\ +BEGIN:VEVENT\ +DTSTAMP:19980309T231000Z\ +UID:guid-1.host1.com\ +ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com\ +ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com\ +DESCRIPTION:Project XYZ Review Meeting\ +CATEGORIES:MEETING\ +CREATED:19980309T130000Z\ +SUMMARY:XYZ Project Review\ +DTSTART;TZID=US-Eastern:19980312T083000\ +DTEND;TZID=US-Eastern:19980312T093000\ +END:VEVENT\ +END:VCALENDAR"; + + + + +/* Here are some ways to work with values. */ +void test_values() +{ + icalvalue *v; + icalvalue *copy; + char *str; + + v = icalvalue_new_caladdress("cap://value/1"); + printf("caladdress 1: %s\n",icalvalue_get_caladdress(v)); + + icalvalue_set_caladdress(v,"cap://value/2"); + printf("caladdress 2: %s\n",icalvalue_get_caladdress(v)); + str = icalvalue_as_ical_string_r(v)); + printf("String: %s\n", str); + free(str); + + copy = icalvalue_new_clone(v); + str = icalvalue_as_ical_string_r(v); + printf("Clone: %s\n", str); + free(str); + icalvalue_free(v); + icalvalue_free(copy); + + +} + +void test_parameters() +{ + icalparameter *p; + char *str; + + p = icalparameter_new_cn("A Common Name"); + + printf("Common Name: %s\n",icalparameter_get_cn(p)); + + str = icalparameter_as_ical_string_r(p)); + printf("As String: %s\n", str); + free(str); +} + + |