diff options
Diffstat (limited to 'libical/doc/UsingLibical.txt')
-rw-r--r-- | libical/doc/UsingLibical.txt | 395 |
1 files changed, 313 insertions, 82 deletions
diff --git a/libical/doc/UsingLibical.txt b/libical/doc/UsingLibical.txt index de803cbfde..ea5726f401 100644 --- a/libical/doc/UsingLibical.txt +++ b/libical/doc/UsingLibical.txt @@ -4,9 +4,9 @@ Using Libical Eric Busboom (eric@softwarestudio.org) -May 2000 +November 2000 + -\tableofcontents{} 1 Introduction @@ -54,14 +54,20 @@ my version of the library if they are similarly dual-licensed. 1.3 Example Code A lot of the documentation for this library is in the form of example -code. These examples are in the ``examples'' directory of the distribution. -Also look in ``src/test'' for more annotated examples. +code. These examples are in the "examples" directory of the distribution. +Also look in "src/test" for more annotated examples. 2 Building the Library Libical uses autoconf to generate makefiles, although it uses none of the autoconf flags to influence the compilation. It should built -with no adjustments on Linux, FreeBSD and Solaris. +with no adjustments on Linux, FreeBSD and Solaris under gcc. Some +version have been successfully been build on MacOS, Solaris and UnixWare +without gcc, but you may run into problems with a particular later +version. + +For a more complete guide to building the library, see the README file +in the distribution. 3 Structure @@ -75,8 +81,8 @@ content line ORGANIZER;ROLE=CHAIR:MAILTO:mrbig@host.com -The property name is ``ORGANIZER,'' the value of the property is ``mrbig@host.com'' -and the ``ROLE'' parameter specifies that Mr Big is the chair of the +The property name is "ORGANIZER," the value of the property is "mrbig@host.com" +and the "ROLE" parameter specifies that Mr Big is the chair of the meetings associated with this property. Components are groups of properties that represent the core objects @@ -84,9 +90,10 @@ of a calendar system, such as events or timezones. The central goal of libical is to parse iTIP data into an internal representation of Components, Properties, Parameters an Values, and -to allow the user to manipulate the data in various ways ([fig] \includegraphics{icaluml.eps} ) When -a component is sent across a network, if it is un-encrypted, it will -look something like: +to allow the user to manipulate the data in various ways + +When a component is sent across a network, if it is un-encrypted, it +will look something like: BEGIN:VEVENT @@ -137,7 +144,7 @@ structures, classes that aid in creating and using iCal components. 3.2.2 Types -3.2.3 The Parser +3.2.3 The parser 3.2.4 Restrictions @@ -163,11 +170,11 @@ like components, but are not defined as components in the specification. XDAYLIGHT and XSTANDARD are notable examples. These pseudo components group properties within the VTIMEZONE components. For instanace, the timezone properties associated with daylight savings time starts with -``BEGIN:DAYLIGHT'' and ends with ``END:DAYLIGHT, just like other components, +"BEGIN:DAYLIGHT" and ends with "END:DAYLIGHT, just like other components, but is not defined as a component in RFC2445. ( See RFC2445, page 61 ) In Libical,this grouping is represented by the XDAYLIGHT component. -Standard iCAL components all start with the letter ``V,'' while pseudo -components start with''X.'' +Standard iCAL components all start with the letter "V," while pseudo +components start with"X." There are also pseudo components that are conceptually derived classess of VALARM. RFC2446 defines what properties may be included in each @@ -175,8 +182,8 @@ component, and for VALARM, the set of properties it may have depends on the value of the ACTION property. For instance, if a VALARM component has an ACTION property with the -value of ``AUDIO,'' the component must also have an ``ATTACH'' property. -However, if the ACTION value is ``DISPLAY,'' the component must have +value of "AUDIO," the component must also have an "ATTACH" property. +However, if the ACTION value is "DISPLAY," the component must have a DESCRIPTION property. To handle these various, complex restrictions, libical has pseudo components @@ -266,14 +273,14 @@ icalcomponent_add_property(event,prop); While we are on this example, you should notice that libical uses a semi-object-oriented style of interface. Most things you work with -are objects, that are instantiated with a constructor that has ``new'' +are objects, that are instantiated with a constructor that has "new" in the name. Also note that, other than the object reference, most structure data is passed in to libical routines by value. Strings, of course, are passed in by reference, but libical will take ownership of the memory, so you had beter strdup() the data unless you want a core dump when the memory is freed for the second time. Libical has some complex but very regular memory handling rules. These are -detailed in section \ref{sec:memory}. +detailed in section [sec:memory]. If any of the constructors fail, they will return 0. If you try to insert 0 into a property or component, or use a zero-valued object @@ -296,7 +303,9 @@ of text. icalproperty_new_version(strdup("2.0")), - icalproperty_new_prodid(strdup("-//RDU Software//NONSGML HandCal//EN")), + icalproperty_new_prodid(strdup( + + "-//RDU Software//NONSGML HandCal//EN")), icalcomponent_vanew( @@ -320,7 +329,9 @@ of text. strdup("employee-A@host.com"), - icalparameter_new_role(ICAL_ROLE_REQPARTICIPANT), + icalparameter_new_role( + + ICAL_ROLE_REQPARTICIPANT), icalparameter_new_rsvp(1), @@ -330,7 +341,9 @@ of text. ), - icalproperty_new_location(strdup("1CP Conference Room 4350")), + icalproperty_new_location(strdup( + + "1CP Conference Room 4350")), 0 @@ -341,8 +354,8 @@ of text. ); This form is similar to the regular constructor, except that they have -``vanew'' instead of ``new'' in the name. The arguments are similar -too, except that the component contstructor can have a list of properties, +"vanew" instead of "new" in the name. The arguments are similar too, +except that the component contstructor can have a list of properties, and the property constructor can have a list or parameters. Be sure to terminate every list with a '0', or your code will crash, if you are lucky. @@ -432,7 +445,8 @@ is a convienience routine; icalcomponent* icalparser_parse(icalparser *parser, - char* (*line_gen_func)(char *s, size_t size, void* d)) + char* (*line_gen_func)(char *s, size_t sise, void* +d)) To use this routine, you still must construct the parser object and pass in a reference to a line reading routine. If the parser can create @@ -456,9 +470,9 @@ To find a sub-component of a component, use: icalcomponent* icalcomponent_get_first_component( - icalcomponent* component, + icalcomponent* component, - icalcomponent_kind kind); + icalcomponent_kind kind); This routine will return a reference to the first component of the type 'kind.' The key kind values, listed in icalenums.h are: @@ -491,7 +505,9 @@ the first: icalcomponent* icalcomponent_get_next_component( - icalcomponent* component, icalcomponent_kind kind); + icalcomponent* component, + + icalcomponent_kind kind); With the 'first' and 'next' routines, you can create a for loop to iterate through all of a components subcomponents @@ -500,7 +516,7 @@ iterate through all of a components subcomponents c != 0; - c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)) + c = icalcomponent_get_next_component(comp,ICAL_ANY_COMPONENT)) { @@ -512,16 +528,68 @@ This code bit wil iterate through all of the subcomponents in 'comp' but you can select a specific type of component by changing ICAL_ANY_COMPONENT to another component type. -6.2.3 Removing Components +6.2.3 Using Component Iterators + +The iteration model in the previous section requires the component +to keep the state of the iteration. So, you could not use this model +to perform a sorting operations, since you'd need two iterators and +there is only space for one. If you ever call icalcomponent_get_first_component() +which an iteration is in progress, the pointer will be reset to the +beginning. + +To solve this problem, there are also external iterators for components. +The routines associated with these external iterators are: + +icalcompiter icalcomponent_begin_component(icalcomponent* component, +icalcomponent_kind kind); + +icalcompiter icalcomponent_end_component(icalcomponent* component, +icalcomponent_kind kind); + +icalcomponent* icalcompiter_next(icalcompiter* i); + +icalcomponent* icalcompiter_prior(icalcompiter* i); + +icalcomponent* icalcompiter_deref(icalcompiter* i); + +The _begin_() and _end_() routines return a new iterator that points +to the begining and ending of the list of subcomponent for the given +component, and the kind argument works like the kind argument for +internal iterators. + +After creating an iterators, use _next_() and _prior_() to step forward +and backward through the list and get the component that the iterator +points to, and use _deref() to return the component that the iterator +points to without moving the iterator. All routines will return 0 +when they move to point off the end of the list. + +Here is an example of a loop using these routines: + +for( + + i = icalcomponent_begin_component(impl->cluster,ICAL_ANY_COMPONENT); + + icalcompiter_deref(&i)!= 0; + + icalcompiter_next(&i) + +) { + + icalcomponent *this = icalcompiter_deref(&i); + +} + +6.2.4 Removing Components Libical component have internal iterators, so you can only have one iteration over a component at a time. Removing an element from a list while iterating through the list can cause problems, since you will probably be removing the element that the internal iterator points -to. This will result in the iteration loop terminating immediately -after removing the element. To avoid the problem, you will need to -step the iterator ahead of the element you are going to remove, like -this: +to. The _remove() routine will keep the iterator valid by moving it +to the next component, but in a normal loop, this will result in two +advances per iteration, and you will remove only every other component. + To avoid the problem, you will need to step the iterator ahead of +the element you are going to remove, like this: for(c = icalcomponent_get_first_component(parent_comp,ICAL_ANY_COMPONENT); @@ -537,7 +605,28 @@ for(c = icalcomponent_get_first_component(parent_comp,ICAL_ANY_COMPONENT); } -6.2.4 Working with properties and parameters +Another way to remove components is to rely on the side effect of icalcomponent_remove_component: +if component iterator in the parent component is pointing to the child +that will be removed, it will move the iterator to the component after +the child. The following code will exploit this behavior: + +icalcomponent_get_first_component(parent_comp,ICAL_VEVENT_COMPONENT); + +while((c=icalcomponent_get_current_component(c)) != 0 ){ + + if(icalcomponent_isa(c) == ICAL_VEVENT_COMPONENT){ + + icalcomponent_remove_component(parent_comp,inner); + + } else { + + icalcomponent_get_next_component(parent_comp,ICAL_VEVENT_COMPONENT); + + } + +} + +6.2.5 Working with properties and parameters Finding, iterating and removing properties works the same as it does for components, using the property-specific or parameter-specific @@ -591,17 +680,55 @@ void icalproperty_remove_parameter( icalparameter_kind kind); -6.2.5 Getting Values +6.2.6 Working with values + +Values are typically part of a property, although they can exist on +their own. You can maniplulate them either as part of the property +or independantly. + +The most common way to work with values to is to maniplate them from +they properties that contain them. This involves fewer routine calls +and intermediate variables than working with them independently, and +it is type-safe. + +For each property, there are a _get_ and a _set_ routine that access +the internal value. For instnace, for the UID property, the routines +are: + +void icalproperty_set_uid(icalproperty* prop, const char* v) + +const char* icalproperty_get_uid(icalproperty* prop) + +For multivalued properties, like ATTACH, the value type is usually +a struct or union that holds both possible types. + +If you want to work with the underlying value object, you can get and +set it with: -6.2.6 Setting Values +icalvalue* icalproperty_get_value (icalproperty* prop) -6.2.7 Getting Parameters +void icalproperty_set_value(icalproperty* prop, icalvalue* value); -6.2.8 Setting Parameters +Icalproperty_get_value() will return a reference that you can manipluate +with other icalvalue routines. Most of the time, you will have to +know what the type of the value is. For instance, if you know that +the value is a DATETIME type, you can manipluate it with: -6.2.9 Removing Parameters +struct icaltimetype icalvalue_get_datetime(icalvalue* value); -6.2.10 Checking Component Validity +void icalvalue_set_datetime(icalvalue* value, struct icaltimetype v); + +When working with an extension property or value (and X-PROPERTY or +a property that has the parameter VALUE=x-name ) the value type is +always a string. To get and set the value, use: + +void icalproperty_set_x(icalproperty* prop, char* v); + +char* icalproperty_get_x(icalproperty* prop); + +6.2.7 Working with parameters + +6.2.8 Checking Component Validity RFC 2446 defines rules for what properties must exist in a component to be used for transfering scheduling data. Most of these rules relate @@ -609,7 +736,7 @@ to the existence of properties relative to the METHOD property, which declares what operation a remote reciever should use to process a component. For instance, if the METHOD is REQUEST and the component is a VEVENT, the sender is probably asking the reciever to join in -a meeting. I this case, RFC2446 says that the component must specify +a meeting. In this case, RFC2446 says that the component must specify a start time (DTSTART) and list the reciever as an attendee (ATTENDEE). Libical can check these restrictions with the routine: @@ -624,7 +751,7 @@ When this routine runs, it will insert new properties into the component to indicate any errors it finds. See section 6.5.3, X-LIC-ERROR for more information about these error properties. -6.2.11 Converting Components to Text +6.2.9 Converting Components to Text To create an RFC2445 compliant text representtion of an object, use one of the *_as_ical_string() routines: @@ -642,21 +769,125 @@ it will cascade and convert all of the parameters, properties and values that are attached to the root component. Icalproperty_as_ical_string() will terminate each line with the RFC2445 -specified line terminator ``\r\n'' However, if you compile with the -symbol ICAL_UNIX_NEWLINE defined, it will terminate lines with ``\n'' +specified line terminator "\r\n" However, if you compile with the symbol +ICAL_UNIX_NEWLINE defined, it will terminate lines with "\n" Remember that the string returned by these routines is owned by the library, and will eventually be re-written. You should copy it if you want to preserve it. -6.3 Storing Objects +6.3 Time + +6.3.1 Time structure + +LIbical defines it's own time structure for storing all dates and times. +It would have been nice to re-use the C library's struct tm, but that +structure does not differentiate between dates and times, and between +local time and UTC. The libical structure is: + +struct icaltimetype { + + int year; + + int month; + + int day; + + int hour; + + int minute; + + int second; + + int is_utc; /* 1-> time is in UTC timezone */ + + int is_date; /* 1 -> interpret this as date. */ }; + +The year, month, day, hour, minute and second fields how the broken-out +time values. The is_utc field distinguishes between times UTC and +a local time zone. The is_date field indicates if the intra-day fields +hold valid data. + +6.3.2 Time manipulating routines + +The null time value is used to indicate that the data in the structure +is not a valid time. + +struct icaltimetype icaltime_null_time(void); + +int icaltime_is_null_time(struct icaltimetype t); + +It is sensible for the broken-out time fields to contain values that +are not permitted in an ISO compliant time string. For instance, the +seconds field can hold values greater than 59, and the hours field +can hold values larger than 24. The excessive values will be rolled +over into the next larger field when the structure is normalized. + +struct icaltimetype icaltime_normalize(struct icaltimetype t); + +There are several routines to get the day of the week or month, etc, +from a time structure. + +short icaltime_day_of_year(struct icaltimetype t); + +struct icaltimetype icaltime_from_day_of_year(short doy, short year); + +short icaltime_day_of_week(struct icaltimetype t); + +short icaltime_start_doy_of_week(struct icaltimetype t); + +short icaltime_week_number(short day_of_month, short month, short year); + +struct icaltimetype icaltime_from_week_number(short week_number, short +year); + +short icaltime_days_in_month(short month,short year); + +Two routines convert time structures to and from the number of seconds +since the POSIX epoch. The is_date field indicates wether or not the +hour, minute and second fields should be used in the conversion, and +is_utc indicates if the value should be converted to a local time +or a UTC time, using the operating system suppled notion of the local +timezone. + +struct icaltimetype icaltime_from_timet(time_t v, int is_date, int +is_utc); + +time_t icaltime_as_timet(struct icaltimetype); + +The compare routine works exactly like strcmp, but on time structures. + +int icaltime_compare(struct icaltimetype a,struct icaltimetype b); + +The following routines convert between UTC and a named timezone. The +tzid field must be a timezone name from the Olsen database, such as +"America/Los_Angeles." + +The utc_offset routine returns the offset of the named time zone from +UTC, in seconds. + +The tt parmeter in the fonllowing routines indicates the date on which +the conversion should be made. The tt parameter is necessary because +timezones have many different rules for when daylight savings time +is used, and these rules can change over time. So, for a single timezone +one year may have daylight savings time on March 15, but for other +years March 15 may be standard time, and some years may have standard +time all year. + +int icaltime_utc_offset(struct icaltimetype tt, char* tzid) + +struct icaltimetype icaltime_as_utc(struct icaltimetype tt,char* tzid); + +struct icaltimetype icaltime_as_zone(struct icaltimetype tt,char* tzid); + +6.4 Storing Objects The libical distribution inclues a seperate library, libicalss, that allows you to store iCal component data to disk in a variety of ways. This library is documented seperately. ( & currently, not at all. ) -6.4 \label{sec:memory}Memory Management +6.5 <sec:memory>Memory Management Libical relies heavily on dynamic allocation for both the core objects and for the strings used to hold values. Some of this memory the library @@ -683,19 +914,19 @@ library. Here is a summary of the memory rules. put it on a ring buffer to reclaim later. You'd better strdup() it if you want to keep it, and you don't have to delete it. -6.5 Error Handling +6.6 Error Handling Libical has several error handling mechanisms for the varioustypes of programming, semantic and syntactic errors you may encounter. -6.5.1 Return values +6.6.1 Return values Many library routines signal errors through their return values. All routines that return a pointer, such as icalcomponent_new(), will return 0 ( zero ) on a fatal error. Some routines will return a value of enum icalerrorenum. -6.5.2 icalerrno +6.6.2 icalerrno Most routines will set the global error value icalerrno on errors. This variable is an enumeration; permissable values can be found in @@ -703,7 +934,7 @@ libical/icalerror.h. If the routine returns an enum icalerrorenum, then the return value will be the same as icalerrno. You can use icalerror_strerror() to get a string that describes the error -6.5.3 X-LIC-ERROR and X-LIC-INVALID-COMPONENT +6.6.3 X-LIC-ERROR and X-LIC-INVALID-COMPONENT The library handles semantic and syntactic errors in components by inserting errors properties into the components. If the parser cannot @@ -723,27 +954,27 @@ RFC2445. There are a few routines to manipulate error properties: -+------------------------------------+--------------------------------+ -|Routine | Purpose | -+------------------------------------+--------------------------------+ -+------------------------------------+--------------------------------+ -|void icalrestriction_check() | Check a component against | -| | RFC2446 and insert error prop | -| | erties to indicate non compli | -| | ance | -|int icalcomponent_count_errors() | Return the number of error | -| | properties in a component | -|void icalcomponent_strip_errors() | Remove all error properties in | -| | as component | -+------------------------------------+--------------------------------+ -|void icalcomponent_convert_errors() | Convert some error properties | -| | into REQUESTS-STATUS to indi | -| | cate the inability to process | -| | the component as an iTIP re | -| | quest. | -+------------------------------------+--------------------------------+ -| | | -+------------------------------------+--------------------------------+ ++-------------------------------------+-----------------------------------------------+ +| Routine | Purpose | ++-------------------------------------+-----------------------------------------------+ +| void icalrestriction_check() | Check a component against RFC2446 and insert | ++-------------------------------------+-----------------------------------------------+ +| | error properties to indicate non compliance | ++-------------------------------------+-----------------------------------------------+ +| int icalcomponent_count_errors() | Return the number of error properties | ++-------------------------------------+-----------------------------------------------+ +| | in a component | ++-------------------------------------+-----------------------------------------------+ +| void icalcomponent_strip_errors() | Remove all error properties in as | ++-------------------------------------+-----------------------------------------------+ +| | component | ++-------------------------------------+-----------------------------------------------+ +| void icalcomponent_convert_errors() | Convert some error properties into | ++-------------------------------------+-----------------------------------------------+ +| | REQUESTS-STATUS to indicate the inability to | ++-------------------------------------+-----------------------------------------------+ +| | process the component as an iTIP request. | ++-------------------------------------+-----------------------------------------------+ The types of errors are listed in icalerror.h. They are: @@ -774,24 +1005,24 @@ As of libical version0.18, this routine only convert *PARSEERROR errors and it always generates a 3.x ( failure ) code. This makes it more of a good idea than a really useful bit of code. -6.6 Naming Standard +6.7 Naming Standard -Structures that you access with the ``struct'' keyword, such as ``struct -icaltimetype'' are things that you are allowed to see inside and poke +Structures that you access with the "struct" keyword, such as "struct +icaltimetype" are things that you are allowed to see inside and poke at. -Structures that you access though a typedef, such as ``icalcomponent'' +Structures that you access though a typedef, such as "icalcomponent" are things where all of the data is hidden. -Component names that start with ``V'' are part of RFC 2445 or another -iCal standard. Component names that start with ``X'' are also part -of the spec, but they are not actually components in the spec. However, +Component names that start with "V" are part of RFC 2445 or another +iCal standard. Component names that start with "X" are also part of +the spec, but they are not actually components in the spec. However, they look and act like components, so they are components in libical. -Names that start with ``XLIC'' or ``X-LIC'' are not part of any iCal -spec. They are used internally by libical. +Names that start with "XLIC" or "X-LIC" are not part of any iCal spec. +They are used internally by libical. Enums that identify a component, property, value or parameter end with -``_COMPONENT,'' ``_PROPERTY,'' ``_VALUE,'' or ``_PARAMETER''s +"_COMPONENT," "_PROPERTY," "_VALUE," or "_PARAMETER"s Enums that identify a parameter value have the name of the parameter as the second word. For instance: ICAL_ROLE_REQPARTICIPANT or ICAL_PARTSTAT_ACCEPTED. @@ -816,4 +1047,4 @@ Checking restrictions is computationally expensive. There are a lot of hacks in the library -- bits of code that I am not proud of and should propbably be changed. These are marked with the -comment string ``HACK.'' +comment string "HACK." |